diff --git a/libp2p/protocols/connectivity/dcutr/client.nim b/libp2p/protocols/connectivity/dcutr/client.nim index dec80664eb..683904fd01 100644 --- a/libp2p/protocols/connectivity/dcutr/client.nim +++ b/libp2p/protocols/connectivity/dcutr/client.nim @@ -28,13 +28,25 @@ type connectTimeout: Duration maxDialableAddrs: int + AnyCompletedBoolProc = proc (futs: seq[Future[bool]]): Future[Future[bool]] {.async.} + logScope: topics = "libp2p dcutrclient" proc new*(T: typedesc[DcutrClient], connectTimeout = 15.seconds, maxDialableAddrs = 8): T = return T(connectTimeout: connectTimeout, maxDialableAddrs: maxDialableAddrs) -proc startSync*(self: DcutrClient, switch: Switch, remotePeerId: PeerId, addrs: seq[MultiAddress], anyCompletedProc: AnyCompletedProc = anyCompleted) {.async.} = +#FIXME: This is a workaround for 1.2 as we can't use anyCompleted as proc param. +proc anyCompletedBool(futs: seq[Future[bool]]): Future[Future[bool]] = + return anyCompleted(futs) + +proc startSync*(self: DcutrClient, switch: Switch, remotePeerId: PeerId, addrs: seq[MultiAddress], anyCompletedBoolProc: AnyCompletedBoolProc = anyCompletedBool) {.async.} = + #FIXME: This is a workaround for 1.2 as we can't use anyCompleted as proc param. + proc connectWrapper(peerId: PeerId, addrs: MultiAddress): Future[bool] {.async.} = + let fut = switch.connect(peerId, @[addrs], forceDial = true, reuseConnection = false, upgradeDir = Direction.In) + await fut + if fut.completed(): return true else: return false + logScope: peerId = switch.peerInfo.peerId @@ -67,10 +79,10 @@ proc startSync*(self: DcutrClient, switch: Switch, remotePeerId: PeerId, addrs: if peerDialableAddrs.len > self.maxDialableAddrs: peerDialableAddrs = peerDialableAddrs[0..