mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
updated multiselect.py and newsfragment
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import trio
|
||||
|
||||
from libp2p.abc import (
|
||||
IMultiselectCommunicator,
|
||||
IMultiselectMuxer,
|
||||
@ -14,6 +16,7 @@ from .exceptions import (
|
||||
|
||||
MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0"
|
||||
PROTOCOL_NOT_FOUND_MSG = "na"
|
||||
DEFAULT_NEGOTIATE_TIMEOUT = 60
|
||||
|
||||
|
||||
class Multiselect(IMultiselectMuxer):
|
||||
@ -102,7 +105,10 @@ class Multiselect(IMultiselectMuxer):
|
||||
raise MultiselectError() from error
|
||||
|
||||
try:
|
||||
handshake_contents = await communicator.read()
|
||||
with trio.fail_after(DEFAULT_NEGOTIATE_TIMEOUT): # Timeout after 5 seconds
|
||||
handshake_contents = await communicator.read()
|
||||
except trio.TooSlowError:
|
||||
raise MultiselectError("protocol selection response timed out")
|
||||
except MultiselectCommunicatorError as error:
|
||||
raise MultiselectError() from error
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
Add timeout to:
|
||||
1. multiselect handshake
|
||||
1. multiselect handshake in multiselect_client.py and multiselect.py
|
||||
2. query_multistream_command
|
||||
3. try_select
|
||||
to prevent indefinite hangs when a remote peer does not respond.
|
||||
|
||||
Reference in New Issue
Block a user