typed muxed_connection_interface.py
This commit is contained in:
parent
b64ed9fd6f
commit
dadac423f2
|
@ -42,7 +42,7 @@ class Mplex(IMuxedConn):
|
||||||
for new muxed streams
|
for new muxed streams
|
||||||
:param peer_id: peer_id of peer the connection is to
|
: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.secured_conn = secured_conn
|
||||||
self.raw_conn = secured_conn.get_conn()
|
self.raw_conn = secured_conn.get_conn()
|
||||||
|
@ -111,7 +111,6 @@ class Mplex(IMuxedConn):
|
||||||
async def accept_stream(self) -> None:
|
async def accept_stream(self) -> None:
|
||||||
"""
|
"""
|
||||||
accepts a muxed stream opened by the other end
|
accepts a muxed stream opened by the other end
|
||||||
:return: the accepted stream
|
|
||||||
"""
|
"""
|
||||||
stream_id = await self.stream_queue.get()
|
stream_id = await self.stream_queue.get()
|
||||||
stream = MplexStream(stream_id, False, self)
|
stream = MplexStream(stream_id, False, self)
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
from abc import ABC, abstractmethod
|
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):
|
class IMuxedConn(ABC):
|
||||||
|
@ -9,10 +16,15 @@ class IMuxedConn(ABC):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
initiator: bool
|
initiator: bool
|
||||||
peer_id: ID
|
peer_id: "ID"
|
||||||
|
|
||||||
@abstractmethod
|
@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
|
create a new muxed connection
|
||||||
:param conn: an instance of secured connection
|
:param conn: an instance of secured connection
|
||||||
|
@ -22,21 +34,22 @@ class IMuxedConn(ABC):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def close(self):
|
def close(self) -> None:
|
||||||
"""
|
"""
|
||||||
close connection
|
close connection
|
||||||
:return: true if successful
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def is_closed(self):
|
def is_closed(self) -> bool:
|
||||||
"""
|
"""
|
||||||
check connection is fully closed
|
check connection is fully closed
|
||||||
:return: true if successful
|
:return: true if successful
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@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
|
creates a new muxed_stream
|
||||||
:param protocol_id: protocol_id of stream
|
:param protocol_id: protocol_id of stream
|
||||||
|
@ -45,8 +58,7 @@ class IMuxedConn(ABC):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def accept_stream(self):
|
async def accept_stream(self) -> None:
|
||||||
"""
|
"""
|
||||||
accepts a muxed stream opened by the other end
|
accepts a muxed stream opened by the other end
|
||||||
:return: the accepted stream
|
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user