1
1
'use strict'
2
2
3
3
const TCP = require ( 'libp2p-tcp' )
4
- const MulticastDNS = require ( 'libp2p-mdns' )
5
4
const WS = require ( 'libp2p-websockets' )
6
- const Bootstrap = require ( 'libp2p-bootstrap' )
7
- const spdy = require ( 'libp2p-spdy' )
8
- const KadDHT = require ( 'libp2p-kad-dht' )
9
5
const mplex = require ( 'libp2p-mplex' )
10
6
const secio = require ( 'libp2p-secio' )
11
7
const defaultsDeep = require ( '@nodeutils/defaults-deep' )
12
8
const libp2p = require ( '../../..' )
13
9
14
- function mapMuxers ( list ) {
15
- return list . map ( ( pref ) => {
16
- if ( typeof pref !== 'string' ) {
17
- return pref
18
- }
19
- switch ( pref . trim ( ) . toLowerCase ( ) ) {
20
- case 'spdy' : return spdy
21
- case 'mplex' : return mplex
22
- default :
23
- throw new Error ( pref + ' muxer not available' )
24
- }
25
- } )
26
- }
27
-
28
- function getMuxers ( muxers ) {
29
- const muxerPrefs = process . env . LIBP2P_MUXER
30
- if ( muxerPrefs && ! muxers ) {
31
- return mapMuxers ( muxerPrefs . split ( ',' ) )
32
- } else if ( muxers ) {
33
- return mapMuxers ( muxers )
34
- } else {
35
- return [ mplex , spdy ]
36
- }
37
- }
38
-
39
10
class Node extends libp2p {
40
11
constructor ( _options ) {
41
12
const defaults = {
@@ -44,29 +15,8 @@ class Node extends libp2p {
44
15
TCP ,
45
16
WS
46
17
] ,
47
- streamMuxer : getMuxers ( _options . muxer ) ,
48
- connEncryption : [ secio ] ,
49
- peerDiscovery : [
50
- MulticastDNS ,
51
- Bootstrap
52
- ] ,
53
- dht : KadDHT
54
- } ,
55
- config : {
56
- peerDiscovery : {
57
- mdns : {
58
- interval : 10000 ,
59
- enabled : false
60
- } ,
61
- bootstrap : {
62
- interval : 10000 ,
63
- enabled : false ,
64
- list : _options . bootstrapList
65
- }
66
- } ,
67
- dht : {
68
- kBucketSize : 20
69
- }
18
+ streamMuxer : [ mplex ] ,
19
+ connEncryption : [ secio ]
70
20
}
71
21
}
72
22
0 commit comments