feat: not remove peer from peerBook on disconnect

This commit is contained in:
David Dias 2017-03-30 07:12:45 +01:00
parent 291e79fc99
commit a4b41b0f9a

View File

@ -48,8 +48,6 @@ class Node extends EventEmitter {
this.swarm.on('peer-mux-closed', (peerInfo) => {
this.emit('peer:disconnect', peerInfo)
// TODO remove this line
this.peerBook.removeByB58String(peerInfo.id.toB58String())
})
}
@ -163,13 +161,19 @@ class Node extends EventEmitter {
dial (peer, protocol, callback) {
assert(this.isOn(), OFFLINE_ERROR_MESSAGE)
const peerInfo = this._getPeerInfo(peer)
if (typeof protocol === 'function') {
callback = protocol
protocol = undefined
}
let peerInfo
try {
peerInfo = this._getPeerInfo(peer)
} catch (err) {
return callback(err)
}
this.swarm.dial(peerInfo, protocol, (err, conn) => {
if (err) {
return callback(err)
@ -183,7 +187,6 @@ class Node extends EventEmitter {
assert(this.isOn(), OFFLINE_ERROR_MESSAGE)
const peerInfo = this._getPeerInfo(peer)
this.peerBook.removeByB58String(peerInfo.id.toB58String())
this.swarm.hangUp(peerInfo, callback)
}