mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-07 13:40:56 +00:00
PR feedbacks
- Move exceptions to exceptions.py - Raise `UpgradeFailure` in upgrader - Refine the try/catch for upgraders in swarm
This commit is contained in:
@ -19,7 +19,7 @@ PLAINTEXT_PROTOCOL_ID = TProtocol("/plaintext/2.0.0")
|
||||
|
||||
|
||||
class InsecureSession(BaseSession):
|
||||
async def run_handshake(self):
|
||||
async def run_handshake(self) -> None:
|
||||
msg = make_exchange_message(self.local_private_key.get_public_key())
|
||||
msg_bytes = msg.SerializeToString()
|
||||
encoded_msg_bytes = encode_fixedint_prefixed(msg_bytes)
|
||||
|
||||
@ -4,15 +4,11 @@ from typing import Mapping
|
||||
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.protocol_muxer.multiselect import Multiselect, MultiselectError
|
||||
from libp2p.protocol_muxer.multiselect_client import (
|
||||
MultiselectClient,
|
||||
MultiselectClientError,
|
||||
)
|
||||
from libp2p.protocol_muxer.multiselect import Multiselect
|
||||
from libp2p.protocol_muxer.multiselect_client import MultiselectClient
|
||||
from libp2p.protocol_muxer.multiselect_communicator import RawConnectionCommunicator
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from libp2p.security.secure_transport_interface import ISecureTransport
|
||||
from libp2p.transport.exceptions import HandshakeFailure, SecurityUpgradeFailure
|
||||
from libp2p.typing import TProtocol
|
||||
|
||||
|
||||
@ -67,18 +63,8 @@ class SecurityMultistream(ABC):
|
||||
for an inbound connection (i.e. we are not the initiator)
|
||||
:return: secure connection object (that implements secure_conn_interface)
|
||||
"""
|
||||
try:
|
||||
transport = await self.select_transport(conn, False)
|
||||
except MultiselectError as error:
|
||||
raise SecurityUpgradeFailure(
|
||||
"failed to negotiate the secure protocol"
|
||||
) from error
|
||||
try:
|
||||
secure_conn = await transport.secure_inbound(conn)
|
||||
except HandshakeFailure as error:
|
||||
raise SecurityUpgradeFailure(
|
||||
"failed to secure the inbound transport"
|
||||
) from error
|
||||
transport = await self.select_transport(conn, False)
|
||||
secure_conn = await transport.secure_inbound(conn)
|
||||
return secure_conn
|
||||
|
||||
async def secure_outbound(self, conn: IRawConnection, peer_id: ID) -> ISecureConn:
|
||||
@ -87,18 +73,8 @@ class SecurityMultistream(ABC):
|
||||
for an inbound connection (i.e. we are the initiator)
|
||||
:return: secure connection object (that implements secure_conn_interface)
|
||||
"""
|
||||
try:
|
||||
transport = await self.select_transport(conn, True)
|
||||
except MultiselectClientError as error:
|
||||
raise SecurityUpgradeFailure(
|
||||
"failed to negotiate the secure protocol"
|
||||
) from error
|
||||
try:
|
||||
secure_conn = await transport.secure_outbound(conn, peer_id)
|
||||
except HandshakeFailure as error:
|
||||
raise SecurityUpgradeFailure(
|
||||
"failed to secure the outbound transport"
|
||||
) from error
|
||||
transport = await self.select_transport(conn, True)
|
||||
secure_conn = await transport.secure_outbound(conn, peer_id)
|
||||
return secure_conn
|
||||
|
||||
async def select_transport(
|
||||
|
||||
Reference in New Issue
Block a user