mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-02 15:51:06 +00:00
feat: not remove peer from peerBook on disconnect
This commit is contained in:
parent
291e79fc99
commit
a4b41b0f9a
11
src/index.js
11
src/index.js
@ -48,8 +48,6 @@ class Node extends EventEmitter {
|
|||||||
|
|
||||||
this.swarm.on('peer-mux-closed', (peerInfo) => {
|
this.swarm.on('peer-mux-closed', (peerInfo) => {
|
||||||
this.emit('peer:disconnect', 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) {
|
dial (peer, protocol, callback) {
|
||||||
assert(this.isOn(), OFFLINE_ERROR_MESSAGE)
|
assert(this.isOn(), OFFLINE_ERROR_MESSAGE)
|
||||||
const peerInfo = this._getPeerInfo(peer)
|
|
||||||
|
|
||||||
if (typeof protocol === 'function') {
|
if (typeof protocol === 'function') {
|
||||||
callback = protocol
|
callback = protocol
|
||||||
protocol = undefined
|
protocol = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let peerInfo
|
||||||
|
try {
|
||||||
|
peerInfo = this._getPeerInfo(peer)
|
||||||
|
} catch (err) {
|
||||||
|
return callback(err)
|
||||||
|
}
|
||||||
|
|
||||||
this.swarm.dial(peerInfo, protocol, (err, conn) => {
|
this.swarm.dial(peerInfo, protocol, (err, conn) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
@ -183,7 +187,6 @@ class Node extends EventEmitter {
|
|||||||
assert(this.isOn(), OFFLINE_ERROR_MESSAGE)
|
assert(this.isOn(), OFFLINE_ERROR_MESSAGE)
|
||||||
const peerInfo = this._getPeerInfo(peer)
|
const peerInfo = this._getPeerInfo(peer)
|
||||||
|
|
||||||
this.peerBook.removeByB58String(peerInfo.id.toB58String())
|
|
||||||
this.swarm.hangUp(peerInfo, callback)
|
this.swarm.hangUp(peerInfo, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user