fix: emit peer:connect after all (#1171)

**Motivation**

In lodestar, when we handle "peer:connect" event, we dial the peer which gives another "peer:connect" event and it causes other issues

**Motivation**

In `onConnect` function, "peer:connect" event should be emitted after we add connection to the `connections` map so that when app dial the peer in "peer:connect" event handler, it uses the same/existing connection
This commit is contained in:
tuyennhv
2022-04-23 02:56:47 +07:00
committed by GitHub
parent fab4f1385c
commit d16817ca44
5 changed files with 17 additions and 12 deletions

View File

@@ -267,8 +267,6 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
const peerIdStr = peerId.toString()
const storedConns = this.connections.get(peerIdStr)
this.dispatchEvent(new CustomEvent<Connection>('peer:connect', { detail: connection }))
if (storedConns != null) {
storedConns.push(connection)
} else {
@@ -284,6 +282,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
}
await this._checkMaxLimit('maxConnections', this.getConnectionList().length)
this.dispatchEvent(new CustomEvent<Connection>('peer:connect', { detail: connection }))
}
/**