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:
@ -1,12 +1,22 @@
|
||||
from libp2p.security.secure_transport_interface import ISecureTransport
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
|
||||
from typing import TYPE_CHECKING, Dict, Any, cast
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .secure_conn_interface import ISecureConn
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
from .typing import TSecurityDetails
|
||||
|
||||
|
||||
class InsecureTransport(ISecureTransport):
|
||||
def __init__(self, transport_id):
|
||||
transport_id: int
|
||||
|
||||
def __init__(self, transport_id: int) -> None:
|
||||
self.transport_id = transport_id
|
||||
|
||||
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)
|
||||
@ -15,7 +25,9 @@ class InsecureTransport(ISecureTransport):
|
||||
insecure_conn = InsecureConn(conn, self.transport_id)
|
||||
return insecure_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)
|
||||
@ -26,18 +38,21 @@ class InsecureTransport(ISecureTransport):
|
||||
|
||||
|
||||
class InsecureConn(ISecureConn):
|
||||
def __init__(self, conn, conn_id):
|
||||
conn: "IRawConnection"
|
||||
details: "TSecurityDetails"
|
||||
|
||||
def __init__(self, conn: "IRawConnection", conn_id: int) -> None:
|
||||
self.conn = conn
|
||||
self.details = {}
|
||||
self.details = cast("TSecurityDetails", {})
|
||||
self.details["id"] = conn_id
|
||||
|
||||
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