mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
updated multiselect.py and newsfragment
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
import trio
|
||||||
|
|
||||||
from libp2p.abc import (
|
from libp2p.abc import (
|
||||||
IMultiselectCommunicator,
|
IMultiselectCommunicator,
|
||||||
IMultiselectMuxer,
|
IMultiselectMuxer,
|
||||||
@ -14,6 +16,7 @@ from .exceptions import (
|
|||||||
|
|
||||||
MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0"
|
MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0"
|
||||||
PROTOCOL_NOT_FOUND_MSG = "na"
|
PROTOCOL_NOT_FOUND_MSG = "na"
|
||||||
|
DEFAULT_NEGOTIATE_TIMEOUT = 60
|
||||||
|
|
||||||
|
|
||||||
class Multiselect(IMultiselectMuxer):
|
class Multiselect(IMultiselectMuxer):
|
||||||
@ -102,7 +105,10 @@ class Multiselect(IMultiselectMuxer):
|
|||||||
raise MultiselectError() from error
|
raise MultiselectError() from error
|
||||||
|
|
||||||
try:
|
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:
|
except MultiselectCommunicatorError as error:
|
||||||
raise MultiselectError() from error
|
raise MultiselectError() from error
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
Add timeout to:
|
Add timeout to:
|
||||||
1. multiselect handshake
|
1. multiselect handshake in multiselect_client.py and multiselect.py
|
||||||
2. query_multistream_command
|
2. query_multistream_command
|
||||||
3. try_select
|
3. try_select
|
||||||
to prevent indefinite hangs when a remote peer does not respond.
|
to prevent indefinite hangs when a remote peer does not respond.
|
||||||
|
|||||||
Reference in New Issue
Block a user