Created
June 6, 2019 13:01
-
-
Save tobowers/ce78d57ffb38525aec7ca4b64f5afcc3 to your computer and use it in GitHub Desktop.
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
const libp2p = require('libp2p') | |
const TCP = require('libp2p-tcp') | |
const Mplex = require('libp2p-mplex') | |
const SECIO = require('libp2p-secio') | |
const DHT = require('libp2p-kad-dht') | |
const WebRTCStar = require('libp2p-webrtc-star') | |
const WebSockets = require('libp2p-websockets') | |
const WebSocketStar = require('libp2p-websocket-star') | |
const Bootstrap = require('libp2p-bootstrap') | |
const defaultsDeep = require('@nodeutils/defaults-deep') | |
const PeerInfo = require('peer-info') | |
// Find this list at: https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/config-nodejs.json | |
// const bootstrapers = [ | |
// '/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ', | |
// '/ip4/104.236.176.52/tcp/4001/p2p/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z', | |
// '/ip4/104.236.179.241/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM', | |
// '/ip4/162.243.248.213/tcp/4001/p2p/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm', | |
// '/ip4/128.199.219.111/tcp/4001/p2p/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu', | |
// '/ip4/104.236.76.40/tcp/4001/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64', | |
// '/ip4/178.62.158.247/tcp/4001/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd', | |
// '/ip4/178.62.61.185/tcp/4001/p2p/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3', | |
// '/ip4/104.236.151.122/tcp/4001/p2p/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx' | |
// ] | |
const bootstrapers = [ | |
'/ip4/192.168.2.112/tcp/57428/ws/ipfs/16Uiu2HAm3TGSEKEjagcCojSJeaT5rypaeJMKejijvYSnAjviWwV55' | |
] | |
class TupeloP2P extends libp2p { | |
constructor (_options) { | |
// const wrtcStar = new WebRTCStar({ id: _options.peerInfo.id }) | |
// const wsstar = new WebSocketStar({ id: _options.peerInfo.id }) | |
const defaults = { | |
modules: { | |
transport: [ | |
// wrtcStar, | |
WebSockets, | |
// wsstar, | |
// TCP | |
], | |
streamMuxer: [ Mplex ], | |
connEncryption: [ SECIO ], | |
peerDiscovery: [ | |
// wrtcStar.discovery, | |
// wsstar.discovery, | |
Bootstrap | |
], | |
dht: DHT | |
}, | |
config: { | |
peerDiscovery: { | |
// webRTCStar: { | |
// enabled: true | |
// }, | |
// websocketStar: { | |
// enabled: true | |
// }, | |
autoDial: true, | |
bootstrap: { | |
interval: 20e3, | |
enabled: true, | |
list: bootstrapers | |
} | |
}, | |
// dht: { | |
// enabled: false | |
// }, | |
EXPERIMENTAL: { | |
pubsub: true | |
} | |
}, | |
connectionManager: { | |
minPeers: 1, | |
maxPeers: 50 | |
} | |
} | |
super(defaultsDeep(_options, defaults)) | |
} | |
} | |
module.exports.TupeloP2P = TupeloP2P | |
module.exports.CreateNode = function(callback) { | |
PeerInfo.create((err, peerInfo) => { | |
if (err) { | |
return callback(err) | |
} | |
// const peerIdStr = peerInfo.id.toB58String() | |
// const ma = `/dns4/star-signal.cloud.ipfs.team/tcp/443/wss/p2p-webrtc-star/p2p/${peerIdStr}` | |
// peerInfo.multiaddrs.add(ma) | |
const node = new TupeloP2P({ | |
peerInfo | |
}) | |
// node.idStr = peerIdStr | |
callback(null, node) | |
}) | |
} | |
// let node | |
// waterfall([ | |
// (cb) => PeerInfo.create(cb), | |
// (peerInfo, cb) => { | |
// peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0') | |
// node = new MyBundle({ | |
// peerInfo | |
// }) | |
// node.start(cb) | |
// } | |
// ], (err) => { | |
// if (err) { throw err } | |
// node.on('peer:discovery', (peer) => { | |
// // No need to dial, autoDial is on | |
// console.log('Discovered:', peer.id.toB58String()) | |
// }) | |
// node.on('peer:connect', (peer) => { | |
// console.log('Connection established to:', peer.id.toB58String()) | |
// }) | |
// }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment