mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-31 00:12:00 +00:00
refactor: ping (#505)
* refactor: ping * chore: ping is now a function * chore: address review
This commit is contained in:
26
doc/API.md
26
doc/API.md
@@ -10,6 +10,7 @@
|
||||
* [`hangUp`](#hangUp)
|
||||
* [`handle`](#handle)
|
||||
* [`unhandle`](#unhandle)
|
||||
* [`ping`](#ping)
|
||||
* [`peerRouting.findPeer`](#peerRouting.findPeer)
|
||||
* [`contentRouting.findProviders`](#contentRouting.findProviders)
|
||||
* [`contentRouting.provide`](#contentRouting.provide)
|
||||
@@ -307,6 +308,31 @@ Unregisters all handlers with the given protocols
|
||||
libp2p.unhandle(['/echo/1.0.0'])
|
||||
```
|
||||
|
||||
### ping
|
||||
|
||||
Pings a given peer and get the operation's latency.
|
||||
|
||||
`libp2p.ping(peer)`
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|------|------|-------------|
|
||||
| peer | `PeerInfo|PeerId|Multiaddr|string` | peer to ping |
|
||||
|
||||
#### Returns
|
||||
|
||||
| Type | Description |
|
||||
|------|-------------|
|
||||
| `Promise<number>` | Latency of the operation in ms |
|
||||
|
||||
#### Example
|
||||
|
||||
```js
|
||||
// ...
|
||||
const latency = await libp2p.ping(otherPeerId)
|
||||
```
|
||||
|
||||
### peerRouting.findPeer
|
||||
|
||||
Iterates over all peer routers in series to find the given peer. If the DHT is enabled, it will be tried first.
|
||||
|
Reference in New Issue
Block a user