Skip to content

Commit

Permalink
Removed async from listeners as per Greg's review
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikerah committed May 1, 2019
1 parent fc240b7 commit 6461d4d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/p2p/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,15 @@ export class P2PNetwork extends EventEmitter implements Service {
bootnodes: this.options.bootnodes
});

// TODO: Add protocol handling for RPC over Libp2p

this.node.on('peer:discovery', async (peerInfo) => {
this.node.on('peer:discovery', (peerInfo) => {
try {
const peerId = peerInfo.id.toB58String();
// Check if peer has already been discovered
if (this.options.peerBook.has(peerId) || this.discoveredPeers.has(peerId)) {
return;
}
this.peerBook.put(peerInfo);
this.node.dial(peerInfo, () => {
});
this.node.dial(peerInfo, () => {});
this.log.info(`Peer discovered: ${peerInfo}`);
this.emit('connected', peerInfo);
} catch (err) {
Expand All @@ -92,7 +89,7 @@ export class P2PNetwork extends EventEmitter implements Service {

});

this.node.on('peer:connect', async (peerInfo) => {
this.node.on('peer:connect', (peerInfo) => {
try {
this.log.info(`Peer connected: ${peerInfo}`);
this.peerBook.put(peerInfo);
Expand All @@ -102,7 +99,7 @@ export class P2PNetwork extends EventEmitter implements Service {
}
});

this.node.on('peer:disconnect', async (peerInfo) => {
this.node.on('peer:disconnect', (peerInfo) => {
try {
this.peerBook.remove(peerInfo);
this.discoveredPeers.delete(peerInfo);
Expand Down

0 comments on commit 6461d4d

Please sign in to comment.