libp2p.stream_muxer.yamux

class libp2p.stream_muxer.yamux.Yamux(secured_conn: ISecureConn, peer_id: ID, is_initiator: bool | None = None, on_close: Callable[[], Awaitable[Any]] | None = None)

Bases: IMuxedConn

async accept_stream() IMuxedStream

Accept a new stream from the remote peer.

Returns:

IMuxedStream: A new stream from the remote peer.

Raises:
MuxedConnUnavailable: If the connection is closed while waiting for a new

stream. This ensures that accept_stream() does not hang indefinitely when the underlying connection terminates (either cleanly or due to error). The caller (e.g., SwarmConn) catches this exception to properly clean up the connection.

async close(error_code: int = 0) None

Close the multiplexed connection.

async handle_incoming() None
property is_closed: bool

Check if the connection is fully closed.

Returns:

True if the connection is closed, otherwise False.

property is_initiator: bool

Determine if this connection is the initiator.

Returns:

True if this connection initiated the connection, otherwise False.

async open_stream() YamuxStream

Create and open a new multiplexed stream.

Returns:

A new instance of IMuxedStream.

async read_stream(stream_id: int, n: int = -1) bytes
async start() None

Start the multiplexer.