Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.
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
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,26 @@
"homepage": "https://github.com/ipfs/js-libp2p-ipfs-nodejs#readme",
"devDependencies": {
"aegir": "^11.0.2",
"async": "^2.4.0",
"chai": "^3.5.0",
"async": "^2.5.0",
"chai": "^4.0.2",
"cids": "^0.5.0",
"dirty-chai": "^1.2.2",
"dirty-chai": "^2.0.0",
"lodash.times": "^4.3.2",
"pre-commit": "^1.2.2",
"pull-stream": "^3.6.0"
"pull-stream": "^3.6.0",
"wrtc": "0.0.62"
},
"dependencies": {
"libp2p": "~0.9.1",
"libp2p-kad-dht": "~0.1.0",
"libp2p-mdns": "~0.7.0",
"libp2p-multiplex": "~0.4.3",
"libp2p-railing": "~0.5.0",
"libp2p-railing": "~0.5.1",
"libp2p-secio": "~0.6.8",
"libp2p-spdy": "~0.10.6",
"libp2p-swarm": "~0.29.1",
"libp2p-tcp": "~0.10.1",
"libp2p-webrtc-star": "~0.10.0",
"libp2p-webrtc-star": "~0.11.0",
"libp2p-websockets": "~0.10.0",
"mafmt": "^2.1.8",
"multiaddr": "^2.3.0",
Expand All @@ -76,4 +77,4 @@
"kumavis <[email protected]>",
"varunagarwal315 <[email protected]>"
]
}
}
18 changes: 9 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'

const TCP = require('libp2p-tcp')
// const UTP = require('libp2p-utp')
const WebRTCStar = require('libp2p-webrtc-star')
const MulticastDNS = require('libp2p-mdns')
const WS = require('libp2p-websockets')
const Railing = require('libp2p-railing')
Expand Down Expand Up @@ -40,13 +38,11 @@ function getMuxers (muxers) {
class Node extends libp2p {
constructor (peerInfo, peerBook, options) {
options = options || {}
const webRTCStar = new WebRTCStar()

const modules = {
transport: [
new TCP(),
new WS(),
webRTCStar
new WS()
],
connection: {
muxer: getMuxers(options.muxer),
Expand All @@ -55,10 +51,6 @@ class Node extends libp2p {
discovery: []
}

if (options.webRTCStar) {
modules.discovery.push(webRTCStar.discovery)
}

if (options.dht) {
modules.DHT = KadDHT
}
Expand All @@ -73,6 +65,14 @@ class Node extends libp2p {
modules.discovery.push(r)
}

if (options.modules && options.modules.transport) {
options.modules.transport.forEach((t) => modules.transport.push(t))
}

if (options.modules && options.modules.discovery) {
options.modules.discovery.forEach((d) => modules.discovery.push(d))
}

super(modules, peerInfo, peerBook, options)
}
}
Expand Down
57 changes: 39 additions & 18 deletions test/tcp+websockets+webrtc-star.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ chai.use(require('dirty-chai'))
const expect = chai.expect
const parallel = require('async/parallel')
const signalling = require('libp2p-webrtc-star/src/sig-server')
const WStar = require('libp2p-webrtc-star')
const wrtc = require('wrtc')
const utils = require('./utils')
const createNode = utils.createNode
const echo = utils.echo
Expand All @@ -27,16 +29,25 @@ describe('TCP + WebSockets + WebRTCStar', () => {
cb()
})
},
(cb) => createNode([
'/ip4/0.0.0.0/tcp/0',
'/ip4/127.0.0.1/tcp/25011/ws',
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws'
], (err, node) => {
expect(err).to.not.exist()
nodeAll = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
}),
(cb) => {
const wstar = new WStar({wrtc: wrtc})

createNode([
'/ip4/0.0.0.0/tcp/0',
'/ip4/127.0.0.1/tcp/25011/ws',
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws'
], {
modules: {
transport: [wstar],
discovery: [wstar.discovery]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeAll = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
})
},
(cb) => createNode([
'/ip4/0.0.0.0/tcp/0'
], (err, node) => {
Expand All @@ -53,14 +64,24 @@ describe('TCP + WebSockets + WebRTCStar', () => {
node.handle('/echo/1.0.0', echo)
node.start(cb)
}),
(cb) => createNode([
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws'
], (err, node) => {
expect(err).to.not.exist()
nodeWStar = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
})

(cb) => {
const wstar = new WStar({wrtc: wrtc})

createNode([
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws'
], {
modules: {
transport: [wstar],
discovery: [wstar.discovery]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeWStar = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
})
}
], done)
})

Expand Down