Compare commits

..

3 Commits

Author SHA1 Message Date
Jacob Heun
b2c02d0923 0.24.0-rc.2 2018-10-25 16:52:35 +02:00
Jacob Heun
f266fba843 chore: update switch version 2018-10-25 16:51:14 +02:00
Jacob Heun
c12fff0506 0.24.0-rc.1 2018-10-19 17:44:50 +02:00
84 changed files with 897 additions and 2324 deletions

View File

@@ -1,16 +1,15 @@
'use strict' 'use strict'
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const pull = require('pull-stream') const pull = require('pull-stream')
const parallel = require('async/parallel') const parallel = require('async/parallel')
const WebSocketStarRendezvous = require('libp2p-websocket-star-rendezvous') const WebSocketStarRendezvous = require('libp2p-websocket-star-rendezvous')
const sigServer = require('libp2p-webrtc-star/src/sig-server') const sigServer = require('libp2p-webrtc-star/src/sig-server')
const rawPeer = require('./test/fixtures/test-peer.json')
const Node = require('./test/utils/bundle-nodejs.js') const Node = require('./test/utils/bundle-nodejs.js')
const {
getPeerRelay,
WRTC_RENDEZVOUS_MULTIADDR,
WS_RENDEZVOUS_MULTIADDR
} = require('./test/utils/constants')
let wrtcRendezvous let wrtcRendezvous
let wsRendezvous let wsRendezvous
@@ -20,18 +19,19 @@ const before = (done) => {
parallel([ parallel([
(cb) => { (cb) => {
sigServer.start({ sigServer.start({
port: WRTC_RENDEZVOUS_MULTIADDR.nodeAddress().port port: 15555
// cryptoChallenge: true TODO: needs https://github.com/libp2p/js-libp2p-webrtc-star/issues/128 // cryptoChallenge: true TODO: needs https://github.com/libp2p/js-libp2p-webrtc-star/issues/128
}) }, (err, server) => {
.then(server => { if (err) {
return cb(err)
}
wrtcRendezvous = server wrtcRendezvous = server
cb() cb()
}) })
.catch(cb)
}, },
(cb) => { (cb) => {
WebSocketStarRendezvous.start({ WebSocketStarRendezvous.start({
port: WS_RENDEZVOUS_MULTIADDR.nodeAddress().port, port: 14444,
refreshPeerListIntervalMS: 1000, refreshPeerListIntervalMS: 1000,
strictMultiaddr: false, strictMultiaddr: false,
cryptoChallenge: true cryptoChallenge: true
@@ -44,24 +44,17 @@ const before = (done) => {
}) })
}, },
(cb) => { (cb) => {
getPeerRelay((err, peerInfo) => { PeerId.createFromJSON(rawPeer, (err, peerId) => {
if (err) { if (err) {
return done(err) return done(err)
} }
const peer = new PeerInfo(peerId)
peer.multiaddrs.add('/ip4/127.0.0.1/tcp/9200/ws')
node = new Node({ node = new Node({
peerInfo, peerInfo: peer
config: {
relay: {
enabled: true,
hop: {
enabled: true,
active: true
}
}
}
}) })
node.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn)) node.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn))
node.start(cb) node.start(cb)
}) })
@@ -71,16 +64,13 @@ const before = (done) => {
const after = (done) => { const after = (done) => {
setTimeout(() => setTimeout(() =>
parallel([ parallel(
(cb) => wrtcRendezvous.stop().then(cb).catch(cb), [node, wrtcRendezvous, wsRendezvous].map((s) => (cb) => s.stop(cb)),
...[node, wsRendezvous].map((s) => (cb) => s.stop(cb)), done),
], done), 2000)
2000
)
} }
module.exports = { module.exports = {
bundlesize: { maxSize: '220kB' },
hooks: { hooks: {
pre: before, pre: before,
post: after post: after

1
.gitignore vendored
View File

@@ -41,4 +41,3 @@ test/test-data/go-ipfs-repo/LOG.old
# while testing npm5 # while testing npm5
package-lock.json package-lock.json
yarn.lock

37
.npmignore Normal file
View File

@@ -0,0 +1,37 @@
**/node_modules/
**/*.log
test/repo-tests*
img
docs
examples
# Logs
logs
*.log
coverage
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
build
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
test

View File

@@ -1,44 +0,0 @@
language: node_js
cache: npm
stages:
- check
- test
- cov
node_js:
- '10'
- '12'
os:
- linux
- osx
script: npx nyc -s npm run test:node -- --bail
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov
jobs:
include:
- stage: check
script:
- npx aegir build --bundlesize
- npx aegir dep-check -- -i wrtc -i electron-webrtc
- npm run lint
- stage: test
name: chrome
addons:
chrome: stable
script:
- npx aegir test -t browser
- npx aegir test -t webworker
- stage: test
name: firefox
addons:
firefox: latest
script:
- npx aegir test -t browser -- --browsers FirefoxHeadless
- npx aegir test -t webworker -- --browsers FirefoxHeadless
notifications:
email: false

View File

@@ -1,177 +1,3 @@
<a name="0.25.4"></a>
## [0.25.4](https://github.com/libp2p/js-libp2p/compare/v0.25.3...v0.25.4) (2019-06-07)
### Features
* add createLibp2p to generate a PeerInfo instance ([#367](https://github.com/libp2p/js-libp2p/issues/367)) ([04faf18](https://github.com/libp2p/js-libp2p/commit/04faf18))
* pass libp2p as option to transport creation ([#363](https://github.com/libp2p/js-libp2p/issues/363)) ([b06ca1b](https://github.com/libp2p/js-libp2p/commit/b06ca1b))
<a name="0.25.3"></a>
## [0.25.3](https://github.com/libp2p/js-libp2p/compare/v0.25.2...v0.25.3) (2019-05-07)
### Features
* sign pubsub messages ([#362](https://github.com/libp2p/js-libp2p/issues/362)) ([40978a1](https://github.com/libp2p/js-libp2p/commit/40978a1))
<a name="0.25.2"></a>
## [0.25.2](https://github.com/libp2p/js-libp2p/compare/v0.25.1...v0.25.2) (2019-04-17)
### Bug Fixes
* dht config ([#359](https://github.com/libp2p/js-libp2p/issues/359)) ([f3801f0](https://github.com/libp2p/js-libp2p/commit/f3801f0))
<a name="0.25.1"></a>
## [0.25.1](https://github.com/libp2p/js-libp2p/compare/v0.25.0...v0.25.1) (2019-04-16)
### Bug Fixes
* bail when discovering self ([#357](https://github.com/libp2p/js-libp2p/issues/357)) ([f28dffb](https://github.com/libp2p/js-libp2p/commit/f28dffb))
<a name="0.25.0"></a>
# [0.25.0](https://github.com/libp2p/js-libp2p/compare/v0.25.0-rc.6...v0.25.0) (2019-04-12)
### Bug Fixes
* allow switch to be configured ([#354](https://github.com/libp2p/js-libp2p/issues/354)) ([eb5aa03](https://github.com/libp2p/js-libp2p/commit/eb5aa03))
<a name="0.25.0-rc.6"></a>
# [0.25.0-rc.6](https://github.com/libp2p/js-libp2p/compare/v0.25.0-rc.5...v0.25.0-rc.6) (2019-04-11)
### Bug Fixes
* connection emits ([#352](https://github.com/libp2p/js-libp2p/issues/352)) ([313b1ea](https://github.com/libp2p/js-libp2p/commit/313b1ea))
* remove unneeded peerbook puts ([#348](https://github.com/libp2p/js-libp2p/issues/348)) ([e5f19e8](https://github.com/libp2p/js-libp2p/commit/e5f19e8))
### Features
* auto dial discovered peers ([#349](https://github.com/libp2p/js-libp2p/issues/349)) ([01aa447](https://github.com/libp2p/js-libp2p/commit/01aa447))
<a name="0.25.0-rc.5"></a>
# [0.25.0-rc.5](https://github.com/libp2p/js-libp2p/compare/v0.25.0-rc.4...v0.25.0-rc.5) (2019-03-21)
### Bug Fixes
* disable dht by default [#338](https://github.com/libp2p/js-libp2p/issues/338) ([#339](https://github.com/libp2p/js-libp2p/issues/339)) ([e52ce66](https://github.com/libp2p/js-libp2p/commit/e52ce66))
### Features
* update to the latest switch ([#336](https://github.com/libp2p/js-libp2p/issues/336)) ([eee60ed](https://github.com/libp2p/js-libp2p/commit/eee60ed))
<a name="0.25.0-rc.4"></a>
# [0.25.0-rc.4](https://github.com/libp2p/js-libp2p/compare/v0.25.0-rc.3...v0.25.0-rc.4) (2019-03-06)
<a name="0.25.0-rc.3"></a>
# [0.25.0-rc.3](https://github.com/libp2p/js-libp2p/compare/v0.25.0-rc.2...v0.25.0-rc.3) (2019-02-26)
<a name="0.25.0-rc.2"></a>
# [0.25.0-rc.2](https://github.com/libp2p/js-libp2p/compare/v0.25.0-rc.1...v0.25.0-rc.2) (2019-02-26)
### Bug Fixes
* make the config less restrictive ([#329](https://github.com/libp2p/js-libp2p/issues/329)) ([5f92acd](https://github.com/libp2p/js-libp2p/commit/5f92acd))
<a name="0.25.0-rc.1"></a>
# [0.25.0-rc.1](https://github.com/libp2p/js-libp2p/compare/v0.25.0-rc.0...v0.25.0-rc.1) (2019-02-21)
### Bug Fixes
* bundle-size ([#298](https://github.com/libp2p/js-libp2p/issues/298)) ([d497961](https://github.com/libp2p/js-libp2p/commit/d497961))
* emit peer discovery for dht discovery ([9e7a080](https://github.com/libp2p/js-libp2p/commit/9e7a080))
### Features
* support unsubscribe all for pubsub ([#321](https://github.com/libp2p/js-libp2p/issues/321)) ([6e76aad](https://github.com/libp2p/js-libp2p/commit/6e76aad))
<a name="0.24.4"></a>
## [0.24.4](https://github.com/libp2p/js-libp2p/compare/v0.24.3...v0.24.4) (2019-01-04)
<a name="0.24.3"></a>
## [0.24.3](https://github.com/libp2p/js-libp2p/compare/v0.24.2...v0.24.3) (2018-12-14)
### Bug Fixes
* not started yet ([#297](https://github.com/libp2p/js-libp2p/issues/297)) ([fdfb7b4](https://github.com/libp2p/js-libp2p/commit/fdfb7b4))
<a name="0.24.2"></a>
## [0.24.2](https://github.com/libp2p/js-libp2p/compare/v0.24.1...v0.24.2) (2018-12-04)
### Bug Fixes
* use symbol instead of constructor name ([#292](https://github.com/libp2p/js-libp2p/issues/292)) ([53ed3bd](https://github.com/libp2p/js-libp2p/commit/53ed3bd))
<a name="0.24.1"></a>
## [0.24.1](https://github.com/libp2p/js-libp2p/compare/v0.24.0...v0.24.1) (2018-12-03)
### Features
* allow configurable validators and selectors to the dht ([#288](https://github.com/libp2p/js-libp2p/issues/288)) ([7d12eb9](https://github.com/libp2p/js-libp2p/commit/7d12eb9))
<a name="0.24.0"></a>
# [0.24.0](https://github.com/libp2p/js-libp2p/compare/v0.24.0-rc.3...v0.24.0) (2018-11-16)
### Bug Fixes
* add maxtimeout to dht get ([#248](https://github.com/libp2p/js-libp2p/issues/248)) ([69f7264](https://github.com/libp2p/js-libp2p/commit/69f7264))
* dht get options ([4460e82](https://github.com/libp2p/js-libp2p/commit/4460e82))
* dont call callback before it's properly set ([17b5f73](https://github.com/libp2p/js-libp2p/commit/17b5f73))
* improve get peer info errors ([714b6ec](https://github.com/libp2p/js-libp2p/commit/714b6ec))
* start kad dht random walk ([#251](https://github.com/libp2p/js-libp2p/issues/251)) ([dd934b9](https://github.com/libp2p/js-libp2p/commit/dd934b9))
### Features
* add datastore to config ([40e840d](https://github.com/libp2p/js-libp2p/commit/40e840d))
* add delegated peer and content routing support ([#242](https://github.com/libp2p/js-libp2p/issues/242)) ([a95389a](https://github.com/libp2p/js-libp2p/commit/a95389a))
* add maxNumProviders to findprovs ([#283](https://github.com/libp2p/js-libp2p/issues/283)) ([970deec](https://github.com/libp2p/js-libp2p/commit/970deec))
* conditionally emit errors ([f71fdfd](https://github.com/libp2p/js-libp2p/commit/f71fdfd))
* enable relay by default (no hop) ([#254](https://github.com/libp2p/js-libp2p/issues/254)) ([686379e](https://github.com/libp2p/js-libp2p/commit/686379e))
* make libp2p a state machine ([#257](https://github.com/libp2p/js-libp2p/issues/257)) ([0b75f99](https://github.com/libp2p/js-libp2p/commit/0b75f99))
* use package-table vs custom script ([a63432e](https://github.com/libp2p/js-libp2p/commit/a63432e))
<a name="0.23.1"></a> <a name="0.23.1"></a>
## [0.23.1](https://github.com/libp2p/js-libp2p/compare/v0.23.0...v0.23.1) (2018-08-13) ## [0.23.1](https://github.com/libp2p/js-libp2p/compare/v0.23.0...v0.23.1) (2018-08-13)

View File

@@ -39,5 +39,5 @@ One of following:
This is for you! Please read, and then delete this text before posting it. This is for you! Please read, and then delete this text before posting it.
The js-ipfs issues are only for bug reports and directly actionable features. The js-ipfs issues are only for bug reports and directly actionable features.
Read https://github.com/ipfs/community/blob/master/CONTRIBUTING.md#reporting-issues if your issue doesn't fit either of those categories. Read https://github.com/ipfs/community/blob/master/contributing.md#reporting-issues if your issue doesn't fit either of those categories.
--> -->

4
OKR.md
View File

@@ -2,10 +2,6 @@
We try to frame our ongoing work using a process based on quarterly Objectives and Key Results (OKRs). Objectives reflect outcomes that are challenging, but realistic. Results are tangible and measurable. We try to frame our ongoing work using a process based on quarterly Objectives and Key Results (OKRs). Objectives reflect outcomes that are challenging, but realistic. Results are tangible and measurable.
## 2019 Q1
Find the js-libp2p OKRs for 2019 Q1 at the [2019 Q1 libp2p OKRs Spreadsheet](https://docs.google.com/spreadsheets/d/11GKG1DBRIIAiQnHvLD7_IqWxDGsVdaZFpxJM6NWtXe8/edit#gid=1271182838)
## 2018 Q4 ## 2018 Q4
Find the js-libp2p OKRs for 2018 Q4 at the [2018 Q4 libp2p OKRs Spreadsheet](https://docs.google.com/spreadsheets/d/1BYwmbVicgo6_tOHAbgiUXWge8Ej0qR1M_gAUulazmrg/edit#gid=1241853194) Find the js-libp2p OKRs for 2018 Q4 at the [2018 Q4 libp2p OKRs Spreadsheet](https://docs.google.com/spreadsheets/d/1BYwmbVicgo6_tOHAbgiUXWge8Ej0qR1M_gAUulazmrg/edit#gid=1241853194)

View File

@@ -1,60 +0,0 @@
# Peer Discovery and Auto Dial
**Synopsis**:
* All peers discovered are emitted via `peer:discovery` so applications can take any desired action.
* Libp2p defaults to automatically connecting to new peers, when under the [ConnectionManager](https://github.com/libp2p/js-libp2p-connection-manager) low watermark (minimum peers).
* Applications can disable this via the `peerDiscovery.autoDial` config property, and handle connections themselves.
* Applications who have not disabled this should **never** connect on peer discovery. Applications should use the `peer:connect` event if they wish to take a specific action on new peers.
## Scenarios
In any scenario, if a peer is discovered it should be added to the PeerBook. This ensures that even if we don't dial to a node when we discover it, we know about it in the event that it becomes known as a provider for something we need. The scenarios listed below detail what actions the auto dialer will take when peers are discovered.
### 1. Joining the network
The node is new and needs to join the network. It currently has 0 peers.
**Discovery Mechanisms**: [Ambient Discovery](#ambient-discovery)
### Action to take
Connect to discovered peers. This should have some degree of concurrency limiting. While the case should be low, if we immediately discover more peers than our high watermark we should avoid dialing them all.
### 2. Connected to some
The node is connected to other nodes. The current number of connections is less than the desired low watermark.
**Discovery Mechanisms**: [Ambient Discovery](#ambient-discovery) and [Active Discovery](#active-discovery)
### Action to take
Connect to discovered peers. This should have some degree of concurrency limiting. The concurrency may need to be modified to reflect the current number of peers connected. The more peers we have, the lower the concurrency may need to be.
### 3. Connected to enough
**Discovery Mechanisms**: [Ambient Discovery](#ambient-discovery) and [Active Discovery](#active-discovery)
### Action to take
None. If we are connected to enough peers, the low watermark, we should not connect to discovered peers. As other peers discover us, they may connect to us based on their current scenario.
For example, a long running node with adequate peers is on an MDNS network. A new peer joins the network and both become aware of each other. The new peer should be the peer that dials, as it has too few peers. The existing node has no reason to dial the new peer, but should keep a record of it in case it later becomes an important node due to its contents/capabilities.
Avoiding dials above the low watermark also allows for a pool of connections to be reserved for application specific actions, such as connecting to a specific content provider via a DHT query to find that content (ipfs-bitswap).
### 4. Connected to too many
The node has more connections than it wants. The current number of connections is greater than the high watermark.
[WIP Connection Manager v2 spec](https://github.com/libp2p/specs/pull/161)
**Discovery Mechanisms**: [Ambient Discovery](#ambient-discovery) and [Active Discovery](#active-discovery)
### Action to take
None, the `ConnectionManager` will automatically prune connections.
## Discovery Mechanisms
Means of which a libp2p node discovers other peers.
### Active Discovery
Through active use of the libp2p network, a node may discovery peers.
* Content/Peer routing (DHT, delegated, etc) provider and peer queries
* DHT random walk
* Rendezvous servers
### Ambient Discovery
Leveraging known addresses, or network discovery mechanisms, a node may discover peers outside of the bounds of the libp2p network.
* Bootstrap
* MDNS
* proximity based (bluetooth, sound, etc)

174
README.md
View File

@@ -8,14 +8,12 @@
<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://ipn.io"><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://discuss.libp2p.io"><img src="https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg" /></a>
<a href="https://waffle.io/libp2p/libp2p"><img src="https://img.shields.io/badge/pm-waffle-yellow.svg?style=flat-square" /></a> <a href="https://waffle.io/libp2p/libp2p"><img src="https://img.shields.io/badge/pm-waffle-yellow.svg?style=flat-square" /></a>
</p> </p>
<p align="center"> <p align="center">
<a href="https://travis-ci.com/libp2p/js-libp2p"><img src="https://flat.badgen.net/travis/libp2p/js-libp2p" /></a> <a href="https://ci.ipfs.team/job/libp2p/job/js-libp2p/job/master/"><img src="https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p/master" /></a>
<a href="https://codecov.io/gh/libp2p/js-libp2p"><img src="https://img.shields.io/codecov/c/github/ipfs/js-ipfs-multipart/master.svg?style=flat-square"></a> <a href="https://codecov.io/gh/libp2p/js-libp2p"><img src="https://codecov.io/gh/libp2p/js-libp2p/branch/master/graph/badge.svg"></a>
<a href="https://bundlephobia.com/result?p=ipfsd-ctl"><img src="https://flat.badgen.net/bundlephobia/minzip/ipfsd-ctl"></a>
<br> <br>
<a href="https://david-dm.org/libp2p/js-libp2p"><img src="https://david-dm.org/libp2p/js-libp2p.svg?style=flat-square" /></a> <a href="https://david-dm.org/libp2p/js-libp2p"><img src="https://david-dm.org/libp2p/js-libp2p.svg?style=flat-square" /></a>
<a href="https://github.com/feross/standard"><img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square"></a> <a href="https://github.com/feross/standard"><img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square"></a>
@@ -65,9 +63,7 @@ libp2p is the product of a long and arduous quest to understand the evolution of
We are in the process of writing better documentation, blog posts, tutorials and a formal specification. Today you can find: We are in the process of writing better documentation, blog posts, tutorials and a formal specification. Today you can find:
- [libp2p.io](https://libp2p.io) - [libp2p.io](https://libp2p.io)
- [docs.libp2p.io](https://docs.libp2p.io)
- [Specification (WIP)](https://github.com/libp2p/specs) - [Specification (WIP)](https://github.com/libp2p/specs)
- [Discussion Forums](https://discuss.libp2p.io)
- Talks - Talks
- [`libp2p <3 ethereum` at DEVCON2](https://ethereumfoundation.org/devcon/?session=libp2p) [📼 video](https://www.youtube.com/watch?v=HxueJbeMVG4) [slides](https://ethereumfoundation.org/devcon/wp-content/uploads/2016/10/libp2p-HEART-devp2p-IPFS-PLUS-Ethereum-networking.pdf) [📼 demo-1](https://ethereumfoundation.org/devcon/wp-content/uploads/2016/10/libp2p_demo1-1.mp4) [📼 demo-2](https://ethereumfoundation.org/devcon/wp-content/uploads/2016/10/libp2p_demo2-1.mp4) - [`libp2p <3 ethereum` at DEVCON2](https://ethereumfoundation.org/devcon/?session=libp2p) [📼 video](https://www.youtube.com/watch?v=HxueJbeMVG4) [slides](https://ethereumfoundation.org/devcon/wp-content/uploads/2016/10/libp2p-HEART-devp2p-IPFS-PLUS-Ethereum-networking.pdf) [📼 demo-1](https://ethereumfoundation.org/devcon/wp-content/uploads/2016/10/libp2p_demo1-1.mp4) [📼 demo-2](https://ethereumfoundation.org/devcon/wp-content/uploads/2016/10/libp2p_demo2-1.mp4)
- Articles - Articles
@@ -100,7 +96,7 @@ You can find multiple examples on the [examples folder](/examples) that will gui
### Creating your own libp2p bundle ### Creating your own libp2p bundle
The libp2p module acts as a glue for every libp2p module that you can use to create your own libp2p bundle. Creating your own libp2p bundle gives you a lot of freedom when it comes to customize it with features and default setup. We recommend creating your own libp2p bundle for the app you are developing that takes in account your needs (e.g. for a browser working version of libp2p that acts as the network layer of IPFS, we have a built one that leverages the Browser transports). The libp2p module acts as a glue for every libp2p module that you can use top create your own libp2p bundle. Creating your own libp2p bundle gives you a lot of freedom when it comes to customize it with features and default setup. We recommend creating your own libp2p bundle for the app you are developing that takes in account your needs (e.g. for a browser working version of libp2p that acts as the network layer of IPFS, we have a built one that leverages the Browser transports).
**Example:** **Example:**
@@ -111,7 +107,7 @@ The libp2p module acts as a glue for every libp2p module that you can use to cre
// crypto-channel: secio // crypto-channel: secio
// discovery: multicast-dns // discovery: multicast-dns
const Libp2p = require('libp2p') const libp2p = require('libp2p')
const TCP = require('libp2p-tcp') const TCP = require('libp2p-tcp')
const WS = require('libp2p-websockets') const WS = require('libp2p-websockets')
const SPDY = require('libp2p-spdy') const SPDY = require('libp2p-spdy')
@@ -124,7 +120,7 @@ const Protector = require('libp2p-pnet')
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing') const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
const DelegatedContentRouter = require('libp2p-delegated-content-routing') const DelegatedContentRouter = require('libp2p-delegated-content-routing')
class Node extends Libp2p { class Node extends libp2p {
constructor (_options) { constructor (_options) {
const peerInfo = _options.peerInfo const peerInfo = _options.peerInfo
const defaults = { const defaults = {
@@ -160,7 +156,6 @@ class Node extends Libp2p {
// libp2p config options (typically found on a config.json) // libp2p config options (typically found on a config.json)
config: { // The config object is the part of the config that can go into a file, config.json. config: { // The config object is the part of the config that can go into a file, config.json.
peerDiscovery: { peerDiscovery: {
autoDial: true, // Auto connect to discovered peers (limited by ConnectionManager minPeers)
mdns: { // mdns options mdns: { // mdns options
interval: 1000, // ms interval: 1000, // ms
enabled: true enabled: true
@@ -180,16 +175,12 @@ class Node extends Libp2p {
}, },
dht: { dht: {
kBucketSize: 20, kBucketSize: 20,
enabled: true, enabledDiscovery: true // Allows to disable discovery (enabled by default)
randomWalk: {
enabled: true, // Allows to disable discovery (enabled by default)
interval: 300e3,
timeout: 10e3
}
}, },
// Enable/Disable Experimental features // Enable/Disable Experimental features
EXPERIMENTAL: { // Experimental features ("behind a flag") EXPERIMENTAL: { // Experimental features ("behind a flag")
pubsub: false pubsub: false,
dht: false
} }
} }
} }
@@ -204,31 +195,13 @@ class Node extends Libp2p {
### API ### API
#### Create a Node - `Libp2p.createLibp2p(options, callback)` #### Create a Node - `new libp2p.Node(options)`
> Behaves exactly like `new Libp2p(options)`, but doesn't require a PeerInfo. One will be generated instead > Creates an instance of the libp2p.Node.
```js
const { createLibp2p } = require('libp2p')
createLibp2p(options, (err, libp2p) => {
if (err) throw err
libp2p.start((err) => {
if (err) throw err
})
})
```
- `options`: Object of libp2p configuration options
- `callback`: Function with signature `function (Error, Libp2p) {}`
#### Create a Node alternative - `new Libp2p(options)`
> Creates an instance of Libp2p with a custom `PeerInfo` provided via `options.peerInfo`.
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. - `peerInfo`: instance of [PeerInfo][] that contains the [PeerId][], Keys and [multiaddrs][multiaddr] of the libp2p Node.
- `modules.transport`: An array that must include at least 1 transport, such as `libp2p-tcp`.
#### `libp2p.start(callback)` #### `libp2p.start(callback)`
@@ -288,12 +261,12 @@ Required keys in the `options` object:
- `key`: Buffer - `key`: Buffer
- `options`: object of options - `options`: object of options
- `options.maxTimeout`: Number milliseconds - `options.maxTimeout`: Number milliseconds
- `options.maxNumProviders` maximum number of providers to find
#### `libp2p.contentRouting.provide(key, callback)` #### `libp2p.contentRouting.provide(key, callback)`
- `key`: Buffer - `key`: Buffer
#### `libp2p.handle(protocol, handlerFunc [, matchFunc])` #### `libp2p.handle(protocol, handlerFunc [, matchFunc])`
> Handle new protocol > Handle new protocol
@@ -328,32 +301,17 @@ Required keys in the `options` object:
> Peer has been discovered. > Peer has been discovered.
If `autoDial` 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.
- `peer`: instance of [PeerInfo][] - `peer`: instance of [PeerInfo][]
##### `libp2p.on('peer:connect', (peer) => {})` ##### `libp2p.on('peer:connect', (peer) => {})`
> We have a new muxed connection to a peer > We connected to a new peer
- `peer`: instance of [PeerInfo][] - `peer`: instance of [PeerInfo][]
##### `libp2p.on('peer:disconnect', (peer) => {})` ##### `libp2p.on('peer:disconnect', (peer) => {})`
> We have closed a connection to a peer > We disconnected from Peer
- `peer`: instance of [PeerInfo][]
##### `libp2p.on('connection:start', (peer) => {})`
> We created a new connection to a peer
- `peer`: instance of [PeerInfo][]
##### `libp2p.on('connection:end', (peer) => {})`
> We closed a connection to a peer
- `peer`: instance of [PeerInfo][] - `peer`: instance of [PeerInfo][]
@@ -547,6 +505,18 @@ Some available network protectors:
> npm run test:browser > npm run test:browser
``` ```
#### Run interop tests
```sh
N/A
```
#### Run benchmark tests
```sh
N/A
```
### Packages ### Packages
List of packages currently in existence for libp2p List of packages currently in existence for libp2p
@@ -556,66 +526,66 @@ List of packages currently in existence for libp2p
| Package | Version | Deps | CI | Coverage | Lead Maintainer | | Package | Version | Deps | CI | Coverage | Lead Maintainer |
| ---------|---------|---------|---------|---------|--------- | | ---------|---------|---------|---------|---------|--------- |
| **Libp2p** | | **Libp2p** |
| [`interface-libp2p`](//github.com/libp2p/interface-libp2p) | [![npm](https://img.shields.io/npm/v/interface-libp2p.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-libp2p/releases) | [![Deps](https://david-dm.org/libp2p/interface-libp2p.svg?style=flat-square)](https://david-dm.org/libp2p/interface-libp2p) | [![Travis CI](https://travis-ci.com/libp2p/interface-libp2p.svg?branch=master)](https://travis-ci.com/libp2p/interface-libp2p) | [![codecov](https://codecov.io/gh/libp2p/interface-libp2p/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-libp2p) | N/A | | [`interface-libp2p`](//github.com/libp2p/interface-libp2p) | [![npm](https://img.shields.io/npm/v/interface-libp2p.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-libp2p/releases) | [![Deps](https://david-dm.org/libp2p/interface-libp2p.svg?style=flat-square)](https://david-dm.org/libp2p/interface-libp2p) | N/A | [![codecov](https://codecov.io/gh/libp2p/interface-libp2p/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-libp2p) | N/A |
| [`libp2p`](//github.com/libp2p/js-libp2p) | [![npm](https://img.shields.io/npm/v/libp2p.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p`](//github.com/libp2p/js-libp2p) | [![npm](https://img.shields.io/npm/v/libp2p.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p) | [Jacob Heun](mailto:jacobheun@gmail.com) |
| **Connection** | | **Connection** |
| [`interface-connection`](//github.com/libp2p/interface-connection) | [![npm](https://img.shields.io/npm/v/interface-connection.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-connection/releases) | [![Deps](https://david-dm.org/libp2p/interface-connection.svg?style=flat-square)](https://david-dm.org/libp2p/interface-connection) | [![Travis CI](https://travis-ci.com/libp2p/interface-connection.svg?branch=master)](https://travis-ci.com/libp2p/interface-connection) | [![codecov](https://codecov.io/gh/libp2p/interface-connection/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-connection) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`interface-connection`](//github.com/libp2p/interface-connection) | [![npm](https://img.shields.io/npm/v/interface-connection.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-connection/releases) | [![Deps](https://david-dm.org/libp2p/interface-connection.svg?style=flat-square)](https://david-dm.org/libp2p/interface-connection) | N/A | [![codecov](https://codecov.io/gh/libp2p/interface-connection/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-connection) | N/A |
| **Transport** | | **Transport** |
| [`interface-transport`](//github.com/libp2p/interface-transport) | [![npm](https://img.shields.io/npm/v/interface-transport.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-transport/releases) | [![Deps](https://david-dm.org/libp2p/interface-transport.svg?style=flat-square)](https://david-dm.org/libp2p/interface-transport) | [![Travis CI](https://travis-ci.com/libp2p/interface-transport.svg?branch=master)](https://travis-ci.com/libp2p/interface-transport) | [![codecov](https://codecov.io/gh/libp2p/interface-transport/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-transport) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`interface-transport`](//github.com/libp2p/interface-transport) | [![npm](https://img.shields.io/npm/v/interface-transport.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-transport/releases) | [![Deps](https://david-dm.org/libp2p/interface-transport.svg?style=flat-square)](https://david-dm.org/libp2p/interface-transport) | N/A | [![codecov](https://codecov.io/gh/libp2p/interface-transport/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-transport) | N/A |
| [`libp2p-tcp`](//github.com/libp2p/js-libp2p-tcp) | [![npm](https://img.shields.io/npm/v/libp2p-tcp.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-tcp/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-tcp.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-tcp) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-tcp.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-tcp) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-tcp/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-tcp) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-tcp`](//github.com/libp2p/js-libp2p-tcp) | [![npm](https://img.shields.io/npm/v/libp2p-tcp.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-tcp/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-tcp.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-tcp) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-tcp/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-tcp/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-tcp/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-tcp) | [Jacob Heun](mailto:jacobheun@gmail.com) |
| [`libp2p-udp`](//github.com/libp2p/js-libp2p-udp) | [![npm](https://img.shields.io/npm/v/libp2p-udp.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-udp/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-udp.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-udp) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-udp.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-udp) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-udp/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-udp) | N/A | | [`libp2p-udp`](//github.com/libp2p/js-libp2p-udp) | [![npm](https://img.shields.io/npm/v/libp2p-udp.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-udp/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-udp.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-udp) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-udp/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-udp) | N/A |
| [`libp2p-udt`](//github.com/libp2p/js-libp2p-udt) | [![npm](https://img.shields.io/npm/v/libp2p-udt.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-udt/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-udt.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-udt) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-udt.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-udt) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-udt/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-udt) | N/A | | [`libp2p-udt`](//github.com/libp2p/js-libp2p-udt) | [![npm](https://img.shields.io/npm/v/libp2p-udt.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-udt/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-udt.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-udt) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-udt/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-udt) | N/A |
| [`libp2p-utp`](//github.com/libp2p/js-libp2p-utp) | [![npm](https://img.shields.io/npm/v/libp2p-utp.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-utp/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-utp.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-utp) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-utp.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-utp) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-utp/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-utp) | N/A | | [`libp2p-utp`](//github.com/libp2p/js-libp2p-utp) | [![npm](https://img.shields.io/npm/v/libp2p-utp.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-utp/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-utp.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-utp) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-utp/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-utp/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-utp/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-utp) | N/A |
| [`libp2p-webrtc-direct`](//github.com/libp2p/js-libp2p-webrtc-direct) | [![npm](https://img.shields.io/npm/v/libp2p-webrtc-direct.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-webrtc-direct/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-webrtc-direct.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-webrtc-direct) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-webrtc-direct.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-webrtc-direct) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-webrtc-direct/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-webrtc-direct) | [Vasco Santos](mailto:vasco.santos@moxy.studio) | | [`libp2p-webrtc-direct`](//github.com/libp2p/js-libp2p-webrtc-direct) | [![npm](https://img.shields.io/npm/v/libp2p-webrtc-direct.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-webrtc-direct/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-webrtc-direct.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-webrtc-direct) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-webrtc-direct/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-webrtc-direct/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-webrtc-direct/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-webrtc-direct) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
| [`libp2p-webrtc-star`](//github.com/libp2p/js-libp2p-webrtc-star) | [![npm](https://img.shields.io/npm/v/libp2p-webrtc-star.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-webrtc-star/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-webrtc-star.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-webrtc-star) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-webrtc-star.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-webrtc-star) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-webrtc-star/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-webrtc-star) | [Vasco Santos](mailto:vasco.santos@moxy.studio) | | [`libp2p-webrtc-star`](//github.com/libp2p/js-libp2p-webrtc-star) | [![npm](https://img.shields.io/npm/v/libp2p-webrtc-star.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-webrtc-star/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-webrtc-star.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-webrtc-star) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-webrtc-star/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-webrtc-star/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-webrtc-star/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-webrtc-star) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
| [`libp2p-websockets`](//github.com/libp2p/js-libp2p-websockets) | [![npm](https://img.shields.io/npm/v/libp2p-websockets.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-websockets/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-websockets.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-websockets) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-websockets.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-websockets) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-websockets/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-websockets) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-websockets`](//github.com/libp2p/js-libp2p-websockets) | [![npm](https://img.shields.io/npm/v/libp2p-websockets.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-websockets/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-websockets.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-websockets) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-websockets/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-websockets) | N/A |
| [`libp2p-websocket-star`](//github.com/libp2p/js-libp2p-websocket-star) | [![npm](https://img.shields.io/npm/v/libp2p-websocket-star.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-websocket-star/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-websocket-star.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-websocket-star) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-websocket-star.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-websocket-star) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-websocket-star/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-websocket-star) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-websocket-star`](//github.com/libp2p/js-libp2p-websocket-star) | [![npm](https://img.shields.io/npm/v/libp2p-websocket-star.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-websocket-star/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-websocket-star.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-websocket-star) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-websocket-star/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-websocket-star) | [Jacob Heun](mailto:jacobheun@gmail.com) |
| [`libp2p-websocket-star-rendezvous`](//github.com/libp2p/js-libp2p-websocket-star-rendezvous) | [![npm](https://img.shields.io/npm/v/libp2p-websocket-star-rendezvous.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-websocket-star-rendezvous/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-websocket-star-rendezvous.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-websocket-star-rendezvous) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-websocket-star-rendezvous.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-websocket-star-rendezvous) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-websocket-star-rendezvous/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-websocket-star-rendezvous) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-websocket-star-rendezvous`](//github.com/libp2p/js-libp2p-websocket-star-rendezvous) | [![npm](https://img.shields.io/npm/v/libp2p-websocket-star-rendezvous.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-websocket-star-rendezvous/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-websocket-star-rendezvous.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-websocket-star-rendezvous) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-websocket-star-rendezvous/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-websocket-star-rendezvous) | N/A |
| **Crypto Channels** | | **Crypto Channels** |
| [`libp2p-secio`](//github.com/libp2p/js-libp2p-secio) | [![npm](https://img.shields.io/npm/v/libp2p-secio.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-secio/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-secio.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-secio) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-secio.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-secio) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-secio/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-secio) | [Friedel Ziegelmayer](mailto:dignifiedquire@gmail.com) | | [`libp2p-secio`](//github.com/libp2p/js-libp2p-secio) | [![npm](https://img.shields.io/npm/v/libp2p-secio.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-secio/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-secio.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-secio) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-secio/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-secio) | N/A |
| **Stream Muxers** | | **Stream Muxers** |
| [`interface-stream-muxer`](//github.com/libp2p/interface-stream-muxer) | [![npm](https://img.shields.io/npm/v/interface-stream-muxer.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-stream-muxer/releases) | [![Deps](https://david-dm.org/libp2p/interface-stream-muxer.svg?style=flat-square)](https://david-dm.org/libp2p/interface-stream-muxer) | [![Travis CI](https://travis-ci.com/libp2p/interface-stream-muxer.svg?branch=master)](https://travis-ci.com/libp2p/interface-stream-muxer) | [![codecov](https://codecov.io/gh/libp2p/interface-stream-muxer/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-stream-muxer) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`interface-stream-muxer`](//github.com/libp2p/interface-stream-muxer) | [![npm](https://img.shields.io/npm/v/interface-stream-muxer.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-stream-muxer/releases) | [![Deps](https://david-dm.org/libp2p/interface-stream-muxer.svg?style=flat-square)](https://david-dm.org/libp2p/interface-stream-muxer) | N/A | [![codecov](https://codecov.io/gh/libp2p/interface-stream-muxer/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-stream-muxer) | N/A |
| [`libp2p-mplex`](//github.com/libp2p/js-libp2p-mplex) | [![npm](https://img.shields.io/npm/v/libp2p-mplex.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-mplex/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-mplex.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-mplex) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-mplex.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-mplex) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-mplex/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-mplex) | [Vasco Santos](mailto:vasco.santos@moxy.studio) | | [`libp2p-mplex`](//github.com/libp2p/js-libp2p-mplex) | [![npm](https://img.shields.io/npm/v/libp2p-mplex.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-mplex/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-mplex.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-mplex) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-mplex/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-mplex) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
| [`libp2p-spdy`](//github.com/libp2p/js-libp2p-spdy) | [![npm](https://img.shields.io/npm/v/libp2p-spdy.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-spdy/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-spdy.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-spdy) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-spdy.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-spdy) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-spdy/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-spdy) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-spdy`](//github.com/libp2p/js-libp2p-spdy) | [![npm](https://img.shields.io/npm/v/libp2p-spdy.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-spdy/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-spdy.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-spdy) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-spdy/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-spdy/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-spdy/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-spdy) | N/A |
| **Discovery** | | **Discovery** |
| [`interface-peer-discovery`](//github.com/libp2p/interface-peer-discovery) | [![npm](https://img.shields.io/npm/v/interface-peer-discovery.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-peer-discovery/releases) | [![Deps](https://david-dm.org/libp2p/interface-peer-discovery.svg?style=flat-square)](https://david-dm.org/libp2p/interface-peer-discovery) | [![Travis CI](https://travis-ci.com/libp2p/interface-peer-discovery.svg?branch=master)](https://travis-ci.com/libp2p/interface-peer-discovery) | [![codecov](https://codecov.io/gh/libp2p/interface-peer-discovery/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-peer-discovery) | N/A | | [`interface-peer-discovery`](//github.com/libp2p/interface-peer-discovery) | [![npm](https://img.shields.io/npm/v/interface-peer-discovery.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-peer-discovery/releases) | [![Deps](https://david-dm.org/libp2p/interface-peer-discovery.svg?style=flat-square)](https://david-dm.org/libp2p/interface-peer-discovery) | N/A | [![codecov](https://codecov.io/gh/libp2p/interface-peer-discovery/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-peer-discovery) | N/A |
| [`libp2p-bootstrap`](//github.com/libp2p/js-libp2p-bootstrap) | [![npm](https://img.shields.io/npm/v/libp2p-bootstrap.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-bootstrap/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-bootstrap.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-bootstrap) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-bootstrap.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-bootstrap) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-bootstrap/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-bootstrap) | [Vasco Santos](mailto:vasco.santos@moxy.studio) | | [`libp2p-bootstrap`](//github.com/libp2p/js-libp2p-bootstrap) | [![npm](https://img.shields.io/npm/v/libp2p-bootstrap.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-bootstrap/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-bootstrap.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-bootstrap) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-bootstrap/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-bootstrap/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-bootstrap/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-bootstrap) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
| [`libp2p-kad-dht`](//github.com/libp2p/js-libp2p-kad-dht) | [![npm](https://img.shields.io/npm/v/libp2p-kad-dht.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-kad-dht/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-kad-dht.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-kad-dht) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-kad-dht.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-kad-dht) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-kad-dht/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) | [Vasco Santos](mailto:vasco.santos@moxy.studio) | | [`libp2p-kad-dht`](//github.com/libp2p/js-libp2p-kad-dht) | [![npm](https://img.shields.io/npm/v/libp2p-kad-dht.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-kad-dht/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-kad-dht.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-kad-dht) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-kad-dht/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-kad-dht/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-kad-dht/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
| [`libp2p-mdns`](//github.com/libp2p/js-libp2p-mdns) | [![npm](https://img.shields.io/npm/v/libp2p-mdns.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-mdns/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-mdns.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-mdns) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-mdns.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-mdns) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-mdns/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-mdns) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-mdns`](//github.com/libp2p/js-libp2p-mdns) | [![npm](https://img.shields.io/npm/v/libp2p-mdns.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-mdns/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-mdns.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-mdns) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-mdns/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-mdns/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-mdns/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-mdns) | N/A |
| [`libp2p-rendezvous`](//github.com/libp2p/js-libp2p-rendezvous) | [![npm](https://img.shields.io/npm/v/libp2p-rendezvous.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-rendezvous/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-rendezvous.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-rendezvous) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-rendezvous.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-rendezvous) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-rendezvous/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-rendezvous) | N/A | | [`libp2p-rendezvous`](//github.com/libp2p/js-libp2p-rendezvous) | [![npm](https://img.shields.io/npm/v/libp2p-rendezvous.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-rendezvous/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-rendezvous.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-rendezvous) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-rendezvous/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-rendezvous) | N/A |
| [`libp2p-webrtc-star`](//github.com/libp2p/js-libp2p-webrtc-star) | [![npm](https://img.shields.io/npm/v/libp2p-webrtc-star.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-webrtc-star/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-webrtc-star.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-webrtc-star) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-webrtc-star.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-webrtc-star) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-webrtc-star/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-webrtc-star) | [Vasco Santos](mailto:vasco.santos@moxy.studio) | | [`libp2p-webrtc-star`](//github.com/libp2p/js-libp2p-webrtc-star) | [![npm](https://img.shields.io/npm/v/libp2p-webrtc-star.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-webrtc-star/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-webrtc-star.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-webrtc-star) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-webrtc-star/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-webrtc-star/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-webrtc-star/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-webrtc-star) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
| [`libp2p-websocket-star`](//github.com/libp2p/js-libp2p-websocket-star) | [![npm](https://img.shields.io/npm/v/libp2p-websocket-star.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-websocket-star/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-websocket-star.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-websocket-star) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-websocket-star.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-websocket-star) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-websocket-star/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-websocket-star) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-websocket-star`](//github.com/libp2p/js-libp2p-websocket-star) | [![npm](https://img.shields.io/npm/v/libp2p-websocket-star.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-websocket-star/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-websocket-star.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-websocket-star) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-websocket-star/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-websocket-star) | [Jacob Heun](mailto:jacobheun@gmail.com) |
| **NAT Traversal** | | **NAT Traversal** |
| [`libp2p-circuit`](//github.com/libp2p/js-libp2p-circuit) | [![npm](https://img.shields.io/npm/v/libp2p-circuit.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-circuit/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-circuit.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-circuit) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-circuit.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-circuit) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-circuit/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-circuit) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-circuit`](//github.com/libp2p/js-libp2p-circuit) | [![npm](https://img.shields.io/npm/v/libp2p-circuit.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-circuit/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-circuit.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-circuit) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-circuit/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-circuit/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-circuit/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-circuit) | [Jacob Heun](mailto:jacobheun@gmail.com) |
| [`libp2p-nat-mngr`](//github.com/libp2p/js-libp2p-nat-mngr) | [![npm](https://img.shields.io/npm/v/libp2p-nat-mngr.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-nat-mngr/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-nat-mngr.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-nat-mngr) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-nat-mngr.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-nat-mngr) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-nat-mngr/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-nat-mngr) | N/A | | [`libp2p-nat-mngr`](//github.com/libp2p/js-libp2p-nat-mngr) | [![npm](https://img.shields.io/npm/v/libp2p-nat-mngr.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-nat-mngr/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-nat-mngr.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-nat-mngr) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-nat-mngr/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-nat-mngr) | N/A |
| **Data Types** | | **Data Types** |
| [`peer-book`](//github.com/libp2p/js-peer-book) | [![npm](https://img.shields.io/npm/v/peer-book.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-peer-book/releases) | [![Deps](https://david-dm.org/libp2p/js-peer-book.svg?style=flat-square)](https://david-dm.org/libp2p/js-peer-book) | [![Travis CI](https://travis-ci.com/libp2p/js-peer-book.svg?branch=master)](https://travis-ci.com/libp2p/js-peer-book) | [![codecov](https://codecov.io/gh/libp2p/js-peer-book/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-peer-book) | [Pedro Teixeira](mailto:i@pgte.me) | | [`peer-book`](//github.com/libp2p/js-peer-book) | [![npm](https://img.shields.io/npm/v/peer-book.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-peer-book/releases) | [![Deps](https://david-dm.org/libp2p/js-peer-book.svg?style=flat-square)](https://david-dm.org/libp2p/js-peer-book) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-peer-book/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-peer-book) | [Pedro Teixeira](mailto:i@pgte.me) |
| [`peer-id`](//github.com/libp2p/js-peer-id) | [![npm](https://img.shields.io/npm/v/peer-id.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-peer-id/releases) | [![Deps](https://david-dm.org/libp2p/js-peer-id.svg?style=flat-square)](https://david-dm.org/libp2p/js-peer-id) | [![Travis CI](https://travis-ci.com/libp2p/js-peer-id.svg?branch=master)](https://travis-ci.com/libp2p/js-peer-id) | [![codecov](https://codecov.io/gh/libp2p/js-peer-id/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-peer-id) | [Pedro Teixeira](mailto:i@pgte.me) | | [`peer-id`](//github.com/libp2p/js-peer-id) | [![npm](https://img.shields.io/npm/v/peer-id.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-peer-id/releases) | [![Deps](https://david-dm.org/libp2p/js-peer-id.svg?style=flat-square)](https://david-dm.org/libp2p/js-peer-id) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-peer-id/master)](https://ci.ipfs.team/job/libp2p/job/js-peer-id/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-peer-id/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-peer-id) | [Pedro Teixeira](mailto:i@pgte.me) |
| [`peer-info`](//github.com/libp2p/js-peer-info) | [![npm](https://img.shields.io/npm/v/peer-info.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-peer-info/releases) | [![Deps](https://david-dm.org/libp2p/js-peer-info.svg?style=flat-square)](https://david-dm.org/libp2p/js-peer-info) | [![Travis CI](https://travis-ci.com/libp2p/js-peer-info.svg?branch=master)](https://travis-ci.com/libp2p/js-peer-info) | [![codecov](https://codecov.io/gh/libp2p/js-peer-info/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-peer-info) | [Pedro Teixeira](mailto:i@pgte.me) | | [`peer-info`](//github.com/libp2p/js-peer-info) | [![npm](https://img.shields.io/npm/v/peer-info.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-peer-info/releases) | [![Deps](https://david-dm.org/libp2p/js-peer-info.svg?style=flat-square)](https://david-dm.org/libp2p/js-peer-info) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-peer-info/master)](https://ci.ipfs.team/job/libp2p/job/js-peer-info/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-peer-info/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-peer-info) | N/A |
| **Content Routing** | | **Content Routing** |
| [`interface-content-routing`](//github.com/libp2p/interface-content-routing) | [![npm](https://img.shields.io/npm/v/interface-content-routing.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-content-routing/releases) | [![Deps](https://david-dm.org/libp2p/interface-content-routing.svg?style=flat-square)](https://david-dm.org/libp2p/interface-content-routing) | [![Travis CI](https://travis-ci.com/libp2p/interface-content-routing.svg?branch=master)](https://travis-ci.com/libp2p/interface-content-routing) | [![codecov](https://codecov.io/gh/libp2p/interface-content-routing/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-content-routing) | N/A | | [`interface-content-routing`](//github.com/libp2p/interface-content-routing) | [![npm](https://img.shields.io/npm/v/interface-content-routing.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-content-routing/releases) | [![Deps](https://david-dm.org/libp2p/interface-content-routing.svg?style=flat-square)](https://david-dm.org/libp2p/interface-content-routing) | N/A | [![codecov](https://codecov.io/gh/libp2p/interface-content-routing/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-content-routing) | N/A |
| [`libp2p-delegated-content-routing`](//github.com/libp2p/js-libp2p-delegated-content-routing) | [![npm](https://img.shields.io/npm/v/libp2p-delegated-content-routing.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-delegated-content-routing/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-delegated-content-routing.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-delegated-content-routing) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-delegated-content-routing.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-delegated-content-routing) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-delegated-content-routing/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-delegated-content-routing) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-delegated-content-routing`](//github.com/libp2p/js-libp2p-delegated-content-routing) | [![npm](https://img.shields.io/npm/v/libp2p-delegated-content-routing.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-delegated-content-routing/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-delegated-content-routing.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-delegated-content-routing) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-delegated-content-routing/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-delegated-content-routing) | [Jacob Heun](mailto:jacobheun@gmail.com) |
| [`libp2p-kad-dht`](//github.com/libp2p/js-libp2p-kad-dht) | [![npm](https://img.shields.io/npm/v/libp2p-kad-dht.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-kad-dht/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-kad-dht.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-kad-dht) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-kad-dht.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-kad-dht) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-kad-dht/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) | [Vasco Santos](mailto:vasco.santos@moxy.studio) | | [`libp2p-kad-dht`](//github.com/libp2p/js-libp2p-kad-dht) | [![npm](https://img.shields.io/npm/v/libp2p-kad-dht.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-kad-dht/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-kad-dht.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-kad-dht) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-kad-dht/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-kad-dht/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-kad-dht/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
| **Peer Routing** | | **Peer Routing** |
| [`interface-peer-routing`](//github.com/libp2p/interface-peer-routing) | [![npm](https://img.shields.io/npm/v/interface-peer-routing.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-peer-routing/releases) | [![Deps](https://david-dm.org/libp2p/interface-peer-routing.svg?style=flat-square)](https://david-dm.org/libp2p/interface-peer-routing) | [![Travis CI](https://travis-ci.com/libp2p/interface-peer-routing.svg?branch=master)](https://travis-ci.com/libp2p/interface-peer-routing) | [![codecov](https://codecov.io/gh/libp2p/interface-peer-routing/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-peer-routing) | N/A | | [`interface-peer-routing`](//github.com/libp2p/interface-peer-routing) | [![npm](https://img.shields.io/npm/v/interface-peer-routing.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-peer-routing/releases) | [![Deps](https://david-dm.org/libp2p/interface-peer-routing.svg?style=flat-square)](https://david-dm.org/libp2p/interface-peer-routing) | N/A | [![codecov](https://codecov.io/gh/libp2p/interface-peer-routing/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-peer-routing) | N/A |
| [`libp2p-delegated-peer-routing`](//github.com/libp2p/js-libp2p-delegated-peer-routing) | [![npm](https://img.shields.io/npm/v/libp2p-delegated-peer-routing.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-delegated-peer-routing/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-delegated-peer-routing.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-delegated-peer-routing) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-delegated-peer-routing.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-delegated-peer-routing) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-delegated-peer-routing/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-delegated-peer-routing) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-delegated-peer-routing`](//github.com/libp2p/js-libp2p-delegated-peer-routing) | [![npm](https://img.shields.io/npm/v/libp2p-delegated-peer-routing.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-delegated-peer-routing/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-delegated-peer-routing.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-delegated-peer-routing) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-delegated-peer-routing/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-delegated-peer-routing) | [Jacob Heun](mailto:jacobheun@gmail.com) |
| [`libp2p-kad-dht`](//github.com/libp2p/js-libp2p-kad-dht) | [![npm](https://img.shields.io/npm/v/libp2p-kad-dht.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-kad-dht/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-kad-dht.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-kad-dht) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-kad-dht.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-kad-dht) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-kad-dht/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) | [Vasco Santos](mailto:vasco.santos@moxy.studio) | | [`libp2p-kad-dht`](//github.com/libp2p/js-libp2p-kad-dht) | [![npm](https://img.shields.io/npm/v/libp2p-kad-dht.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-kad-dht/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-kad-dht.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-kad-dht) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-kad-dht/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-kad-dht/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-kad-dht/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
| **Record Store** | | **Record Store** |
| [`interface-record-store`](//github.com/libp2p/interface-record-store) | [![npm](https://img.shields.io/npm/v/interface-record-store.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-record-store/releases) | [![Deps](https://david-dm.org/libp2p/interface-record-store.svg?style=flat-square)](https://david-dm.org/libp2p/interface-record-store) | [![Travis CI](https://travis-ci.com/libp2p/interface-record-store.svg?branch=master)](https://travis-ci.com/libp2p/interface-record-store) | [![codecov](https://codecov.io/gh/libp2p/interface-record-store/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-record-store) | N/A | | [`interface-record-store`](//github.com/libp2p/interface-record-store) | [![npm](https://img.shields.io/npm/v/interface-record-store.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/interface-record-store/releases) | [![Deps](https://david-dm.org/libp2p/interface-record-store.svg?style=flat-square)](https://david-dm.org/libp2p/interface-record-store) | N/A | [![codecov](https://codecov.io/gh/libp2p/interface-record-store/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/interface-record-store) | N/A |
| [`libp2p-record`](//github.com/libp2p/js-libp2p-record) | [![npm](https://img.shields.io/npm/v/libp2p-record.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-record/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-record.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-record) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-record.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-record) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-record/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-record) | [Vasco Santos](mailto:vasco.santos@moxy.studio) | | [`libp2p-record`](//github.com/libp2p/js-libp2p-record) | [![npm](https://img.shields.io/npm/v/libp2p-record.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-record/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-record.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-record) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-record/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-record/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-record/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-record) | N/A |
| **Generics** | | **Generics** |
| [`libp2p-connection-manager`](//github.com/libp2p/js-libp2p-connection-manager) | [![npm](https://img.shields.io/npm/v/libp2p-connection-manager.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-connection-manager/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-connection-manager.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-connection-manager) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-connection-manager.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-connection-manager) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-connection-manager/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-connection-manager) | N/A | | [`libp2p-connection-manager`](//github.com/libp2p/js-libp2p-connection-manager) | [![npm](https://img.shields.io/npm/v/libp2p-connection-manager.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-connection-manager/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-connection-manager.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-connection-manager) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-connection-manager/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-connection-manager) | N/A |
| [`libp2p-crypto`](//github.com/libp2p/js-libp2p-crypto) | [![npm](https://img.shields.io/npm/v/libp2p-crypto.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-crypto/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-crypto.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-crypto) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-crypto.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-crypto) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-crypto/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-crypto) | [Friedel Ziegelmayer](mailto:dignifiedquire@gmail.com) | | [`libp2p-crypto`](//github.com/libp2p/js-libp2p-crypto) | [![npm](https://img.shields.io/npm/v/libp2p-crypto.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-crypto/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-crypto.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-crypto) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-crypto/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-crypto/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-crypto/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-crypto) | [Friedel Ziegelmayer](mailto:dignifiedquire@gmail.com) |
| [`libp2p-crypto-secp256k1`](//github.com/libp2p/js-libp2p-crypto-secp256k1) | [![npm](https://img.shields.io/npm/v/libp2p-crypto-secp256k1.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-crypto-secp256k1/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-crypto-secp256k1.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-crypto-secp256k1) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-crypto-secp256k1.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-crypto-secp256k1) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-crypto-secp256k1/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-crypto-secp256k1) | [Friedel Ziegelmayer](mailto:dignifiedquire@gmail.com) | | [`libp2p-crypto-secp256k1`](//github.com/libp2p/js-libp2p-crypto-secp256k1) | [![npm](https://img.shields.io/npm/v/libp2p-crypto-secp256k1.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-crypto-secp256k1/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-crypto-secp256k1.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-crypto-secp256k1) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-crypto-secp256k1/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-crypto-secp256k1/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-crypto-secp256k1/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-crypto-secp256k1) | N/A |
| [`libp2p-switch`](//github.com/libp2p/js-libp2p-switch) | [![npm](https://img.shields.io/npm/v/libp2p-switch.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-switch/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-switch.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-switch) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-switch.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-switch) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-switch/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-switch) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-switch`](//github.com/libp2p/js-libp2p-switch) | [![npm](https://img.shields.io/npm/v/libp2p-switch.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-switch/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-switch.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-switch) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-switch/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-switch/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-switch/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-switch) | [Jacob Heun](mailto:jacobheun@gmail.com) |
| **Extensions** | | **Extensions** |
| [`libp2p-floodsub`](//github.com/libp2p/js-libp2p-floodsub) | [![npm](https://img.shields.io/npm/v/libp2p-floodsub.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-floodsub/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-floodsub.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-floodsub) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-floodsub.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-floodsub) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-floodsub/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-floodsub) | [Vasco Santos](mailto:vasco.santos@moxy.studio) | | [`libp2p-floodsub`](//github.com/libp2p/js-libp2p-floodsub) | [![npm](https://img.shields.io/npm/v/libp2p-floodsub.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-floodsub/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-floodsub.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-floodsub) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-floodsub/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-floodsub) | N/A |
| [`libp2p-identify`](//github.com/libp2p/js-libp2p-identify) | [![npm](https://img.shields.io/npm/v/libp2p-identify.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-identify/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-identify.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-identify) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-identify.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-identify) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-identify/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-identify) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-identify`](//github.com/libp2p/js-libp2p-identify) | [![npm](https://img.shields.io/npm/v/libp2p-identify.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-identify/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-identify.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-identify) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-identify/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-identify) | [Jacob Heun](mailto:jacobheun@gmail.com) |
| [`libp2p-keychain`](//github.com/libp2p/js-libp2p-keychain) | [![npm](https://img.shields.io/npm/v/libp2p-keychain.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-keychain/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-keychain.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-keychain) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-keychain.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-keychain) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-keychain/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-keychain) | [Vasco Santos](mailto:vasco.santos@moxy.studio) | | [`libp2p-keychain`](//github.com/libp2p/js-libp2p-keychain) | [![npm](https://img.shields.io/npm/v/libp2p-keychain.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-keychain/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-keychain.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-keychain) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-keychain/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-keychain) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
| [`libp2p-ping`](//github.com/libp2p/js-libp2p-ping) | [![npm](https://img.shields.io/npm/v/libp2p-ping.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-ping/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-ping.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-ping) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-ping.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-ping) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-ping/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-ping) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-ping`](//github.com/libp2p/js-libp2p-ping) | [![npm](https://img.shields.io/npm/v/libp2p-ping.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-ping/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-ping.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-ping) | [![jenkins](https://ci.ipfs.team/buildStatus/icon?job=libp2p/js-libp2p-ping/master)](https://ci.ipfs.team/job/libp2p/job/js-libp2p-ping/job/master/) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-ping/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-ping) | N/A |
| [`libp2p-pnet`](//github.com/libp2p/js-libp2p-pnet) | [![npm](https://img.shields.io/npm/v/libp2p-pnet.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-pnet/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-pnet.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-pnet) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-pnet.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-pnet) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-pnet/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-pnet) | [Jacob Heun](mailto:jacobheun@gmail.com) | | [`libp2p-pnet`](//github.com/libp2p/js-libp2p-pnet) | [![npm](https://img.shields.io/npm/v/libp2p-pnet.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-libp2p-pnet/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-pnet.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-pnet) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-pnet/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-pnet) | [Jacob Heun](mailto:jacobheun@gmail.com) |
| **Utilities** | | **Utilities** |
| [`p2pcat`](//github.com/libp2p/js-p2pcat) | [![npm](https://img.shields.io/npm/v/p2pcat.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-p2pcat/releases) | [![Deps](https://david-dm.org/libp2p/js-p2pcat.svg?style=flat-square)](https://david-dm.org/libp2p/js-p2pcat) | [![Travis CI](https://travis-ci.com/libp2p/js-p2pcat.svg?branch=master)](https://travis-ci.com/libp2p/js-p2pcat) | [![codecov](https://codecov.io/gh/libp2p/js-p2pcat/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-p2pcat) | N/A | | [`p2pcat`](//github.com/libp2p/js-p2pcat) | [![npm](https://img.shields.io/npm/v/p2pcat.svg?maxAge=86400&style=flat-square)](//github.com/libp2p/js-p2pcat/releases) | [![Deps](https://david-dm.org/libp2p/js-p2pcat.svg?style=flat-square)](https://david-dm.org/libp2p/js-p2pcat) | N/A | [![codecov](https://codecov.io/gh/libp2p/js-p2pcat/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-p2pcat) | N/A |
## Contribute ## Contribute

View File

@@ -13,14 +13,6 @@
- Robustness and quality - Robustness and quality
- [ ] Ensure that all tests are passing, this includes: - [ ] Ensure that all tests are passing, this includes:
- [ ] unit - [ ] unit
- [ ] Publish a release candidate to npm
```sh
# Minor prerelease (e.g. 0.24.1 -> 0.25.0-rc.0)
$ npx aegir release --type preminor -t node -t browser --preid rc --dist-tag next
# Increment prerelease (e.g. 0.25.0-rc.0 -> 0.25.0-rc.1)
$ npx aegir release --type prerelease -t node -t browser --preid rc --dist-tag next
```
- [ ] Run tests of the following projects with the new release: - [ ] Run tests of the following projects with the new release:
- [ ] [js-ipfs](https://github.com/ipfs/js-ipfs) - [ ] [js-ipfs](https://github.com/ipfs/js-ipfs)
- Documentation - Documentation
@@ -28,31 +20,22 @@
- [ ] Ensure that all the examples run - [ ] Ensure that all the examples run
- Communication - Communication
- [ ] Create the release issue - [ ] Create the release issue
- [ ] Take a snapshot between of everyone that has contributed to this release (including its subdeps in IPFS, libp2p, IPLD and multiformats) using [`name-your-contributors`](https://www.npmjs.com/package/name-your-contributors). Generate a nice markdown list with [this script](https://gist.github.com/jacobheun/d2ff479ca991733c13cdcf688a1317e5)
- [ ] Announcements (both pre-release and post-release) - [ ] Announcements (both pre-release and post-release)
- [ ] Twitter - [ ] Twitter
- [ ] IRC - [ ] IRC
- [ ] Reddit - [ ] Reddit
- [ ] [discuss.libp2p.io](https://discuss.libp2p.io/c/news)
- [ ] Blog post - [ ] Blog post
- [ ] Copy release notes to the [GitHub Release description](https://github.com/libp2p/js-libp2p/releases)
# ❤️ Huge thank you to everyone that made this release possible
In alphabetical order, here are all the humans that contributed to the release:
- ...
# 🙌🏽 Want to contribute? # 🙌🏽 Want to contribute?
Would you like to contribute to the libp2p project and don't know how? Well, there are a few places you can get started: Would you like to contribute to the libp2p project and don't know how? Well, there are a few places you can get started:
- Check the issues with the `help wanted` label in the [libp2p repo](https://github.com/libp2p/js-libp2p/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) - Check the issues with the `help wanted` label at the Ready column in our waffle board - https://waffle.io/libp2p/js-libp2p?label=help%20wanted
- Join an IPFS All Hands, introduce yourself and let us know where you would like to contribute - https://github.com/ipfs/team-mgmt#all-hands-call - Join an IPFS All Hands, introduce yourself and let us know where you would like to contribute - https://github.com/ipfs/pm/#all-hands-call
- Hack with IPFS and show us what you made! The All Hands call is also the perfect venue for demos, join in and show us what you built - Hack with IPFS and show us what you made! The All Hands call is also the perfect venue for demos, join in and show us what you built
- Join the discussion at http://discuss.ipfs.io/ and help users finding their answers. - Join the discussion at http://discuss.ipfs.io/ and help users finding their answers.
- Join the [⚡️ⒿⓈ Core Dev Team Weekly Sync 🙌🏽 ](https://github.com/ipfs/team-mgmt/issues/650) and be part of the Sprint action! - Join the [⚡️ⒿⓈ Core Dev Team Weekly Sync 🙌🏽 ](https://github.com/ipfs/pm/issues/650) and be part of the Sprint action!
# ⁉️ Do you have questions? # ⁉️ Do you have questions?
The best place to ask your questions about libp2p, how it works and what you can do with it is at [discuss.libp2p.io](https://discuss.libp2p.io). We are also available at the #libp2p channel on Freenode. The best place to ask your questions about libp2p, how it works and what you can do with it is at [discuss.ipfs.io](http://discuss.ipfs.io). We are also available at the #libp2p channel on Freenode.

29
appveyor.yml Normal file
View File

@@ -0,0 +1,29 @@
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
version: "{build}"
environment:
matrix:
- nodejs_version: "6"
- nodejs_version: "8"
matrix:
fast_finish: true
install:
# Install Node.js
- ps: Install-Product node $env:nodejs_version
# Upgrade npm
- npm install -g npm
# Output our current versions for debugging
- node --version
- npm --version
# Install our package dependencies
- npm install
test_script:
- npm run test:node
build: off

2
ci/Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,2 @@
// Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
javascript()

22
circle.yml Normal file
View File

@@ -0,0 +1,22 @@
machine:
node:
version: 8.11.3
test:
post:
- npm run coverage -- --upload --providers coveralls
dependencies:
pre:
- google-chrome --version
- curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- for v in $(curl http://archive.ubuntu.com/ubuntu/pool/main/n/nss/ | grep "href=" | grep "libnss3.*deb\"" -o | grep -o "libnss3.*deb" | grep "3.28" | grep "14.04"); do curl -L -o $v http://archive.ubuntu.com/ubuntu/pool/main/n/nss/$v; done && rm libnss3-tools*_i386.deb libnss3-dev*_i386.deb
- sudo dpkg -i google-chrome.deb || true
- sudo dpkg -i libnss3*.deb || true
- sudo apt-get update
- sudo apt-get install -f || true
- sudo dpkg -i libnss3*.deb
- sudo apt-get install -f
- sudo apt-get install --only-upgrade lsb-base
- sudo dpkg -i google-chrome.deb
- google-chrome --version

View File

@@ -10,7 +10,8 @@ Let us know if you find any issue or if you want to contribute and add a new tut
- [Protocol and Stream Muxing](./protocol-and-stream-muxing) - [Protocol and Stream Muxing](./protocol-and-stream-muxing)
- [Encrypted Communications](./encrypted-communications) - [Encrypted Communications](./encrypted-communications)
- [Discovery Mechanisms](./discovery-mechanisms) - [Discovery Mechanisms](./discovery-mechanisms)
- [Peer and Content Routing](./peer-and-content-routing) - [Peer Routing](./peer-and-content-routing)
- [Content Routing](./peer-and-content-routing)
- [PubSub](./pubsub) - [PubSub](./pubsub)
- [NAT Traversal](./nat-traversal) - [NAT Traversal](./nat-traversal)
- Circuit Relay (future) - Circuit Relay (future)

View File

@@ -3,11 +3,11 @@
This example creates a simple chat app in your terminal. This example creates a simple chat app in your terminal.
## Setup ## Setup
1. Install the modules in the libp2p root directory, `npm install`. 1. Install the modules, `npm install`.
2. Open 2 terminal windows in the `./examples/chat/src` directory. 2. Open 2 terminal windows in the `./src` directory.
## Running ## Running
1. Run the listener in window 1, `node listener.js` 1. Run the listener in window 1, `node listener.js`
2. Run the dialer in window 2, `node dialer.js` 2. Run the dialer in window 2, `node dialer.js`
3. Type a message in either window and hit _enter_ 3. Type a message in either window and hit _enter_
4. Tell yourself secrets to your hearts content! 4. Tell youself secrets to your hearts content!

View File

@@ -46,7 +46,7 @@ async.parallel([
console.log('Dialer ready, listening on:') console.log('Dialer ready, listening on:')
peerListener.multiaddrs.forEach((ma) => { peerListener.multiaddrs.forEach((ma) => {
console.log(ma.toString() + '/p2p/' + idListener.toB58String()) console.log(ma.toString() + '/ipfs/' + idListener.toB58String())
}) })
nodeDialer.dialProtocol(peerListener, '/chat/1.0.0', (err, conn) => { nodeDialer.dialProtocol(peerListener, '/chat/1.0.0', (err, conn) => {

View File

@@ -3,7 +3,7 @@
const TCP = require('libp2p-tcp') const TCP = require('libp2p-tcp')
const MulticastDNS = require('libp2p-mdns') const MulticastDNS = require('libp2p-mdns')
const WS = require('libp2p-websockets') const WS = require('libp2p-websockets')
const Bootstrap = require('libp2p-bootstrap') const Bootstrap = require('libp2p-railing')
const spdy = require('libp2p-spdy') const spdy = require('libp2p-spdy')
const KadDHT = require('libp2p-kad-dht') const KadDHT = require('libp2p-kad-dht')
const mplex = require('libp2p-mplex') const mplex = require('libp2p-mplex')

View File

@@ -50,7 +50,7 @@ PeerId.createFromJSON(require('./peer-id-listener'), (err, idListener) => {
console.log('Listener ready, listening on:') console.log('Listener ready, listening on:')
peerListener.multiaddrs.forEach((ma) => { peerListener.multiaddrs.forEach((ma) => {
console.log(ma.toString() + '/p2p/' + idListener.toB58String()) console.log(ma.toString() + '/ipfs/' + idListener.toB58String())
}) })
}) })
}) })

View File

@@ -10,17 +10,18 @@ The starting [Libp2p Bundle](./src/libp2p-bundle.js) in this example starts by d
Once you've completed the example, you should try enabled the DHT and see what kind of results you get! You can also enable the Once you've completed the example, you should try enabled the DHT and see what kind of results you get! You can also enable the
various Peer Discovery modules and see the impact it has on your Peer count. various Peer Discovery modules and see the impact it has on your Peer count.
## Prerequisite
**NOTE**: This example is currently dependent on a clone of the [delegated routing support branch of go-ipfs](https://github.com/ipfs/go-ipfs/pull/4595).
## Running this example ## Running this example
1. Install go-ipfs locally if you dont already have it. [Install Guide](https://docs.ipfs.io/introduction/install/). 1. Install IPFS locally if you dont already have it. [Install Guide](https://docs.ipfs.io/introduction/install/)
1. Run the IPFS daemon: `ipfs daemon`. 2. Run the IPFS daemon: `ipfs daemon`
1. The daemon will output a line about its API address, like `API server listening on /ip4/127.0.0.1/tcp/8080`. 3. The daemon will output a line about its API address, like `API server listening on /ip4/127.0.0.1/tcp/8080`
1. In another window, while the daemon is running, Configure the IPFS Gateway to support delegate routing `ipfs config Gateway.APICommands --json '["dht/findprovs", "dht/findpeer", "refs", "swarm/connect"]'`. 4. In another window output the addresses of the node: `ipfs id`. Make note of the websocket address, is will contain `/ws/` in the address.
1. In the same window, output the addresses of the node: `ipfs id`. Make note of the websocket address, it will contain `/ws` in the address, like `/ip4/127.0.0.1/tcp/8081/ws`. 5. In `./src/libp2p-bundle.js` replace the `delegatedApiOptions` host and port of your node if they are different.
1. In `./src/libp2p-bundle.js` check if the host and port of your node are correct, according to the previous step. If they are different, replace them. 6. In `./src/App.js` replace `BootstrapNode` with your nodes Websocket address from step 4.
1. In `./src/App.js` replace `BootstrapNode` with your nodes Websocket address from step 3. **Also**, in `./src/App.js` set BootstrapNodeID to your nodes id, which is displayed when running `ipfs id` in the `ID` property. 7. Start this example:
1. Start this example:
```sh ```sh
npm install npm install
@@ -46,12 +47,3 @@ This will do a few things:
2. Copy one of the CIDs from the list of peer addresses, this will be the last portion of the address and will look something like `QmdoG8DpzYUZMVP5dGmgmigZwR1RE8Cf6SxMPg1SBXJAQ8`. 2. Copy one of the CIDs from the list of peer addresses, this will be the last portion of the address and will look something like `QmdoG8DpzYUZMVP5dGmgmigZwR1RE8Cf6SxMPg1SBXJAQ8`.
3. In your browser, paste the CID into the *Peer* field and hit `Find`. 3. In your browser, paste the CID into the *Peer* field and hit `Find`.
4. You should see information about the peer including its addresses. 4. You should see information about the peer including its addresses.
### Adding Content via the Delegate
1. In one browser, such as Firefox, enter some text in the `Add Data` field and click `Add`.
2. Once added, JSON will be printed in the browser. Copy the value of `"hash"`.
3. Close your Firefox tab. Open a new browser window in a **different** browser, such as Chrome.
4. In the new window, copy the hash from step 2 into the `Hash` field and click `Find`.
5. The text you entered in step 1 should display.
**Note**: By closing the first window before fetching the content, you are ensuring that data cannot be retrieved from it, and instead the delegate must be relied on.

View File

@@ -3,27 +3,21 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"ipfs": "~0.36.1", "ipfs": "~0.32.2",
"libp2p": "github:libp2p/js-libp2p#master", "libp2p": "../../",
"libp2p-delegated-content-routing": "~0.2.2", "libp2p-delegated-content-routing": "~0.2.2",
"libp2p-delegated-peer-routing": "~0.2.2", "libp2p-delegated-peer-routing": "~0.2.2",
"libp2p-kad-dht": "~0.15.0", "libp2p-kad-dht": "~0.10.4",
"libp2p-secio": "~0.11.1", "libp2p-mplex": "~0.8.0",
"libp2p-webrtc-star": "~0.16.1", "libp2p-secio": "~0.10.0",
"libp2p-websocket-star": "~0.10.2", "libp2p-webrtc-star": "~0.15.5",
"libp2p-websockets": "~0.12.2", "libp2p-websocket-star": "~0.8.1",
"pull-mplex": "~0.1.2", "libp2p-websockets": "~0.12.0",
"react": "^16.8.6", "react": "^16.5.2",
"react-dom": "^16.8.6", "react-dom": "^16.5.2",
"react-scripts": "2.1.8" "react-scripts": "1.1.5"
}, },
"scripts": { "scripts": {
"start": "react-scripts start" "start": "react-scripts start"
}, }
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
} }

View File

@@ -1,15 +1,13 @@
// eslint-disable-next-line // eslint-disable-next-line
'use strict' 'use strict'
import React from 'react' const React = require('react')
import Ipfs from 'ipfs'
import libp2pBundle from './libp2p-bundle'
const Component = React.Component const Component = React.Component
const Ipfs = require('ipfs')
const libp2pBundle = require('./libp2p-bundle')
// require('./App.css')
/* TODO: Add your go IPFS nodes ID here by running `ipfs id` */ const BootstrapNode = '/ip4/127.0.0.1/tcp/8081/ws/ipfs/QmdoG8DpzYUZMVP5dGmgmigZwR1RE8Cf6SxMPg1SBXJAQ8'
const BootstrapNodeID = 'Qm...'
/* TODO: Ensure the IP and port match your nodes Websocket address shown when running the daemon `ipfs daemon` */
const BootstrapNode = `/ip4/127.0.0.1/tcp/8081/ws/p2p/${BootstrapNodeID}`
class App extends Component { class App extends Component {
constructor (props) { constructor (props) {
@@ -20,7 +18,6 @@ class App extends Component {
hash: 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB', hash: 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB',
// This peer is one of the Bootstrap nodes for IPFS // This peer is one of the Bootstrap nodes for IPFS
peer: 'QmV6kA2fB8kTr6jc3pL5zbNsjKbmPUHAPKKHRBYe1kDEyc', peer: 'QmV6kA2fB8kTr6jc3pL5zbNsjKbmPUHAPKKHRBYe1kDEyc',
data: '',
isLoading: 0 isLoading: 0
} }
this.peerInterval = null this.peerInterval = null
@@ -29,8 +26,6 @@ class App extends Component {
this.handleHashSubmit = this.handleHashSubmit.bind(this) this.handleHashSubmit = this.handleHashSubmit.bind(this)
this.handlePeerChange = this.handlePeerChange.bind(this) this.handlePeerChange = this.handlePeerChange.bind(this)
this.handlePeerSubmit = this.handlePeerSubmit.bind(this) this.handlePeerSubmit = this.handlePeerSubmit.bind(this)
this.handleDataChange = this.handleDataChange.bind(this)
this.handleDataSubmit = this.handleDataSubmit.bind(this)
} }
handleHashChange (event) { handleHashChange (event) {
@@ -43,11 +38,6 @@ class App extends Component {
peer: event.target.value peer: event.target.value
}) })
} }
handleDataChange (event) {
this.setState({
data: event.target.value
})
}
handleHashSubmit (event) { handleHashSubmit (event) {
event.preventDefault() event.preventDefault()
@@ -55,7 +45,7 @@ class App extends Component {
isLoading: this.state.isLoading + 1 isLoading: this.state.isLoading + 1
}) })
this.ipfs.cat(this.state.hash, (err, data) => { this.ipfs.files.cat(this.state.hash, (err, data) => {
if (err) console.log('Error', err) if (err) console.log('Error', err)
this.setState({ this.setState({
@@ -70,22 +60,7 @@ class App extends Component {
isLoading: this.state.isLoading + 1 isLoading: this.state.isLoading + 1
}) })
this.ipfs.dht.findPeer(this.state.peer, (err, results) => { this.ipfs.dht.findpeer(this.state.peer, (err, results) => {
if (err) console.log('Error', err)
this.setState({
response: JSON.stringify(results, null, 2),
isLoading: this.state.isLoading - 1
})
})
}
handleDataSubmit (event) {
event.preventDefault()
this.setState({
isLoading: this.state.isLoading + 1
})
this.ipfs.add(Buffer.from(this.state.data), (err, results) => {
if (err) console.log('Error', err) if (err) console.log('Error', err)
this.setState({ this.setState({
@@ -161,13 +136,6 @@ class App extends Component {
<input type="submit" value="Find" /> <input type="submit" value="Find" />
</label> </label>
</form> </form>
<form onSubmit={this.handleDataSubmit}>
<label>
Add Data:
<input type="text" value={this.state.data} onChange={this.handleDataChange} />
<input type="submit" value="Add" />
</label>
</form>
</section> </section>
<section className={[this.state.isLoading > 0 ? 'loading' : '', 'loader'].join(' ')}> <section className={[this.state.isLoading > 0 ? 'loading' : '', 'loader'].join(' ')}>
<div className="lds-ripple"><div></div><div></div></div> <div className="lds-ripple"><div></div><div></div></div>
@@ -182,4 +150,4 @@ class App extends Component {
} }
} }
export default App module.exports = App

View File

@@ -1,8 +1,9 @@
// eslint-disable-next-line // eslint-disable-next-line
'use strict' 'use strict'
import React from 'react' // eslint-disable-line no-unused-vars const React = require('react') // eslint-disable-line no-unused-vars
import ReactDOM from 'react-dom' const ReactDOM = require('react-dom')
import App from './App' // eslint-disable-line no-unused-vars const App = require('./App') // eslint-disable-line no-unused-vars
// require('index.css')
ReactDOM.render(<App />, document.getElementById('root')) ReactDOM.render(<App />, document.getElementById('root'))

View File

@@ -5,18 +5,17 @@ const Libp2p = require('libp2p')
const Websockets = require('libp2p-websockets') const Websockets = require('libp2p-websockets')
const WebSocketStar = require('libp2p-websocket-star') const WebSocketStar = require('libp2p-websocket-star')
const WebRTCStar = require('libp2p-webrtc-star') const WebRTCStar = require('libp2p-webrtc-star')
const MPLEX = require('pull-mplex') const MPLEX = require('libp2p-mplex')
const SECIO = require('libp2p-secio') const SECIO = require('libp2p-secio')
const KadDHT = require('libp2p-kad-dht') const KadDHT = require('libp2p-kad-dht')
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing') const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
const DelegatedContentRouter = require('libp2p-delegated-content-routing') const DelegatedContentRouter = require('libp2p-delegated-content-routing')
export default function Libp2pBundle ({peerInfo, peerBook}) { module.exports = ({peerInfo, peerBook}) => {
const wrtcstar = new WebRTCStar({id: peerInfo.id}) const wrtcstar = new WebRTCStar({id: peerInfo.id})
const wsstar = new WebSocketStar({id: peerInfo.id}) const wsstar = new WebSocketStar({id: peerInfo.id})
/* TODO: Ensure the delegatedApiOptions match your IPFS nodes API server */
const delegatedApiOptions = { const delegatedApiOptions = {
host: '127.0.0.1', host: '0.0.0.0',
protocol: 'http', protocol: 'http',
port: '8080' port: '8080'
} }
@@ -26,8 +25,7 @@ export default function Libp2pBundle ({peerInfo, peerBook}) {
peerBook, peerBook,
// Lets limit the connection managers peers and have it check peer health less frequently // Lets limit the connection managers peers and have it check peer health less frequently
connectionManager: { connectionManager: {
minPeers: 20, maxPeers: 10,
maxPeers: 50,
pollInterval: 5000 pollInterval: 5000
}, },
modules: { modules: {
@@ -56,7 +54,6 @@ export default function Libp2pBundle ({peerInfo, peerBook}) {
}, },
config: { config: {
peerDiscovery: { peerDiscovery: {
autoDial: false,
webrtcStar: { webrtcStar: {
enabled: false enabled: false
}, },
@@ -65,13 +62,16 @@ export default function Libp2pBundle ({peerInfo, peerBook}) {
} }
}, },
dht: { dht: {
enabled: false kBucketSize: 20
}, },
relay: { relay: {
enabled: true, enabled: true,
hop: { hop: {
enabled: false enabled: false
} }
},
EXPERIMENTAL: {
dht: false
} }
} }
}) })

View File

@@ -6,21 +6,21 @@ const TCP = require('libp2p-tcp')
const Mplex = require('libp2p-mplex') const Mplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio') const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info') const PeerInfo = require('peer-info')
const Bootstrap = require('libp2p-bootstrap') const Bootstrap = require('libp2p-railing')
const waterfall = require('async/waterfall') const waterfall = require('async/waterfall')
const defaultsDeep = require('@nodeutils/defaults-deep') const defaultsDeep = require('@nodeutils/defaults-deep')
// Find this list at: https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/config-nodejs.json // Find this list at: https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/config-nodejs.json
const bootstrapers = [ const bootstrapers = [
'/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ', '/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
'/ip4/104.236.176.52/tcp/4001/p2p/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z', '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
'/ip4/104.236.179.241/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM', '/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
'/ip4/162.243.248.213/tcp/4001/p2p/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm', '/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
'/ip4/128.199.219.111/tcp/4001/p2p/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu', '/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
'/ip4/104.236.76.40/tcp/4001/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64', '/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
'/ip4/178.62.158.247/tcp/4001/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd', '/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
'/ip4/178.62.61.185/tcp/4001/p2p/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3', '/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
'/ip4/104.236.151.122/tcp/4001/p2p/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx' '/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx'
] ]
class MyBundle extends libp2p { class MyBundle extends libp2p {
@@ -34,9 +34,8 @@ class MyBundle extends libp2p {
}, },
config: { config: {
peerDiscovery: { peerDiscovery: {
autoDial: true,
bootstrap: { bootstrap: {
interval: 20e3, interval: 2000,
enabled: true, enabled: true,
list: bootstrapers list: bootstrapers
} }
@@ -63,8 +62,8 @@ waterfall([
if (err) { throw err } if (err) { throw err }
node.on('peer:discovery', (peer) => { node.on('peer:discovery', (peer) => {
// No need to dial, autoDial is on
console.log('Discovered:', peer.id.toB58String()) console.log('Discovered:', peer.id.toB58String())
node.dial(peer, () => {})
}) })
node.on('peer:connect', (peer) => { node.on('peer:connect', (peer) => {

View File

@@ -23,7 +23,7 @@ class MyBundle extends libp2p {
config: { config: {
peerDiscovery: { peerDiscovery: {
mdns: { mdns: {
interval: 20e3, interval: 1000,
enabled: true enabled: true
} }
} }

View File

@@ -43,15 +43,15 @@ In this bundle, we use a `bootstrappers` array listing peers to connect _on boot
```JavaScript ```JavaScript
const bootstrapers = [ const bootstrapers = [
'/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ', '/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
'/ip4/104.236.176.52/tcp/4001/p2p/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z', '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
'/ip4/104.236.179.241/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM', '/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
'/ip4/162.243.248.213/tcp/4001/p2p/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm', '/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
'/ip4/128.199.219.111/tcp/4001/p2p/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu', '/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
'/ip4/104.236.76.40/tcp/4001/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64', '/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
'/ip4/178.62.158.247/tcp/4001/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd', '/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
'/ip4/178.62.61.185/tcp/4001/p2p/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3', '/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
'/ip4/104.236.151.122/tcp/4001/p2p/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx' '/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx'
] ]
``` ```

View File

@@ -3,7 +3,7 @@
This example performs a simple echo from the listener to the dialer. This example performs a simple echo from the listener to the dialer.
## Setup ## Setup
1. Install the modules from libp2p root, `npm install`. 1. Install the modules, `npm install`.
2. Open 2 terminal windows in the `./src` directory. 2. Open 2 terminal windows in the `./src` directory.
## Running ## Running

View File

@@ -28,7 +28,7 @@ async.parallel([
// Peer to Dial // Peer to Dial
const listenerPeerInfo = new PeerInfo(ids[1]) const listenerPeerInfo = new PeerInfo(ids[1])
const listenerId = ids[1] const listenerId = ids[1]
const listenerMultiaddr = '/ip4/127.0.0.1/tcp/10333/p2p/' + const listenerMultiaddr = '/ip4/127.0.0.1/tcp/10333/ipfs/' +
listenerId.toB58String() listenerId.toB58String()
listenerPeerInfo.multiaddrs.add(listenerMultiaddr) listenerPeerInfo.multiaddrs.add(listenerMultiaddr)
@@ -37,7 +37,7 @@ async.parallel([
console.log('Dialer ready, listening on:') console.log('Dialer ready, listening on:')
dialerPeerInfo.multiaddrs.forEach((ma) => console.log(ma.toString() + dialerPeerInfo.multiaddrs.forEach((ma) => console.log(ma.toString() +
'/p2p/' + dialerId.toB58String())) '/ipfs/' + dialerId.toB58String()))
console.log('Dialing to peer:', listenerMultiaddr.toString()) console.log('Dialing to peer:', listenerMultiaddr.toString())
dialerNode.dialProtocol(listenerPeerInfo, '/echo/1.0.0', (err, conn) => { dialerNode.dialProtocol(listenerPeerInfo, '/echo/1.0.0', (err, conn) => {

View File

@@ -3,7 +3,7 @@
const TCP = require('libp2p-tcp') const TCP = require('libp2p-tcp')
const MulticastDNS = require('libp2p-mdns') const MulticastDNS = require('libp2p-mdns')
const WS = require('libp2p-websockets') const WS = require('libp2p-websockets')
const Bootstrap = require('libp2p-bootstrap') const Bootstrap = require('libp2p-railing')
const spdy = require('libp2p-spdy') const spdy = require('libp2p-spdy')
const KadDHT = require('libp2p-kad-dht') const KadDHT = require('libp2p-kad-dht')
const mplex = require('libp2p-mplex') const mplex = require('libp2p-mplex')

View File

@@ -41,6 +41,6 @@ series([
console.log('Listener ready, listening on:') console.log('Listener ready, listening on:')
listenerNode.peerInfo.multiaddrs.forEach((ma) => { listenerNode.peerInfo.multiaddrs.forEach((ma) => {
console.log(ma.toString() + '/p2p/' + listenerId.toB58String()) console.log(ma.toString() + '/ipfs/' + listenerId.toB58String())
}) })
}) })

View File

@@ -37,4 +37,4 @@ And that's it, from now on, all your libp2p communications are encrypted. Try ru
If you want to want to learn more about how SECIO works, you can read the [great write up done by Dominic Tarr](https://github.com/auditdrivencrypto/secure-channel/blob/master/prior-art.md#ipfss-secure-channel). If you want to want to learn more about how SECIO works, you can read the [great write up done by Dominic Tarr](https://github.com/auditdrivencrypto/secure-channel/blob/master/prior-art.md#ipfss-secure-channel).
Important note: SECIO hasn't been audited and so, we do not recommend to trust its security. We intent to move to TLS 1.3 once the specification is finalized and an implementation exists that we can use. Importante note: SECIO hasn't been audited and so, we do not recommend to trust its security. We intent to move to TLS 1.3 once the specification is finalized and an implementation exists that we can use.

View File

@@ -17,13 +17,12 @@
}, },
"dependencies": { "dependencies": {
"detect-dom-ready": "^1.0.2", "detect-dom-ready": "^1.0.2",
"libp2p-bootstrap": "~0.9.7", "libp2p-mplex": "~0.8.0",
"libp2p-mplex": "~0.8.5", "libp2p-railing": "~0.9.1",
"libp2p-secio": "~0.11.1", "libp2p-secio": "~0.10.0",
"libp2p-spdy": "~0.13.3", "libp2p-spdy": "~0.12.1",
"libp2p-webrtc-star": "~0.15.8", "libp2p-webrtc-star": "~0.15.3",
"libp2p-websocket-star": "~0.10.2", "libp2p-websockets": "~0.12.0",
"libp2p-websockets": "~0.12.2", "peer-info": "~0.14.1"
"peer-info": "~0.15.1"
} }
} }

View File

@@ -2,40 +2,36 @@
const WebRTCStar = require('libp2p-webrtc-star') const WebRTCStar = require('libp2p-webrtc-star')
const WebSockets = require('libp2p-websockets') const WebSockets = require('libp2p-websockets')
const WebSocketStar = require('libp2p-websocket-star')
const Mplex = require('libp2p-mplex') const Mplex = require('libp2p-mplex')
const SPDY = require('libp2p-spdy') const SPDY = require('libp2p-spdy')
const SECIO = require('libp2p-secio') const SECIO = require('libp2p-secio')
const Bootstrap = require('libp2p-bootstrap') const Bootstrap = require('libp2p-railing')
const DHT = require('libp2p-kad-dht')
const defaultsDeep = require('@nodeutils/defaults-deep') const defaultsDeep = require('@nodeutils/defaults-deep')
const libp2p = require('../../../../') const libp2p = require('../../../../')
// Find this list at: https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/config-browser.json // Find this list at: https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/config-browser.json
const bootstrapList = [ const bootstrapers = [
'/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd', '/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
'/dns4/sfo-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx', '/dns4/sfo-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx',
'/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3', '/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
'/dns4/sfo-2.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z', '/dns4/sfo-2.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
'/dns4/sfo-3.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM', '/dns4/sfo-3.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
'/dns4/sgp-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu', '/dns4/sgp-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
'/dns4/nyc-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm', '/dns4/nyc-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
'/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64', '/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
'/dns4/node0.preload.ipfs.io/tcp/443/wss/p2p/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic', '/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
'/dns4/node0.preload.ipfs.io/tcp/443/wss/p2p/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6' '/dns4/wss1.bootstrap.libp2p.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
] ]
class Node extends libp2p { class Node extends libp2p {
constructor (_options) { constructor (_options) {
const wrtcStar = new WebRTCStar({ id: _options.peerInfo.id }) const wrtcStar = new WebRTCStar({ id: _options.peerInfo.id })
const wsstar = new WebSocketStar({ id: _options.peerInfo.id })
const defaults = { const defaults = {
modules: { modules: {
transport: [ transport: [
wrtcStar, wrtcStar,
WebSockets, new WebSockets()
wsstar
], ],
streamMuxer: [ streamMuxer: [
Mplex, Mplex,
@@ -46,14 +42,11 @@ class Node extends libp2p {
], ],
peerDiscovery: [ peerDiscovery: [
wrtcStar.discovery, wrtcStar.discovery,
wsstar.discovery,
Bootstrap Bootstrap
], ]
dht: DHT
}, },
config: { config: {
peerDiscovery: { peerDiscovery: {
autoDial: true,
webRTCStar: { webRTCStar: {
enabled: true enabled: true
}, },
@@ -61,28 +54,22 @@ class Node extends libp2p {
enabled: true enabled: true
}, },
bootstrap: { bootstrap: {
interval: 20e3, interval: 10000,
enabled: true, enabled: false,
list: bootstrapList list: bootstrapers
} }
}, },
relay: { relay: {
enabled: true, enabled: false,
hop: { hop: {
enabled: false, enabled: false,
active: false active: false
} }
}, },
dht: {
enabled: false
},
EXPERIMENTAL: { EXPERIMENTAL: {
dht: false,
pubsub: false pubsub: false
} }
},
connectionManager: {
minPeers: 10,
maxPeers: 50
} }
} }

View File

@@ -10,7 +10,7 @@ function createNode (callback) {
} }
const peerIdStr = peerInfo.id.toB58String() const peerIdStr = peerInfo.id.toB58String()
const ma = `/dns4/star-signal.cloud.ipfs.team/tcp/443/wss/p2p-webrtc-star/p2p/${peerIdStr}` const ma = `/dns4/star-signal.cloud.ipfs.team/tcp/443/wss/p2p-webrtc-star/ipfs/${peerIdStr}`
peerInfo.multiaddrs.add(ma) peerInfo.multiaddrs.add(ma)

View File

@@ -1,5 +1,4 @@
/* eslint no-console: ["error", { allow: ["log"] }] */ /* eslint-disable no-console */
/* eslint max-nested-callbacks: ["error", 5] */
'use strict' 'use strict'
const domReady = require('detect-dom-ready') const domReady = require('detect-dom-ready')
@@ -15,7 +14,13 @@ domReady(() => {
} }
node.on('peer:discovery', (peerInfo) => { node.on('peer:discovery', (peerInfo) => {
console.log('Discovered a peer:', peerInfo.id.toB58String()) console.log('Discovered a peer')
const idStr = peerInfo.id.toB58String()
console.log('Discovered: ' + idStr)
node.dial(peerInfo, (err, conn) => {
if (err) { return console.log('Failed to dial:', idStr) }
})
}) })
node.on('peer:connect', (peerInfo) => { node.on('peer:connect', (peerInfo) => {
@@ -29,13 +34,13 @@ domReady(() => {
node.on('peer:disconnect', (peerInfo) => { node.on('peer:disconnect', (peerInfo) => {
const idStr = peerInfo.id.toB58String() const idStr = peerInfo.id.toB58String()
const el = document.getElementById(idStr) console.log('Lost connection to: ' + idStr)
el && el.remove() document.getElementById(idStr).remove()
}) })
node.start((err) => { node.start((err) => {
if (err) { if (err) {
return console.log(err) return console.log('WebRTC not supported')
} }
const idStr = node.peerInfo.id.toB58String() const idStr = node.peerInfo.id.toB58String()

View File

@@ -4,15 +4,7 @@ One of the primary goals with libp2p P2P was to get it fully working in the brow
# 1. Setting up a simple app that lists connections to other nodes # 1. Setting up a simple app that lists connections to other nodes
Start by installing libp2p's dependencies. Simple go into the folder [1](./1) and execute the following
```bash
> cd ../../
> npm install
> cd examples/libp2p-in-the-browser
```
Then simply go into the folder [1](./1) and execute the following
```bash ```bash
> cd 1 > cd 1

View File

@@ -23,8 +23,10 @@ class MyBundle extends libp2p {
}, },
config: { config: {
dht: { dht: {
enabled: true,
kBucketSize: 20 kBucketSize: 20
},
EXPERIMENTAL: {
dht: true
} }
} }
} }

View File

@@ -24,8 +24,10 @@ class MyBundle extends libp2p {
}, },
config: { config: {
dht: { dht: {
enabled: true,
kBucketSize: 20 kBucketSize: 20
},
EXPERIMENTAL: {
dht: true
} }
} }
} }

View File

@@ -25,9 +25,11 @@ class MyBundle extends libp2p {
}, },
config: { config: {
dht: { dht: {
// dht must be enabled
enabled: true,
kBucketSize: 20 kBucketSize: 20
},
EXPERIMENTAL: {
// dht must be enabled
dht: true
} }
} }
} }
@@ -67,8 +69,8 @@ You should see the output being something like:
```Bash ```Bash
> node 1.js > node 1.js
Found it, multiaddrs are: Found it, multiaddrs are:
/ip4/127.0.0.1/tcp/63617/p2p/QmWrFXvZr9S4iDqycyoyc2zDdrT1jg9wpdenUTdd1LTar6 /ip4/127.0.0.1/tcp/63617/ipfs/QmWrFXvZr9S4iDqycyoyc2zDdrT1jg9wpdenUTdd1LTar6
/ip4/192.168.86.41/tcp/63617/p2p/QmWrFXvZr9S4iDqycyoyc2zDdrT1jg9wpdenUTdd1LTar6 /ip4/192.168.86.41/tcp/63617/ipfs/QmWrFXvZr9S4iDqycyoyc2zDdrT1jg9wpdenUTdd1LTar6
``` ```
You have successfully used Peer Routing to find a peer that you were not directly connected. Now all you have to do is to dial to the multiaddrs you discovered. You have successfully used Peer Routing to find a peer that you were not directly connected. Now all you have to do is to dial to the multiaddrs you discovered.

View File

@@ -169,7 +169,7 @@ You can see this working on example [3.js](./3.js). The result should look like
> node 3.js > node 3.js
from 1 to 2 from 1 to 2
Addresses by which both peers are connected Addresses by which both peers are connected
node 1 to node 2: /ip4/127.0.0.1/tcp/50629/p2p/QmZwMKTo6wG4Te9A6M2eJnWDpR8uhsGed4YRegnV5DcKiv node 1 to node 2: /ip4/127.0.0.1/tcp/50629/ipfs/QmZwMKTo6wG4Te9A6M2eJnWDpR8uhsGed4YRegnV5DcKiv
node 2 to node 1: /ip4/127.0.0.1/tcp/50630/p2p/QmRgormJQeDyXhDKma11eUtksoh8vWmeBoxghVt4meauW9 node 2 to node 1: /ip4/127.0.0.1/tcp/50630/ipfs/QmRgormJQeDyXhDKma11eUtksoh8vWmeBoxghVt4meauW9
from 2 to 1 from 2 to 1
``` ```

View File

@@ -62,8 +62,11 @@ parallel([
const node1 = nodes[0] const node1 = nodes[0]
const node2 = nodes[1] const node2 = nodes[1]
node1.once('peer:connect', (peer) => { series([
console.log('connected to %s', peer.id.toB58String()) (cb) => node1.once('peer:discovery', (peer) => node1.dial(peer, cb)),
(cb) => setTimeout(cb, 500)
], (err) => {
if (err) { throw err }
// Subscribe to the topic 'news' // Subscribe to the topic 'news'
node1.pubsub.subscribe('news', node1.pubsub.subscribe('news',

View File

@@ -12,11 +12,14 @@ We've seen many interesting use cases appear with this, here are some highlights
For this example, we will use MulticastDNS for automatic Peer Discovery. This example is based the previous examples found in [Discovery Mechanisms](../discovery-mechanisms). You can find the complete version at [1.js](./1.js). For this example, we will use MulticastDNS for automatic Peer Discovery. This example is based the previous examples found in [Discovery Mechanisms](../discovery-mechanisms). You can find the complete version at [1.js](./1.js).
Using PubSub is super simple, all you have to do is start a libp2p node with `EXPERIMENTAL.pubsub` set to true. Using PubSub is super simple, all you have to do is start a libp2p node, PubSub will be enabled by default.
```JavaScript ```JavaScript
node1.once('peer:connect', (peer) => { series([
console.log('connected to %s', peer.id.toB58String()) (cb) => node1.once('peer:discovery', (peer) => node1.dial(peer, cb)),
(cb) => setTimeout(cb, 500)
], (err) => {
if (err) { throw err }
// Subscribe to the topic 'news' // Subscribe to the topic 'news'
node1.pubsub.subscribe('news', node1.pubsub.subscribe('news',
@@ -39,7 +42,6 @@ The output of the program should look like:
``` ```
> node 1.js > node 1.js
connected to QmWpvkKm6qHLhoxpWrTswY6UMNWDyn8hN265Qp9ZYvgS82
QmWpvkKm6qHLhoxpWrTswY6UMNWDyn8hN265Qp9ZYvgS82 Bird bird bird, bird is the word! QmWpvkKm6qHLhoxpWrTswY6UMNWDyn8hN265Qp9ZYvgS82 Bird bird bird, bird is the word!
QmWpvkKm6qHLhoxpWrTswY6UMNWDyn8hN265Qp9ZYvgS82 Bird bird bird, bird is the word! QmWpvkKm6qHLhoxpWrTswY6UMNWDyn8hN265Qp9ZYvgS82 Bird bird bird, bird is the word!
QmWpvkKm6qHLhoxpWrTswY6UMNWDyn8hN265Qp9ZYvgS82 Bird bird bird, bird is the word! QmWpvkKm6qHLhoxpWrTswY6UMNWDyn8hN265Qp9ZYvgS82 Bird bird bird, bird is the word!

View File

@@ -88,8 +88,8 @@ Running this should result in something like:
> node 1.js > node 1.js
node has started (true/false): true node has started (true/false): true
listening on: listening on:
/ip4/127.0.0.1/tcp/61329/p2p/QmW2cKTakTYqbQkUzBTEGXgWYFj1YEPeUndE1YWs6CBzDQ /ip4/127.0.0.1/tcp/61329/ipfs/QmW2cKTakTYqbQkUzBTEGXgWYFj1YEPeUndE1YWs6CBzDQ
/ip4/192.168.2.156/tcp/61329/p2p/QmW2cKTakTYqbQkUzBTEGXgWYFj1YEPeUndE1YWs6CBzDQ /ip4/192.168.2.156/tcp/61329/ipfs/QmW2cKTakTYqbQkUzBTEGXgWYFj1YEPeUndE1YWs6CBzDQ
``` ```
That `QmW2cKTakTYqbQkUzBTEGXgWYFj1YEPeUndE1YWs6CBzDQ` is the PeerId that was created during the PeerInfo generation. That `QmW2cKTakTYqbQkUzBTEGXgWYFj1YEPeUndE1YWs6CBzDQ` is the PeerId that was created during the PeerInfo generation.
@@ -175,11 +175,11 @@ The result should be look like:
```bash ```bash
> node 2.js > node 2.js
node 1 is listening on: node 1 is listening on:
/ip4/127.0.0.1/tcp/62279/p2p/QmeM4wNWv1uci7UJjUXZYfvcy9uqAbw7G9icuxdqy88Mj9 /ip4/127.0.0.1/tcp/62279/ipfs/QmeM4wNWv1uci7UJjUXZYfvcy9uqAbw7G9icuxdqy88Mj9
/ip4/192.168.2.156/tcp/62279/p2p/QmeM4wNWv1uci7UJjUXZYfvcy9uqAbw7G9icuxdqy88Mj9 /ip4/192.168.2.156/tcp/62279/ipfs/QmeM4wNWv1uci7UJjUXZYfvcy9uqAbw7G9icuxdqy88Mj9
node 2 is listening on: node 2 is listening on:
/ip4/127.0.0.1/tcp/62278/p2p/QmWp58xJgzbouNJcyiNNTpZuqQCJU8jf6ixc7TZT9xEZhV /ip4/127.0.0.1/tcp/62278/ipfs/QmWp58xJgzbouNJcyiNNTpZuqQCJU8jf6ixc7TZT9xEZhV
/ip4/192.168.2.156/tcp/62278/p2p/QmWp58xJgzbouNJcyiNNTpZuqQCJU8jf6ixc7TZT9xEZhV /ip4/192.168.2.156/tcp/62278/ipfs/QmWp58xJgzbouNJcyiNNTpZuqQCJU8jf6ixc7TZT9xEZhV
Hello p2p world! Hello p2p world!
``` ```
@@ -304,14 +304,14 @@ If everything was set correctly, you now should see the following after you run
```Bash ```Bash
> node 3.js > node 3.js
node 1 is listening on: node 1 is listening on:
/ip4/127.0.0.1/tcp/62620/p2p/QmWpWmcVJkF6EpmAaVDauku8g1uFGuxPsGP35XZp9GYEqs /ip4/127.0.0.1/tcp/62620/ipfs/QmWpWmcVJkF6EpmAaVDauku8g1uFGuxPsGP35XZp9GYEqs
/ip4/192.168.2.156/tcp/62620/p2p/QmWpWmcVJkF6EpmAaVDauku8g1uFGuxPsGP35XZp9GYEqs /ip4/192.168.2.156/tcp/62620/ipfs/QmWpWmcVJkF6EpmAaVDauku8g1uFGuxPsGP35XZp9GYEqs
node 2 is listening on: node 2 is listening on:
/ip4/127.0.0.1/tcp/10000/ws/p2p/QmWAQtWdzWXibgfyc7WRHhhv6MdqVKzXvyfSTnN2aAvixX /ip4/127.0.0.1/tcp/10000/ws/ipfs/QmWAQtWdzWXibgfyc7WRHhhv6MdqVKzXvyfSTnN2aAvixX
/ip4/127.0.0.1/tcp/62619/p2p/QmWAQtWdzWXibgfyc7WRHhhv6MdqVKzXvyfSTnN2aAvixX /ip4/127.0.0.1/tcp/62619/ipfs/QmWAQtWdzWXibgfyc7WRHhhv6MdqVKzXvyfSTnN2aAvixX
/ip4/192.168.2.156/tcp/62619/p2p/QmWAQtWdzWXibgfyc7WRHhhv6MdqVKzXvyfSTnN2aAvixX /ip4/192.168.2.156/tcp/62619/ipfs/QmWAQtWdzWXibgfyc7WRHhhv6MdqVKzXvyfSTnN2aAvixX
node 3 is listening on: node 3 is listening on:
/ip4/127.0.0.1/tcp/20000/ws/p2p/QmVq1PWh3VSDYdFqYMtqp4YQyXcrH27N7968tGdM1VQPj1 /ip4/127.0.0.1/tcp/20000/ws/ipfs/QmVq1PWh3VSDYdFqYMtqp4YQyXcrH27N7968tGdM1VQPj1
node 3 failed to dial to node 1 with: No available transport to dial to node 3 failed to dial to node 1 with: No available transport to dial to
node 1 dialed to node 2 successfully node 1 dialed to node 2 successfully
node 2 dialed to node 3 successfully node 2 dialed to node 3 successfully

View File

@@ -3,7 +3,7 @@
"Package", "Package",
"Version", "Version",
"Deps", "Deps",
"CI/Travis", "CI",
"Coverage", "Coverage",
"Lead Maintainer" "Lead Maintainer"
], ],

View File

@@ -1,13 +1,9 @@
{ {
"name": "libp2p", "name": "libp2p",
"version": "0.25.4", "version": "0.24.0-rc.2",
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack", "description": "JavaScript base class for libp2p bundles",
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>", "leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
"main": "src/index.js", "main": "src/index.js",
"files": [
"dist",
"src"
],
"scripts": { "scripts": {
"lint": "aegir lint", "lint": "aegir lint",
"build": "aegir build", "build": "aegir build",
@@ -16,86 +12,80 @@
"test:browser": "aegir test -t browser", "test:browser": "aegir test -t browser",
"release": "aegir release -t node -t browser", "release": "aegir release -t node -t browser",
"release-minor": "aegir release --type minor -t node -t browser", "release-minor": "aegir release --type minor -t node -t browser",
"release-major": "aegir release --type major -t node -t browser" "release-major": "aegir release --type major -t node -t browser",
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage --provider coveralls"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/libp2p/js-libp2p.git" "url": "https://github.com/libp2p/js-libp2p.git"
}, },
"keywords": [ "keywords": [
"libp2p",
"network",
"p2p",
"peer",
"peer-to-peer",
"IPFS" "IPFS"
], ],
"engines": {
"node": ">=6.0.0",
"npm": ">=3.0.0"
},
"license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/libp2p/js-libp2p/issues" "url": "https://github.com/libp2p/js-libp2p/issues"
}, },
"homepage": "https://libp2p.io", "homepage": "https://github.com/libp2p/js-libp2p",
"license": "MIT",
"browser": { "browser": {
"joi": "joi-browser",
"./test/utils/bundle-nodejs": "./test/utils/bundle-browser" "./test/utils/bundle-nodejs": "./test/utils/bundle-browser"
}, },
"engines": {
"node": ">=10.0.0",
"npm": ">=6.0.0"
},
"dependencies": { "dependencies": {
"async": "^2.6.2", "async": "^2.6.1",
"debug": "^4.1.1", "debug": "^4.0.1",
"err-code": "^1.1.2", "err-code": "^1.1.2",
"fsm-event": "^2.1.0", "fsm-event": "^2.1.0",
"libp2p-connection-manager": "^0.1.0", "joi": "^13.6.0",
"libp2p-floodsub": "^0.16.1", "joi-browser": "^13.4.0",
"libp2p-ping": "^0.8.5", "libp2p-connection-manager": "~0.0.2",
"libp2p-switch": "^0.42.12", "libp2p-floodsub": "~0.15.0",
"libp2p-websockets": "^0.12.2", "libp2p-ping": "~0.8.0",
"mafmt": "^6.0.7", "libp2p-switch": "~0.41.1",
"multiaddr": "^6.1.0", "libp2p-websockets": "~0.12.0",
"once": "^1.4.0", "mafmt": "^6.0.2",
"peer-book": "^0.9.1", "multiaddr": "^5.0.0",
"peer-id": "^0.12.2", "nock": "^9.4.3",
"peer-info": "^0.15.1", "peer-book": "~0.8.0",
"superstruct": "^0.6.0" "peer-id": "~0.11.0",
"peer-info": "~0.14.1"
}, },
"devDependencies": { "devDependencies": {
"@nodeutils/defaults-deep": "^1.1.0", "@nodeutils/defaults-deep": "^1.1.0",
"aegir": "^19.0.3", "aegir": "^15.2.0",
"chai": "^4.2.0", "chai": "^4.1.2",
"chai-checkmark": "^1.0.1", "chai-checkmark": "^1.0.1",
"cids": "^0.7.1", "cids": "~0.5.3",
"dirty-chai": "^2.0.1", "dirty-chai": "^2.0.1",
"electron-webrtc": "^0.3.0", "electron-webrtc": "~0.3.0",
"interface-datastore": "^0.6.0", "libp2p-bootstrap": "~0.9.3",
"libp2p-bootstrap": "^0.9.7", "libp2p-circuit": "~0.2.1",
"libp2p-circuit": "^0.3.7", "libp2p-delegated-content-routing": "~0.2.2",
"libp2p-delegated-content-routing": "^0.2.2", "libp2p-delegated-peer-routing": "~0.2.2",
"libp2p-delegated-peer-routing": "^0.2.2", "libp2p-kad-dht": "~0.10.5",
"libp2p-kad-dht": "^0.15.2", "libp2p-mdns": "~0.12.0",
"libp2p-mdns": "^0.12.3", "libp2p-mplex": "~0.8.2",
"libp2p-mplex": "^0.8.4", "libp2p-secio": "~0.10.0",
"libp2p-secio": "^0.11.1", "libp2p-spdy": "~0.12.1",
"libp2p-spdy": "^0.13.2", "libp2p-tcp": "~0.13.0",
"libp2p-tcp": "^0.13.0", "libp2p-webrtc-star": "~0.15.5",
"libp2p-webrtc-star": "^0.16.1", "libp2p-websocket-star": "~0.8.1",
"libp2p-websocket-star": "~0.10.2", "libp2p-websocket-star-rendezvous": "~0.2.3",
"libp2p-websocket-star-rendezvous": "~0.3.0",
"lodash.times": "^4.3.2", "lodash.times": "^4.3.2",
"nock": "^10.0.6",
"pull-goodbye": "0.0.2", "pull-goodbye": "0.0.2",
"pull-mplex": "^0.1.2", "pull-serializer": "~0.3.2",
"pull-serializer": "^0.3.2", "pull-stream": "^3.6.9",
"pull-stream": "^3.6.12", "sinon": "^6.3.4",
"sinon": "^7.2.7", "webrtcsupport": "^2.2.0",
"wrtc": "^0.4.1" "wrtc": "~0.2.0"
}, },
"contributors": [ "contributors": [
"Aditya Bose <13054902+adbose@users.noreply.github.com>",
"Alan Shaw <alan.shaw@protocol.ai>",
"Alan Shaw <alan@tableflip.io>", "Alan Shaw <alan@tableflip.io>",
"Andrew Nesbitt <andrewnez@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>",
@@ -106,9 +96,6 @@
"Florian-Merle <florian.david.merle@gmail.com>", "Florian-Merle <florian.david.merle@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>", "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Giovanni T. Parra <fiatjaf@gmail.com>", "Giovanni T. Parra <fiatjaf@gmail.com>",
"Guy Sviry <32539816+guysv@users.noreply.github.com>",
"Henrique Dias <hacdias@gmail.com>",
"Hugo Dias <mail@hugodias.me>",
"Hugo Dias <hugomrdias@gmail.com>", "Hugo Dias <hugomrdias@gmail.com>",
"Irakli Gozalishvili <rfobic@gmail.com>", "Irakli Gozalishvili <rfobic@gmail.com>",
"Jacob Heun <jacobheun@gmail.com>", "Jacob Heun <jacobheun@gmail.com>",
@@ -118,25 +105,17 @@
"Kevin Kwok <antimatter15@gmail.com>", "Kevin Kwok <antimatter15@gmail.com>",
"Lars Gierth <lgierth@users.noreply.github.com>", "Lars Gierth <lgierth@users.noreply.github.com>",
"Maciej Krüger <mkg20001@gmail.com>", "Maciej Krüger <mkg20001@gmail.com>",
"Marcin Tojek <mtojek@users.noreply.github.com>",
"Nuno Nogueira <nunofmn@gmail.com>", "Nuno Nogueira <nunofmn@gmail.com>",
"Pedro Teixeira <pedro@protocol.ai>", "Pedro Teixeira <pedro@protocol.ai>",
"Pedro Teixeira <i@pgte.me>", "Pedro Teixeira <i@pgte.me>",
"RasmusErik Voel Jensen <github@solsort.com>", "RasmusErik Voel Jensen <github@solsort.com>",
"Richard Littauer <richard.littauer@gmail.com>", "Richard Littauer <richard.littauer@gmail.com>",
"Ryan Bell <ryan@piing.net>", "Ryan Bell <ryan@piing.net>",
"Soeren <nikorpoulsen@gmail.com>",
"Sönke Hahn <soenkehahn@gmail.com>", "Sönke Hahn <soenkehahn@gmail.com>",
"Thomas Eizinger <thomas@eizinger.io>",
"Tiago Alves <alvesjtiago@gmail.com>", "Tiago Alves <alvesjtiago@gmail.com>",
"Vasco Santos <vasco.santos@ua.pt>",
"Vasco Santos <vasco.santos@moxy.studio>",
"Volker Mische <volker.mische@gmail.com>", "Volker Mische <volker.mische@gmail.com>",
"Yusef Napora <yusef@napora.org>",
"Zane Starr <zcstarr@gmail.com>", "Zane Starr <zcstarr@gmail.com>",
"ebinks <elizabethjbinks@gmail.com>",
"greenkeeperio-bot <support@greenkeeper.io>", "greenkeeperio-bot <support@greenkeeper.io>",
"isan_rivkin <isanrivkin@gmail.com>",
"mayerwin <mayerwin@users.noreply.github.com>", "mayerwin <mayerwin@users.noreply.github.com>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>" "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>"
] ]

View File

@@ -59,7 +59,7 @@ test('story 1 - peerA', (t) => {
t.ifErr(err, 'created Node successfully') t.ifErr(err, 'created Node successfully')
t.ok(node.isStarted(), 'PeerA is Running') t.ok(node.isStarted(), 'PeerA is Running')
const peerBAddr = `/ip4/127.0.0.1/tcp/10001/p2p/${PeerB.id}` const peerBAddr = `/ip4/127.0.0.1/tcp/10001/ipfs/${PeerB.id}`
node.handle('/time/1.0.0', (protocol, conn) => { node.handle('/time/1.0.0', (protocol, conn) => {
pull( pull(

View File

@@ -59,7 +59,7 @@ test('story 1 - peerA', (t) => {
t.ifErr(err, 'created Node successfully') t.ifErr(err, 'created Node successfully')
t.ok(node.isStarted(), 'PeerB is Running') t.ok(node.isStarted(), 'PeerB is Running')
const peerAAddr = `/ip4/127.0.0.1/tcp/10000/p2p/${PeerA.id}` const peerAAddr = `/ip4/127.0.0.1/tcp/10000/ipfs/${PeerA.id}`
node.handle('/echo/1.0.0', (protocol, conn) => { node.handle('/echo/1.0.0', (protocol, conn) => {
pull( pull(

View File

@@ -33,7 +33,7 @@ test('story 1 - peerA', (t) => {
t.ifErr(err, 'created Node') t.ifErr(err, 'created Node')
t.ok(node.isStarted(), 'PeerA is running') t.ok(node.isStarted(), 'PeerA is running')
const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/p2p/${PeerB.id}` const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/ipfs/${PeerB.id}`
node.dial(PeerBAddr, '/echo/1.0.0', (err, conn) => { node.dial(PeerBAddr, '/echo/1.0.0', (err, conn) => {
t.ifErr(err, 'dial successful') t.ifErr(err, 'dial successful')

View File

@@ -33,7 +33,7 @@ test('story 2 - peerA', (t) => {
t.ifErr(err, 'created Node') t.ifErr(err, 'created Node')
t.ok(node.isStarted(), 'PeerA is running') t.ok(node.isStarted(), 'PeerA is running')
const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/p2p/${PeerB.id}` const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/ws/ipfs/${PeerB.id}`
node.dial(PeerBAddr, '/echo/1.0.0', (err, conn) => { node.dial(PeerBAddr, '/echo/1.0.0', (err, conn) => {
t.ifErr(err, 'dial successful') t.ifErr(err, 'dial successful')

View File

@@ -32,7 +32,7 @@ test('story 3 - peerA', (t) => {
t.ifErr(err, 'created Node') t.ifErr(err, 'created Node')
t.ok(node.isStarted(), 'PeerA is running') t.ok(node.isStarted(), 'PeerA is running')
const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/ws/p2p/${PeerB.id}` const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/ws/ipfs/${PeerB.id}`
setTimeout(() => node.dial(PeerBAddr, '/echo/1.0.0', (err, conn) => { setTimeout(() => node.dial(PeerBAddr, '/echo/1.0.0', (err, conn) => {
t.ok(err, 'dial failed') t.ok(err, 'dial failed')

View File

@@ -32,7 +32,7 @@ test('story 3 - peerB', (t) => {
t.ifErr(err, 'created Node') t.ifErr(err, 'created Node')
t.ok(node.isStarted(), 'PeerA is running') t.ok(node.isStarted(), 'PeerA is running')
const PeerAAddr = `/ip4/127.0.0.1/tcp/10000/ws/p2p/${PeerA.id}` const PeerAAddr = `/ip4/127.0.0.1/tcp/10000/ws/ipfs/${PeerA.id}`
setTimeout(() => node.dial(PeerAAddr, '/echo/1.0.0', (err, conn) => { setTimeout(() => node.dial(PeerAAddr, '/echo/1.0.0', (err, conn) => {
t.ok(err, 'dial failed') t.ok(err, 'dial failed')

View File

@@ -1,100 +1,52 @@
'use strict' 'use strict'
const { struct, superstruct } = require('superstruct') const Joi = require('joi')
const { optional, list } = struct
// Define custom types const ModuleSchema = Joi.alternatives().try(Joi.func(), Joi.object())
const s = superstruct()
const transport = s.union([ const OptionsSchema = Joi.object({
s.interface({ // TODO: create proper validators for the generics
createListener: 'function', connectionManager: Joi.object(),
dial: 'function' peerInfo: Joi.object().required(),
peerBook: Joi.object(),
modules: Joi.object().keys({
connEncryption: Joi.array().items(ModuleSchema).allow(null),
connProtector: Joi.object().keys({
protect: Joi.func().required()
}).unknown(),
contentRouting: Joi.array().items(Joi.object()).allow(null),
dht: ModuleSchema.allow(null),
peerDiscovery: Joi.array().items(ModuleSchema).allow(null),
peerRouting: Joi.array().items(Joi.object()).allow(null),
streamMuxer: Joi.array().items(ModuleSchema).allow(null),
transport: Joi.array().items(ModuleSchema).min(1).required()
}).required(),
config: Joi.object().keys({
peerDiscovery: Joi.object().allow(null),
relay: Joi.object().keys({
enabled: Joi.boolean().default(true),
hop: Joi.object().keys({
enabled: Joi.boolean().default(false),
active: Joi.boolean().default(false)
})
}).default(),
dht: Joi.object().keys({
kBucketSize: Joi.number().allow(null),
enabledDiscovery: Joi.boolean().default(true)
}), }),
'function' EXPERIMENTAL: Joi.object().keys({
]) dht: Joi.boolean().default(false),
const modulesSchema = s({ pubsub: Joi.boolean().default(false)
connEncryption: optional(list([s('object|function')])), }).default()
// this is hacky to simulate optional because interface doesnt work correctly with it }).default()
// change to optional when fixed upstream
connProtector: s.union(['undefined', s.interface({ protect: 'function' })]),
contentRouting: optional(list(['object'])),
dht: optional(s('null|function|object')),
peerDiscovery: optional(list([s('object|function')])),
peerRouting: optional(list(['object'])),
streamMuxer: optional(list([s('object|function')])),
transport: s.intersection([[transport], s.interface({
length (v) {
return v > 0 ? true : 'ERROR_EMPTY'
}
})])
}) })
const configSchema = s({ module.exports.validate = (options) => {
peerDiscovery: s('object', { options = Joi.attempt(options, OptionsSchema)
autoDial: true
}),
relay: s({
enabled: 'boolean',
hop: optional(s({
enabled: 'boolean',
active: 'boolean'
}, {
// HOP defaults
enabled: false,
active: false
}))
}, {
// Relay defaults
enabled: true
}),
// DHT config
dht: s('object?', {
// DHT defaults
enabled: false,
kBucketSize: 20,
randomWalk: {
enabled: false, // disabled waiting for https://github.com/libp2p/js-libp2p-kad-dht/issues/86
queriesPerPeriod: 1,
interval: 300e3,
timeout: 10e3
}
}),
// Experimental config
EXPERIMENTAL: s({
pubsub: 'boolean'
}, {
// Experimental defaults
pubsub: false
})
}, {})
const optionsSchema = s({ // Ensure dht is correct
switch: 'object?', if (options.config.EXPERIMENTAL.dht) {
connectionManager: s('object', { Joi.assert(options.modules.dht, ModuleSchema.required())
minPeers: 25
}),
datastore: 'object?',
peerInfo: 'object',
peerBook: 'object?',
modules: modulesSchema,
config: configSchema
})
module.exports.validate = (opts) => {
const [error, options] = optionsSchema.validate(opts)
// Improve errors throwed, reduce stack by throwing here and add reason to the message
if (error) {
throw new Error(`${error.message}${error.reason ? ' - ' + error.reason : ''}`)
} else {
// Throw when dht is enabled but no dht module provided
if (options.config.dht.enabled) {
s('function|object')(options.modules.dht)
}
}
if (options.config.peerDiscovery.autoDial === undefined) {
options.config.peerDiscovery.autoDial = true
} }
return options return options

View File

@@ -20,11 +20,14 @@ module.exports = (node) => {
* @param {CID} key The CID key of the content to find * @param {CID} key The CID key of the content to find
* @param {object} options * @param {object} options
* @param {number} options.maxTimeout How long the query should run * @param {number} options.maxTimeout How long the query should run
* @param {number} options.maxNumProviders - maximum number of providers to find
* @param {function(Error, Result<Array>)} callback * @param {function(Error, Result<Array>)} callback
* @returns {void} * @returns {void}
*/ */
findProviders: (key, options, callback) => { findProviders: (key, options, callback) => {
if (!routers.length) {
return callback(errCode(new Error('No content routers available'), 'NO_ROUTERS_AVAILABLE'))
}
if (typeof options === 'function') { if (typeof options === 'function') {
callback = options callback = options
options = {} options = {}
@@ -34,10 +37,6 @@ module.exports = (node) => {
} }
} }
if (!routers.length) {
return callback(errCode(new Error('No content routers available'), 'NO_ROUTERS_AVAILABLE'))
}
const tasks = routers.map((router) => { const tasks = routers.map((router) => {
return (cb) => router.findProviders(key, options, (err, results) => { return (cb) => router.findProviders(key, options, (err, results) => {
if (err) { if (err) {

View File

@@ -1,15 +1,10 @@
'use strict' 'use strict'
const nextTick = require('async/nextTick')
const errCode = require('err-code')
const { messages, codes } = require('./errors')
module.exports = (node) => { module.exports = (node) => {
return { return {
put: (key, value, callback) => { put: (key, value, callback) => {
if (!node._dht) { if (!node._dht) {
return nextTick(callback, errCode(new Error(messages.DHT_DISABLED), codes.DHT_DISABLED)) return callback(new Error('DHT is not available'))
} }
node._dht.put(key, value, callback) node._dht.put(key, value, callback)
@@ -21,7 +16,7 @@ module.exports = (node) => {
} }
if (!node._dht) { if (!node._dht) {
return nextTick(callback, errCode(new Error(messages.DHT_DISABLED), codes.DHT_DISABLED)) return callback(new Error('DHT is not available'))
} }
node._dht.get(key, options, callback) node._dht.get(key, options, callback)
@@ -33,7 +28,7 @@ module.exports = (node) => {
} }
if (!node._dht) { if (!node._dht) {
return nextTick(callback, errCode(new Error(messages.DHT_DISABLED), codes.DHT_DISABLED)) return callback(new Error('DHT is not available'))
} }
node._dht.getMany(key, nVals, options, callback) node._dht.getMany(key, nVals, options, callback)

3
src/error-messages.js Normal file
View File

@@ -0,0 +1,3 @@
'use strict'
exports.NOT_STARTED_YET = 'The libp2p node is not started yet'

View File

@@ -1,13 +0,0 @@
'use strict'
exports.messages = {
NOT_STARTED_YET: 'The libp2p node is not started yet',
DHT_DISABLED: 'DHT is not available'
}
exports.codes = {
DHT_DISABLED: 'ERR_DHT_DISABLED',
PUBSUB_NOT_STARTED: 'ERR_PUBSUB_NOT_STARTED',
ERR_NODE_NOT_STARTED: 'ERR_NODE_NOT_STARTED',
ERR_DISCOVERED_SELF: 'ERR_DISCOVERED_SELF'
}

View File

@@ -3,7 +3,7 @@
const PeerId = require('peer-id') const PeerId = require('peer-id')
const PeerInfo = require('peer-info') const PeerInfo = require('peer-info')
const multiaddr = require('multiaddr') const multiaddr = require('multiaddr')
const errCode = require('err-code') const setImmediate = require('async/setImmediate')
module.exports = (node) => { module.exports = (node) => {
/* /*
@@ -20,21 +20,16 @@ module.exports = (node) => {
try { try {
peer = multiaddr(peer) peer = multiaddr(peer)
} catch (err) { } catch (err) {
return callback( return setImmediate(() => callback(err))
errCode(err, 'ERR_INVALID_MULTIADDR')
)
} }
} }
const peerIdB58Str = peer.getPeerId() const peerIdB58Str = peer.getPeerId()
if (!peerIdB58Str) { if (!peerIdB58Str) {
return callback( return setImmediate(() => {
errCode( callback(new Error('peer multiaddr instance or string must include peerId'))
new Error('peer multiaddr instance or string must include peerId'), })
'ERR_INVALID_MULTIADDR'
)
)
} }
try { try {
@@ -53,14 +48,9 @@ module.exports = (node) => {
return node.peerRouting.findPeer(peer, callback) return node.peerRouting.findPeer(peer, callback)
} }
} else { } else {
return callback( return setImmediate(() => callback(new Error('peer type not recognized')))
errCode(
new Error(`${p} is not a valid peer type`),
'ERR_INVALID_PEER_TYPE'
)
)
} }
callback(null, p) setImmediate(() => callback(null, p))
} }
} }

View File

@@ -2,69 +2,57 @@
const FSM = require('fsm-event') const FSM = require('fsm-event')
const EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
const assert = require('assert')
const debug = require('debug') const debug = require('debug')
const log = debug('libp2p') const log = debug('libp2p')
log.error = debug('libp2p:error') log.error = debug('libp2p:error')
const errCode = require('err-code')
const each = require('async/each') const each = require('async/each')
const series = require('async/series') const series = require('async/series')
const parallel = require('async/parallel') const parallel = require('async/parallel')
const nextTick = require('async/nextTick')
const PeerBook = require('peer-book') const PeerBook = require('peer-book')
const PeerInfo = require('peer-info')
const Switch = require('libp2p-switch') const Switch = require('libp2p-switch')
const Ping = require('libp2p-ping') const Ping = require('libp2p-ping')
const WebSockets = require('libp2p-websockets') const WebSockets = require('libp2p-websockets')
const ConnectionManager = require('libp2p-connection-manager') const ConnectionManager = require('libp2p-connection-manager')
const { emitFirst } = require('./util')
const peerRouting = require('./peer-routing') const peerRouting = require('./peer-routing')
const contentRouting = require('./content-routing') const contentRouting = require('./content-routing')
const dht = require('./dht') const dht = require('./dht')
const pubsub = require('./pubsub') const pubsub = require('./pubsub')
const getPeerInfo = require('./get-peer-info') const getPeerInfo = require('./get-peer-info')
const validateConfig = require('./config').validate const validateConfig = require('./config').validate
const { codes } = require('./errors')
const notStarted = (action, state) => { const NOT_STARTED_ERROR_MESSAGE = 'The libp2p node is not started yet'
return errCode(
new Error(`libp2p cannot ${action} when not started; state is ${state}`),
codes.ERR_NODE_NOT_STARTED
)
}
/** /**
* @fires Libp2p#error Emitted when an error occurs * @fires Node#error Emitted when an error occurs
* @fires Libp2p#peer:connect Emitted when a peer is connected to this node * @fires Node#peer:connect Emitted when a peer is connected to this node
* @fires Libp2p#peer:disconnect Emitted when a peer disconnects from this node * @fires Node#peer:disconnect Emitted when a peer disconnects from this node
* @fires Libp2p#peer:discovery Emitted when a peer is discovered * @fires Node#peer:discovery Emitted when a peer is discovered
* @fires Libp2p#start Emitted when the node and its services has started * @fires Node#start Emitted when the node and its services has started
* @fires Libp2p#stop Emitted when the node and its services has stopped * @fires Node#stop Emitted when the node and its services has stopped
*/ */
class Libp2p extends EventEmitter { class Node extends EventEmitter {
constructor (_options) { constructor (_options) {
super() super()
// validateConfig will ensure the config is correct, // validateConfig will ensure the config is correct,
// and add default values where appropriate // and add default values where appropriate
this._options = validateConfig(_options) _options = validateConfig(_options)
this.datastore = this._options.datastore this.peerInfo = _options.peerInfo
this.peerInfo = this._options.peerInfo this.peerBook = _options.peerBook || new PeerBook()
this.peerBook = this._options.peerBook || new PeerBook()
this._modules = this._options.modules this._modules = _options.modules
this._config = this._options.config this._config = _options.config
this._isStarted = false
this._transport = [] // Transport instances/references this._transport = [] // Transport instances/references
this._discovery = [] // Discovery service instances/references this._discovery = [] // Discovery service instances/references
// create the switch, and listen for errors this._switch = new Switch(this.peerInfo, this.peerBook, _options.switch)
this._switch = new Switch(this.peerInfo, this.peerBook, this._options.switch)
this._switch.on('error', (...args) => this.emit('error', ...args))
this.stats = this._switch.stats this.stats = this._switch.stats
this.connectionManager = new ConnectionManager(this, this._options.connectionManager) this.connectionManager = new ConnectionManager(this, _options.connectionManager)
// Attach stream multiplexers // Attach stream multiplexers
if (this._modules.streamMuxer) { if (this._modules.streamMuxer) {
@@ -81,6 +69,7 @@ class Libp2p extends EventEmitter {
// reuse this muxed connection // reuse this muxed connection
this._switch.on('peer-mux-established', (peerInfo) => { this._switch.on('peer-mux-established', (peerInfo) => {
this.emit('peer:connect', peerInfo) this.emit('peer:connect', peerInfo)
this.peerBook.put(peerInfo)
}) })
this._switch.on('peer-mux-closed', (peerInfo) => { this._switch.on('peer-mux-closed', (peerInfo) => {
@@ -88,14 +77,6 @@ class Libp2p extends EventEmitter {
}) })
} }
// Events for anytime connections are created/removed
this._switch.on('connection:start', (peerInfo) => {
this.emit('connection:start', peerInfo)
})
this._switch.on('connection:end', (peerInfo) => {
this.emit('connection:end', peerInfo)
})
// Attach crypto channels // Attach crypto channels
if (this._modules.connEncryption) { if (this._modules.connEncryption) {
let cryptos = this._modules.connEncryption let cryptos = this._modules.connEncryption
@@ -112,12 +93,16 @@ class Libp2p extends EventEmitter {
} }
// dht provided components (peerRouting, contentRouting, dht) // dht provided components (peerRouting, contentRouting, dht)
if (this._config.dht.enabled) { if (this._config.EXPERIMENTAL.dht) {
const DHT = this._modules.dht const DHT = this._modules.dht
const enabledDiscovery = this._config.dht.enabledDiscovery !== false
this._dht = new DHT(this._switch, { this._dht = new DHT(this._switch, {
datastore: this.datastore, kBucketSize: this._config.dht.kBucketSize || 20,
...this._config.dht enabledDiscovery,
// TODO make datastore an option of libp2p itself so
// that other things can use it as well
datastore: dht.datastore
}) })
} }
@@ -176,31 +161,6 @@ class Libp2p extends EventEmitter {
log.error(err) log.error(err)
this.emit('error', err) this.emit('error', err)
}) })
// Once we start, emit and dial any peers we may have already discovered
this.state.on('STARTED', () => {
this.peerBook.getAllArray().forEach((peerInfo) => {
this.emit('peer:discovery', peerInfo)
this._maybeConnect(peerInfo)
})
})
this._peerDiscovered = this._peerDiscovered.bind(this)
}
/**
* Overrides EventEmitter.emit to conditionally emit errors
* if there is a handler. If not, errors will be logged.
* @param {string} eventName
* @param {...any} args
* @returns {void}
*/
emit (eventName, ...args) {
if (eventName === 'error' && !this._events.error) {
log.error(...args)
} else {
super.emit(eventName, ...args)
}
} }
/** /**
@@ -210,7 +170,7 @@ class Libp2p extends EventEmitter {
* @returns {void} * @returns {void}
*/ */
start (callback = () => {}) { start (callback = () => {}) {
emitFirst(this, ['error', 'start'], callback) this.once('start', callback)
this.state('start') this.state('start')
} }
@@ -221,7 +181,7 @@ class Libp2p extends EventEmitter {
* @returns {void} * @returns {void}
*/ */
stop (callback = () => {}) { stop (callback = () => {}) {
emitFirst(this, ['error', 'stop'], callback) this.once('stop', callback)
this.state('stop') this.state('stop')
} }
@@ -238,6 +198,8 @@ class Libp2p extends EventEmitter {
* @returns {void} * @returns {void}
*/ */
dial (peer, callback) { dial (peer, callback) {
assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE)
this.dialProtocol(peer, null, callback) this.dialProtocol(peer, null, callback)
} }
@@ -252,9 +214,7 @@ class Libp2p extends EventEmitter {
* @returns {void} * @returns {void}
*/ */
dialProtocol (peer, protocol, callback) { dialProtocol (peer, protocol, callback) {
if (!this.isStarted()) { assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE)
return callback(notStarted('dial', this.state._state))
}
if (typeof protocol === 'function') { if (typeof protocol === 'function') {
callback = protocol callback = protocol
@@ -264,7 +224,11 @@ class Libp2p extends EventEmitter {
this._getPeerInfo(peer, (err, peerInfo) => { this._getPeerInfo(peer, (err, peerInfo) => {
if (err) { return callback(err) } if (err) { return callback(err) }
this._switch.dial(peerInfo, protocol, callback) this._switch.dial(peerInfo, protocol, (err, conn) => {
if (err) { return callback(err) }
this.peerBook.put(peerInfo)
callback(null, conn)
})
}) })
} }
@@ -278,9 +242,7 @@ class Libp2p extends EventEmitter {
* @returns {void} * @returns {void}
*/ */
dialFSM (peer, protocol, callback) { dialFSM (peer, protocol, callback) {
if (!this.isStarted()) { assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE)
return callback(notStarted('dial', this.state._state))
}
if (typeof protocol === 'function') { if (typeof protocol === 'function') {
callback = protocol callback = protocol
@@ -290,11 +252,19 @@ class Libp2p extends EventEmitter {
this._getPeerInfo(peer, (err, peerInfo) => { this._getPeerInfo(peer, (err, peerInfo) => {
if (err) { return callback(err) } if (err) { return callback(err) }
this._switch.dialFSM(peerInfo, protocol, callback) const connFSM = this._switch.dialFSM(peerInfo, protocol, (err) => {
if (!err) {
this.peerBook.put(peerInfo)
}
})
callback(null, connFSM)
}) })
} }
hangUp (peer, callback) { hangUp (peer, callback) {
assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE)
this._getPeerInfo(peer, (err, peerInfo) => { this._getPeerInfo(peer, (err, peerInfo) => {
if (err) { return callback(err) } if (err) { return callback(err) }
@@ -304,7 +274,7 @@ class Libp2p extends EventEmitter {
ping (peer, callback) { ping (peer, callback) {
if (!this.isStarted()) { if (!this.isStarted()) {
return callback(notStarted('ping', this.state._state)) return callback(new Error(NOT_STARTED_ERROR_MESSAGE))
} }
this._getPeerInfo(peer, (err, peerInfo) => { this._getPeerInfo(peer, (err, peerInfo) => {
@@ -336,7 +306,7 @@ class Libp2p extends EventEmitter {
this.peerInfo.multiaddrs.toArray().forEach((ma) => { this.peerInfo.multiaddrs.toArray().forEach((ma) => {
if (!ma.getPeerId()) { if (!ma.getPeerId()) {
maOld.push(ma) maOld.push(ma)
maNew.push(ma.encapsulate('/p2p/' + this.peerInfo.id.toB58String())) maNew.push(ma.encapsulate('/ipfs/' + this.peerInfo.id.toB58String()))
} }
}) })
this.peerInfo.multiaddrs.replace(maOld, maNew) this.peerInfo.multiaddrs.replace(maOld, maNew)
@@ -347,13 +317,13 @@ class Libp2p extends EventEmitter {
let t let t
if (typeof Transport === 'function') { if (typeof Transport === 'function') {
t = new Transport({ libp2p: this }) t = new Transport()
} else { } else {
t = Transport t = Transport
} }
if (t.filter(multiaddrs).length > 0) { if (t.filter(multiaddrs).length > 0) {
this._switch.transport.add(t.tag || t[Symbol.toStringTag], t) this._switch.transport.add(t.tag || t.constructor.name, t)
} else if (WebSockets.isWebSockets(t)) { } else if (WebSockets.isWebSockets(t)) {
// TODO find a cleaner way to signal that a transport is always used // TODO find a cleaner way to signal that a transport is always used
// for dialing, even if no listener // for dialing, even if no listener
@@ -373,6 +343,60 @@ class Libp2p extends EventEmitter {
this._switch.transport.add(ws.tag || ws.constructor.name, ws) this._switch.transport.add(ws.tag || ws.constructor.name, ws)
} }
// all transports need to be setup before discover starts
if (this._modules.peerDiscovery) {
each(this._modules.peerDiscovery, (D, _cb) => {
let config = {}
if (D.tag &&
this._config.peerDiscovery &&
this._config.peerDiscovery[D.tag]) {
config = this._config.peerDiscovery[D.tag]
}
// If not configured to be enabled/disabled then enable by default
const enabled = config.enabled == null ? true : config.enabled
// If enabled then start it
if (enabled) {
let d
if (typeof D === 'function') {
d = new D(Object.assign({}, config, { peerInfo: this.peerInfo }))
} else {
d = D
}
d.on('peer', (peerInfo) => this.emit('peer:discovery', peerInfo))
this._discovery.push(d)
d.start(_cb)
} else {
_cb()
}
}, cb)
} else {
cb()
}
},
(cb) => {
// TODO: chicken-and-egg problem #1:
// have to set started here because DHT requires libp2p is already started
this._isStarted = true
if (this._dht) {
this._dht.start(cb)
} else {
cb()
}
},
(cb) => {
// TODO: chicken-and-egg problem #2:
// have to set started here because FloodSub requires libp2p is already started
if (this._floodSub) {
return this._floodSub.start(cb)
}
cb()
},
(cb) => {
// detect which multiaddrs we don't have a transport for and remove them // detect which multiaddrs we don't have a transport for and remove them
const multiaddrs = this.peerInfo.multiaddrs.toArray() const multiaddrs = this.peerInfo.multiaddrs.toArray()
@@ -383,30 +407,6 @@ class Libp2p extends EventEmitter {
} }
}) })
cb() cb()
},
(cb) => {
if (this._dht) {
this._dht.start(() => {
this._dht.on('peer', this._peerDiscovered)
cb()
})
} else {
cb()
}
},
(cb) => {
if (this._floodSub) {
return this._floodSub.start(cb)
}
cb()
},
// Peer Discovery
(cb) => {
if (this._modules.peerDiscovery) {
this._setupPeerDiscovery(cb)
} else {
cb()
}
} }
], (err) => { ], (err) => {
if (err) { if (err) {
@@ -421,17 +421,16 @@ class Libp2p extends EventEmitter {
_onStopping () { _onStopping () {
series([ series([
(cb) => { (cb) => {
if (this._modules.peerDiscovery) {
// stop all discoveries before continuing with shutdown // stop all discoveries before continuing with shutdown
parallel( return parallel(
this._discovery.map((d) => { this._discovery.map((d) => {
d.removeListener('peer', this._peerDiscovered) return (_cb) => d.stop(() => { _cb() })
return (_cb) => d.stop((err) => {
log.error('an error occurred stopping the discovery service', err)
_cb()
})
}), }),
cb cb
) )
}
cb()
}, },
(cb) => { (cb) => {
if (this._floodSub) { if (this._floodSub) {
@@ -441,19 +440,17 @@ class Libp2p extends EventEmitter {
}, },
(cb) => { (cb) => {
if (this._dht) { if (this._dht) {
this._dht.removeListener('peer', this._peerDiscovered)
return this._dht.stop(cb) return this._dht.stop(cb)
} }
cb() cb()
}, },
(cb) => { (cb) => {
this.connectionManager.stop() // Ensures idempotency for restarts
this._switch.stop(cb) this._switch.transport.removeAll(cb)
}, },
(cb) => { (cb) => {
// Ensures idempotent restarts, ignore any errors this.connectionManager.stop()
// from removeAll, they're not useful at this point this._switch.stop(cb)
this._switch.transport.removeAll(() => cb())
} }
], (err) => { ], (err) => {
if (err) { if (err) {
@@ -463,107 +460,6 @@ class Libp2p extends EventEmitter {
this.state('done') this.state('done')
}) })
} }
/**
* Handles discovered peers. Each discovered peer will be emitted via
* the `peer:discovery` event. If auto dial is enabled for libp2p
* and the current connection count is under the low watermark, the
* peer will be dialed.
*
* TODO: If `peerBook.put` becomes centralized, https://github.com/libp2p/js-libp2p/issues/345,
* it would be ideal if only new peers were emitted. Currently, with
* other modules adding peers to the `PeerBook` we have no way of knowing
* if a peer is new or not, so it has to be emitted.
*
* @private
* @param {PeerInfo} peerInfo
*/
_peerDiscovered (peerInfo) {
if (peerInfo.id.toB58String() === this.peerInfo.id.toB58String()) {
log.error(new Error(codes.ERR_DISCOVERED_SELF))
return
}
peerInfo = this.peerBook.put(peerInfo)
if (!this.isStarted()) return
this.emit('peer:discovery', peerInfo)
this._maybeConnect(peerInfo)
} }
/** module.exports = Node
* Will dial to the given `peerInfo` if the current number of
* connected peers is less than the configured `ConnectionManager`
* minPeers.
* @private
* @param {PeerInfo} peerInfo
*/
_maybeConnect (peerInfo) {
// If auto dialing is on, check if we should dial
if (this._config.peerDiscovery.autoDial === true && !peerInfo.isConnected()) {
const minPeers = this._options.connectionManager.minPeers || 0
if (minPeers > Object.keys(this._switch.connection.connections).length) {
log('connecting to discovered peer')
this._switch.dialer.connect(peerInfo, (err) => {
err && log.error('could not connect to discovered peer', err)
})
}
}
}
/**
* Initializes and starts peer discovery services
*
* @private
* @param {function(Error)} callback
*/
_setupPeerDiscovery (callback) {
for (const DiscoveryService of this._modules.peerDiscovery) {
let config = {
enabled: true // on by default
}
if (DiscoveryService.tag &&
this._config.peerDiscovery &&
this._config.peerDiscovery[DiscoveryService.tag]) {
config = { ...config, ...this._config.peerDiscovery[DiscoveryService.tag] }
}
if (config.enabled) {
let discoveryService
if (typeof DiscoveryService === 'function') {
discoveryService = new DiscoveryService(Object.assign({}, config, { peerInfo: this.peerInfo }))
} else {
discoveryService = DiscoveryService
}
discoveryService.on('peer', this._peerDiscovered)
this._discovery.push(discoveryService)
}
}
each(this._discovery, (d, cb) => {
d.start(cb)
}, callback)
}
}
module.exports = Libp2p
/**
* Like `new Libp2p(options)` except it will create a `PeerInfo`
* instance if one is not provided in options.
* @param {object} options Libp2p configuration options
* @param {function(Error, Libp2p)} callback
* @returns {void}
*/
module.exports.createLibp2p = (options, callback) => {
if (options.peerInfo) {
return nextTick(callback, null, new Libp2p(options))
}
PeerInfo.create((err, peerInfo) => {
if (err) return callback(err)
options.peerInfo = peerInfo
callback(null, new Libp2p(options))
})
}

View File

@@ -22,15 +22,15 @@ module.exports = (node) => {
* @returns {void} * @returns {void}
*/ */
findPeer: (id, options, callback) => { findPeer: (id, options, callback) => {
if (!routers.length) {
callback(errCode(new Error('No peer routers available'), 'NO_ROUTERS_AVAILABLE'))
}
if (typeof options === 'function') { if (typeof options === 'function') {
callback = options callback = options
options = {} options = {}
} }
if (!routers.length) {
callback(errCode(new Error('No peer routers available'), 'NO_ROUTERS_AVAILABLE'))
}
const tasks = routers.map((router) => { const tasks = routers.map((router) => {
return (cb) => router.findPeer(id, options, (err, result) => { return (cb) => router.findPeer(id, options, (err, result) => {
if (err) { if (err) {

View File

@@ -1,11 +1,9 @@
'use strict' 'use strict'
const nextTick = require('async/nextTick') const setImmediate = require('async/setImmediate')
const { messages, codes } = require('./errors') const NOT_STARTED_YET = require('./error-messages').NOT_STARTED_YET
const FloodSub = require('libp2p-floodsub') const FloodSub = require('libp2p-floodsub')
const errCode = require('err-code')
module.exports = (node) => { module.exports = (node) => {
const floodSub = new FloodSub(node) const floodSub = new FloodSub(node)
@@ -20,7 +18,7 @@ module.exports = (node) => {
} }
if (!node.isStarted() && !floodSub.started) { if (!node.isStarted() && !floodSub.started) {
return nextTick(callback, errCode(new Error(messages.NOT_STARTED_YET), codes.PUBSUB_NOT_STARTED)) return setImmediate(() => callback(new Error(NOT_STARTED_YET)))
} }
function subscribe (cb) { function subscribe (cb) {
@@ -29,56 +27,51 @@ module.exports = (node) => {
} }
floodSub.on(topic, handler) floodSub.on(topic, handler)
nextTick(cb) setImmediate(cb)
} }
subscribe(callback) subscribe(callback)
}, },
unsubscribe: (topic, handler, callback) => { unsubscribe: (topic, handler) => {
if (!node.isStarted() && !floodSub.started) { if (!node.isStarted() && !floodSub.started) {
return nextTick(callback, errCode(new Error(messages.NOT_STARTED_YET), codes.PUBSUB_NOT_STARTED)) throw new Error(NOT_STARTED_YET)
} }
if (!handler && !callback) {
floodSub.removeAllListeners(topic)
} else {
floodSub.removeListener(topic, handler) floodSub.removeListener(topic, handler)
}
if (floodSub.listenerCount(topic) === 0) { if (floodSub.listenerCount(topic) === 0) {
floodSub.unsubscribe(topic) floodSub.unsubscribe(topic)
} }
if (typeof callback === 'function') {
nextTick(() => callback())
}
}, },
publish: (topic, data, callback) => { publish: (topic, data, callback) => {
if (!node.isStarted() && !floodSub.started) { if (!node.isStarted() && !floodSub.started) {
return nextTick(callback, errCode(new Error(messages.NOT_STARTED_YET), codes.PUBSUB_NOT_STARTED)) return setImmediate(() => callback(new Error(NOT_STARTED_YET)))
} }
if (!Buffer.isBuffer(data)) { if (!Buffer.isBuffer(data)) {
return nextTick(callback, errCode(new Error('data must be a Buffer'), 'ERR_DATA_IS_NOT_A_BUFFER')) return setImmediate(() => callback(new Error('data must be a Buffer')))
} }
floodSub.publish(topic, data, callback) floodSub.publish(topic, data)
setImmediate(() => callback())
}, },
ls: (callback) => { ls: (callback) => {
if (!node.isStarted() && !floodSub.started) { if (!node.isStarted() && !floodSub.started) {
return nextTick(callback, errCode(new Error(messages.NOT_STARTED_YET), codes.PUBSUB_NOT_STARTED)) return setImmediate(() => callback(new Error(NOT_STARTED_YET)))
} }
const subscriptions = Array.from(floodSub.subscriptions) const subscriptions = Array.from(floodSub.subscriptions)
nextTick(() => callback(null, subscriptions)) setImmediate(() => callback(null, subscriptions))
}, },
peers: (topic, callback) => { peers: (topic, callback) => {
if (!node.isStarted() && !floodSub.started) { if (!node.isStarted() && !floodSub.started) {
return nextTick(callback, errCode(new Error(messages.NOT_STARTED_YET), codes.PUBSUB_NOT_STARTED)) return setImmediate(() => callback(new Error(NOT_STARTED_YET)))
} }
if (typeof topic === 'function') { if (typeof topic === 'function') {
@@ -90,7 +83,7 @@ module.exports = (node) => {
.filter((peer) => topic ? peer.topics.has(topic) : true) .filter((peer) => topic ? peer.topics.has(topic) : true)
.map((peer) => peer.info.id.toB58String()) .map((peer) => peer.info.id.toB58String())
nextTick(() => callback(null, peers)) setImmediate(() => callback(null, peers))
}, },
setMaxListeners (n) { setMaxListeners (n) {

View File

@@ -1,33 +0,0 @@
'use strict'
const once = require('once')
/**
* Registers `handler` to each event in `events`. The `handler`
* will only be called for the first event fired, at which point
* the `handler` will be removed as a listener.
*
* Ensures `handler` is only called once.
*
* @example
* // will call `callback` when `start` or `error` is emitted by `this`
* emitFirst(this, ['error', 'start'], callback)
*
* @private
* @param {EventEmitter} emitter The emitter to listen on
* @param {Array<string>} events The events to listen for
* @param {function(*)} handler The handler to call when an event is triggered
* @returns {void}
*/
function emitFirst (emitter, events, handler) {
handler = once(handler)
events.forEach((e) => {
emitter.once(e, (...args) => {
events.forEach((ev) => {
emitter.removeListener(ev, handler)
})
handler.apply(emitter, args)
})
})
}
module.exports.emitFirst = emitFirst

View File

@@ -1,4 +1,3 @@
'use strict' 'use strict'
require('./circuit-relay.browser')
require('./transports.browser') require('./transports.browser')

View File

@@ -1,98 +0,0 @@
/* eslint-env mocha */
'use strict'
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const createNode = require('./utils/create-node')
const tryEcho = require('./utils/try-echo')
const echo = require('./utils/echo')
const {
getPeerRelay
} = require('./utils/constants')
function setupNodeWithRelay (addrs, options = {}) {
options = {
config: {
relay: {
enabled: true
},
...options.config
},
...options
}
return new Promise((resolve) => {
createNode(addrs, options, (err, node) => {
expect(err).to.not.exist()
node.handle(echo.multicodec, echo)
node.start((err) => {
expect(err).to.not.exist()
resolve(node)
})
})
})
}
describe('circuit relay', () => {
let browserNode1
let browserNode2
let peerRelay
before('get peer relay', async () => {
peerRelay = await new Promise(resolve => {
getPeerRelay((err, peer) => {
expect(err).to.not.exist()
resolve(peer)
})
})
})
before('create the browser nodes', async () => {
[browserNode1, browserNode2] = await Promise.all([
setupNodeWithRelay([]),
setupNodeWithRelay([])
])
})
before('connect to the relay node', async () => {
await Promise.all(
[browserNode1, browserNode2].map((node) => {
return new Promise(resolve => {
node.dialProtocol(peerRelay, (err) => {
expect(err).to.not.exist()
resolve()
})
})
})
)
})
before('give time for HOP support to be determined', async () => {
await new Promise(resolve => {
setTimeout(resolve, 1e3)
})
})
after(async () => {
await Promise.all(
[browserNode1, browserNode2].map((node) => {
return new Promise((resolve) => {
node.stop(resolve)
})
})
)
})
it('should be able to echo over relay', (done) => {
browserNode1.dialProtocol(browserNode2.peerInfo, echo.multicodec, (err, conn) => {
expect(err).to.not.exist()
expect(conn).to.exist()
tryEcho(conn, done)
})
})
})

View File

@@ -114,9 +114,10 @@ describe('circuit relay', () => {
nodeWS2 = node nodeWS2 = node
cb() cb()
}), }),
// set up node with TCP // set up node with TCP and listening on relay1
(cb) => setupNode([ (cb) => setupNode([
'/ip4/0.0.0.0/tcp/0' '/ip4/0.0.0.0/tcp/0',
`/ipfs/${relayNode1.peerInfo.id.toB58String()}/p2p-circuit`
], { ], {
config: { config: {
relay: { relay: {
@@ -127,9 +128,10 @@ describe('circuit relay', () => {
nodeTCP1 = node nodeTCP1 = node
cb() cb()
}), }),
// set up node with TCP // set up node with TCP and listening on relay2 over TCP transport
(cb) => setupNode([ (cb) => setupNode([
'/ip4/0.0.0.0/tcp/0' '/ip4/0.0.0.0/tcp/0',
`/ip4/0.0.0.0/tcp/0/ipfs/${relayNode2.peerInfo.id.toB58String()}/p2p-circuit`
], { ], {
config: { config: {
relay: { relay: {

View File

@@ -11,7 +11,6 @@ const WS = require('libp2p-websockets')
const Bootstrap = require('libp2p-bootstrap') const Bootstrap = require('libp2p-bootstrap')
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing') const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
const DelegatedContentRouter = require('libp2p-delegated-content-routing') const DelegatedContentRouter = require('libp2p-delegated-content-routing')
const DHT = require('libp2p-kad-dht')
const validateConfig = require('../src/config').validate const validateConfig = require('../src/config').validate
@@ -55,57 +54,7 @@ describe('configuration', () => {
transport: [ ] transport: [ ]
} }
}) })
}).to.throw('ERROR_EMPTY') }).to.throw()
})
it('should add defaults to config', () => {
const options = {
peerInfo,
modules: {
transport: [ WS ],
peerDiscovery: [ Bootstrap ],
dht: DHT
}
}
const expected = {
peerInfo,
connectionManager: {
minPeers: 25
},
modules: {
transport: [ WS ],
peerDiscovery: [ Bootstrap ],
dht: DHT
},
config: {
peerDiscovery: {
autoDial: true
},
EXPERIMENTAL: {
pubsub: false
},
dht: {
kBucketSize: 20,
enabled: false,
randomWalk: {
enabled: false,
queriesPerPeriod: 1,
interval: 300000,
timeout: 10000
}
},
relay: {
enabled: true,
hop: {
active: false,
enabled: false
}
}
}
}
expect(validateConfig(options)).to.deep.equal(expected)
}) })
it('should add defaults to missing items', () => { it('should add defaults to missing items', () => {
@@ -113,8 +62,7 @@ describe('configuration', () => {
peerInfo, peerInfo,
modules: { modules: {
transport: [ WS ], transport: [ WS ],
peerDiscovery: [ Bootstrap ], peerDiscovery: [ Bootstrap ]
dht: DHT
}, },
config: { config: {
peerDiscovery: { peerDiscovery: {
@@ -128,41 +76,23 @@ describe('configuration', () => {
const expected = { const expected = {
peerInfo, peerInfo,
connectionManager: {
minPeers: 25
},
modules: { modules: {
transport: [ WS ], transport: [ WS ],
peerDiscovery: [ Bootstrap ], peerDiscovery: [ Bootstrap ]
dht: DHT
}, },
config: { config: {
peerDiscovery: { peerDiscovery: {
autoDial: true,
bootstrap: { bootstrap: {
interval: 1000, interval: 1000,
enabled: true enabled: true
} }
}, },
EXPERIMENTAL: { EXPERIMENTAL: {
pubsub: false pubsub: false,
}, dht: false
dht: {
kBucketSize: 20,
enabled: false,
randomWalk: {
enabled: false,
queriesPerPeriod: 1,
interval: 300000,
timeout: 10000
}
}, },
relay: { relay: {
enabled: true, enabled: true
hop: {
active: false,
enabled: false
}
} }
} }
} }
@@ -170,33 +100,6 @@ describe('configuration', () => {
expect(validateConfig(options)).to.deep.equal(expected) expect(validateConfig(options)).to.deep.equal(expected)
}) })
it('should allow for configuring the switch', () => {
const options = {
peerInfo,
switch: {
blacklistTTL: 60e3,
blackListAttempts: 5,
maxParallelDials: 100,
maxColdCalls: 50,
dialTimeout: 30e3
},
modules: {
transport: [ WS ],
peerDiscovery: [ ]
}
}
expect(validateConfig(options)).to.deep.include({
switch: {
blacklistTTL: 60e3,
blackListAttempts: 5,
maxParallelDials: 100,
maxColdCalls: 50,
dialTimeout: 30e3
}
})
})
it('should allow for delegated content and peer routing', () => { it('should allow for delegated content and peer routing', () => {
const peerRouter = new DelegatedPeerRouter() const peerRouter = new DelegatedPeerRouter()
const contentRouter = new DelegatedContentRouter(peerInfo) const contentRouter = new DelegatedContentRouter(peerInfo)
@@ -207,8 +110,7 @@ describe('configuration', () => {
transport: [ WS ], transport: [ WS ],
peerDiscovery: [ Bootstrap ], peerDiscovery: [ Bootstrap ],
peerRouting: [ peerRouter ], peerRouting: [ peerRouter ],
contentRouting: [ contentRouter ], contentRouting: [ contentRouter ]
dht: DHT
}, },
config: { config: {
peerDiscovery: { peerDiscovery: {
@@ -233,100 +135,12 @@ describe('configuration', () => {
transport: [ WS ] transport: [ WS ]
}, },
config: { config: {
dht: { EXPERIMENTAL: {
enabled: true dht: true
} }
} }
} }
expect(() => validateConfig(options)).to.throw() expect(() => validateConfig(options)).to.throw()
}) })
it('should be able to add validators and selectors for dht', () => {
const selectors = {}
const validators = {}
const options = {
peerInfo,
modules: {
transport: [WS],
dht: DHT
},
config: {
dht: {
selectors,
validators
}
}
}
const expected = {
peerInfo,
connectionManager: {
minPeers: 25
},
modules: {
transport: [WS],
dht: DHT
},
config: {
EXPERIMENTAL: {
pubsub: false
},
peerDiscovery: {
autoDial: true
},
relay: {
enabled: true,
hop: {
active: false,
enabled: false
}
},
dht: {
selectors,
validators
}
}
}
expect(validateConfig(options)).to.deep.equal(expected)
})
it('should support new properties for the dht config', () => {
const options = {
peerInfo,
modules: {
transport: [WS],
dht: DHT
},
config: {
dht: {
kBucketSize: 20,
enabled: false,
myNewDHTConfigProperty: true,
randomWalk: {
enabled: false,
queriesPerPeriod: 1,
interval: 300000,
timeout: 10000
}
}
}
}
const expected = {
kBucketSize: 20,
enabled: false,
myNewDHTConfigProperty: true,
randomWalk: {
enabled: false,
queriesPerPeriod: 1,
interval: 300000,
timeout: 10000
}
}
const actual = validateConfig(options).config.dht
expect(actual).to.deep.equal(expected)
})
}) })

View File

@@ -30,7 +30,13 @@ describe('.contentRouting', () => {
before(function (done) { before(function (done) {
this.timeout(5 * 1000) this.timeout(5 * 1000)
const tasks = _times(5, () => (cb) => { const tasks = _times(5, () => (cb) => {
createNode('/ip4/0.0.0.0/tcp/0', (err, node) => { createNode('/ip4/0.0.0.0/tcp/0', {
config: {
EXPERIMENTAL: {
dht: true
}
}
}, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
node.start((err) => cb(err, node)) node.start((err) => cb(err, node))
}) })
@@ -101,22 +107,6 @@ describe('.contentRouting', () => {
}) })
}) })
it('nodeE.contentRouting.findProviders with limited number of providers', (done) => {
parallel([
(cb) => nodeA.contentRouting.provide(cid, cb),
(cb) => nodeB.contentRouting.provide(cid, cb),
(cb) => nodeC.contentRouting.provide(cid, cb)
], (err) => {
expect(err).to.not.exist()
nodeE.contentRouting.findProviders(cid, { maxNumProviders: 2 }, (err, providers) => {
expect(err).to.not.exist()
expect(providers).to.have.length(2)
done()
})
})
})
it('nodeC.contentRouting.findProviders for non existing record (timeout)', (done) => { it('nodeC.contentRouting.findProviders for non existing record (timeout)', (done) => {
const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSnnnn') const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSnnnn')
@@ -153,9 +143,6 @@ describe('.contentRouting', () => {
contentRouting: [ delegate ] contentRouting: [ delegate ]
}, },
config: { config: {
dht: {
enabled: false
},
relay: { relay: {
enabled: true, enabled: true,
hop: { hop: {
@@ -317,6 +304,9 @@ describe('.contentRouting', () => {
enabled: true, enabled: true,
active: false active: false
} }
},
EXPERIMENTAL: {
dht: true
} }
} }
}) })
@@ -377,35 +367,4 @@ describe('.contentRouting', () => {
}) })
}) })
}) })
describe('no routers', () => {
let nodeA
before((done) => {
createNode('/ip4/0.0.0.0/tcp/0', {
config: {
dht: {
enabled: false
}
}
}, (err, node) => {
expect(err).to.not.exist()
nodeA = node
done()
})
})
it('.findProviders should return an error with no options', (done) => {
nodeA.contentRouting.findProviders('a cid', (err) => {
expect(err).to.exist()
done()
})
})
it('.findProviders should return an error with options', (done) => {
nodeA.contentRouting.findProviders('a cid', { maxTimeout: 5000 }, (err) => {
expect(err).to.exist()
done()
})
})
})
}) })

View File

@@ -7,23 +7,14 @@ const expect = chai.expect
const series = require('async/series') const series = require('async/series')
const createNode = require('./utils/create-node') const createNode = require('./utils/create-node')
const sinon = require('sinon') const sinon = require('sinon')
const { createLibp2p } = require('../src')
const WS = require('libp2p-websockets')
const PeerInfo = require('peer-info')
describe('libp2p creation', () => { describe('libp2p creation', () => {
afterEach(() => {
sinon.restore()
})
it('should be able to start and stop successfully', (done) => { it('should be able to start and stop successfully', (done) => {
createNode([], { createNode([], {
config: { config: {
EXPERIMENTAL: { EXPERIMENTAL: {
dht: true,
pubsub: true pubsub: true
},
dht: {
enabled: true
} }
} }
}, (err, node) => { }, (err, node) => {
@@ -78,66 +69,15 @@ describe('libp2p creation', () => {
createNode([], { createNode([], {
config: { config: {
EXPERIMENTAL: { EXPERIMENTAL: {
dht: false,
pubsub: false pubsub: false
} }
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
expect(node._dht).to.not.exist()
expect(node._floodSub).to.not.exist() expect(node._floodSub).to.not.exist()
done() done()
}) })
}) })
it('should not throw errors from switch if node has no error listeners', (done) => {
createNode([], {}, (err, node) => {
expect(err).to.not.exist()
node._switch.emit('error', new Error('bad things'))
done()
})
})
it('should emit errors from switch if node has error listeners', (done) => {
const error = new Error('bad things')
createNode([], {}, (err, node) => {
expect(err).to.not.exist()
node.once('error', (err) => {
expect(err).to.eql(error)
done()
})
node._switch.emit('error', error)
})
})
it('createLibp2p should create a peerInfo instance', function (done) {
this.timeout(10e3)
createLibp2p({
modules: {
transport: [ WS ]
}
}, (err, libp2p) => {
expect(err).to.not.exist()
expect(libp2p).to.exist()
done()
})
})
it('createLibp2p should allow for a provided peerInfo instance', function (done) {
this.timeout(10e3)
PeerInfo.create((err, peerInfo) => {
expect(err).to.not.exist()
sinon.spy(PeerInfo, 'create')
createLibp2p({
peerInfo,
modules: {
transport: [ WS ]
}
}, (err, libp2p) => {
expect(err).to.not.exist()
expect(libp2p).to.exist()
expect(PeerInfo.create.callCount).to.eql(0)
done()
})
})
})
}) })

View File

@@ -6,18 +6,19 @@ const chai = require('chai')
chai.use(require('dirty-chai')) chai.use(require('dirty-chai'))
const expect = chai.expect const expect = chai.expect
const MemoryStore = require('interface-datastore').MemoryDatastore
const createNode = require('./utils/create-node') const createNode = require('./utils/create-node')
describe('.dht', () => { describe('.dht', () => {
describe('enabled', () => { describe('enabled', () => {
let nodeA let nodeA
const datastore = new MemoryStore()
before(function (done) { before(function (done) {
createNode('/ip4/0.0.0.0/tcp/0', { createNode('/ip4/0.0.0.0/tcp/0', {
datastore config: {
EXPERIMENTAL: {
dht: true
}
}
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
nodeA = node nodeA = node
@@ -119,8 +120,8 @@ describe('.dht', () => {
before(function (done) { before(function (done) {
createNode('/ip4/0.0.0.0/tcp/0', { createNode('/ip4/0.0.0.0/tcp/0', {
config: { config: {
dht: { EXPERIMENTAL: {
enabled: false dht: false
} }
} }
}, (err, node) => { }, (err, node) => {
@@ -140,7 +141,6 @@ describe('.dht', () => {
nodeA.dht.put(key, value, (err) => { nodeA.dht.put(key, value, (err) => {
expect(err).to.exist() expect(err).to.exist()
expect(err.code).to.equal('ERR_DHT_DISABLED')
done() done()
}) })
}) })
@@ -150,7 +150,6 @@ describe('.dht', () => {
nodeA.dht.get(key, (err) => { nodeA.dht.get(key, (err) => {
expect(err).to.exist() expect(err).to.exist()
expect(err.code).to.equal('ERR_DHT_DISABLED')
done() done()
}) })
}) })
@@ -160,7 +159,6 @@ describe('.dht', () => {
nodeA.dht.getMany(key, 10, (err) => { nodeA.dht.getMany(key, 10, (err) => {
expect(err).to.exist() expect(err).to.exist()
expect(err.code).to.equal('ERR_DHT_DISABLED')
done() done()
}) })
}) })

View File

@@ -13,20 +13,13 @@ describe('libp2p state machine (fsm)', () => {
describe('starting and stopping', () => { describe('starting and stopping', () => {
let node let node
beforeEach((done) => { beforeEach((done) => {
createNode([], { createNode([], (err, _node) => {
config: {
dht: {
enabled: false
}
}
}, (err, _node) => {
node = _node node = _node
done(err) done(err)
}) })
}) })
afterEach(() => { afterEach(() => {
node.removeAllListeners() node.removeAllListeners()
sinon.restore()
}) })
after((done) => { after((done) => {
node.stop(done) node.stop(done)
@@ -65,23 +58,6 @@ describe('libp2p state machine (fsm)', () => {
node.start() node.start()
}) })
it('should callback with an error when it occurs on stop', (done) => {
const error = new Error('some error starting')
node.once('start', () => {
node.once('error', (err) => {
expect(err).to.eql(error).mark()
})
node.stop((err) => {
expect(err).to.eql(error).mark()
})
})
expect(2).checks(done)
sinon.stub(node._switch, 'stop').callsArgWith(0, error)
node.start()
})
it('should noop when starting a started node', (done) => { it('should noop when starting a started node', (done) => {
node.once('start', () => { node.once('start', () => {
node.state.on('STARTING', () => { node.state.on('STARTING', () => {
@@ -134,35 +110,9 @@ describe('libp2p state machine (fsm)', () => {
throw new Error('should not start') throw new Error('should not start')
}) })
expect(3).checks(done) expect(2).checks(done)
node.start((err) => { node.start()
expect(err).to.eql(error).mark()
})
})
it('should not dial when the node is stopped', (done) => {
node.on('stop', () => {
node.dial(null, (err) => {
expect(err).to.exist()
expect(err.code).to.eql('ERR_NODE_NOT_STARTED')
done()
})
})
node.stop()
})
it('should not dial (fsm) when the node is stopped', (done) => {
node.on('stop', () => {
node.dialFSM(null, null, (err) => {
expect(err).to.exist()
expect(err.code).to.eql('ERR_NODE_NOT_STARTED')
done()
})
})
node.stop()
}) })
}) })
}) })

View File

@@ -11,7 +11,7 @@ describe('getPeerInfo', () => {
it('should callback with error for invalid string multiaddr', (done) => { it('should callback with error for invalid string multiaddr', (done) => {
getPeerInfo(null)('INVALID MULTIADDR', (err) => { getPeerInfo(null)('INVALID MULTIADDR', (err) => {
expect(err).to.exist() expect(err).to.exist()
expect(err.code).to.eql('ERR_INVALID_MULTIADDR') expect(err.message).to.contain('must start with a "/"')
done() done()
}) })
}) })
@@ -19,15 +19,7 @@ describe('getPeerInfo', () => {
it('should callback with error for invalid non-peer multiaddr', (done) => { it('should callback with error for invalid non-peer multiaddr', (done) => {
getPeerInfo(null)('/ip4/8.8.8.8/tcp/1080', (err) => { getPeerInfo(null)('/ip4/8.8.8.8/tcp/1080', (err) => {
expect(err).to.exist() expect(err).to.exist()
expect(err.code).to.equal('ERR_INVALID_MULTIADDR') expect(err.message).to.equal('peer multiaddr instance or string must include peerId')
done()
})
})
it('should callback with error for invalid non-peer multiaddr', (done) => {
getPeerInfo(null)(undefined, (err) => {
expect(err).to.exist()
expect(err.code).to.eql('ERR_INVALID_PEER_TYPE')
done() done()
}) })
}) })

View File

@@ -29,12 +29,10 @@ describe('multiaddr trim', () => {
expect(err).to.not.exist() expect(err).to.not.exist()
const multiaddrs = node.peerInfo.multiaddrs.toArray() const multiaddrs = node.peerInfo.multiaddrs.toArray()
expect(multiaddrs.length).to.be.at.least(2)
// ensure the p2p-webrtc-direct address has been trimmed
multiaddrs.forEach((addr) => {
expect(() => addr.decapsulate('/ip4/0.0.0.0/tcp/999/wss/p2p-webrtc-direct')).to.throw()
})
expect(multiaddrs.length).to.at.least(2)
expect(multiaddrs[0].toString())
.to.match(/^\/ip4\/127\.0\.0\.1\/tcp\/[0-9]+\/ws\/ipfs\/\w+$/)
node.stop(done) node.stop(done)
}) })
}) })

View File

@@ -5,24 +5,33 @@ const chai = require('chai')
chai.use(require('dirty-chai')) chai.use(require('dirty-chai'))
const expect = chai.expect const expect = chai.expect
const sinon = require('sinon') const sinon = require('sinon')
const signalling = require('libp2p-webrtc-star/src/sig-server')
const parallel = require('async/parallel') const parallel = require('async/parallel')
const crypto = require('crypto') const crypto = require('crypto')
const createNode = require('./utils/create-node') const createNode = require('./utils/create-node')
const echo = require('./utils/echo') const echo = require('./utils/echo')
const { WRTC_RENDEZVOUS_MULTIADDR } = require('./utils/constants')
describe('peer discovery', () => { describe('peer discovery', () => {
let nodeA let nodeA
let nodeB let nodeB
let nodeC let port = 24642
let ss
function setup (options) { function setup (options) {
before((done) => { before((done) => {
port++
parallel([ parallel([
(cb) => {
signalling.start({ port: port }, (err, server) => {
expect(err).to.not.exist()
ss = server
cb()
})
},
(cb) => createNode([ (cb) => createNode([
'/ip4/0.0.0.0/tcp/0', '/ip4/0.0.0.0/tcp/0',
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star` `/ip4/127.0.0.1/tcp/${port}/ws/p2p-webrtc-star`
], options, (err, node) => { ], options, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
nodeA = node nodeA = node
@@ -31,21 +40,12 @@ describe('peer discovery', () => {
}), }),
(cb) => createNode([ (cb) => createNode([
'/ip4/0.0.0.0/tcp/0', '/ip4/0.0.0.0/tcp/0',
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star` `/ip4/127.0.0.1/tcp/${port}/ws/p2p-webrtc-star`
], options, (err, node) => { ], options, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
nodeB = node nodeB = node
node.handle('/echo/1.0.0', echo) node.handle('/echo/1.0.0', echo)
node.start(cb) node.start(cb)
}),
(cb) => createNode([
'/ip4/0.0.0.0/tcp/0',
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
], options, (err, node) => {
expect(err).to.not.exist()
nodeC = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
}) })
], done) ], done)
}) })
@@ -54,20 +54,15 @@ describe('peer discovery', () => {
parallel([ parallel([
(cb) => nodeA.stop(cb), (cb) => nodeA.stop(cb),
(cb) => nodeB.stop(cb), (cb) => nodeB.stop(cb),
(cb) => nodeC.stop(cb) (cb) => ss.stop(cb)
], done) ], done)
}) })
afterEach(() => {
sinon.restore()
})
} }
describe('module registration', () => { describe('module registration', () => {
it('should enable by default a module passed as an object', (done) => { it('should enable by default a module passed as an object', (done) => {
const mockDiscovery = { const mockDiscovery = {
on: sinon.stub(), on: sinon.stub(),
removeListener: sinon.stub(),
start: sinon.stub().callsArg(0), start: sinon.stub().callsArg(0),
stop: sinon.stub().callsArg(0) stop: sinon.stub().callsArg(0)
} }
@@ -88,7 +83,6 @@ describe('peer discovery', () => {
it('should enable by default a module passed as a function', (done) => { it('should enable by default a module passed as a function', (done) => {
const mockDiscovery = { const mockDiscovery = {
on: sinon.stub(), on: sinon.stub(),
removeListener: sinon.stub(),
start: sinon.stub().callsArg(0), start: sinon.stub().callsArg(0),
stop: sinon.stub().callsArg(0) stop: sinon.stub().callsArg(0)
} }
@@ -111,7 +105,6 @@ describe('peer discovery', () => {
it('should enable module by configutation', (done) => { it('should enable module by configutation', (done) => {
const mockDiscovery = { const mockDiscovery = {
on: sinon.stub(), on: sinon.stub(),
removeListener: sinon.stub(),
start: sinon.stub().callsArg(0), start: sinon.stub().callsArg(0),
stop: sinon.stub().callsArg(0), stop: sinon.stub().callsArg(0),
tag: 'mockDiscovery' tag: 'mockDiscovery'
@@ -147,7 +140,6 @@ describe('peer discovery', () => {
it('should disable module by configutation', (done) => { it('should disable module by configutation', (done) => {
const mockDiscovery = { const mockDiscovery = {
on: sinon.stub(), on: sinon.stub(),
removeListener: sinon.stub(),
start: sinon.stub().callsArg(0), start: sinon.stub().callsArg(0),
stop: sinon.stub().callsArg(0), stop: sinon.stub().callsArg(0),
tag: 'mockDiscovery' tag: 'mockDiscovery'
@@ -183,7 +175,6 @@ describe('peer discovery', () => {
it('should register module passed as function', (done) => { it('should register module passed as function', (done) => {
const mockDiscovery = { const mockDiscovery = {
on: sinon.stub(), on: sinon.stub(),
removeListener: sinon.stub(),
start: sinon.stub().callsArg(0), start: sinon.stub().callsArg(0),
stop: sinon.stub().callsArg(0) stop: sinon.stub().callsArg(0)
} }
@@ -221,7 +212,6 @@ describe('peer discovery', () => {
it('should register module passed as object', (done) => { it('should register module passed as object', (done) => {
const mockDiscovery = { const mockDiscovery = {
on: sinon.stub(), on: sinon.stub(),
removeListener: sinon.stub(),
start: sinon.stub().callsArg(0), start: sinon.stub().callsArg(0),
stop: sinon.stub().callsArg(0), stop: sinon.stub().callsArg(0),
tag: 'mockDiscovery' tag: 'mockDiscovery'
@@ -248,44 +238,12 @@ describe('peer discovery', () => {
}) })
}) })
describe('discovery scenarios', () => {
setup({
config: {
dht: {
enabled: false
},
peerDiscovery: {
autoDial: false,
bootstrap: {
enabled: true,
list: []
}
}
}
})
it('should ignore self on discovery', function () {
const discoverySpy = sinon.spy()
nodeA.on('peer:discovery', discoverySpy)
nodeA._discovery[0].emit('peer', nodeA.peerInfo)
expect(discoverySpy.called).to.eql(false)
expect(nodeA.peerBook.getAllArray()).to.have.length(0)
expect()
})
})
describe('MulticastDNS', () => { describe('MulticastDNS', () => {
setup({ setup({
config: { config: {
dht: {
enabled: false
},
peerDiscovery: { peerDiscovery: {
autoDial: true,
mdns: { mdns: {
enabled: true, enabled: true,
interval: 200, // discover quickly
// use a random tag to prevent CI collision // use a random tag to prevent CI collision
serviceTag: crypto.randomBytes(10).toString('hex') serviceTag: crypto.randomBytes(10).toString('hex')
} }
@@ -293,23 +251,13 @@ describe('peer discovery', () => {
} }
}) })
it('find peers', function (done) { it('find a peer', function (done) {
let expectedPeers = new Set([ this.timeout(15 * 1000)
nodeB.peerInfo.id.toB58String(),
nodeC.peerInfo.id.toB58String()
])
function finish () { nodeA.once('peer:discovery', (peerInfo) => {
nodeA.removeAllListeners('peer:discovery') expect(nodeB.peerInfo.id.toB58String())
expect(expectedPeers.size).to.eql(0) .to.eql(peerInfo.id.toB58String())
done() done()
}
nodeA.on('peer:discovery', (peerInfo) => {
expectedPeers.delete(peerInfo.id.toB58String())
if (expectedPeers.size === 0) {
finish()
}
}) })
}) })
}) })
@@ -318,11 +266,7 @@ describe('peer discovery', () => {
describe.skip('WebRTCStar', () => { describe.skip('WebRTCStar', () => {
setup({ setup({
config: { config: {
dht: {
enabled: false
},
peerDiscovery: { peerDiscovery: {
autoDial: true,
webRTCStar: { webRTCStar: {
enabled: true enabled: true
} }
@@ -330,24 +274,12 @@ describe('peer discovery', () => {
} }
}) })
it('find peers', function (done) { it('find a peer', function (done) {
this.timeout(20e3) this.timeout(15 * 1000)
let expectedPeers = new Set([ nodeA.once('peer:discovery', (peerInfo) => {
nodeB.peerInfo.id.toB58String(), expect(nodeB.peerInfo.id.toB58String())
nodeC.peerInfo.id.toB58String() .to.eql(peerInfo.id.toB58String())
])
function finish () {
nodeA.removeAllListeners('peer:discovery')
expect(expectedPeers.size).to.eql(0)
done() done()
}
nodeA.on('peer:discovery', (peerInfo) => {
expectedPeers.delete(peerInfo.id.toB58String())
if (expectedPeers.size === 0) {
finish()
}
}) })
}) })
}) })
@@ -355,14 +287,9 @@ describe('peer discovery', () => {
describe('MulticastDNS + WebRTCStar', () => { describe('MulticastDNS + WebRTCStar', () => {
setup({ setup({
config: { config: {
dht: {
enabled: false
},
peerDiscovery: { peerDiscovery: {
autoDial: true,
mdns: { mdns: {
enabled: true, enabled: true,
interval: 200, // discovery quickly
// use a random tag to prevent CI collision // use a random tag to prevent CI collision
serviceTag: crypto.randomBytes(10).toString('hex') serviceTag: crypto.randomBytes(10).toString('hex')
}, },
@@ -373,122 +300,13 @@ describe('peer discovery', () => {
} }
}) })
it('find peers', function (done) { it('find a peer', function (done) {
let expectedPeers = new Set([ this.timeout(15 * 1000)
nodeB.peerInfo.id.toB58String(), nodeA.once('peer:discovery', (peerInfo) => {
nodeC.peerInfo.id.toB58String() expect(nodeB.peerInfo.id.toB58String())
]) .to.eql(peerInfo.id.toB58String())
function finish () {
nodeA.removeAllListeners('peer:discovery')
expect(expectedPeers.size).to.eql(0)
done()
}
nodeA.on('peer:discovery', (peerInfo) => {
expectedPeers.delete(peerInfo.id.toB58String())
if (expectedPeers.size === 0) {
finish()
}
})
})
})
describe('dht', () => {
setup({
config: {
peerDiscovery: {
autoDial: true,
mdns: {
enabled: false
},
webRTCStar: {
enabled: false
}
},
dht: {
enabled: true,
kBucketSize: 20,
randomWalk: {
enabled: true,
queriesPerPeriod: 1,
delay: 100,
interval: 200, // start the query sooner
timeout: 3000
}
}
}
})
it('find peers through the dht', function (done) {
let expectedPeers = new Set([
nodeB.peerInfo.id.toB58String(),
nodeC.peerInfo.id.toB58String()
])
function finish () {
nodeA.removeAllListeners('peer:discovery')
expect(expectedPeers.size).to.eql(0)
done()
}
nodeA.on('peer:discovery', (peerInfo) => {
expectedPeers.delete(peerInfo.id.toB58String())
if (expectedPeers.size === 0) {
finish()
}
})
// Topology:
// A -> B
// C -> B
nodeA.dial(nodeB.peerInfo, (err) => {
expect(err).to.not.exist()
})
nodeC.dial(nodeB.peerInfo, (err) => {
expect(err).to.not.exist()
})
})
})
describe('auto dial', () => {
setup({
connectionManager: {
minPeers: 1
},
config: {
peerDiscovery: {
autoDial: true,
mdns: {
enabled: false
},
webRTCStar: {
enabled: false
},
bootstrap: {
enabled: true,
list: []
}
},
dht: {
enabled: false
}
}
})
it('should only dial when the peer count is below the low watermark', (done) => {
const bootstrap = nodeA._discovery[0]
sinon.stub(nodeA._switch.dialer, 'connect').callsFake((peerInfo) => {
nodeA._switch.connection.connections[peerInfo.id.toB58String()] = []
})
bootstrap.emit('peer', nodeB.peerInfo)
bootstrap.emit('peer', nodeC.peerInfo)
// Only nodeB should get dialed
expect(nodeA._switch.dialer.connect.callCount).to.eql(1)
expect(nodeA._switch.dialer.connect.getCall(0).args[0]).to.eql(nodeB.peerInfo)
done() done()
}) })
}) })
}) })
})

View File

@@ -24,7 +24,13 @@ describe('.peerRouting', () => {
before('create the outer ring of connections', (done) => { before('create the outer ring of connections', (done) => {
const tasks = _times(5, () => (cb) => { const tasks = _times(5, () => (cb) => {
createNode('/ip4/0.0.0.0/tcp/0', (err, node) => { createNode('/ip4/0.0.0.0/tcp/0', {
config: {
EXPERIMENTAL: {
dht: true
}
}
}, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
node.start((err) => cb(err, node)) node.start((err) => cb(err, node))
}) })
@@ -106,11 +112,6 @@ describe('.peerRouting', () => {
createNode('/ip4/0.0.0.0/tcp/0', { createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
peerRouting: [ delegate ] peerRouting: [ delegate ]
},
config: {
dht: {
enabled: false
}
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@@ -212,6 +213,11 @@ describe('.peerRouting', () => {
createNode('/ip4/0.0.0.0/tcp/0', { createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
peerRouting: [ delegate ] peerRouting: [ delegate ]
},
config: {
EXPERIMENTAL: {
dht: true
}
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@@ -260,35 +266,4 @@ describe('.peerRouting', () => {
}) })
}) })
}) })
describe('no routers', () => {
let nodeA
before((done) => {
createNode('/ip4/0.0.0.0/tcp/0', {
config: {
dht: {
enabled: false
}
}
}, (err, node) => {
expect(err).to.not.exist()
nodeA = node
done()
})
})
it('.findPeer should return an error with no options', (done) => {
nodeA.peerRouting.findPeer('a cid', (err) => {
expect(err).to.exist()
done()
})
})
it('.findPeer should return an error with options', (done) => {
nodeA.peerRouting.findPeer('a cid', { maxTimeout: 5000 }, (err) => {
expect(err).to.exist()
done()
})
})
})
}) })

View File

@@ -9,7 +9,6 @@ const PeerId = require('peer-id')
const waterfall = require('async/waterfall') const waterfall = require('async/waterfall')
const WS = require('libp2p-websockets') const WS = require('libp2p-websockets')
const defaultsDeep = require('@nodeutils/defaults-deep') const defaultsDeep = require('@nodeutils/defaults-deep')
const DHT = require('libp2p-kad-dht')
const Libp2p = require('../src') const Libp2p = require('../src')
@@ -24,8 +23,7 @@ describe('private network', () => {
config = { config = {
peerInfo, peerInfo,
modules: { modules: {
transport: [ WS ], transport: [ WS ]
dht: DHT
} }
} }
cb() cb()

View File

@@ -5,13 +5,11 @@
const chai = require('chai') const chai = require('chai')
chai.use(require('dirty-chai')) chai.use(require('dirty-chai'))
chai.use(require('chai-checkmark'))
const expect = chai.expect const expect = chai.expect
const parallel = require('async/parallel') const parallel = require('async/parallel')
const series = require('async/series') const waterfall = require('async/waterfall')
const _times = require('lodash.times') const _times = require('lodash.times')
const { codes } = require('../src/errors')
const createNode = require('./utils/create-node') const createNode = require('./utils/create-node')
function startTwo (callback) { function startTwo (callback) {
@@ -54,115 +52,26 @@ function stopTwo (nodes, callback) {
// TODO: consider if all or some of those should come here // TODO: consider if all or some of those should come here
describe('.pubsub', () => { describe('.pubsub', () => {
describe('.pubsub on (default)', (done) => { describe('.pubsub on (default)', (done) => {
it('start two nodes and send one message, then unsubscribe', (done) => { it('start two nodes and send one message', (done) => {
// Check the final series error, and the publish handler waterfall([
expect(2).checks(done) (cb) => startTwo(cb),
(nodes, cb) => {
let nodes
const data = Buffer.from('test') const data = Buffer.from('test')
const handler = (msg) => { nodes[0].pubsub.subscribe('pubsub',
// verify the data is correct and mark the expect (msg) => {
expect(msg.data).to.eql(data).mark() expect(msg.data).to.eql(data)
} cb(null, nodes)
series([
// Start the nodes
(cb) => startTwo((err, _nodes) => {
nodes = _nodes
cb(err)
}),
// subscribe on the first
(cb) => nodes[0].pubsub.subscribe('pubsub', handler, cb),
// Wait a moment before publishing
(cb) => setTimeout(cb, 500),
// publish on the second
(cb) => nodes[1].pubsub.publish('pubsub', data, cb),
// ls subscripts
(cb) => nodes[1].pubsub.ls(cb),
// get subscribed peers
(cb) => nodes[1].pubsub.peers('pubsub', cb),
// Wait a moment before unsubscribing
(cb) => setTimeout(cb, 500),
// unsubscribe on the first
(cb) => nodes[0].pubsub.unsubscribe('pubsub', handler, cb),
// Stop both nodes
(cb) => stopTwo(nodes, cb)
], (err) => {
// Verify there was no error, and mark the expect
expect(err).to.not.exist().mark()
})
})
it('start two nodes and send one message, then unsubscribe without handler', (done) => {
// Check the final series error, and the publish handler
expect(3).checks(done)
let nodes
const data = Buffer.from('test')
const handler = (msg) => {
// verify the data is correct and mark the expect
expect(msg.data).to.eql(data).mark()
}
series([
// Start the nodes
(cb) => startTwo((err, _nodes) => {
nodes = _nodes
cb(err)
}),
// subscribe on the first
(cb) => nodes[0].pubsub.subscribe('pubsub', handler, cb),
// Wait a moment before publishing
(cb) => setTimeout(cb, 500),
// publish on the second
(cb) => nodes[1].pubsub.publish('pubsub', data, cb),
// Wait a moment before unsubscribing
(cb) => setTimeout(cb, 500),
// unsubscribe on the first
(cb) => {
nodes[0].pubsub.unsubscribe('pubsub')
// Wait a moment to make sure the ubsubscribe-from-all worked
setTimeout(cb, 500)
}, },
// Verify unsubscribed (err) => {
(cb) => {
nodes[0].pubsub.ls((err, topics) => {
expect(topics.length).to.eql(0).mark()
cb(err)
})
},
// Stop both nodes
(cb) => stopTwo(nodes, cb)
], (err) => {
// Verify there was no error, and mark the expect
expect(err).to.not.exist().mark()
})
})
it('publish should fail if data is not a buffer', (done) => {
createNode('/ip4/0.0.0.0/tcp/0', {
config: {
peerDiscovery: {
mdns: {
enabled: false
}
},
EXPERIMENTAL: {
pubsub: true
}
}
}, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
setTimeout(() => nodes[1].pubsub.publish('pubsub', data, (err) => {
node.start((err) => {
expect(err).to.not.exist() expect(err).to.not.exist()
}), 500)
node.pubsub.publish('pubsub', 'datastr', (err) => { }
expect(err).to.exist() )
expect(err.code).to.equal('ERR_DATA_IS_NOT_A_BUFFER') },
(nodes, cb) => stopTwo(nodes, cb)
done() ], done)
})
})
})
}) })
}) })
@@ -186,73 +95,4 @@ describe('.pubsub', () => {
}) })
}) })
}) })
describe('.pubsub on and node not started', () => {
let libp2pNode
before(function (done) {
createNode('/ip4/0.0.0.0/tcp/0', {
config: {
peerDiscovery: {
mdns: {
enabled: false
}
},
EXPERIMENTAL: {
pubsub: true
}
}
}, (err, node) => {
expect(err).to.not.exist()
libp2pNode = node
done()
})
})
it('fail to subscribe if node not started yet', (done) => {
libp2pNode.pubsub.subscribe('pubsub', () => { }, (err) => {
expect(err).to.exist()
expect(err.code).to.equal(codes.PUBSUB_NOT_STARTED)
done()
})
})
it('fail to unsubscribe if node not started yet', (done) => {
libp2pNode.pubsub.unsubscribe('pubsub', () => { }, (err) => {
expect(err).to.exist()
expect(err.code).to.equal(codes.PUBSUB_NOT_STARTED)
done()
})
})
it('fail to publish if node not started yet', (done) => {
libp2pNode.pubsub.publish('pubsub', Buffer.from('data'), (err) => {
expect(err).to.exist()
expect(err.code).to.equal(codes.PUBSUB_NOT_STARTED)
done()
})
})
it('fail to ls if node not started yet', (done) => {
libp2pNode.pubsub.ls((err) => {
expect(err).to.exist()
expect(err.code).to.equal(codes.PUBSUB_NOT_STARTED)
done()
})
})
it('fail to get subscribed peers to a topic if node not started yet', (done) => {
libp2pNode.pubsub.peers('pubsub', (err) => {
expect(err).to.exist()
expect(err.code).to.equal(codes.PUBSUB_NOT_STARTED)
done()
})
})
})
}) })

View File

@@ -15,6 +15,9 @@ describe('libp2p', () => {
mdns: { mdns: {
enabled: false enabled: false
} }
},
EXPERIMENTAL: {
dht: true
} }
} }
}, (err, node) => { }, (err, node) => {

View File

@@ -6,7 +6,6 @@ chai.use(require('dirty-chai'))
const expect = chai.expect const expect = chai.expect
const parallel = require('async/parallel') const parallel = require('async/parallel')
const series = require('async/series') const series = require('async/series')
const pMplex = require('pull-mplex')
const Mplex = require('libp2p-mplex') const Mplex = require('libp2p-mplex')
const SPDY = require('libp2p-spdy') const SPDY = require('libp2p-spdy')
const createNode = require('./utils/create-node') const createNode = require('./utils/create-node')
@@ -29,6 +28,8 @@ function teardown (nodeA, nodeB, callback) {
describe('stream muxing', () => { describe('stream muxing', () => {
it('spdy only', function (done) { it('spdy only', function (done) {
this.timeout(5 * 1000)
let nodeA let nodeA
let nodeB let nodeB
@@ -100,42 +101,6 @@ describe('stream muxing', () => {
], done) ], done)
}) })
it('pMplex only', (done) => {
let nodeA
let nodeB
function setup (callback) {
parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
streamMuxer: [ pMplex ]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeA = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
}),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
streamMuxer: [ pMplex ]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeB = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
})
], callback)
}
series([
(cb) => setup(cb),
(cb) => test(nodeA, nodeB, cb),
(cb) => teardown(nodeA, nodeB, cb)
], done)
})
it('spdy + mplex', function (done) { it('spdy + mplex', function (done) {
this.timeout(5000) this.timeout(5000)
@@ -174,45 +139,7 @@ describe('stream muxing', () => {
], done) ], done)
}) })
it('mplex + pull-mplex', function (done) { it('spdy + mplex switched order', function (done) {
this.timeout(5000)
let nodeA
let nodeB
function setup (callback) {
parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
streamMuxer: [ Mplex ]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeA = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
}),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
streamMuxer: [ pMplex ]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeB = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
})
], callback)
}
series([
(cb) => setup(cb),
(cb) => test(nodeA, nodeB, cb),
(cb) => teardown(nodeA, nodeB, cb)
], done)
})
it('spdy + mplex in reverse muxer order', function (done) {
this.timeout(5 * 1000) this.timeout(5 * 1000)
let nodeA let nodeA
@@ -250,44 +177,6 @@ describe('stream muxing', () => {
], done) ], done)
}) })
it('spdy + pull-mplex in reverse muxer order', function (done) {
this.timeout(5 * 1000)
let nodeA
let nodeB
function setup (callback) {
parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
streamMuxer: [ SPDY, pMplex ]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeA = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
}),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
streamMuxer: [ pMplex, SPDY ]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeB = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
})
], callback)
}
series([
(cb) => setup(cb),
(cb) => test(nodeA, nodeB, cb),
(cb) => teardown(nodeA, nodeB, cb)
], done)
})
it('one without the other fails to establish a muxedConn', function (done) { it('one without the other fails to establish a muxedConn', function (done) {
this.timeout(5 * 1000) this.timeout(5 * 1000)
@@ -326,10 +215,10 @@ describe('stream muxing', () => {
expect(Object.keys(nodeA._switch.muxers)).to.have.length(1) expect(Object.keys(nodeA._switch.muxers)).to.have.length(1)
expect(Object.keys(nodeB._switch.muxers)).to.have.length(1) expect(Object.keys(nodeB._switch.muxers)).to.have.length(1)
nodeA.dialFSM(nodeB.peerInfo, (err, connFSM) => { nodeA.dial(nodeB.peerInfo, (err) => {
expect(err).to.not.exist() expect(err).to.not.exist()
// The connection should fall back to 'unmuxed' expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
connFSM.once('unmuxed', () => cb()) cb()
}) })
}, },
(cb) => teardown(nodeA, nodeB, cb) (cb) => teardown(nodeA, nodeB, cb)

View File

@@ -4,32 +4,31 @@
const chai = require('chai') const chai = require('chai')
chai.use(require('dirty-chai')) chai.use(require('dirty-chai'))
chai.use(require('chai-checkmark'))
const expect = chai.expect const expect = chai.expect
const PeerInfo = require('peer-info') const PeerInfo = require('peer-info')
const PeerId = require('peer-id') const PeerId = require('peer-id')
const Mplex = require('pull-mplex') const Mplex = require('libp2p-mplex')
const pull = require('pull-stream') const pull = require('pull-stream')
const parallel = require('async/parallel') const parallel = require('async/parallel')
const goodbye = require('pull-goodbye') const goodbye = require('pull-goodbye')
const serializer = require('pull-serializer') const serializer = require('pull-serializer')
const wrtcSupport = self.RTCPeerConnection && ('createDataChannel' in self.RTCPeerConnection.prototype) const w = require('webrtcsupport')
const tryEcho = require('./utils/try-echo') const tryEcho = require('./utils/try-echo')
const Node = require('./utils/bundle-browser') const Node = require('./utils/bundle-browser')
const { getPeerRelay } = require('./utils/constants') const jsonPeerId = require('./fixtures/test-peer.json')
describe('transports', () => { describe('transports', () => {
describe('websockets', () => { describe('websockets', () => {
let peerB let peerB
let peerBMultiaddr let peerBMultiaddr = '/ip4/127.0.0.1/tcp/9200/ws/ipfs/' + jsonPeerId.id
let nodeA let nodeA
before((done) => { before((done) => {
getPeerRelay((err, peerInfo) => { PeerId.createFromPrivKey(jsonPeerId.privKey, (err, id) => {
expect(err).to.not.exist() expect(err).to.not.exist()
peerB = new PeerInfo(peerInfo.id)
peerBMultiaddr = `/ip4/127.0.0.1/tcp/9200/ws/p2p/${peerInfo.id.toB58String()}` peerB = new PeerInfo(id)
peerB.multiaddrs.add(peerBMultiaddr) peerB.multiaddrs.add(peerBMultiaddr)
done() done()
}) })
@@ -58,7 +57,7 @@ describe('transports', () => {
streamMuxer: [ Mplex ] streamMuxer: [ Mplex ]
} }
}) })
expect(b._modules.streamMuxer).to.eql([require('pull-mplex')]) expect(b._modules.streamMuxer).to.eql([require('libp2p-mplex')])
done() done()
}) })
}) })
@@ -103,7 +102,7 @@ describe('transports', () => {
function check () { function check () {
const peers = nodeA.peerBook.getAll() const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(0) expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
done() done()
} }
}) })
@@ -143,7 +142,7 @@ describe('transports', () => {
const peers = nodeA.peerBook.getAll() const peers = nodeA.peerBook.getAll()
expect(err).to.not.exist() expect(err).to.not.exist()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(0) expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
done() done()
} }
}) })
@@ -154,17 +153,16 @@ describe('transports', () => {
expect(err).to.not.exist() expect(err).to.not.exist()
connFSM.once('muxed', () => { connFSM.once('muxed', () => {
expect( expect(nodeA._switch.muxedConns).to.have.any.keys(
nodeA._switch.connection.getAllById(peerB.id.toB58String()) peerB.id.toB58String()
).to.have.length(1) )
connFSM.once('error', done) connFSM.once('error', done)
connFSM.once('close', () => { connFSM.once('close', () => {
// ensure the connection is closed // ensure the connection is closed
expect( expect(nodeA._switch.muxedConns).to.not.have.any.keys([
nodeA._switch.connection.getAllById(peerB.id.toB58String()) peerB.id.toB58String()
).to.have.length(0) ])
done() done()
}) })
@@ -233,7 +231,7 @@ describe('transports', () => {
describe('webrtc-star', () => { describe('webrtc-star', () => {
/* eslint-disable-next-line no-console */ /* eslint-disable-next-line no-console */
if (!wrtcSupport) { return console.log('NO WEBRTC SUPPORT') } if (!w.support) { return console.log('NO WEBRTC SUPPORT') }
let peer1 let peer1
let peer2 let peer2
@@ -257,11 +255,11 @@ describe('transports', () => {
expect(err).to.not.exist() expect(err).to.not.exist()
peer1 = new PeerInfo(ids[0]) peer1 = new PeerInfo(ids[0])
const ma1 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/p2p/' + ids[0].toB58String() const ma1 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/ipfs/' + ids[0].toB58String()
peer1.multiaddrs.add(ma1) peer1.multiaddrs.add(ma1)
peer2 = new PeerInfo(ids[1]) peer2 = new PeerInfo(ids[1])
const ma2 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/p2p/' + ids[1].toB58String() const ma2 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/ipfs/' + ids[1].toB58String()
peer2.multiaddrs.add(ma2) peer2.multiaddrs.add(ma2)
done() done()
@@ -314,7 +312,7 @@ describe('transports', () => {
function check () { function check () {
const peers = node1.peerBook.getAll() const peers = node1.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(node1._switch.connection.getAll()).to.have.length(0) expect(Object.keys(node1._switch.muxedConns)).to.have.length(0)
done() done()
} }
}) })
@@ -328,13 +326,13 @@ describe('transports', () => {
function check () { function check () {
// Verify both nodes are connected to node 3 // Verify both nodes are connected to node 3
if (node1._switch.connection.getAllById(b58Id) && node2._switch.connection.getAllById(b58Id)) { if (node1._switch.muxedConns[b58Id] && node2._switch.muxedConns[b58Id]) {
done() done()
} }
} }
const peer3 = new PeerInfo(id3) const peer3 = new PeerInfo(id3)
const ma3 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/p2p/' + b58Id const ma3 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/ipfs/' + b58Id
peer3.multiaddrs.add(ma3) peer3.multiaddrs.add(ma3)
node1.on('peer:discovery', (peerInfo) => node1.dial(peerInfo, check)) node1.on('peer:discovery', (peerInfo) => node1.dial(peerInfo, check))
@@ -414,39 +412,44 @@ describe('transports', () => {
it('node1 hangUp node2', (done) => { it('node1 hangUp node2', (done) => {
node1.hangUp(peer2, (err) => { node1.hangUp(peer2, (err) => {
expect(err).to.not.exist() expect(err).to.not.exist()
setTimeout(check, 500)
function check () {
const peers = node1.peerBook.getAll() const peers = node1.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(node1._switch.connection.getAll()).to.have.length(0) expect(Object.keys(node1._switch.muxedConns)).to.have.length(0)
done() done()
}
}) })
}) })
it('create a third node and check that discovery works', function (done) { it('create a third node and check that discovery works', function (done) {
this.timeout(10 * 1000) this.timeout(10 * 1000)
const expectedPeers = [
node1.peerInfo.id.toB58String(), let counter = 0
node2.peerInfo.id.toB58String()
] function check () {
if (++counter === 3) {
expect(Object.keys(node1._switch.muxedConns).length).to.equal(1)
expect(Object.keys(node2._switch.muxedConns).length).to.equal(1)
done()
}
}
PeerId.create((err, id3) => { PeerId.create((err, id3) => {
expect(err).to.not.exist() expect(err).to.not.exist()
const peer3 = new PeerInfo(id3) const peer3 = new PeerInfo(id3)
const ma3 = '/ip4/127.0.0.1/tcp/14444/ws/p2p-websocket-star/p2p/' + id3.toB58String() const ma3 = '/ip4/127.0.0.1/tcp/14444/ws/p2p-websocket-star/ipfs/' + id3.toB58String()
peer3.multiaddrs.add(ma3) peer3.multiaddrs.add(ma3)
// 2 connects and 1 start node1.on('peer:discovery', (peerInfo) => node1.dial(peerInfo, check))
expect(3).checks(done) node2.on('peer:discovery', (peerInfo) => node2.dial(peerInfo, check))
const node3 = new Node({ const node3 = new Node({
peerInfo: peer3 peerInfo: peer3
}) })
node3.on('peer:connect', (peerInfo) => { node3.start(check)
expect(expectedPeers).to.include(peerInfo.id.toB58String()).mark()
})
node3.start((err) => {
expect(err).to.not.exist().mark()
})
}) })
}) })
}) })

View File

@@ -6,6 +6,7 @@ chai.use(require('dirty-chai'))
const expect = chai.expect const expect = chai.expect
const parallel = require('async/parallel') const parallel = require('async/parallel')
const series = require('async/series') const series = require('async/series')
const signalling = require('libp2p-webrtc-star/src/sig-server')
const rendezvous = require('libp2p-websocket-star-rendezvous') const rendezvous = require('libp2p-websocket-star-rendezvous')
const TCP = require('libp2p-tcp') const TCP = require('libp2p-tcp')
const WS = require('libp2p-websockets') const WS = require('libp2p-websockets')
@@ -17,8 +18,6 @@ const createNode = require('./utils/create-node.js')
const tryEcho = require('./utils/try-echo') const tryEcho = require('./utils/try-echo')
const echo = require('./utils/echo') const echo = require('./utils/echo')
const { WRTC_RENDEZVOUS_MULTIADDR } = require('./utils/constants')
describe('transports', () => { describe('transports', () => {
describe('TCP only', () => { describe('TCP only', () => {
let nodeA let nodeA
@@ -92,13 +91,14 @@ describe('transports', () => {
(cb) => { (cb) => {
const peers = nodeA.peerBook.getAll() const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(0) expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
cb() cb()
}, },
(cb) => { (cb) => {
const peers = nodeB.peerBook.getAll() const peers = nodeB.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeB._switch.connection.getAll()).to.have.length(0)
expect(Object.keys(nodeB._switch.muxedConns)).to.have.length(0)
cb() cb()
} }
], done) ], done)
@@ -117,13 +117,15 @@ describe('transports', () => {
(cb) => { (cb) => {
const peers = nodeA.peerBook.getAll() const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(1)
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(1)
cb() cb()
}, },
(cb) => { (cb) => {
const peers = nodeB.peerBook.getAll() const peers = nodeB.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(1)
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(1)
cb() cb()
} }
], () => tryEcho(conn, done)) ], () => tryEcho(conn, done))
@@ -141,13 +143,15 @@ describe('transports', () => {
(cb) => { (cb) => {
const peers = nodeA.peerBook.getAll() const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(0)
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
cb() cb()
}, },
(cb) => { (cb) => {
const peers = nodeB.peerBook.getAll() const peers = nodeB.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeB._switch.connection.getAll()).to.have.length(0)
expect(Object.keys(nodeB._switch.muxedConns)).to.have.length(0)
cb() cb()
} }
], done) ], done)
@@ -166,13 +170,13 @@ describe('transports', () => {
(cb) => { (cb) => {
const peers = nodeA.peerBook.getAll() const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(1) expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(1)
cb() cb()
}, },
(cb) => { (cb) => {
const peers = nodeB.peerBook.getAll() const peers = nodeB.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(1) expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(1)
cb() cb()
} }
], () => tryEcho(conn, done)) ], () => tryEcho(conn, done))
@@ -190,13 +194,13 @@ describe('transports', () => {
(cb) => { (cb) => {
const peers = nodeA.peerBook.getAll() const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(0) expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
cb() cb()
}, },
(cb) => { (cb) => {
const peers = nodeB.peerBook.getAll() const peers = nodeB.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeB._switch.connection.getAll()).to.have.length(0) expect(Object.keys(nodeB._switch.muxedConns)).to.have.length(0)
cb() cb()
} }
], done) ], done)
@@ -209,16 +213,16 @@ describe('transports', () => {
expect(err).to.not.exist() expect(err).to.not.exist()
connFSM.once('muxed', () => { connFSM.once('muxed', () => {
expect( expect(nodeA._switch.muxedConns).to.have.any.keys(
nodeA._switch.connection.getAllById(nodeB.peerInfo.id.toB58String()) nodeB.peerInfo.id.toB58String()
).to.have.length(1) )
connFSM.once('error', done) connFSM.once('error', done)
connFSM.once('close', () => { connFSM.once('close', () => {
// ensure the connection is closed // ensure the connection is closed
expect( expect(nodeA._switch.muxedConns).to.not.have.any.keys([
nodeA._switch.connection.getAllById(nodeB.peerInfo.id.toB58String()) nodeB.peerInfo.id.toB58String()
).to.have.length(0) ])
done() done()
}) })
@@ -231,9 +235,9 @@ describe('transports', () => {
nodeA.dialFSM(nodeB.peerInfo, '/echo/1.0.0', (err, connFSM) => { nodeA.dialFSM(nodeB.peerInfo, '/echo/1.0.0', (err, connFSM) => {
expect(err).to.not.exist() expect(err).to.not.exist()
connFSM.once('connection', (conn) => { connFSM.once('connection', (conn) => {
expect( expect(nodeA._switch.muxedConns).to.have.all.keys([
nodeA._switch.connection.getAllById(nodeB.peerInfo.id.toB58String()) nodeB.peerInfo.id.toB58String()
).to.have.length(1) ])
tryEcho(conn, () => { tryEcho(conn, () => {
connFSM.close() connFSM.close()
}) })
@@ -241,9 +245,9 @@ describe('transports', () => {
connFSM.once('error', done) connFSM.once('error', done)
connFSM.once('close', () => { connFSM.once('close', () => {
// ensure the connection is closed // ensure the connection is closed
expect( expect(nodeA._switch.muxedConns).to.not.have.any.keys([
nodeA._switch.connection.getAllById(nodeB.peerInfo.id.toB58String()) nodeB.peerInfo.id.toB58String()
).to.have.length(0) ])
done() done()
}) })
}) })
@@ -305,13 +309,13 @@ describe('transports', () => {
(cb) => { (cb) => {
const peers = nodeTCP.peerBook.getAll() const peers = nodeTCP.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeTCP._switch.connection.getAll()).to.have.length(1) expect(Object.keys(nodeTCP._switch.muxedConns)).to.have.length(1)
cb() cb()
}, },
(cb) => { (cb) => {
const peers = nodeTCPnWS.peerBook.getAll() const peers = nodeTCPnWS.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeTCPnWS._switch.connection.getAll()).to.have.length(1) expect(Object.keys(nodeTCPnWS._switch.muxedConns)).to.have.length(1)
cb() cb()
} }
], done) ], done)
@@ -329,13 +333,14 @@ describe('transports', () => {
(cb) => { (cb) => {
const peers = nodeTCP.peerBook.getAll() const peers = nodeTCP.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeTCP._switch.connection.getAll()).to.have.length(0) expect(Object.keys(nodeTCP._switch.muxedConns)).to.have.length(0)
cb() cb()
}, },
(cb) => { (cb) => {
const peers = nodeTCPnWS.peerBook.getAll() const peers = nodeTCPnWS.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeTCPnWS._switch.connection.getAll()).to.have.length(0) expect(Object.keys(nodeTCPnWS._switch.muxedConns)).to.have.length(0)
cb() cb()
} }
], done) ], done)
@@ -355,13 +360,13 @@ describe('transports', () => {
(cb) => { (cb) => {
const peers = nodeTCPnWS.peerBook.getAll() const peers = nodeTCPnWS.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(2) expect(Object.keys(peers)).to.have.length(2)
expect(nodeTCPnWS._switch.connection.getAll()).to.have.length(1) expect(Object.keys(nodeTCPnWS._switch.muxedConns)).to.have.length(1)
cb() cb()
}, },
(cb) => { (cb) => {
const peers = nodeWS.peerBook.getAll() const peers = nodeWS.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeWS._switch.connection.getAll()).to.have.length(1) expect(Object.keys(nodeWS._switch.muxedConns)).to.have.length(1)
cb() cb()
} }
], done) ], done)
@@ -379,14 +384,14 @@ describe('transports', () => {
(cb) => { (cb) => {
const peers = nodeTCPnWS.peerBook.getAll() const peers = nodeTCPnWS.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(2) expect(Object.keys(peers)).to.have.length(2)
expect(nodeTCPnWS._switch.connection.getAll()).to.have.length(0) expect(Object.keys(nodeTCPnWS._switch.muxedConns)).to.have.length(0)
cb() cb()
}, },
(cb) => { (cb) => {
const peers = nodeWS.peerBook.getAll() const peers = nodeWS.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1) expect(Object.keys(peers)).to.have.length(1)
expect(nodeWS._switch.connection.getAll()).to.have.length(0) expect(Object.keys(nodeWS._switch.muxedConns)).to.have.length(0)
cb() cb()
} }
], done) ], done)
@@ -410,17 +415,24 @@ describe('transports', () => {
let nodeWS let nodeWS
let nodeWebRTCStar let nodeWebRTCStar
let ss
before(function (done) { before(function (done) {
this.timeout(5 * 1000) this.timeout(5 * 1000)
parallel([ parallel([
(cb) => signalling.start({ port: 24642 }, (err, server) => {
expect(err).to.not.exist()
ss = server
cb()
}),
(cb) => { (cb) => {
const wstar = new WRTCStar({wrtc: wrtc}) const wstar = new WRTCStar({wrtc: wrtc})
createNode([ createNode([
'/ip4/0.0.0.0/tcp/0', '/ip4/0.0.0.0/tcp/0',
'/ip4/127.0.0.1/tcp/25011/ws', '/ip4/127.0.0.1/tcp/25011/ws',
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star` '/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'
], { ], {
modules: { modules: {
transport: [ transport: [
@@ -432,7 +444,6 @@ describe('transports', () => {
}, },
config: { config: {
peerDiscovery: { peerDiscovery: {
autoDial: false,
[wstar.discovery.tag]: { [wstar.discovery.tag]: {
enabled: true enabled: true
} }
@@ -447,13 +458,7 @@ describe('transports', () => {
}, },
(cb) => createNode([ (cb) => createNode([
'/ip4/0.0.0.0/tcp/0' '/ip4/0.0.0.0/tcp/0'
], { ], (err, node) => {
config: {
peerDiscovery: {
autoDial: false
}
}
}, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
nodeTCP = node nodeTCP = node
node.handle('/echo/1.0.0', echo) node.handle('/echo/1.0.0', echo)
@@ -461,23 +466,18 @@ describe('transports', () => {
}), }),
(cb) => createNode([ (cb) => createNode([
'/ip4/127.0.0.1/tcp/25022/ws' '/ip4/127.0.0.1/tcp/25022/ws'
], { ], (err, node) => {
config: {
peerDiscovery: {
autoDial: false
}
}
}, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
nodeWS = node nodeWS = node
node.handle('/echo/1.0.0', echo) node.handle('/echo/1.0.0', echo)
node.start(cb) node.start(cb)
}), }),
(cb) => { (cb) => {
const wstar = new WRTCStar({wrtc: wrtc}) const wstar = new WRTCStar({wrtc: wrtc})
createNode([ createNode([
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star` '/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'
], { ], {
modules: { modules: {
transport: [wstar], transport: [wstar],
@@ -485,7 +485,6 @@ describe('transports', () => {
}, },
config: { config: {
peerDiscovery: { peerDiscovery: {
autoDial: false,
[wstar.discovery.tag]: { [wstar.discovery.tag]: {
enabled: true enabled: true
} }
@@ -508,7 +507,8 @@ describe('transports', () => {
(cb) => nodeAll.stop(cb), (cb) => nodeAll.stop(cb),
(cb) => nodeTCP.stop(cb), (cb) => nodeTCP.stop(cb),
(cb) => nodeWS.stop(cb), (cb) => nodeWS.stop(cb),
(cb) => nodeWebRTCStar.stop(cb) (cb) => nodeWebRTCStar.stop(cb),
(cb) => ss.stop(cb)
], done) ], done)
}) })
@@ -516,7 +516,7 @@ describe('transports', () => {
let i = 1; let i = 1;
[nodeAll, otherNode].forEach((node) => { [nodeAll, otherNode].forEach((node) => {
expect(Object.keys(node.peerBook.getAll())).to.have.length(i-- ? peers : 1) expect(Object.keys(node.peerBook.getAll())).to.have.length(i-- ? peers : 1)
expect(node._switch.connection.getAll()).to.have.length(muxed) expect(Object.keys(node._switch.muxedConns)).to.have.length(muxed)
}) })
callback() callback()
} }
@@ -678,7 +678,7 @@ describe('transports', () => {
let i = 1; let i = 1;
[nodeAll, otherNode].forEach((node) => { [nodeAll, otherNode].forEach((node) => {
expect(Object.keys(node.peerBook.getAll())).to.have.length(i-- ? peers : 1) expect(Object.keys(node.peerBook.getAll())).to.have.length(i-- ? peers : 1)
expect(node._switch.connection.getAll()).to.have.length(muxed) expect(Object.keys(node._switch.muxedConns)).to.have.length(muxed)
}) })
done() done()
} }

84
test/turbolence.node.js Normal file
View File

@@ -0,0 +1,84 @@
/* eslint-env mocha */
'use strict'
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const multiaddr = require('multiaddr')
const spawn = require('child_process').spawn
const path = require('path')
const pull = require('pull-stream')
const utils = require('./utils/node')
const createNode = utils.createNode
const echo = utils.echo
describe('Turbolence tests', () => {
let nodeA
let nodeSpawn
before((done) => {
createNode('/ip4/0.0.0.0/tcp/0', (err, node) => {
expect(err).to.not.exist()
nodeA = node
node.handle('/echo/1.0.0', echo)
node.start(done)
})
})
after((done) => nodeA.stop(done))
it('spawn a node in a different process', (done) => {
const filePath = path.join(__dirname, './spawn-libp2p-node.js')
nodeSpawn = spawn(filePath, { env: process.env })
let spawned = false
nodeSpawn.stdout.on('data', (data) => {
// console.log(data.toString())
if (!spawned) {
spawned = true
done()
}
})
/* eslint-disable-next-line no-console */
nodeSpawn.stderr.on('data', (data) => console.log(data.toString()))
})
it('connect nodeA to that node', (done) => {
const spawnedId = require('./test-data/test-id.json')
const maddr = multiaddr('/ip4/127.0.0.1/tcp/12345/ipfs/' + spawnedId.id)
nodeA.dial(maddr, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist()
const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
pull(
pull.values([Buffer.from('hey')]),
conn,
pull.collect((err, data) => {
expect(err).to.not.exist()
expect(data).to.eql([Buffer.from('hey')])
done()
})
)
})
})
it('crash that node, ensure nodeA continues going steady', (done) => {
// TODO investigate why CI crashes
setTimeout(() => nodeSpawn.kill('SIGKILL'), 1000)
// nodeSpawn.kill('SIGKILL')
setTimeout(check, 5000)
function check () {
const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(0)
done()
}
})
})

View File

@@ -6,7 +6,6 @@ const WebSocketStar = require('libp2p-websocket-star')
const Bootstrap = require('libp2p-bootstrap') const Bootstrap = require('libp2p-bootstrap')
const SPDY = require('libp2p-spdy') const SPDY = require('libp2p-spdy')
const MPLEX = require('libp2p-mplex') const MPLEX = require('libp2p-mplex')
const PULLMPLEX = require('pull-mplex')
const KadDHT = require('libp2p-kad-dht') const KadDHT = require('libp2p-kad-dht')
const SECIO = require('libp2p-secio') const SECIO = require('libp2p-secio')
const defaultsDeep = require('@nodeutils/defaults-deep') const defaultsDeep = require('@nodeutils/defaults-deep')
@@ -18,7 +17,6 @@ function mapMuxers (list) {
switch (pref.trim().toLowerCase()) { switch (pref.trim().toLowerCase()) {
case 'spdy': return SPDY case 'spdy': return SPDY
case 'mplex': return MPLEX case 'mplex': return MPLEX
case 'pullmplex': return PULLMPLEX
default: default:
throw new Error(pref + ' muxer not available') throw new Error(pref + ' muxer not available')
} }
@@ -29,7 +27,7 @@ function getMuxers (options) {
if (options) { if (options) {
return mapMuxers(options) return mapMuxers(options)
} else { } else {
return [PULLMPLEX, MPLEX, SPDY] return [MPLEX, SPDY]
} }
} }
@@ -61,7 +59,6 @@ class Node extends libp2p {
}, },
config: { config: {
peerDiscovery: { peerDiscovery: {
autoDial: true,
webRTCStar: { webRTCStar: {
enabled: true enabled: true
}, },
@@ -83,12 +80,10 @@ class Node extends libp2p {
}, },
dht: { dht: {
kBucketSize: 20, kBucketSize: 20,
randomWalk: { enabledDiscovery: true
enabled: true
},
enabled: false
}, },
EXPERIMENTAL: { EXPERIMENTAL: {
dht: false,
pubsub: false pubsub: false
} }
} }

View File

@@ -7,7 +7,6 @@ const Bootstrap = require('libp2p-bootstrap')
const SPDY = require('libp2p-spdy') const SPDY = require('libp2p-spdy')
const KadDHT = require('libp2p-kad-dht') const KadDHT = require('libp2p-kad-dht')
const MPLEX = require('libp2p-mplex') const MPLEX = require('libp2p-mplex')
const PULLMPLEX = require('pull-mplex')
const SECIO = require('libp2p-secio') const SECIO = require('libp2p-secio')
const defaultsDeep = require('@nodeutils/defaults-deep') const defaultsDeep = require('@nodeutils/defaults-deep')
const libp2p = require('../..') const libp2p = require('../..')
@@ -18,7 +17,6 @@ function mapMuxers (list) {
switch (pref.trim().toLowerCase()) { switch (pref.trim().toLowerCase()) {
case 'spdy': return SPDY case 'spdy': return SPDY
case 'mplex': return MPLEX case 'mplex': return MPLEX
case 'pullmplex': return PULLMPLEX
default: default:
throw new Error(pref + ' muxer not available') throw new Error(pref + ' muxer not available')
} }
@@ -32,7 +30,7 @@ function getMuxers (muxers) {
} else if (muxers) { } else if (muxers) {
return mapMuxers(muxers) return mapMuxers(muxers)
} else { } else {
return [PULLMPLEX, MPLEX, SPDY] return [MPLEX, SPDY]
} }
} }
@@ -56,7 +54,6 @@ class Node extends libp2p {
}, },
config: { config: {
peerDiscovery: { peerDiscovery: {
autoDial: true,
mdns: { mdns: {
interval: 10000, interval: 10000,
enabled: false enabled: false
@@ -76,12 +73,10 @@ class Node extends libp2p {
}, },
dht: { dht: {
kBucketSize: 20, kBucketSize: 20,
randomWalk: { enabledDiscovery: true
enabled: true
},
enabled: true
}, },
EXPERIMENTAL: { EXPERIMENTAL: {
dht: false,
pubsub: false pubsub: false
} }
} }

View File

@@ -1,40 +0,0 @@
'use strict'
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const nextTick = require('async/nextTick')
const peerJSON = require('../fixtures/test-peer')
const multiaddr = require('multiaddr')
let peerRelay = null
/**
* Creates a `PeerInfo` that can be used across testing. Once the
* relay `PeerInfo` has been requested, it will be reused for each
* additional request.
*
* This is currently being used to create a relay on test bootstrapping
* so that it can be used by browser nodes during their test suite. This
* is necessary for running a TCP node during browser tests.
* @private
* @param {function(error, PeerInfo)} callback
* @returns {void}
*/
module.exports.getPeerRelay = (callback) => {
if (peerRelay) return nextTick(callback, null, peerRelay)
PeerId.createFromJSON(peerJSON, (err, peerId) => {
if (err) {
return callback(err)
}
peerRelay = new PeerInfo(peerId)
peerRelay.multiaddrs.add('/ip4/127.0.0.1/tcp/9200/ws')
peerRelay.multiaddrs.add('/ip4/127.0.0.1/tcp/9245')
callback(null, peerRelay)
})
}
module.exports.WS_RENDEZVOUS_MULTIADDR = multiaddr('/ip4/127.0.0.1/tcp/14444/wss')
module.exports.WRTC_RENDEZVOUS_MULTIADDR = multiaddr('/ip4/127.0.0.1/tcp/15555/wss')

View File

@@ -8,4 +8,3 @@ function echo (protocol, conn) {
} }
module.exports = echo module.exports = echo
module.exports.multicodec = '/echo/1.0.0'