Restructure mplex and mplex_stream

This commit is contained in:
mhchia
2019-09-05 22:29:33 +08:00
parent 96230758e4
commit eac159c527
4 changed files with 55 additions and 71 deletions

View File

@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING
from libp2p.peer.id import ID
from libp2p.security.secure_conn_interface import ISecureConn
@ -51,20 +51,6 @@ class IMuxedConn(ABC):
:return: true if successful
"""
@abstractmethod
async def read_buffer(self, stream_id: StreamID) -> bytes:
"""
Read a message from stream_id's buffer, check raw connection for new messages
:param stream_id: stream id of stream to read from
:return: message read
"""
@abstractmethod
async def read_buffer_nonblocking(self, stream_id: StreamID) -> Optional[bytes]:
"""
Read a message from `stream_id`'s buffer, non-blockingly.
"""
@abstractmethod
async def open_stream(self) -> "IMuxedStream":
"""
@ -73,7 +59,7 @@ class IMuxedConn(ABC):
"""
@abstractmethod
async def accept_stream(self, name: str) -> None:
async def accept_stream(self, stream_id: StreamID, name: str) -> None:
"""
accepts a muxed stream opened by the other end
"""