mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-09 05:41:33 +00:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
3ad696445d | |||
30bec8d53b | |||
db2b5300b4 | |||
df4d60df88 | |||
29cc0afc64 | |||
2504cbeb26 | |||
468cc421fa | |||
0b991e19d1 | |||
2a81fc75a8 | |||
e04c249d4d | |||
4a995613ae | |||
066c4976bb | |||
429cf9c361 |
@ -1,6 +1,5 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const gulp = require('gulp')
|
|
||||||
const Node = require('./test/nodejs-bundle/nodejs-bundle.js')
|
const Node = require('./test/nodejs-bundle/nodejs-bundle.js')
|
||||||
const PeerInfo = require('peer-info')
|
const PeerInfo = require('peer-info')
|
||||||
const PeerId = require('peer-id')
|
const PeerId = require('peer-id')
|
||||||
@ -12,7 +11,7 @@ let server
|
|||||||
let node
|
let node
|
||||||
const rawPeer = require('./test/browser-bundle/peer.json')
|
const rawPeer = require('./test/browser-bundle/peer.json')
|
||||||
|
|
||||||
gulp.task('libnode:start', (done) => {
|
const before = (done) => {
|
||||||
let count = 0
|
let count = 0
|
||||||
const ready = () => ++count === 2 ? done() : null
|
const ready = () => ++count === 2 ? done() : null
|
||||||
|
|
||||||
@ -36,20 +35,21 @@ gulp.task('libnode:start', (done) => {
|
|||||||
node.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn))
|
node.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn))
|
||||||
node.start(() => ready())
|
node.start(() => ready())
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
gulp.task('libnode:stop', (done) => {
|
const after = (done) => {
|
||||||
setTimeout(() => node.stop((err) => {
|
setTimeout(() => node.stop((err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err)
|
return done(err)
|
||||||
}
|
}
|
||||||
server.stop(done)
|
server.stop(done)
|
||||||
}), 2000)
|
}), 2000)
|
||||||
})
|
}
|
||||||
|
|
||||||
gulp.task('test:browser:before', ['libnode:start'])
|
module.exports = {
|
||||||
gulp.task('test:node:before', ['libnode:start'])
|
hooks: {
|
||||||
gulp.task('test:browser:after', ['libnode:stop'])
|
pre: before,
|
||||||
gulp.task('test:node:after', ['libnode:stop'])
|
post: after
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
require('aegir/gulp')(gulp)
|
|
15
CHANGELOG.md
15
CHANGELOG.md
@ -1,3 +1,18 @@
|
|||||||
|
<a name="0.13.0"></a>
|
||||||
|
# [0.13.0](https://github.com/libp2p/js-libp2p/compare/v0.12.4...v0.13.0) (2017-10-26)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* enable and test Circuit Relay ([29cc0af](https://github.com/libp2p/js-libp2p/commit/29cc0af))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.12.4"></a>
|
||||||
|
## [0.12.4](https://github.com/libp2p/js-libp2p/compare/v0.12.3...v0.12.4) (2017-09-07)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="0.12.3"></a>
|
<a name="0.12.3"></a>
|
||||||
## [0.12.3](https://github.com/libp2p/js-libp2p/compare/v0.12.2...v0.12.3) (2017-09-07)
|
## [0.12.3](https://github.com/libp2p/js-libp2p/compare/v0.12.2...v0.12.3) (2017-09-07)
|
||||||
|
|
||||||
|
36
README.md
36
README.md
@ -263,6 +263,42 @@ class Node extends libp2p {
|
|||||||
[multiaddr]: https://github.com/multiformats/js-multiaddr
|
[multiaddr]: https://github.com/multiformats/js-multiaddr
|
||||||
[Connection]: https://github.com/libp2p/interface-connection
|
[Connection]: https://github.com/libp2p/interface-connection
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
**Clone and install dependencies:**
|
||||||
|
|
||||||
|
```sh
|
||||||
|
> git clone https://github.com/ipfs/js-ipfs.git
|
||||||
|
> cd js-ipfs
|
||||||
|
> npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
### Tests
|
||||||
|
|
||||||
|
#### Run unit tests
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# run all the unit tsts
|
||||||
|
> npm test
|
||||||
|
|
||||||
|
# run just Node.js tests
|
||||||
|
> npm run test:node
|
||||||
|
|
||||||
|
# run just Browser tests (Chrome)
|
||||||
|
> npm run test:browser
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Run interop tests
|
||||||
|
|
||||||
|
```sh
|
||||||
|
N/A
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Run benchmark tests
|
||||||
|
|
||||||
|
```sh
|
||||||
|
N/A
|
||||||
|
```
|
||||||
|
|
||||||
### Packages
|
### Packages
|
||||||
|
|
||||||
|
@ -6,9 +6,13 @@ dependencies:
|
|||||||
pre:
|
pre:
|
||||||
- google-chrome --version
|
- google-chrome --version
|
||||||
- curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
|
- curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
|
||||||
|
- for v in $(curl http://archive.ubuntu.com/ubuntu/pool/main/n/nss/ | grep "href=" | grep "libnss3.*deb\"" -o | grep -o "libnss3.*deb" | grep "3.28" | grep "14.04"); do curl -L -o $v http://archive.ubuntu.com/ubuntu/pool/main/n/nss/$v; done && rm libnss3-tools*_i386.deb libnss3-dev*_i386.deb
|
||||||
- sudo dpkg -i google-chrome.deb || true
|
- sudo dpkg -i google-chrome.deb || true
|
||||||
|
- sudo dpkg -i libnss3*.deb || true
|
||||||
- sudo apt-get update
|
- sudo apt-get update
|
||||||
|
- sudo apt-get install -f || true
|
||||||
|
- sudo dpkg -i libnss3*.deb
|
||||||
- sudo apt-get install -f
|
- sudo apt-get install -f
|
||||||
- sudo apt-get install --only-upgrade lsb-base
|
- sudo apt-get install --only-upgrade lsb-base
|
||||||
- sudo dpkg -i google-chrome.deb
|
- sudo dpkg -i google-chrome.deb
|
||||||
- google-chrome --version
|
- google-chrome --version
|
@ -32,7 +32,7 @@ class MyBundle extends libp2p {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
And that's it, from now on, all your libp2p communications are encrypted. Try running the exampme [1.js](./1.js) to see it working.
|
And that's it, from now on, all your libp2p communications are encrypted. Try running the example [1.js](./1.js) to see it working.
|
||||||
|
|
||||||
If you want to want to learn more about how SECIO works, you can read the [great write up done by Dominic Tarr](https://github.com/auditdrivencrypto/secure-channel/blob/master/prior-art.md#ipfss-secure-channel).
|
If you want to want to learn more about how SECIO works, you can read the [great write up done by Dominic Tarr](https://github.com/auditdrivencrypto/secure-channel/blob/master/prior-art.md#ipfss-secure-channel).
|
||||||
|
|
||||||
|
@ -19,7 +19,9 @@ const bootstrapers = [
|
|||||||
'/dns4/sfo-3.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
|
'/dns4/sfo-3.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
|
||||||
'/dns4/sgp-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
|
'/dns4/sgp-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
|
||||||
'/dns4/nyc-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
|
'/dns4/nyc-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
|
||||||
'/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
|
'/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
|
||||||
|
'/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
|
||||||
|
'/dns4/wss1.bootstrap.libp2p.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
|
||||||
]
|
]
|
||||||
|
|
||||||
class Node extends libp2p {
|
class Node extends libp2p {
|
||||||
|
@ -53,7 +53,7 @@ parallel([
|
|||||||
(cb) => node1.dial(node2.peerInfo, cb),
|
(cb) => node1.dial(node2.peerInfo, cb),
|
||||||
(cb) => node2.dial(node3.peerInfo, cb),
|
(cb) => node2.dial(node3.peerInfo, cb),
|
||||||
// Set up of the cons might take time
|
// Set up of the cons might take time
|
||||||
(cb) => setTimeout(cb, 100)
|
(cb) => setTimeout(cb, 300)
|
||||||
], (err) => {
|
], (err) => {
|
||||||
if (err) { throw err }
|
if (err) { throw err }
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ parallel([
|
|||||||
(cb) => node1.dial(node2.peerInfo, cb),
|
(cb) => node1.dial(node2.peerInfo, cb),
|
||||||
(cb) => node2.dial(node3.peerInfo, cb),
|
(cb) => node2.dial(node3.peerInfo, cb),
|
||||||
// Set up of the cons might take time
|
// Set up of the cons might take time
|
||||||
(cb) => setTimeout(cb, 100)
|
(cb) => setTimeout(cb, 300)
|
||||||
], (err) => {
|
], (err) => {
|
||||||
if (err) { throw err }
|
if (err) { throw err }
|
||||||
|
|
||||||
|
@ -74,10 +74,10 @@ parallel([
|
|||||||
if (err) { throw err }
|
if (err) { throw err }
|
||||||
console.log('Addresses by which both peers are connected')
|
console.log('Addresses by which both peers are connected')
|
||||||
node1.peerBook
|
node1.peerBook
|
||||||
.getAllArray()
|
.getAllArray()
|
||||||
.forEach((peer) => console.log('node 1 to node 2:', peer.isConnected().toString()))
|
.forEach((peer) => console.log('node 1 to node 2:', peer.isConnected().toString()))
|
||||||
node2.peerBook
|
node2.peerBook
|
||||||
.getAllArray()
|
.getAllArray()
|
||||||
.forEach((peer) => console.log('node 2 to node 1:', peer.isConnected().toString()))
|
.forEach((peer) => console.log('node 2 to node 1:', peer.isConnected().toString()))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
60
package.json
60
package.json
@ -1,19 +1,19 @@
|
|||||||
{
|
{
|
||||||
"name": "libp2p",
|
"name": "libp2p",
|
||||||
"version": "0.12.3",
|
"version": "0.13.0",
|
||||||
"description": "JavaScript base class for libp2p bundles",
|
"description": "JavaScript base class for libp2p bundles",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "gulp test",
|
"lint": "aegir lint",
|
||||||
"test:node": "gulp test:node",
|
"build": "aegir build",
|
||||||
"test:browser": "gulp test:browser --dom",
|
"test": "aegir test --target node --target browser --no-parallel",
|
||||||
"release": "gulp release --dom",
|
"test:node": "aegir test --target node --no-parallel",
|
||||||
"release-minor": "gulp release --type minor --dom",
|
"test:browser": "aegir test --target browser --no-parallel",
|
||||||
"release-major": "gulp release --type major --dom",
|
"release": "aegir test release --target node --target browser --no-parallel",
|
||||||
"build": "gulp build",
|
"release-minor": "aegir release --type minor --target node --target browser --no-parallel",
|
||||||
"lint": "aegir-lint",
|
"release-major": "aegir release --type major --target node --target browser --no-parallel",
|
||||||
"coverage": "aegir-coverage",
|
"coverage": "aegir coverage",
|
||||||
"coverage-publish": "aegir-coverage publish"
|
"coverage-publish": "aegir coverage --provider coveralls"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -39,46 +39,52 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.5.0",
|
"async": "^2.5.0",
|
||||||
"libp2p-ping": "~0.6.0",
|
"libp2p-ping": "~0.6.0",
|
||||||
"libp2p-swarm": "~0.32.2",
|
"libp2p-swarm": "~0.33.0",
|
||||||
"mafmt": "^3.0.1",
|
"mafmt": "^3.0.2",
|
||||||
"multiaddr": "^3.0.1",
|
"multiaddr": "^3.0.1",
|
||||||
"peer-book": "~0.5.0",
|
"peer-book": "~0.5.1",
|
||||||
"peer-id": "~0.10.0",
|
"peer-id": "~0.10.2",
|
||||||
"peer-info": "~0.11.0"
|
"peer-info": "~0.11.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"aegir": "^11.0.2",
|
"aegir": "^12.1.1",
|
||||||
"chai": "^4.1.2",
|
"chai": "^4.1.2",
|
||||||
|
"cids": "~0.5.2",
|
||||||
"dirty-chai": "^2.0.1",
|
"dirty-chai": "^2.0.1",
|
||||||
"cids": "~0.5.1",
|
"electron-webrtc": "~0.3.0",
|
||||||
"libp2p-kad-dht": "~0.5.0",
|
"libp2p-circuit": "~0.1.3",
|
||||||
"libp2p-mdns": "~0.9.0",
|
"libp2p-kad-dht": "~0.5.1",
|
||||||
|
"libp2p-mdns": "~0.9.1",
|
||||||
"libp2p-multiplex": "~0.5.0",
|
"libp2p-multiplex": "~0.5.0",
|
||||||
"libp2p-railing": "~0.7.0",
|
"libp2p-railing": "~0.7.1",
|
||||||
"libp2p-secio": "~0.8.1",
|
"libp2p-secio": "~0.8.1",
|
||||||
"libp2p-spdy": "~0.11.0",
|
"libp2p-spdy": "~0.11.0",
|
||||||
"libp2p-tcp": "~0.11.0",
|
"libp2p-tcp": "~0.11.1",
|
||||||
"libp2p-webrtc-star": "~0.13.1",
|
"libp2p-webrtc-star": "~0.13.2",
|
||||||
"libp2p-websockets": "~0.10.1",
|
"libp2p-websockets": "~0.10.4",
|
||||||
"lodash.times": "^4.3.2",
|
"lodash.times": "^4.3.2",
|
||||||
"pre-commit": "^1.2.2",
|
"pre-commit": "^1.2.2",
|
||||||
"pull-goodbye": "0.0.2",
|
"pull-goodbye": "0.0.2",
|
||||||
"pull-serializer": "^0.3.2",
|
"pull-serializer": "~0.3.2",
|
||||||
"pull-stream": "^3.6.0",
|
"pull-stream": "^3.6.1",
|
||||||
"safe-buffer": "^5.1.1",
|
"safe-buffer": "^5.1.1",
|
||||||
"electron-webrtc": "^0.3.0",
|
"sinon": "^4.0.2",
|
||||||
"wrtc": "0.0.62"
|
"wrtc": "0.0.62"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Chris Bratlien <chrisbratlien@gmail.com>",
|
"Chris Bratlien <chrisbratlien@gmail.com>",
|
||||||
"Daijiro Wachi <daijiro.wachi@gmail.com>",
|
"Daijiro Wachi <daijiro.wachi@gmail.com>",
|
||||||
"David Dias <daviddias.p@gmail.com>",
|
"David Dias <daviddias.p@gmail.com>",
|
||||||
|
"Dmitriy Ryajov <dryajov@gmail.com>",
|
||||||
"Elven <mon.samuel@qq.com>",
|
"Elven <mon.samuel@qq.com>",
|
||||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||||
|
"Lars Gierth <lgierth@users.noreply.github.com>",
|
||||||
|
"Nuno Nogueira <nunofmn@gmail.com>",
|
||||||
"Pedro Teixeira <i@pgte.me>",
|
"Pedro Teixeira <i@pgte.me>",
|
||||||
"RasmusErik Voel Jensen <github@solsort.com>",
|
"RasmusErik Voel Jensen <github@solsort.com>",
|
||||||
"Richard Littauer <richard.littauer@gmail.com>",
|
"Richard Littauer <richard.littauer@gmail.com>",
|
||||||
|
"Ryan Bell <ryan@piing.net>",
|
||||||
"greenkeeperio-bot <support@greenkeeper.io>",
|
"greenkeeperio-bot <support@greenkeeper.io>",
|
||||||
"mayerwin <mayerwin@users.noreply.github.com>"
|
"mayerwin <mayerwin@users.noreply.github.com>"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ const Swarm = require('libp2p-swarm')
|
|||||||
const PeerId = require('peer-id')
|
const PeerId = require('peer-id')
|
||||||
const PeerInfo = require('peer-info')
|
const PeerInfo = require('peer-info')
|
||||||
const PeerBook = require('peer-book')
|
const PeerBook = require('peer-book')
|
||||||
const mafmt = require('mafmt')
|
|
||||||
const multiaddr = require('multiaddr')
|
const multiaddr = require('multiaddr')
|
||||||
|
|
||||||
exports = module.exports
|
exports = module.exports
|
||||||
@ -43,6 +42,9 @@ class Node extends EventEmitter {
|
|||||||
// If muxer exists, we can use Identify
|
// If muxer exists, we can use Identify
|
||||||
this.swarm.connection.reuse()
|
this.swarm.connection.reuse()
|
||||||
|
|
||||||
|
// If muxer exists, we can use Relay for listening/dialing
|
||||||
|
this.swarm.connection.enableCircuitRelay(_options.relay)
|
||||||
|
|
||||||
// Received incommind dial and muxer upgrade happened,
|
// Received incommind dial and muxer upgrade happened,
|
||||||
// reuse this muxed connection
|
// reuse this muxed connection
|
||||||
this.swarm.on('peer-mux-established', (peerInfo) => {
|
this.swarm.on('peer-mux-established', (peerInfo) => {
|
||||||
@ -155,7 +157,7 @@ class Node extends EventEmitter {
|
|||||||
const maOld = []
|
const maOld = []
|
||||||
const maNew = []
|
const maNew = []
|
||||||
this.peerInfo.multiaddrs.forEach((ma) => {
|
this.peerInfo.multiaddrs.forEach((ma) => {
|
||||||
if (!mafmt.IPFS.matches(ma)) {
|
if (!ma.getPeerId()) {
|
||||||
maOld.push(ma)
|
maOld.push(ma)
|
||||||
maNew.push(ma.encapsulate('/ipfs/' + this.peerInfo.id.toB58String()))
|
maNew.push(ma.encapsulate('/ipfs/' + this.peerInfo.id.toB58String()))
|
||||||
}
|
}
|
||||||
|
@ -8,3 +8,4 @@ require('./nodejs-bundle/stream-muxing')
|
|||||||
require('./nodejs-bundle/discovery')
|
require('./nodejs-bundle/discovery')
|
||||||
require('./nodejs-bundle/peer-routing')
|
require('./nodejs-bundle/peer-routing')
|
||||||
require('./nodejs-bundle/content-routing')
|
require('./nodejs-bundle/content-routing')
|
||||||
|
require('./nodejs-bundle/circuit')
|
||||||
|
223
test/nodejs-bundle/circuit.js
Normal file
223
test/nodejs-bundle/circuit.js
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
/* eslint-env mocha */
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const pull = require('pull-stream')
|
||||||
|
const waterfall = require('async/waterfall')
|
||||||
|
const series = require('async/series')
|
||||||
|
const parallel = require('async/parallel')
|
||||||
|
const utils = require('./utils')
|
||||||
|
const Circuit = require('libp2p-circuit')
|
||||||
|
const multiaddr = require('multiaddr')
|
||||||
|
|
||||||
|
const chai = require('chai')
|
||||||
|
chai.use(require('dirty-chai'))
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
const sinon = require('sinon')
|
||||||
|
|
||||||
|
describe(`circuit`, function () {
|
||||||
|
let handlerSpies = []
|
||||||
|
let relayNode1
|
||||||
|
let relayNode2
|
||||||
|
let nodeWS1
|
||||||
|
let nodeWS2
|
||||||
|
let nodeTCP1
|
||||||
|
let nodeTCP2
|
||||||
|
|
||||||
|
function setupNode (addrs, options, cb) {
|
||||||
|
if (typeof options === 'function') {
|
||||||
|
cb = options
|
||||||
|
options = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
options = options || {}
|
||||||
|
|
||||||
|
return utils.createNode(addrs, options, (err, node) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
|
node.handle('/echo/1.0.0', utils.echo)
|
||||||
|
node.start((err) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
|
handlerSpies.push(sinon.spy(node.swarm.transports[Circuit.tag].listeners[0].hopHandler, 'handle'))
|
||||||
|
cb(node)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
before(function (done) {
|
||||||
|
this.timeout(20000)
|
||||||
|
|
||||||
|
waterfall([
|
||||||
|
// set up passive relay
|
||||||
|
(cb) => setupNode([
|
||||||
|
`/ip4/0.0.0.0/tcp/0/ws`,
|
||||||
|
`/ip4/0.0.0.0/tcp/0`
|
||||||
|
], {
|
||||||
|
relay: {
|
||||||
|
enabled: true,
|
||||||
|
hop: {
|
||||||
|
enabled: true,
|
||||||
|
active: false // passive relay
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, (node) => {
|
||||||
|
relayNode1 = node
|
||||||
|
cb()
|
||||||
|
}),
|
||||||
|
// setup active relay
|
||||||
|
(cb) => setupNode([
|
||||||
|
`/ip4/0.0.0.0/tcp/0/ws`,
|
||||||
|
`/ip4/0.0.0.0/tcp/0`
|
||||||
|
], {
|
||||||
|
relay: {
|
||||||
|
enabled: true,
|
||||||
|
hop: {
|
||||||
|
enabled: true,
|
||||||
|
active: false // passive relay
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, (node) => {
|
||||||
|
relayNode2 = node
|
||||||
|
cb()
|
||||||
|
}),
|
||||||
|
// setup node with WS
|
||||||
|
(cb) => setupNode([
|
||||||
|
`/ip4/0.0.0.0/tcp/0/ws`
|
||||||
|
], {
|
||||||
|
relay: {
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
}, (node) => {
|
||||||
|
nodeWS1 = node
|
||||||
|
cb()
|
||||||
|
}),
|
||||||
|
// setup node with WS
|
||||||
|
(cb) => setupNode([
|
||||||
|
`/ip4/0.0.0.0/tcp/0/ws`
|
||||||
|
], {
|
||||||
|
relay: {
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
}, (node) => {
|
||||||
|
nodeWS2 = node
|
||||||
|
cb()
|
||||||
|
}),
|
||||||
|
// set up node with TCP and listening on relay1
|
||||||
|
(cb) => setupNode([
|
||||||
|
`/ip4/0.0.0.0/tcp/0`,
|
||||||
|
`/ipfs/${relayNode1.peerInfo.id.toB58String()}/p2p-circuit`
|
||||||
|
], {
|
||||||
|
relay: {
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
}, (node) => {
|
||||||
|
nodeTCP1 = node
|
||||||
|
cb()
|
||||||
|
}),
|
||||||
|
// set up node with TCP and listening on relay2 over TCP transport
|
||||||
|
(cb) => setupNode([
|
||||||
|
`/ip4/0.0.0.0/tcp/0`,
|
||||||
|
`/ip4/0.0.0.0/tcp/0/ipfs/${relayNode2.peerInfo.id.toB58String()}/p2p-circuit`
|
||||||
|
], {
|
||||||
|
relay: {
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
}, (node) => {
|
||||||
|
nodeTCP2 = node
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
], (err) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
|
series([
|
||||||
|
(cb) => nodeWS1.dial(relayNode1.peerInfo, cb),
|
||||||
|
(cb) => nodeWS1.dial(relayNode2.peerInfo, cb),
|
||||||
|
(cb) => nodeTCP1.dial(relayNode1.peerInfo, cb),
|
||||||
|
(cb) => nodeTCP2.dial(relayNode2.peerInfo, cb)
|
||||||
|
], done)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
after((done) => {
|
||||||
|
parallel([
|
||||||
|
(cb) => relayNode1.stop(cb),
|
||||||
|
(cb) => relayNode2.stop(cb),
|
||||||
|
(cb) => nodeWS1.stop(cb),
|
||||||
|
(cb) => nodeWS2.stop(cb),
|
||||||
|
(cb) => nodeTCP1.stop(cb),
|
||||||
|
(cb) => nodeTCP2.stop(cb)
|
||||||
|
], done)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe(`any relay`, function () {
|
||||||
|
this.timeout(20000)
|
||||||
|
it('should dial from WS1 to TCP1 over any R', function (done) {
|
||||||
|
nodeWS1.dial(nodeTCP1.peerInfo, '/echo/1.0.0', (err, conn) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
expect(conn).to.exist()
|
||||||
|
|
||||||
|
pull(
|
||||||
|
pull.values(['hello']),
|
||||||
|
conn,
|
||||||
|
pull.collect((e, result) => {
|
||||||
|
expect(e).to.not.exist()
|
||||||
|
expect(result[0].toString()).to.equal('hello')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it(`should not dial - no R from WS2 to TCP1`, function (done) {
|
||||||
|
nodeWS2.dial(nodeTCP2.peerInfo, '/echo/1.0.0', (err, conn) => {
|
||||||
|
expect(err).to.exist()
|
||||||
|
expect(conn).to.not.exist()
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe(`explicit relay`, function () {
|
||||||
|
this.timeout(20000)
|
||||||
|
it('should dial from WS1 to TCP1 over R1', function (done) {
|
||||||
|
nodeWS1.dial(nodeTCP1.peerInfo, '/echo/1.0.0', (err, conn) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
expect(conn).to.exist()
|
||||||
|
|
||||||
|
pull(
|
||||||
|
pull.values(['hello']),
|
||||||
|
conn,
|
||||||
|
pull.collect((e, result) => {
|
||||||
|
expect(e).to.not.exist()
|
||||||
|
expect(result[0].toString()).to.equal('hello')
|
||||||
|
|
||||||
|
const addr = multiaddr(handlerSpies[0].args[2][0].dstPeer.addrs[0]).toString()
|
||||||
|
expect(addr).to.equal(`/ipfs/${nodeTCP1.peerInfo.id.toB58String()}`)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it(`should dial from WS1 to TCP2 over R2`, function (done) {
|
||||||
|
nodeWS1.dial(nodeTCP2.peerInfo, '/echo/1.0.0', (err, conn) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
expect(conn).to.exist()
|
||||||
|
|
||||||
|
pull(
|
||||||
|
pull.values(['hello']),
|
||||||
|
conn,
|
||||||
|
pull.collect((e, result) => {
|
||||||
|
expect(e).to.not.exist()
|
||||||
|
expect(result[0].toString()).to.equal('hello')
|
||||||
|
|
||||||
|
const addr = multiaddr(handlerSpies[1].args[2][0].dstPeer.addrs[0]).toString()
|
||||||
|
expect(addr).to.equal(`/ipfs/${nodeTCP2.peerInfo.id.toB58String()}`)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
@ -19,7 +19,8 @@ describe('.contentRouting', () => {
|
|||||||
let nodeD
|
let nodeD
|
||||||
let nodeE
|
let nodeE
|
||||||
|
|
||||||
before((done) => {
|
before(function (done) {
|
||||||
|
this.timeout(5000)
|
||||||
const tasks = _times(5, () => (cb) => {
|
const tasks = _times(5, () => (cb) => {
|
||||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||||
mdns: false,
|
mdns: false,
|
||||||
|
@ -60,7 +60,8 @@ describe('discovery', () => {
|
|||||||
describe('MulticastDNS', () => {
|
describe('MulticastDNS', () => {
|
||||||
setup({ mdns: true })
|
setup({ mdns: true })
|
||||||
|
|
||||||
it('find a peer', (done) => {
|
it('find a peer', function (done) {
|
||||||
|
this.timeout(15000)
|
||||||
nodeA.once('peer:discovery', (peerInfo) => {
|
nodeA.once('peer:discovery', (peerInfo) => {
|
||||||
expect(nodeB.peerInfo.id.toB58String())
|
expect(nodeB.peerInfo.id.toB58String())
|
||||||
.to.eql(peerInfo.id.toB58String())
|
.to.eql(peerInfo.id.toB58String())
|
||||||
@ -73,7 +74,8 @@ describe('discovery', () => {
|
|||||||
describe.skip('WebRTCStar', () => {
|
describe.skip('WebRTCStar', () => {
|
||||||
setup({ webRTCStar: true })
|
setup({ webRTCStar: true })
|
||||||
|
|
||||||
it('find a peer', (done) => {
|
it('find a peer', function (done) {
|
||||||
|
this.timeout(15000)
|
||||||
nodeA.once('peer:discovery', (peerInfo) => {
|
nodeA.once('peer:discovery', (peerInfo) => {
|
||||||
expect(nodeB.peerInfo.id.toB58String())
|
expect(nodeB.peerInfo.id.toB58String())
|
||||||
.to.eql(peerInfo.id.toB58String())
|
.to.eql(peerInfo.id.toB58String())
|
||||||
@ -88,7 +90,8 @@ describe('discovery', () => {
|
|||||||
mdns: true
|
mdns: true
|
||||||
})
|
})
|
||||||
|
|
||||||
it('find a peer', (done) => {
|
it('find a peer', function (done) {
|
||||||
|
this.timeout(15000)
|
||||||
nodeA.once('peer:discovery', (peerInfo) => {
|
nodeA.once('peer:discovery', (peerInfo) => {
|
||||||
expect(nodeB.peerInfo.id.toB58String())
|
expect(nodeB.peerInfo.id.toB58String())
|
||||||
.to.eql(peerInfo.id.toB58String())
|
.to.eql(peerInfo.id.toB58String())
|
||||||
|
@ -18,7 +18,8 @@ describe('.peerRouting', () => {
|
|||||||
let nodeD
|
let nodeD
|
||||||
let nodeE
|
let nodeE
|
||||||
|
|
||||||
before((done) => {
|
before(function (done) {
|
||||||
|
this.timeout(5000)
|
||||||
const tasks = _times(5, () => (cb) => {
|
const tasks = _times(5, () => (cb) => {
|
||||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||||
mdns: false,
|
mdns: false,
|
||||||
|
@ -16,11 +16,11 @@ function test (nodeA, nodeB, callback) {
|
|||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
pull.values([new Buffer('hey')]),
|
pull.values([Buffer.from('hey')]),
|
||||||
conn,
|
conn,
|
||||||
pull.collect((err, data) => {
|
pull.collect((err, data) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
expect(data).to.be.eql([new Buffer('hey')])
|
expect(data).to.be.eql([Buffer.from('hey')])
|
||||||
callback()
|
callback()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -34,8 +34,10 @@ function teardown (nodeA, nodeB, callback) {
|
|||||||
], callback)
|
], callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('stream muxing', (done) => {
|
describe('stream muxing', () => {
|
||||||
it('spdy only', (done) => {
|
it('spdy only', function (done) {
|
||||||
|
this.timeout(5000)
|
||||||
|
|
||||||
let nodeA
|
let nodeA
|
||||||
let nodeB
|
let nodeB
|
||||||
|
|
||||||
@ -99,7 +101,9 @@ describe('stream muxing', (done) => {
|
|||||||
], done)
|
], done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('spdy + multiplex', (done) => {
|
it('spdy + multiplex', function (done) {
|
||||||
|
this.timeout(5000)
|
||||||
|
|
||||||
let nodeA
|
let nodeA
|
||||||
let nodeB
|
let nodeB
|
||||||
|
|
||||||
@ -131,7 +135,9 @@ describe('stream muxing', (done) => {
|
|||||||
], done)
|
], done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('spdy + multiplex switched order', (done) => {
|
it('spdy + multiplex switched order', function (done) {
|
||||||
|
this.timeout(5000)
|
||||||
|
|
||||||
let nodeA
|
let nodeA
|
||||||
let nodeB
|
let nodeB
|
||||||
|
|
||||||
@ -163,7 +169,9 @@ describe('stream muxing', (done) => {
|
|||||||
], done)
|
], done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('one without the other fails to establish a muxedConn', (done) => {
|
it('one without the other fails to establish a muxedConn', function (done) {
|
||||||
|
this.timeout(5000)
|
||||||
|
|
||||||
let nodeA
|
let nodeA
|
||||||
let nodeB
|
let nodeB
|
||||||
|
|
||||||
|
@ -20,7 +20,8 @@ describe('TCP + WebSockets + WebRTCStar', () => {
|
|||||||
|
|
||||||
let ss
|
let ss
|
||||||
|
|
||||||
before((done) => {
|
before(function (done) {
|
||||||
|
this.timeout(5000)
|
||||||
parallel([
|
parallel([
|
||||||
(cb) => {
|
(cb) => {
|
||||||
signalling.start({ port: 24642 }, (err, server) => {
|
signalling.start({ port: 24642 }, (err, server) => {
|
||||||
@ -194,7 +195,8 @@ describe('TCP + WebSockets + WebRTCStar', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('nodeAll.dial nodeWStar using PeerInfo', (done) => {
|
it('nodeAll.dial nodeWStar using PeerInfo', function (done) {
|
||||||
|
this.timeout(10000)
|
||||||
nodeAll.dial(nodeWStar.peerInfo, (err) => {
|
nodeAll.dial(nodeWStar.peerInfo, (err) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
|
@ -70,11 +70,11 @@ describe('TCP only', () => {
|
|||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
pull.values([new Buffer('hey')]),
|
pull.values([Buffer.from('hey')]),
|
||||||
conn,
|
conn,
|
||||||
pull.collect((err, data) => {
|
pull.collect((err, data) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
expect(data).to.be.eql([new Buffer('hey')])
|
expect(data).to.be.eql([Buffer.from('hey')])
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -130,11 +130,11 @@ describe('TCP only', () => {
|
|||||||
}
|
}
|
||||||
], () => {
|
], () => {
|
||||||
pull(
|
pull(
|
||||||
pull.values([new Buffer('hey')]),
|
pull.values([Buffer.from('hey')]),
|
||||||
conn,
|
conn,
|
||||||
pull.collect((err, data) => {
|
pull.collect((err, data) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
expect(data).to.be.eql([new Buffer('hey')])
|
expect(data).to.be.eql([Buffer.from('hey')])
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -193,11 +193,11 @@ describe('TCP only', () => {
|
|||||||
}
|
}
|
||||||
], () => {
|
], () => {
|
||||||
pull(
|
pull(
|
||||||
pull.values([new Buffer('hey')]),
|
pull.values([Buffer.from('hey')]),
|
||||||
conn,
|
conn,
|
||||||
pull.collect((err, data) => {
|
pull.collect((err, data) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
expect(data).to.be.eql([new Buffer('hey')])
|
expect(data).to.be.eql([Buffer.from('hey')])
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -57,11 +57,11 @@ describe('Turbolence tests', () => {
|
|||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
pull.values([new Buffer('hey')]),
|
pull.values([Buffer.from('hey')]),
|
||||||
conn,
|
conn,
|
||||||
pull.collect((err, data) => {
|
pull.collect((err, data) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
expect(data).to.eql([new Buffer('hey')])
|
expect(data).to.eql([Buffer.from('hey')])
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -15,6 +15,8 @@ function createNode (multiaddrs, options, callback) {
|
|||||||
options = {}
|
options = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options = options || {}
|
||||||
|
|
||||||
if (!Array.isArray(multiaddrs)) {
|
if (!Array.isArray(multiaddrs)) {
|
||||||
multiaddrs = [multiaddrs]
|
multiaddrs = [multiaddrs]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user