fix: add null check in libp2p.hangUp()

test: add hangup test and fix linting
This commit is contained in:
robertkiel
2020-04-15 09:52:58 +02:00
committed by Jacob Heun
parent 2620d46f01
commit c940f2d384
2 changed files with 23 additions and 3 deletions

View File

@ -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()
})
)