Skip to content

Commit

Permalink
Move peer:discovery event emission to PeerBook
Browse files Browse the repository at this point in the history
  • Loading branch information
JustMaier committed May 31, 2019
1 parent b06ca1b commit 7f6eec9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"mafmt": "^6.0.7",
"multiaddr": "^6.0.6",
"once": "^1.4.0",
"peer-book": "~0.9.1",
"peer-book": "justmaier/js-peer-book",
"peer-id": "~0.12.2",
"peer-info": "~0.15.1",
"superstruct": "~0.6.0"
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Node extends EventEmitter {
this.datastore = this._options.datastore
this.peerInfo = this._options.peerInfo
this.peerBook = this._options.peerBook || new PeerBook()
this.peerBook.on('peer:discovery', (peerInfo) => this.emit('peer:discovery', peerInfo))

this._modules = this._options.modules
this._config = this._options.config
Expand Down Expand Up @@ -177,6 +178,7 @@ class Node extends EventEmitter {

// Once we start, emit and dial any peers we may have already discovered
this.state.on('STARTED', () => {
// TODO Consider moving this process into the new autonomous PeerBook
this.peerBook.getAllArray().forEach((peerInfo) => {
this.emit('peer:discovery', peerInfo)
this._maybeConnect(peerInfo)
Expand Down Expand Up @@ -463,8 +465,7 @@ class Node extends EventEmitter {
}

/**
* Handles discovered peers. Each discovered peer will be emitted via
* the `peer:discovery` event. If auto dial is enabled for libp2p
* Handles discovered peers. If auto dial is enabled for libp2p
* and the current connection count is under the low watermark, the
* peer will be dialed.
*
Expand All @@ -485,7 +486,6 @@ class Node extends EventEmitter {

if (!this.isStarted()) return

this.emit('peer:discovery', peerInfo)
this._maybeConnect(peerInfo)
}

Expand Down

0 comments on commit 7f6eec9

Please sign in to comment.