mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 08:00:54 +00:00
DEFAULT_NEGOTIATE_TIMEOUT configurable
This commit is contained in:
@ -50,7 +50,9 @@ class Multiselect(IMultiselectMuxer):
|
|||||||
|
|
||||||
# FIXME: Make TProtocol Optional[TProtocol] to keep types consistent
|
# FIXME: Make TProtocol Optional[TProtocol] to keep types consistent
|
||||||
async def negotiate(
|
async def negotiate(
|
||||||
self, communicator: IMultiselectCommunicator
|
self,
|
||||||
|
communicator: IMultiselectCommunicator,
|
||||||
|
negotiate_timeout: int = DEFAULT_NEGOTIATE_TIMEOUT,
|
||||||
) -> tuple[TProtocol, StreamHandlerFn | None]:
|
) -> tuple[TProtocol, StreamHandlerFn | None]:
|
||||||
"""
|
"""
|
||||||
Negotiate performs protocol selection.
|
Negotiate performs protocol selection.
|
||||||
@ -60,7 +62,7 @@ class Multiselect(IMultiselectMuxer):
|
|||||||
:raise MultiselectError: raised when negotiation failed
|
:raise MultiselectError: raised when negotiation failed
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with trio.fail_after(DEFAULT_NEGOTIATE_TIMEOUT):
|
with trio.fail_after(negotiate_timeout):
|
||||||
await self.handshake(communicator)
|
await self.handshake(communicator)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
@ -51,7 +51,10 @@ class MultiselectClient(IMultiselectClient):
|
|||||||
raise MultiselectClientError("multiselect protocol ID mismatch")
|
raise MultiselectClientError("multiselect protocol ID mismatch")
|
||||||
|
|
||||||
async def select_one_of(
|
async def select_one_of(
|
||||||
self, protocols: Sequence[TProtocol], communicator: IMultiselectCommunicator
|
self,
|
||||||
|
protocols: Sequence[TProtocol],
|
||||||
|
communicator: IMultiselectCommunicator,
|
||||||
|
negotitate_timeout: int = DEFAULT_NEGOTIATE_TIMEOUT,
|
||||||
) -> TProtocol:
|
) -> TProtocol:
|
||||||
"""
|
"""
|
||||||
For each protocol, send message to multiselect selecting protocol and
|
For each protocol, send message to multiselect selecting protocol and
|
||||||
@ -64,7 +67,7 @@ class MultiselectClient(IMultiselectClient):
|
|||||||
:raise MultiselectClientError: raised when protocol negotiation failed
|
:raise MultiselectClientError: raised when protocol negotiation failed
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with trio.fail_after(DEFAULT_NEGOTIATE_TIMEOUT):
|
with trio.fail_after(negotitate_timeout):
|
||||||
await self.handshake(communicator)
|
await self.handshake(communicator)
|
||||||
|
|
||||||
for protocol in protocols:
|
for protocol in protocols:
|
||||||
@ -81,7 +84,10 @@ class MultiselectClient(IMultiselectClient):
|
|||||||
raise MultiselectClientError("response timed out")
|
raise MultiselectClientError("response timed out")
|
||||||
|
|
||||||
async def query_multistream_command(
|
async def query_multistream_command(
|
||||||
self, communicator: IMultiselectCommunicator, command: str
|
self,
|
||||||
|
communicator: IMultiselectCommunicator,
|
||||||
|
command: str,
|
||||||
|
response_timeout: int = DEFAULT_NEGOTIATE_TIMEOUT,
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
"""
|
"""
|
||||||
Send a multistream-select command over the given communicator and return
|
Send a multistream-select command over the given communicator and return
|
||||||
@ -89,11 +95,13 @@ class MultiselectClient(IMultiselectClient):
|
|||||||
|
|
||||||
:param communicator: communicator to use to communicate with counterparty
|
:param communicator: communicator to use to communicate with counterparty
|
||||||
:param command: supported multistream-select command(e.g., ls)
|
:param command: supported multistream-select command(e.g., ls)
|
||||||
|
:param negotiate_timeout: timeout for negotiation,
|
||||||
|
defaults to DEFAULT_NEGOTIATE_TIMEOUT
|
||||||
:raise MultiselectClientError: If the communicator fails to process data.
|
:raise MultiselectClientError: If the communicator fails to process data.
|
||||||
:return: list of strings representing the response from peer.
|
:return: list of strings representing the response from peer.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with trio.fail_after(DEFAULT_NEGOTIATE_TIMEOUT):
|
with trio.fail_after(response_timeout):
|
||||||
await self.handshake(communicator)
|
await self.handshake(communicator)
|
||||||
|
|
||||||
if command == "ls":
|
if command == "ls":
|
||||||
|
|||||||
Reference in New Issue
Block a user