mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-13 01:01:23 +00:00
feat: enable and test Circuit Relay
* feat: new super simplified API * feat: append peer id to multiaddr if not there * [WIP] Awesome DHT (#86) * feat: integrate dht * better interfaces * docs: add documentation for peerRouting, contentRouting, dht * fix: take in passed datastore * fix: update usage of _getPeerInfo * fix: getPeerInfo * docs: update docs * moar feat: correctly handle p2p-circuit addrs when creating a peer info object refactor: rework config options * feat: adding circuit relaying * feat: rework circuit relay for protobufs * feat: circuit loading and tests * fix: clean up _getPeerInfo to work with /p2p-circuit * wip: tests cleaup * test: clean up * wip * fix: bringing back test reworks and new aegir * test: group tests * test: clean up * test: adjust test * fix: use getPeerId to determine if the ipfs fragment is missing * feat: adding circuit relaying * feat: circuit loading and tests * test: clean up * wip * feat: upgrade to latest aegir * fix: removing unused tests * feat: cleanup tests * fix: create node defautl options * chore: upgrade swarm to latest version * fix: updated aegir and adjust timeouts * feat: more timeouts * chore: updating deps * fix: circle ci builds * test: timeouts
This commit is contained in:
committed by
David Dias
parent
2504cbeb26
commit
29cc0afc64
@ -8,3 +8,4 @@ require('./nodejs-bundle/stream-muxing')
|
||||
require('./nodejs-bundle/discovery')
|
||||
require('./nodejs-bundle/peer-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 nodeE
|
||||
|
||||
before((done) => {
|
||||
before(function (done) {
|
||||
this.timeout(5000)
|
||||
const tasks = _times(5, () => (cb) => {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||
mdns: false,
|
||||
|
@ -60,7 +60,8 @@ describe('discovery', () => {
|
||||
describe('MulticastDNS', () => {
|
||||
setup({ mdns: true })
|
||||
|
||||
it('find a peer', (done) => {
|
||||
it('find a peer', function (done) {
|
||||
this.timeout(15000)
|
||||
nodeA.once('peer:discovery', (peerInfo) => {
|
||||
expect(nodeB.peerInfo.id.toB58String())
|
||||
.to.eql(peerInfo.id.toB58String())
|
||||
@ -73,7 +74,8 @@ describe('discovery', () => {
|
||||
describe.skip('WebRTCStar', () => {
|
||||
setup({ webRTCStar: true })
|
||||
|
||||
it('find a peer', (done) => {
|
||||
it('find a peer', function (done) {
|
||||
this.timeout(15000)
|
||||
nodeA.once('peer:discovery', (peerInfo) => {
|
||||
expect(nodeB.peerInfo.id.toB58String())
|
||||
.to.eql(peerInfo.id.toB58String())
|
||||
@ -88,7 +90,8 @@ describe('discovery', () => {
|
||||
mdns: true
|
||||
})
|
||||
|
||||
it('find a peer', (done) => {
|
||||
it('find a peer', function (done) {
|
||||
this.timeout(15000)
|
||||
nodeA.once('peer:discovery', (peerInfo) => {
|
||||
expect(nodeB.peerInfo.id.toB58String())
|
||||
.to.eql(peerInfo.id.toB58String())
|
||||
|
@ -18,7 +18,8 @@ describe('.peerRouting', () => {
|
||||
let nodeD
|
||||
let nodeE
|
||||
|
||||
before((done) => {
|
||||
before(function (done) {
|
||||
this.timeout(5000)
|
||||
const tasks = _times(5, () => (cb) => {
|
||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||
mdns: false,
|
||||
|
@ -16,11 +16,11 @@ function test (nodeA, nodeB, callback) {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
pull(
|
||||
pull.values([new Buffer('hey')]),
|
||||
pull.values([Buffer.from('hey')]),
|
||||
conn,
|
||||
pull.collect((err, data) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(data).to.be.eql([new Buffer('hey')])
|
||||
expect(data).to.be.eql([Buffer.from('hey')])
|
||||
callback()
|
||||
})
|
||||
)
|
||||
@ -34,8 +34,10 @@ function teardown (nodeA, nodeB, callback) {
|
||||
], callback)
|
||||
}
|
||||
|
||||
describe('stream muxing', (done) => {
|
||||
it('spdy only', (done) => {
|
||||
describe('stream muxing', () => {
|
||||
it('spdy only', function (done) {
|
||||
this.timeout(5000)
|
||||
|
||||
let nodeA
|
||||
let nodeB
|
||||
|
||||
@ -99,7 +101,9 @@ describe('stream muxing', (done) => {
|
||||
], done)
|
||||
})
|
||||
|
||||
it('spdy + multiplex', (done) => {
|
||||
it('spdy + multiplex', function (done) {
|
||||
this.timeout(5000)
|
||||
|
||||
let nodeA
|
||||
let nodeB
|
||||
|
||||
@ -131,7 +135,9 @@ describe('stream muxing', (done) => {
|
||||
], done)
|
||||
})
|
||||
|
||||
it('spdy + multiplex switched order', (done) => {
|
||||
it('spdy + multiplex switched order', function (done) {
|
||||
this.timeout(5000)
|
||||
|
||||
let nodeA
|
||||
let nodeB
|
||||
|
||||
@ -163,7 +169,9 @@ describe('stream muxing', (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 nodeB
|
||||
|
||||
|
@ -20,7 +20,8 @@ describe('TCP + WebSockets + WebRTCStar', () => {
|
||||
|
||||
let ss
|
||||
|
||||
before((done) => {
|
||||
before(function (done) {
|
||||
this.timeout(5000)
|
||||
parallel([
|
||||
(cb) => {
|
||||
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) => {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
|
@ -70,11 +70,11 @@ describe('TCP only', () => {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
pull(
|
||||
pull.values([new Buffer('hey')]),
|
||||
pull.values([Buffer.from('hey')]),
|
||||
conn,
|
||||
pull.collect((err, data) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(data).to.be.eql([new Buffer('hey')])
|
||||
expect(data).to.be.eql([Buffer.from('hey')])
|
||||
done()
|
||||
})
|
||||
)
|
||||
@ -130,11 +130,11 @@ describe('TCP only', () => {
|
||||
}
|
||||
], () => {
|
||||
pull(
|
||||
pull.values([new Buffer('hey')]),
|
||||
pull.values([Buffer.from('hey')]),
|
||||
conn,
|
||||
pull.collect((err, data) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(data).to.be.eql([new Buffer('hey')])
|
||||
expect(data).to.be.eql([Buffer.from('hey')])
|
||||
done()
|
||||
})
|
||||
)
|
||||
@ -193,11 +193,11 @@ describe('TCP only', () => {
|
||||
}
|
||||
], () => {
|
||||
pull(
|
||||
pull.values([new Buffer('hey')]),
|
||||
pull.values([Buffer.from('hey')]),
|
||||
conn,
|
||||
pull.collect((err, data) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(data).to.be.eql([new Buffer('hey')])
|
||||
expect(data).to.be.eql([Buffer.from('hey')])
|
||||
done()
|
||||
})
|
||||
)
|
||||
|
@ -57,11 +57,11 @@ describe('Turbolence tests', () => {
|
||||
expect(Object.keys(peers)).to.have.length(1)
|
||||
|
||||
pull(
|
||||
pull.values([new Buffer('hey')]),
|
||||
pull.values([Buffer.from('hey')]),
|
||||
conn,
|
||||
pull.collect((err, data) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(data).to.eql([new Buffer('hey')])
|
||||
expect(data).to.eql([Buffer.from('hey')])
|
||||
done()
|
||||
})
|
||||
)
|
||||
|
@ -15,6 +15,8 @@ function createNode (multiaddrs, options, callback) {
|
||||
options = {}
|
||||
}
|
||||
|
||||
options = options || {}
|
||||
|
||||
if (!Array.isArray(multiaddrs)) {
|
||||
multiaddrs = [multiaddrs]
|
||||
}
|
||||
|
Reference in New Issue
Block a user