From 6a7f9f058c04ecdfd26e5dbfd8df88221b8511e7 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 21 Feb 2020 08:25:09 -0600 Subject: [PATCH] address review comments --- libp2p/switch.nim | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libp2p/switch.nim b/libp2p/switch.nim index 704d39de8..42a1a78f6 100644 --- a/libp2p/switch.nim +++ b/libp2p/switch.nim @@ -145,8 +145,7 @@ proc cleanupConn(s: Switch, conn: Connection) {.async, gcsafe.} = await s.connections[id].close() s.connections.del(id) - if id in s.dialedPubSubPeers: - s.dialedPubSubPeers.excl(id) + s.dialedPubSubPeers.excl(id) # TODO: Investigate cleanupConn() always called twice for one peer. if not(conn.peerInfo.isClosed()): @@ -222,7 +221,11 @@ proc dial*(s: Switch, for a in peer.addrs: # for each address if t.handles(a): # check if it can dial it trace "Dialing address", address = $a - conn = await t.dial(a) + try: + conn = await t.dial(a) + except CatchableError as exc: + trace "couldn't dial peer, transport failed", exc = exc.msg, address = a + continue # make sure to assign the peer to the connection conn.peerInfo = peer conn = await s.upgradeOutgoing(conn) @@ -276,7 +279,7 @@ proc start*(s: Switch): Future[seq[Future[void]]] {.async, gcsafe.} = await conn.close() await s.cleanupConn(conn) - + var startFuts: seq[Future[void]] for t in s.transports: # for each transport for i, a in s.peerInfo.addrs: @@ -307,7 +310,7 @@ proc subscribeToPeer(s: Switch, peerInfo: PeerInfo) {.async, gcsafe.} = let conn = await s.dial(peerInfo, s.pubSub.get().codec) await s.pubSub.get().subscribeToPeer(conn) except CatchableError as exc: - trace "unable to initiate pubsub", exc = exc.msg + warn "unable to initiate pubsub", exc = exc.msg s.dialedPubSubPeers.excl(peerInfo.id) proc subscribe*(s: Switch, topic: string, handler: TopicHandler): Future[void] {.gcsafe.} =