libp2p.stream_muxer.mplex package¶
Submodules¶
libp2p.stream_muxer.mplex.constants module¶
libp2p.stream_muxer.mplex.datastructures module¶
libp2p.stream_muxer.mplex.exceptions module¶
-
exception
libp2p.stream_muxer.mplex.exceptions.
MplexError
¶
-
exception
libp2p.stream_muxer.mplex.exceptions.
MplexStreamClosed
¶
-
exception
libp2p.stream_muxer.mplex.exceptions.
MplexStreamEOF
¶
-
exception
libp2p.stream_muxer.mplex.exceptions.
MplexStreamReset
¶
libp2p.stream_muxer.mplex.mplex module¶
-
class
libp2p.stream_muxer.mplex.mplex.
Mplex
(secured_conn: libp2p.security.secure_conn_interface.ISecureConn, peer_id: libp2p.peer.id.ID)¶ Bases:
libp2p.stream_muxer.abc.IMuxedConn
reference: https://github.com/libp2p/go-mplex/blob/master/multiplex.go
-
async
accept_stream
() → libp2p.stream_muxer.abc.IMuxedStream¶ accepts a muxed stream opened by the other end.
-
async
close
() → None¶ close the stream muxer and underlying secured connection.
-
event_closed
: trio.Event = None¶
-
event_shutting_down
: trio.Event = None¶
-
event_started
: trio.Event = None¶
-
async
handle_incoming
() → None¶ Read a message off of the secured connection and add it to the corresponding message buffer.
-
property
is_closed
¶ check connection is fully closed.
- Returns
true if successful
-
property
is_initiator
¶ if this connection is the initiator.
-
new_stream_receive_channel
: 'trio.MemoryReceiveChannel[IMuxedStream]' = None¶
-
new_stream_send_channel
: 'trio.MemorySendChannel[IMuxedStream]' = None¶
-
next_channel_id
: int = None¶
-
async
open_stream
() → libp2p.stream_muxer.abc.IMuxedStream¶ creates a new muxed_stream.
- Returns
a new
MplexStream
-
peer_id
: ID = None¶
-
async
read_message
() → Tuple[int, int, bytes]¶ Read a single message off of the secured connection.
- Returns
stream_id, flag, message contents
-
secured_conn
: ISecureConn = None¶
-
async
send_message
(flag: libp2p.stream_muxer.mplex.constants.HeaderTags, data: Optional[bytes], stream_id: libp2p.stream_muxer.mplex.datastructures.StreamID) → int¶ sends a message over the connection.
- Parameters
flag – header to use
data – data to send in the message
stream_id – stream the message is in
-
async
start
() → None¶ start the multiplexer.
-
streams
: Dict[StreamID, MplexStream] = None¶
-
streams_lock
: trio.Lock = None¶
-
streams_msg_channels
: Dict[StreamID, 'trio.MemorySendChannel[bytes]'] = None¶
-
async
write_to_stream
(_bytes: bytes) → None¶ writes a byte array to a secured connection.
- Parameters
_bytes – byte array to write
- Returns
length written
-
async
libp2p.stream_muxer.mplex.mplex_stream module¶
-
class
libp2p.stream_muxer.mplex.mplex_stream.
MplexStream
(name: str, stream_id: libp2p.stream_muxer.mplex.datastructures.StreamID, muxed_conn: Mplex, incoming_data_channel: trio.MemoryReceiveChannel[bytes])¶ Bases:
libp2p.stream_muxer.abc.IMuxedStream
reference: https://github.com/libp2p/go-mplex/blob/master/stream.go
-
async
close
() → None¶ Closing a stream closes it for writing and closes the remote end for reading but allows writing in the other direction.
-
close_lock
: trio.Lock = None¶
-
event_local_closed
: trio.Event = None¶
-
event_remote_closed
: trio.Event = None¶
-
event_reset
: trio.Event = None¶
-
incoming_data_channel
: 'trio.MemoryReceiveChannel[bytes]' = None¶
-
property
is_initiator
¶
-
muxed_conn
: 'Mplex' = None¶
-
name
: str = None¶
-
async
read
(n: int = None) → bytes¶ Read up to n bytes. Read possibly returns fewer than n bytes, if there are not enough bytes in the Mplex buffer. If n is None, read until EOF.
- Parameters
n – number of bytes to read
- Returns
bytes actually read
-
read_deadline
: int = None¶
-
async
reset
() → None¶ closes both ends of the stream tells this remote side to hang up.
-
set_deadline
(ttl: int) → bool¶ set deadline for muxed stream.
- Returns
True if successful
-
set_read_deadline
(ttl: int) → bool¶ set read deadline for muxed stream.
- Returns
True if successful
-
set_write_deadline
(ttl: int) → bool¶ set write deadline for muxed stream.
- Returns
True if successful
-
stream_id
: StreamID = None¶
-
async
write
(data: bytes) → None¶ write to stream.
- Returns
number of bytes written
-
write_deadline
: int = None¶
-
async