@@ -8,7 +8,7 @@ const each = require('async/each')
8
8
const series = require ( 'async/series' )
9
9
10
10
const Ping = require ( 'libp2p-ping' )
11
- const Swarm = require ( 'libp2p-swarm ' )
11
+ const Switch = require ( 'libp2p-switch ' )
12
12
const PeerId = require ( 'peer-id' )
13
13
const PeerInfo = require ( 'peer-info' )
14
14
const PeerBook = require ( 'peer-book' )
@@ -31,28 +31,28 @@ class Node extends EventEmitter {
31
31
32
32
this . _isStarted = false
33
33
34
- this . swarm = new Swarm ( this . peerInfo , this . peerBook )
34
+ this . switch = new Switch ( this . peerInfo , this . peerBook )
35
35
36
36
// Attach stream multiplexers
37
37
if ( this . modules . connection && this . modules . connection . muxer ) {
38
38
let muxers = this . modules . connection . muxer
39
39
muxers = Array . isArray ( muxers ) ? muxers : [ muxers ]
40
- muxers . forEach ( ( muxer ) => this . swarm . connection . addStreamMuxer ( muxer ) )
40
+ muxers . forEach ( ( muxer ) => this . switch . connection . addStreamMuxer ( muxer ) )
41
41
42
42
// If muxer exists, we can use Identify
43
- this . swarm . connection . reuse ( )
43
+ this . switch . connection . reuse ( )
44
44
45
45
// If muxer exists, we can use Relay for listening/dialing
46
- this . swarm . connection . enableCircuitRelay ( _options . relay )
46
+ this . switch . connection . enableCircuitRelay ( _options . relay )
47
47
48
48
// Received incommind dial and muxer upgrade happened,
49
49
// reuse this muxed connection
50
- this . swarm . on ( 'peer-mux-established' , ( peerInfo ) => {
50
+ this . switch . on ( 'peer-mux-established' , ( peerInfo ) => {
51
51
this . emit ( 'peer:connect' , peerInfo )
52
52
this . peerBook . put ( peerInfo )
53
53
} )
54
54
55
- this . swarm . on ( 'peer-mux-closed' , ( peerInfo ) => {
55
+ this . switch . on ( 'peer-mux-closed' , ( peerInfo ) => {
56
56
this . emit ( 'peer:disconnect' , peerInfo )
57
57
} )
58
58
}
@@ -62,7 +62,7 @@ class Node extends EventEmitter {
62
62
let cryptos = this . modules . connection . crypto
63
63
cryptos = Array . isArray ( cryptos ) ? cryptos : [ cryptos ]
64
64
cryptos . forEach ( ( crypto ) => {
65
- this . swarm . connection . crypto ( crypto . tag , crypto . encrypt )
65
+ this . switch . connection . crypto ( crypto . tag , crypto . encrypt )
66
66
} )
67
67
}
68
68
@@ -77,11 +77,11 @@ class Node extends EventEmitter {
77
77
}
78
78
79
79
// Mount default protocols
80
- Ping . mount ( this . swarm )
80
+ Ping . mount ( this . switch )
81
81
82
82
// dht provided components (peerRouting, contentRouting, dht)
83
83
if ( _modules . DHT ) {
84
- this . _dht = new this . modules . DHT ( this . swarm , {
84
+ this . _dht = new this . modules . DHT ( this . switch , {
85
85
kBucketSize : 20 ,
86
86
datastore : _options . DHT && _options . DHT . datastore
87
87
} )
@@ -167,7 +167,7 @@ class Node extends EventEmitter {
167
167
const multiaddrs = this . peerInfo . multiaddrs . toArray ( )
168
168
transports . forEach ( ( transport ) => {
169
169
if ( transport . filter ( multiaddrs ) . length > 0 ) {
170
- this . swarm . transport . add (
170
+ this . switch . transport . add (
171
171
transport . tag || transport . constructor . name , transport )
172
172
} else if ( transport . constructor &&
173
173
transport . constructor . name === 'WebSockets' ) {
@@ -178,11 +178,11 @@ class Node extends EventEmitter {
178
178
} )
179
179
180
180
series ( [
181
- ( cb ) => this . swarm . listen ( cb ) ,
181
+ ( cb ) => this . switch . start ( cb ) ,
182
182
( cb ) => {
183
183
if ( ws ) {
184
184
// always add dialing on websockets
185
- this . swarm . transport . add ( ws . tag || ws . constructor . name , ws )
185
+ this . switch . transport . add ( ws . tag || ws . constructor . name , ws )
186
186
}
187
187
188
188
// all transports need to be setup before discover starts
@@ -237,7 +237,7 @@ class Node extends EventEmitter {
237
237
}
238
238
cb ( )
239
239
} ,
240
- ( cb ) => this . swarm . close ( cb ) ,
240
+ ( cb ) => this . switch . stop ( cb ) ,
241
241
( cb ) => {
242
242
this . emit ( 'stop' )
243
243
cb ( )
@@ -259,7 +259,7 @@ class Node extends EventEmitter {
259
259
return callback ( err )
260
260
}
261
261
262
- callback ( null , new Ping ( this . swarm , peerInfo ) )
262
+ callback ( null , new Ping ( this . switch , peerInfo ) )
263
263
} )
264
264
}
265
265
@@ -276,7 +276,7 @@ class Node extends EventEmitter {
276
276
return callback ( err )
277
277
}
278
278
279
- this . swarm . dial ( peerInfo , protocol , ( err , conn ) => {
279
+ this . switch . dial ( peerInfo , protocol , ( err , conn ) => {
280
280
if ( err ) {
281
281
return callback ( err )
282
282
}
@@ -294,16 +294,16 @@ class Node extends EventEmitter {
294
294
return callback ( err )
295
295
}
296
296
297
- this . swarm . hangUp ( peerInfo , callback )
297
+ this . switch . hangUp ( peerInfo , callback )
298
298
} )
299
299
}
300
300
301
301
handle ( protocol , handlerFunc , matchFunc ) {
302
- this . swarm . handle ( protocol , handlerFunc , matchFunc )
302
+ this . switch . handle ( protocol , handlerFunc , matchFunc )
303
303
}
304
304
305
305
unhandle ( protocol ) {
306
- this . swarm . unhandle ( protocol )
306
+ this . switch . unhandle ( protocol )
307
307
}
308
308
309
309
/*
0 commit comments