mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Run black over repo
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
from libp2p.security.secure_transport_interface import ISecureTransport
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
|
||||
class InsecureTransport(ISecureTransport):
|
||||
|
||||
class InsecureTransport(ISecureTransport):
|
||||
def __init__(self, transport_id):
|
||||
self.transport_id = transport_id
|
||||
|
||||
@ -24,8 +24,8 @@ class InsecureTransport(ISecureTransport):
|
||||
insecure_conn = InsecureConn(conn, self.transport_id)
|
||||
return insecure_conn
|
||||
|
||||
class InsecureConn(ISecureConn):
|
||||
|
||||
class InsecureConn(ISecureConn):
|
||||
def __init__(self, conn, conn_id):
|
||||
self.conn = conn
|
||||
self.details = {}
|
||||
|
||||
@ -8,8 +8,9 @@ involved in the secured connection
|
||||
|
||||
Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interface.go
|
||||
"""
|
||||
class ISecureConn(ABC):
|
||||
|
||||
|
||||
class ISecureConn(ABC):
|
||||
@abstractmethod
|
||||
def get_conn(self):
|
||||
"""
|
||||
|
||||
@ -8,8 +8,9 @@ chosen by a security transport multistream module.
|
||||
|
||||
Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interface.go
|
||||
"""
|
||||
class ISecureTransport(ABC):
|
||||
|
||||
|
||||
class ISecureTransport(ABC):
|
||||
@abstractmethod
|
||||
async def secure_inbound(self, conn):
|
||||
"""
|
||||
|
||||
@ -10,8 +10,9 @@ involved in the secured connection
|
||||
|
||||
Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interface.go
|
||||
"""
|
||||
class SecurityMultistream(ABC):
|
||||
|
||||
|
||||
class SecurityMultistream(ABC):
|
||||
def __init__(self):
|
||||
# Map protocol to secure transport
|
||||
self.transports = {}
|
||||
@ -31,7 +32,6 @@ class SecurityMultistream(ABC):
|
||||
# we only care about selecting the protocol, not any handler function
|
||||
self.multiselect.add_handler(protocol, None)
|
||||
|
||||
|
||||
async def secure_inbound(self, conn):
|
||||
"""
|
||||
Secure the connection, either locally or by communicating with opposing node via conn,
|
||||
@ -47,7 +47,6 @@ class SecurityMultistream(ABC):
|
||||
|
||||
return secure_conn
|
||||
|
||||
|
||||
async def secure_outbound(self, conn, peer_id):
|
||||
"""
|
||||
Secure the connection, either locally or by communicating with opposing node via conn,
|
||||
@ -63,7 +62,6 @@ class SecurityMultistream(ABC):
|
||||
|
||||
return secure_conn
|
||||
|
||||
|
||||
async def select_transport(self, conn, initiator):
|
||||
"""
|
||||
Select a transport that both us and the node on the
|
||||
@ -79,8 +77,9 @@ class SecurityMultistream(ABC):
|
||||
protocol = None
|
||||
if initiator:
|
||||
# Select protocol if initiator
|
||||
protocol = \
|
||||
await self.multiselect_client.select_one_of(list(self.transports.keys()), conn)
|
||||
protocol = await self.multiselect_client.select_one_of(
|
||||
list(self.transports.keys()), conn
|
||||
)
|
||||
else:
|
||||
# Select protocol if non-initiator
|
||||
protocol, _ = await self.multiselect.negotiate(conn)
|
||||
|
||||
@ -2,8 +2,8 @@ import asyncio
|
||||
from libp2p.security.secure_transport_interface import ISecureTransport
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
|
||||
class SimpleSecurityTransport(ISecureTransport):
|
||||
|
||||
class SimpleSecurityTransport(ISecureTransport):
|
||||
def __init__(self, key_phrase):
|
||||
self.key_phrase = key_phrase
|
||||
|
||||
@ -17,7 +17,9 @@ class SimpleSecurityTransport(ISecureTransport):
|
||||
incoming = (await conn.read()).decode()
|
||||
|
||||
if incoming != self.key_phrase:
|
||||
raise Exception("Key phrase differed between nodes. Expected " + self.key_phrase)
|
||||
raise Exception(
|
||||
"Key phrase differed between nodes. Expected " + self.key_phrase
|
||||
)
|
||||
|
||||
secure_conn = SimpleSecureConn(conn, self.key_phrase)
|
||||
return secure_conn
|
||||
@ -36,13 +38,15 @@ class SimpleSecurityTransport(ISecureTransport):
|
||||
await asyncio.sleep(0)
|
||||
|
||||
if incoming != self.key_phrase:
|
||||
raise Exception("Key phrase differed between nodes. Expected " + self.key_phrase)
|
||||
raise Exception(
|
||||
"Key phrase differed between nodes. Expected " + self.key_phrase
|
||||
)
|
||||
|
||||
secure_conn = SimpleSecureConn(conn, self.key_phrase)
|
||||
return secure_conn
|
||||
|
||||
class SimpleSecureConn(ISecureConn):
|
||||
|
||||
class SimpleSecureConn(ISecureConn):
|
||||
def __init__(self, conn, key_phrase):
|
||||
self.conn = conn
|
||||
self.details = {}
|
||||
|
||||
Reference in New Issue
Block a user