mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-16 17:11:57 +00:00
Compare commits
109 Commits
refactor/a
...
v0.27.2
Author | SHA1 | Date | |
---|---|---|---|
|
8bed8f39ff | ||
|
58c0c7c03e | ||
|
f662fdcf36 | ||
|
5608178247 | ||
|
dcd58693f5 | ||
|
8bf05e6db6 | ||
|
0589d53616 | ||
|
eb2528c1d6 | ||
|
141cf90ca0 | ||
|
f4ec459a7b | ||
|
56a7842664 | ||
|
be8fc9daf1 | ||
|
f39e8f0da9 | ||
|
ed0c2cb6c1 | ||
|
c6592c5797 | ||
|
33cef10721 | ||
|
2d6408eb30 | ||
|
29a96690ad | ||
|
8b94cd1e2e | ||
|
b83880765f | ||
|
560d7084fe | ||
|
d21b7ce4ff | ||
|
c1038bec92 | ||
|
bb2e56e6c7 | ||
|
4222c49556 | ||
|
2f2ba420ef | ||
|
e9d16ba190 | ||
|
afb552c063 | ||
|
721151b9fc | ||
|
efc96c2f19 | ||
|
ba4681b312 | ||
|
6b00eeab0a | ||
|
c339be10ee | ||
|
7b326cc525 | ||
|
835a689965 | ||
|
b08d81cee7 | ||
|
6445fda050 | ||
|
4ca481b869 | ||
|
5d7ee50e76 | ||
|
48fd64182b | ||
|
58db09a9d3 | ||
|
15f7c2a974 | ||
|
4384d139d2 | ||
|
bd1068e5d9 | ||
|
854ac49a10 | ||
|
f9d0047bf6 | ||
|
ae5ce9a66f | ||
|
14a1955a78 | ||
|
f1eb373235 | ||
|
dabee00127 | ||
|
17b6a3fd73 | ||
|
4f7586886c | ||
|
71f46bf4a6 | ||
|
cba035a75b | ||
|
2c5183bd70 | ||
|
a586efb5f7 | ||
|
1db69c5f27 | ||
|
9e1a9f04ae | ||
|
287f1b98e5 | ||
|
90ecc57dbc | ||
|
ae52d483fc | ||
|
2570a1ba30 | ||
|
633b0c291f | ||
|
7d505494be | ||
|
1df52ae205 | ||
|
ba02764c5f | ||
|
404fa69513 | ||
|
85988cfaab | ||
|
def3574ba0 | ||
|
6b1da8326f | ||
|
a12006a4fa | ||
|
466b4dfd70 | ||
|
98e82df5e1 | ||
|
6ad840c3f3 | ||
|
7ac5e42a1a | ||
|
b86ef64904 | ||
|
b6cd48b798 | ||
|
a5b54a7017 | ||
|
e1e3be8106 | ||
|
b7432bd02b | ||
|
7c2fefda46 | ||
|
2788982c53 | ||
|
76ec1ccd21 | ||
|
e445a17278 | ||
|
2329ef3ea3 | ||
|
ce8e60bb0d | ||
|
12fc069873 | ||
|
9a6e07d70b | ||
|
8da9fc97d4 | ||
|
a020db183a | ||
|
f77ce39484 | ||
|
18a062ed12 | ||
|
1999606ecc | ||
|
472e14f2b4 | ||
|
953d185c39 | ||
|
c563e06a60 | ||
|
f28b09fc0d | ||
|
2104578924 | ||
|
bcad60995e | ||
|
432b0997ae | ||
|
2afdbb71b2 | ||
|
c7a54f34f7 | ||
|
9d52b80c45 | ||
|
582094a834 | ||
|
fe2a8eddbb | ||
|
5e1dbc21a2 | ||
|
b37ccc7279 | ||
|
440fbf0c04 | ||
|
0cef51d4c2 |
@@ -39,5 +39,12 @@ jobs:
|
|||||||
script:
|
script:
|
||||||
- npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless
|
- npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless
|
||||||
|
|
||||||
|
- stage: test
|
||||||
|
name: interop
|
||||||
|
script:
|
||||||
|
- cd node_modules/interop-libp2p
|
||||||
|
- npm install
|
||||||
|
- LIBP2P_JS=${TRAVIS_BUILD_DIR}/src/index.js npx aegir test -t node --bail
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
58
CHANGELOG.md
58
CHANGELOG.md
@@ -1,3 +1,61 @@
|
|||||||
|
<a name="0.27.2"></a>
|
||||||
|
## [0.27.2](https://github.com/libp2p/js-libp2p/compare/v0.27.1...v0.27.2) (2020-02-05)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* ensure identify streams are closed ([#551](https://github.com/libp2p/js-libp2p/issues/551)) ([f662fdc](https://github.com/libp2p/js-libp2p/commit/f662fdc))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.27.1"></a>
|
||||||
|
## [0.27.1](https://github.com/libp2p/js-libp2p/compare/v0.27.0...v0.27.1) (2020-02-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* stop stream after first pong received ([#545](https://github.com/libp2p/js-libp2p/issues/545)) ([be8fc9d](https://github.com/libp2p/js-libp2p/commit/be8fc9d))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.27.0"></a>
|
||||||
|
# [0.27.0](https://github.com/libp2p/js-libp2p/compare/v0.26.2...v0.27.0) (2020-01-28)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* clean up peer discovery flow ([#494](https://github.com/libp2p/js-libp2p/issues/494)) ([12fc069](https://github.com/libp2p/js-libp2p/commit/12fc069))
|
||||||
|
* clean up pending dials abort per feedback ([633b0c2](https://github.com/libp2p/js-libp2p/commit/633b0c2))
|
||||||
|
* conn mngr min/max connection values ([#528](https://github.com/libp2p/js-libp2p/issues/528)) ([ba4681b](https://github.com/libp2p/js-libp2p/commit/ba4681b))
|
||||||
|
* correct release readme ([ce8e60b](https://github.com/libp2p/js-libp2p/commit/ce8e60b))
|
||||||
|
* examples readme typos ([#481](https://github.com/libp2p/js-libp2p/issues/481)) ([35ac02d](https://github.com/libp2p/js-libp2p/commit/35ac02d))
|
||||||
|
* make dialer configurable ([#521](https://github.com/libp2p/js-libp2p/issues/521)) ([4ca481b](https://github.com/libp2p/js-libp2p/commit/4ca481b))
|
||||||
|
* performance bottleneck in stat.js ([#463](https://github.com/libp2p/js-libp2p/issues/463)) ([93a1e42](https://github.com/libp2p/js-libp2p/commit/93a1e42))
|
||||||
|
* registrar should filter the disconnected conn ([#532](https://github.com/libp2p/js-libp2p/issues/532)) ([bb2e56e](https://github.com/libp2p/js-libp2p/commit/bb2e56e))
|
||||||
|
* release tokens as soon as they are available ([2570a1b](https://github.com/libp2p/js-libp2p/commit/2570a1b))
|
||||||
|
* replace peerInfo addresses with listen addresses ([#485](https://github.com/libp2p/js-libp2p/issues/485)) ([1999606](https://github.com/libp2p/js-libp2p/commit/1999606))
|
||||||
|
* stop discoveries ([#530](https://github.com/libp2p/js-libp2p/issues/530)) ([4222c49](https://github.com/libp2p/js-libp2p/commit/4222c49))
|
||||||
|
* token release logic ([90ecc57](https://github.com/libp2p/js-libp2p/commit/90ecc57))
|
||||||
|
* upgrader should not need muxers ([#517](https://github.com/libp2p/js-libp2p/issues/517)) ([5d7ee50](https://github.com/libp2p/js-libp2p/commit/5d7ee50))
|
||||||
|
* use toB58String everywhere to be consistent ([#537](https://github.com/libp2p/js-libp2p/issues/537)) ([c1038be](https://github.com/libp2p/js-libp2p/commit/c1038be))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* abort all pending dials on stop ([ba02764](https://github.com/libp2p/js-libp2p/commit/ba02764))
|
||||||
|
* add early token recycling in ([a5b54a7](https://github.com/libp2p/js-libp2p/commit/a5b54a7))
|
||||||
|
* add libp2p.connections getter ([#522](https://github.com/libp2p/js-libp2p/issues/522)) ([6445fda](https://github.com/libp2p/js-libp2p/commit/6445fda))
|
||||||
|
* add token based dialer ([e445a17](https://github.com/libp2p/js-libp2p/commit/e445a17))
|
||||||
|
* allow transport options to be passed on creation ([#524](https://github.com/libp2p/js-libp2p/issues/524)) ([c339be1](https://github.com/libp2p/js-libp2p/commit/c339be1))
|
||||||
|
* coalescing dial support ([#518](https://github.com/libp2p/js-libp2p/issues/518)) ([15f7c2a](https://github.com/libp2p/js-libp2p/commit/15f7c2a))
|
||||||
|
* discovery modules ([#486](https://github.com/libp2p/js-libp2p/issues/486)) ([18a062e](https://github.com/libp2p/js-libp2p/commit/18a062e))
|
||||||
|
* discovery modules from transports should be added ([#510](https://github.com/libp2p/js-libp2p/issues/510)) ([f1eb373](https://github.com/libp2p/js-libp2p/commit/f1eb373))
|
||||||
|
* peer store ([#470](https://github.com/libp2p/js-libp2p/issues/470)) ([582094a](https://github.com/libp2p/js-libp2p/commit/582094a))
|
||||||
|
* registrar ([#471](https://github.com/libp2p/js-libp2p/issues/471)) ([9d52b80](https://github.com/libp2p/js-libp2p/commit/9d52b80))
|
||||||
|
* support peer-id instances in peer store operations ([#491](https://github.com/libp2p/js-libp2p/issues/491)) ([8da9fc9](https://github.com/libp2p/js-libp2p/commit/8da9fc9))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="0.27.0-rc.0"></a>
|
<a name="0.27.0-rc.0"></a>
|
||||||
# [0.27.0-rc.0](https://github.com/libp2p/js-libp2p/compare/v0.27.0-pre.2...v0.27.0-rc.0) (2020-01-24)
|
# [0.27.0-rc.0](https://github.com/libp2p/js-libp2p/compare/v0.27.0-pre.2...v0.27.0-rc.0) (2020-01-24)
|
||||||
|
|
||||||
|
@@ -5,10 +5,10 @@
|
|||||||
<h3 align="center">The JavaScript implementation of the libp2p Networking Stack.</h3>
|
<h3 align="center">The JavaScript implementation of the libp2p Networking Stack.</h3>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="http://ipn.io"><img src="https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square" /></a>
|
<a href="http://protocol.ai"><img src="https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square" /></a>
|
||||||
<a href="http://libp2p.io/"><img src="https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square" /></a>
|
<a href="http://libp2p.io/"><img src="https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square" /></a>
|
||||||
<a href="http://webchat.freenode.net/?channels=%23libp2p"><img src="https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square" /></a>
|
<a href="http://webchat.freenode.net/?channels=%23libp2p"><img src="https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square" /></a>
|
||||||
<a href="https://riot.permaweb.io/#/room/#libp2p:permaweb.io"><img src="https://img.shields.io/badge/matrix-%23libp2p%3Apermaweb.io-blue.svg?style=flat-square" /> </a>
|
<a href="https://riot.im/app/#/room/#libp2p:matrix.org"><img src="https://img.shields.io/badge/matrix-%23libp2p%3Apermaweb.io-blue.svg?style=flat-square" /> </a>
|
||||||
<a href="https://discord.gg/66KBrm2"><img src="https://img.shields.io/discord/475789330380488707?color=blueviolet&label=discord&style=flat-square" /></a>
|
<a href="https://discord.gg/66KBrm2"><img src="https://img.shields.io/discord/475789330380488707?color=blueviolet&label=discord&style=flat-square" /></a>
|
||||||
<a href="https://discuss.libp2p.io"><img src="https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg" /></a>
|
<a href="https://discuss.libp2p.io"><img src="https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg" /></a>
|
||||||
</p>
|
</p>
|
||||||
@@ -30,6 +30,9 @@
|
|||||||
|
|
||||||
We've come a long way, but this project is still in Alpha, lots of development is happening, API might change, beware of the Dragons 🐉..
|
We've come a long way, but this project is still in Alpha, lots of development is happening, API might change, beware of the Dragons 🐉..
|
||||||
|
|
||||||
|
The documentation in the master branch may contain changes from a pre-release.
|
||||||
|
If you are looking for the documentation of the latest release, you can view the latest release on [**npm**](https://www.npmjs.com/package/libp2p), or select the tag in github that matches the version you are looking for.
|
||||||
|
|
||||||
**Want to get started?** Check our [examples folder](/examples).
|
**Want to get started?** Check our [examples folder](/examples).
|
||||||
|
|
||||||
[**`Weekly Core Dev Calls`**](https://github.com/ipfs/pm/issues/650)
|
[**`Weekly Core Dev Calls`**](https://github.com/ipfs/pm/issues/650)
|
||||||
|
37
doc/API.md
37
doc/API.md
@@ -51,7 +51,7 @@ Creates an instance of Libp2p.
|
|||||||
| [options.datastore] | `Object` | must implement [ipfs/interface-datastore](https://github.com/ipfs/interface-datastore) (in memory datastore will be used if not provided) |
|
| [options.datastore] | `Object` | must implement [ipfs/interface-datastore](https://github.com/ipfs/interface-datastore) (in memory datastore will be used if not provided) |
|
||||||
| [options.dialer] | `Object` | libp2p Dialer configuration
|
| [options.dialer] | `Object` | libp2p Dialer configuration
|
||||||
| [options.metrics] | `Object` | libp2p Metrics configuration
|
| [options.metrics] | `Object` | libp2p Metrics configuration
|
||||||
| [options.peerInfo] | [PeerInfo](https://github.com/libp2p/js-peer-info) | peerInfo instance (it will be created if not provided) |
|
| [options.peerInfo] | [`PeerInfo`][peer-info] | peerInfo instance (it will be created if not provided) |
|
||||||
|
|
||||||
For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).
|
For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ const options = {}
|
|||||||
const libp2p = await Libp2p.create(options)
|
const libp2p = await Libp2p.create(options)
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: The `PeerInfo` option is not required and will be generated if it is not provided.
|
Note: The [`PeerInfo`][peer-info] option is not required and will be generated if it is not provided.
|
||||||
|
|
||||||
<details><summary>Alternative</summary>
|
<details><summary>Alternative</summary>
|
||||||
As an alternative, it is possible to create a Libp2p instance with the constructor:
|
As an alternative, it is possible to create a Libp2p instance with the constructor:
|
||||||
@@ -92,7 +92,7 @@ const libp2p = new Libp2p(options)
|
|||||||
|
|
||||||
Required keys in the `options` object:
|
Required keys in the `options` object:
|
||||||
|
|
||||||
- `peerInfo`: instance of [PeerInfo][] that contains the [PeerId][], Keys and [multiaddrs][multiaddr] of the libp2p Node (optional when using `.create`).
|
- `peerInfo`: instance of [`PeerInfo`][peer-info] that contains the [`PeerId`][peer-id], Keys and [multiaddrs][multiaddr] of the libp2p Node (optional when using `.create`).
|
||||||
- `modules.transport`: An array that must include at least 1 compliant transport. See [modules that implement the transport interface](https://github.com/libp2p/js-interfaces/tree/master/src/transport#modules-that-implement-the-interface).
|
- `modules.transport`: An array that must include at least 1 compliant transport. See [modules that implement the transport interface](https://github.com/libp2p/js-interfaces/tree/master/src/transport#modules-that-implement-the-interface).
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
@@ -182,7 +182,7 @@ Dials to another peer in the network and establishes the connection.
|
|||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|------|------|-------------|
|
|------|------|-------------|
|
||||||
| peer | [PeerInfo](https://github.com/libp2p/js-peer-info), [PeerId][peer-id], [multiaddr](https://github.com/multiformats/js-multiaddr), `string` | peer to dial |
|
| peer | [`PeerInfo`][peer-info]\|[`PeerId`][peer-id]\|[`Multiaddr`][multiaddr]\|`string` | peer to dial |
|
||||||
| [options] | `Object` | dial options |
|
| [options] | `Object` | dial options |
|
||||||
| [options.signal] | [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) | An `AbortSignal` instance obtained from an [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) that can be used to abort the connection before it completes |
|
| [options.signal] | [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) | An `AbortSignal` instance obtained from an [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) that can be used to abort the connection before it completes |
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ Dials to another peer in the network and selects a protocol to communicate with
|
|||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|------|------|-------------|
|
|------|------|-------------|
|
||||||
| peer | [PeerInfo](https://github.com/libp2p/js-peer-info), [PeerId][peer-id], [multiaddr](https://github.com/multiformats/js-multiaddr), `string` | peer to dial |
|
| peer | [`PeerInfo`][peer-info]\|[`PeerId`][peer-id]\|[`Multiaddr`][multiaddr]\|`string` | peer to dial |
|
||||||
| protocols | `String|Array<String>` | A list of protocols (or single protocol) to negotiate with. Protocols are attempted in order until a match is made. (e.g '/ipfs/bitswap/1.1.0') |
|
| protocols | `String|Array<String>` | A list of protocols (or single protocol) to negotiate with. Protocols are attempted in order until a match is made. (e.g '/ipfs/bitswap/1.1.0') |
|
||||||
| [options] | `Object` | dial options |
|
| [options] | `Object` | dial options |
|
||||||
| [options.signal] | [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) | An `AbortSignal` instance obtained from an [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) that can be used to abort the connection before it completes |
|
| [options.signal] | [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) | An `AbortSignal` instance obtained from an [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) that can be used to abort the connection before it completes |
|
||||||
@@ -250,7 +250,7 @@ Attempts to gracefully close an open connection to the given peer. If the connec
|
|||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|------|------|-------------|
|
|------|------|-------------|
|
||||||
| peer | [PeerInfo](https://github.com/libp2p/js-peer-info), [PeerId][peer-id], [multiaddr](https://github.com/multiformats/js-multiaddr), `string` | peer to hang up |
|
| peer | [`PeerInfo`][peer-info]\|[`PeerId`][peer-id]\|[`Multiaddr`][multiaddr]\|`string` | peer to hang up |
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
@@ -321,7 +321,7 @@ Pings a given peer and get the operation's latency.
|
|||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|------|------|-------------|
|
|------|------|-------------|
|
||||||
| peer | `PeerInfo|PeerId|Multiaddr|string` | peer to ping |
|
| peer | [`PeerInfo`][peer-info]\|[`PeerId`][peer-id]\|[`Multiaddr`][multiaddr]\|`string` | peer to ping |
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
@@ -374,7 +374,7 @@ Once a content router succeeds, the iteration will stop. If the DHT is enabled,
|
|||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|------|------|-------------|
|
|------|------|-------------|
|
||||||
| cid | [`CID`](https://github.com/multiformats/js-cid) | cid to find |
|
| cid | [`CID`][cid] | cid to find |
|
||||||
| options | `Object` | operation options |
|
| options | `Object` | operation options |
|
||||||
| options.timeout | `number` | maximum time the query should run |
|
| options.timeout | `number` | maximum time the query should run |
|
||||||
| options.maxNumProviders | `number` | maximum number of providers to find |
|
| options.maxNumProviders | `number` | maximum number of providers to find |
|
||||||
@@ -383,7 +383,7 @@ Once a content router succeeds, the iteration will stop. If the DHT is enabled,
|
|||||||
|
|
||||||
| Type | Description |
|
| Type | Description |
|
||||||
|------|-------------|
|
|------|-------------|
|
||||||
| `AsyncIterator<PeerInfo>` | Async iterator for [`PeerInfo`](https://github.com/libp2p/js-peer-info) |
|
| `AsyncIterator<PeerInfo>` | Async iterator for [`PeerInfo`][peer-info] |
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
@@ -404,7 +404,7 @@ Iterates over all content routers in parallel, in order to notify it is a provid
|
|||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|------|------|-------------|
|
|------|------|-------------|
|
||||||
| cid | [`CID`](https://github.com/multiformats/js-cid) | cid to provide |
|
| cid | [`CID`][cid] | cid to provide |
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
@@ -649,7 +649,7 @@ Enables users to change the value of certain peers in a range of 0 to 1. Peers w
|
|||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|------|------|-------------|
|
|------|------|-------------|
|
||||||
| peerId | `PeerId` | The peer to set the value for |
|
| peerId | [`PeerId`][peer-id] | The peer to set the value for |
|
||||||
| value | `number` | The value of the peer from 0 to 1 |
|
| value | `number` | The value of the peer from 0 to 1 |
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
@@ -677,7 +677,7 @@ const peerIdStrings = libp2p.metrics.peers
|
|||||||
|
|
||||||
### metrics.peers
|
### metrics.peers
|
||||||
|
|
||||||
An array of `PeerId` strings of each peer currently being tracked.
|
An array of [`PeerId`][peer-id] strings of each peer currently being tracked.
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
@@ -697,7 +697,7 @@ const protocols = libp2p.metrics.protocols
|
|||||||
|
|
||||||
### metrics.forPeer
|
### metrics.forPeer
|
||||||
|
|
||||||
Returns the [`Stats`](#stats) object for a given `PeerId` if it is being tracked.
|
Returns the [`Stats`](#stats) object for a given [`PeerId`][peer-id] if it is being tracked.
|
||||||
|
|
||||||
`libp2p.metrics.forPeer(peerId)`
|
`libp2p.metrics.forPeer(peerId)`
|
||||||
|
|
||||||
@@ -705,7 +705,7 @@ Returns the [`Stats`](#stats) object for a given `PeerId` if it is being tracked
|
|||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|------|------|-------------|
|
|------|------|-------------|
|
||||||
| peerId | `PeerId` | The peer to get stats for |
|
| peerId | [`PeerId`][peer-id] | The peer to get stats for |
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
@@ -762,7 +762,7 @@ Once you have a libp2p instance, you can listen to several events it emits, so t
|
|||||||
If `autoDial` option is `true`, applications should **not** attempt to connect to the peer
|
If `autoDial` option is `true`, applications should **not** attempt to connect to the peer
|
||||||
unless they are performing a specific action. See [peer discovery and auto dial](./PEER_DISCOVERY.md) for more information.
|
unless they are performing a specific action. See [peer discovery and auto dial](./PEER_DISCOVERY.md) for more information.
|
||||||
|
|
||||||
- `peer`: instance of [PeerInfo][https://github.com/libp2p/js-peer-info]
|
- `peer`: instance of [`PeerInfo`][peer-info]
|
||||||
|
|
||||||
#### A new connection to a peer has been opened
|
#### A new connection to a peer has been opened
|
||||||
|
|
||||||
@@ -770,7 +770,7 @@ This event will be triggered anytime a new Connection is established to another
|
|||||||
|
|
||||||
`libp2p.on('peer:connect', (peer) => {})`
|
`libp2p.on('peer:connect', (peer) => {})`
|
||||||
|
|
||||||
- `peer`: instance of [PeerInfo][https://github.com/libp2p/js-peer-info]
|
- `peer`: instance of [`PeerInfo`][peer-info]
|
||||||
|
|
||||||
#### An existing connection to a peer has been closed
|
#### An existing connection to a peer has been closed
|
||||||
|
|
||||||
@@ -778,7 +778,7 @@ This event will be triggered anytime we are disconnected from another peer, rega
|
|||||||
|
|
||||||
`libp2p.on('peer:disconnect', (peer) => {})`
|
`libp2p.on('peer:disconnect', (peer) => {})`
|
||||||
|
|
||||||
- `peer`: instance of [PeerInfo][https://github.com/libp2p/js-peer-info]
|
- `peer`: instance of [`PeerInfo`][peer-info]
|
||||||
|
|
||||||
## Types
|
## Types
|
||||||
|
|
||||||
@@ -800,5 +800,8 @@ This event will be triggered anytime we are disconnected from another peer, rega
|
|||||||
- `['300000']<MovingAverage>`: The [MovingAverage](https://www.npmjs.com/package/moving-averages) at a 5 minute interval.
|
- `['300000']<MovingAverage>`: The [MovingAverage](https://www.npmjs.com/package/moving-averages) at a 5 minute interval.
|
||||||
- `['900000']<MovingAverage>`: The [MovingAverage](https://www.npmjs.com/package/moving-averages) at a 15 minute interval.
|
- `['900000']<MovingAverage>`: The [MovingAverage](https://www.npmjs.com/package/moving-averages) at a 15 minute interval.
|
||||||
|
|
||||||
|
[cid]: https://github.com/multiformats/js-cid
|
||||||
[connection]: https://github.com/libp2p/js-interfaces/tree/master/src/connection
|
[connection]: https://github.com/libp2p/js-interfaces/tree/master/src/connection
|
||||||
|
[multiaddr]: https://github.com/multiformats/js-multiaddr
|
||||||
[peer-id]: https://github.com/libp2p/js-peer-id
|
[peer-id]: https://github.com/libp2p/js-peer-id
|
||||||
|
[peer-info]: https://github.com/libp2p/js-peer-info
|
||||||
|
178
doc/migrations/v0.26-v0.27.md
Normal file
178
doc/migrations/v0.26-v0.27.md
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
# Migrating to the new API
|
||||||
|
|
||||||
|
A migration guide for refactoring your application code from libp2p v0.26.x to v0.27.0.
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
|
||||||
|
- [Migrating from callbacks](#migrating-from-callbacks)
|
||||||
|
- [Pull Streams to Streaming Iterables](#pull-streams-to-streaming-iterables)
|
||||||
|
- [Sample API Migrations](#sample-api-migrations)
|
||||||
|
- [Registering Protocol Handlers](#registering-protocol-handlers)
|
||||||
|
- [Dialing and Sending Data](#dialing-and-sending-data)
|
||||||
|
- [Checking if a peer is connected](#checking-if-a-peer-is-connected)
|
||||||
|
- [Pinging another peer](#pinging-another-peer)
|
||||||
|
- [Pubsub](#pubsub)
|
||||||
|
- [Getting subscribers](#getting-subscribers)
|
||||||
|
- [Getting subscribed topics](#getting-subscribed-topics)
|
||||||
|
|
||||||
|
## Migrating from callbacks
|
||||||
|
|
||||||
|
Callbacks are no longer supported in the libp2p API, as the API has now fully moved to async / await. You can see a full list of the available methods in the [API readme][api]
|
||||||
|
|
||||||
|
**Before**
|
||||||
|
```js
|
||||||
|
libp2p.start((err) => {
|
||||||
|
if (err) throw err
|
||||||
|
console.log('libp2p started')
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
**After**
|
||||||
|
```js
|
||||||
|
await libp2p.start()
|
||||||
|
console.log('libp2p started')
|
||||||
|
```
|
||||||
|
|
||||||
|
## Pull Streams to Streaming Iterables
|
||||||
|
|
||||||
|
The libp2p API no longer supports Pull Streams and has migrated to [Streaming Iterables][streaming_iterable]. If you would like to continue using Pull Streams in your application code, or need additional time to migrate your code base, you can leverage the conversion modules [async-iterator-to-pull-stream](https://github.com/alanshaw/async-iterator-to-pull-stream) and [pull-stream-to-async-iterator](https://github.com/alanshaw/pull-stream-to-async-iterator).
|
||||||
|
|
||||||
|
For a growing list of async iterator modules, you should follow the [it-awesome repo][it_awesome].
|
||||||
|
|
||||||
|
## Sample API Migrations
|
||||||
|
|
||||||
|
### Registering Protocol Handlers
|
||||||
|
|
||||||
|
Protocol registration is very similar to how it previously was, however, the handler now takes a single parameter containing the incoming stream and its protocol. Additionally, you can now pass an array of protocols to `.handle`, but a single string is still supported.
|
||||||
|
|
||||||
|
**Before**
|
||||||
|
```js
|
||||||
|
const pull = require('pull-stream')
|
||||||
|
libp2p.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn))
|
||||||
|
```
|
||||||
|
|
||||||
|
**After**
|
||||||
|
```js
|
||||||
|
const pipe = require('it-pipe')
|
||||||
|
libp2p.handle(['/echo/1.0.0'], ({ protocol, stream }) => pipe(stream, stream))
|
||||||
|
```
|
||||||
|
|
||||||
|
### Dialing and Sending Data
|
||||||
|
|
||||||
|
`dialProtocol` no longer takes a callback, and will now return a [Streaming Iterable][streaming_iterable] and the protocol that was successfully negotiated. The new stream can be used with async iterator modules, see [it-awesome][it_awesome], instead of pull streams.
|
||||||
|
|
||||||
|
**Before**
|
||||||
|
```js
|
||||||
|
const pull = require('pull-stream')
|
||||||
|
libp2p.dialProtocol(peerInfo, '/echo/1.0.0', (err, conn) => {
|
||||||
|
if (err) { throw err }
|
||||||
|
pull(
|
||||||
|
pull.values(['hey']),
|
||||||
|
conn,
|
||||||
|
pull.drain((data) => {
|
||||||
|
console.log('received echo:', data.toString())
|
||||||
|
}, (err) => {
|
||||||
|
if (err) { throw err }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
**After**
|
||||||
|
```js
|
||||||
|
const pipe = require('it-pipe')
|
||||||
|
const { protocol, stream } = await libp2p.dialProtocol(peerInfo, '/echo/1.0.0')
|
||||||
|
await pipe(
|
||||||
|
['hey'],
|
||||||
|
stream,
|
||||||
|
async function (source) {
|
||||||
|
for await (const data of source) {
|
||||||
|
console.log('received echo:', data.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Checking if a peer is connected
|
||||||
|
|
||||||
|
`peerInfo.isConnected` has been deprecated. libp2p now tracks all connections centrally and will no longer update the state of `peerInfo.isConnected`. Consumers should switch to using `libp2p.registrar.getConnection(peerInfo)`, which will return an open connection to that peer if one exists.
|
||||||
|
|
||||||
|
**Before**
|
||||||
|
```js
|
||||||
|
if (peerInfo.isConnected()) {
|
||||||
|
// ...do something if connected
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**After**
|
||||||
|
```js
|
||||||
|
const connection = libp2p.registrar.getConnection(peerInfo)
|
||||||
|
if (connection) {
|
||||||
|
// ...do something if connected
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pinging another peer
|
||||||
|
|
||||||
|
`libp2p.ping` will no longer callback with a `Ping` event emitter. The internal logic has been simplified to give more flexibility to the API. `libp2p.ping` will now execute a single ping and return the latency.
|
||||||
|
|
||||||
|
**Before**
|
||||||
|
```js
|
||||||
|
libp2p.ping(peerInfo, (err, ping) => {
|
||||||
|
if (err) throw err
|
||||||
|
ping.once('ping', (latency) => {
|
||||||
|
console.log('Latency is %s ms', latency)
|
||||||
|
ping.stop()
|
||||||
|
})
|
||||||
|
|
||||||
|
ping.start()
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
**After**
|
||||||
|
```js
|
||||||
|
const latency = await libp2p.ping(peerInfo)
|
||||||
|
console.log('Latency is %s ms', latency)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pubsub
|
||||||
|
|
||||||
|
#### Getting subscribers
|
||||||
|
|
||||||
|
`libp2p.pubsub.peers()` is now `libp2p.pubsub.getSubscribers()` and is no longer an asynchronous action.
|
||||||
|
|
||||||
|
**Before**
|
||||||
|
```js
|
||||||
|
libp2p.pubsub.peers(topic, (err, subscribers) => {
|
||||||
|
if (err) throw err
|
||||||
|
console.log('Subscribers:', subscribers)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
**After**
|
||||||
|
```js
|
||||||
|
const subscribers = libp2p.pubsub.getSubscribers(topic)
|
||||||
|
console.log('Subscribers:', subscribers)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Getting subscribed topics
|
||||||
|
|
||||||
|
`libp2p.pubsub.ls()` is now `libp2p.pubsub.getTopics()` and is no longer an asynchronous action.
|
||||||
|
|
||||||
|
**Before**
|
||||||
|
```js
|
||||||
|
libp2p.pubsub.ls((err, topics) => {
|
||||||
|
if (err) throw err
|
||||||
|
console.log('Topics:', topics)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
**After**
|
||||||
|
```js
|
||||||
|
const topics = libp2p.pubsub.getTopics()
|
||||||
|
console.log('Topics:', topics)
|
||||||
|
```
|
||||||
|
|
||||||
|
[api]: ../API.md
|
||||||
|
[it_awesome]: https://github.com/alanshaw/it-awesome
|
||||||
|
[streaming_iterable]: ../STREAMING_ITERABLES.md
|
12
package.json
12
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "libp2p",
|
"name": "libp2p",
|
||||||
"version": "0.27.0-rc.0",
|
"version": "0.27.2",
|
||||||
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
||||||
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
"bignumber.js": "^9.0.0",
|
"bignumber.js": "^9.0.0",
|
||||||
"class-is": "^1.1.0",
|
"class-is": "^1.1.0",
|
||||||
"debug": "^4.1.1",
|
"debug": "^4.1.1",
|
||||||
"err-code": "^1.1.2",
|
"err-code": "^2.0.0",
|
||||||
"hashlru": "^2.3.0",
|
"hashlru": "^2.3.0",
|
||||||
"it-all": "^1.0.1",
|
"it-all": "^1.0.1",
|
||||||
"it-buffer": "^0.1.1",
|
"it-buffer": "^0.1.1",
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nodeutils/defaults-deep": "^1.1.0",
|
"@nodeutils/defaults-deep": "^1.1.0",
|
||||||
"abortable-iterator": "^2.1.0",
|
"abortable-iterator": "^3.0.0",
|
||||||
"aegir": "^20.5.1",
|
"aegir": "^20.5.1",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"chai-as-promised": "^7.1.1",
|
"chai-as-promised": "^7.1.1",
|
||||||
@@ -86,6 +86,7 @@
|
|||||||
"it-concat": "^1.0.0",
|
"it-concat": "^1.0.0",
|
||||||
"it-pair": "^1.0.0",
|
"it-pair": "^1.0.0",
|
||||||
"it-pushable": "^1.4.0",
|
"it-pushable": "^1.4.0",
|
||||||
|
"interop-libp2p": "~0.0.1",
|
||||||
"libp2p-bootstrap": "^0.10.3",
|
"libp2p-bootstrap": "^0.10.3",
|
||||||
"libp2p-delegated-content-routing": "^0.4.1",
|
"libp2p-delegated-content-routing": "^0.4.1",
|
||||||
"libp2p-delegated-peer-routing": "^0.4.0",
|
"libp2p-delegated-peer-routing": "^0.4.0",
|
||||||
@@ -98,7 +99,7 @@
|
|||||||
"libp2p-tcp": "^0.14.1",
|
"libp2p-tcp": "^0.14.1",
|
||||||
"libp2p-webrtc-star": "^0.17.0",
|
"libp2p-webrtc-star": "^0.17.0",
|
||||||
"libp2p-websockets": "^0.13.1",
|
"libp2p-websockets": "^0.13.1",
|
||||||
"nock": "^10.0.6",
|
"nock": "^11.7.2",
|
||||||
"p-defer": "^3.0.0",
|
"p-defer": "^3.0.0",
|
||||||
"p-times": "^2.1.0",
|
"p-times": "^2.1.0",
|
||||||
"p-wait-for": "^3.1.0",
|
"p-wait-for": "^3.1.0",
|
||||||
@@ -112,6 +113,7 @@
|
|||||||
"Alan Shaw <alan@tableflip.io>",
|
"Alan Shaw <alan@tableflip.io>",
|
||||||
"Alex Potsides <alex@achingbrain.net>",
|
"Alex Potsides <alex@achingbrain.net>",
|
||||||
"Andrew Nesbitt <andrewnez@gmail.com>",
|
"Andrew Nesbitt <andrewnez@gmail.com>",
|
||||||
|
"Cayman <caymannava@gmail.com>",
|
||||||
"Chris Bratlien <chrisbratlien@gmail.com>",
|
"Chris Bratlien <chrisbratlien@gmail.com>",
|
||||||
"Chris Dostert <chrisdostert@users.noreply.github.com>",
|
"Chris Dostert <chrisdostert@users.noreply.github.com>",
|
||||||
"Daijiro Wachi <daijiro.wachi@gmail.com>",
|
"Daijiro Wachi <daijiro.wachi@gmail.com>",
|
||||||
@@ -153,12 +155,14 @@
|
|||||||
"Yusef Napora <yusef@napora.org>",
|
"Yusef Napora <yusef@napora.org>",
|
||||||
"Zane Starr <zcstarr@gmail.com>",
|
"Zane Starr <zcstarr@gmail.com>",
|
||||||
"a1300 <a1300@users.noreply.github.com>",
|
"a1300 <a1300@users.noreply.github.com>",
|
||||||
|
"dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>",
|
||||||
"dirkmc <dirkmdev@gmail.com>",
|
"dirkmc <dirkmdev@gmail.com>",
|
||||||
"ebinks <elizabethjbinks@gmail.com>",
|
"ebinks <elizabethjbinks@gmail.com>",
|
||||||
"greenkeeperio-bot <support@greenkeeper.io>",
|
"greenkeeperio-bot <support@greenkeeper.io>",
|
||||||
"isan_rivkin <isanrivkin@gmail.com>",
|
"isan_rivkin <isanrivkin@gmail.com>",
|
||||||
"mayerwin <mayerwin@users.noreply.github.com>",
|
"mayerwin <mayerwin@users.noreply.github.com>",
|
||||||
"phillmac <phillmac@users.noreply.github.com>",
|
"phillmac <phillmac@users.noreply.github.com>",
|
||||||
|
"shresthagrawal <34920931+shresthagrawal@users.noreply.github.com>",
|
||||||
"swedneck <40505480+swedneck@users.noreply.github.com>",
|
"swedneck <40505480+swedneck@users.noreply.github.com>",
|
||||||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>"
|
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>"
|
||||||
]
|
]
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
# PDD Test Stories Implementation
|
|
||||||
|
|
||||||
> Implementation of the Compliance tests from https://github.com/libp2p/interop
|
|
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "pdd-impl",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"description": "PDD Test Stories implementation",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": " "
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"PDD",
|
|
||||||
"libp2p"
|
|
||||||
],
|
|
||||||
"author": "David Dias <daviddias@ipfs.io>",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"libp2p": "file:./..",
|
|
||||||
"libp2p-interop": "github:libp2p/interop#master",
|
|
||||||
"tape": "^4.8.0"
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,104 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
const test = require('tape')
|
|
||||||
const libp2p = require('libp2p')
|
|
||||||
const TCP = require('libp2p-tcp')
|
|
||||||
const WebSockets = require('libp2p-websockets')
|
|
||||||
const SECIO = require('libp2p-secio')
|
|
||||||
const Multiplex = require('libp2p-multiplex')
|
|
||||||
const Railing = require('libp2p-railing')
|
|
||||||
const MulticastDNS = require('libp2p-mdns')
|
|
||||||
const KadDHT = require('libp2p-kad-dht')
|
|
||||||
const PeerInfo = require('peer-info')
|
|
||||||
const pull = require('pull-stream')
|
|
||||||
const waterfall = require('async/waterfall')
|
|
||||||
const series = require('async/series')
|
|
||||||
const PeerA = require('libp2p-interop/peer-a.json')
|
|
||||||
const PeerB = require('libp2p-interop/peer-b.json')
|
|
||||||
|
|
||||||
class IPFSBundle extends libp2p {
|
|
||||||
constructor (peerInfo, options) {
|
|
||||||
options = Object.assign({ bootstrap: [] }, options)
|
|
||||||
|
|
||||||
const modules = {
|
|
||||||
transport: [
|
|
||||||
new TCP(),
|
|
||||||
new WebSockets()
|
|
||||||
],
|
|
||||||
connection: {
|
|
||||||
muxer: [
|
|
||||||
Multiplex
|
|
||||||
],
|
|
||||||
crypto: [
|
|
||||||
SECIO
|
|
||||||
]
|
|
||||||
},
|
|
||||||
discovery: [
|
|
||||||
new MulticastDNS(peerInfo, 'ipfs.local'),
|
|
||||||
new Railing(options.bootstrap)
|
|
||||||
],
|
|
||||||
DHT: KadDHT
|
|
||||||
}
|
|
||||||
|
|
||||||
super(modules, peerInfo, undefined, options)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test('story 1 - peerA', (t) => {
|
|
||||||
t.plan(10)
|
|
||||||
let node
|
|
||||||
|
|
||||||
waterfall([
|
|
||||||
(cb) => PeerInfo.create(PeerA, cb),
|
|
||||||
(peerInfo, cb) => {
|
|
||||||
peerInfo.multiaddrs.add('/ip4/127.0.0.1/tcp/10000')
|
|
||||||
node = new IPFSBundle(peerInfo)
|
|
||||||
node.start(cb)
|
|
||||||
}
|
|
||||||
], (err) => {
|
|
||||||
t.ifErr(err, 'created Node successfully')
|
|
||||||
t.ok(node.isStarted(), 'PeerA is Running')
|
|
||||||
|
|
||||||
const peerBAddr = `/ip4/127.0.0.1/tcp/10001/p2p/${PeerB.id}`
|
|
||||||
|
|
||||||
node.handle('/time/1.0.0', (protocol, conn) => {
|
|
||||||
pull(
|
|
||||||
pull.values([Date.now().toString()]),
|
|
||||||
conn,
|
|
||||||
pull.onEnd((err) => {
|
|
||||||
t.ifErr(err)
|
|
||||||
t.pass('Sent time successfully')
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
series([
|
|
||||||
(cb) => setTimeout(cb, 5 * 1000), // time to run both scripts
|
|
||||||
(cb) => node.ping(peerBAddr, (err, p) => {
|
|
||||||
t.ifErr(err, 'initiated Ping to PeerB')
|
|
||||||
p.once('error', (err) => t.ifErr(err, 'Ping should not fail'))
|
|
||||||
p.once('ping', (time) => {
|
|
||||||
t.pass('ping PeerB successfully')
|
|
||||||
p.stop()
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
(cb) => node.dial(peerBAddr, '/echo/1.0.0', (err, conn) => {
|
|
||||||
t.ifErr(err, 'dial successful')
|
|
||||||
|
|
||||||
const data = Buffer.from('Hey')
|
|
||||||
|
|
||||||
pull(
|
|
||||||
pull.values([data]),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, values) => {
|
|
||||||
t.ifErr(err, 'Received echo back')
|
|
||||||
t.deepEqual(values[0], data)
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
(cb) => setTimeout(cb, 2 * 1000) // time to both finish
|
|
||||||
], () => node.stop((err) => t.ifErr(err, 'PeerA has stopped')))
|
|
||||||
})
|
|
||||||
})
|
|
@@ -1,98 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
const test = require('tape')
|
|
||||||
const libp2p = require('libp2p')
|
|
||||||
const TCP = require('libp2p-tcp')
|
|
||||||
const WebSockets = require('libp2p-websockets')
|
|
||||||
const SECIO = require('libp2p-secio')
|
|
||||||
const Multiplex = require('libp2p-multiplex')
|
|
||||||
const Railing = require('libp2p-railing')
|
|
||||||
const MulticastDNS = require('libp2p-mdns')
|
|
||||||
const KadDHT = require('libp2p-kad-dht')
|
|
||||||
const PeerInfo = require('peer-info')
|
|
||||||
const pull = require('pull-stream')
|
|
||||||
const waterfall = require('async/waterfall')
|
|
||||||
const series = require('async/series')
|
|
||||||
const PeerA = require('libp2p-interop/peer-a.json')
|
|
||||||
const PeerB = require('libp2p-interop/peer-b.json')
|
|
||||||
|
|
||||||
class IPFSBundle extends libp2p {
|
|
||||||
constructor (peerInfo, options) {
|
|
||||||
options = Object.assign({ bootstrap: [] }, options)
|
|
||||||
|
|
||||||
const modules = {
|
|
||||||
transport: [
|
|
||||||
new TCP(),
|
|
||||||
new WebSockets()
|
|
||||||
],
|
|
||||||
connection: {
|
|
||||||
muxer: [
|
|
||||||
Multiplex
|
|
||||||
],
|
|
||||||
crypto: [
|
|
||||||
SECIO
|
|
||||||
]
|
|
||||||
},
|
|
||||||
discovery: [
|
|
||||||
new MulticastDNS(peerInfo, 'ipfs.local'),
|
|
||||||
new Railing(options.bootstrap)
|
|
||||||
],
|
|
||||||
DHT: KadDHT
|
|
||||||
}
|
|
||||||
|
|
||||||
super(modules, peerInfo, undefined, options)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test('story 1 - peerA', (t) => {
|
|
||||||
t.plan(8)
|
|
||||||
let node
|
|
||||||
|
|
||||||
waterfall([
|
|
||||||
(cb) => PeerInfo.create(PeerB, cb),
|
|
||||||
(peerInfo, cb) => {
|
|
||||||
peerInfo.multiaddrs.add('/ip4/127.0.0.1/tcp/10001')
|
|
||||||
node = new IPFSBundle(peerInfo)
|
|
||||||
node.start(cb)
|
|
||||||
}
|
|
||||||
], (err) => {
|
|
||||||
t.ifErr(err, 'created Node successfully')
|
|
||||||
t.ok(node.isStarted(), 'PeerB is Running')
|
|
||||||
|
|
||||||
const peerAAddr = `/ip4/127.0.0.1/tcp/10000/p2p/${PeerA.id}`
|
|
||||||
|
|
||||||
node.handle('/echo/1.0.0', (protocol, conn) => {
|
|
||||||
pull(
|
|
||||||
conn,
|
|
||||||
conn,
|
|
||||||
pull.onEnd((err) => t.ifErr(err, 'echo was successful'))
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
series([
|
|
||||||
(cb) => setTimeout(cb, 5 * 1000), // time to run both scripts
|
|
||||||
(cb) => node.ping(peerAAddr, (err, p) => {
|
|
||||||
t.ifErr(err, 'initiated Ping to PeerA')
|
|
||||||
p.once('error', (err) => t.ifErr(err, 'Ping should not fail'))
|
|
||||||
p.once('ping', (time) => {
|
|
||||||
t.pass('ping PeerA successfully')
|
|
||||||
p.stop()
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
(cb) => node.dial(peerAAddr, '/time/1.0.0', (err, conn) => {
|
|
||||||
t.ifErr(err, 'dial successful')
|
|
||||||
|
|
||||||
pull(
|
|
||||||
pull.values([]),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, values) => {
|
|
||||||
t.ifErr(err, 'Received time')
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
(cb) => setTimeout(cb, 2 * 1000) // time to both finish
|
|
||||||
], () => node.stop((err) => t.ifErr(err, 'PeerB has stopped')))
|
|
||||||
})
|
|
||||||
})
|
|
@@ -1,54 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
const test = require('tape')
|
|
||||||
const libp2p = require('libp2p')
|
|
||||||
const TCP = require('libp2p-tcp')
|
|
||||||
const PeerInfo = require('peer-info')
|
|
||||||
const waterfall = require('async/waterfall')
|
|
||||||
const pull = require('pull-stream')
|
|
||||||
const PeerA = require('libp2p-interop/peer-a.json')
|
|
||||||
const PeerB = require('libp2p-interop/peer-b.json')
|
|
||||||
|
|
||||||
class MyBundle extends libp2p {
|
|
||||||
constructor (peerInfo) {
|
|
||||||
const modules = {
|
|
||||||
transport: [new TCP()]
|
|
||||||
}
|
|
||||||
super(modules, peerInfo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test('story 1 - peerA', (t) => {
|
|
||||||
t.plan(6)
|
|
||||||
let node
|
|
||||||
|
|
||||||
waterfall([
|
|
||||||
(cb) => PeerInfo.create(PeerA, cb),
|
|
||||||
(peerInfo, cb) => {
|
|
||||||
peerInfo.multiaddrs.add('/ip4/127.0.0.1/tcp/10000')
|
|
||||||
node = new MyBundle(peerInfo)
|
|
||||||
node.start(cb)
|
|
||||||
}
|
|
||||||
], (err) => {
|
|
||||||
t.ifErr(err, 'created Node')
|
|
||||||
t.ok(node.isStarted(), 'PeerA is running')
|
|
||||||
|
|
||||||
const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/p2p/${PeerB.id}`
|
|
||||||
|
|
||||||
node.dial(PeerBAddr, '/echo/1.0.0', (err, conn) => {
|
|
||||||
t.ifErr(err, 'dial successful')
|
|
||||||
|
|
||||||
const data = Buffer.from('Heey')
|
|
||||||
|
|
||||||
pull(
|
|
||||||
pull.values([data]),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, values) => {
|
|
||||||
t.ifErr(err, 'Received echo back')
|
|
||||||
t.deepEqual(values[0], data)
|
|
||||||
node.stop((err) => t.ifErr(err, 'PeerA has stopped'))
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
@@ -1,49 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
const test = require('tape')
|
|
||||||
const libp2p = require('libp2p')
|
|
||||||
const TCP = require('libp2p-tcp')
|
|
||||||
const PeerInfo = require('peer-info')
|
|
||||||
const waterfall = require('async/waterfall')
|
|
||||||
const pull = require('pull-stream')
|
|
||||||
const PeerB = require('libp2p-interop/peer-b.json')
|
|
||||||
|
|
||||||
class MyBundle extends libp2p {
|
|
||||||
constructor (peerInfo) {
|
|
||||||
const modules = {
|
|
||||||
transport: [new TCP()]
|
|
||||||
}
|
|
||||||
super(modules, peerInfo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test('story 1 - peerB', (t) => {
|
|
||||||
t.plan(5)
|
|
||||||
let node
|
|
||||||
|
|
||||||
waterfall([
|
|
||||||
(cb) => PeerInfo.create(PeerB, cb),
|
|
||||||
(peerInfo, cb) => {
|
|
||||||
peerInfo.multiaddrs.add('/ip4/127.0.0.1/tcp/10001')
|
|
||||||
node = new MyBundle(peerInfo)
|
|
||||||
node.start(cb)
|
|
||||||
}
|
|
||||||
], (err) => {
|
|
||||||
t.ifErr(err)
|
|
||||||
t.ok(node.isStarted(), 'PeerB is running')
|
|
||||||
|
|
||||||
node.handle('/echo/1.0.0', (protocol, conn) => {
|
|
||||||
pull(
|
|
||||||
conn,
|
|
||||||
conn,
|
|
||||||
pull.onEnd((err) => {
|
|
||||||
t.ifErr(err)
|
|
||||||
t.pass('Received End of Connection')
|
|
||||||
node.stop((err) => {
|
|
||||||
t.ifErr(err, 'PeerB has stopped')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
@@ -1,54 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
const test = require('tape')
|
|
||||||
const libp2p = require('libp2p')
|
|
||||||
const WebSockets = require('libp2p-websockets')
|
|
||||||
const PeerInfo = require('peer-info')
|
|
||||||
const waterfall = require('async/waterfall')
|
|
||||||
const pull = require('pull-stream')
|
|
||||||
const PeerA = require('libp2p-interop/peer-a.json')
|
|
||||||
const PeerB = require('libp2p-interop/peer-b.json')
|
|
||||||
|
|
||||||
class MyBundle extends libp2p {
|
|
||||||
constructor (peerInfo) {
|
|
||||||
const modules = {
|
|
||||||
transport: [new WebSockets()]
|
|
||||||
}
|
|
||||||
super(modules, peerInfo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test('story 2 - peerA', (t) => {
|
|
||||||
t.plan(6)
|
|
||||||
let node
|
|
||||||
|
|
||||||
waterfall([
|
|
||||||
(cb) => PeerInfo.create(PeerA, cb),
|
|
||||||
(peerInfo, cb) => {
|
|
||||||
peerInfo.multiaddrs.add('/ip4/127.0.0.1/tcp/10000/ws')
|
|
||||||
node = new MyBundle(peerInfo)
|
|
||||||
node.start(cb)
|
|
||||||
}
|
|
||||||
], (err) => {
|
|
||||||
t.ifErr(err, 'created Node')
|
|
||||||
t.ok(node.isStarted(), 'PeerA is running')
|
|
||||||
|
|
||||||
const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/p2p/${PeerB.id}`
|
|
||||||
|
|
||||||
node.dial(PeerBAddr, '/echo/1.0.0', (err, conn) => {
|
|
||||||
t.ifErr(err, 'dial successful')
|
|
||||||
|
|
||||||
const data = Buffer.from('Heey')
|
|
||||||
|
|
||||||
pull(
|
|
||||||
pull.values([data]),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, values) => {
|
|
||||||
t.ifErr(err, 'Received echo back')
|
|
||||||
t.deepEqual(values[0], data)
|
|
||||||
node.stop((err) => t.ifErr(err, 'PeerA has stopped'))
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
@@ -1,49 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
const test = require('tape')
|
|
||||||
const libp2p = require('libp2p')
|
|
||||||
const WebSockets = require('libp2p-websockets')
|
|
||||||
const PeerInfo = require('peer-info')
|
|
||||||
const waterfall = require('async/waterfall')
|
|
||||||
const pull = require('pull-stream')
|
|
||||||
const PeerB = require('libp2p-interop/peer-b.json')
|
|
||||||
|
|
||||||
class MyBundle extends libp2p {
|
|
||||||
constructor (peerInfo) {
|
|
||||||
const modules = {
|
|
||||||
transport: [new WebSockets()]
|
|
||||||
}
|
|
||||||
super(modules, peerInfo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test('story 2 - peerB', (t) => {
|
|
||||||
t.plan(5)
|
|
||||||
let node
|
|
||||||
|
|
||||||
waterfall([
|
|
||||||
(cb) => PeerInfo.create(PeerB, cb),
|
|
||||||
(peerInfo, cb) => {
|
|
||||||
peerInfo.multiaddrs.add('/ip4/127.0.0.1/tcp/10001/ws')
|
|
||||||
node = new MyBundle(peerInfo)
|
|
||||||
node.start(cb)
|
|
||||||
}
|
|
||||||
], (err) => {
|
|
||||||
t.ifErr(err)
|
|
||||||
t.ok(node.isStarted(), 'PeerB is running')
|
|
||||||
|
|
||||||
node.handle('/echo/1.0.0', (protocol, conn) => {
|
|
||||||
pull(
|
|
||||||
conn,
|
|
||||||
pull.through(v => v, err => {
|
|
||||||
t.ifErr(err)
|
|
||||||
t.pass('Received End of Connection')
|
|
||||||
node.stop((err) => {
|
|
||||||
t.ifErr(err, 'PeerB has stopped')
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
conn
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
@@ -1,42 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
const test = require('tape')
|
|
||||||
const libp2p = require('libp2p')
|
|
||||||
const TCP = require('libp2p-tcp')
|
|
||||||
const PeerInfo = require('peer-info')
|
|
||||||
const waterfall = require('async/waterfall')
|
|
||||||
const PeerA = require('libp2p-interop/peer-a.json')
|
|
||||||
const PeerB = require('libp2p-interop/peer-b.json')
|
|
||||||
|
|
||||||
class MyBundle extends libp2p {
|
|
||||||
constructor (peerInfo) {
|
|
||||||
const modules = {
|
|
||||||
transport: [new TCP()]
|
|
||||||
}
|
|
||||||
super(modules, peerInfo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test('story 3 - peerA', (t) => {
|
|
||||||
t.plan(4)
|
|
||||||
let node
|
|
||||||
|
|
||||||
waterfall([
|
|
||||||
(cb) => PeerInfo.create(PeerA, cb),
|
|
||||||
(peerInfo, cb) => {
|
|
||||||
peerInfo.multiaddrs.add('/ip4/127.0.0.1/tcp/10000')
|
|
||||||
node = new MyBundle(peerInfo)
|
|
||||||
node.start(cb)
|
|
||||||
}
|
|
||||||
], (err) => {
|
|
||||||
t.ifErr(err, 'created Node')
|
|
||||||
t.ok(node.isStarted(), 'PeerA is running')
|
|
||||||
|
|
||||||
const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/ws/p2p/${PeerB.id}`
|
|
||||||
|
|
||||||
setTimeout(() => node.dial(PeerBAddr, '/echo/1.0.0', (err, conn) => {
|
|
||||||
t.ok(err, 'dial failed')
|
|
||||||
node.stop((err) => t.ifErr(err, 'PeerA has stopped'))
|
|
||||||
}), 1000)
|
|
||||||
})
|
|
||||||
})
|
|
@@ -1,42 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
const test = require('tape')
|
|
||||||
const libp2p = require('libp2p')
|
|
||||||
const WebSockets = require('libp2p-websockets')
|
|
||||||
const PeerInfo = require('peer-info')
|
|
||||||
const waterfall = require('async/waterfall')
|
|
||||||
const PeerA = require('libp2p-interop/peer-a.json')
|
|
||||||
const PeerB = require('libp2p-interop/peer-b.json')
|
|
||||||
|
|
||||||
class MyBundle extends libp2p {
|
|
||||||
constructor (peerInfo) {
|
|
||||||
const modules = {
|
|
||||||
transport: [new WebSockets()]
|
|
||||||
}
|
|
||||||
super(modules, peerInfo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test('story 3 - peerB', (t) => {
|
|
||||||
t.plan(4)
|
|
||||||
let node
|
|
||||||
|
|
||||||
waterfall([
|
|
||||||
(cb) => PeerInfo.create(PeerB, cb),
|
|
||||||
(peerInfo, cb) => {
|
|
||||||
peerInfo.multiaddrs.add('/ip4/127.0.0.1/tcp/10000/ws')
|
|
||||||
node = new MyBundle(peerInfo)
|
|
||||||
node.start(cb)
|
|
||||||
}
|
|
||||||
], (err) => {
|
|
||||||
t.ifErr(err, 'created Node')
|
|
||||||
t.ok(node.isStarted(), 'PeerA is running')
|
|
||||||
|
|
||||||
const PeerAAddr = `/ip4/127.0.0.1/tcp/10000/ws/p2p/${PeerA.id}`
|
|
||||||
|
|
||||||
setTimeout(() => node.dial(PeerAAddr, '/echo/1.0.0', (err, conn) => {
|
|
||||||
t.ok(err, 'dial failed')
|
|
||||||
node.stop((err) => t.ifErr(err, 'PeerA has stopped'))
|
|
||||||
}), 1000)
|
|
||||||
})
|
|
||||||
})
|
|
@@ -4,7 +4,7 @@ const debug = require('debug')
|
|||||||
const pb = require('it-protocol-buffers')
|
const pb = require('it-protocol-buffers')
|
||||||
const lp = require('it-length-prefixed')
|
const lp = require('it-length-prefixed')
|
||||||
const pipe = require('it-pipe')
|
const pipe = require('it-pipe')
|
||||||
const { collect, take } = require('streaming-iterables')
|
const { collect, take, consume } = require('streaming-iterables')
|
||||||
|
|
||||||
const PeerInfo = require('peer-info')
|
const PeerInfo = require('peer-info')
|
||||||
const PeerId = require('peer-id')
|
const PeerId = require('peer-id')
|
||||||
@@ -114,7 +114,8 @@ class IdentifyService {
|
|||||||
protocols: Array.from(this._protocols.keys())
|
protocols: Array.from(this._protocols.keys())
|
||||||
}],
|
}],
|
||||||
pb.encode(Message),
|
pb.encode(Message),
|
||||||
stream
|
stream,
|
||||||
|
consume
|
||||||
)
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Just log errors
|
// Just log errors
|
||||||
@@ -153,6 +154,7 @@ class IdentifyService {
|
|||||||
async identify (connection) {
|
async identify (connection) {
|
||||||
const { stream } = await connection.newStream(MULTICODEC_IDENTIFY)
|
const { stream } = await connection.newStream(MULTICODEC_IDENTIFY)
|
||||||
const [data] = await pipe(
|
const [data] = await pipe(
|
||||||
|
[],
|
||||||
stream,
|
stream,
|
||||||
lp.decode(),
|
lp.decode(),
|
||||||
take(1),
|
take(1),
|
||||||
@@ -242,7 +244,8 @@ class IdentifyService {
|
|||||||
pipe(
|
pipe(
|
||||||
[message],
|
[message],
|
||||||
lp.encode(),
|
lp.encode(),
|
||||||
stream
|
stream,
|
||||||
|
consume
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,6 +258,7 @@ class IdentifyService {
|
|||||||
*/
|
*/
|
||||||
async _handlePush ({ connection, stream }) {
|
async _handlePush ({ connection, stream }) {
|
||||||
const [data] = await pipe(
|
const [data] = await pipe(
|
||||||
|
[],
|
||||||
stream,
|
stream,
|
||||||
lp.decode(),
|
lp.decode(),
|
||||||
take(1),
|
take(1),
|
||||||
|
@@ -8,7 +8,7 @@ const errCode = require('err-code')
|
|||||||
const crypto = require('libp2p-crypto')
|
const crypto = require('libp2p-crypto')
|
||||||
const pipe = require('it-pipe')
|
const pipe = require('it-pipe')
|
||||||
const { toBuffer } = require('it-buffer')
|
const { toBuffer } = require('it-buffer')
|
||||||
const { collect } = require('streaming-iterables')
|
const { collect, take } = require('streaming-iterables')
|
||||||
|
|
||||||
const { PROTOCOL, PING_LENGTH } = require('./constants')
|
const { PROTOCOL, PING_LENGTH } = require('./constants')
|
||||||
|
|
||||||
@@ -29,6 +29,7 @@ async function ping (node, peer) {
|
|||||||
const [result] = await pipe(
|
const [result] = await pipe(
|
||||||
[data],
|
[data],
|
||||||
stream,
|
stream,
|
||||||
|
stream => take(1, stream),
|
||||||
toBuffer,
|
toBuffer,
|
||||||
collect
|
collect
|
||||||
)
|
)
|
||||||
|
@@ -231,7 +231,7 @@ class Upgrader {
|
|||||||
const { stream, protocol } = await mss.handle(Array.from(this.protocols.keys()))
|
const { stream, protocol } = await mss.handle(Array.from(this.protocols.keys()))
|
||||||
log('%s: incoming stream opened on %s', direction, protocol)
|
log('%s: incoming stream opened on %s', direction, protocol)
|
||||||
if (this.metrics) this.metrics.trackStream({ stream, remotePeer, protocol })
|
if (this.metrics) this.metrics.trackStream({ stream, remotePeer, protocol })
|
||||||
connection.addStream(stream, protocol)
|
connection.addStream(muxedStream, { protocol })
|
||||||
this._onStream({ connection, stream, protocol })
|
this._onStream({ connection, stream, protocol })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error(err)
|
log.error(err)
|
||||||
|
@@ -6,9 +6,11 @@ chai.use(require('dirty-chai'))
|
|||||||
const { expect } = chai
|
const { expect } = chai
|
||||||
|
|
||||||
const pTimes = require('p-times')
|
const pTimes = require('p-times')
|
||||||
|
const pipe = require('it-pipe')
|
||||||
|
|
||||||
const peerUtils = require('../utils/creators/peer')
|
const peerUtils = require('../utils/creators/peer')
|
||||||
const baseOptions = require('../utils/base-options')
|
const baseOptions = require('../utils/base-options')
|
||||||
|
const { PROTOCOL } = require('../../src/ping/constants')
|
||||||
|
|
||||||
describe('ping', () => {
|
describe('ping', () => {
|
||||||
let nodes
|
let nodes
|
||||||
@@ -32,4 +34,40 @@ describe('ping', () => {
|
|||||||
const averageLatency = latencies.reduce((p, c) => p + c, 0) / latencies.length
|
const averageLatency = latencies.reduce((p, c) => p + c, 0) / latencies.length
|
||||||
expect(averageLatency).to.be.a('Number')
|
expect(averageLatency).to.be.a('Number')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('only waits for the first response to arrive', async () => {
|
||||||
|
nodes[1].handle(PROTOCOL, async ({ connection, stream }) => {
|
||||||
|
let firstInvocation = true
|
||||||
|
|
||||||
|
await pipe(
|
||||||
|
stream,
|
||||||
|
function (stream) {
|
||||||
|
const output = {
|
||||||
|
[Symbol.asyncIterator]: () => output,
|
||||||
|
next: async () => {
|
||||||
|
if (firstInvocation) {
|
||||||
|
firstInvocation = false
|
||||||
|
|
||||||
|
for await (const data of stream) {
|
||||||
|
return {
|
||||||
|
value: data,
|
||||||
|
done: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return new Promise() // never resolve
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output
|
||||||
|
},
|
||||||
|
stream
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const latency = await nodes[0].ping(nodes[1].peerInfo)
|
||||||
|
|
||||||
|
expect(latency).to.be.a('Number')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@@ -12,6 +12,7 @@ const PeerId = require('peer-id')
|
|||||||
const PeerInfo = require('peer-info')
|
const PeerInfo = require('peer-info')
|
||||||
const duplexPair = require('it-pair/duplex')
|
const duplexPair = require('it-pair/duplex')
|
||||||
const multiaddr = require('multiaddr')
|
const multiaddr = require('multiaddr')
|
||||||
|
const pWaitFor = require('p-wait-for')
|
||||||
|
|
||||||
const { codes: Errors } = require('../../src/errors')
|
const { codes: Errors } = require('../../src/errors')
|
||||||
const { IdentifyService, multicodecs } = require('../../src/identify')
|
const { IdentifyService, multicodecs } = require('../../src/identify')
|
||||||
@@ -203,16 +204,17 @@ describe('Identify', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
sinon.spy(libp2p.identifyService, 'identify')
|
sinon.spy(libp2p.identifyService, 'identify')
|
||||||
sinon.spy(libp2p.peerStore, 'replace')
|
const peerStoreSpy = sinon.spy(libp2p.peerStore, 'replace')
|
||||||
|
|
||||||
const connection = await libp2p.dialer.connectToPeer(remoteAddr)
|
const connection = await libp2p.dialer.connectToPeer(remoteAddr)
|
||||||
expect(connection).to.exist()
|
expect(connection).to.exist()
|
||||||
// Wait for nextTick to trigger the identify call
|
|
||||||
await delay(1)
|
|
||||||
expect(libp2p.identifyService.identify.callCount).to.equal(1)
|
|
||||||
await libp2p.identifyService.identify.firstCall.returnValue
|
|
||||||
|
|
||||||
expect(libp2p.peerStore.replace.callCount).to.equal(1)
|
// Wait for peer store to be updated
|
||||||
|
await pWaitFor(() => peerStoreSpy.callCount === 1)
|
||||||
|
expect(libp2p.identifyService.identify.callCount).to.equal(1)
|
||||||
|
|
||||||
|
// The connection should have no open streams
|
||||||
|
expect(connection.streams).to.have.length(0)
|
||||||
await connection.close()
|
await connection.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -247,6 +249,9 @@ describe('Identify', () => {
|
|||||||
const results = await call.returnValue
|
const results = await call.returnValue
|
||||||
expect(results.length).to.equal(1)
|
expect(results.length).to.equal(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify the streams close
|
||||||
|
await pWaitFor(() => connection.streams.length === 0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user