From 10a8347c6a2ce6f89aec7d63cbdc927c65d7e50a Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Fri, 2 Aug 2019 14:12:59 +0800 Subject: [PATCH] PR feedback --- libp2p/security/insecure_security.py | 12 ++++++------ libp2p/security/secure_conn_interface.py | 5 +++-- libp2p/security/simple_security.py | 4 ++-- libp2p/security/typing.py | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/libp2p/security/insecure_security.py b/libp2p/security/insecure_security.py index af648b0..959ea78 100644 --- a/libp2p/security/insecure_security.py +++ b/libp2p/security/insecure_security.py @@ -4,16 +4,16 @@ 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 .secure_conn_interface import ISecureConn from .typing import TSecurityDetails class InsecureTransport(ISecureTransport): - transport_id: int + transport_id: str - def __init__(self, transport_id: int) -> None: + def __init__(self, transport_id: str) -> None: self.transport_id = transport_id async def secure_inbound(self, conn: "IRawConnection") -> ISecureConn: @@ -41,16 +41,16 @@ class InsecureConn(ISecureConn): conn: "IRawConnection" details: "TSecurityDetails" - def __init__(self, conn: "IRawConnection", conn_id: int) -> None: + def __init__(self, conn: "IRawConnection", conn_id: str) -> None: self.conn = conn self.details = cast("TSecurityDetails", {}) self.details["id"] = conn_id - def get_conn(self) -> "ISecureConn": + def get_conn(self) -> "IRawConnection": """ :return: connection object that has been made secure """ - return cast("ISecureConn", self.conn) + return self.conn def get_security_details(self) -> "TSecurityDetails": """ diff --git a/libp2p/security/secure_conn_interface.py b/libp2p/security/secure_conn_interface.py index 5864bd9..f5de4cd 100644 --- a/libp2p/security/secure_conn_interface.py +++ b/libp2p/security/secure_conn_interface.py @@ -3,6 +3,7 @@ from abc import ABC, abstractmethod from typing import TYPE_CHECKING if TYPE_CHECKING: + from libp2p.network.connection.raw_connection_interface import IRawConnection from .typing import TSecurityDetails # pylint: disable=W0105 @@ -17,9 +18,9 @@ Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interfa class ISecureConn(ABC): @abstractmethod - def get_conn(self) -> "ISecureConn": + def get_conn(self) -> "IRawConnection": """ - :return: connection object that has been made secure + :return: the underlying raw connection """ @abstractmethod diff --git a/libp2p/security/simple_security.py b/libp2p/security/simple_security.py index f5df0b1..07a0129 100644 --- a/libp2p/security/simple_security.py +++ b/libp2p/security/simple_security.py @@ -67,11 +67,11 @@ class SimpleSecureConn(ISecureConn): self.details = cast("TSecurityDetails", {}) self.details["key_phrase"] = key_phrase - def get_conn(self) -> "ISecureConn": + def get_conn(self) -> "IRawConnection": """ :return: connection object that has been made secure """ - return cast("ISecureConn", self.conn) + return self.conn def get_security_details(self) -> "TSecurityDetails": """ diff --git a/libp2p/security/typing.py b/libp2p/security/typing.py index b2d3f4c..9832fbe 100644 --- a/libp2p/security/typing.py +++ b/libp2p/security/typing.py @@ -1,4 +1,4 @@ from typing import TypeVar, Dict, Any, NewType -TSecurityDetails = NewType("TSecurityDetails", Dict[str, Any]) +TSecurityDetails = NewType("TSecurityDetails", Dict[str, str])