stream_muxer done

This commit is contained in:
Chih Cheng Liang
2019-08-02 18:28:04 +08:00
parent dadac423f2
commit 4c9a930f84
5 changed files with 62 additions and 24 deletions

View File

@ -8,6 +8,7 @@ if TYPE_CHECKING:
from libp2p.network.swarm import GenericProtocolHandlerFn
from libp2p.peer.id import ID
from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream
from libp2p.stream_muxer.mplex.constants import HeaderTags
class IMuxedConn(ABC):
@ -46,6 +47,14 @@ class IMuxedConn(ABC):
:return: true if successful
"""
@abstractmethod
async def read_buffer(self, stream_id: int) -> 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 open_stream(
self, protocol_id: str, multi_addr: "Multiaddr"
@ -62,3 +71,12 @@ class IMuxedConn(ABC):
"""
accepts a muxed stream opened by the other end
"""
@abstractmethod
async def send_message(self, flag: HeaderTags, data: bytes, stream_id: int) -> 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
"""