mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-23 22:11:35 +00:00
feat: (BREAKING CHANGE) overhaul libp2p config and constructor
* docs: update chat example and add info to its readme * docs: update echo example * docs: update libp2p in browser example * docs: update pubsub example * docs: update peer and content routing examples * docs: update discovery mechanisms example * docs: update encrypted comms example * docs: update protocol and stream muxing example * feat: add config validation * test: update CI configs, use only node 8
This commit is contained in:
@ -2,13 +2,12 @@
|
||||
|
||||
const WebRTCStar = require('libp2p-webrtc-star')
|
||||
const WebSockets = require('libp2p-websockets')
|
||||
|
||||
const Mplex = require('libp2p-mplex')
|
||||
const SPDY = require('libp2p-spdy')
|
||||
const SECIO = require('libp2p-secio')
|
||||
|
||||
const Railing = require('libp2p-railing')
|
||||
const libp2p = require('libp2p')
|
||||
const Bootstrap = require('libp2p-railing')
|
||||
const defaultsDeep = require('@nodeutils/defaults-deep')
|
||||
const libp2p = require('../../../../')
|
||||
|
||||
// Find this list at: https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/config-browser.json
|
||||
const bootstrapers = [
|
||||
@ -25,30 +24,56 @@ const bootstrapers = [
|
||||
]
|
||||
|
||||
class Node extends libp2p {
|
||||
constructor (peerInfo, peerBook, options) {
|
||||
options = options || {}
|
||||
constructor (_options) {
|
||||
const wrtcStar = new WebRTCStar({ id: _options.peerInfo.id })
|
||||
|
||||
const wstar = new WebRTCStar()
|
||||
|
||||
const modules = {
|
||||
transport: [
|
||||
wstar,
|
||||
new WebSockets()
|
||||
],
|
||||
connection: {
|
||||
muxer: [
|
||||
const defaults = {
|
||||
modules: {
|
||||
transport: [
|
||||
wrtcStar,
|
||||
new WebSockets()
|
||||
],
|
||||
streamMuxer: [
|
||||
Mplex,
|
||||
SPDY
|
||||
],
|
||||
crypto: [SECIO]
|
||||
connEncryption: [
|
||||
SECIO
|
||||
],
|
||||
peerDiscovery: [
|
||||
wrtcStar.discovery,
|
||||
Bootstrap
|
||||
]
|
||||
},
|
||||
discovery: [
|
||||
wstar.discovery,
|
||||
new Railing(bootstrapers)
|
||||
]
|
||||
config: {
|
||||
peerDiscovery: {
|
||||
webRTCStar: {
|
||||
enabled: true
|
||||
},
|
||||
websocketStar: {
|
||||
enabled: true
|
||||
},
|
||||
bootstrap: {
|
||||
interval: 10000,
|
||||
enabled: false,
|
||||
list: bootstrapers
|
||||
}
|
||||
},
|
||||
relay: {
|
||||
enabled: false,
|
||||
hop: {
|
||||
enabled: false,
|
||||
active: false
|
||||
}
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
dht: false,
|
||||
pubsub: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super(modules, peerInfo, peerBook, options)
|
||||
super(defaultsDeep(_options, defaults))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,9 @@ function createNode (callback) {
|
||||
|
||||
peerInfo.multiaddrs.add(ma)
|
||||
|
||||
const node = new Node(peerInfo)
|
||||
const node = new Node({
|
||||
peerInfo
|
||||
})
|
||||
|
||||
node.idStr = peerIdStr
|
||||
callback(null, node)
|
||||
|
Reference in New Issue
Block a user