This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
runtime specific things - bring libp2p bundles here #895
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict' | ||
|
||
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 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 modules = { | ||
transport: [ | ||
new WS(), | ||
webRTCStar | ||
], | ||
connection: { | ||
muxer: getMuxers(options.muxer), | ||
crypto: [ | ||
secio | ||
] | ||
}, | ||
discovery: [] | ||
} | ||
|
||
if (options.webRTCStar) { | ||
modules.discovery.push(webRTCStar.discovery) | ||
} | ||
|
||
if (options.bootstrap) { | ||
const r = new Railing(options.bootstrap) | ||
modules.discovery.push(r) | ||
} | ||
|
||
super(modules, peerInfo, peerBook, options) | ||
} | ||
} | ||
|
||
module.exports = Node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict' | ||
|
||
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 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file has a lot in common with it's browser version. Perhaps we could reduce this to a declarative config and not need to declare a class here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, at the same time it serves the purpose of being an awesome template for others to c&p |
||
constructor (peerInfo, peerBook, options) { | ||
options = options || {} | ||
|
||
const modules = { | ||
transport: [ | ||
new TCP(), | ||
new WS() | ||
], | ||
connection: { | ||
muxer: getMuxers(options.muxer), | ||
crypto: [ secio ] | ||
}, | ||
discovery: [] | ||
} | ||
|
||
if (options.dht) { | ||
modules.DHT = KadDHT | ||
} | ||
|
||
if (options.mdns) { | ||
const mdns = new MulticastDNS(peerInfo, 'ipfs.local') | ||
modules.discovery.push(mdns) | ||
} | ||
|
||
if (options.bootstrap) { | ||
const r = new Railing(options.bootstrap) | ||
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) | ||
} | ||
} | ||
|
||
module.exports = Node |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ module.exports = (ctl) => { | |
ctl.bootstrap.add({ default: true }, (err, res) => { | ||
expect(err).to.not.exist() | ||
peers = res.Peers | ||
console.log(res) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. letfover console.log? |
||
expect(peers).to.exist() | ||
expect(peers.length).to.be.above(1) | ||
done() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add a comment before explaining that this will be switched to file x in the browser?