Created
June 6, 2019 19:00
-
-
Save tobowers/f1a2ba018f54199a1ab990a293093bdd 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 WS = require('libp2p-websockets') | |
const Multiplex = require('pull-mplex') | |
const SECIO = require('libp2p-secio') | |
const Bootstrap = require('libp2p-bootstrap') | |
const KadDHT = require('libp2p-kad-dht') | |
const libp2p = require('libp2p') | |
const mergeOptions = require('merge-options') | |
const multiaddr = require('multiaddr') | |
const PeerInfo = require('peer-info') | |
const bootstrapers = [ | |
'/ip4/192.168.2.112/tcp/65333/ws/ipfs/16Uiu2HAm3TGSEKEjagcCojSJeaT5rypaeJMKejijvYSnAjviWwV' | |
] | |
class TupeloP2P extends libp2p { | |
constructor (_options) { | |
const defaults = { | |
switch: { | |
blacklistTTL: 2 * 60 * 1e3, // 2 minute base | |
blackListAttempts: 5, // back off 5 times | |
maxParallelDials: 100, | |
maxColdCalls: 25, | |
dialTimeout: 20e3 | |
}, | |
modules: { | |
transport: [ | |
WS, | |
], | |
streamMuxer: [ | |
Multiplex | |
], | |
connEncryption: [ | |
SECIO | |
], | |
peerDiscovery: [ | |
Bootstrap | |
], | |
dht: KadDHT | |
}, | |
config: { | |
peerDiscovery: { | |
autoDial: true, | |
bootstrap: { | |
enabled: true, | |
list: bootstrapers | |
} | |
}, | |
dht: { | |
enabled: false | |
}, | |
EXPERIMENTAL: { | |
pubsub: false | |
} | |
} | |
} | |
super(mergeOptions(defaults, _options)) | |
} | |
} | |
module.exports.TupeloP2P = TupeloP2P | |
module.exports.CreateNode = function(callback) { | |
PeerInfo.create((err, peerInfo) => { | |
if (err) { | |
return callback(err) | |
} | |
const node = new TupeloP2P({ | |
peerInfo | |
}) | |
callback(null, node) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment