mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
add typing to security
This commit is contained in:
@ -2,12 +2,21 @@ import asyncio
|
||||
from libp2p.security.secure_transport_interface import ISecureTransport
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
|
||||
from typing import TYPE_CHECKING, cast
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
from .typing import TSecurityDetails
|
||||
|
||||
|
||||
class SimpleSecurityTransport(ISecureTransport):
|
||||
def __init__(self, key_phrase):
|
||||
key_phrase: str
|
||||
|
||||
def __init__(self, key_phrase: str) -> None:
|
||||
self.key_phrase = key_phrase
|
||||
|
||||
async def secure_inbound(self, conn):
|
||||
async def secure_inbound(self, conn: "IRawConnection") -> "ISecureConn":
|
||||
"""
|
||||
Secure the connection, either locally or by communicating with opposing node via conn,
|
||||
for an inbound connection (i.e. we are not the initiator)
|
||||
@ -24,7 +33,9 @@ class SimpleSecurityTransport(ISecureTransport):
|
||||
secure_conn = SimpleSecureConn(conn, self.key_phrase)
|
||||
return secure_conn
|
||||
|
||||
async def secure_outbound(self, conn, peer_id):
|
||||
async def secure_outbound(
|
||||
self, conn: "IRawConnection", peer_id: "ID"
|
||||
) -> "ISecureConn":
|
||||
"""
|
||||
Secure the connection, either locally or by communicating with opposing node via conn,
|
||||
for an inbound connection (i.e. we are the initiator)
|
||||
@ -47,18 +58,22 @@ class SimpleSecurityTransport(ISecureTransport):
|
||||
|
||||
|
||||
class SimpleSecureConn(ISecureConn):
|
||||
def __init__(self, conn, key_phrase):
|
||||
conn: "IRawConnection"
|
||||
key_phrase: str
|
||||
details: "TSecurityDetails"
|
||||
|
||||
def __init__(self, conn: "IRawConnection", key_phrase: str) -> None:
|
||||
self.conn = conn
|
||||
self.details = {}
|
||||
self.details = cast("TSecurityDetails", {})
|
||||
self.details["key_phrase"] = key_phrase
|
||||
|
||||
def get_conn(self):
|
||||
def get_conn(self) -> "ISecureConn":
|
||||
"""
|
||||
:return: connection object that has been made secure
|
||||
"""
|
||||
return self.conn
|
||||
return cast("ISecureConn", self.conn)
|
||||
|
||||
def get_security_details(self):
|
||||
def get_security_details(self) -> "TSecurityDetails":
|
||||
"""
|
||||
:return: map containing details about the connections security
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user