mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 02:22:14 +00:00
feat: add ConnectionManager#getAll
This commit is contained in:
parent
afafd08943
commit
8f680e20e9
@ -229,6 +229,26 @@ class ConnectionManager extends EventEmitter {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all open connections with a peer.
|
||||
* @param {PeerId} peerId
|
||||
* @returns {Array<Connection>}
|
||||
*/
|
||||
getAll (peerId) {
|
||||
if (!PeerId.isPeerId(peerId)) {
|
||||
throw errcode(new Error('peerId must be an instance of peer-id'), ERR_INVALID_PARAMETERS)
|
||||
}
|
||||
|
||||
const id = peerId.toB58String()
|
||||
const connections = this.connections.get(id)
|
||||
|
||||
// Return all open connections
|
||||
if (connections) {
|
||||
return connections.filter(connection => connection.stat.status === 'open')
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
/**
|
||||
* If the event loop is slow, maybe close a connection
|
||||
* @private
|
||||
|
Loading…
x
Reference in New Issue
Block a user