28f6de37ee
* ignore kad * fix swarm, and minor * fix init and swarm * ignore pb * enable mypy * fix basic host * fix tcp * fix mplex * add typing for pb * skip format pyi * [mypy] no need to ignore pb now * add typing to chat
44 lines
1004 B
Python
44 lines
1004 B
Python
from abc import ABC, abstractmethod
|
|
|
|
from libp2p.stream_muxer.abc import IMuxedConn
|
|
from libp2p.typing import TProtocol
|
|
|
|
|
|
class INetStream(ABC):
|
|
|
|
mplex_conn: IMuxedConn
|
|
|
|
@abstractmethod
|
|
def get_protocol(self) -> TProtocol:
|
|
"""
|
|
:return: protocol id that stream runs on
|
|
"""
|
|
|
|
@abstractmethod
|
|
def set_protocol(self, protocol_id: TProtocol) -> bool:
|
|
"""
|
|
:param protocol_id: protocol id that stream runs on
|
|
:return: true if successful
|
|
"""
|
|
|
|
@abstractmethod
|
|
async def read(self) -> bytes:
|
|
"""
|
|
reads from the underlying muxed_stream
|
|
:return: bytes of input
|
|
"""
|
|
|
|
@abstractmethod
|
|
async def write(self, data: bytes) -> int:
|
|
"""
|
|
write to the underlying muxed_stream
|
|
:return: number of bytes written
|
|
"""
|
|
|
|
@abstractmethod
|
|
async def close(self) -> bool:
|
|
"""
|
|
close the underlying muxed stream
|
|
:return: true if successful
|
|
"""
|