fix(core): networking fixes
This commit is contained in:
parent
7eaacc5343
commit
3068c07347
3 changed files with 25 additions and 7 deletions
|
@ -143,6 +143,7 @@ export class MultiSessionConnection {
|
||||||
})
|
})
|
||||||
|
|
||||||
this._connections.push(conn)
|
this._connections.push(conn)
|
||||||
|
if (this._authKey !== null) conn._session._authKey.setup(this._authKey)
|
||||||
// if enforcePfsChanged, we need to connect after setting the new auth key
|
// if enforcePfsChanged, we need to connect after setting the new auth key
|
||||||
if (connect && !enforcePfsChanged) conn.connect()
|
if (connect && !enforcePfsChanged) conn.connect()
|
||||||
}
|
}
|
||||||
|
@ -212,10 +213,16 @@ export class MultiSessionConnection {
|
||||||
this.connect()
|
this.connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
setAuthKey(authKey: Uint8Array | null, temp = false, idx = 0): void {
|
private _authKey: Uint8Array | null = null
|
||||||
const session = this._connections[idx]._session
|
setAuthKey(authKey: Uint8Array | null): void {
|
||||||
const key = temp ? session._authKeyTemp : session._authKey
|
this._authKey = authKey
|
||||||
key.setup(authKey)
|
for (const conn of this._connections) {
|
||||||
|
conn._session._authKey.setup(authKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setTempAuthKey(authKey: Uint8Array | null, idx: number): void {
|
||||||
|
this._connections[idx]?._session._authKeyTemp.setup(authKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
resetAuthKeys(): void {
|
resetAuthKeys(): void {
|
||||||
|
|
|
@ -314,7 +314,7 @@ export class DcConnectionManager {
|
||||||
const connection = this[kind]
|
const connection = this[kind]
|
||||||
|
|
||||||
connection.onKeyChange.add(([idx, key]) => {
|
connection.onKeyChange.add(([idx, key]) => {
|
||||||
if (kind !== 'main') {
|
if (kind !== 'main' && key !== null) {
|
||||||
// main connection is responsible for authorization,
|
// main connection is responsible for authorization,
|
||||||
// and keys are then sent to other connections
|
// and keys are then sent to other connections
|
||||||
this.manager._log.warn('got key-change from non-main connection, ignoring')
|
this.manager._log.warn('got key-change from non-main connection, ignoring')
|
||||||
|
@ -322,7 +322,7 @@ export class DcConnectionManager {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.manager._log.debug('key change for dc %d from connection %d', this.dcId, idx)
|
this.manager._log.debug('key change (empty=%b) for dc %d from connection %d', key === null, this.dcId, idx)
|
||||||
|
|
||||||
// send key to other connections
|
// send key to other connections
|
||||||
this.upload.setAuthKey(key)
|
this.upload.setAuthKey(key)
|
||||||
|
@ -433,7 +433,7 @@ export class DcConnectionManager {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Array.from({ length: this.main.getCount() }, async (_, i) => {
|
Array.from({ length: this.main.getCount() }, async (_, i) => {
|
||||||
const temp = await this.manager._storage.provider.authKeys.getTemp(this.dcId, i, now)
|
const temp = await this.manager._storage.provider.authKeys.getTemp(this.dcId, i, now)
|
||||||
this.main.setAuthKey(temp, true, i)
|
this.main.setTempAuthKey(temp, i)
|
||||||
|
|
||||||
// NB: we do not set temp auth keys for media connections,
|
// NB: we do not set temp auth keys for media connections,
|
||||||
// as they are ephemeral and dc-bound. doing this *will* lead to unwanted -404s
|
// as they are ephemeral and dc-bound. doing this *will* lead to unwanted -404s
|
||||||
|
|
|
@ -99,6 +99,8 @@ export class SessionConnection extends PersistentConnection {
|
||||||
readonly onUpdate: Emitter<tl.TypeUpdates> = new Emitter()
|
readonly onUpdate: Emitter<tl.TypeUpdates> = new Emitter()
|
||||||
readonly onFutureSalts: Emitter<mtp.RawMt_future_salt[]> = new Emitter()
|
readonly onFutureSalts: Emitter<mtp.RawMt_future_salt[]> = new Emitter()
|
||||||
|
|
||||||
|
private _triedReconnectingOn404 = false
|
||||||
|
|
||||||
constructor(params: SessionConnectionParams, log: Logger) {
|
constructor(params: SessionConnectionParams, log: Logger) {
|
||||||
super(params, log.create('conn'))
|
super(params, log.create('conn'))
|
||||||
this._session = new MtprotoSession(
|
this._session = new MtprotoSession(
|
||||||
|
@ -263,6 +265,14 @@ export class SessionConnection extends PersistentConnection {
|
||||||
// otherwise, 404 must be referencing the perm_key
|
// otherwise, 404 must be referencing the perm_key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this._triedReconnectingOn404) {
|
||||||
|
// maybe this is some mtproto issue? let's try reconnecting and hope for the best
|
||||||
|
this.log.warn('transport error 404. trying to reconnect')
|
||||||
|
this._triedReconnectingOn404 = true
|
||||||
|
this._resetSession()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// there happened a little trolling
|
// there happened a little trolling
|
||||||
this.log.warn('transport error 404, reauthorizing')
|
this.log.warn('transport error 404, reauthorizing')
|
||||||
this._session.resetAuthKey()
|
this._session.resetAuthKey()
|
||||||
|
@ -1176,6 +1186,7 @@ export class SessionConnection extends PersistentConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._salts.currentSalt = serverSalt
|
this._salts.currentSalt = serverSalt
|
||||||
|
this._triedReconnectingOn404 = false
|
||||||
|
|
||||||
this.log.debug('received new_session_created, uid = %l, first msg_id = %l', uniqueId, firstMsgId)
|
this.log.debug('received new_session_created, uid = %l, first msg_id = %l', uniqueId, firstMsgId)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue