Raise OpenConnectionError

when failed to open connection
This commit is contained in:
NIC619 2019-09-19 21:23:35 +08:00
parent c44be5e247
commit 1f76f6ee1b
No known key found for this signature in database
GPG Key ID: 570C35F5C2D51B17

View File

@ -6,6 +6,7 @@ from multiaddr import Multiaddr
from libp2p.network.connection.raw_connection import RawConnection from libp2p.network.connection.raw_connection import RawConnection
from libp2p.network.connection.raw_connection_interface import IRawConnection from libp2p.network.connection.raw_connection_interface import IRawConnection
from libp2p.transport.exceptions import OpenConnectionError
from libp2p.transport.listener_interface import IListener from libp2p.transport.listener_interface import IListener
from libp2p.transport.transport_interface import ITransport from libp2p.transport.transport_interface import ITransport
from libp2p.transport.typing import THandler from libp2p.transport.typing import THandler
@ -66,7 +67,10 @@ class TCP(ITransport):
self.host = maddr.value_for_protocol("ip4") self.host = maddr.value_for_protocol("ip4")
self.port = int(maddr.value_for_protocol("tcp")) self.port = int(maddr.value_for_protocol("tcp"))
try:
reader, writer = await asyncio.open_connection(self.host, self.port) reader, writer = await asyncio.open_connection(self.host, self.port)
except (ConnectionAbortedError, ConnectionRefusedError) as error:
raise OpenConnectionError(error)
return RawConnection(reader, writer, True) return RawConnection(reader, writer, True)