diff --git a/libp2p/connmanager.nim b/libp2p/connmanager.nim index e411d40..3c88d2d 100644 --- a/libp2p/connmanager.nim +++ b/libp2p/connmanager.nim @@ -416,7 +416,7 @@ proc getIncomingSlot*(c: ConnManager): Future[ConnectionSlot] {.async.} = await c.inSema.acquire() return ConnectionSlot(connManager: c, direction: In) -proc getOutgoingSlot*(c: ConnManager, forceDial = false): Future[ConnectionSlot] {.async.} = +proc getOutgoingSlot*(c: ConnManager, forceDial = false): ConnectionSlot {.raises: [Defect, TooManyConnectionsError].} = if forceDial: c.outSema.forceAcquire() elif not c.outSema.tryAcquire(): diff --git a/libp2p/dialer.nim b/libp2p/dialer.nim index 4e39733..4f7c035 100644 --- a/libp2p/dialer.nim +++ b/libp2p/dialer.nim @@ -177,7 +177,7 @@ proc internalConnect( trace "Reusing existing connection", conn, direction = $conn.dir return conn - let slot = await self.connManager.getOutgoingSlot(forceDial) + let slot = self.connManager.getOutgoingSlot(forceDial) conn = try: await self.dialAndUpgrade(peerId, addrs) diff --git a/tests/testconnmngr.nim b/tests/testconnmngr.nim index dda2e3d..9a59e61 100644 --- a/tests/testconnmngr.nim +++ b/tests/testconnmngr.nim @@ -259,11 +259,11 @@ suite "Connection Manager": let connMngr = ConnManager.new(maxConnections = 3) for i in 0..<3: - check await connMngr.getOutgoingSlot().withTimeout(10.millis) + discard connMngr.getOutgoingSlot() # should throw adding a connection over the limit expect TooManyConnectionsError: - discard await connMngr.getOutgoingSlot() + discard connMngr.getOutgoingSlot() await connMngr.close() @@ -271,7 +271,7 @@ suite "Connection Manager": let connMngr = ConnManager.new(maxConnections = 3) for i in 0..<3: - check await connMngr.getOutgoingSlot().withTimeout(10.millis) + discard connMngr.getOutgoingSlot() # should timeout adding a connection over the limit check not(await connMngr.getIncomingSlot().withTimeout(10.millis)) @@ -286,7 +286,7 @@ suite "Connection Manager": # should throw adding a connection over the limit expect TooManyConnectionsError: - discard await connMngr.getOutgoingSlot() + discard connMngr.getOutgoingSlot() await connMngr.close() @@ -304,11 +304,11 @@ suite "Connection Manager": let connMngr = ConnManager.new(maxOut = 3) for i in 0..<3: - check await connMngr.getOutgoingSlot().withTimeout(10.millis) + discard connMngr.getOutgoingSlot() # should throw adding a connection over the limit expect TooManyConnectionsError: - discard await connMngr.getOutgoingSlot() + discard connMngr.getOutgoingSlot() await connMngr.close() @@ -316,7 +316,7 @@ suite "Connection Manager": let connMngr = ConnManager.new(maxOut = 3) for i in 0..<3: - check await connMngr.getOutgoingSlot().withTimeout(10.millis) + discard connMngr.getOutgoingSlot() # should timeout adding a connection over the limit check not(await connMngr.getIncomingSlot().withTimeout(10.millis)) @@ -332,7 +332,7 @@ suite "Connection Manager": # should throw adding a connection over the limit expect TooManyConnectionsError: - discard await connMngr.getOutgoingSlot() + discard connMngr.getOutgoingSlot() await connMngr.close() @@ -341,11 +341,11 @@ suite "Connection Manager": var conns: seq[Connection] for i in 0..<3: - check await connMngr.getOutgoingSlot(true).withTimeout(10.millis) + discard connMngr.getOutgoingSlot(true) # should throw adding a connection over the limit expect TooManyConnectionsError: - discard await connMngr.getOutgoingSlot(false) + discard connMngr.getOutgoingSlot(false) await connMngr.close() @@ -354,7 +354,7 @@ suite "Connection Manager": var conns: seq[Connection] for i in 0..<3: - let slot = await ((connMngr.getOutgoingSlot()).wait(10.millis)) + let slot = connMngr.getOutgoingSlot() let conn = getConnection(