diff --git a/libp2p/stream_muxer/mplex/mplex.py b/libp2p/stream_muxer/mplex/mplex.py index e75d8eea..233a9e66 100644 --- a/libp2p/stream_muxer/mplex/mplex.py +++ b/libp2p/stream_muxer/mplex/mplex.py @@ -42,7 +42,7 @@ class Mplex(IMuxedConn): for new muxed streams :param peer_id: peer_id of peer the connection is to """ - super(Mplex, self).__init__(secured_conn, generic_protocol_handler, peer_id) + super().__init__(secured_conn, generic_protocol_handler, peer_id) self.secured_conn = secured_conn self.raw_conn = secured_conn.get_conn() @@ -111,7 +111,6 @@ class Mplex(IMuxedConn): async def accept_stream(self) -> None: """ accepts a muxed stream opened by the other end - :return: the accepted stream """ stream_id = await self.stream_queue.get() stream = MplexStream(stream_id, False, self) diff --git a/libp2p/stream_muxer/muxed_connection_interface.py b/libp2p/stream_muxer/muxed_connection_interface.py index b7bd4e6b..9236fbca 100644 --- a/libp2p/stream_muxer/muxed_connection_interface.py +++ b/libp2p/stream_muxer/muxed_connection_interface.py @@ -1,6 +1,13 @@ from abc import ABC, abstractmethod -from libp2p.peer.id import ID +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from multiaddr import Multiaddr + from libp2p.security.secure_conn_interface import ISecureConn + from libp2p.network.swarm import GenericProtocolHandlerFn + from libp2p.peer.id import ID + from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream class IMuxedConn(ABC): @@ -9,10 +16,15 @@ class IMuxedConn(ABC): """ initiator: bool - peer_id: ID + peer_id: "ID" @abstractmethod - def __init__(self, conn, generic_protocol_handler, peer_id): + def __init__( + self, + conn: "ISecureConn", + generic_protocol_handler: "GenericProtocolHandlerFn", + peer_id: "ID", + ) -> None: """ create a new muxed connection :param conn: an instance of secured connection @@ -22,21 +34,22 @@ class IMuxedConn(ABC): """ @abstractmethod - def close(self): + def close(self) -> None: """ close connection - :return: true if successful """ @abstractmethod - def is_closed(self): + def is_closed(self) -> bool: """ check connection is fully closed :return: true if successful """ @abstractmethod - def open_stream(self, protocol_id, multi_addr): + async def open_stream( + self, protocol_id: str, multi_addr: "Multiaddr" + ) -> "IMuxedStream": """ creates a new muxed_stream :param protocol_id: protocol_id of stream @@ -45,8 +58,7 @@ class IMuxedConn(ABC): """ @abstractmethod - def accept_stream(self): + async def accept_stream(self) -> None: """ accepts a muxed stream opened by the other end - :return: the accepted stream """