libp2p.stream_muxer package

Subpackages

Submodules

libp2p.stream_muxer.abc module

class libp2p.stream_muxer.abc.IMuxedConn(conn: ISecureConn, peer_id: ID)

Bases: ABC

reference: https://github.com/libp2p/go-stream-muxer/blob/master/muxer.go

abstract async accept_stream() IMuxedStream

Accept a muxed stream opened by the other end.

abstract async close() None

Close connection.

event_started: Event
abstract property is_closed: bool

Check connection is fully closed.

Returns:

true if successful

abstract property is_initiator: bool

If this connection is the initiator.

abstract async open_stream() IMuxedStream

Create a new muxed_stream.

Returns:

a new IMuxedStream stream

peer_id: ID
abstract async start() None

Start the multiplexer.

class libp2p.stream_muxer.abc.IMuxedStream

Bases: ReadWriteCloser

muxed_conn: IMuxedConn
abstract async reset() None

Close both ends of the stream tells this remote side to hang up.

abstract set_deadline(ttl: int) bool

Set deadline for muxed stream.

Returns:

a new stream

libp2p.stream_muxer.exceptions module

exception libp2p.stream_muxer.exceptions.MuxedConnError

Bases: BaseLibp2pError

exception libp2p.stream_muxer.exceptions.MuxedConnUnavailable

Bases: MuxedConnError

exception libp2p.stream_muxer.exceptions.MuxedStreamClosed

Bases: MuxedStreamError

exception libp2p.stream_muxer.exceptions.MuxedStreamEOF

Bases: MuxedStreamError, EOFError

exception libp2p.stream_muxer.exceptions.MuxedStreamError

Bases: BaseLibp2pError

exception libp2p.stream_muxer.exceptions.MuxedStreamReset

Bases: MuxedStreamError

libp2p.stream_muxer.muxer_multistream module

class libp2p.stream_muxer.muxer_multistream.MuxerMultistream(muxer_transports_by_protocol: Mapping[TProtocol, Type[IMuxedConn]])

Bases: object

MuxerMultistream is a multistream stream muxed transport multiplexer.

go implementation: github.com/libp2p/go-stream-muxer-multistream/multistream.go

add_transport(protocol: TProtocol, transport: Type[IMuxedConn]) None

Add a protocol and its corresponding transport to multistream- select(multiselect). The order that a protocol is added is exactly the precedence it is negotiated in multiselect.

Parameters:
  • protocol – the protocol name, which is negotiated in multiselect.

  • transport – the corresponding transportation to the protocol.

multiselect: Multiselect
multiselect_client: MultiselectClient
async new_conn(conn: ISecureConn, peer_id: ID) IMuxedConn
async select_transport(conn: IRawConnection) Type[IMuxedConn]

Select a transport that both us and the node on the other end of conn support and agree on.

Parameters:

conn – conn to choose a transport over

Returns:

selected muxer transport

transports: OrderedDict[TProtocol, Type[IMuxedConn]]

Module contents