Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: issue #905 (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Jul 10, 2017
1 parent 7889d59 commit cbcf90e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 217 deletions.
137 changes: 0 additions & 137 deletions examples/transfer-files/package-lock.json

This file was deleted.

4 changes: 1 addition & 3 deletions examples/transfer-files/public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ function start () {
if (!node) {
updateView('starting', node)

node = new self.Ipfs({
repo: 'ipfs-' + Math.random()
})
node = new self.Ipfs({repo: 'ipfs-' + Math.random()})

node.on('start', () => {
node.id().then((id) => {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"main": "src/core/index.js",
"browser": {
"./src/core/components/init-assets.js": false,
"./src/core/runtime/config-nodejs.js": "./src/core/runtime/config-browser.js",
"./src/core/runtime/config-nodejs.json": "./src/core/runtime/config-browser.json",
"./src/core/runtime/libp2p-nodejs.js": "./src/core/runtime/libp2p-browser.js",
"./src/core/runtime/repo-nodejs.js": "./src/core/runtime/repo-browser.js",
"./test/utils/create-repo-nodejs.js": "./test/utils/create-repo-browser.js",
Expand Down Expand Up @@ -118,7 +118,6 @@
"libp2p-multiplex": "^0.4.3",
"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.11.0",
Expand Down
48 changes: 7 additions & 41 deletions src/core/runtime/libp2p-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,23 @@

const WS = require('libp2p-websockets')
const WebRTCStar = require('libp2p-webrtc-star')
const spdy = require('libp2p-spdy')
const multiplex = require('libp2p-multiplex')
const secio = require('libp2p-secio')
const Multiplex = require('libp2p-multiplex')
const SECIO = require('libp2p-secio')
const Railing = require('libp2p-railing')
const libp2p = require('libp2p')

function mapMuxers (list) {
return list.map((pref) => {
if (typeof pref !== 'string') {
return pref
}
switch (pref.trim().toLowerCase()) {
case 'spdy':
return spdy
case 'multiplex':
return multiplex
default:
throw new Error(pref + ' muxer not available')
}
})
}

function getMuxers (options) {
if (options) {
return mapMuxers(options)
} else {
return [multiplex, spdy]
}
}

class Node extends libp2p {
constructor (peerInfo, peerBook, options) {
options = options || {}
const webRTCStar = new WebRTCStar()
const wstar = new WebRTCStar()

const modules = {
transport: [
new WS(),
webRTCStar
],
transport: [new WS(), wstar],
connection: {
muxer: getMuxers(options.muxer),
crypto: [
secio
]
muxer: [Multiplex],
crypto: [SECIO]
},
discovery: []
}

if (options.webRTCStar) {
modules.discovery.push(webRTCStar.discovery)
discovery: [wstar.discovery]
}

if (options.bootstrap) {
Expand Down
39 changes: 5 additions & 34 deletions src/core/runtime/libp2p-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,20 @@ const TCP = require('libp2p-tcp')
const MulticastDNS = require('libp2p-mdns')
const WS = require('libp2p-websockets')
const Railing = require('libp2p-railing')
const spdy = require('libp2p-spdy')
const KadDHT = require('libp2p-kad-dht')
const multiplex = require('libp2p-multiplex')
const secio = require('libp2p-secio')
const Multiplex = require('libp2p-multiplex')
const SECIO = require('libp2p-secio')
const libp2p = require('libp2p')

function mapMuxers (list) {
return list.map((pref) => {
if (typeof pref !== 'string') {
return pref
}
switch (pref.trim().toLowerCase()) {
case 'spdy': return spdy
case 'multiplex': return multiplex
default:
throw new Error(pref + ' muxer not available')
}
})
}

function getMuxers (muxers) {
const muxerPrefs = process.env.LIBP2P_MUXER
if (muxerPrefs && !muxers) {
return mapMuxers(muxerPrefs.split(','))
} else if (muxers) {
return mapMuxers(muxers)
} else {
return [multiplex, spdy]
}
}

class Node extends libp2p {
constructor (peerInfo, peerBook, options) {
options = options || {}

const modules = {
transport: [
new TCP(),
new WS()
],
transport: [new TCP(), new WS()],
connection: {
muxer: getMuxers(options.muxer),
crypto: [ secio ]
muxer: [Multiplex],
crypto: [SECIO]
},
discovery: []
}
Expand Down

0 comments on commit cbcf90e

Please sign in to comment.