mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-23 14:01:35 +00:00
fix: add null check in libp2p.hangUp()
test: add hangup test and fix linting
This commit is contained in:
13
src/index.js
13
src/index.js
@ -311,10 +311,17 @@ class Libp2p extends EventEmitter {
|
||||
* @param {PeerInfo|PeerId|multiaddr|string} peer the peer to close connections to
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
hangUp (peer) {
|
||||
async hangUp (peer) {
|
||||
const peerInfo = getPeerInfo(peer, this.peerStore)
|
||||
return Promise.all(
|
||||
this.registrar.connections.get(peerInfo.id.toB58String()).map(connection => {
|
||||
|
||||
const connections = this.registrar.connections.get(peerInfo.id.toB58String())
|
||||
|
||||
if (!connections) {
|
||||
return
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
connections.map(connection => {
|
||||
return connection.close()
|
||||
})
|
||||
)
|
||||
|
Reference in New Issue
Block a user