Skip to content

Instantly share code, notes, and snippets.

@tobowers tobowers/p2p.js
Created Jun 6, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.