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

Commit

Permalink
feat: use new webrtc-star, remove support it by default, support it t…
Browse files Browse the repository at this point in the history
…o be pluggable
  • Loading branch information
daviddias committed Jun 28, 2017
1 parent 822fb6e commit 05dde5b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 33 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
"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",
"electron-webrtc": "^0.3.0",
"lodash.times": "^4.3.2",
"pre-commit": "^1.2.2",
"pull-stream": "^3.6.0"
Expand All @@ -51,12 +52,12 @@
"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 <kumavis@users.noreply.github.com>",
"varunagarwal315 <varunagarwal315@gmail.com>"
]
}
}
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 electronWebRTC = require('electron-webrtc')
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: electronWebRTC()})

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: electronWebRTC()})

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

0 comments on commit 05dde5b

Please sign in to comment.