mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-13 17:21:21 +00:00
refactor: ping (#505)
* refactor: ping * chore: ping is now a function * chore: address review
This commit is contained in:
27
src/index.js
27
src/index.js
@ -21,6 +21,7 @@ const TransportManager = require('./transport-manager')
|
||||
const Upgrader = require('./upgrader')
|
||||
const PeerStore = require('./peer-store')
|
||||
const Registrar = require('./registrar')
|
||||
const ping = require('./ping')
|
||||
const {
|
||||
IdentifyService,
|
||||
multicodecs: IDENTIFY_PROTOCOLS
|
||||
@ -148,6 +149,9 @@ class Libp2p extends EventEmitter {
|
||||
this.peerRouting = peerRouting(this)
|
||||
this.contentRouting = contentRouting(this)
|
||||
|
||||
// Mount default protocols
|
||||
ping.mount(this)
|
||||
|
||||
this._onDiscoveryPeer = this._onDiscoveryPeer.bind(this)
|
||||
}
|
||||
|
||||
@ -203,6 +207,8 @@ class Libp2p extends EventEmitter {
|
||||
|
||||
await this.transportManager.close()
|
||||
await this.registrar.close()
|
||||
|
||||
ping.unmount(this)
|
||||
} catch (err) {
|
||||
if (err) {
|
||||
log.error(err)
|
||||
@ -280,17 +286,16 @@ class Libp2p extends EventEmitter {
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: Update ping
|
||||
// /**
|
||||
// * Pings the provided peer
|
||||
// *
|
||||
// * @param {PeerInfo|PeerId|Multiaddr|string} peer The peer to ping
|
||||
// * @returns {Promise<Ping>}
|
||||
// */
|
||||
// ping (peer) {
|
||||
// const peerInfo = await getPeerInfoRemote(peer, this)
|
||||
// return new Ping(this._switch, peerInfo)
|
||||
// }
|
||||
/**
|
||||
* Pings the given peer
|
||||
* @param {PeerInfo|PeerId|Multiaddr|string} peer The peer to ping
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
async ping (peer) {
|
||||
const peerInfo = await getPeerInfo(peer, this.peerStore)
|
||||
|
||||
return ping(this, peerInfo)
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the `handler` for each protocol
|
||||
|
Reference in New Issue
Block a user