mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +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(
|
protocol, handler = await self.multiselect.negotiate(
|
||||||
MultiselectCommunicator(net_stream), self.negotiate_timeout
|
MultiselectCommunicator(net_stream), self.negotiate_timeout
|
||||||
)
|
)
|
||||||
|
if protocol is None:
|
||||||
|
await net_stream.reset()
|
||||||
|
raise StreamFailure("No protocol selected")
|
||||||
except MultiselectError as error:
|
except MultiselectError as error:
|
||||||
peer_id = net_stream.muxed_conn.peer_id
|
peer_id = net_stream.muxed_conn.peer_id
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
|||||||
@ -53,7 +53,7 @@ class Multiselect(IMultiselectMuxer):
|
|||||||
self,
|
self,
|
||||||
communicator: IMultiselectCommunicator,
|
communicator: IMultiselectCommunicator,
|
||||||
negotiate_timeout: int = DEFAULT_NEGOTIATE_TIMEOUT,
|
negotiate_timeout: int = DEFAULT_NEGOTIATE_TIMEOUT,
|
||||||
) -> tuple[TProtocol, StreamHandlerFn | None]:
|
) -> tuple[TProtocol | None, StreamHandlerFn | None]:
|
||||||
"""
|
"""
|
||||||
Negotiate performs protocol selection.
|
Negotiate performs protocol selection.
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,9 @@ from libp2p.protocol_muxer.multiselect_client import (
|
|||||||
from libp2p.protocol_muxer.multiselect_communicator import (
|
from libp2p.protocol_muxer.multiselect_communicator import (
|
||||||
MultiselectCommunicator,
|
MultiselectCommunicator,
|
||||||
)
|
)
|
||||||
|
from libp2p.transport.exceptions import (
|
||||||
|
SecurityUpgradeFailure,
|
||||||
|
)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Represents a secured connection object, which includes a connection and details about
|
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
|
:param is_initiator: true if we are the initiator, false otherwise
|
||||||
:return: selected secure transport
|
:return: selected secure transport
|
||||||
"""
|
"""
|
||||||
protocol: TProtocol
|
protocol: TProtocol | None
|
||||||
communicator = MultiselectCommunicator(conn)
|
communicator = MultiselectCommunicator(conn)
|
||||||
if is_initiator:
|
if is_initiator:
|
||||||
# Select protocol if initiator
|
# Select protocol if initiator
|
||||||
@ -114,5 +117,7 @@ class SecurityMultistream(ABC):
|
|||||||
else:
|
else:
|
||||||
# Select protocol if non-initiator
|
# Select protocol if non-initiator
|
||||||
protocol, _ = await self.multiselect.negotiate(communicator)
|
protocol, _ = await self.multiselect.negotiate(communicator)
|
||||||
|
if protocol is None:
|
||||||
|
raise SecurityUpgradeFailure("No protocol selected")
|
||||||
# Return transport from protocol
|
# Return transport from protocol
|
||||||
return self.transports[protocol]
|
return self.transports[protocol]
|
||||||
|
|||||||
@ -30,6 +30,9 @@ from libp2p.stream_muxer.yamux.yamux import (
|
|||||||
PROTOCOL_ID,
|
PROTOCOL_ID,
|
||||||
Yamux,
|
Yamux,
|
||||||
)
|
)
|
||||||
|
from libp2p.transport.exceptions import (
|
||||||
|
MuxerUpgradeFailure,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MuxerMultistream:
|
class MuxerMultistream:
|
||||||
@ -73,7 +76,7 @@ class MuxerMultistream:
|
|||||||
:param conn: conn to choose a transport over
|
:param conn: conn to choose a transport over
|
||||||
:return: selected muxer transport
|
:return: selected muxer transport
|
||||||
"""
|
"""
|
||||||
protocol: TProtocol
|
protocol: TProtocol | None
|
||||||
communicator = MultiselectCommunicator(conn)
|
communicator = MultiselectCommunicator(conn)
|
||||||
if conn.is_initiator:
|
if conn.is_initiator:
|
||||||
protocol = await self.multiselect_client.select_one_of(
|
protocol = await self.multiselect_client.select_one_of(
|
||||||
@ -81,6 +84,8 @@ class MuxerMultistream:
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
protocol, _ = await self.multiselect.negotiate(communicator)
|
protocol, _ = await self.multiselect.negotiate(communicator)
|
||||||
|
if protocol is None:
|
||||||
|
raise MuxerUpgradeFailure("No protocol selected")
|
||||||
return self.transports[protocol]
|
return self.transports[protocol]
|
||||||
|
|
||||||
async def new_conn(self, conn: ISecureConn, peer_id: ID) -> IMuxedConn:
|
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