From a01d1db6a08acf17e6c81cfee06f6e1a12951d02 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sat, 28 Sep 2019 13:56:13 -0600 Subject: [PATCH] prperly close and chronos connections --- libp2p/stream/chronosstream.nim | 13 ++++--------- libp2p/transports/tcptransport.nim | 1 + libp2p/transports/transport.nim | 3 ++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/libp2p/stream/chronosstream.nim b/libp2p/stream/chronosstream.nim index 2a4bf3a21..4cc921302 100644 --- a/libp2p/stream/chronosstream.nim +++ b/libp2p/stream/chronosstream.nim @@ -95,15 +95,10 @@ method write*(s: ChronosStream, msg: seq[byte], msglen = -1) {.async, gcsafe.} = method close*(s: ChronosStream) {.async, gcsafe.} = if not s.closed: - trace "closing connection for", address = $s.client.remoteAddress() - if not s.reader.closed: - await s.reader.closeWait() - + trace "shutting down server", address = $s.client.remoteAddress() await s.writer.finish() - if not s.writer.closed: - await s.writer.closeWait() + await s.writer.closeWait() + await s.reader.closeWait() + await s.client.closeWait() - if not s.client.closed: - await s.client.closeWait() - s.closed = true diff --git a/libp2p/transports/tcptransport.nim b/libp2p/transports/tcptransport.nim index 83ff4cfda..6845d6653 100644 --- a/libp2p/transports/tcptransport.nim +++ b/libp2p/transports/tcptransport.nim @@ -67,6 +67,7 @@ method listen*(t: TcpTransport, # always get the resolved address in case we're bound to 0.0.0.0:0 t.ma = t.server.sock.getLocalAddress().toMultiAddr() result = t.server.join() + trace "started node on", address = t.ma method dial*(t: TcpTransport, address: MultiAddress): diff --git a/libp2p/transports/transport.nim b/libp2p/transports/transport.nim index 8b4af30ce..1e196cd06 100644 --- a/libp2p/transports/transport.nim +++ b/libp2p/transports/transport.nim @@ -8,7 +8,7 @@ ## those terms. import sequtils -import chronos +import chronos, chronicles import ../peerinfo, ../connection, ../multiaddress, @@ -47,6 +47,7 @@ method listen*(t: Transport, ## listen for incoming connections t.ma = ma t.handler = handler + debug "starting node", address = $ma method dial*(t: Transport, address: MultiAddress):