@@ -132,44 +132,45 @@ module.exports = function dial (swarm) {
132
132
// - add the muxedConn to the list of muxedConns
133
133
// - add incomming new streams to connHandler
134
134
135
- nextMuxer ( muxers . shift ( ) )
135
+ const ms = new multistream . Dialer ( )
136
+ ms . handle ( conn , ( err ) => {
137
+ if ( err ) {
138
+ return callback ( new Error ( 'multistream not supported' ) )
139
+ }
140
+
141
+ nextMuxer ( muxers . shift ( ) )
142
+ } )
136
143
137
144
function nextMuxer ( key ) {
138
- const ms = new multistream . Dialer ( )
139
- ms . handle ( conn , ( err ) => {
145
+ log ( 'selecting %s' , key )
146
+ ms . select ( key , ( err , conn ) => {
140
147
if ( err ) {
141
- return callback ( new Error ( 'multistream not supported' ) )
142
- }
143
- log ( 'selecting %s' , key )
144
- ms . select ( key , ( err , conn ) => {
145
- if ( err ) {
146
- if ( muxers . length === 0 ) {
147
- cb ( new Error ( 'could not upgrade to stream muxing' ) )
148
- } else {
149
- nextMuxer ( muxers . shift ( ) )
150
- }
151
- return
148
+ if ( muxers . length === 0 ) {
149
+ cb ( new Error ( 'could not upgrade to stream muxing' ) )
150
+ } else {
151
+ nextMuxer ( muxers . shift ( ) )
152
152
}
153
+ return
154
+ }
153
155
154
- const muxedConn = swarm . muxers [ key ] . dialer ( conn )
155
- swarm . muxedConns [ b58Id ] = { }
156
- swarm . muxedConns [ b58Id ] . muxer = muxedConn
157
- // should not be needed anymore - swarm.muxedConns[b58Id].conn = conn
158
-
159
- swarm . emit ( 'peer-mux-established' , pi )
156
+ const muxedConn = swarm . muxers [ key ] . dialer ( conn )
157
+ swarm . muxedConns [ b58Id ] = { }
158
+ swarm . muxedConns [ b58Id ] . muxer = muxedConn
159
+ // should not be needed anymore - swarm.muxedConns[b58Id].conn = conn
160
160
161
- muxedConn . once ( 'close' , ( ) => {
162
- delete swarm . muxedConns [ pi . id . toB58String ( ) ]
163
- swarm . emit ( 'peer-mux-closed' , pi )
164
- } )
161
+ swarm . emit ( 'peer-mux-established' , pi )
165
162
166
- // For incoming streams, in case identify is on
167
- muxedConn . on ( 'stream' , ( conn ) => {
168
- protocolMuxer ( swarm . protocols , conn )
169
- } )
163
+ muxedConn . once ( 'close' , ( ) => {
164
+ delete swarm . muxedConns [ pi . id . toB58String ( ) ]
165
+ swarm . emit ( 'peer-mux-closed' , pi )
166
+ } )
170
167
171
- cb ( null , muxedConn )
168
+ // For incoming streams, in case identify is on
169
+ muxedConn . on ( 'stream' , ( conn ) => {
170
+ protocolMuxer ( swarm . protocols , conn )
172
171
} )
172
+
173
+ cb ( null , muxedConn )
173
174
} )
174
175
}
175
176
}
0 commit comments