diff --git a/libp2p/security/base_session.py b/libp2p/security/base_session.py index 3cfd0190..5b23ba64 100644 --- a/libp2p/security/base_session.py +++ b/libp2p/security/base_session.py @@ -13,12 +13,21 @@ class BaseSession(ISecureConn, IRawConnection): def __init__( self, transport: BaseSecureTransport, conn: IRawConnection, peer_id: ID ) -> None: - self.local_peer = self.transport.local_peer - self.local_private_key = self.transport.local_private_key + self.local_peer = transport.local_peer + self.local_private_key = transport.local_private_key self.insecure_conn = conn self.remote_peer_id = peer_id self.remote_permanent_pubkey = b"" + # TODO clean up how this is passed around? + @property + def initiator(self) -> bool: + return self.insecure_conn.initiator + + # TODO clean up how this is passed around? + def next_stream_id(self) -> int: + return self.insecure_conn.next_stream_id() + def get_local_peer(self) -> ID: return self.local_peer diff --git a/libp2p/security/simple/transport.py b/libp2p/security/simple/transport.py index 87883998..8a9c6dbb 100644 --- a/libp2p/security/simple/transport.py +++ b/libp2p/security/simple/transport.py @@ -2,11 +2,12 @@ import asyncio from libp2p.network.connection.raw_connection_interface import IRawConnection from libp2p.peer.id import ID +from libp2p.security.base_transport import BaseSecureTransport +from libp2p.security.insecure.transport import InsecureSession from libp2p.security.secure_conn_interface import ISecureConn -from libp2p.security.secure_transport_interface import ISecureTransport -class SimpleSecurityTransport(ISecureTransport): +class SimpleSecurityTransport(BaseSecureTransport): key_phrase: str def __init__(self, key_phrase: str) -> None: @@ -26,7 +27,12 @@ class SimpleSecurityTransport(ISecureTransport): "Key phrase differed between nodes. Expected " + self.key_phrase ) - return conn + session = InsecureSession(self, conn, ID(b"")) + # NOTE: this is abusing the abstraction we have here + # but this code may be deprecated soon and this exists + # mainly to satisfy a test that will go along w/ it + session.key_phrase = self.key_phrase + return session async def secure_outbound(self, conn: IRawConnection, peer_id: ID) -> ISecureConn: """ @@ -46,4 +52,9 @@ class SimpleSecurityTransport(ISecureTransport): "Key phrase differed between nodes. Expected " + self.key_phrase ) - return conn + session = InsecureSession(self, conn, peer_id) + # NOTE: this is abusing the abstraction we have here + # but this code may be deprecated soon and this exists + # mainly to satisfy a test that will go along w/ it + session.key_phrase = self.key_phrase + return session diff --git a/libp2p/stream_muxer/mplex/mplex.py b/libp2p/stream_muxer/mplex/mplex.py index 60db1d2d..00dc25c3 100644 --- a/libp2p/stream_muxer/mplex/mplex.py +++ b/libp2p/stream_muxer/mplex/mplex.py @@ -39,7 +39,7 @@ class Mplex(IMuxedConn): :param peer_id: peer_id of peer the connection is to """ self.conn = secured_conn - self.initiator = self.conn.initiator + self.initiator = secured_conn.initiator # Store generic protocol handler self.generic_protocol_handler = generic_protocol_handler