Skip to content

Commit

Permalink
fix: last touches
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Mar 27, 2017
1 parent a6623c1 commit 2c23d9a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"libp2p-swarm": "~0.26.19",
"multiaddr": "^2.2.3",
"peer-book": "~0.3.1",
"peer-id": "~0.8.4",
"peer-info": "~0.8.4"
"peer-id": "~0.8.5",
"peer-info": "~0.8.5"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
Expand Down
45 changes: 22 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class Node extends EventEmitter {
if (err) {
return callback(err)
}
this.peerBook.put(peer)
this.peerBook.put(peerInfo)
callback(null, conn)
})
}
Expand All @@ -170,7 +170,7 @@ class Node extends EventEmitter {
const peerInfo = this._getPeerInfo(peer)

this.peerBook.removeByB58String(peerInfo.id.toB58String())
this.swarm.hangUp(peer, callback)
this.swarm.hangUp(peerInfo, callback)
}

handle (protocol, handlerFunc, matchFunc) {
Expand All @@ -186,27 +186,26 @@ class Node extends EventEmitter {
*/
_getPeerInfo (peer) {
let p
switch (peer) {
case PeerInfo.isPeerInfo(peer): p = peer; break
case multiaddr.isMultiaddr(peer): {
const peerIdB58Str = multiaddr.getPeerId(peer)
try {
p = this.peerBook.getByB58String(peerIdB58Str)
} catch (err) {
p = new PeerInfo(PeerId.createFromB58String(peerIdB58Str))
}
p.multiaddr.add(peer)
} break
case PeerId.isPeerId(peer): {
const peerIdB58Str = peer.toB58String()
try {
p = this.peerBook.getByB58String(peerIdB58Str)
} catch (err) {
// TODO this is where PeerRouting comes into place
throw new Error('No knowledge about: ' + peerIdB58Str)
}
} break
default: throw new Error('Peer type not recognized')
if (PeerInfo.isPeerInfo(peer)) {
p = peer
} else if (multiaddr.isMultiaddr(peer)) {
const peerIdB58Str = peer.getPeerId()
try {
p = this.peerBook.getByB58String(peerIdB58Str)
} catch (err) {
p = new PeerInfo(PeerId.createFromB58String(peerIdB58Str))
}
p.multiaddr.add(peer)
} else if (PeerId.isPeerId(peer)) {
const peerIdB58Str = peer.toB58String()
try {
p = this.peerBook.getByB58String(peerIdB58Str)
} catch (err) {
// TODO this is where PeerRouting comes into place
throw new Error('No knowledge about: ' + peerIdB58Str)
}
} else {
throw new Error('peer type not recognized')
}

return p
Expand Down

0 comments on commit 2c23d9a

Please sign in to comment.