mirror of https://github.com/vacp2p/nim-libp2p.git
fix: don't call conn handler on dials
This commit is contained in:
parent
0f52a6e798
commit
60245a065d
|
@ -17,13 +17,15 @@ type TcpTransport* = ref object of Transport
|
||||||
|
|
||||||
proc connHandler*(t: Transport,
|
proc connHandler*(t: Transport,
|
||||||
server: StreamServer,
|
server: StreamServer,
|
||||||
client: StreamTransport):
|
client: StreamTransport,
|
||||||
|
initiator: bool = false):
|
||||||
Future[Connection] {.async, gcsafe.} =
|
Future[Connection] {.async, gcsafe.} =
|
||||||
let conn: Connection = newConnection(newChronosStream(server, client))
|
let conn: Connection = newConnection(newChronosStream(server, client))
|
||||||
let handlerFut = if t.handler == nil: nil else: t.handler(conn)
|
if not initiator:
|
||||||
let connHolder: ConnHolder = ConnHolder(connection: conn,
|
let handlerFut = if t.handler == nil: nil else: t.handler(conn)
|
||||||
connFuture: handlerFut)
|
let connHolder: ConnHolder = ConnHolder(connection: conn,
|
||||||
t.connections.add(connHolder)
|
connFuture: handlerFut)
|
||||||
|
t.connections.add(connHolder)
|
||||||
result = conn
|
result = conn
|
||||||
|
|
||||||
proc connCb(server: StreamServer,
|
proc connCb(server: StreamServer,
|
||||||
|
@ -61,6 +63,6 @@ method dial*(t: TcpTransport,
|
||||||
Future[Connection] {.async, gcsafe.} =
|
Future[Connection] {.async, gcsafe.} =
|
||||||
## dial a peer
|
## dial a peer
|
||||||
let client: StreamTransport = await connect(address)
|
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
|
method handles*(t: TcpTransport, address: MultiAddress): bool {.gcsafe.} = true
|
||||||
|
|
Loading…
Reference in New Issue