mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
fix: added negotiate timeout to MuxerMultistream
This commit is contained in:
@ -2,6 +2,8 @@ from collections.abc import (
|
|||||||
Sequence,
|
Sequence,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
import trio
|
||||||
|
|
||||||
from libp2p.abc import (
|
from libp2p.abc import (
|
||||||
IMultiselectClient,
|
IMultiselectClient,
|
||||||
IMultiselectCommunicator,
|
IMultiselectCommunicator,
|
||||||
@ -17,6 +19,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 MultiselectClient(IMultiselectClient):
|
class MultiselectClient(IMultiselectClient):
|
||||||
@ -39,7 +42,10 @@ class MultiselectClient(IMultiselectClient):
|
|||||||
raise MultiselectClientError() from error
|
raise MultiselectClientError() from error
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handshake_contents = await communicator.read()
|
with trio.fail_after(DEFAULT_NEGOTIATE_TIMEOUT):
|
||||||
|
handshake_contents = await communicator.read()
|
||||||
|
except trio.TooSlowError:
|
||||||
|
raise MultiselectClientError("handshake read timed out")
|
||||||
except MultiselectCommunicatorError as error:
|
except MultiselectCommunicatorError as error:
|
||||||
raise MultiselectClientError() from error
|
raise MultiselectClientError() from error
|
||||||
|
|
||||||
@ -93,8 +99,11 @@ class MultiselectClient(IMultiselectClient):
|
|||||||
raise ValueError("Command not supported")
|
raise ValueError("Command not supported")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = await communicator.read()
|
with trio.fail_after(DEFAULT_NEGOTIATE_TIMEOUT): # Timeout after 5 seconds
|
||||||
|
response = await communicator.read()
|
||||||
response_list = response.strip().splitlines()
|
response_list = response.strip().splitlines()
|
||||||
|
except trio.TooSlowError:
|
||||||
|
raise MultiselectClientError("command response timed out")
|
||||||
except MultiselectCommunicatorError as error:
|
except MultiselectCommunicatorError as error:
|
||||||
raise MultiselectClientError() from error
|
raise MultiselectClientError() from error
|
||||||
|
|
||||||
@ -117,7 +126,10 @@ class MultiselectClient(IMultiselectClient):
|
|||||||
raise MultiselectClientError() from error
|
raise MultiselectClientError() from error
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = await communicator.read()
|
with trio.fail_after(DEFAULT_NEGOTIATE_TIMEOUT): # Timeout after 5 seconds
|
||||||
|
response = await communicator.read()
|
||||||
|
except trio.TooSlowError:
|
||||||
|
raise MultiselectClientError("protocol selection response timed out")
|
||||||
except MultiselectCommunicatorError as error:
|
except MultiselectCommunicatorError as error:
|
||||||
raise MultiselectClientError() from error
|
raise MultiselectClientError() from error
|
||||||
|
|
||||||
|
|||||||
@ -31,9 +31,6 @@ from libp2p.stream_muxer.yamux.yamux import (
|
|||||||
Yamux,
|
Yamux,
|
||||||
)
|
)
|
||||||
|
|
||||||
# FIXME: add negotiate timeout to `MuxerMultistream`
|
|
||||||
DEFAULT_NEGOTIATE_TIMEOUT = 60
|
|
||||||
|
|
||||||
|
|
||||||
class MuxerMultistream:
|
class MuxerMultistream:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user