refactor: ping (#505)

* refactor: ping

* chore: ping is now a function

* chore: address review
This commit is contained in:
Vasco Santos
2019-12-10 19:26:54 +01:00
committed by Jacob Heun
parent 7fc1900343
commit 64cbf90e02
10 changed files with 142 additions and 174 deletions

View File

@@ -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.