mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-08 13:21:34 +00:00
Compare commits
81 Commits
v0.24.0
...
docs/deleg
Author | SHA1 | Date | |
---|---|---|---|
8c4dbe2766 | |||
27af24ffc1 | |||
10811e9ced | |||
9c2789bc15 | |||
24be691bc1 | |||
9433c6c398 | |||
04faf1806c | |||
b06ca1b3c7 | |||
bde30cac45 | |||
28c054c21e | |||
c346e8066b | |||
40978a1940 | |||
71dcaafcac | |||
5319e065ec | |||
f3801f0e6c | |||
51cc993876 | |||
a800c1ad91 | |||
54c474de98 | |||
f28dffb268 | |||
c049074cb5 | |||
1bde70f1b5 | |||
cfa4df6e11 | |||
eb5aa03232 | |||
4cb541ddae | |||
aa1d9b273a | |||
7313f781fc | |||
313b1eae20 | |||
01aa44724e | |||
8b627797e2 | |||
e5f19e860b | |||
5204da73f7 | |||
66130ccba8 | |||
aa1bb3ab75 | |||
813a59b9ce | |||
eee60ed37d | |||
e52ce66ab7 | |||
da52af704e | |||
282ce62703 | |||
ef3238bdee | |||
4c06c54fc5 | |||
bb0c45d704 | |||
eb10b5c6d2 | |||
a282fbe139 | |||
6cfb0b2692 | |||
de84ee473c | |||
f28ecb2483 | |||
bba6f7eff8 | |||
9f5f07269e | |||
5f92acd5bb | |||
dfe8f632f7 | |||
9f47100713 | |||
d497961938 | |||
6e76aade7f | |||
ec7d0761de | |||
59fe9732d7 | |||
4ed5c039fc | |||
9e7a080a5c | |||
558e5987be | |||
dcf59a8468 | |||
ab028a2be3 | |||
91e60d4253 | |||
679d446daa | |||
8047fb76fa | |||
c4cab007af | |||
ebaab3e47f | |||
b31690c8e6 | |||
3bde9c8bed | |||
14e12ee1f1 | |||
2374929990 | |||
26de739bb1 | |||
0f8d6afd8f | |||
daa26859e0 | |||
fdfb7b4e86 | |||
15bdb795a4 | |||
7d78728f54 | |||
53ed3bdb99 | |||
ae513887f5 | |||
7c78faa171 | |||
7d12eb9e26 | |||
581a1de472 | |||
288ac17954 |
48
.aegir.js
48
.aegir.js
@ -1,15 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
const PeerInfo = require('peer-info')
|
||||
const PeerId = require('peer-id')
|
||||
const pull = require('pull-stream')
|
||||
const parallel = require('async/parallel')
|
||||
|
||||
const WebSocketStarRendezvous = require('libp2p-websocket-star-rendezvous')
|
||||
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 {
|
||||
getPeerRelay,
|
||||
WRTC_RENDEZVOUS_MULTIADDR,
|
||||
WS_RENDEZVOUS_MULTIADDR
|
||||
} = require('./test/utils/constants')
|
||||
|
||||
let wrtcRendezvous
|
||||
let wsRendezvous
|
||||
@ -19,19 +20,18 @@ const before = (done) => {
|
||||
parallel([
|
||||
(cb) => {
|
||||
sigServer.start({
|
||||
port: 15555
|
||||
port: WRTC_RENDEZVOUS_MULTIADDR.nodeAddress().port
|
||||
// cryptoChallenge: true TODO: needs https://github.com/libp2p/js-libp2p-webrtc-star/issues/128
|
||||
}, (err, server) => {
|
||||
if (err) {
|
||||
return cb(err)
|
||||
}
|
||||
})
|
||||
.then(server => {
|
||||
wrtcRendezvous = server
|
||||
cb()
|
||||
})
|
||||
.catch(cb)
|
||||
},
|
||||
(cb) => {
|
||||
WebSocketStarRendezvous.start({
|
||||
port: 14444,
|
||||
port: WS_RENDEZVOUS_MULTIADDR.nodeAddress().port,
|
||||
refreshPeerListIntervalMS: 1000,
|
||||
strictMultiaddr: false,
|
||||
cryptoChallenge: true
|
||||
@ -44,17 +44,24 @@ const before = (done) => {
|
||||
})
|
||||
},
|
||||
(cb) => {
|
||||
PeerId.createFromJSON(rawPeer, (err, peerId) => {
|
||||
getPeerRelay((err, peerInfo) => {
|
||||
if (err) {
|
||||
return done(err)
|
||||
}
|
||||
const peer = new PeerInfo(peerId)
|
||||
|
||||
peer.multiaddrs.add('/ip4/127.0.0.1/tcp/9200/ws')
|
||||
|
||||
node = new Node({
|
||||
peerInfo: peer
|
||||
peerInfo,
|
||||
config: {
|
||||
relay: {
|
||||
enabled: true,
|
||||
hop: {
|
||||
enabled: true,
|
||||
active: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
node.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn))
|
||||
node.start(cb)
|
||||
})
|
||||
@ -64,13 +71,16 @@ const before = (done) => {
|
||||
|
||||
const after = (done) => {
|
||||
setTimeout(() =>
|
||||
parallel(
|
||||
[node, wrtcRendezvous, wsRendezvous].map((s) => (cb) => s.stop(cb)),
|
||||
done),
|
||||
2000)
|
||||
parallel([
|
||||
(cb) => wrtcRendezvous.stop().then(cb).catch(cb),
|
||||
...[node, wsRendezvous].map((s) => (cb) => s.stop(cb)),
|
||||
], done),
|
||||
2000
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
bundlesize: { maxSize: '220kB' },
|
||||
hooks: {
|
||||
pre: before,
|
||||
post: after
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -41,3 +41,4 @@ test/test-data/go-ipfs-repo/LOG.old
|
||||
|
||||
# while testing npm5
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
|
37
.npmignore
37
.npmignore
@ -1,37 +0,0 @@
|
||||
**/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
|
44
.travis.yml
Normal file
44
.travis.yml
Normal file
@ -0,0 +1,44 @@
|
||||
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
|
169
CHANGELOG.md
169
CHANGELOG.md
@ -1,7 +1,176 @@
|
||||
<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>
|
||||
## [0.23.1](https://github.com/libp2p/js-libp2p/compare/v0.23.0...v0.23.1) (2018-08-13)
|
||||
|
@ -39,5 +39,5 @@ One of following:
|
||||
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.
|
||||
|
||||
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
4
OKR.md
@ -2,6 +2,10 @@
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
|
60
PEER_DISCOVERY.md
Normal file
60
PEER_DISCOVERY.md
Normal file
@ -0,0 +1,60 @@
|
||||
# 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)
|
172
README.md
172
README.md
@ -8,12 +8,14 @@
|
||||
<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://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>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<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://codecov.io/gh/libp2p/js-libp2p/branch/master/graph/badge.svg"></a>
|
||||
<a href="https://travis-ci.com/libp2p/js-libp2p"><img src="https://flat.badgen.net/travis/libp2p/js-libp2p" /></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://bundlephobia.com/result?p=ipfsd-ctl"><img src="https://flat.badgen.net/bundlephobia/minzip/ipfsd-ctl"></a>
|
||||
<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://github.com/feross/standard"><img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square"></a>
|
||||
@ -63,7 +65,9 @@ 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:
|
||||
|
||||
- [libp2p.io](https://libp2p.io)
|
||||
- [docs.libp2p.io](https://docs.libp2p.io)
|
||||
- [Specification (WIP)](https://github.com/libp2p/specs)
|
||||
- [Discussion Forums](https://discuss.libp2p.io)
|
||||
- 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)
|
||||
- Articles
|
||||
@ -96,7 +100,7 @@ You can find multiple examples on the [examples folder](/examples) that will gui
|
||||
|
||||
### Creating your own libp2p bundle
|
||||
|
||||
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).
|
||||
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).
|
||||
|
||||
**Example:**
|
||||
|
||||
@ -107,7 +111,7 @@ The libp2p module acts as a glue for every libp2p module that you can use top cr
|
||||
// crypto-channel: secio
|
||||
// discovery: multicast-dns
|
||||
|
||||
const libp2p = require('libp2p')
|
||||
const Libp2p = require('libp2p')
|
||||
const TCP = require('libp2p-tcp')
|
||||
const WS = require('libp2p-websockets')
|
||||
const SPDY = require('libp2p-spdy')
|
||||
@ -120,7 +124,7 @@ const Protector = require('libp2p-pnet')
|
||||
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
|
||||
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
|
||||
|
||||
class Node extends libp2p {
|
||||
class Node extends Libp2p {
|
||||
constructor (_options) {
|
||||
const peerInfo = _options.peerInfo
|
||||
const defaults = {
|
||||
@ -156,6 +160,7 @@ class Node extends libp2p {
|
||||
// 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.
|
||||
peerDiscovery: {
|
||||
autoDial: true, // Auto connect to discovered peers (limited by ConnectionManager minPeers)
|
||||
mdns: { // mdns options
|
||||
interval: 1000, // ms
|
||||
enabled: true
|
||||
@ -175,12 +180,16 @@ class Node extends libp2p {
|
||||
},
|
||||
dht: {
|
||||
kBucketSize: 20,
|
||||
enabledDiscovery: true // Allows to disable discovery (enabled by default)
|
||||
enabled: true,
|
||||
randomWalk: {
|
||||
enabled: true, // Allows to disable discovery (enabled by default)
|
||||
interval: 300e3,
|
||||
timeout: 10e3
|
||||
}
|
||||
},
|
||||
// Enable/Disable Experimental features
|
||||
EXPERIMENTAL: { // Experimental features ("behind a flag")
|
||||
pubsub: false,
|
||||
dht: false
|
||||
pubsub: false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -195,13 +204,31 @@ class Node extends libp2p {
|
||||
|
||||
### API
|
||||
|
||||
#### Create a Node - `new libp2p.Node(options)`
|
||||
#### Create a Node - `Libp2p.createLibp2p(options, callback)`
|
||||
|
||||
> Creates an instance of the libp2p.Node.
|
||||
> Behaves exactly like `new Libp2p(options)`, but doesn't require a PeerInfo. One will be generated instead
|
||||
|
||||
```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:
|
||||
|
||||
- `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)`
|
||||
|
||||
@ -301,17 +328,32 @@ Required keys in the `options` object:
|
||||
|
||||
> 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][]
|
||||
|
||||
##### `libp2p.on('peer:connect', (peer) => {})`
|
||||
|
||||
> We connected to a new peer
|
||||
> We have a new muxed connection to a peer
|
||||
|
||||
- `peer`: instance of [PeerInfo][]
|
||||
|
||||
##### `libp2p.on('peer:disconnect', (peer) => {})`
|
||||
|
||||
> We disconnected from Peer
|
||||
> We have closed a connection to a 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][]
|
||||
|
||||
@ -505,18 +547,6 @@ Some available network protectors:
|
||||
> npm run test:browser
|
||||
```
|
||||
|
||||
#### Run interop tests
|
||||
|
||||
```sh
|
||||
N/A
|
||||
```
|
||||
|
||||
#### Run benchmark tests
|
||||
|
||||
```sh
|
||||
N/A
|
||||
```
|
||||
|
||||
### Packages
|
||||
|
||||
List of packages currently in existence for libp2p
|
||||
@ -526,66 +556,66 @@ List of packages currently in existence for libp2p
|
||||
| Package | Version | Deps | CI | Coverage | Lead Maintainer |
|
||||
| ---------|---------|---------|---------|---------|--------- |
|
||||
| **Libp2p** |
|
||||
| [`interface-libp2p`](//github.com/libp2p/interface-libp2p) | [](//github.com/libp2p/interface-libp2p/releases) | [](https://david-dm.org/libp2p/interface-libp2p) | N/A | [](https://codecov.io/gh/libp2p/interface-libp2p) | N/A |
|
||||
| [`libp2p`](//github.com/libp2p/js-libp2p) | [](//github.com/libp2p/js-libp2p/releases) | [](https://david-dm.org/libp2p/js-libp2p) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`interface-libp2p`](//github.com/libp2p/interface-libp2p) | [](//github.com/libp2p/interface-libp2p/releases) | [](https://david-dm.org/libp2p/interface-libp2p) | [](https://travis-ci.com/libp2p/interface-libp2p) | [](https://codecov.io/gh/libp2p/interface-libp2p) | N/A |
|
||||
| [`libp2p`](//github.com/libp2p/js-libp2p) | [](//github.com/libp2p/js-libp2p/releases) | [](https://david-dm.org/libp2p/js-libp2p) | [](https://travis-ci.com/libp2p/js-libp2p) | [](https://codecov.io/gh/libp2p/js-libp2p) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| **Connection** |
|
||||
| [`interface-connection`](//github.com/libp2p/interface-connection) | [](//github.com/libp2p/interface-connection/releases) | [](https://david-dm.org/libp2p/interface-connection) | N/A | [](https://codecov.io/gh/libp2p/interface-connection) | N/A |
|
||||
| [`interface-connection`](//github.com/libp2p/interface-connection) | [](//github.com/libp2p/interface-connection/releases) | [](https://david-dm.org/libp2p/interface-connection) | [](https://travis-ci.com/libp2p/interface-connection) | [](https://codecov.io/gh/libp2p/interface-connection) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| **Transport** |
|
||||
| [`interface-transport`](//github.com/libp2p/interface-transport) | [](//github.com/libp2p/interface-transport/releases) | [](https://david-dm.org/libp2p/interface-transport) | N/A | [](https://codecov.io/gh/libp2p/interface-transport) | N/A |
|
||||
| [`libp2p-tcp`](//github.com/libp2p/js-libp2p-tcp) | [](//github.com/libp2p/js-libp2p-tcp/releases) | [](https://david-dm.org/libp2p/js-libp2p-tcp) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-tcp/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-tcp) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-udp`](//github.com/libp2p/js-libp2p-udp) | [](//github.com/libp2p/js-libp2p-udp/releases) | [](https://david-dm.org/libp2p/js-libp2p-udp) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-udp) | N/A |
|
||||
| [`libp2p-udt`](//github.com/libp2p/js-libp2p-udt) | [](//github.com/libp2p/js-libp2p-udt/releases) | [](https://david-dm.org/libp2p/js-libp2p-udt) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-udt) | N/A |
|
||||
| [`libp2p-utp`](//github.com/libp2p/js-libp2p-utp) | [](//github.com/libp2p/js-libp2p-utp/releases) | [](https://david-dm.org/libp2p/js-libp2p-utp) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-utp/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-utp) | N/A |
|
||||
| [`libp2p-webrtc-direct`](//github.com/libp2p/js-libp2p-webrtc-direct) | [](//github.com/libp2p/js-libp2p-webrtc-direct/releases) | [](https://david-dm.org/libp2p/js-libp2p-webrtc-direct) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-webrtc-direct/job/master/) | [](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) | [](//github.com/libp2p/js-libp2p-webrtc-star/releases) | [](https://david-dm.org/libp2p/js-libp2p-webrtc-star) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-webrtc-star/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-webrtc-star) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| [`libp2p-websockets`](//github.com/libp2p/js-libp2p-websockets) | [](//github.com/libp2p/js-libp2p-websockets/releases) | [](https://david-dm.org/libp2p/js-libp2p-websockets) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-websockets) | N/A |
|
||||
| [`libp2p-websocket-star`](//github.com/libp2p/js-libp2p-websocket-star) | [](//github.com/libp2p/js-libp2p-websocket-star/releases) | [](https://david-dm.org/libp2p/js-libp2p-websocket-star) | N/A | [](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) | [](//github.com/libp2p/js-libp2p-websocket-star-rendezvous/releases) | [](https://david-dm.org/libp2p/js-libp2p-websocket-star-rendezvous) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-websocket-star-rendezvous) | N/A |
|
||||
| [`interface-transport`](//github.com/libp2p/interface-transport) | [](//github.com/libp2p/interface-transport/releases) | [](https://david-dm.org/libp2p/interface-transport) | [](https://travis-ci.com/libp2p/interface-transport) | [](https://codecov.io/gh/libp2p/interface-transport) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-tcp`](//github.com/libp2p/js-libp2p-tcp) | [](//github.com/libp2p/js-libp2p-tcp/releases) | [](https://david-dm.org/libp2p/js-libp2p-tcp) | [](https://travis-ci.com/libp2p/js-libp2p-tcp) | [](https://codecov.io/gh/libp2p/js-libp2p-tcp) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-udp`](//github.com/libp2p/js-libp2p-udp) | [](//github.com/libp2p/js-libp2p-udp/releases) | [](https://david-dm.org/libp2p/js-libp2p-udp) | [](https://travis-ci.com/libp2p/js-libp2p-udp) | [](https://codecov.io/gh/libp2p/js-libp2p-udp) | N/A |
|
||||
| [`libp2p-udt`](//github.com/libp2p/js-libp2p-udt) | [](//github.com/libp2p/js-libp2p-udt/releases) | [](https://david-dm.org/libp2p/js-libp2p-udt) | [](https://travis-ci.com/libp2p/js-libp2p-udt) | [](https://codecov.io/gh/libp2p/js-libp2p-udt) | N/A |
|
||||
| [`libp2p-utp`](//github.com/libp2p/js-libp2p-utp) | [](//github.com/libp2p/js-libp2p-utp/releases) | [](https://david-dm.org/libp2p/js-libp2p-utp) | [](https://travis-ci.com/libp2p/js-libp2p-utp) | [](https://codecov.io/gh/libp2p/js-libp2p-utp) | N/A |
|
||||
| [`libp2p-webrtc-direct`](//github.com/libp2p/js-libp2p-webrtc-direct) | [](//github.com/libp2p/js-libp2p-webrtc-direct/releases) | [](https://david-dm.org/libp2p/js-libp2p-webrtc-direct) | [](https://travis-ci.com/libp2p/js-libp2p-webrtc-direct) | [](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) | [](//github.com/libp2p/js-libp2p-webrtc-star/releases) | [](https://david-dm.org/libp2p/js-libp2p-webrtc-star) | [](https://travis-ci.com/libp2p/js-libp2p-webrtc-star) | [](https://codecov.io/gh/libp2p/js-libp2p-webrtc-star) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| [`libp2p-websockets`](//github.com/libp2p/js-libp2p-websockets) | [](//github.com/libp2p/js-libp2p-websockets/releases) | [](https://david-dm.org/libp2p/js-libp2p-websockets) | [](https://travis-ci.com/libp2p/js-libp2p-websockets) | [](https://codecov.io/gh/libp2p/js-libp2p-websockets) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-websocket-star`](//github.com/libp2p/js-libp2p-websocket-star) | [](//github.com/libp2p/js-libp2p-websocket-star/releases) | [](https://david-dm.org/libp2p/js-libp2p-websocket-star) | [](https://travis-ci.com/libp2p/js-libp2p-websocket-star) | [](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) | [](//github.com/libp2p/js-libp2p-websocket-star-rendezvous/releases) | [](https://david-dm.org/libp2p/js-libp2p-websocket-star-rendezvous) | [](https://travis-ci.com/libp2p/js-libp2p-websocket-star-rendezvous) | [](https://codecov.io/gh/libp2p/js-libp2p-websocket-star-rendezvous) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| **Crypto Channels** |
|
||||
| [`libp2p-secio`](//github.com/libp2p/js-libp2p-secio) | [](//github.com/libp2p/js-libp2p-secio/releases) | [](https://david-dm.org/libp2p/js-libp2p-secio) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-secio) | N/A |
|
||||
| [`libp2p-secio`](//github.com/libp2p/js-libp2p-secio) | [](//github.com/libp2p/js-libp2p-secio/releases) | [](https://david-dm.org/libp2p/js-libp2p-secio) | [](https://travis-ci.com/libp2p/js-libp2p-secio) | [](https://codecov.io/gh/libp2p/js-libp2p-secio) | [Friedel Ziegelmayer](mailto:dignifiedquire@gmail.com) |
|
||||
| **Stream Muxers** |
|
||||
| [`interface-stream-muxer`](//github.com/libp2p/interface-stream-muxer) | [](//github.com/libp2p/interface-stream-muxer/releases) | [](https://david-dm.org/libp2p/interface-stream-muxer) | N/A | [](https://codecov.io/gh/libp2p/interface-stream-muxer) | N/A |
|
||||
| [`libp2p-mplex`](//github.com/libp2p/js-libp2p-mplex) | [](//github.com/libp2p/js-libp2p-mplex/releases) | [](https://david-dm.org/libp2p/js-libp2p-mplex) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-mplex) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| [`libp2p-spdy`](//github.com/libp2p/js-libp2p-spdy) | [](//github.com/libp2p/js-libp2p-spdy/releases) | [](https://david-dm.org/libp2p/js-libp2p-spdy) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-spdy/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-spdy) | N/A |
|
||||
| [`interface-stream-muxer`](//github.com/libp2p/interface-stream-muxer) | [](//github.com/libp2p/interface-stream-muxer/releases) | [](https://david-dm.org/libp2p/interface-stream-muxer) | [](https://travis-ci.com/libp2p/interface-stream-muxer) | [](https://codecov.io/gh/libp2p/interface-stream-muxer) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-mplex`](//github.com/libp2p/js-libp2p-mplex) | [](//github.com/libp2p/js-libp2p-mplex/releases) | [](https://david-dm.org/libp2p/js-libp2p-mplex) | [](https://travis-ci.com/libp2p/js-libp2p-mplex) | [](https://codecov.io/gh/libp2p/js-libp2p-mplex) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| [`libp2p-spdy`](//github.com/libp2p/js-libp2p-spdy) | [](//github.com/libp2p/js-libp2p-spdy/releases) | [](https://david-dm.org/libp2p/js-libp2p-spdy) | [](https://travis-ci.com/libp2p/js-libp2p-spdy) | [](https://codecov.io/gh/libp2p/js-libp2p-spdy) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| **Discovery** |
|
||||
| [`interface-peer-discovery`](//github.com/libp2p/interface-peer-discovery) | [](//github.com/libp2p/interface-peer-discovery/releases) | [](https://david-dm.org/libp2p/interface-peer-discovery) | N/A | [](https://codecov.io/gh/libp2p/interface-peer-discovery) | N/A |
|
||||
| [`libp2p-bootstrap`](//github.com/libp2p/js-libp2p-bootstrap) | [](//github.com/libp2p/js-libp2p-bootstrap/releases) | [](https://david-dm.org/libp2p/js-libp2p-bootstrap) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-bootstrap/job/master/) | [](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) | [](//github.com/libp2p/js-libp2p-kad-dht/releases) | [](https://david-dm.org/libp2p/js-libp2p-kad-dht) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-kad-dht/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| [`libp2p-mdns`](//github.com/libp2p/js-libp2p-mdns) | [](//github.com/libp2p/js-libp2p-mdns/releases) | [](https://david-dm.org/libp2p/js-libp2p-mdns) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-mdns/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-mdns) | N/A |
|
||||
| [`libp2p-rendezvous`](//github.com/libp2p/js-libp2p-rendezvous) | [](//github.com/libp2p/js-libp2p-rendezvous/releases) | [](https://david-dm.org/libp2p/js-libp2p-rendezvous) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-rendezvous) | N/A |
|
||||
| [`libp2p-webrtc-star`](//github.com/libp2p/js-libp2p-webrtc-star) | [](//github.com/libp2p/js-libp2p-webrtc-star/releases) | [](https://david-dm.org/libp2p/js-libp2p-webrtc-star) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-webrtc-star/job/master/) | [](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) | [](//github.com/libp2p/js-libp2p-websocket-star/releases) | [](https://david-dm.org/libp2p/js-libp2p-websocket-star) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-websocket-star) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`interface-peer-discovery`](//github.com/libp2p/interface-peer-discovery) | [](//github.com/libp2p/interface-peer-discovery/releases) | [](https://david-dm.org/libp2p/interface-peer-discovery) | [](https://travis-ci.com/libp2p/interface-peer-discovery) | [](https://codecov.io/gh/libp2p/interface-peer-discovery) | N/A |
|
||||
| [`libp2p-bootstrap`](//github.com/libp2p/js-libp2p-bootstrap) | [](//github.com/libp2p/js-libp2p-bootstrap/releases) | [](https://david-dm.org/libp2p/js-libp2p-bootstrap) | [](https://travis-ci.com/libp2p/js-libp2p-bootstrap) | [](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) | [](//github.com/libp2p/js-libp2p-kad-dht/releases) | [](https://david-dm.org/libp2p/js-libp2p-kad-dht) | [](https://travis-ci.com/libp2p/js-libp2p-kad-dht) | [](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| [`libp2p-mdns`](//github.com/libp2p/js-libp2p-mdns) | [](//github.com/libp2p/js-libp2p-mdns/releases) | [](https://david-dm.org/libp2p/js-libp2p-mdns) | [](https://travis-ci.com/libp2p/js-libp2p-mdns) | [](https://codecov.io/gh/libp2p/js-libp2p-mdns) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-rendezvous`](//github.com/libp2p/js-libp2p-rendezvous) | [](//github.com/libp2p/js-libp2p-rendezvous/releases) | [](https://david-dm.org/libp2p/js-libp2p-rendezvous) | [](https://travis-ci.com/libp2p/js-libp2p-rendezvous) | [](https://codecov.io/gh/libp2p/js-libp2p-rendezvous) | N/A |
|
||||
| [`libp2p-webrtc-star`](//github.com/libp2p/js-libp2p-webrtc-star) | [](//github.com/libp2p/js-libp2p-webrtc-star/releases) | [](https://david-dm.org/libp2p/js-libp2p-webrtc-star) | [](https://travis-ci.com/libp2p/js-libp2p-webrtc-star) | [](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) | [](//github.com/libp2p/js-libp2p-websocket-star/releases) | [](https://david-dm.org/libp2p/js-libp2p-websocket-star) | [](https://travis-ci.com/libp2p/js-libp2p-websocket-star) | [](https://codecov.io/gh/libp2p/js-libp2p-websocket-star) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| **NAT Traversal** |
|
||||
| [`libp2p-circuit`](//github.com/libp2p/js-libp2p-circuit) | [](//github.com/libp2p/js-libp2p-circuit/releases) | [](https://david-dm.org/libp2p/js-libp2p-circuit) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-circuit/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-circuit) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-nat-mngr`](//github.com/libp2p/js-libp2p-nat-mngr) | [](//github.com/libp2p/js-libp2p-nat-mngr/releases) | [](https://david-dm.org/libp2p/js-libp2p-nat-mngr) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-nat-mngr) | N/A |
|
||||
| [`libp2p-circuit`](//github.com/libp2p/js-libp2p-circuit) | [](//github.com/libp2p/js-libp2p-circuit/releases) | [](https://david-dm.org/libp2p/js-libp2p-circuit) | [](https://travis-ci.com/libp2p/js-libp2p-circuit) | [](https://codecov.io/gh/libp2p/js-libp2p-circuit) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-nat-mngr`](//github.com/libp2p/js-libp2p-nat-mngr) | [](//github.com/libp2p/js-libp2p-nat-mngr/releases) | [](https://david-dm.org/libp2p/js-libp2p-nat-mngr) | [](https://travis-ci.com/libp2p/js-libp2p-nat-mngr) | [](https://codecov.io/gh/libp2p/js-libp2p-nat-mngr) | N/A |
|
||||
| **Data Types** |
|
||||
| [`peer-book`](//github.com/libp2p/js-peer-book) | [](//github.com/libp2p/js-peer-book/releases) | [](https://david-dm.org/libp2p/js-peer-book) | N/A | [](https://codecov.io/gh/libp2p/js-peer-book) | [Pedro Teixeira](mailto:i@pgte.me) |
|
||||
| [`peer-id`](//github.com/libp2p/js-peer-id) | [](//github.com/libp2p/js-peer-id/releases) | [](https://david-dm.org/libp2p/js-peer-id) | [](https://ci.ipfs.team/job/libp2p/job/js-peer-id/job/master/) | [](https://codecov.io/gh/libp2p/js-peer-id) | [Pedro Teixeira](mailto:i@pgte.me) |
|
||||
| [`peer-info`](//github.com/libp2p/js-peer-info) | [](//github.com/libp2p/js-peer-info/releases) | [](https://david-dm.org/libp2p/js-peer-info) | [](https://ci.ipfs.team/job/libp2p/job/js-peer-info/job/master/) | [](https://codecov.io/gh/libp2p/js-peer-info) | N/A |
|
||||
| [`peer-book`](//github.com/libp2p/js-peer-book) | [](//github.com/libp2p/js-peer-book/releases) | [](https://david-dm.org/libp2p/js-peer-book) | [](https://travis-ci.com/libp2p/js-peer-book) | [](https://codecov.io/gh/libp2p/js-peer-book) | [Pedro Teixeira](mailto:i@pgte.me) |
|
||||
| [`peer-id`](//github.com/libp2p/js-peer-id) | [](//github.com/libp2p/js-peer-id/releases) | [](https://david-dm.org/libp2p/js-peer-id) | [](https://travis-ci.com/libp2p/js-peer-id) | [](https://codecov.io/gh/libp2p/js-peer-id) | [Pedro Teixeira](mailto:i@pgte.me) |
|
||||
| [`peer-info`](//github.com/libp2p/js-peer-info) | [](//github.com/libp2p/js-peer-info/releases) | [](https://david-dm.org/libp2p/js-peer-info) | [](https://travis-ci.com/libp2p/js-peer-info) | [](https://codecov.io/gh/libp2p/js-peer-info) | [Pedro Teixeira](mailto:i@pgte.me) |
|
||||
| **Content Routing** |
|
||||
| [`interface-content-routing`](//github.com/libp2p/interface-content-routing) | [](//github.com/libp2p/interface-content-routing/releases) | [](https://david-dm.org/libp2p/interface-content-routing) | N/A | [](https://codecov.io/gh/libp2p/interface-content-routing) | N/A |
|
||||
| [`libp2p-delegated-content-routing`](//github.com/libp2p/js-libp2p-delegated-content-routing) | [](//github.com/libp2p/js-libp2p-delegated-content-routing/releases) | [](https://david-dm.org/libp2p/js-libp2p-delegated-content-routing) | N/A | [](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) | [](//github.com/libp2p/js-libp2p-kad-dht/releases) | [](https://david-dm.org/libp2p/js-libp2p-kad-dht) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-kad-dht/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| [`interface-content-routing`](//github.com/libp2p/interface-content-routing) | [](//github.com/libp2p/interface-content-routing/releases) | [](https://david-dm.org/libp2p/interface-content-routing) | [](https://travis-ci.com/libp2p/interface-content-routing) | [](https://codecov.io/gh/libp2p/interface-content-routing) | N/A |
|
||||
| [`libp2p-delegated-content-routing`](//github.com/libp2p/js-libp2p-delegated-content-routing) | [](//github.com/libp2p/js-libp2p-delegated-content-routing/releases) | [](https://david-dm.org/libp2p/js-libp2p-delegated-content-routing) | [](https://travis-ci.com/libp2p/js-libp2p-delegated-content-routing) | [](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) | [](//github.com/libp2p/js-libp2p-kad-dht/releases) | [](https://david-dm.org/libp2p/js-libp2p-kad-dht) | [](https://travis-ci.com/libp2p/js-libp2p-kad-dht) | [](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| **Peer Routing** |
|
||||
| [`interface-peer-routing`](//github.com/libp2p/interface-peer-routing) | [](//github.com/libp2p/interface-peer-routing/releases) | [](https://david-dm.org/libp2p/interface-peer-routing) | N/A | [](https://codecov.io/gh/libp2p/interface-peer-routing) | N/A |
|
||||
| [`libp2p-delegated-peer-routing`](//github.com/libp2p/js-libp2p-delegated-peer-routing) | [](//github.com/libp2p/js-libp2p-delegated-peer-routing/releases) | [](https://david-dm.org/libp2p/js-libp2p-delegated-peer-routing) | N/A | [](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) | [](//github.com/libp2p/js-libp2p-kad-dht/releases) | [](https://david-dm.org/libp2p/js-libp2p-kad-dht) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-kad-dht/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| [`interface-peer-routing`](//github.com/libp2p/interface-peer-routing) | [](//github.com/libp2p/interface-peer-routing/releases) | [](https://david-dm.org/libp2p/interface-peer-routing) | [](https://travis-ci.com/libp2p/interface-peer-routing) | [](https://codecov.io/gh/libp2p/interface-peer-routing) | N/A |
|
||||
| [`libp2p-delegated-peer-routing`](//github.com/libp2p/js-libp2p-delegated-peer-routing) | [](//github.com/libp2p/js-libp2p-delegated-peer-routing/releases) | [](https://david-dm.org/libp2p/js-libp2p-delegated-peer-routing) | [](https://travis-ci.com/libp2p/js-libp2p-delegated-peer-routing) | [](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) | [](//github.com/libp2p/js-libp2p-kad-dht/releases) | [](https://david-dm.org/libp2p/js-libp2p-kad-dht) | [](https://travis-ci.com/libp2p/js-libp2p-kad-dht) | [](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| **Record Store** |
|
||||
| [`interface-record-store`](//github.com/libp2p/interface-record-store) | [](//github.com/libp2p/interface-record-store/releases) | [](https://david-dm.org/libp2p/interface-record-store) | N/A | [](https://codecov.io/gh/libp2p/interface-record-store) | N/A |
|
||||
| [`libp2p-record`](//github.com/libp2p/js-libp2p-record) | [](//github.com/libp2p/js-libp2p-record/releases) | [](https://david-dm.org/libp2p/js-libp2p-record) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-record/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-record) | N/A |
|
||||
| [`interface-record-store`](//github.com/libp2p/interface-record-store) | [](//github.com/libp2p/interface-record-store/releases) | [](https://david-dm.org/libp2p/interface-record-store) | [](https://travis-ci.com/libp2p/interface-record-store) | [](https://codecov.io/gh/libp2p/interface-record-store) | N/A |
|
||||
| [`libp2p-record`](//github.com/libp2p/js-libp2p-record) | [](//github.com/libp2p/js-libp2p-record/releases) | [](https://david-dm.org/libp2p/js-libp2p-record) | [](https://travis-ci.com/libp2p/js-libp2p-record) | [](https://codecov.io/gh/libp2p/js-libp2p-record) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| **Generics** |
|
||||
| [`libp2p-connection-manager`](//github.com/libp2p/js-libp2p-connection-manager) | [](//github.com/libp2p/js-libp2p-connection-manager/releases) | [](https://david-dm.org/libp2p/js-libp2p-connection-manager) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-connection-manager) | N/A |
|
||||
| [`libp2p-crypto`](//github.com/libp2p/js-libp2p-crypto) | [](//github.com/libp2p/js-libp2p-crypto/releases) | [](https://david-dm.org/libp2p/js-libp2p-crypto) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-crypto/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-crypto) | [Friedel Ziegelmayer](mailto:dignifiedquire@gmail.com) |
|
||||
| [`libp2p-crypto-secp256k1`](//github.com/libp2p/js-libp2p-crypto-secp256k1) | [](//github.com/libp2p/js-libp2p-crypto-secp256k1/releases) | [](https://david-dm.org/libp2p/js-libp2p-crypto-secp256k1) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-crypto-secp256k1/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-crypto-secp256k1) | N/A |
|
||||
| [`libp2p-switch`](//github.com/libp2p/js-libp2p-switch) | [](//github.com/libp2p/js-libp2p-switch/releases) | [](https://david-dm.org/libp2p/js-libp2p-switch) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-switch/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-switch) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-connection-manager`](//github.com/libp2p/js-libp2p-connection-manager) | [](//github.com/libp2p/js-libp2p-connection-manager/releases) | [](https://david-dm.org/libp2p/js-libp2p-connection-manager) | [](https://travis-ci.com/libp2p/js-libp2p-connection-manager) | [](https://codecov.io/gh/libp2p/js-libp2p-connection-manager) | N/A |
|
||||
| [`libp2p-crypto`](//github.com/libp2p/js-libp2p-crypto) | [](//github.com/libp2p/js-libp2p-crypto/releases) | [](https://david-dm.org/libp2p/js-libp2p-crypto) | [](https://travis-ci.com/libp2p/js-libp2p-crypto) | [](https://codecov.io/gh/libp2p/js-libp2p-crypto) | [Friedel Ziegelmayer](mailto:dignifiedquire@gmail.com) |
|
||||
| [`libp2p-crypto-secp256k1`](//github.com/libp2p/js-libp2p-crypto-secp256k1) | [](//github.com/libp2p/js-libp2p-crypto-secp256k1/releases) | [](https://david-dm.org/libp2p/js-libp2p-crypto-secp256k1) | [](https://travis-ci.com/libp2p/js-libp2p-crypto-secp256k1) | [](https://codecov.io/gh/libp2p/js-libp2p-crypto-secp256k1) | [Friedel Ziegelmayer](mailto:dignifiedquire@gmail.com) |
|
||||
| [`libp2p-switch`](//github.com/libp2p/js-libp2p-switch) | [](//github.com/libp2p/js-libp2p-switch/releases) | [](https://david-dm.org/libp2p/js-libp2p-switch) | [](https://travis-ci.com/libp2p/js-libp2p-switch) | [](https://codecov.io/gh/libp2p/js-libp2p-switch) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| **Extensions** |
|
||||
| [`libp2p-floodsub`](//github.com/libp2p/js-libp2p-floodsub) | [](//github.com/libp2p/js-libp2p-floodsub/releases) | [](https://david-dm.org/libp2p/js-libp2p-floodsub) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-floodsub) | N/A |
|
||||
| [`libp2p-identify`](//github.com/libp2p/js-libp2p-identify) | [](//github.com/libp2p/js-libp2p-identify/releases) | [](https://david-dm.org/libp2p/js-libp2p-identify) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-identify) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-keychain`](//github.com/libp2p/js-libp2p-keychain) | [](//github.com/libp2p/js-libp2p-keychain/releases) | [](https://david-dm.org/libp2p/js-libp2p-keychain) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-keychain) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| [`libp2p-ping`](//github.com/libp2p/js-libp2p-ping) | [](//github.com/libp2p/js-libp2p-ping/releases) | [](https://david-dm.org/libp2p/js-libp2p-ping) | [](https://ci.ipfs.team/job/libp2p/job/js-libp2p-ping/job/master/) | [](https://codecov.io/gh/libp2p/js-libp2p-ping) | N/A |
|
||||
| [`libp2p-pnet`](//github.com/libp2p/js-libp2p-pnet) | [](//github.com/libp2p/js-libp2p-pnet/releases) | [](https://david-dm.org/libp2p/js-libp2p-pnet) | N/A | [](https://codecov.io/gh/libp2p/js-libp2p-pnet) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-floodsub`](//github.com/libp2p/js-libp2p-floodsub) | [](//github.com/libp2p/js-libp2p-floodsub/releases) | [](https://david-dm.org/libp2p/js-libp2p-floodsub) | [](https://travis-ci.com/libp2p/js-libp2p-floodsub) | [](https://codecov.io/gh/libp2p/js-libp2p-floodsub) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| [`libp2p-identify`](//github.com/libp2p/js-libp2p-identify) | [](//github.com/libp2p/js-libp2p-identify/releases) | [](https://david-dm.org/libp2p/js-libp2p-identify) | [](https://travis-ci.com/libp2p/js-libp2p-identify) | [](https://codecov.io/gh/libp2p/js-libp2p-identify) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-keychain`](//github.com/libp2p/js-libp2p-keychain) | [](//github.com/libp2p/js-libp2p-keychain/releases) | [](https://david-dm.org/libp2p/js-libp2p-keychain) | [](https://travis-ci.com/libp2p/js-libp2p-keychain) | [](https://codecov.io/gh/libp2p/js-libp2p-keychain) | [Vasco Santos](mailto:vasco.santos@moxy.studio) |
|
||||
| [`libp2p-ping`](//github.com/libp2p/js-libp2p-ping) | [](//github.com/libp2p/js-libp2p-ping/releases) | [](https://david-dm.org/libp2p/js-libp2p-ping) | [](https://travis-ci.com/libp2p/js-libp2p-ping) | [](https://codecov.io/gh/libp2p/js-libp2p-ping) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| [`libp2p-pnet`](//github.com/libp2p/js-libp2p-pnet) | [](//github.com/libp2p/js-libp2p-pnet/releases) | [](https://david-dm.org/libp2p/js-libp2p-pnet) | [](https://travis-ci.com/libp2p/js-libp2p-pnet) | [](https://codecov.io/gh/libp2p/js-libp2p-pnet) | [Jacob Heun](mailto:jacobheun@gmail.com) |
|
||||
| **Utilities** |
|
||||
| [`p2pcat`](//github.com/libp2p/js-p2pcat) | [](//github.com/libp2p/js-p2pcat/releases) | [](https://david-dm.org/libp2p/js-p2pcat) | N/A | [](https://codecov.io/gh/libp2p/js-p2pcat) | N/A |
|
||||
| [`p2pcat`](//github.com/libp2p/js-p2pcat) | [](//github.com/libp2p/js-p2pcat/releases) | [](https://david-dm.org/libp2p/js-p2pcat) | [](https://travis-ci.com/libp2p/js-p2pcat) | [](https://codecov.io/gh/libp2p/js-p2pcat) | N/A |
|
||||
|
||||
## Contribute
|
||||
|
||||
|
25
RELEASE.md
25
RELEASE.md
@ -13,6 +13,14 @@
|
||||
- Robustness and quality
|
||||
- [ ] Ensure that all tests are passing, this includes:
|
||||
- [ ] 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:
|
||||
- [ ] [js-ipfs](https://github.com/ipfs/js-ipfs)
|
||||
- Documentation
|
||||
@ -20,22 +28,31 @@
|
||||
- [ ] Ensure that all the examples run
|
||||
- Communication
|
||||
- [ ] 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)
|
||||
- [ ] Twitter
|
||||
- [ ] IRC
|
||||
- [ ] Reddit
|
||||
- [ ] [discuss.libp2p.io](https://discuss.libp2p.io/c/news)
|
||||
- [ ] 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?
|
||||
|
||||
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 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/pm/#all-hands-call
|
||||
- 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)
|
||||
- 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
|
||||
- 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 [⚡️ⒿⓈ Core Dev Team Weekly Sync 🙌🏽 ](https://github.com/ipfs/pm/issues/650) and be part of the Sprint action!
|
||||
- Join the [⚡️ⒿⓈ Core Dev Team Weekly Sync 🙌🏽 ](https://github.com/ipfs/team-mgmt/issues/650) and be part of the Sprint action!
|
||||
|
||||
# ⁉️ 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.ipfs.io](http://discuss.ipfs.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.libp2p.io](https://discuss.libp2p.io). We are also available at the #libp2p channel on Freenode.
|
||||
|
2
ci/Jenkinsfile
vendored
2
ci/Jenkinsfile
vendored
@ -1,2 +0,0 @@
|
||||
// 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()
|
@ -10,8 +10,7 @@ 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)
|
||||
- [Encrypted Communications](./encrypted-communications)
|
||||
- [Discovery Mechanisms](./discovery-mechanisms)
|
||||
- [Peer Routing](./peer-and-content-routing)
|
||||
- [Content Routing](./peer-and-content-routing)
|
||||
- [Peer and Content Routing](./peer-and-content-routing)
|
||||
- [PubSub](./pubsub)
|
||||
- [NAT Traversal](./nat-traversal)
|
||||
- Circuit Relay (future)
|
||||
|
@ -3,8 +3,8 @@
|
||||
This example creates a simple chat app in your terminal.
|
||||
|
||||
## Setup
|
||||
1. Install the modules, `npm install`.
|
||||
2. Open 2 terminal windows in the `./src` directory.
|
||||
1. Install the modules in the libp2p root directory, `npm install`.
|
||||
2. Open 2 terminal windows in the `./examples/chat/src` directory.
|
||||
|
||||
## Running
|
||||
1. Run the listener in window 1, `node listener.js`
|
||||
|
@ -46,7 +46,7 @@ async.parallel([
|
||||
console.log('Dialer ready, listening on:')
|
||||
|
||||
peerListener.multiaddrs.forEach((ma) => {
|
||||
console.log(ma.toString() + '/ipfs/' + idListener.toB58String())
|
||||
console.log(ma.toString() + '/p2p/' + idListener.toB58String())
|
||||
})
|
||||
|
||||
nodeDialer.dialProtocol(peerListener, '/chat/1.0.0', (err, conn) => {
|
||||
|
@ -50,7 +50,7 @@ PeerId.createFromJSON(require('./peer-id-listener'), (err, idListener) => {
|
||||
|
||||
console.log('Listener ready, listening on:')
|
||||
peerListener.multiaddrs.forEach((ma) => {
|
||||
console.log(ma.toString() + '/ipfs/' + idListener.toB58String())
|
||||
console.log(ma.toString() + '/p2p/' + idListener.toB58String())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -10,18 +10,17 @@ 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
|
||||
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
|
||||
|
||||
1. Install IPFS locally if you dont already have it. [Install Guide](https://docs.ipfs.io/introduction/install/)
|
||||
2. Run the IPFS daemon: `ipfs daemon`
|
||||
3. The daemon will output a line about its API address, like `API server listening on /ip4/127.0.0.1/tcp/8080`
|
||||
4. In another window output the addresses of the node: `ipfs id`. Make note of the websocket address, it will contain `/ws/` in the address.
|
||||
5. 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.
|
||||
7. Start this example:
|
||||
1. Install go-ipfs locally if you dont already have it. [Install Guide](https://docs.ipfs.io/introduction/install/).
|
||||
1. 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`.
|
||||
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"]'`.
|
||||
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`.
|
||||
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.
|
||||
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.
|
||||
1. Start this example:
|
||||
|
||||
```sh
|
||||
npm install
|
||||
@ -47,3 +46,12 @@ 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`.
|
||||
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.
|
||||
|
||||
### 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.
|
||||
|
@ -3,21 +3,27 @@
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"ipfs": "~0.32.2",
|
||||
"libp2p": "../../",
|
||||
"ipfs": "~0.36.1",
|
||||
"libp2p": "github:libp2p/js-libp2p#master",
|
||||
"libp2p-delegated-content-routing": "~0.2.2",
|
||||
"libp2p-delegated-peer-routing": "~0.2.2",
|
||||
"libp2p-kad-dht": "~0.10.4",
|
||||
"libp2p-mplex": "~0.8.0",
|
||||
"libp2p-secio": "~0.10.0",
|
||||
"libp2p-webrtc-star": "~0.15.5",
|
||||
"libp2p-websocket-star": "~0.8.1",
|
||||
"libp2p-websockets": "~0.12.0",
|
||||
"react": "^16.5.2",
|
||||
"react-dom": "^16.5.2",
|
||||
"react-scripts": "1.1.5"
|
||||
"libp2p-kad-dht": "~0.15.0",
|
||||
"libp2p-secio": "~0.11.1",
|
||||
"libp2p-webrtc-star": "~0.16.1",
|
||||
"libp2p-websocket-star": "~0.10.2",
|
||||
"libp2p-websockets": "~0.12.2",
|
||||
"pull-mplex": "~0.1.2",
|
||||
"react": "^16.8.6",
|
||||
"react-dom": "^16.8.6",
|
||||
"react-scripts": "2.1.8"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start"
|
||||
}
|
||||
},
|
||||
"browserslist": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not ie <= 11",
|
||||
"not op_mini all"
|
||||
]
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
// eslint-disable-next-line
|
||||
'use strict'
|
||||
|
||||
const React = require('react')
|
||||
import React from 'react'
|
||||
import Ipfs from 'ipfs'
|
||||
import libp2pBundle from './libp2p-bundle'
|
||||
const Component = React.Component
|
||||
const Ipfs = require('ipfs')
|
||||
const libp2pBundle = require('./libp2p-bundle')
|
||||
// require('./App.css')
|
||||
|
||||
const BootstrapNode = '/ip4/127.0.0.1/tcp/8081/ws/ipfs/QmdoG8DpzYUZMVP5dGmgmigZwR1RE8Cf6SxMPg1SBXJAQ8'
|
||||
/* TODO: Add your go IPFS nodes ID here by running `ipfs id` */
|
||||
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 {
|
||||
constructor (props) {
|
||||
@ -18,6 +20,7 @@ class App extends Component {
|
||||
hash: 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB',
|
||||
// This peer is one of the Bootstrap nodes for IPFS
|
||||
peer: 'QmV6kA2fB8kTr6jc3pL5zbNsjKbmPUHAPKKHRBYe1kDEyc',
|
||||
data: '',
|
||||
isLoading: 0
|
||||
}
|
||||
this.peerInterval = null
|
||||
@ -26,6 +29,8 @@ class App extends Component {
|
||||
this.handleHashSubmit = this.handleHashSubmit.bind(this)
|
||||
this.handlePeerChange = this.handlePeerChange.bind(this)
|
||||
this.handlePeerSubmit = this.handlePeerSubmit.bind(this)
|
||||
this.handleDataChange = this.handleDataChange.bind(this)
|
||||
this.handleDataSubmit = this.handleDataSubmit.bind(this)
|
||||
}
|
||||
|
||||
handleHashChange (event) {
|
||||
@ -38,6 +43,11 @@ class App extends Component {
|
||||
peer: event.target.value
|
||||
})
|
||||
}
|
||||
handleDataChange (event) {
|
||||
this.setState({
|
||||
data: event.target.value
|
||||
})
|
||||
}
|
||||
|
||||
handleHashSubmit (event) {
|
||||
event.preventDefault()
|
||||
@ -45,7 +55,7 @@ class App extends Component {
|
||||
isLoading: this.state.isLoading + 1
|
||||
})
|
||||
|
||||
this.ipfs.files.cat(this.state.hash, (err, data) => {
|
||||
this.ipfs.cat(this.state.hash, (err, data) => {
|
||||
if (err) console.log('Error', err)
|
||||
|
||||
this.setState({
|
||||
@ -60,7 +70,22 @@ class App extends Component {
|
||||
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)
|
||||
|
||||
this.setState({
|
||||
@ -136,6 +161,13 @@ class App extends Component {
|
||||
<input type="submit" value="Find" />
|
||||
</label>
|
||||
</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 className={[this.state.isLoading > 0 ? 'loading' : '', 'loader'].join(' ')}>
|
||||
<div className="lds-ripple"><div></div><div></div></div>
|
||||
@ -150,4 +182,4 @@ class App extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = App
|
||||
export default App
|
||||
|
@ -1,9 +1,8 @@
|
||||
// eslint-disable-next-line
|
||||
'use strict'
|
||||
|
||||
const React = require('react') // eslint-disable-line no-unused-vars
|
||||
const ReactDOM = require('react-dom')
|
||||
const App = require('./App') // eslint-disable-line no-unused-vars
|
||||
// require('index.css')
|
||||
import React from 'react' // eslint-disable-line no-unused-vars
|
||||
import ReactDOM from 'react-dom'
|
||||
import App from './App' // eslint-disable-line no-unused-vars
|
||||
|
||||
ReactDOM.render(<App />, document.getElementById('root'))
|
||||
|
@ -5,17 +5,18 @@ const Libp2p = require('libp2p')
|
||||
const Websockets = require('libp2p-websockets')
|
||||
const WebSocketStar = require('libp2p-websocket-star')
|
||||
const WebRTCStar = require('libp2p-webrtc-star')
|
||||
const MPLEX = require('libp2p-mplex')
|
||||
const MPLEX = require('pull-mplex')
|
||||
const SECIO = require('libp2p-secio')
|
||||
const KadDHT = require('libp2p-kad-dht')
|
||||
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
|
||||
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
|
||||
|
||||
module.exports = ({peerInfo, peerBook}) => {
|
||||
export default function Libp2pBundle ({peerInfo, peerBook}) {
|
||||
const wrtcstar = new WebRTCStar({id: peerInfo.id})
|
||||
const wsstar = new WebSocketStar({id: peerInfo.id})
|
||||
/* TODO: Ensure the delegatedApiOptions match your IPFS nodes API server */
|
||||
const delegatedApiOptions = {
|
||||
host: '0.0.0.0',
|
||||
host: '127.0.0.1',
|
||||
protocol: 'http',
|
||||
port: '8080'
|
||||
}
|
||||
@ -25,7 +26,8 @@ module.exports = ({peerInfo, peerBook}) => {
|
||||
peerBook,
|
||||
// Lets limit the connection managers peers and have it check peer health less frequently
|
||||
connectionManager: {
|
||||
maxPeers: 10,
|
||||
minPeers: 20,
|
||||
maxPeers: 50,
|
||||
pollInterval: 5000
|
||||
},
|
||||
modules: {
|
||||
@ -54,6 +56,7 @@ module.exports = ({peerInfo, peerBook}) => {
|
||||
},
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
autoDial: false,
|
||||
webrtcStar: {
|
||||
enabled: false
|
||||
},
|
||||
@ -62,16 +65,13 @@ module.exports = ({peerInfo, peerBook}) => {
|
||||
}
|
||||
},
|
||||
dht: {
|
||||
kBucketSize: 20
|
||||
enabled: false
|
||||
},
|
||||
relay: {
|
||||
enabled: true,
|
||||
hop: {
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
dht: false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -12,15 +12,15 @@ const defaultsDeep = require('@nodeutils/defaults-deep')
|
||||
|
||||
// Find this list at: https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/config-nodejs.json
|
||||
const bootstrapers = [
|
||||
'/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
|
||||
'/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
|
||||
'/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
|
||||
'/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
|
||||
'/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
|
||||
'/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
|
||||
'/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
|
||||
'/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
|
||||
'/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx'
|
||||
'/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
|
||||
'/ip4/104.236.176.52/tcp/4001/p2p/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
|
||||
'/ip4/104.236.179.241/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
|
||||
'/ip4/162.243.248.213/tcp/4001/p2p/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
|
||||
'/ip4/128.199.219.111/tcp/4001/p2p/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
|
||||
'/ip4/104.236.76.40/tcp/4001/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
|
||||
'/ip4/178.62.158.247/tcp/4001/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
|
||||
'/ip4/178.62.61.185/tcp/4001/p2p/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
|
||||
'/ip4/104.236.151.122/tcp/4001/p2p/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx'
|
||||
]
|
||||
|
||||
class MyBundle extends libp2p {
|
||||
@ -34,8 +34,9 @@ class MyBundle extends libp2p {
|
||||
},
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
autoDial: true,
|
||||
bootstrap: {
|
||||
interval: 2000,
|
||||
interval: 20e3,
|
||||
enabled: true,
|
||||
list: bootstrapers
|
||||
}
|
||||
@ -62,8 +63,8 @@ waterfall([
|
||||
if (err) { throw err }
|
||||
|
||||
node.on('peer:discovery', (peer) => {
|
||||
// No need to dial, autoDial is on
|
||||
console.log('Discovered:', peer.id.toB58String())
|
||||
node.dial(peer, () => {})
|
||||
})
|
||||
|
||||
node.on('peer:connect', (peer) => {
|
||||
|
@ -23,7 +23,7 @@ class MyBundle extends libp2p {
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
mdns: {
|
||||
interval: 1000,
|
||||
interval: 20e3,
|
||||
enabled: true
|
||||
}
|
||||
}
|
||||
|
@ -43,15 +43,15 @@ In this bundle, we use a `bootstrappers` array listing peers to connect _on boot
|
||||
|
||||
```JavaScript
|
||||
const bootstrapers = [
|
||||
'/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
|
||||
'/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
|
||||
'/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
|
||||
'/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
|
||||
'/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
|
||||
'/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
|
||||
'/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
|
||||
'/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
|
||||
'/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx'
|
||||
'/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
|
||||
'/ip4/104.236.176.52/tcp/4001/p2p/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
|
||||
'/ip4/104.236.179.241/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
|
||||
'/ip4/162.243.248.213/tcp/4001/p2p/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
|
||||
'/ip4/128.199.219.111/tcp/4001/p2p/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
|
||||
'/ip4/104.236.76.40/tcp/4001/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
|
||||
'/ip4/178.62.158.247/tcp/4001/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
|
||||
'/ip4/178.62.61.185/tcp/4001/p2p/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
|
||||
'/ip4/104.236.151.122/tcp/4001/p2p/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx'
|
||||
]
|
||||
```
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
This example performs a simple echo from the listener to the dialer.
|
||||
|
||||
## Setup
|
||||
1. Install the modules, `npm install`.
|
||||
1. Install the modules from libp2p root, `npm install`.
|
||||
2. Open 2 terminal windows in the `./src` directory.
|
||||
|
||||
## Running
|
||||
|
@ -28,7 +28,7 @@ async.parallel([
|
||||
// Peer to Dial
|
||||
const listenerPeerInfo = new PeerInfo(ids[1])
|
||||
const listenerId = ids[1]
|
||||
const listenerMultiaddr = '/ip4/127.0.0.1/tcp/10333/ipfs/' +
|
||||
const listenerMultiaddr = '/ip4/127.0.0.1/tcp/10333/p2p/' +
|
||||
listenerId.toB58String()
|
||||
listenerPeerInfo.multiaddrs.add(listenerMultiaddr)
|
||||
|
||||
@ -37,7 +37,7 @@ async.parallel([
|
||||
|
||||
console.log('Dialer ready, listening on:')
|
||||
dialerPeerInfo.multiaddrs.forEach((ma) => console.log(ma.toString() +
|
||||
'/ipfs/' + dialerId.toB58String()))
|
||||
'/p2p/' + dialerId.toB58String()))
|
||||
|
||||
console.log('Dialing to peer:', listenerMultiaddr.toString())
|
||||
dialerNode.dialProtocol(listenerPeerInfo, '/echo/1.0.0', (err, conn) => {
|
||||
|
@ -41,6 +41,6 @@ series([
|
||||
|
||||
console.log('Listener ready, listening on:')
|
||||
listenerNode.peerInfo.multiaddrs.forEach((ma) => {
|
||||
console.log(ma.toString() + '/ipfs/' + listenerId.toB58String())
|
||||
console.log(ma.toString() + '/p2p/' + listenerId.toB58String())
|
||||
})
|
||||
})
|
||||
|
@ -17,13 +17,13 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"detect-dom-ready": "^1.0.2",
|
||||
"libp2p-bootstrap": "~0.9.3",
|
||||
"libp2p-mplex": "~0.8.0",
|
||||
"libp2p-secio": "~0.10.0",
|
||||
"libp2p-spdy": "~0.12.1",
|
||||
"libp2p-webrtc-star": "~0.15.3",
|
||||
"libp2p-websocket-star": "~0.8.1",
|
||||
"libp2p-websockets": "~0.12.0",
|
||||
"peer-info": "~0.14.1"
|
||||
"libp2p-bootstrap": "~0.9.7",
|
||||
"libp2p-mplex": "~0.8.5",
|
||||
"libp2p-secio": "~0.11.1",
|
||||
"libp2p-spdy": "~0.13.3",
|
||||
"libp2p-webrtc-star": "~0.15.8",
|
||||
"libp2p-websocket-star": "~0.10.2",
|
||||
"libp2p-websockets": "~0.12.2",
|
||||
"peer-info": "~0.15.1"
|
||||
}
|
||||
}
|
||||
|
@ -7,21 +7,22 @@ const Mplex = require('libp2p-mplex')
|
||||
const SPDY = require('libp2p-spdy')
|
||||
const SECIO = require('libp2p-secio')
|
||||
const Bootstrap = require('libp2p-bootstrap')
|
||||
const DHT = require('libp2p-kad-dht')
|
||||
const defaultsDeep = require('@nodeutils/defaults-deep')
|
||||
const libp2p = require('../../../../')
|
||||
|
||||
// Find this list at: https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/config-browser.json
|
||||
const bootstrapList = [
|
||||
'/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
|
||||
'/dns4/sfo-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx',
|
||||
'/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
|
||||
'/dns4/sfo-2.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
|
||||
'/dns4/sfo-3.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
|
||||
'/dns4/sgp-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
|
||||
'/dns4/nyc-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
|
||||
'/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
|
||||
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
|
||||
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
|
||||
'/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
|
||||
'/dns4/sfo-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx',
|
||||
'/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
|
||||
'/dns4/sfo-2.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
|
||||
'/dns4/sfo-3.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
|
||||
'/dns4/sgp-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
|
||||
'/dns4/nyc-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
|
||||
'/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
|
||||
'/dns4/node0.preload.ipfs.io/tcp/443/wss/p2p/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
|
||||
'/dns4/node0.preload.ipfs.io/tcp/443/wss/p2p/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
|
||||
]
|
||||
|
||||
class Node extends libp2p {
|
||||
@ -47,10 +48,12 @@ class Node extends libp2p {
|
||||
wrtcStar.discovery,
|
||||
wsstar.discovery,
|
||||
Bootstrap
|
||||
]
|
||||
],
|
||||
dht: DHT
|
||||
},
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
autoDial: true,
|
||||
webRTCStar: {
|
||||
enabled: true
|
||||
},
|
||||
@ -58,7 +61,7 @@ class Node extends libp2p {
|
||||
enabled: true
|
||||
},
|
||||
bootstrap: {
|
||||
interval: 10000,
|
||||
interval: 20e3,
|
||||
enabled: true,
|
||||
list: bootstrapList
|
||||
}
|
||||
@ -66,16 +69,19 @@ class Node extends libp2p {
|
||||
relay: {
|
||||
enabled: true,
|
||||
hop: {
|
||||
enabled: true,
|
||||
enabled: false,
|
||||
active: false
|
||||
}
|
||||
},
|
||||
dht: {
|
||||
enabled: false
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
dht: false,
|
||||
pubsub: false
|
||||
}
|
||||
},
|
||||
connectionManager: {
|
||||
minPeers: 10,
|
||||
maxPeers: 50
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ function createNode (callback) {
|
||||
}
|
||||
|
||||
const peerIdStr = peerInfo.id.toB58String()
|
||||
const ma = `/dns4/star-signal.cloud.ipfs.team/tcp/443/wss/p2p-webrtc-star/ipfs/${peerIdStr}`
|
||||
const ma = `/dns4/star-signal.cloud.ipfs.team/tcp/443/wss/p2p-webrtc-star/p2p/${peerIdStr}`
|
||||
|
||||
peerInfo.multiaddrs.add(ma)
|
||||
|
||||
|
@ -14,26 +14,8 @@ domReady(() => {
|
||||
return console.log('Could not create the Node, check if your browser has WebRTC Support', err)
|
||||
}
|
||||
|
||||
let connections = {}
|
||||
|
||||
node.on('peer:discovery', (peerInfo) => {
|
||||
const idStr = peerInfo.id.toB58String()
|
||||
if (connections[idStr]) {
|
||||
// If we're already trying to connect to this peer, dont dial again
|
||||
return
|
||||
}
|
||||
console.log('Discovered a peer:', idStr)
|
||||
|
||||
connections[idStr] = true
|
||||
node.dial(peerInfo, (err, conn) => {
|
||||
if (err) {
|
||||
// Prevent immediate connection retries from happening
|
||||
// and include a 10s jitter
|
||||
const timeToNextDial = 25 * 1000 + (Math.random(0) * 10000).toFixed(0)
|
||||
console.log('Failed to dial:', idStr)
|
||||
setTimeout(() => delete connections[idStr], timeToNextDial)
|
||||
}
|
||||
})
|
||||
console.log('Discovered a peer:', peerInfo.id.toB58String())
|
||||
})
|
||||
|
||||
node.on('peer:connect', (peerInfo) => {
|
||||
@ -47,15 +29,13 @@ domReady(() => {
|
||||
|
||||
node.on('peer:disconnect', (peerInfo) => {
|
||||
const idStr = peerInfo.id.toB58String()
|
||||
delete connections[idStr]
|
||||
console.log('Lost connection to: ' + idStr)
|
||||
const el = document.getElementById(idStr)
|
||||
el && el.remove()
|
||||
})
|
||||
|
||||
node.start((err) => {
|
||||
if (err) {
|
||||
return console.log('WebRTC not supported')
|
||||
return console.log(err)
|
||||
}
|
||||
|
||||
const idStr = node.peerInfo.id.toB58String()
|
||||
|
@ -4,7 +4,15 @@ 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
|
||||
|
||||
Simple go into the folder [1](./1) and execute the following
|
||||
Start by installing libp2p's dependencies.
|
||||
|
||||
```bash
|
||||
> cd ../../
|
||||
> npm install
|
||||
> cd examples/libp2p-in-the-browser
|
||||
```
|
||||
|
||||
Then simply go into the folder [1](./1) and execute the following
|
||||
|
||||
```bash
|
||||
> cd 1
|
||||
|
@ -23,10 +23,8 @@ class MyBundle extends libp2p {
|
||||
},
|
||||
config: {
|
||||
dht: {
|
||||
enabled: true,
|
||||
kBucketSize: 20
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
dht: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,8 @@ class MyBundle extends libp2p {
|
||||
},
|
||||
config: {
|
||||
dht: {
|
||||
enabled: true,
|
||||
kBucketSize: 20
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
dht: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,9 @@ class MyBundle extends libp2p {
|
||||
},
|
||||
config: {
|
||||
dht: {
|
||||
kBucketSize: 20
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
// dht must be enabled
|
||||
dht: true
|
||||
enabled: true,
|
||||
kBucketSize: 20
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,8 +67,8 @@ You should see the output being something like:
|
||||
```Bash
|
||||
> node 1.js
|
||||
Found it, multiaddrs are:
|
||||
/ip4/127.0.0.1/tcp/63617/ipfs/QmWrFXvZr9S4iDqycyoyc2zDdrT1jg9wpdenUTdd1LTar6
|
||||
/ip4/192.168.86.41/tcp/63617/ipfs/QmWrFXvZr9S4iDqycyoyc2zDdrT1jg9wpdenUTdd1LTar6
|
||||
/ip4/127.0.0.1/tcp/63617/p2p/QmWrFXvZr9S4iDqycyoyc2zDdrT1jg9wpdenUTdd1LTar6
|
||||
/ip4/192.168.86.41/tcp/63617/p2p/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.
|
||||
|
@ -169,7 +169,7 @@ You can see this working on example [3.js](./3.js). The result should look like
|
||||
> node 3.js
|
||||
from 1 to 2
|
||||
Addresses by which both peers are connected
|
||||
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/ipfs/QmRgormJQeDyXhDKma11eUtksoh8vWmeBoxghVt4meauW9
|
||||
node 1 to node 2: /ip4/127.0.0.1/tcp/50629/p2p/QmZwMKTo6wG4Te9A6M2eJnWDpR8uhsGed4YRegnV5DcKiv
|
||||
node 2 to node 1: /ip4/127.0.0.1/tcp/50630/p2p/QmRgormJQeDyXhDKma11eUtksoh8vWmeBoxghVt4meauW9
|
||||
from 2 to 1
|
||||
```
|
||||
|
@ -62,11 +62,8 @@ parallel([
|
||||
const node1 = nodes[0]
|
||||
const node2 = nodes[1]
|
||||
|
||||
series([
|
||||
(cb) => node1.once('peer:discovery', (peer) => node1.dial(peer, cb)),
|
||||
(cb) => setTimeout(cb, 500)
|
||||
], (err) => {
|
||||
if (err) { throw err }
|
||||
node1.once('peer:connect', (peer) => {
|
||||
console.log('connected to %s', peer.id.toB58String())
|
||||
|
||||
// Subscribe to the topic 'news'
|
||||
node1.pubsub.subscribe('news',
|
||||
|
@ -12,14 +12,11 @@ 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).
|
||||
|
||||
Using PubSub is super simple, all you have to do is start a libp2p node, PubSub will be enabled by default.
|
||||
Using PubSub is super simple, all you have to do is start a libp2p node with `EXPERIMENTAL.pubsub` set to true.
|
||||
|
||||
```JavaScript
|
||||
series([
|
||||
(cb) => node1.once('peer:discovery', (peer) => node1.dial(peer, cb)),
|
||||
(cb) => setTimeout(cb, 500)
|
||||
], (err) => {
|
||||
if (err) { throw err }
|
||||
node1.once('peer:connect', (peer) => {
|
||||
console.log('connected to %s', peer.id.toB58String())
|
||||
|
||||
// Subscribe to the topic 'news'
|
||||
node1.pubsub.subscribe('news',
|
||||
@ -42,6 +39,7 @@ The output of the program should look like:
|
||||
|
||||
```
|
||||
> 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!
|
||||
|
@ -88,8 +88,8 @@ Running this should result in something like:
|
||||
> node 1.js
|
||||
node has started (true/false): true
|
||||
listening on:
|
||||
/ip4/127.0.0.1/tcp/61329/ipfs/QmW2cKTakTYqbQkUzBTEGXgWYFj1YEPeUndE1YWs6CBzDQ
|
||||
/ip4/192.168.2.156/tcp/61329/ipfs/QmW2cKTakTYqbQkUzBTEGXgWYFj1YEPeUndE1YWs6CBzDQ
|
||||
/ip4/127.0.0.1/tcp/61329/p2p/QmW2cKTakTYqbQkUzBTEGXgWYFj1YEPeUndE1YWs6CBzDQ
|
||||
/ip4/192.168.2.156/tcp/61329/p2p/QmW2cKTakTYqbQkUzBTEGXgWYFj1YEPeUndE1YWs6CBzDQ
|
||||
```
|
||||
|
||||
That `QmW2cKTakTYqbQkUzBTEGXgWYFj1YEPeUndE1YWs6CBzDQ` is the PeerId that was created during the PeerInfo generation.
|
||||
@ -175,11 +175,11 @@ The result should be look like:
|
||||
```bash
|
||||
> node 2.js
|
||||
node 1 is listening on:
|
||||
/ip4/127.0.0.1/tcp/62279/ipfs/QmeM4wNWv1uci7UJjUXZYfvcy9uqAbw7G9icuxdqy88Mj9
|
||||
/ip4/192.168.2.156/tcp/62279/ipfs/QmeM4wNWv1uci7UJjUXZYfvcy9uqAbw7G9icuxdqy88Mj9
|
||||
/ip4/127.0.0.1/tcp/62279/p2p/QmeM4wNWv1uci7UJjUXZYfvcy9uqAbw7G9icuxdqy88Mj9
|
||||
/ip4/192.168.2.156/tcp/62279/p2p/QmeM4wNWv1uci7UJjUXZYfvcy9uqAbw7G9icuxdqy88Mj9
|
||||
node 2 is listening on:
|
||||
/ip4/127.0.0.1/tcp/62278/ipfs/QmWp58xJgzbouNJcyiNNTpZuqQCJU8jf6ixc7TZT9xEZhV
|
||||
/ip4/192.168.2.156/tcp/62278/ipfs/QmWp58xJgzbouNJcyiNNTpZuqQCJU8jf6ixc7TZT9xEZhV
|
||||
/ip4/127.0.0.1/tcp/62278/p2p/QmWp58xJgzbouNJcyiNNTpZuqQCJU8jf6ixc7TZT9xEZhV
|
||||
/ip4/192.168.2.156/tcp/62278/p2p/QmWp58xJgzbouNJcyiNNTpZuqQCJU8jf6ixc7TZT9xEZhV
|
||||
Hello p2p world!
|
||||
```
|
||||
|
||||
@ -304,14 +304,14 @@ If everything was set correctly, you now should see the following after you run
|
||||
```Bash
|
||||
> node 3.js
|
||||
node 1 is listening on:
|
||||
/ip4/127.0.0.1/tcp/62620/ipfs/QmWpWmcVJkF6EpmAaVDauku8g1uFGuxPsGP35XZp9GYEqs
|
||||
/ip4/192.168.2.156/tcp/62620/ipfs/QmWpWmcVJkF6EpmAaVDauku8g1uFGuxPsGP35XZp9GYEqs
|
||||
/ip4/127.0.0.1/tcp/62620/p2p/QmWpWmcVJkF6EpmAaVDauku8g1uFGuxPsGP35XZp9GYEqs
|
||||
/ip4/192.168.2.156/tcp/62620/p2p/QmWpWmcVJkF6EpmAaVDauku8g1uFGuxPsGP35XZp9GYEqs
|
||||
node 2 is listening on:
|
||||
/ip4/127.0.0.1/tcp/10000/ws/ipfs/QmWAQtWdzWXibgfyc7WRHhhv6MdqVKzXvyfSTnN2aAvixX
|
||||
/ip4/127.0.0.1/tcp/62619/ipfs/QmWAQtWdzWXibgfyc7WRHhhv6MdqVKzXvyfSTnN2aAvixX
|
||||
/ip4/192.168.2.156/tcp/62619/ipfs/QmWAQtWdzWXibgfyc7WRHhhv6MdqVKzXvyfSTnN2aAvixX
|
||||
/ip4/127.0.0.1/tcp/10000/ws/p2p/QmWAQtWdzWXibgfyc7WRHhhv6MdqVKzXvyfSTnN2aAvixX
|
||||
/ip4/127.0.0.1/tcp/62619/p2p/QmWAQtWdzWXibgfyc7WRHhhv6MdqVKzXvyfSTnN2aAvixX
|
||||
/ip4/192.168.2.156/tcp/62619/p2p/QmWAQtWdzWXibgfyc7WRHhhv6MdqVKzXvyfSTnN2aAvixX
|
||||
node 3 is listening on:
|
||||
/ip4/127.0.0.1/tcp/20000/ws/ipfs/QmVq1PWh3VSDYdFqYMtqp4YQyXcrH27N7968tGdM1VQPj1
|
||||
/ip4/127.0.0.1/tcp/20000/ws/p2p/QmVq1PWh3VSDYdFqYMtqp4YQyXcrH27N7968tGdM1VQPj1
|
||||
node 3 failed to dial to node 1 with: No available transport to dial to
|
||||
node 1 dialed to node 2 successfully
|
||||
node 2 dialed to node 3 successfully
|
||||
|
@ -3,7 +3,7 @@
|
||||
"Package",
|
||||
"Version",
|
||||
"Deps",
|
||||
"CI",
|
||||
"CI/Travis",
|
||||
"Coverage",
|
||||
"Lead Maintainer"
|
||||
],
|
||||
|
111
package.json
111
package.json
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "libp2p",
|
||||
"version": "0.24.0",
|
||||
"description": "JavaScript base class for libp2p bundles",
|
||||
"version": "0.25.4",
|
||||
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
||||
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||
"main": "src/index.js",
|
||||
"files": [
|
||||
@ -16,81 +16,86 @@
|
||||
"test:browser": "aegir test -t browser",
|
||||
"release": "aegir release -t node -t browser",
|
||||
"release-minor": "aegir release --type minor -t node -t browser",
|
||||
"release-major": "aegir release --type major -t node -t browser",
|
||||
"coverage": "aegir coverage",
|
||||
"coverage-publish": "aegir coverage --provider coveralls"
|
||||
"release-major": "aegir release --type major -t node -t browser"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/libp2p/js-libp2p.git"
|
||||
},
|
||||
"keywords": [
|
||||
"libp2p",
|
||||
"network",
|
||||
"p2p",
|
||||
"peer",
|
||||
"peer-to-peer",
|
||||
"IPFS"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=6.0.0",
|
||||
"npm": ">=3.0.0"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/libp2p/js-libp2p/issues"
|
||||
},
|
||||
"homepage": "https://github.com/libp2p/js-libp2p",
|
||||
"homepage": "https://libp2p.io",
|
||||
"license": "MIT",
|
||||
"browser": {
|
||||
"joi": "joi-browser",
|
||||
"./test/utils/bundle-nodejs": "./test/utils/bundle-browser"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0",
|
||||
"npm": ">=6.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "^2.6.1",
|
||||
"debug": "^4.1.0",
|
||||
"async": "^2.6.2",
|
||||
"debug": "^4.1.1",
|
||||
"err-code": "^1.1.2",
|
||||
"fsm-event": "^2.1.0",
|
||||
"joi": "^14.0.6",
|
||||
"joi-browser": "^13.4.0",
|
||||
"libp2p-connection-manager": "~0.0.2",
|
||||
"libp2p-floodsub": "~0.15.1",
|
||||
"libp2p-ping": "~0.8.3",
|
||||
"libp2p-switch": "~0.41.2",
|
||||
"libp2p-websockets": "~0.12.0",
|
||||
"mafmt": "^6.0.2",
|
||||
"multiaddr": "^5.0.2",
|
||||
"peer-book": "~0.8.0",
|
||||
"peer-id": "~0.12.0",
|
||||
"peer-info": "~0.14.1"
|
||||
"libp2p-connection-manager": "^0.1.0",
|
||||
"libp2p-floodsub": "^0.16.1",
|
||||
"libp2p-ping": "^0.8.5",
|
||||
"libp2p-switch": "^0.42.12",
|
||||
"libp2p-websockets": "^0.12.2",
|
||||
"mafmt": "^6.0.7",
|
||||
"multiaddr": "^6.1.0",
|
||||
"once": "^1.4.0",
|
||||
"peer-book": "^0.9.1",
|
||||
"peer-id": "^0.12.2",
|
||||
"peer-info": "^0.15.1",
|
||||
"superstruct": "^0.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nodeutils/defaults-deep": "^1.1.0",
|
||||
"aegir": "^17.0.1",
|
||||
"aegir": "^19.0.3",
|
||||
"chai": "^4.2.0",
|
||||
"chai-checkmark": "^1.0.1",
|
||||
"cids": "~0.5.5",
|
||||
"cids": "^0.7.1",
|
||||
"dirty-chai": "^2.0.1",
|
||||
"electron-webrtc": "~0.3.0",
|
||||
"interface-datastore": "~0.6.0",
|
||||
"libp2p-bootstrap": "~0.9.3",
|
||||
"libp2p-circuit": "~0.3.0",
|
||||
"libp2p-delegated-content-routing": "~0.2.2",
|
||||
"libp2p-delegated-peer-routing": "~0.2.2",
|
||||
"libp2p-kad-dht": "~0.11.1",
|
||||
"libp2p-mdns": "~0.12.0",
|
||||
"libp2p-mplex": "~0.8.4",
|
||||
"libp2p-secio": "~0.10.1",
|
||||
"libp2p-spdy": "~0.13.0",
|
||||
"libp2p-tcp": "~0.13.0",
|
||||
"libp2p-webrtc-star": "~0.15.5",
|
||||
"libp2p-websocket-star": "~0.9.0",
|
||||
"libp2p-websocket-star-rendezvous": "~0.2.4",
|
||||
"electron-webrtc": "^0.3.0",
|
||||
"interface-datastore": "^0.6.0",
|
||||
"libp2p-bootstrap": "^0.9.7",
|
||||
"libp2p-circuit": "^0.3.7",
|
||||
"libp2p-delegated-content-routing": "^0.2.2",
|
||||
"libp2p-delegated-peer-routing": "^0.2.2",
|
||||
"libp2p-kad-dht": "^0.15.2",
|
||||
"libp2p-mdns": "^0.12.3",
|
||||
"libp2p-mplex": "^0.8.4",
|
||||
"libp2p-secio": "^0.11.1",
|
||||
"libp2p-spdy": "^0.13.2",
|
||||
"libp2p-tcp": "^0.13.0",
|
||||
"libp2p-webrtc-star": "^0.16.1",
|
||||
"libp2p-websocket-star": "~0.10.2",
|
||||
"libp2p-websocket-star-rendezvous": "~0.3.0",
|
||||
"lodash.times": "^4.3.2",
|
||||
"nock": "^10.0.2",
|
||||
"nock": "^10.0.6",
|
||||
"pull-goodbye": "0.0.2",
|
||||
"pull-serializer": "~0.3.2",
|
||||
"pull-stream": "^3.6.9",
|
||||
"sinon": "^7.1.1",
|
||||
"webrtcsupport": "^2.2.0",
|
||||
"wrtc": "~0.3.2"
|
||||
"pull-mplex": "^0.1.2",
|
||||
"pull-serializer": "^0.3.2",
|
||||
"pull-stream": "^3.6.12",
|
||||
"sinon": "^7.2.7",
|
||||
"wrtc": "^0.4.1"
|
||||
},
|
||||
"contributors": [
|
||||
"Aditya Bose <13054902+adbose@users.noreply.github.com>",
|
||||
"Alan Shaw <alan.shaw@protocol.ai>",
|
||||
"Alan Shaw <alan@tableflip.io>",
|
||||
"Andrew Nesbitt <andrewnez@gmail.com>",
|
||||
"Chris Bratlien <chrisbratlien@gmail.com>",
|
||||
"Chris Dostert <chrisdostert@users.noreply.github.com>",
|
||||
"Daijiro Wachi <daijiro.wachi@gmail.com>",
|
||||
@ -101,7 +106,9 @@
|
||||
"Florian-Merle <florian.david.merle@gmail.com>",
|
||||
"Friedel Ziegelmayer <dignifiedquire@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>",
|
||||
"Irakli Gozalishvili <rfobic@gmail.com>",
|
||||
"Jacob Heun <jacobheun@gmail.com>",
|
||||
@ -111,19 +118,25 @@
|
||||
"Kevin Kwok <antimatter15@gmail.com>",
|
||||
"Lars Gierth <lgierth@users.noreply.github.com>",
|
||||
"Maciej Krüger <mkg20001@gmail.com>",
|
||||
"Marcin Tojek <mtojek@users.noreply.github.com>",
|
||||
"Nuno Nogueira <nunofmn@gmail.com>",
|
||||
"Pedro Teixeira <pedro@protocol.ai>",
|
||||
"Pedro Teixeira <i@pgte.me>",
|
||||
"RasmusErik Voel Jensen <github@solsort.com>",
|
||||
"Richard Littauer <richard.littauer@gmail.com>",
|
||||
"Ryan Bell <ryan@piing.net>",
|
||||
"Soeren <nikorpoulsen@gmail.com>",
|
||||
"Sönke Hahn <soenkehahn@gmail.com>",
|
||||
"Thomas Eizinger <thomas@eizinger.io>",
|
||||
"Tiago Alves <alvesjtiago@gmail.com>",
|
||||
"Vasco Santos <vasco.santos@ua.pt>",
|
||||
"Vasco Santos <vasco.santos@moxy.studio>",
|
||||
"Volker Mische <volker.mische@gmail.com>",
|
||||
"Yusef Napora <yusef@napora.org>",
|
||||
"Zane Starr <zcstarr@gmail.com>",
|
||||
"ebinks <elizabethjbinks@gmail.com>",
|
||||
"greenkeeperio-bot <support@greenkeeper.io>",
|
||||
"isan_rivkin <isanrivkin@gmail.com>",
|
||||
"mayerwin <mayerwin@users.noreply.github.com>",
|
||||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>"
|
||||
]
|
||||
|
@ -59,7 +59,7 @@ test('story 1 - peerA', (t) => {
|
||||
t.ifErr(err, 'created Node successfully')
|
||||
t.ok(node.isStarted(), 'PeerA is Running')
|
||||
|
||||
const peerBAddr = `/ip4/127.0.0.1/tcp/10001/ipfs/${PeerB.id}`
|
||||
const peerBAddr = `/ip4/127.0.0.1/tcp/10001/p2p/${PeerB.id}`
|
||||
|
||||
node.handle('/time/1.0.0', (protocol, conn) => {
|
||||
pull(
|
||||
|
@ -59,7 +59,7 @@ test('story 1 - peerA', (t) => {
|
||||
t.ifErr(err, 'created Node successfully')
|
||||
t.ok(node.isStarted(), 'PeerB is Running')
|
||||
|
||||
const peerAAddr = `/ip4/127.0.0.1/tcp/10000/ipfs/${PeerA.id}`
|
||||
const peerAAddr = `/ip4/127.0.0.1/tcp/10000/p2p/${PeerA.id}`
|
||||
|
||||
node.handle('/echo/1.0.0', (protocol, conn) => {
|
||||
pull(
|
||||
|
@ -33,7 +33,7 @@ test('story 1 - peerA', (t) => {
|
||||
t.ifErr(err, 'created Node')
|
||||
t.ok(node.isStarted(), 'PeerA is running')
|
||||
|
||||
const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/ipfs/${PeerB.id}`
|
||||
const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/p2p/${PeerB.id}`
|
||||
|
||||
node.dial(PeerBAddr, '/echo/1.0.0', (err, conn) => {
|
||||
t.ifErr(err, 'dial successful')
|
||||
|
@ -33,7 +33,7 @@ test('story 2 - peerA', (t) => {
|
||||
t.ifErr(err, 'created Node')
|
||||
t.ok(node.isStarted(), 'PeerA is running')
|
||||
|
||||
const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/ws/ipfs/${PeerB.id}`
|
||||
const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/p2p/${PeerB.id}`
|
||||
|
||||
node.dial(PeerBAddr, '/echo/1.0.0', (err, conn) => {
|
||||
t.ifErr(err, 'dial successful')
|
||||
|
@ -32,7 +32,7 @@ test('story 3 - peerA', (t) => {
|
||||
t.ifErr(err, 'created Node')
|
||||
t.ok(node.isStarted(), 'PeerA is running')
|
||||
|
||||
const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/ws/ipfs/${PeerB.id}`
|
||||
const PeerBAddr = `/ip4/127.0.0.1/tcp/10001/ws/p2p/${PeerB.id}`
|
||||
|
||||
setTimeout(() => node.dial(PeerBAddr, '/echo/1.0.0', (err, conn) => {
|
||||
t.ok(err, 'dial failed')
|
||||
|
@ -32,7 +32,7 @@ test('story 3 - peerB', (t) => {
|
||||
t.ifErr(err, 'created Node')
|
||||
t.ok(node.isStarted(), 'PeerA is running')
|
||||
|
||||
const PeerAAddr = `/ip4/127.0.0.1/tcp/10000/ws/ipfs/${PeerA.id}`
|
||||
const PeerAAddr = `/ip4/127.0.0.1/tcp/10000/ws/p2p/${PeerA.id}`
|
||||
|
||||
setTimeout(() => node.dial(PeerAAddr, '/echo/1.0.0', (err, conn) => {
|
||||
t.ok(err, 'dial failed')
|
||||
|
135
src/config.js
135
src/config.js
@ -1,53 +1,100 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const { struct, superstruct } = require('superstruct')
|
||||
const { optional, list } = struct
|
||||
|
||||
const ModuleSchema = Joi.alternatives().try(Joi.func(), Joi.object())
|
||||
|
||||
const OptionsSchema = Joi.object({
|
||||
// TODO: create proper validators for the generics
|
||||
connectionManager: Joi.object(),
|
||||
datastore: Joi.object(),
|
||||
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)
|
||||
}),
|
||||
EXPERIMENTAL: Joi.object().keys({
|
||||
dht: Joi.boolean().default(false),
|
||||
pubsub: Joi.boolean().default(false)
|
||||
}).default()
|
||||
}).default()
|
||||
// Define custom types
|
||||
const s = superstruct()
|
||||
const transport = s.union([
|
||||
s.interface({
|
||||
createListener: 'function',
|
||||
dial: 'function'
|
||||
}),
|
||||
'function'
|
||||
])
|
||||
const modulesSchema = s({
|
||||
connEncryption: optional(list([s('object|function')])),
|
||||
// this is hacky to simulate optional because interface doesnt work correctly with it
|
||||
// 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'
|
||||
}
|
||||
})])
|
||||
})
|
||||
|
||||
module.exports.validate = (options) => {
|
||||
options = Joi.attempt(options, OptionsSchema)
|
||||
const configSchema = s({
|
||||
peerDiscovery: s('object', {
|
||||
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
|
||||
})
|
||||
}, {})
|
||||
|
||||
// Ensure dht is correct
|
||||
if (options.config.EXPERIMENTAL.dht) {
|
||||
Joi.assert(options.modules.dht, ModuleSchema.required())
|
||||
const optionsSchema = s({
|
||||
switch: 'object?',
|
||||
connectionManager: s('object', {
|
||||
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
|
||||
|
11
src/dht.js
11
src/dht.js
@ -1,10 +1,15 @@
|
||||
'use strict'
|
||||
|
||||
const nextTick = require('async/nextTick')
|
||||
const errCode = require('err-code')
|
||||
|
||||
const { messages, codes } = require('./errors')
|
||||
|
||||
module.exports = (node) => {
|
||||
return {
|
||||
put: (key, value, callback) => {
|
||||
if (!node._dht) {
|
||||
return callback(new Error('DHT is not available'))
|
||||
return nextTick(callback, errCode(new Error(messages.DHT_DISABLED), codes.DHT_DISABLED))
|
||||
}
|
||||
|
||||
node._dht.put(key, value, callback)
|
||||
@ -16,7 +21,7 @@ module.exports = (node) => {
|
||||
}
|
||||
|
||||
if (!node._dht) {
|
||||
return callback(new Error('DHT is not available'))
|
||||
return nextTick(callback, errCode(new Error(messages.DHT_DISABLED), codes.DHT_DISABLED))
|
||||
}
|
||||
|
||||
node._dht.get(key, options, callback)
|
||||
@ -28,7 +33,7 @@ module.exports = (node) => {
|
||||
}
|
||||
|
||||
if (!node._dht) {
|
||||
return callback(new Error('DHT is not available'))
|
||||
return nextTick(callback, errCode(new Error(messages.DHT_DISABLED), codes.DHT_DISABLED))
|
||||
}
|
||||
|
||||
node._dht.getMany(key, nVals, options, callback)
|
||||
|
@ -1,3 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
exports.NOT_STARTED_YET = 'The libp2p node is not started yet'
|
13
src/errors.js
Normal file
13
src/errors.js
Normal file
@ -0,0 +1,13 @@
|
||||
'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'
|
||||
}
|
321
src/index.js
321
src/index.js
@ -2,61 +2,69 @@
|
||||
|
||||
const FSM = require('fsm-event')
|
||||
const EventEmitter = require('events').EventEmitter
|
||||
const assert = require('assert')
|
||||
const debug = require('debug')
|
||||
const log = debug('libp2p')
|
||||
log.error = debug('libp2p:error')
|
||||
const errCode = require('err-code')
|
||||
|
||||
const each = require('async/each')
|
||||
const series = require('async/series')
|
||||
const parallel = require('async/parallel')
|
||||
const nextTick = require('async/nextTick')
|
||||
|
||||
const PeerBook = require('peer-book')
|
||||
const PeerInfo = require('peer-info')
|
||||
const Switch = require('libp2p-switch')
|
||||
const Ping = require('libp2p-ping')
|
||||
const WebSockets = require('libp2p-websockets')
|
||||
const ConnectionManager = require('libp2p-connection-manager')
|
||||
|
||||
const { emitFirst } = require('./util')
|
||||
const peerRouting = require('./peer-routing')
|
||||
const contentRouting = require('./content-routing')
|
||||
const dht = require('./dht')
|
||||
const pubsub = require('./pubsub')
|
||||
const getPeerInfo = require('./get-peer-info')
|
||||
const validateConfig = require('./config').validate
|
||||
const { codes } = require('./errors')
|
||||
|
||||
const NOT_STARTED_ERROR_MESSAGE = 'The libp2p node is not started yet'
|
||||
const notStarted = (action, state) => {
|
||||
return errCode(
|
||||
new Error(`libp2p cannot ${action} when not started; state is ${state}`),
|
||||
codes.ERR_NODE_NOT_STARTED
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @fires Node#error Emitted when an error occurs
|
||||
* @fires Node#peer:connect Emitted when a peer is connected to this node
|
||||
* @fires Node#peer:disconnect Emitted when a peer disconnects from this node
|
||||
* @fires Node#peer:discovery Emitted when a peer is discovered
|
||||
* @fires Node#start Emitted when the node and its services has started
|
||||
* @fires Node#stop Emitted when the node and its services has stopped
|
||||
* @fires Libp2p#error Emitted when an error occurs
|
||||
* @fires Libp2p#peer:connect Emitted when a peer is connected to this node
|
||||
* @fires Libp2p#peer:disconnect Emitted when a peer disconnects from this node
|
||||
* @fires Libp2p#peer:discovery Emitted when a peer is discovered
|
||||
* @fires Libp2p#start Emitted when the node and its services has started
|
||||
* @fires Libp2p#stop Emitted when the node and its services has stopped
|
||||
*/
|
||||
class Node extends EventEmitter {
|
||||
class Libp2p extends EventEmitter {
|
||||
constructor (_options) {
|
||||
super()
|
||||
// validateConfig will ensure the config is correct,
|
||||
// and add default values where appropriate
|
||||
_options = validateConfig(_options)
|
||||
this._options = validateConfig(_options)
|
||||
|
||||
this.datastore = _options.datastore
|
||||
this.peerInfo = _options.peerInfo
|
||||
this.peerBook = _options.peerBook || new PeerBook()
|
||||
this.datastore = this._options.datastore
|
||||
this.peerInfo = this._options.peerInfo
|
||||
this.peerBook = this._options.peerBook || new PeerBook()
|
||||
|
||||
this._modules = _options.modules
|
||||
this._config = _options.config
|
||||
this._isStarted = false
|
||||
this._modules = this._options.modules
|
||||
this._config = this._options.config
|
||||
this._transport = [] // Transport 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.connectionManager = new ConnectionManager(this, _options.connectionManager)
|
||||
this.connectionManager = new ConnectionManager(this, this._options.connectionManager)
|
||||
|
||||
// Attach stream multiplexers
|
||||
if (this._modules.streamMuxer) {
|
||||
@ -73,7 +81,6 @@ class Node extends EventEmitter {
|
||||
// reuse this muxed connection
|
||||
this._switch.on('peer-mux-established', (peerInfo) => {
|
||||
this.emit('peer:connect', peerInfo)
|
||||
this.peerBook.put(peerInfo)
|
||||
})
|
||||
|
||||
this._switch.on('peer-mux-closed', (peerInfo) => {
|
||||
@ -81,6 +88,14 @@ class Node 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
|
||||
if (this._modules.connEncryption) {
|
||||
let cryptos = this._modules.connEncryption
|
||||
@ -97,14 +112,12 @@ class Node extends EventEmitter {
|
||||
}
|
||||
|
||||
// dht provided components (peerRouting, contentRouting, dht)
|
||||
if (this._config.EXPERIMENTAL.dht) {
|
||||
if (this._config.dht.enabled) {
|
||||
const DHT = this._modules.dht
|
||||
const enabledDiscovery = this._config.dht.enabledDiscovery !== false
|
||||
|
||||
this._dht = new DHT(this._switch, {
|
||||
kBucketSize: this._config.dht.kBucketSize || 20,
|
||||
enabledDiscovery,
|
||||
datastore: this.datastore
|
||||
datastore: this.datastore,
|
||||
...this._config.dht
|
||||
})
|
||||
}
|
||||
|
||||
@ -163,6 +176,16 @@ class Node extends EventEmitter {
|
||||
log.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)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,7 +210,7 @@ class Node extends EventEmitter {
|
||||
* @returns {void}
|
||||
*/
|
||||
start (callback = () => {}) {
|
||||
this.once('start', callback)
|
||||
emitFirst(this, ['error', 'start'], callback)
|
||||
this.state('start')
|
||||
}
|
||||
|
||||
@ -198,7 +221,7 @@ class Node extends EventEmitter {
|
||||
* @returns {void}
|
||||
*/
|
||||
stop (callback = () => {}) {
|
||||
this.once('stop', callback)
|
||||
emitFirst(this, ['error', 'stop'], callback)
|
||||
this.state('stop')
|
||||
}
|
||||
|
||||
@ -215,8 +238,6 @@ class Node extends EventEmitter {
|
||||
* @returns {void}
|
||||
*/
|
||||
dial (peer, callback) {
|
||||
assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE)
|
||||
|
||||
this.dialProtocol(peer, null, callback)
|
||||
}
|
||||
|
||||
@ -231,7 +252,9 @@ class Node extends EventEmitter {
|
||||
* @returns {void}
|
||||
*/
|
||||
dialProtocol (peer, protocol, callback) {
|
||||
assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE)
|
||||
if (!this.isStarted()) {
|
||||
return callback(notStarted('dial', this.state._state))
|
||||
}
|
||||
|
||||
if (typeof protocol === 'function') {
|
||||
callback = protocol
|
||||
@ -241,11 +264,7 @@ class Node extends EventEmitter {
|
||||
this._getPeerInfo(peer, (err, peerInfo) => {
|
||||
if (err) { return callback(err) }
|
||||
|
||||
this._switch.dial(peerInfo, protocol, (err, conn) => {
|
||||
if (err) { return callback(err) }
|
||||
this.peerBook.put(peerInfo)
|
||||
callback(null, conn)
|
||||
})
|
||||
this._switch.dial(peerInfo, protocol, callback)
|
||||
})
|
||||
}
|
||||
|
||||
@ -259,7 +278,9 @@ class Node extends EventEmitter {
|
||||
* @returns {void}
|
||||
*/
|
||||
dialFSM (peer, protocol, callback) {
|
||||
assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE)
|
||||
if (!this.isStarted()) {
|
||||
return callback(notStarted('dial', this.state._state))
|
||||
}
|
||||
|
||||
if (typeof protocol === 'function') {
|
||||
callback = protocol
|
||||
@ -269,19 +290,11 @@ class Node extends EventEmitter {
|
||||
this._getPeerInfo(peer, (err, peerInfo) => {
|
||||
if (err) { return callback(err) }
|
||||
|
||||
const connFSM = this._switch.dialFSM(peerInfo, protocol, (err) => {
|
||||
if (!err) {
|
||||
this.peerBook.put(peerInfo)
|
||||
}
|
||||
})
|
||||
|
||||
callback(null, connFSM)
|
||||
this._switch.dialFSM(peerInfo, protocol, callback)
|
||||
})
|
||||
}
|
||||
|
||||
hangUp (peer, callback) {
|
||||
assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE)
|
||||
|
||||
this._getPeerInfo(peer, (err, peerInfo) => {
|
||||
if (err) { return callback(err) }
|
||||
|
||||
@ -291,7 +304,7 @@ class Node extends EventEmitter {
|
||||
|
||||
ping (peer, callback) {
|
||||
if (!this.isStarted()) {
|
||||
return callback(new Error(NOT_STARTED_ERROR_MESSAGE))
|
||||
return callback(notStarted('ping', this.state._state))
|
||||
}
|
||||
|
||||
this._getPeerInfo(peer, (err, peerInfo) => {
|
||||
@ -323,7 +336,7 @@ class Node extends EventEmitter {
|
||||
this.peerInfo.multiaddrs.toArray().forEach((ma) => {
|
||||
if (!ma.getPeerId()) {
|
||||
maOld.push(ma)
|
||||
maNew.push(ma.encapsulate('/ipfs/' + this.peerInfo.id.toB58String()))
|
||||
maNew.push(ma.encapsulate('/p2p/' + this.peerInfo.id.toB58String()))
|
||||
}
|
||||
})
|
||||
this.peerInfo.multiaddrs.replace(maOld, maNew)
|
||||
@ -334,13 +347,13 @@ class Node extends EventEmitter {
|
||||
let t
|
||||
|
||||
if (typeof Transport === 'function') {
|
||||
t = new Transport()
|
||||
t = new Transport({ libp2p: this })
|
||||
} else {
|
||||
t = Transport
|
||||
}
|
||||
|
||||
if (t.filter(multiaddrs).length > 0) {
|
||||
this._switch.transport.add(t.tag || t.constructor.name, t)
|
||||
this._switch.transport.add(t.tag || t[Symbol.toStringTag], t)
|
||||
} else if (WebSockets.isWebSockets(t)) {
|
||||
// TODO find a cleaner way to signal that a transport is always used
|
||||
// for dialing, even if no listener
|
||||
@ -360,60 +373,6 @@ class Node extends EventEmitter {
|
||||
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
|
||||
const multiaddrs = this.peerInfo.multiaddrs.toArray()
|
||||
|
||||
@ -424,6 +383,30 @@ class Node extends EventEmitter {
|
||||
}
|
||||
})
|
||||
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) => {
|
||||
if (err) {
|
||||
@ -438,16 +421,17 @@ class Node extends EventEmitter {
|
||||
_onStopping () {
|
||||
series([
|
||||
(cb) => {
|
||||
if (this._modules.peerDiscovery) {
|
||||
// stop all discoveries before continuing with shutdown
|
||||
return parallel(
|
||||
this._discovery.map((d) => {
|
||||
return (_cb) => d.stop(() => { _cb() })
|
||||
}),
|
||||
cb
|
||||
)
|
||||
}
|
||||
cb()
|
||||
// stop all discoveries before continuing with shutdown
|
||||
parallel(
|
||||
this._discovery.map((d) => {
|
||||
d.removeListener('peer', this._peerDiscovered)
|
||||
return (_cb) => d.stop((err) => {
|
||||
log.error('an error occurred stopping the discovery service', err)
|
||||
_cb()
|
||||
})
|
||||
}),
|
||||
cb
|
||||
)
|
||||
},
|
||||
(cb) => {
|
||||
if (this._floodSub) {
|
||||
@ -457,17 +441,19 @@ class Node extends EventEmitter {
|
||||
},
|
||||
(cb) => {
|
||||
if (this._dht) {
|
||||
this._dht.removeListener('peer', this._peerDiscovered)
|
||||
return this._dht.stop(cb)
|
||||
}
|
||||
cb()
|
||||
},
|
||||
(cb) => {
|
||||
// Ensures idempotency for restarts
|
||||
this._switch.transport.removeAll(cb)
|
||||
},
|
||||
(cb) => {
|
||||
this.connectionManager.stop()
|
||||
this._switch.stop(cb)
|
||||
},
|
||||
(cb) => {
|
||||
// Ensures idempotent restarts, ignore any errors
|
||||
// from removeAll, they're not useful at this point
|
||||
this._switch.transport.removeAll(() => cb())
|
||||
}
|
||||
], (err) => {
|
||||
if (err) {
|
||||
@ -477,6 +463,107 @@ class Node extends EventEmitter {
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = Node
|
||||
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))
|
||||
})
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
'use strict'
|
||||
|
||||
const setImmediate = require('async/setImmediate')
|
||||
const NOT_STARTED_YET = require('./error-messages').NOT_STARTED_YET
|
||||
const nextTick = require('async/nextTick')
|
||||
const { messages, codes } = require('./errors')
|
||||
const FloodSub = require('libp2p-floodsub')
|
||||
|
||||
const errCode = require('err-code')
|
||||
|
||||
module.exports = (node) => {
|
||||
const floodSub = new FloodSub(node)
|
||||
|
||||
@ -18,7 +20,7 @@ module.exports = (node) => {
|
||||
}
|
||||
|
||||
if (!node.isStarted() && !floodSub.started) {
|
||||
return setImmediate(() => callback(new Error(NOT_STARTED_YET)))
|
||||
return nextTick(callback, errCode(new Error(messages.NOT_STARTED_YET), codes.PUBSUB_NOT_STARTED))
|
||||
}
|
||||
|
||||
function subscribe (cb) {
|
||||
@ -27,51 +29,56 @@ module.exports = (node) => {
|
||||
}
|
||||
|
||||
floodSub.on(topic, handler)
|
||||
setImmediate(cb)
|
||||
nextTick(cb)
|
||||
}
|
||||
|
||||
subscribe(callback)
|
||||
},
|
||||
|
||||
unsubscribe: (topic, handler) => {
|
||||
unsubscribe: (topic, handler, callback) => {
|
||||
if (!node.isStarted() && !floodSub.started) {
|
||||
throw new Error(NOT_STARTED_YET)
|
||||
return nextTick(callback, errCode(new Error(messages.NOT_STARTED_YET), codes.PUBSUB_NOT_STARTED))
|
||||
}
|
||||
if (!handler && !callback) {
|
||||
floodSub.removeAllListeners(topic)
|
||||
} else {
|
||||
floodSub.removeListener(topic, handler)
|
||||
}
|
||||
|
||||
floodSub.removeListener(topic, handler)
|
||||
|
||||
if (floodSub.listenerCount(topic) === 0) {
|
||||
floodSub.unsubscribe(topic)
|
||||
}
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
nextTick(() => callback())
|
||||
}
|
||||
},
|
||||
|
||||
publish: (topic, data, callback) => {
|
||||
if (!node.isStarted() && !floodSub.started) {
|
||||
return setImmediate(() => callback(new Error(NOT_STARTED_YET)))
|
||||
return nextTick(callback, errCode(new Error(messages.NOT_STARTED_YET), codes.PUBSUB_NOT_STARTED))
|
||||
}
|
||||
|
||||
if (!Buffer.isBuffer(data)) {
|
||||
return setImmediate(() => callback(new Error('data must be a Buffer')))
|
||||
return nextTick(callback, errCode(new Error('data must be a Buffer'), 'ERR_DATA_IS_NOT_A_BUFFER'))
|
||||
}
|
||||
|
||||
floodSub.publish(topic, data)
|
||||
|
||||
setImmediate(() => callback())
|
||||
floodSub.publish(topic, data, callback)
|
||||
},
|
||||
|
||||
ls: (callback) => {
|
||||
if (!node.isStarted() && !floodSub.started) {
|
||||
return setImmediate(() => callback(new Error(NOT_STARTED_YET)))
|
||||
return nextTick(callback, errCode(new Error(messages.NOT_STARTED_YET), codes.PUBSUB_NOT_STARTED))
|
||||
}
|
||||
|
||||
const subscriptions = Array.from(floodSub.subscriptions)
|
||||
|
||||
setImmediate(() => callback(null, subscriptions))
|
||||
nextTick(() => callback(null, subscriptions))
|
||||
},
|
||||
|
||||
peers: (topic, callback) => {
|
||||
if (!node.isStarted() && !floodSub.started) {
|
||||
return setImmediate(() => callback(new Error(NOT_STARTED_YET)))
|
||||
return nextTick(callback, errCode(new Error(messages.NOT_STARTED_YET), codes.PUBSUB_NOT_STARTED))
|
||||
}
|
||||
|
||||
if (typeof topic === 'function') {
|
||||
@ -83,7 +90,7 @@ module.exports = (node) => {
|
||||
.filter((peer) => topic ? peer.topics.has(topic) : true)
|
||||
.map((peer) => peer.info.id.toB58String())
|
||||
|
||||
setImmediate(() => callback(null, peers))
|
||||
nextTick(() => callback(null, peers))
|
||||
},
|
||||
|
||||
setMaxListeners (n) {
|
||||
|
33
src/util/index.js
Normal file
33
src/util/index.js
Normal file
@ -0,0 +1,33 @@
|
||||
'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
|
@ -1,3 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
require('./circuit-relay.browser')
|
||||
require('./transports.browser')
|
||||
|
98
test/circuit-relay.browser.js
Normal file
98
test/circuit-relay.browser.js
Normal file
@ -0,0 +1,98 @@
|
||||
/* 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)
|
||||
})
|
||||
})
|
||||
})
|
@ -114,10 +114,9 @@ describe('circuit relay', () => {
|
||||
nodeWS2 = node
|
||||
cb()
|
||||
}),
|
||||
// set up node with TCP and listening on relay1
|
||||
// set up node with TCP
|
||||
(cb) => setupNode([
|
||||
'/ip4/0.0.0.0/tcp/0',
|
||||
`/ipfs/${relayNode1.peerInfo.id.toB58String()}/p2p-circuit`
|
||||
'/ip4/0.0.0.0/tcp/0'
|
||||
], {
|
||||
config: {
|
||||
relay: {
|
||||
@ -128,10 +127,9 @@ describe('circuit relay', () => {
|
||||
nodeTCP1 = node
|
||||
cb()
|
||||
}),
|
||||
// set up node with TCP and listening on relay2 over TCP transport
|
||||
// set up node with TCP
|
||||
(cb) => setupNode([
|
||||
'/ip4/0.0.0.0/tcp/0',
|
||||
`/ip4/0.0.0.0/tcp/0/ipfs/${relayNode2.peerInfo.id.toB58String()}/p2p-circuit`
|
||||
'/ip4/0.0.0.0/tcp/0'
|
||||
], {
|
||||
config: {
|
||||
relay: {
|
||||
|
@ -11,6 +11,7 @@ const WS = require('libp2p-websockets')
|
||||
const Bootstrap = require('libp2p-bootstrap')
|
||||
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
|
||||
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
|
||||
const DHT = require('libp2p-kad-dht')
|
||||
|
||||
const validateConfig = require('../src/config').validate
|
||||
|
||||
@ -54,7 +55,57 @@ describe('configuration', () => {
|
||||
transport: [ ]
|
||||
}
|
||||
})
|
||||
}).to.throw()
|
||||
}).to.throw('ERROR_EMPTY')
|
||||
})
|
||||
|
||||
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', () => {
|
||||
@ -62,7 +113,8 @@ describe('configuration', () => {
|
||||
peerInfo,
|
||||
modules: {
|
||||
transport: [ WS ],
|
||||
peerDiscovery: [ Bootstrap ]
|
||||
peerDiscovery: [ Bootstrap ],
|
||||
dht: DHT
|
||||
},
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
@ -76,23 +128,41 @@ describe('configuration', () => {
|
||||
|
||||
const expected = {
|
||||
peerInfo,
|
||||
connectionManager: {
|
||||
minPeers: 25
|
||||
},
|
||||
modules: {
|
||||
transport: [ WS ],
|
||||
peerDiscovery: [ Bootstrap ]
|
||||
peerDiscovery: [ Bootstrap ],
|
||||
dht: DHT
|
||||
},
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
autoDial: true,
|
||||
bootstrap: {
|
||||
interval: 1000,
|
||||
enabled: true
|
||||
}
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
pubsub: false,
|
||||
dht: false
|
||||
pubsub: false
|
||||
},
|
||||
dht: {
|
||||
kBucketSize: 20,
|
||||
enabled: false,
|
||||
randomWalk: {
|
||||
enabled: false,
|
||||
queriesPerPeriod: 1,
|
||||
interval: 300000,
|
||||
timeout: 10000
|
||||
}
|
||||
},
|
||||
relay: {
|
||||
enabled: true
|
||||
enabled: true,
|
||||
hop: {
|
||||
active: false,
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,6 +170,33 @@ describe('configuration', () => {
|
||||
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', () => {
|
||||
const peerRouter = new DelegatedPeerRouter()
|
||||
const contentRouter = new DelegatedContentRouter(peerInfo)
|
||||
@ -110,7 +207,8 @@ describe('configuration', () => {
|
||||
transport: [ WS ],
|
||||
peerDiscovery: [ Bootstrap ],
|
||||
peerRouting: [ peerRouter ],
|
||||
contentRouting: [ contentRouter ]
|
||||
contentRouting: [ contentRouter ],
|
||||
dht: DHT
|
||||
},
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
@ -135,12 +233,100 @@ describe('configuration', () => {
|
||||
transport: [ WS ]
|
||||
},
|
||||
config: {
|
||||
EXPERIMENTAL: {
|
||||
dht: true
|
||||
dht: {
|
||||
enabled: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
@ -30,13 +30,7 @@ describe('.contentRouting', () => {
|
||||
before(function (done) {
|
||||
this.timeout(5 * 1000)
|
||||
const tasks = _times(5, () => (cb) => {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||
config: {
|
||||
EXPERIMENTAL: {
|
||||
dht: true
|
||||
}
|
||||
}
|
||||
}, (err, node) => {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', (err, node) => {
|
||||
expect(err).to.not.exist()
|
||||
node.start((err) => cb(err, node))
|
||||
})
|
||||
@ -159,6 +153,9 @@ describe('.contentRouting', () => {
|
||||
contentRouting: [ delegate ]
|
||||
},
|
||||
config: {
|
||||
dht: {
|
||||
enabled: false
|
||||
},
|
||||
relay: {
|
||||
enabled: true,
|
||||
hop: {
|
||||
@ -320,9 +317,6 @@ describe('.contentRouting', () => {
|
||||
enabled: true,
|
||||
active: false
|
||||
}
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
dht: true
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -387,7 +381,13 @@ describe('.contentRouting', () => {
|
||||
describe('no routers', () => {
|
||||
let nodeA
|
||||
before((done) => {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', (err, node) => {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||
config: {
|
||||
dht: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
}, (err, node) => {
|
||||
expect(err).to.not.exist()
|
||||
nodeA = node
|
||||
done()
|
||||
|
@ -7,14 +7,23 @@ const expect = chai.expect
|
||||
const series = require('async/series')
|
||||
const createNode = require('./utils/create-node')
|
||||
const sinon = require('sinon')
|
||||
const { createLibp2p } = require('../src')
|
||||
const WS = require('libp2p-websockets')
|
||||
const PeerInfo = require('peer-info')
|
||||
|
||||
describe('libp2p creation', () => {
|
||||
afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
it('should be able to start and stop successfully', (done) => {
|
||||
createNode([], {
|
||||
config: {
|
||||
EXPERIMENTAL: {
|
||||
dht: true,
|
||||
pubsub: true
|
||||
},
|
||||
dht: {
|
||||
enabled: true
|
||||
}
|
||||
}
|
||||
}, (err, node) => {
|
||||
@ -69,13 +78,11 @@ describe('libp2p creation', () => {
|
||||
createNode([], {
|
||||
config: {
|
||||
EXPERIMENTAL: {
|
||||
dht: false,
|
||||
pubsub: false
|
||||
}
|
||||
}
|
||||
}, (err, node) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(node._dht).to.not.exist()
|
||||
expect(node._floodSub).to.not.exist()
|
||||
done()
|
||||
})
|
||||
@ -101,4 +108,36 @@ describe('libp2p creation', () => {
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -17,12 +17,7 @@ describe('.dht', () => {
|
||||
|
||||
before(function (done) {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||
datastore,
|
||||
config: {
|
||||
EXPERIMENTAL: {
|
||||
dht: true
|
||||
}
|
||||
}
|
||||
datastore
|
||||
}, (err, node) => {
|
||||
expect(err).to.not.exist()
|
||||
nodeA = node
|
||||
@ -124,8 +119,8 @@ describe('.dht', () => {
|
||||
before(function (done) {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||
config: {
|
||||
EXPERIMENTAL: {
|
||||
dht: false
|
||||
dht: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
}, (err, node) => {
|
||||
@ -145,6 +140,7 @@ describe('.dht', () => {
|
||||
|
||||
nodeA.dht.put(key, value, (err) => {
|
||||
expect(err).to.exist()
|
||||
expect(err.code).to.equal('ERR_DHT_DISABLED')
|
||||
done()
|
||||
})
|
||||
})
|
||||
@ -154,6 +150,7 @@ describe('.dht', () => {
|
||||
|
||||
nodeA.dht.get(key, (err) => {
|
||||
expect(err).to.exist()
|
||||
expect(err.code).to.equal('ERR_DHT_DISABLED')
|
||||
done()
|
||||
})
|
||||
})
|
||||
@ -163,6 +160,7 @@ describe('.dht', () => {
|
||||
|
||||
nodeA.dht.getMany(key, 10, (err) => {
|
||||
expect(err).to.exist()
|
||||
expect(err.code).to.equal('ERR_DHT_DISABLED')
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
@ -13,13 +13,20 @@ describe('libp2p state machine (fsm)', () => {
|
||||
describe('starting and stopping', () => {
|
||||
let node
|
||||
beforeEach((done) => {
|
||||
createNode([], (err, _node) => {
|
||||
createNode([], {
|
||||
config: {
|
||||
dht: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
}, (err, _node) => {
|
||||
node = _node
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
afterEach(() => {
|
||||
node.removeAllListeners()
|
||||
sinon.restore()
|
||||
})
|
||||
after((done) => {
|
||||
node.stop(done)
|
||||
@ -58,6 +65,23 @@ describe('libp2p state machine (fsm)', () => {
|
||||
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) => {
|
||||
node.once('start', () => {
|
||||
node.state.on('STARTING', () => {
|
||||
@ -110,9 +134,35 @@ describe('libp2p state machine (fsm)', () => {
|
||||
throw new Error('should not start')
|
||||
})
|
||||
|
||||
expect(2).checks(done)
|
||||
expect(3).checks(done)
|
||||
|
||||
node.start()
|
||||
node.start((err) => {
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -5,33 +5,24 @@ const chai = require('chai')
|
||||
chai.use(require('dirty-chai'))
|
||||
const expect = chai.expect
|
||||
const sinon = require('sinon')
|
||||
const signalling = require('libp2p-webrtc-star/src/sig-server')
|
||||
const parallel = require('async/parallel')
|
||||
const crypto = require('crypto')
|
||||
|
||||
const createNode = require('./utils/create-node')
|
||||
const echo = require('./utils/echo')
|
||||
const { WRTC_RENDEZVOUS_MULTIADDR } = require('./utils/constants')
|
||||
|
||||
describe('peer discovery', () => {
|
||||
let nodeA
|
||||
let nodeB
|
||||
let port = 24642
|
||||
let ss
|
||||
let nodeC
|
||||
|
||||
function setup (options) {
|
||||
before((done) => {
|
||||
port++
|
||||
parallel([
|
||||
(cb) => {
|
||||
signalling.start({ port: port }, (err, server) => {
|
||||
expect(err).to.not.exist()
|
||||
ss = server
|
||||
cb()
|
||||
})
|
||||
},
|
||||
(cb) => createNode([
|
||||
'/ip4/0.0.0.0/tcp/0',
|
||||
`/ip4/127.0.0.1/tcp/${port}/ws/p2p-webrtc-star`
|
||||
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
|
||||
], options, (err, node) => {
|
||||
expect(err).to.not.exist()
|
||||
nodeA = node
|
||||
@ -40,12 +31,21 @@ describe('peer discovery', () => {
|
||||
}),
|
||||
(cb) => createNode([
|
||||
'/ip4/0.0.0.0/tcp/0',
|
||||
`/ip4/127.0.0.1/tcp/${port}/ws/p2p-webrtc-star`
|
||||
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
|
||||
], options, (err, node) => {
|
||||
expect(err).to.not.exist()
|
||||
nodeB = node
|
||||
node.handle('/echo/1.0.0', echo)
|
||||
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)
|
||||
})
|
||||
@ -54,15 +54,20 @@ describe('peer discovery', () => {
|
||||
parallel([
|
||||
(cb) => nodeA.stop(cb),
|
||||
(cb) => nodeB.stop(cb),
|
||||
(cb) => ss.stop(cb)
|
||||
(cb) => nodeC.stop(cb)
|
||||
], done)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
}
|
||||
|
||||
describe('module registration', () => {
|
||||
it('should enable by default a module passed as an object', (done) => {
|
||||
const mockDiscovery = {
|
||||
on: sinon.stub(),
|
||||
removeListener: sinon.stub(),
|
||||
start: sinon.stub().callsArg(0),
|
||||
stop: sinon.stub().callsArg(0)
|
||||
}
|
||||
@ -83,6 +88,7 @@ describe('peer discovery', () => {
|
||||
it('should enable by default a module passed as a function', (done) => {
|
||||
const mockDiscovery = {
|
||||
on: sinon.stub(),
|
||||
removeListener: sinon.stub(),
|
||||
start: sinon.stub().callsArg(0),
|
||||
stop: sinon.stub().callsArg(0)
|
||||
}
|
||||
@ -105,6 +111,7 @@ describe('peer discovery', () => {
|
||||
it('should enable module by configutation', (done) => {
|
||||
const mockDiscovery = {
|
||||
on: sinon.stub(),
|
||||
removeListener: sinon.stub(),
|
||||
start: sinon.stub().callsArg(0),
|
||||
stop: sinon.stub().callsArg(0),
|
||||
tag: 'mockDiscovery'
|
||||
@ -140,6 +147,7 @@ describe('peer discovery', () => {
|
||||
it('should disable module by configutation', (done) => {
|
||||
const mockDiscovery = {
|
||||
on: sinon.stub(),
|
||||
removeListener: sinon.stub(),
|
||||
start: sinon.stub().callsArg(0),
|
||||
stop: sinon.stub().callsArg(0),
|
||||
tag: 'mockDiscovery'
|
||||
@ -175,6 +183,7 @@ describe('peer discovery', () => {
|
||||
it('should register module passed as function', (done) => {
|
||||
const mockDiscovery = {
|
||||
on: sinon.stub(),
|
||||
removeListener: sinon.stub(),
|
||||
start: sinon.stub().callsArg(0),
|
||||
stop: sinon.stub().callsArg(0)
|
||||
}
|
||||
@ -212,6 +221,7 @@ describe('peer discovery', () => {
|
||||
it('should register module passed as object', (done) => {
|
||||
const mockDiscovery = {
|
||||
on: sinon.stub(),
|
||||
removeListener: sinon.stub(),
|
||||
start: sinon.stub().callsArg(0),
|
||||
stop: sinon.stub().callsArg(0),
|
||||
tag: 'mockDiscovery'
|
||||
@ -238,12 +248,44 @@ 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', () => {
|
||||
setup({
|
||||
config: {
|
||||
dht: {
|
||||
enabled: false
|
||||
},
|
||||
peerDiscovery: {
|
||||
autoDial: true,
|
||||
mdns: {
|
||||
enabled: true,
|
||||
interval: 200, // discover quickly
|
||||
// use a random tag to prevent CI collision
|
||||
serviceTag: crypto.randomBytes(10).toString('hex')
|
||||
}
|
||||
@ -251,13 +293,23 @@ describe('peer discovery', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('find a peer', function (done) {
|
||||
this.timeout(15 * 1000)
|
||||
it('find peers', function (done) {
|
||||
let expectedPeers = new Set([
|
||||
nodeB.peerInfo.id.toB58String(),
|
||||
nodeC.peerInfo.id.toB58String()
|
||||
])
|
||||
|
||||
nodeA.once('peer:discovery', (peerInfo) => {
|
||||
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()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -266,7 +318,11 @@ describe('peer discovery', () => {
|
||||
describe.skip('WebRTCStar', () => {
|
||||
setup({
|
||||
config: {
|
||||
dht: {
|
||||
enabled: false
|
||||
},
|
||||
peerDiscovery: {
|
||||
autoDial: true,
|
||||
webRTCStar: {
|
||||
enabled: true
|
||||
}
|
||||
@ -274,12 +330,24 @@ describe('peer discovery', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('find a peer', function (done) {
|
||||
this.timeout(15 * 1000)
|
||||
nodeA.once('peer:discovery', (peerInfo) => {
|
||||
expect(nodeB.peerInfo.id.toB58String())
|
||||
.to.eql(peerInfo.id.toB58String())
|
||||
it('find peers', function (done) {
|
||||
this.timeout(20e3)
|
||||
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()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -287,9 +355,14 @@ describe('peer discovery', () => {
|
||||
describe('MulticastDNS + WebRTCStar', () => {
|
||||
setup({
|
||||
config: {
|
||||
dht: {
|
||||
enabled: false
|
||||
},
|
||||
peerDiscovery: {
|
||||
autoDial: true,
|
||||
mdns: {
|
||||
enabled: true,
|
||||
interval: 200, // discovery quickly
|
||||
// use a random tag to prevent CI collision
|
||||
serviceTag: crypto.randomBytes(10).toString('hex')
|
||||
},
|
||||
@ -300,13 +373,122 @@ describe('peer discovery', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('find a peer', function (done) {
|
||||
this.timeout(15 * 1000)
|
||||
nodeA.once('peer:discovery', (peerInfo) => {
|
||||
expect(nodeB.peerInfo.id.toB58String())
|
||||
.to.eql(peerInfo.id.toB58String())
|
||||
it('find peers', 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()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -24,13 +24,7 @@ describe('.peerRouting', () => {
|
||||
|
||||
before('create the outer ring of connections', (done) => {
|
||||
const tasks = _times(5, () => (cb) => {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||
config: {
|
||||
EXPERIMENTAL: {
|
||||
dht: true
|
||||
}
|
||||
}
|
||||
}, (err, node) => {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', (err, node) => {
|
||||
expect(err).to.not.exist()
|
||||
node.start((err) => cb(err, node))
|
||||
})
|
||||
@ -112,6 +106,11 @@ describe('.peerRouting', () => {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||
modules: {
|
||||
peerRouting: [ delegate ]
|
||||
},
|
||||
config: {
|
||||
dht: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
}, (err, node) => {
|
||||
expect(err).to.not.exist()
|
||||
@ -213,11 +212,6 @@ describe('.peerRouting', () => {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||
modules: {
|
||||
peerRouting: [ delegate ]
|
||||
},
|
||||
config: {
|
||||
EXPERIMENTAL: {
|
||||
dht: true
|
||||
}
|
||||
}
|
||||
}, (err, node) => {
|
||||
expect(err).to.not.exist()
|
||||
@ -270,7 +264,13 @@ describe('.peerRouting', () => {
|
||||
describe('no routers', () => {
|
||||
let nodeA
|
||||
before((done) => {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', (err, node) => {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||
config: {
|
||||
dht: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
}, (err, node) => {
|
||||
expect(err).to.not.exist()
|
||||
nodeA = node
|
||||
done()
|
||||
|
@ -9,6 +9,7 @@ const PeerId = require('peer-id')
|
||||
const waterfall = require('async/waterfall')
|
||||
const WS = require('libp2p-websockets')
|
||||
const defaultsDeep = require('@nodeutils/defaults-deep')
|
||||
const DHT = require('libp2p-kad-dht')
|
||||
|
||||
const Libp2p = require('../src')
|
||||
|
||||
@ -23,7 +24,8 @@ describe('private network', () => {
|
||||
config = {
|
||||
peerInfo,
|
||||
modules: {
|
||||
transport: [ WS ]
|
||||
transport: [ WS ],
|
||||
dht: DHT
|
||||
}
|
||||
}
|
||||
cb()
|
||||
|
@ -5,11 +5,13 @@
|
||||
|
||||
const chai = require('chai')
|
||||
chai.use(require('dirty-chai'))
|
||||
chai.use(require('chai-checkmark'))
|
||||
const expect = chai.expect
|
||||
const parallel = require('async/parallel')
|
||||
const waterfall = require('async/waterfall')
|
||||
const series = require('async/series')
|
||||
const _times = require('lodash.times')
|
||||
|
||||
const { codes } = require('../src/errors')
|
||||
const createNode = require('./utils/create-node')
|
||||
|
||||
function startTwo (callback) {
|
||||
@ -52,26 +54,115 @@ function stopTwo (nodes, callback) {
|
||||
// TODO: consider if all or some of those should come here
|
||||
describe('.pubsub', () => {
|
||||
describe('.pubsub on (default)', (done) => {
|
||||
it('start two nodes and send one message', (done) => {
|
||||
waterfall([
|
||||
(cb) => startTwo(cb),
|
||||
(nodes, cb) => {
|
||||
const data = Buffer.from('test')
|
||||
nodes[0].pubsub.subscribe('pubsub',
|
||||
(msg) => {
|
||||
expect(msg.data).to.eql(data)
|
||||
cb(null, nodes)
|
||||
},
|
||||
(err) => {
|
||||
expect(err).to.not.exist()
|
||||
setTimeout(() => nodes[1].pubsub.publish('pubsub', data, (err) => {
|
||||
expect(err).to.not.exist()
|
||||
}), 500)
|
||||
}
|
||||
)
|
||||
it('start two nodes and send one message, then unsubscribe', (done) => {
|
||||
// Check the final series error, and the publish handler
|
||||
expect(2).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),
|
||||
// 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)
|
||||
},
|
||||
(nodes, cb) => stopTwo(nodes, cb)
|
||||
], done)
|
||||
// Verify unsubscribed
|
||||
(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()
|
||||
|
||||
node.start((err) => {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
node.pubsub.publish('pubsub', 'datastr', (err) => {
|
||||
expect(err).to.exist()
|
||||
expect(err.code).to.equal('ERR_DATA_IS_NOT_A_BUFFER')
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -95,4 +186,73 @@ 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()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -15,9 +15,6 @@ describe('libp2p', () => {
|
||||
mdns: {
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
dht: true
|
||||
}
|
||||
}
|
||||
}, (err, node) => {
|
||||
|
@ -6,6 +6,7 @@ chai.use(require('dirty-chai'))
|
||||
const expect = chai.expect
|
||||
const parallel = require('async/parallel')
|
||||
const series = require('async/series')
|
||||
const pMplex = require('pull-mplex')
|
||||
const Mplex = require('libp2p-mplex')
|
||||
const SPDY = require('libp2p-spdy')
|
||||
const createNode = require('./utils/create-node')
|
||||
@ -99,6 +100,42 @@ describe('stream muxing', () => {
|
||||
], 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) {
|
||||
this.timeout(5000)
|
||||
|
||||
@ -137,7 +174,45 @@ describe('stream muxing', () => {
|
||||
], done)
|
||||
})
|
||||
|
||||
it('spdy + mplex switched order', function (done) {
|
||||
it('mplex + pull-mplex', 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)
|
||||
|
||||
let nodeA
|
||||
@ -175,6 +250,44 @@ describe('stream muxing', () => {
|
||||
], 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) {
|
||||
this.timeout(5 * 1000)
|
||||
|
||||
@ -213,10 +326,10 @@ describe('stream muxing', () => {
|
||||
expect(Object.keys(nodeA._switch.muxers)).to.have.length(1)
|
||||
expect(Object.keys(nodeB._switch.muxers)).to.have.length(1)
|
||||
|
||||
nodeA.dial(nodeB.peerInfo, (err) => {
|
||||
nodeA.dialFSM(nodeB.peerInfo, (err, connFSM) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
|
||||
cb()
|
||||
// The connection should fall back to 'unmuxed'
|
||||
connFSM.once('unmuxed', () => cb())
|
||||
})
|
||||
},
|
||||
(cb) => teardown(nodeA, nodeB, cb)
|
||||
|
@ -4,31 +4,32 @@
|
||||
|
||||
const chai = require('chai')
|
||||
chai.use(require('dirty-chai'))
|
||||
chai.use(require('chai-checkmark'))
|
||||
const expect = chai.expect
|
||||
const PeerInfo = require('peer-info')
|
||||
const PeerId = require('peer-id')
|
||||
const Mplex = require('libp2p-mplex')
|
||||
const Mplex = require('pull-mplex')
|
||||
const pull = require('pull-stream')
|
||||
const parallel = require('async/parallel')
|
||||
const goodbye = require('pull-goodbye')
|
||||
const serializer = require('pull-serializer')
|
||||
const w = require('webrtcsupport')
|
||||
const wrtcSupport = self.RTCPeerConnection && ('createDataChannel' in self.RTCPeerConnection.prototype)
|
||||
const tryEcho = require('./utils/try-echo')
|
||||
|
||||
const Node = require('./utils/bundle-browser')
|
||||
const jsonPeerId = require('./fixtures/test-peer.json')
|
||||
const { getPeerRelay } = require('./utils/constants')
|
||||
|
||||
describe('transports', () => {
|
||||
describe('websockets', () => {
|
||||
let peerB
|
||||
let peerBMultiaddr = '/ip4/127.0.0.1/tcp/9200/ws/ipfs/' + jsonPeerId.id
|
||||
let peerBMultiaddr
|
||||
let nodeA
|
||||
|
||||
before((done) => {
|
||||
PeerId.createFromPrivKey(jsonPeerId.privKey, (err, id) => {
|
||||
getPeerRelay((err, peerInfo) => {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
peerB = new PeerInfo(id)
|
||||
peerB = new PeerInfo(peerInfo.id)
|
||||
peerBMultiaddr = `/ip4/127.0.0.1/tcp/9200/ws/p2p/${peerInfo.id.toB58String()}`
|
||||
peerB.multiaddrs.add(peerBMultiaddr)
|
||||
done()
|
||||
})
|
||||
@ -57,7 +58,7 @@ describe('transports', () => {
|
||||
streamMuxer: [ Mplex ]
|
||||
}
|
||||
})
|
||||
expect(b._modules.streamMuxer).to.eql([require('libp2p-mplex')])
|
||||
expect(b._modules.streamMuxer).to.eql([require('pull-mplex')])
|
||||
done()
|
||||
})
|
||||
})
|
||||
@ -102,7 +103,7 @@ describe('transports', () => {
|
||||
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)
|
||||
expect(nodeA._switch.connection.getAll()).to.have.length(0)
|
||||
done()
|
||||
}
|
||||
})
|
||||
@ -142,7 +143,7 @@ describe('transports', () => {
|
||||
const peers = nodeA.peerBook.getAll()
|
||||
expect(err).to.not.exist()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
|
||||
expect(nodeA._switch.connection.getAll()).to.have.length(0)
|
||||
done()
|
||||
}
|
||||
})
|
||||
@ -153,16 +154,17 @@ describe('transports', () => {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
connFSM.once('muxed', () => {
|
||||
expect(nodeA._switch.muxedConns).to.have.any.keys(
|
||||
peerB.id.toB58String()
|
||||
)
|
||||
expect(
|
||||
nodeA._switch.connection.getAllById(peerB.id.toB58String())
|
||||
).to.have.length(1)
|
||||
|
||||
connFSM.once('error', done)
|
||||
connFSM.once('close', () => {
|
||||
// ensure the connection is closed
|
||||
expect(nodeA._switch.muxedConns).to.not.have.any.keys([
|
||||
peerB.id.toB58String()
|
||||
])
|
||||
expect(
|
||||
nodeA._switch.connection.getAllById(peerB.id.toB58String())
|
||||
).to.have.length(0)
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
@ -231,7 +233,7 @@ describe('transports', () => {
|
||||
|
||||
describe('webrtc-star', () => {
|
||||
/* eslint-disable-next-line no-console */
|
||||
if (!w.support) { return console.log('NO WEBRTC SUPPORT') }
|
||||
if (!wrtcSupport) { return console.log('NO WEBRTC SUPPORT') }
|
||||
|
||||
let peer1
|
||||
let peer2
|
||||
@ -255,11 +257,11 @@ describe('transports', () => {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
peer1 = new PeerInfo(ids[0])
|
||||
const ma1 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/ipfs/' + ids[0].toB58String()
|
||||
const ma1 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/p2p/' + ids[0].toB58String()
|
||||
peer1.multiaddrs.add(ma1)
|
||||
|
||||
peer2 = new PeerInfo(ids[1])
|
||||
const ma2 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/ipfs/' + ids[1].toB58String()
|
||||
const ma2 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/p2p/' + ids[1].toB58String()
|
||||
peer2.multiaddrs.add(ma2)
|
||||
|
||||
done()
|
||||
@ -312,7 +314,7 @@ describe('transports', () => {
|
||||
function check () {
|
||||
const peers = node1.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(node1._switch.muxedConns)).to.have.length(0)
|
||||
expect(node1._switch.connection.getAll()).to.have.length(0)
|
||||
done()
|
||||
}
|
||||
})
|
||||
@ -326,13 +328,13 @@ describe('transports', () => {
|
||||
|
||||
function check () {
|
||||
// Verify both nodes are connected to node 3
|
||||
if (node1._switch.muxedConns[b58Id] && node2._switch.muxedConns[b58Id]) {
|
||||
if (node1._switch.connection.getAllById(b58Id) && node2._switch.connection.getAllById(b58Id)) {
|
||||
done()
|
||||
}
|
||||
}
|
||||
|
||||
const peer3 = new PeerInfo(id3)
|
||||
const ma3 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/ipfs/' + b58Id
|
||||
const ma3 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/p2p/' + b58Id
|
||||
peer3.multiaddrs.add(ma3)
|
||||
|
||||
node1.on('peer:discovery', (peerInfo) => node1.dial(peerInfo, check))
|
||||
@ -412,44 +414,39 @@ describe('transports', () => {
|
||||
it('node1 hangUp node2', (done) => {
|
||||
node1.hangUp(peer2, (err) => {
|
||||
expect(err).to.not.exist()
|
||||
setTimeout(check, 500)
|
||||
|
||||
function check () {
|
||||
const peers = node1.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(node1._switch.muxedConns)).to.have.length(0)
|
||||
done()
|
||||
}
|
||||
const peers = node1.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(node1._switch.connection.getAll()).to.have.length(0)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('create a third node and check that discovery works', function (done) {
|
||||
this.timeout(10 * 1000)
|
||||
|
||||
let counter = 0
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
const expectedPeers = [
|
||||
node1.peerInfo.id.toB58String(),
|
||||
node2.peerInfo.id.toB58String()
|
||||
]
|
||||
|
||||
PeerId.create((err, id3) => {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
const peer3 = new PeerInfo(id3)
|
||||
const ma3 = '/ip4/127.0.0.1/tcp/14444/ws/p2p-websocket-star/ipfs/' + id3.toB58String()
|
||||
const ma3 = '/ip4/127.0.0.1/tcp/14444/ws/p2p-websocket-star/p2p/' + id3.toB58String()
|
||||
peer3.multiaddrs.add(ma3)
|
||||
|
||||
node1.on('peer:discovery', (peerInfo) => node1.dial(peerInfo, check))
|
||||
node2.on('peer:discovery', (peerInfo) => node2.dial(peerInfo, check))
|
||||
// 2 connects and 1 start
|
||||
expect(3).checks(done)
|
||||
|
||||
const node3 = new Node({
|
||||
peerInfo: peer3
|
||||
})
|
||||
node3.start(check)
|
||||
node3.on('peer:connect', (peerInfo) => {
|
||||
expect(expectedPeers).to.include(peerInfo.id.toB58String()).mark()
|
||||
})
|
||||
node3.start((err) => {
|
||||
expect(err).to.not.exist().mark()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -6,7 +6,6 @@ chai.use(require('dirty-chai'))
|
||||
const expect = chai.expect
|
||||
const parallel = require('async/parallel')
|
||||
const series = require('async/series')
|
||||
const signalling = require('libp2p-webrtc-star/src/sig-server')
|
||||
const rendezvous = require('libp2p-websocket-star-rendezvous')
|
||||
const TCP = require('libp2p-tcp')
|
||||
const WS = require('libp2p-websockets')
|
||||
@ -18,6 +17,8 @@ const createNode = require('./utils/create-node.js')
|
||||
const tryEcho = require('./utils/try-echo')
|
||||
const echo = require('./utils/echo')
|
||||
|
||||
const { WRTC_RENDEZVOUS_MULTIADDR } = require('./utils/constants')
|
||||
|
||||
describe('transports', () => {
|
||||
describe('TCP only', () => {
|
||||
let nodeA
|
||||
@ -91,14 +92,13 @@ describe('transports', () => {
|
||||
(cb) => {
|
||||
const peers = nodeA.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
|
||||
expect(nodeA._switch.connection.getAll()).to.have.length(0)
|
||||
cb()
|
||||
},
|
||||
(cb) => {
|
||||
const peers = nodeB.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
|
||||
expect(Object.keys(nodeB._switch.muxedConns)).to.have.length(0)
|
||||
expect(nodeB._switch.connection.getAll()).to.have.length(0)
|
||||
cb()
|
||||
}
|
||||
], done)
|
||||
@ -117,15 +117,13 @@ describe('transports', () => {
|
||||
(cb) => {
|
||||
const peers = nodeA.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
|
||||
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(1)
|
||||
expect(nodeA._switch.connection.getAll()).to.have.length(1)
|
||||
cb()
|
||||
},
|
||||
(cb) => {
|
||||
const peers = nodeB.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
|
||||
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(1)
|
||||
expect(nodeA._switch.connection.getAll()).to.have.length(1)
|
||||
cb()
|
||||
}
|
||||
], () => tryEcho(conn, done))
|
||||
@ -143,15 +141,13 @@ describe('transports', () => {
|
||||
(cb) => {
|
||||
const peers = nodeA.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
|
||||
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
|
||||
expect(nodeA._switch.connection.getAll()).to.have.length(0)
|
||||
cb()
|
||||
},
|
||||
(cb) => {
|
||||
const peers = nodeB.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
|
||||
expect(Object.keys(nodeB._switch.muxedConns)).to.have.length(0)
|
||||
expect(nodeB._switch.connection.getAll()).to.have.length(0)
|
||||
cb()
|
||||
}
|
||||
], done)
|
||||
@ -170,13 +166,13 @@ describe('transports', () => {
|
||||
(cb) => {
|
||||
const peers = nodeA.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(1)
|
||||
expect(nodeA._switch.connection.getAll()).to.have.length(1)
|
||||
cb()
|
||||
},
|
||||
(cb) => {
|
||||
const peers = nodeB.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(1)
|
||||
expect(nodeA._switch.connection.getAll()).to.have.length(1)
|
||||
cb()
|
||||
}
|
||||
], () => tryEcho(conn, done))
|
||||
@ -194,13 +190,13 @@ describe('transports', () => {
|
||||
(cb) => {
|
||||
const peers = nodeA.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
|
||||
expect(nodeA._switch.connection.getAll()).to.have.length(0)
|
||||
cb()
|
||||
},
|
||||
(cb) => {
|
||||
const peers = nodeB.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(nodeB._switch.muxedConns)).to.have.length(0)
|
||||
expect(nodeB._switch.connection.getAll()).to.have.length(0)
|
||||
cb()
|
||||
}
|
||||
], done)
|
||||
@ -213,16 +209,16 @@ describe('transports', () => {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
connFSM.once('muxed', () => {
|
||||
expect(nodeA._switch.muxedConns).to.have.any.keys(
|
||||
nodeB.peerInfo.id.toB58String()
|
||||
)
|
||||
expect(
|
||||
nodeA._switch.connection.getAllById(nodeB.peerInfo.id.toB58String())
|
||||
).to.have.length(1)
|
||||
|
||||
connFSM.once('error', done)
|
||||
connFSM.once('close', () => {
|
||||
// ensure the connection is closed
|
||||
expect(nodeA._switch.muxedConns).to.not.have.any.keys([
|
||||
nodeB.peerInfo.id.toB58String()
|
||||
])
|
||||
expect(
|
||||
nodeA._switch.connection.getAllById(nodeB.peerInfo.id.toB58String())
|
||||
).to.have.length(0)
|
||||
done()
|
||||
})
|
||||
|
||||
@ -235,9 +231,9 @@ describe('transports', () => {
|
||||
nodeA.dialFSM(nodeB.peerInfo, '/echo/1.0.0', (err, connFSM) => {
|
||||
expect(err).to.not.exist()
|
||||
connFSM.once('connection', (conn) => {
|
||||
expect(nodeA._switch.muxedConns).to.have.all.keys([
|
||||
nodeB.peerInfo.id.toB58String()
|
||||
])
|
||||
expect(
|
||||
nodeA._switch.connection.getAllById(nodeB.peerInfo.id.toB58String())
|
||||
).to.have.length(1)
|
||||
tryEcho(conn, () => {
|
||||
connFSM.close()
|
||||
})
|
||||
@ -245,9 +241,9 @@ describe('transports', () => {
|
||||
connFSM.once('error', done)
|
||||
connFSM.once('close', () => {
|
||||
// ensure the connection is closed
|
||||
expect(nodeA._switch.muxedConns).to.not.have.any.keys([
|
||||
nodeB.peerInfo.id.toB58String()
|
||||
])
|
||||
expect(
|
||||
nodeA._switch.connection.getAllById(nodeB.peerInfo.id.toB58String())
|
||||
).to.have.length(0)
|
||||
done()
|
||||
})
|
||||
})
|
||||
@ -309,13 +305,13 @@ describe('transports', () => {
|
||||
(cb) => {
|
||||
const peers = nodeTCP.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(nodeTCP._switch.muxedConns)).to.have.length(1)
|
||||
expect(nodeTCP._switch.connection.getAll()).to.have.length(1)
|
||||
cb()
|
||||
},
|
||||
(cb) => {
|
||||
const peers = nodeTCPnWS.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(nodeTCPnWS._switch.muxedConns)).to.have.length(1)
|
||||
expect(nodeTCPnWS._switch.connection.getAll()).to.have.length(1)
|
||||
cb()
|
||||
}
|
||||
], done)
|
||||
@ -333,14 +329,13 @@ describe('transports', () => {
|
||||
(cb) => {
|
||||
const peers = nodeTCP.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(nodeTCP._switch.muxedConns)).to.have.length(0)
|
||||
|
||||
expect(nodeTCP._switch.connection.getAll()).to.have.length(0)
|
||||
cb()
|
||||
},
|
||||
(cb) => {
|
||||
const peers = nodeTCPnWS.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(nodeTCPnWS._switch.muxedConns)).to.have.length(0)
|
||||
expect(nodeTCPnWS._switch.connection.getAll()).to.have.length(0)
|
||||
cb()
|
||||
}
|
||||
], done)
|
||||
@ -360,13 +355,13 @@ describe('transports', () => {
|
||||
(cb) => {
|
||||
const peers = nodeTCPnWS.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(2)
|
||||
expect(Object.keys(nodeTCPnWS._switch.muxedConns)).to.have.length(1)
|
||||
expect(nodeTCPnWS._switch.connection.getAll()).to.have.length(1)
|
||||
cb()
|
||||
},
|
||||
(cb) => {
|
||||
const peers = nodeWS.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(nodeWS._switch.muxedConns)).to.have.length(1)
|
||||
expect(nodeWS._switch.connection.getAll()).to.have.length(1)
|
||||
cb()
|
||||
}
|
||||
], done)
|
||||
@ -384,14 +379,14 @@ describe('transports', () => {
|
||||
(cb) => {
|
||||
const peers = nodeTCPnWS.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(2)
|
||||
expect(Object.keys(nodeTCPnWS._switch.muxedConns)).to.have.length(0)
|
||||
expect(nodeTCPnWS._switch.connection.getAll()).to.have.length(0)
|
||||
|
||||
cb()
|
||||
},
|
||||
(cb) => {
|
||||
const peers = nodeWS.peerBook.getAll()
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
expect(Object.keys(nodeWS._switch.muxedConns)).to.have.length(0)
|
||||
expect(nodeWS._switch.connection.getAll()).to.have.length(0)
|
||||
cb()
|
||||
}
|
||||
], done)
|
||||
@ -415,24 +410,17 @@ describe('transports', () => {
|
||||
let nodeWS
|
||||
let nodeWebRTCStar
|
||||
|
||||
let ss
|
||||
|
||||
before(function (done) {
|
||||
this.timeout(5 * 1000)
|
||||
|
||||
parallel([
|
||||
(cb) => signalling.start({ port: 24642 }, (err, server) => {
|
||||
expect(err).to.not.exist()
|
||||
ss = server
|
||||
cb()
|
||||
}),
|
||||
(cb) => {
|
||||
const wstar = new WRTCStar({wrtc: wrtc})
|
||||
const wstar = new WRTCStar({ wrtc: wrtc })
|
||||
|
||||
createNode([
|
||||
'/ip4/0.0.0.0/tcp/0',
|
||||
'/ip4/127.0.0.1/tcp/25011/ws',
|
||||
'/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'
|
||||
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
|
||||
], {
|
||||
modules: {
|
||||
transport: [
|
||||
@ -444,6 +432,7 @@ describe('transports', () => {
|
||||
},
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
autoDial: false,
|
||||
[wstar.discovery.tag]: {
|
||||
enabled: true
|
||||
}
|
||||
@ -458,7 +447,13 @@ describe('transports', () => {
|
||||
},
|
||||
(cb) => createNode([
|
||||
'/ip4/0.0.0.0/tcp/0'
|
||||
], (err, node) => {
|
||||
], {
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
autoDial: false
|
||||
}
|
||||
}
|
||||
}, (err, node) => {
|
||||
expect(err).to.not.exist()
|
||||
nodeTCP = node
|
||||
node.handle('/echo/1.0.0', echo)
|
||||
@ -466,18 +461,23 @@ describe('transports', () => {
|
||||
}),
|
||||
(cb) => createNode([
|
||||
'/ip4/127.0.0.1/tcp/25022/ws'
|
||||
], (err, node) => {
|
||||
], {
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
autoDial: false
|
||||
}
|
||||
}
|
||||
}, (err, node) => {
|
||||
expect(err).to.not.exist()
|
||||
nodeWS = node
|
||||
node.handle('/echo/1.0.0', echo)
|
||||
node.start(cb)
|
||||
}),
|
||||
|
||||
(cb) => {
|
||||
const wstar = new WRTCStar({wrtc: wrtc})
|
||||
const wstar = new WRTCStar({ wrtc: wrtc })
|
||||
|
||||
createNode([
|
||||
'/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'
|
||||
`${WRTC_RENDEZVOUS_MULTIADDR.toString()}/p2p-webrtc-star`
|
||||
], {
|
||||
modules: {
|
||||
transport: [wstar],
|
||||
@ -485,6 +485,7 @@ describe('transports', () => {
|
||||
},
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
autoDial: false,
|
||||
[wstar.discovery.tag]: {
|
||||
enabled: true
|
||||
}
|
||||
@ -507,8 +508,7 @@ describe('transports', () => {
|
||||
(cb) => nodeAll.stop(cb),
|
||||
(cb) => nodeTCP.stop(cb),
|
||||
(cb) => nodeWS.stop(cb),
|
||||
(cb) => nodeWebRTCStar.stop(cb),
|
||||
(cb) => ss.stop(cb)
|
||||
(cb) => nodeWebRTCStar.stop(cb)
|
||||
], done)
|
||||
})
|
||||
|
||||
@ -516,7 +516,7 @@ describe('transports', () => {
|
||||
let i = 1;
|
||||
[nodeAll, otherNode].forEach((node) => {
|
||||
expect(Object.keys(node.peerBook.getAll())).to.have.length(i-- ? peers : 1)
|
||||
expect(Object.keys(node._switch.muxedConns)).to.have.length(muxed)
|
||||
expect(node._switch.connection.getAll()).to.have.length(muxed)
|
||||
})
|
||||
callback()
|
||||
}
|
||||
@ -678,7 +678,7 @@ describe('transports', () => {
|
||||
let i = 1;
|
||||
[nodeAll, otherNode].forEach((node) => {
|
||||
expect(Object.keys(node.peerBook.getAll())).to.have.length(i-- ? peers : 1)
|
||||
expect(Object.keys(node._switch.muxedConns)).to.have.length(muxed)
|
||||
expect(node._switch.connection.getAll()).to.have.length(muxed)
|
||||
})
|
||||
done()
|
||||
}
|
||||
|
@ -1,84 +0,0 @@
|
||||
/* 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()
|
||||
}
|
||||
})
|
||||
})
|
@ -6,6 +6,7 @@ const WebSocketStar = require('libp2p-websocket-star')
|
||||
const Bootstrap = require('libp2p-bootstrap')
|
||||
const SPDY = require('libp2p-spdy')
|
||||
const MPLEX = require('libp2p-mplex')
|
||||
const PULLMPLEX = require('pull-mplex')
|
||||
const KadDHT = require('libp2p-kad-dht')
|
||||
const SECIO = require('libp2p-secio')
|
||||
const defaultsDeep = require('@nodeutils/defaults-deep')
|
||||
@ -17,6 +18,7 @@ function mapMuxers (list) {
|
||||
switch (pref.trim().toLowerCase()) {
|
||||
case 'spdy': return SPDY
|
||||
case 'mplex': return MPLEX
|
||||
case 'pullmplex': return PULLMPLEX
|
||||
default:
|
||||
throw new Error(pref + ' muxer not available')
|
||||
}
|
||||
@ -27,7 +29,7 @@ function getMuxers (options) {
|
||||
if (options) {
|
||||
return mapMuxers(options)
|
||||
} else {
|
||||
return [MPLEX, SPDY]
|
||||
return [PULLMPLEX, MPLEX, SPDY]
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,6 +61,7 @@ class Node extends libp2p {
|
||||
},
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
autoDial: true,
|
||||
webRTCStar: {
|
||||
enabled: true
|
||||
},
|
||||
@ -80,10 +83,12 @@ class Node extends libp2p {
|
||||
},
|
||||
dht: {
|
||||
kBucketSize: 20,
|
||||
enabledDiscovery: true
|
||||
randomWalk: {
|
||||
enabled: true
|
||||
},
|
||||
enabled: false
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
dht: false,
|
||||
pubsub: false
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ const Bootstrap = require('libp2p-bootstrap')
|
||||
const SPDY = require('libp2p-spdy')
|
||||
const KadDHT = require('libp2p-kad-dht')
|
||||
const MPLEX = require('libp2p-mplex')
|
||||
const PULLMPLEX = require('pull-mplex')
|
||||
const SECIO = require('libp2p-secio')
|
||||
const defaultsDeep = require('@nodeutils/defaults-deep')
|
||||
const libp2p = require('../..')
|
||||
@ -17,6 +18,7 @@ function mapMuxers (list) {
|
||||
switch (pref.trim().toLowerCase()) {
|
||||
case 'spdy': return SPDY
|
||||
case 'mplex': return MPLEX
|
||||
case 'pullmplex': return PULLMPLEX
|
||||
default:
|
||||
throw new Error(pref + ' muxer not available')
|
||||
}
|
||||
@ -30,7 +32,7 @@ function getMuxers (muxers) {
|
||||
} else if (muxers) {
|
||||
return mapMuxers(muxers)
|
||||
} else {
|
||||
return [MPLEX, SPDY]
|
||||
return [PULLMPLEX, MPLEX, SPDY]
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +56,7 @@ class Node extends libp2p {
|
||||
},
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
autoDial: true,
|
||||
mdns: {
|
||||
interval: 10000,
|
||||
enabled: false
|
||||
@ -73,10 +76,12 @@ class Node extends libp2p {
|
||||
},
|
||||
dht: {
|
||||
kBucketSize: 20,
|
||||
enabledDiscovery: true
|
||||
randomWalk: {
|
||||
enabled: true
|
||||
},
|
||||
enabled: true
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
dht: false,
|
||||
pubsub: false
|
||||
}
|
||||
}
|
||||
|
40
test/utils/constants.js
Normal file
40
test/utils/constants.js
Normal file
@ -0,0 +1,40 @@
|
||||
'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')
|
@ -8,3 +8,4 @@ function echo (protocol, conn) {
|
||||
}
|
||||
|
||||
module.exports = echo
|
||||
module.exports.multicodec = '/echo/1.0.0'
|
||||
|
Reference in New Issue
Block a user