From 60245a065ddbf5f26e3f0330ddb8f4c355940a89 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Thu, 5 Sep 2019 09:20:05 -0600 Subject: [PATCH] fix: don't call conn handler on dials --- libp2p/tcptransport.nim | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libp2p/tcptransport.nim b/libp2p/tcptransport.nim index ab688fa..a523bad 100644 --- a/libp2p/tcptransport.nim +++ b/libp2p/tcptransport.nim @@ -17,13 +17,15 @@ type TcpTransport* = ref object of Transport proc connHandler*(t: Transport, server: StreamServer, - client: StreamTransport): + client: StreamTransport, + initiator: bool = false): Future[Connection] {.async, gcsafe.} = let conn: Connection = newConnection(newChronosStream(server, client)) - let handlerFut = if t.handler == nil: nil else: t.handler(conn) - let connHolder: ConnHolder = ConnHolder(connection: conn, - connFuture: handlerFut) - t.connections.add(connHolder) + if not initiator: + let handlerFut = if t.handler == nil: nil else: t.handler(conn) + let connHolder: ConnHolder = ConnHolder(connection: conn, + connFuture: handlerFut) + t.connections.add(connHolder) result = conn proc connCb(server: StreamServer, @@ -61,6 +63,6 @@ method dial*(t: TcpTransport, Future[Connection] {.async, gcsafe.} = ## dial a peer let client: StreamTransport = await connect(address) - result = await t.connHandler(t.server, client) + result = await t.connHandler(t.server, client, true) method handles*(t: TcpTransport, address: MultiAddress): bool {.gcsafe.} = true