@@ -53,7 +53,7 @@ proc dialAndUpgrade(
5353 peerId: Opt [PeerId ],
5454 hostname: string ,
5555 address: MultiAddress ,
56- upgradeDir = Direction .Out ):
56+ dir = Direction .Out ):
5757 Future [Muxer ] {.async .} =
5858
5959 for transport in self.transports: # for each transport
@@ -75,23 +75,27 @@ proc dialAndUpgrade(
7575
7676 let mux =
7777 try :
78- dialed.transportDir = upgradeDir
79- await transport.upgrade (dialed, upgradeDir, peerId)
78+ # This is for the very specific case of a simultaneous dial during DCUtR. In this case, both sides will have
79+ # an Outbound direction at the transport level. Therefore we update the DCUtR initiator transport direction to Inbound.
80+ # The if below is more general and might handle other use cases in the future.
81+ if dialed.dir != dir:
82+ dialed.dir = dir
83+ await transport.upgrade (dialed, peerId)
8084 except CatchableError as exc:
8185 # If we failed to establish the connection through one transport,
8286 # we won't succeeded through another - no use in trying again
8387 await dialed.close ()
8488 debug " Upgrade failed" , err = exc.msg, peerId = peerId.get (default (PeerId ))
8589 if exc isnot CancelledError :
86- if upgradeDir == Direction .Out :
90+ if dialed.dir == Direction .Out :
8791 libp2p_failed_upgrades_outgoing.inc ()
8892 else :
8993 libp2p_failed_upgrades_incoming.inc ()
9094
9195 # Try other address
9296 return nil
9397
94- doAssert not isNil (mux), " connection died after upgrade " & $ upgradeDir
98+ doAssert not isNil (mux), " connection died after upgrade " & $ dialed.dir
9599 debug " Dial successful" , peerId = mux.connection.peerId
96100 return mux
97101 return nil
@@ -128,7 +132,7 @@ proc dialAndUpgrade(
128132 self: Dialer ,
129133 peerId: Opt [PeerId ],
130134 addrs: seq [MultiAddress ],
131- upgradeDir = Direction .Out ):
135+ dir = Direction .Out ):
132136 Future [Muxer ] {.async .} =
133137
134138 debug " Dialing peer" , peerId = peerId.get (default (PeerId ))
@@ -146,7 +150,7 @@ proc dialAndUpgrade(
146150 else : await self.nameResolver.resolveMAddress (expandedAddress)
147151
148152 for resolvedAddress in resolvedAddresses:
149- result = await self.dialAndUpgrade (addrPeerId, hostname, resolvedAddress, upgradeDir )
153+ result = await self.dialAndUpgrade (addrPeerId, hostname, resolvedAddress, dir )
150154 if not isNil (result ):
151155 return result
152156
@@ -164,7 +168,7 @@ proc internalConnect(
164168 addrs: seq [MultiAddress ],
165169 forceDial: bool ,
166170 reuseConnection = true ,
167- upgradeDir = Direction .Out ):
171+ dir = Direction .Out ):
168172 Future [Muxer ] {.async .} =
169173 if Opt .some (self.localPeerId) == peerId:
170174 raise newException (CatchableError , " can't dial self!" )
@@ -182,7 +186,7 @@ proc internalConnect(
182186 let slot = self.connManager.getOutgoingSlot (forceDial)
183187 let muxed =
184188 try :
185- await self.dialAndUpgrade (peerId, addrs, upgradeDir )
189+ await self.dialAndUpgrade (peerId, addrs, dir )
186190 except CatchableError as exc:
187191 slot.release ()
188192 raise exc
@@ -209,15 +213,15 @@ method connect*(
209213 addrs: seq [MultiAddress ],
210214 forceDial = false ,
211215 reuseConnection = true ,
212- upgradeDir = Direction .Out ) {.async .} =
216+ dir = Direction .Out ) {.async .} =
213217 # # connect remote peer without negotiating
214218 # # a protocol
215219 # #
216220
217221 if self.connManager.connCount (peerId) > 0 and reuseConnection:
218222 return
219223
220- discard await self.internalConnect (Opt .some (peerId), addrs, forceDial, reuseConnection, upgradeDir )
224+ discard await self.internalConnect (Opt .some (peerId), addrs, forceDial, reuseConnection, dir )
221225
222226method connect * (
223227 self: Dialer ,
0 commit comments