From b9d18750275492e37b9c9ae0ebb4fd65a8668722 Mon Sep 17 00:00:00 2001 From: NIC619 Date: Thu, 19 Sep 2019 21:24:01 +0800 Subject: [PATCH] Catch `OpenConnectionError` in `swarm.dial_peer` --- libp2p/network/swarm.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libp2p/network/swarm.py b/libp2p/network/swarm.py index 711dc88..83df555 100644 --- a/libp2p/network/swarm.py +++ b/libp2p/network/swarm.py @@ -13,7 +13,11 @@ from libp2p.protocol_muxer.multiselect_client import MultiselectClient from libp2p.protocol_muxer.multiselect_communicator import MultiselectCommunicator from libp2p.routing.interfaces import IPeerRouting from libp2p.stream_muxer.abc import IMuxedConn, IMuxedStream -from libp2p.transport.exceptions import MuxerUpgradeFailure, SecurityUpgradeFailure +from libp2p.transport.exceptions import ( + MuxerUpgradeFailure, + OpenConnectionError, + SecurityUpgradeFailure, +) from libp2p.transport.listener_interface import IListener from libp2p.transport.transport_interface import ITransport from libp2p.transport.upgrader import TransportUpgrader @@ -118,7 +122,13 @@ class Swarm(INetwork): multiaddr = self.router.find_peer(peer_id) # Dial peer (connection to peer does not yet exist) # Transport dials peer (gets back a raw conn) - raw_conn = await self.transport.dial(multiaddr) + try: + raw_conn = await self.transport.dial(multiaddr) + except OpenConnectionError as error: + logger.debug("fail to dial peer %s over base transport", peer_id) + raise SwarmException( + "fail to open connection to peer %s", peer_id + ) from error logger.debug("dialed peer %s over base transport", peer_id)