Wire some missing properties up

This commit is contained in:
Alex Stokes 2019-08-02 17:41:29 -07:00
parent 02e073d85a
commit 0ebc8ffb21
No known key found for this signature in database
GPG Key ID: 51CE1721B245C086
3 changed files with 27 additions and 7 deletions

View File

@ -13,12 +13,21 @@ class BaseSession(ISecureConn, IRawConnection):
def __init__( def __init__(
self, transport: BaseSecureTransport, conn: IRawConnection, peer_id: ID self, transport: BaseSecureTransport, conn: IRawConnection, peer_id: ID
) -> None: ) -> None:
self.local_peer = self.transport.local_peer self.local_peer = transport.local_peer
self.local_private_key = self.transport.local_private_key self.local_private_key = transport.local_private_key
self.insecure_conn = conn self.insecure_conn = conn
self.remote_peer_id = peer_id self.remote_peer_id = peer_id
self.remote_permanent_pubkey = b"" 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: def get_local_peer(self) -> ID:
return self.local_peer return self.local_peer

View File

@ -2,11 +2,12 @@ import asyncio
from libp2p.network.connection.raw_connection_interface import IRawConnection from libp2p.network.connection.raw_connection_interface import IRawConnection
from libp2p.peer.id import ID 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_conn_interface import ISecureConn
from libp2p.security.secure_transport_interface import ISecureTransport
class SimpleSecurityTransport(ISecureTransport): class SimpleSecurityTransport(BaseSecureTransport):
key_phrase: str key_phrase: str
def __init__(self, key_phrase: str) -> None: def __init__(self, key_phrase: str) -> None:
@ -26,7 +27,12 @@ class SimpleSecurityTransport(ISecureTransport):
"Key phrase differed between nodes. Expected " + self.key_phrase "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: 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 "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

View File

@ -39,7 +39,7 @@ class Mplex(IMuxedConn):
:param peer_id: peer_id of peer the connection is to :param peer_id: peer_id of peer the connection is to
""" """
self.conn = secured_conn self.conn = secured_conn
self.initiator = self.conn.initiator self.initiator = secured_conn.initiator
# Store generic protocol handler # Store generic protocol handler
self.generic_protocol_handler = generic_protocol_handler self.generic_protocol_handler = generic_protocol_handler