Skip to content

Commit

Permalink
Exchange nitro info with already connected peers
Browse files Browse the repository at this point in the history
  • Loading branch information
nikugogoi committed Jul 13, 2023
1 parent aa107f0 commit 4943259
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export class P2PMessageService implements MessageService {
});
});

await ms.exchangeInfoWithConnectedPeers();

return ms;
}

Expand All @@ -154,6 +156,17 @@ export class P2PMessageService implements MessageService {
return PeerIdFactory.createFromPrivKey(this.key);
}

// Method to exchange info with already connected peers
private async exchangeInfoWithConnectedPeers() {
const peerIds = this.p2pHost.getPeers();

await Promise.all(peerIds.map(async (peerId: PeerId) => {
const connection: Connection = await this.p2pHost.dial(peerId);

await this.handlePeerConnect({ detail: connection } as CustomEvent<Connection>);
}));
}

private async handleChangeProtocols({ detail: data }: CustomEvent<PeerProtocolsChangeData>) {
// Ignore self protocol changes
if (data.peerId.equals(this.p2pHost.peerId)) {
Expand Down

0 comments on commit 4943259

Please sign in to comment.