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.

get_connection_type() ConnectionType

Get connection type by delegating to secured_conn.

get_remote_address() tuple[str, int] | None

Return the transport-level remote endpoint, same as Mplex.

Delegates to secured_conn so callers (e.g. host subsystems) can resolve the peer address without opening a stream — matching get_remote_address().

get_transport_addresses() list[Multiaddr]

Get transport addresses by delegating to secured_conn.

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_established: bool

Check if the Yamux connection is fully established and ready for streams.

Returns True when: - The event_started has been set - The handle_incoming task is actively running - The connection is not shutting down

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
rtt() float

Return the current smoothed RTT estimate in seconds.

async start() None

Start the multiplexer.