mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-28 16:31:35 +00:00
chore: rename address functions and apply suggestions from code review
Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
32
doc/API.md
32
doc/API.md
@ -11,10 +11,10 @@
|
||||
* [`handle`](#handle)
|
||||
* [`unhandle`](#unhandle)
|
||||
* [`ping`](#ping)
|
||||
* [`getAdvertisingMultiaddrs`](#getadvertisingmultiaddrs)
|
||||
* [`addressManager.getListenMultiaddrs`](#addressmanagergetlistenmultiaddrs)
|
||||
* [`addressmger.getAnnounceMultiaddrs`](#addressmanagergetannouncemultiaddrs)
|
||||
* [`addressManager.getNoAnnounceMultiaddrs`](#addressmanagergetnoannouncemultiaddrs)
|
||||
* [`multiaddrs`](#multiaddrs)
|
||||
* [`addressManager.getListenAddrs`](#addressmanagergetlistenaddrs)
|
||||
* [`addressmger.getAnnounceAddrs`](#addressmanagergetannounceaddrs)
|
||||
* [`addressManager.getNoAnnounceAddrs`](#addressmanagergetnoannounceaddrs)
|
||||
* [`contentRouting.findProviders`](#contentroutingfindproviders)
|
||||
* [`contentRouting.provide`](#contentroutingprovide)
|
||||
* [`contentRouting.put`](#contentroutingput)
|
||||
@ -364,14 +364,14 @@ Pings a given peer and get the operation's latency.
|
||||
const latency = await libp2p.ping(otherPeerId)
|
||||
```
|
||||
|
||||
## getAdvertisingMultiaddrs
|
||||
## multiaddrs
|
||||
|
||||
Get peer advertising multiaddrs. This computes the advertising multiaddrs of the peer by
|
||||
joining the multiaddrs that libp2p transports are listening on with the announce multiaddrs
|
||||
provided in hte libp2p config. No announce multiaddrs will be filtered out, even when
|
||||
using random ports in the provided multiaddrs.
|
||||
|
||||
`libp2p.getAdvertisingMultiaddrs()`
|
||||
`libp2p.multiaddrs`
|
||||
|
||||
#### Returns
|
||||
|
||||
@ -383,15 +383,15 @@ using random ports in the provided multiaddrs.
|
||||
|
||||
```js
|
||||
// ...
|
||||
const listenMa = libp2p.getAdvertisingMultiaddrs()
|
||||
const listenMa = libp2p.multiaddrs
|
||||
// [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
|
||||
```
|
||||
|
||||
### addressManager.getListenMultiaddrs
|
||||
### addressManager.getListenAddrs
|
||||
|
||||
Get the multiaddrs that were provided for listening on libp2p transports.
|
||||
|
||||
`libp2p.addressManager.getListenMultiaddrs()`
|
||||
`libp2p.addressManager.getListenAddrs()`
|
||||
|
||||
#### Returns
|
||||
|
||||
@ -403,15 +403,15 @@ Get the multiaddrs that were provided for listening on libp2p transports.
|
||||
|
||||
```js
|
||||
// ...
|
||||
const listenMa = libp2p.addressManager.getListenMultiaddrs()
|
||||
const listenMa = libp2p.addressManager.getListenAddrs()
|
||||
// [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
|
||||
```
|
||||
|
||||
### addressManager.getAnnounceMultiaddrs
|
||||
### addressManager.getAnnounceAddrs
|
||||
|
||||
Get the multiaddrs that were provided to announce to the network.
|
||||
|
||||
`libp2p.addressManager.getAnnounceMultiaddrs()`
|
||||
`libp2p.addressManager.getAnnounceAddrs()`
|
||||
|
||||
#### Returns
|
||||
|
||||
@ -423,15 +423,15 @@ Get the multiaddrs that were provided to announce to the network.
|
||||
|
||||
```js
|
||||
// ...
|
||||
const announceMa = libp2p.addressManager.getAnnounceMultiaddrs()
|
||||
const announceMa = libp2p.addressManager.getAnnounceAddrs()
|
||||
// [ <Multiaddr 047f00000106f9ba - /dns4/peer.io/...> ]
|
||||
```
|
||||
|
||||
### addressManager.getNoAnnounceMultiaddrs
|
||||
### addressManager.getNoAnnounceAddrs
|
||||
|
||||
Get the multiaddrs that were provided to not announce to the network.
|
||||
|
||||
`libp2p.addressManager.getNoAnnounceMultiaddrs()`
|
||||
`libp2p.addressManager.getNoAnnounceAddrs()`
|
||||
|
||||
#### Returns
|
||||
|
||||
@ -443,7 +443,7 @@ Get the multiaddrs that were provided to not announce to the network.
|
||||
|
||||
```js
|
||||
// ...
|
||||
const noAnnounceMa = libp2p.addressManager.getNoAnnounceMultiaddrs()
|
||||
const noAnnounceMa = libp2p.addressManager.getNoAnnounceAddrs()
|
||||
// [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
|
||||
```
|
||||
|
||||
|
@ -204,7 +204,7 @@ Moreover, the majority of the modules can be customized via option parameters. T
|
||||
Besides the `modules` and `config`, libp2p allows other internal options and configurations:
|
||||
- `datastore`: an instance of [ipfs/interface-datastore](https://github.com/ipfs/interface-datastore/) modules.
|
||||
- This is used in modules such as the DHT. If it is not provided, `js-libp2p` will use an in memory datastore.
|
||||
- `peerId`: a previously computed instance of [libp2p/js-peer-id](https://github.com/libp2p/js-peer-id).
|
||||
- `peerId`: the identity of the node, an instance of [libp2p/js-peer-id](https://github.com/libp2p/js-peer-id).
|
||||
- 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.
|
||||
- `addresses`: an object containing `listen`, `announce` and `noAnnounce` properties with `Array<string>`:
|
||||
- `listen` addresses will be provided to the libp2p underlying transports for listening on them.
|
||||
@ -215,8 +215,6 @@ Besides the `modules` and `config`, libp2p allows other internal options and con
|
||||
|
||||
#### Basic setup
|
||||
|
||||
TODO: should we add to the basic setup the configuration of listen addresses? we should probably make it a required option?
|
||||
|
||||
```js
|
||||
// Creating a libp2p node with:
|
||||
// transport: websockets + tcp
|
||||
|
@ -136,8 +136,6 @@ If you want to know more about libp2p stream multiplexing, you should read the f
|
||||
|
||||
Now that you have configured a [**Transport**][transport], [**Crypto**][crypto] and [**Stream Multiplexer**](streamMuxer) module, you can start your libp2p node. We can start and stop libp2p using the [`libp2p.start()`](./API.md#start) and [`libp2p.stop()`](./API.md#stop) methods.
|
||||
|
||||
TODO: add listen addresses here?
|
||||
|
||||
```js
|
||||
const Libp2p = require('libp2p')
|
||||
const WebSockets = require('libp2p-websockets')
|
||||
@ -145,6 +143,9 @@ const SECIO = require('libp2p-secio')
|
||||
const MPLEX = require('libp2p-mplex')
|
||||
|
||||
const node = await Libp2p.create({
|
||||
addresses: {
|
||||
listen: ['/ip4/127.0.0.1/tcp/8000/ws']
|
||||
},
|
||||
modules: {
|
||||
transport: [WebSockets],
|
||||
connEncryption: [SECIO],
|
||||
@ -156,6 +157,12 @@ const node = await Libp2p.create({
|
||||
await node.start()
|
||||
console.log('libp2p has started')
|
||||
|
||||
const listenAddrs = node.transportManager.getAddrs()
|
||||
console.log('libp2p is listening on the following addresses: ', listenAddrs)
|
||||
|
||||
const advertiseAddrs = node.multiaddrs
|
||||
console.log('libp2p is advertising the following addresses: ', advertiseAddrs)
|
||||
|
||||
// stop libp2p
|
||||
await node.stop()
|
||||
console.log('libp2p has stopped')
|
||||
|
Reference in New Issue
Block a user