From d9563d65aea0c32ad3dc017dcf1ee328295b217a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Mon, 8 Feb 2021 22:21:43 +0100 Subject: [PATCH] support compilation with Nim-1.4 HEAD (#521) --- libp2p/switch.nim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libp2p/switch.nim b/libp2p/switch.nim index e742d78..faf7a15 100644 --- a/libp2p/switch.nim +++ b/libp2p/switch.nim @@ -103,8 +103,16 @@ proc dialAndUpgrade(s: Switch, addrs: seq[MultiAddress]): Future[Connection] {.async.} = debug "Dialing peer", peerId + + # Avoid "cannot be captured as it would violate memory safety" errors in Nim-1.4.x. + var + transport: Transport + address: MultiAddress + for t in s.transports: # for each transport + transport = t for a in addrs: # for each address + address = a if t.handles(a): # check if it can dial it trace "Dialing address", address = $a, peerId let dialed = try: @@ -112,7 +120,7 @@ proc dialAndUpgrade(s: Switch, # await a connection slot when the total # connection count is equal to `maxConns` await s.connManager.trackOutgoingConn( - () => t.dial(a) + () => transport.dial(address) ) except TooManyConnectionsError as exc: trace "Connection limit reached!"