-
Notifications
You must be signed in to change notification settings - Fork 175
fix: Added multiselect type consistency in negotiate
method
#814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5d17cc7
e3658ca
3f0211d
71d208a
ade4588
1fb0ace
962fba5
1a7fb78
227627b
b5090c2
abe640b
95598fa
69abcdf
96ffba9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,9 @@ | |
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 @@ async def select_transport( | |
: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 @@ async def select_transport( | |
else: | ||
# Select protocol if non-initiator | ||
protocol, _ = await self.multiselect.negotiate(communicator) | ||
if protocol is None: | ||
raise SecurityUpgradeFailure("No protocol selected") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. |
||
# Return transport from protocol | ||
return self.transports[protocol] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,9 @@ | |
PROTOCOL_ID, | ||
Yamux, | ||
) | ||
from libp2p.transport.exceptions import ( | ||
MuxerUpgradeFailure, | ||
) | ||
|
||
|
||
class MuxerMultistream: | ||
|
@@ -73,14 +76,16 @@ async def select_transport(self, conn: IRawConnection) -> TMuxerClass: | |
: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( | ||
tuple(self.transports.keys()), communicator | ||
) | ||
else: | ||
protocol, _ = await self.multiselect.negotiate(communicator) | ||
if protocol is None: | ||
raise MuxerUpgradeFailure("No protocol selected") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, somethink like: |
||
return self.transports[protocol] | ||
|
||
async def new_conn(self, conn: ISecureConn, peer_id: ID) -> IMuxedConn: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added multiselect type consistency in negotiate method. Updates all the usages of the method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For error messages, can you be more verbose, something like:
raise StreamFailure("Failed to negotiate protocol: no protocol selected")