mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
fix: removed dummy ID(b) from upgrade_security for inbound connections (#681)
* fix: removed dummy ID(b) from upgrade_security for inbound connections * added newsfragment * updated newsfragment
This commit is contained in:
committed by
GitHub
parent
d61bca78ab
commit
2ed2587fc9
@ -187,7 +187,7 @@ class Swarm(Service, INetworkService):
|
|||||||
# Per, https://discuss.libp2p.io/t/multistream-security/130, we first secure
|
# Per, https://discuss.libp2p.io/t/multistream-security/130, we first secure
|
||||||
# the conn and then mux the conn
|
# the conn and then mux the conn
|
||||||
try:
|
try:
|
||||||
secured_conn = await self.upgrader.upgrade_security(raw_conn, peer_id, True)
|
secured_conn = await self.upgrader.upgrade_security(raw_conn, True, peer_id)
|
||||||
except SecurityUpgradeFailure as error:
|
except SecurityUpgradeFailure as error:
|
||||||
logger.debug("failed to upgrade security for peer %s", peer_id)
|
logger.debug("failed to upgrade security for peer %s", peer_id)
|
||||||
await raw_conn.close()
|
await raw_conn.close()
|
||||||
@ -257,10 +257,7 @@ class Swarm(Service, INetworkService):
|
|||||||
# Per, https://discuss.libp2p.io/t/multistream-security/130, we first
|
# Per, https://discuss.libp2p.io/t/multistream-security/130, we first
|
||||||
# secure the conn and then mux the conn
|
# secure the conn and then mux the conn
|
||||||
try:
|
try:
|
||||||
# FIXME: This dummy `ID(b"")` for the remote peer is useless.
|
secured_conn = await self.upgrader.upgrade_security(raw_conn, False)
|
||||||
secured_conn = await self.upgrader.upgrade_security(
|
|
||||||
raw_conn, ID(b""), False
|
|
||||||
)
|
|
||||||
except SecurityUpgradeFailure as error:
|
except SecurityUpgradeFailure as error:
|
||||||
logger.debug("failed to upgrade security for peer at %s", maddr)
|
logger.debug("failed to upgrade security for peer at %s", maddr)
|
||||||
await raw_conn.close()
|
await raw_conn.close()
|
||||||
|
|||||||
@ -48,11 +48,16 @@ class TransportUpgrader:
|
|||||||
# TODO: Figure out what to do with this function.
|
# TODO: Figure out what to do with this function.
|
||||||
|
|
||||||
async def upgrade_security(
|
async def upgrade_security(
|
||||||
self, raw_conn: IRawConnection, peer_id: ID, is_initiator: bool
|
self,
|
||||||
|
raw_conn: IRawConnection,
|
||||||
|
is_initiator: bool,
|
||||||
|
peer_id: ID | None = None,
|
||||||
) -> ISecureConn:
|
) -> ISecureConn:
|
||||||
"""Upgrade conn to a secured connection."""
|
"""Upgrade conn to a secured connection."""
|
||||||
try:
|
try:
|
||||||
if is_initiator:
|
if is_initiator:
|
||||||
|
if peer_id is None:
|
||||||
|
raise ValueError("peer_id must be provided for outbout connection")
|
||||||
return await self.security_multistream.secure_outbound(
|
return await self.security_multistream.secure_outbound(
|
||||||
raw_conn, peer_id
|
raw_conn, peer_id
|
||||||
)
|
)
|
||||||
|
|||||||
2
newsfragments/681.breaking.rst
Normal file
2
newsfragments/681.breaking.rst
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Reordered the arguments to `upgrade_security` to place `is_initiator` before `peer_id`, and made `peer_id` optional.
|
||||||
|
This allows the method to reflect the fact that peer identity is not required for inbound connections.
|
||||||
Reference in New Issue
Block a user