Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Advanced peer-book #91

Merged
merged 8 commits into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@
"pull-stream": "^3.5.0"
},
"dependencies": {
"libp2p": "~0.7.0",
"libp2p-mdns": "~0.6.2",
"libp2p": "~0.8.0",
"libp2p-mdns": "~0.7.0",
"libp2p-multiplex": "~0.4.3",
"libp2p-railing": "~0.4.3",
"libp2p-railing": "~0.5.0",
"libp2p-secio": "~0.6.8",
"libp2p-spdy": "~0.10.6",
"libp2p-swarm": "~0.28.0",
"libp2p-swarm": "~0.29.0",
"libp2p-tcp": "~0.10.0",
"libp2p-webrtc-star": "~0.8.10",
"libp2p-webrtc-star": "~0.9.0",
"libp2p-websockets": "~0.10.0",
"mafmt": "^2.1.8",
"multiaddr": "^2.3.0",
"peer-book": "~0.3.2",
"peer-id": "~0.8.5",
"peer-info": "~0.8.5"
"peer-book": "~0.4.0",
"peer-id": "~0.8.6",
"peer-info": "~0.9.2"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
Expand Down
16 changes: 7 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@ function mapMuxers (list) {
return pref
}
switch (pref.trim().toLowerCase()) {
case 'spdy':
return spdy
case 'multiplex':
return multiplex
case 'spdy': return spdy
case 'multiplex': return multiplex
default:
throw new Error(pref + ' muxer not available')
}
})
}

function getMuxers (options) {
if (process.env.LIBP2P_MUXER) {
const muxerPrefs = process.env.LIBP2P_MUXER
function getMuxers (muxers) {
const muxerPrefs = process.env.LIBP2P_MUXER
if (muxerPrefs && !muxers) {
return mapMuxers(muxerPrefs.split(','))
} else if (options) {
return mapMuxers(options)
} else if (muxers) {
return mapMuxers(muxers)
} else {
return [multiplex, spdy]
}
Expand Down
97 changes: 97 additions & 0 deletions test/discovery.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const signalling = require('libp2p-webrtc-star/src/sig-server')
const parallel = require('async/parallel')
const utils = require('./utils')
const createNode = utils.createNode
const echo = utils.echo

describe('discovery', () => {
let nodeA
let nodeB
let ss

function setup (options) {
before((done) => {
parallel([
(cb) => {
signalling.start({ port: 24642 }, (err, server) => {
expect(err).to.not.exist()
ss = server
cb()
})
},
(cb) => createNode([
'/ip4/0.0.0.0/tcp/0',
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws'
], options, (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',
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws'
], options, (err, node) => {
expect(err).to.not.exist()
nodeB = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
})
], done)
})

after((done) => {
parallel([
(cb) => nodeA.stop(cb),
(cb) => nodeB.stop(cb),
(cb) => ss.stop(done)
], done)
})
}

describe('MulticastDNS', () => {
setup({ mdns: true })

it('find a peer', (done) => {
nodeA.once('peer:discovery', (peerInfo) => {
expect(nodeB.peerInfo.id.toB58String())
.to.eql(peerInfo.id.toB58String())
done()
})
})
})

// TODO needs a delay (this test is already long)
describe.skip('WebRTCStar', () => {
setup({ webRTCStar: true })

it('find a peer', (done) => {
nodeA.once('peer:discovery', (peerInfo) => {
expect(nodeB.peerInfo.id.toB58String())
.to.eql(peerInfo.id.toB58String())
done()
})
})
})

describe('MulticastDNS + WebRTCStar', () => {
setup({
webRTCStar: true,
mdns: true
})

it('find a peer', (done) => {
nodeA.once('peer:discovery', (peerInfo) => {
expect(nodeB.peerInfo.id.toB58String())
.to.eql(peerInfo.id.toB58String())
done()
})
})
})
})
Loading