11'use strict'
22
3- const libp2p = require ( 'libp2p ' )
3+ const libp2p = require ( '../../ ' )
44const TCP = require ( 'libp2p-tcp' )
55const Mplex = require ( 'libp2p-mplex' )
66const SECIO = require ( 'libp2p-secio' )
77const PeerInfo = require ( 'peer-info' )
88const CID = require ( 'cids' )
99const KadDHT = require ( 'libp2p-kad-dht' )
10-
10+ const defaultsDeep = require ( '@nodeutils/defaults-deep' )
1111const waterfall = require ( 'async/waterfall' )
1212const parallel = require ( 'async/parallel' )
1313
1414class MyBundle extends libp2p {
15- constructor ( peerInfo ) {
16- const modules = {
17- transport : [ new TCP ( ) ] ,
18- connection : {
19- muxer : [ Mplex ] ,
20- crypto : [ SECIO ]
15+ constructor ( _options ) {
16+ const defaults = {
17+ modules : {
18+ transport : [ TCP ] ,
19+ streamMuxer : [ Mplex ] ,
20+ connEncryption : [ SECIO ] ,
21+ // we add the DHT module that will enable Peer and Content Routing
22+ dht : KadDHT
2123 } ,
22- // we add the DHT module that will enable Peer and Content Routing
23- DHT : KadDHT
24+ config : {
25+ dht : {
26+ kBucketSize : 20
27+ } ,
28+ EXPERIMENTAL : {
29+ dht : true
30+ }
31+ }
2432 }
25- super ( modules , peerInfo )
33+
34+ super ( defaultsDeep ( _options , defaults ) )
2635 }
2736}
2837
@@ -33,7 +42,9 @@ function createNode (callback) {
3342 ( cb ) => PeerInfo . create ( cb ) ,
3443 ( peerInfo , cb ) => {
3544 peerInfo . multiaddrs . add ( '/ip4/0.0.0.0/tcp/0' )
36- node = new MyBundle ( peerInfo )
45+ node = new MyBundle ( {
46+ peerInfo
47+ } )
3748 node . start ( cb )
3849 }
3950 ] , ( err ) => callback ( err , node ) )
0 commit comments