mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-30 22:31:03 +00:00
* 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
216 lines
5.1 KiB
JavaScript
216 lines
5.1 KiB
JavaScript
/* eslint-env mocha */
|
|
'use strict'
|
|
|
|
const chai = require('chai')
|
|
chai.use(require('dirty-chai'))
|
|
const expect = chai.expect
|
|
const parallel = require('async/parallel')
|
|
const series = require('async/series')
|
|
const pull = require('pull-stream')
|
|
const utils = require('./utils')
|
|
const createNode = utils.createNode
|
|
const echo = utils.echo
|
|
|
|
function test (nodeA, nodeB, callback) {
|
|
nodeA.dial(nodeB.peerInfo, '/echo/1.0.0', (err, conn) => {
|
|
expect(err).to.not.exist()
|
|
|
|
pull(
|
|
pull.values([Buffer.from('hey')]),
|
|
conn,
|
|
pull.collect((err, data) => {
|
|
expect(err).to.not.exist()
|
|
expect(data).to.be.eql([Buffer.from('hey')])
|
|
callback()
|
|
})
|
|
)
|
|
})
|
|
}
|
|
|
|
function teardown (nodeA, nodeB, callback) {
|
|
parallel([
|
|
(cb) => nodeA.stop(cb),
|
|
(cb) => nodeB.stop(cb)
|
|
], callback)
|
|
}
|
|
|
|
describe('stream muxing', () => {
|
|
it('spdy only', function (done) {
|
|
this.timeout(5000)
|
|
|
|
let nodeA
|
|
let nodeB
|
|
|
|
function setup (callback) {
|
|
parallel([
|
|
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
|
|
muxer: ['spdy']
|
|
}, (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', {
|
|
muxer: ['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('multiplex only', (done) => {
|
|
let nodeA
|
|
let nodeB
|
|
|
|
function setup (callback) {
|
|
parallel([
|
|
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
|
|
muxer: ['multiplex']
|
|
}, (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', {
|
|
muxer: ['multiplex']
|
|
}, (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 + multiplex', function (done) {
|
|
this.timeout(5000)
|
|
|
|
let nodeA
|
|
let nodeB
|
|
|
|
function setup (callback) {
|
|
parallel([
|
|
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
|
|
muxer: ['spdy', 'multiplex']
|
|
}, (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', {
|
|
muxer: ['spdy', 'multiplex']
|
|
}, (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 + multiplex switched order', function (done) {
|
|
this.timeout(5000)
|
|
|
|
let nodeA
|
|
let nodeB
|
|
|
|
function setup (callback) {
|
|
parallel([
|
|
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
|
|
muxer: ['spdy', 'multiplex']
|
|
}, (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', {
|
|
muxer: ['multiplex', '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(5000)
|
|
|
|
let nodeA
|
|
let nodeB
|
|
|
|
function setup (callback) {
|
|
parallel([
|
|
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
|
|
muxer: ['spdy']
|
|
}, (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', {
|
|
muxer: ['multiplex']
|
|
}, (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) => {
|
|
// it will just 'warm up a conn'
|
|
expect(Object.keys(nodeA.swarm.muxers)).to.have.length(1)
|
|
expect(Object.keys(nodeB.swarm.muxers)).to.have.length(1)
|
|
|
|
nodeA.dial(nodeB.peerInfo, (err) => {
|
|
expect(err).to.not.exist()
|
|
expect(Object.keys(nodeA.swarm.muxedConns)).to.have.length(0)
|
|
cb()
|
|
})
|
|
},
|
|
(cb) => teardown(nodeA, nodeB, cb)
|
|
], done)
|
|
})
|
|
})
|