libp2p.network.stream package

Submodules

libp2p.network.stream.exceptions module

exception libp2p.network.stream.exceptions.StreamClosed

Bases: StreamError

exception libp2p.network.stream.exceptions.StreamEOF

Bases: StreamError, EOFError

exception libp2p.network.stream.exceptions.StreamError

Bases: IOException

exception libp2p.network.stream.exceptions.StreamReset

Bases: StreamError

libp2p.network.stream.net_stream module

class libp2p.network.stream.net_stream.NetStream(muxed_stream: IMuxedStream)

Bases: INetStream

async close() None

Close stream.

get_protocol() TProtocol
Returns:

protocol id that stream runs on

muxed_stream: IMuxedStream
protocol_id: TProtocol | None
async read(n: int | None = None) bytes

Read from stream.

Parameters:

n – number of bytes to read

Returns:

bytes of input

async reset() None

Close both ends of the stream.

set_protocol(protocol_id: TProtocol) None
Parameters:

protocol_id – protocol id that stream runs on

async write(data: bytes) None

Write to stream.

Returns:

number of bytes written

libp2p.network.stream.net_stream_interface module

class libp2p.network.stream.net_stream_interface.INetStream

Bases: ReadWriteCloser

abstract get_protocol() TProtocol
Returns:

protocol id that stream runs on

muxed_conn: IMuxedConn
abstract async reset() None

Close both ends of the stream.

abstract set_protocol(protocol_id: TProtocol) None
Parameters:

protocol_id – protocol id that stream runs on

Module contents