From d38c5adeb5f1f90e2b4d956e4192b0b92d9dae3c Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Mon, 7 Feb 2022 19:50:20 +0400 Subject: [PATCH] Handle 'CONNECTION_NOT_INITED' --- src/lib/mtproto/apiManager.ts | 3 +++ src/lib/mtproto/networker.ts | 4 ++++ src/lib/mtproto/networkerFactory.ts | 6 ++++++ src/lib/mtproto/tl_utils.ts | 4 ++++ 4 files changed, 17 insertions(+) diff --git a/src/lib/mtproto/apiManager.ts b/src/lib/mtproto/apiManager.ts index ab1d955c..ae7229e1 100644 --- a/src/lib/mtproto/apiManager.ts +++ b/src/lib/mtproto/apiManager.ts @@ -576,6 +576,9 @@ export class ApiManager { } else { rejectPromise(error); } + } else if(error.code === 400 && error.type === 'CONNECTION_NOT_INITED') { + networkerFactory.unsetConnectionInited(); + performRequest(cachedNetworker); } else if(!options.rawError && error.code === 420) { const waitTime = +error.type.match(/^FLOOD_WAIT_(\d+)/)[1] || 1; diff --git a/src/lib/mtproto/networker.ts b/src/lib/mtproto/networker.ts index ae828306..5b793d5e 100644 --- a/src/lib/mtproto/networker.ts +++ b/src/lib/mtproto/networker.ts @@ -375,6 +375,8 @@ export default class MTPNetworker { this.nextReq = 0; } + this.connectionInited = false; + /// #if MTPROTO_HAS_HTTP if(this.longPollInterval !== undefined) { clearInterval(this.longPollInterval); @@ -1336,7 +1338,9 @@ export default class MTPNetworker { return; } + // deserializer.setMtproto(false); result.result = deserializer.fetchObject(type, field + '[result]'); + // deserializer.setMtproto(true); // self.log(dT(), 'override rpc_result', sentMessage, type, result); } } diff --git a/src/lib/mtproto/networkerFactory.ts b/src/lib/mtproto/networkerFactory.ts index f2d498b6..0c57c2a5 100644 --- a/src/lib/mtproto/networkerFactory.ts +++ b/src/lib/mtproto/networkerFactory.ts @@ -65,6 +65,12 @@ export class NetworkerFactory { } } + public unsetConnectionInited() { + for(const networker of this.networkers) { + networker.connectionInited = false; + } + } + public forceReconnectTimeout() { for(const networker of this.networkers) { networker.forceReconnectTimeout(); diff --git a/src/lib/mtproto/tl_utils.ts b/src/lib/mtproto/tl_utils.ts index fd889bac..27246c49 100644 --- a/src/lib/mtproto/tl_utils.ts +++ b/src/lib/mtproto/tl_utils.ts @@ -491,6 +491,10 @@ class TLDeserialization { this.debug = options.debug !== undefined ? options.debug : /* Modes.debug */false; } + /* public setMtproto(mtproto: boolean) { + this.mtproto = mtproto; + } */ + private readInt(field: string) { //if(this.offset >= this.intView.length * 4) { if((this.byteView.length - this.offset) < 4) {