mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
Refactor mplex and start to add close detection
This commit is contained in:
@ -1,15 +1,8 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from libp2p.io.abc import ReadWriteCloser
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from libp2p.stream_muxer.mplex.constants import HeaderTags
|
||||
from libp2p.stream_muxer.mplex.datastructures import StreamID
|
||||
|
||||
if TYPE_CHECKING:
|
||||
# Prevent GenericProtocolHandlerFn introducing circular dependencies
|
||||
from libp2p.network.typing import GenericProtocolHandlerFn # noqa: F401
|
||||
|
||||
|
||||
class IMuxedConn(ABC):
|
||||
@ -20,16 +13,10 @@ class IMuxedConn(ABC):
|
||||
peer_id: ID
|
||||
|
||||
@abstractmethod
|
||||
def __init__(
|
||||
self,
|
||||
conn: ISecureConn,
|
||||
generic_protocol_handler: "GenericProtocolHandlerFn",
|
||||
peer_id: ID,
|
||||
) -> None:
|
||||
def __init__(self, conn: ISecureConn, peer_id: ID) -> None:
|
||||
"""
|
||||
create a new muxed connection
|
||||
:param conn: an instance of secured connection
|
||||
:param generic_protocol_handler: generic protocol handler
|
||||
for new muxed streams
|
||||
:param peer_id: peer_id of peer the connection is to
|
||||
"""
|
||||
@ -60,22 +47,11 @@ class IMuxedConn(ABC):
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def accept_stream(self, stream_id: StreamID, name: str) -> None:
|
||||
async def accept_stream(self) -> "IMuxedStream":
|
||||
"""
|
||||
accepts a muxed stream opened by the other end
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def send_message(
|
||||
self, flag: HeaderTags, data: bytes, stream_id: StreamID
|
||||
) -> int:
|
||||
"""
|
||||
sends a message over the connection
|
||||
:param header: header to use
|
||||
:param data: data to send in the message
|
||||
:param stream_id: stream the message is in
|
||||
"""
|
||||
|
||||
|
||||
class IMuxedStream(ReadWriteCloser):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user