mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
Code cleanup / formatting
This commit is contained in:
@ -15,7 +15,6 @@ def _serialize_public_key(key: PublicKey) -> bytes:
|
|||||||
|
|
||||||
|
|
||||||
class ID:
|
class ID:
|
||||||
|
|
||||||
_bytes: bytes
|
_bytes: bytes
|
||||||
_xor_id: int = None
|
_xor_id: int = None
|
||||||
_b58_str: str = None
|
_b58_str: str = None
|
||||||
|
|||||||
@ -24,20 +24,13 @@ class SecurityMultistream(ABC):
|
|||||||
multiselect_client: MultiselectClient
|
multiselect_client: MultiselectClient
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
# Map protocol to secure transport
|
|
||||||
self.transports = {}
|
self.transports = {}
|
||||||
|
|
||||||
# Create multiselect
|
|
||||||
self.multiselect = Multiselect()
|
self.multiselect = Multiselect()
|
||||||
|
|
||||||
# Create multiselect client
|
|
||||||
self.multiselect_client = MultiselectClient()
|
self.multiselect_client = MultiselectClient()
|
||||||
|
|
||||||
def add_transport(self, protocol: TProtocol, transport: ISecureTransport) -> None:
|
def add_transport(self, protocol: TProtocol, transport: ISecureTransport) -> None:
|
||||||
# Associate protocol with transport
|
|
||||||
self.transports[protocol] = transport
|
self.transports[protocol] = transport
|
||||||
|
|
||||||
# Add protocol and handler to multiselect
|
|
||||||
# Note: None is added as the handler for the given protocol since
|
# Note: None is added as the handler for the given protocol since
|
||||||
# we only care about selecting the protocol, not any handler function
|
# we only care about selecting the protocol, not any handler function
|
||||||
self.multiselect.add_handler(protocol, None)
|
self.multiselect.add_handler(protocol, None)
|
||||||
@ -48,13 +41,8 @@ class SecurityMultistream(ABC):
|
|||||||
for an inbound connection (i.e. we are not the initiator)
|
for an inbound connection (i.e. we are not the initiator)
|
||||||
:return: secure connection object (that implements secure_conn_interface)
|
:return: secure connection object (that implements secure_conn_interface)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Select a secure transport
|
|
||||||
transport = await self.select_transport(conn, False)
|
transport = await self.select_transport(conn, False)
|
||||||
|
|
||||||
# Create secured connection
|
|
||||||
secure_conn = await transport.secure_inbound(conn)
|
secure_conn = await transport.secure_inbound(conn)
|
||||||
|
|
||||||
return secure_conn
|
return secure_conn
|
||||||
|
|
||||||
async def secure_outbound(self, conn: IRawConnection, peer_id: ID) -> ISecureConn:
|
async def secure_outbound(self, conn: IRawConnection, peer_id: ID) -> ISecureConn:
|
||||||
@ -63,13 +51,8 @@ class SecurityMultistream(ABC):
|
|||||||
for an inbound connection (i.e. we are the initiator)
|
for an inbound connection (i.e. we are the initiator)
|
||||||
:return: secure connection object (that implements secure_conn_interface)
|
:return: secure connection object (that implements secure_conn_interface)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Select a secure transport
|
|
||||||
transport = await self.select_transport(conn, True)
|
transport = await self.select_transport(conn, True)
|
||||||
|
|
||||||
# Create secured connection
|
|
||||||
secure_conn = await transport.secure_outbound(conn, peer_id)
|
secure_conn = await transport.secure_outbound(conn, peer_id)
|
||||||
|
|
||||||
return secure_conn
|
return secure_conn
|
||||||
|
|
||||||
async def select_transport(
|
async def select_transport(
|
||||||
|
|||||||
@ -54,7 +54,5 @@ class TransportUpgrader:
|
|||||||
"""
|
"""
|
||||||
Upgrade raw connection to muxed connection
|
Upgrade raw connection to muxed connection
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# For PoC, no security, default to mplex
|
|
||||||
# TODO do exchange to determine multiplexer
|
# TODO do exchange to determine multiplexer
|
||||||
return Mplex(conn, generic_protocol_handler, peer_id)
|
return Mplex(conn, generic_protocol_handler, peer_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user