mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
added none type to return value of negotiate and changed caller handles to handle none. Added newsfragment.
This commit is contained in:
@ -288,6 +288,9 @@ class BasicHost(IHost):
|
||||
protocol, handler = await self.multiselect.negotiate(
|
||||
MultiselectCommunicator(net_stream), self.negotiate_timeout
|
||||
)
|
||||
if protocol is None:
|
||||
await net_stream.reset()
|
||||
raise StreamFailure("No protocol selected")
|
||||
except MultiselectError as error:
|
||||
peer_id = net_stream.muxed_conn.peer_id
|
||||
logger.debug(
|
||||
|
||||
@ -53,7 +53,7 @@ class Multiselect(IMultiselectMuxer):
|
||||
self,
|
||||
communicator: IMultiselectCommunicator,
|
||||
negotiate_timeout: int = DEFAULT_NEGOTIATE_TIMEOUT,
|
||||
) -> tuple[TProtocol, StreamHandlerFn | None]:
|
||||
) -> tuple[TProtocol | None, StreamHandlerFn | None]:
|
||||
"""
|
||||
Negotiate performs protocol selection.
|
||||
|
||||
|
||||
@ -26,6 +26,9 @@ from libp2p.protocol_muxer.multiselect_client import (
|
||||
from libp2p.protocol_muxer.multiselect_communicator import (
|
||||
MultiselectCommunicator,
|
||||
)
|
||||
from libp2p.transport.exceptions import (
|
||||
SecurityUpgradeFailure,
|
||||
)
|
||||
|
||||
"""
|
||||
Represents a secured connection object, which includes a connection and details about
|
||||
@ -104,7 +107,7 @@ class SecurityMultistream(ABC):
|
||||
:param is_initiator: true if we are the initiator, false otherwise
|
||||
:return: selected secure transport
|
||||
"""
|
||||
protocol: TProtocol
|
||||
protocol: TProtocol | None
|
||||
communicator = MultiselectCommunicator(conn)
|
||||
if is_initiator:
|
||||
# Select protocol if initiator
|
||||
@ -114,5 +117,7 @@ class SecurityMultistream(ABC):
|
||||
else:
|
||||
# Select protocol if non-initiator
|
||||
protocol, _ = await self.multiselect.negotiate(communicator)
|
||||
if protocol is None:
|
||||
raise SecurityUpgradeFailure("No protocol selected")
|
||||
# Return transport from protocol
|
||||
return self.transports[protocol]
|
||||
|
||||
@ -30,6 +30,9 @@ from libp2p.stream_muxer.yamux.yamux import (
|
||||
PROTOCOL_ID,
|
||||
Yamux,
|
||||
)
|
||||
from libp2p.transport.exceptions import (
|
||||
MuxerUpgradeFailure,
|
||||
)
|
||||
|
||||
|
||||
class MuxerMultistream:
|
||||
@ -73,7 +76,7 @@ class MuxerMultistream:
|
||||
:param conn: conn to choose a transport over
|
||||
:return: selected muxer transport
|
||||
"""
|
||||
protocol: TProtocol
|
||||
protocol: TProtocol | None
|
||||
communicator = MultiselectCommunicator(conn)
|
||||
if conn.is_initiator:
|
||||
protocol = await self.multiselect_client.select_one_of(
|
||||
@ -81,6 +84,8 @@ class MuxerMultistream:
|
||||
)
|
||||
else:
|
||||
protocol, _ = await self.multiselect.negotiate(communicator)
|
||||
if protocol is None:
|
||||
raise MuxerUpgradeFailure("No protocol selected")
|
||||
return self.transports[protocol]
|
||||
|
||||
async def new_conn(self, conn: ISecureConn, peer_id: ID) -> IMuxedConn:
|
||||
|
||||
1
newsfragments/837.fix.rst
Normal file
1
newsfragments/837.fix.rst
Normal file
@ -0,0 +1 @@
|
||||
Added multiselect type consistency in negotiate method. Updates all the usages of the method.
|
||||
Reference in New Issue
Block a user