@@ -115,17 +115,17 @@ class ConnectionFSM extends BaseConnection {
115
115
this . _state . on ( 'PRIVATIZED' , ( ) => this . _onPrivatized ( ) )
116
116
this . _state . on ( 'ENCRYPTING' , ( ) => this . _onEncrypting ( ) )
117
117
this . _state . on ( 'ENCRYPTED' , ( ) => {
118
- this . log ( ` successfully encrypted connection to ${ this . theirB58Id } ` )
118
+ this . log ( ' successfully encrypted connection to %s' , this . theirB58Id )
119
119
this . emit ( 'encrypted' , this . conn )
120
120
} )
121
121
this . _state . on ( 'UPGRADING' , ( ) => this . _onUpgrading ( ) )
122
122
this . _state . on ( 'MUXED' , ( ) => {
123
- this . log ( ` successfully muxed connection to ${ this . theirB58Id } ` )
123
+ this . log ( ' successfully muxed connection to %s' , this . theirB58Id )
124
124
delete this . switch . conns [ this . theirB58Id ]
125
125
this . emit ( 'muxed' , this . muxer )
126
126
} )
127
127
this . _state . on ( 'CONNECTED' , ( ) => {
128
- this . log ( ` unmuxed connection opened to ${ this . theirB58Id } ` )
128
+ this . log ( ' unmuxed connection opened to %s' , this . theirB58Id )
129
129
this . emit ( 'unmuxed' , this . conn )
130
130
} )
131
131
this . _state . on ( 'DISCONNECTING' , ( ) => this . _onDisconnecting ( ) )
@@ -169,7 +169,7 @@ class ConnectionFSM extends BaseConnection {
169
169
return callback ( err , null )
170
170
}
171
171
172
- this . log ( ` created new stream to ${ this . theirB58Id } ` )
172
+ this . log ( ' created new stream to %s' , this . theirB58Id )
173
173
this . _protocolHandshake ( protocol , stream , callback )
174
174
} )
175
175
}
@@ -194,7 +194,7 @@ class ConnectionFSM extends BaseConnection {
194
194
* @returns {void }
195
195
*/
196
196
_onDialing ( ) {
197
- this . log ( ` dialing ${ this . theirB58Id } ` )
197
+ this . log ( ' dialing %s' , this . theirB58Id )
198
198
199
199
if ( ! this . switch . hasTransports ( ) ) {
200
200
return this . close ( NO_TRANSPORTS_REGISTERED ( ) )
@@ -226,7 +226,7 @@ class ConnectionFSM extends BaseConnection {
226
226
this . theirPeerInfo . multiaddrs . add ( `/p2p-circuit/p2p/${ this . theirB58Id } ` )
227
227
}
228
228
229
- this . log ( ` dialing transport ${ transport } ` )
229
+ this . log ( ' dialing transport %s' , transport )
230
230
this . switch . transport . dial ( transport , this . theirPeerInfo , ( errors , _conn ) => {
231
231
if ( errors ) {
232
232
this . emit ( 'error:connection_attempt_failed' , errors )
@@ -250,7 +250,7 @@ class ConnectionFSM extends BaseConnection {
250
250
* @returns {void }
251
251
*/
252
252
_onDialed ( ) {
253
- this . log ( ` successfully dialed ${ this . theirB58Id } ` )
253
+ this . log ( ' successfully dialed %s' , this . theirB58Id )
254
254
255
255
this . emit ( 'connected' , this . conn )
256
256
}
@@ -261,33 +261,32 @@ class ConnectionFSM extends BaseConnection {
261
261
* @returns {void }
262
262
*/
263
263
_onDisconnecting ( ) {
264
- this . log ( ` disconnecting from ${ this . theirB58Id } ` )
264
+ this . log ( ' disconnecting from %s' , this . theirB58Id )
265
265
266
266
// Issue disconnects on both Peers
267
267
if ( this . theirPeerInfo ) {
268
268
this . theirPeerInfo . disconnect ( )
269
269
}
270
270
271
+ this . switch . connection . remove ( this )
272
+
273
+ delete this . switch . conns [ this . theirB58Id ]
274
+
271
275
// Clean up stored connections
272
276
if ( this . muxer ) {
273
277
this . muxer . end ( )
278
+ delete this . muxer
279
+ this . switch . emit ( 'peer-mux-closed' , this . theirPeerInfo )
274
280
}
275
281
276
- this . switch . connection . remove ( this )
277
-
278
- delete this . switch . conns [ this . theirB58Id ]
279
- delete this . muxer
280
-
281
282
// If we have the base connection, abort it
282
283
if ( this . conn ) {
283
284
this . conn . source ( true , ( ) => {
284
285
this . _state ( 'done' )
285
- this . switch . emit ( 'peer-mux-closed' , this . theirPeerInfo )
286
286
delete this . conn
287
287
} )
288
288
} else {
289
289
this . _state ( 'done' )
290
- this . switch . emit ( 'peer-mux-closed' , this . theirPeerInfo )
291
290
}
292
291
}
293
292
@@ -336,7 +335,7 @@ class ConnectionFSM extends BaseConnection {
336
335
*/
337
336
_onUpgrading ( ) {
338
337
const muxers = Object . keys ( this . switch . muxers )
339
- this . log ( ` upgrading connection to ${ this . theirB58Id } ` )
338
+ this . log ( ' upgrading connection to %s' , this . theirB58Id )
340
339
341
340
if ( muxers . length === 0 ) {
342
341
return this . _state ( 'stop' )
@@ -376,7 +375,7 @@ class ConnectionFSM extends BaseConnection {
376
375
377
376
// For incoming streams, in case identify is on
378
377
this . muxer . on ( 'stream' , ( conn ) => {
379
- this . log ( ` new stream created via muxer to ${ this . theirB58Id } ` )
378
+ this . log ( ' new stream created via muxer to %s' , this . theirB58Id )
380
379
conn . setPeerInfo ( this . theirPeerInfo )
381
380
this . switch . protocolMuxer ( null ) ( conn )
382
381
} )
@@ -431,12 +430,12 @@ class ConnectionFSM extends BaseConnection {
431
430
432
431
msDialer . select ( protocol , ( err , _conn ) => {
433
432
if ( err ) {
434
- this . log ( ` could not perform protocol handshake: ` , err )
433
+ this . log ( ' could not perform protocol handshake:' , err )
435
434
return callback ( err , null )
436
435
}
437
436
438
437
const conn = observeConnection ( null , protocol , _conn , this . switch . observer )
439
- this . log ( ` successfully performed handshake of ${ protocol } to ${ this . theirB58Id } ` )
438
+ this . log ( ' successfully performed handshake of %s to %s' , protocol , this . theirB58Id )
440
439
this . emit ( 'connection' , conn )
441
440
callback ( null , conn )
442
441
} )
0 commit comments