@@ -115,17 +115,17 @@ class ConnectionFSM extends BaseConnection {
115115 this . _state . on ( 'PRIVATIZED' , ( ) => this . _onPrivatized ( ) )
116116 this . _state . on ( 'ENCRYPTING' , ( ) => this . _onEncrypting ( ) )
117117 this . _state . on ( 'ENCRYPTED' , ( ) => {
118- this . log ( ` successfully encrypted connection to ${ this . theirB58Id } ` )
118+ this . log ( ' successfully encrypted connection to %s' , this . theirB58Id )
119119 this . emit ( 'encrypted' , this . conn )
120120 } )
121121 this . _state . on ( 'UPGRADING' , ( ) => this . _onUpgrading ( ) )
122122 this . _state . on ( 'MUXED' , ( ) => {
123- this . log ( ` successfully muxed connection to ${ this . theirB58Id } ` )
123+ this . log ( ' successfully muxed connection to %s' , this . theirB58Id )
124124 delete this . switch . conns [ this . theirB58Id ]
125125 this . emit ( 'muxed' , this . muxer )
126126 } )
127127 this . _state . on ( 'CONNECTED' , ( ) => {
128- this . log ( ` unmuxed connection opened to ${ this . theirB58Id } ` )
128+ this . log ( ' unmuxed connection opened to %s' , this . theirB58Id )
129129 this . emit ( 'unmuxed' , this . conn )
130130 } )
131131 this . _state . on ( 'DISCONNECTING' , ( ) => this . _onDisconnecting ( ) )
@@ -169,7 +169,7 @@ class ConnectionFSM extends BaseConnection {
169169 return callback ( err , null )
170170 }
171171
172- this . log ( ` created new stream to ${ this . theirB58Id } ` )
172+ this . log ( ' created new stream to %s' , this . theirB58Id )
173173 this . _protocolHandshake ( protocol , stream , callback )
174174 } )
175175 }
@@ -194,7 +194,7 @@ class ConnectionFSM extends BaseConnection {
194194 * @returns {void }
195195 */
196196 _onDialing ( ) {
197- this . log ( ` dialing ${ this . theirB58Id } ` )
197+ this . log ( ' dialing %s' , this . theirB58Id )
198198
199199 if ( ! this . switch . hasTransports ( ) ) {
200200 return this . close ( NO_TRANSPORTS_REGISTERED ( ) )
@@ -226,7 +226,7 @@ class ConnectionFSM extends BaseConnection {
226226 this . theirPeerInfo . multiaddrs . add ( `/p2p-circuit/p2p/${ this . theirB58Id } ` )
227227 }
228228
229- this . log ( ` dialing transport ${ transport } ` )
229+ this . log ( ' dialing transport %s' , transport )
230230 this . switch . transport . dial ( transport , this . theirPeerInfo , ( errors , _conn ) => {
231231 if ( errors ) {
232232 this . emit ( 'error:connection_attempt_failed' , errors )
@@ -250,7 +250,7 @@ class ConnectionFSM extends BaseConnection {
250250 * @returns {void }
251251 */
252252 _onDialed ( ) {
253- this . log ( ` successfully dialed ${ this . theirB58Id } ` )
253+ this . log ( ' successfully dialed %s' , this . theirB58Id )
254254
255255 this . emit ( 'connected' , this . conn )
256256 }
@@ -261,33 +261,32 @@ class ConnectionFSM extends BaseConnection {
261261 * @returns {void }
262262 */
263263 _onDisconnecting ( ) {
264- this . log ( ` disconnecting from ${ this . theirB58Id } ` )
264+ this . log ( ' disconnecting from %s' , this . theirB58Id )
265265
266266 // Issue disconnects on both Peers
267267 if ( this . theirPeerInfo ) {
268268 this . theirPeerInfo . disconnect ( )
269269 }
270270
271+ this . switch . connection . remove ( this )
272+
273+ delete this . switch . conns [ this . theirB58Id ]
274+
271275 // Clean up stored connections
272276 if ( this . muxer ) {
273277 this . muxer . end ( )
278+ delete this . muxer
279+ this . switch . emit ( 'peer-mux-closed' , this . theirPeerInfo )
274280 }
275281
276- this . switch . connection . remove ( this )
277-
278- delete this . switch . conns [ this . theirB58Id ]
279- delete this . muxer
280-
281282 // If we have the base connection, abort it
282283 if ( this . conn ) {
283284 this . conn . source ( true , ( ) => {
284285 this . _state ( 'done' )
285- this . switch . emit ( 'peer-mux-closed' , this . theirPeerInfo )
286286 delete this . conn
287287 } )
288288 } else {
289289 this . _state ( 'done' )
290- this . switch . emit ( 'peer-mux-closed' , this . theirPeerInfo )
291290 }
292291 }
293292
@@ -336,7 +335,7 @@ class ConnectionFSM extends BaseConnection {
336335 */
337336 _onUpgrading ( ) {
338337 const muxers = Object . keys ( this . switch . muxers )
339- this . log ( ` upgrading connection to ${ this . theirB58Id } ` )
338+ this . log ( ' upgrading connection to %s' , this . theirB58Id )
340339
341340 if ( muxers . length === 0 ) {
342341 return this . _state ( 'stop' )
@@ -376,7 +375,7 @@ class ConnectionFSM extends BaseConnection {
376375
377376 // For incoming streams, in case identify is on
378377 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 )
380379 conn . setPeerInfo ( this . theirPeerInfo )
381380 this . switch . protocolMuxer ( null ) ( conn )
382381 } )
@@ -431,12 +430,12 @@ class ConnectionFSM extends BaseConnection {
431430
432431 msDialer . select ( protocol , ( err , _conn ) => {
433432 if ( err ) {
434- this . log ( ` could not perform protocol handshake: ` , err )
433+ this . log ( ' could not perform protocol handshake:' , err )
435434 return callback ( err , null )
436435 }
437436
438437 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 )
440439 this . emit ( 'connection' , conn )
441440 callback ( null , conn )
442441 } )
0 commit comments