feat: address manager

This commit is contained in:
Vasco Santos
2020-04-18 23:26:46 +02:00
committed by Jacob Heun
parent 9e9ec0b575
commit 2a7967c1cc
24 changed files with 598 additions and 126 deletions

View File

@ -11,6 +11,9 @@
* [`handle`](#handle)
* [`unhandle`](#unhandle)
* [`ping`](#ping)
* [`addressManager.listen`](#addressManagerlisten)
* [`addressManager.announce`](#addressManagerannounce)
* [`addressManager.noAnnounce`](#addressManagernoannounce)
* [`contentRouting.findProviders`](#contentroutingfindproviders)
* [`contentRouting.provide`](#contentroutingprovide)
* [`contentRouting.put`](#contentroutingput)
@ -360,31 +363,42 @@ Pings a given peer and get the operation's latency.
const latency = await libp2p.ping(otherPeerId)
```
### peerRouting.findPeer
### addressManager.listen
Iterates over all peer routers in series to find the given peer. If the DHT is enabled, it will be tried first.
Getter for getting the addresses that the peer is using for listening on libp2p transports.
`libp2p.peerRouting.findPeer(peerId, options)`
#### Parameters
| Name | Type | Description |
|------|------|-------------|
| peerId | [`PeerId`][peer-id] | ID of the peer to find |
| options | `object` | operation options |
| options.timeout | `number` | maximum time the query should run |
#### Returns
| Type | Description |
|------|-------------|
| `Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>` | Peer data of a known peer |
`libp2p.addressManager.listen`
#### Example
```js
// ...
const peer = await libp2p.peerRouting.findPeer(peerId, options)
const listenAddresses = libp2p.addressManager.listen
// [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
```
### addressManager.announce
Getter for getting the addresses that the peer is announcing to other peers in the network.
`libp2p.addressManager.announce`
```js
// ...
const announceAddresses = libp2p.addressManager.announce
// [ <Multiaddr 047f00000106f9ba - /dns4/peer.io/...> ]
```
### addressManager.noAnnounce
Getter for getting the addresses that the peer is not announcing in the network.
`libp2p.addressManager.noAnnounce`
```js
// ...
const noAnnounceAddresses = libp2p.addressManager.noAnnounce
// [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
```
### contentRouting.findProviders
@ -533,6 +547,33 @@ const key = '/key'
const { from, val } = await libp2p.contentRouting.get(key)
```
### peerRouting.findPeer
Iterates over all peer routers in series to find the given peer. If the DHT is enabled, it will be tried first.
`libp2p.peerRouting.findPeer(peerId, options)`
#### Parameters
| Name | Type | Description |
|------|------|-------------|
| peerId | [`PeerId`][peer-id] | ID of the peer to find |
| options | `object` | operation options |
| options.timeout | `number` | maximum time the query should run |
#### Returns
| Type | Description |
|------|-------------|
| `Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>` | Peer data of a known peer |
#### Example
```js
// ...
const peer = await libp2p.peerRouting.findPeer(peerId, options)
```
### peerStore.addressBook.add
Adds known `multiaddrs` of a given peer. If the peer is not known, it will be set with the provided multiaddrs.

View File

@ -207,6 +207,8 @@ Besides the `modules` and `config`, libp2p allows other internal options and con
- `peerInfo`: a previously created instance of [libp2p/js-peer-info](https://github.com/libp2p/js-peer-info).
- This is particularly useful if you want to reuse the same `peer-id`, as well as for modules like `libp2p-delegated-content-routing`, which need a `peer-id` in their instantiation.
TODO: Add listen/announce addresses and remove peerInfo!!
### Examples
#### Basic setup