mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-26 19:12:15 +00:00
fix: add null check in libp2p.hangUp()
test: add hangup test and fix linting
This commit is contained in:
parent
2620d46f01
commit
c940f2d384
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
|
* @param {PeerInfo|PeerId|multiaddr|string} peer the peer to close connections to
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
hangUp (peer) {
|
async hangUp (peer) {
|
||||||
const peerInfo = getPeerInfo(peer, this.peerStore)
|
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()
|
return connection.close()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -371,6 +371,19 @@ describe('Dialing (direct, WebSockets)', () => {
|
|||||||
expect(connection.stat.timeline.close).to.exist()
|
expect(connection.stat.timeline.close).to.exist()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should be able to use hangup when no connection exists', async () => {
|
||||||
|
libp2p = new Libp2p({
|
||||||
|
peerInfo,
|
||||||
|
modules: {
|
||||||
|
transport: [Transport],
|
||||||
|
streamMuxer: [Muxer],
|
||||||
|
connEncryption: [Crypto]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
await libp2p.hangUp(remoteAddr)
|
||||||
|
})
|
||||||
|
|
||||||
it('should abort pending dials on stop', async () => {
|
it('should abort pending dials on stop', async () => {
|
||||||
libp2p = new Libp2p({
|
libp2p = new Libp2p({
|
||||||
peerInfo,
|
peerInfo,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user