2019-07-31 15:00:12 -07:00
|
|
|
from abc import ABC, abstractmethod
|
2018-11-11 18:03:04 -05:00
|
|
|
|
2019-07-30 23:41:28 +08:00
|
|
|
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
2019-07-30 15:31:02 +08:00
|
|
|
|
2019-01-09 21:38:56 +03:00
|
|
|
|
2018-10-31 22:31:00 +01:00
|
|
|
class IMuxedStream(ABC):
|
|
|
|
|
2019-07-30 23:41:28 +08:00
|
|
|
mplex_conn: IMuxedConn
|
2019-07-30 15:31:02 +08:00
|
|
|
|
2018-11-11 18:03:04 -05:00
|
|
|
@abstractmethod
|
|
|
|
def read(self):
|
|
|
|
"""
|
2018-11-26 18:24:29 -05:00
|
|
|
reads from the underlying muxed_conn
|
2018-11-11 18:03:04 -05:00
|
|
|
:return: bytes of input
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def write(self, _bytes):
|
|
|
|
"""
|
2018-11-26 18:24:29 -05:00
|
|
|
writes to the underlying muxed_conn
|
2018-11-11 18:03:04 -05:00
|
|
|
:return: number of bytes written
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def close(self):
|
|
|
|
"""
|
2018-11-26 18:24:29 -05:00
|
|
|
close the underlying muxed_conn
|
2018-11-11 18:03:04 -05:00
|
|
|
:return: true if successful
|
|
|
|
"""
|
2018-10-31 22:31:00 +01:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def reset(self):
|
|
|
|
"""
|
|
|
|
closes both ends of the stream
|
|
|
|
tells this remote side to hang up
|
|
|
|
:return: error/exception
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def set_deadline(self, ttl):
|
|
|
|
"""
|
|
|
|
set deadline for muxed stream
|
|
|
|
:return: a new stream
|
|
|
|
"""
|