PR feedback

This commit is contained in:
Chih Cheng Liang 2019-08-02 14:12:59 +08:00
parent e731f77f2d
commit 10a8347c6a
No known key found for this signature in database
GPG Key ID: C86B5E6612B1487A
4 changed files with 12 additions and 11 deletions

View File

@ -4,16 +4,16 @@ from libp2p.security.secure_conn_interface import ISecureConn
from typing import TYPE_CHECKING, Dict, Any, cast from typing import TYPE_CHECKING, Dict, Any, cast
if TYPE_CHECKING: if TYPE_CHECKING:
from .secure_conn_interface import ISecureConn
from libp2p.network.connection.raw_connection_interface import IRawConnection from libp2p.network.connection.raw_connection_interface import IRawConnection
from libp2p.peer.id import ID from libp2p.peer.id import ID
from .secure_conn_interface import ISecureConn
from .typing import TSecurityDetails from .typing import TSecurityDetails
class InsecureTransport(ISecureTransport): 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 self.transport_id = transport_id
async def secure_inbound(self, conn: "IRawConnection") -> ISecureConn: async def secure_inbound(self, conn: "IRawConnection") -> ISecureConn:
@ -41,16 +41,16 @@ class InsecureConn(ISecureConn):
conn: "IRawConnection" conn: "IRawConnection"
details: "TSecurityDetails" details: "TSecurityDetails"
def __init__(self, conn: "IRawConnection", conn_id: int) -> None: def __init__(self, conn: "IRawConnection", conn_id: str) -> None:
self.conn = conn self.conn = conn
self.details = cast("TSecurityDetails", {}) self.details = cast("TSecurityDetails", {})
self.details["id"] = conn_id self.details["id"] = conn_id
def get_conn(self) -> "ISecureConn": def get_conn(self) -> "IRawConnection":
""" """
:return: connection object that has been made secure :return: connection object that has been made secure
""" """
return cast("ISecureConn", self.conn) return self.conn
def get_security_details(self) -> "TSecurityDetails": def get_security_details(self) -> "TSecurityDetails":
""" """

View File

@ -3,6 +3,7 @@ from abc import ABC, abstractmethod
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
if TYPE_CHECKING: if TYPE_CHECKING:
from libp2p.network.connection.raw_connection_interface import IRawConnection
from .typing import TSecurityDetails from .typing import TSecurityDetails
# pylint: disable=W0105 # pylint: disable=W0105
@ -17,9 +18,9 @@ Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interfa
class ISecureConn(ABC): class ISecureConn(ABC):
@abstractmethod @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 @abstractmethod

View File

@ -67,11 +67,11 @@ class SimpleSecureConn(ISecureConn):
self.details = cast("TSecurityDetails", {}) self.details = cast("TSecurityDetails", {})
self.details["key_phrase"] = key_phrase 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: connection object that has been made secure
""" """
return cast("ISecureConn", self.conn) return self.conn
def get_security_details(self) -> "TSecurityDetails": def get_security_details(self) -> "TSecurityDetails":
""" """

View File

@ -1,4 +1,4 @@
from typing import TypeVar, Dict, Any, NewType from typing import TypeVar, Dict, Any, NewType
TSecurityDetails = NewType("TSecurityDetails", Dict[str, Any]) TSecurityDetails = NewType("TSecurityDetails", Dict[str, str])