Ping protocol: move with statement out of try

This commit is contained in:
mhchia
2020-02-04 15:09:42 +08:00
parent 113696dce2
commit 5da102d1c9

View File

@ -17,8 +17,8 @@ logger = logging.getLogger("libp2p.host.ping")
async def _handle_ping(stream: INetStream, peer_id: PeerID) -> bool: async def _handle_ping(stream: INetStream, peer_id: PeerID) -> bool:
"""Return a boolean indicating if we expect more pings from the peer at """Return a boolean indicating if we expect more pings from the peer at
``peer_id``.""" ``peer_id``."""
with trio.fail_after(RESP_TIMEOUT):
try: try:
with trio.fail_after(RESP_TIMEOUT):
payload = await stream.read(PING_LENGTH) payload = await stream.read(PING_LENGTH)
except trio.TooSlowError as error: except trio.TooSlowError as error:
logger.debug("Timed out waiting for ping from %s: %s", peer_id, error) logger.debug("Timed out waiting for ping from %s: %s", peer_id, error)