libp2p.io package

Submodules

libp2p.io.abc module

class libp2p.io.abc.Closer

Bases: ABC

abstract async close() None
class libp2p.io.abc.EncryptedMsgReadWriter

Bases: MsgReadWriteCloser, Encrypter

Read/write message with encryption/decryption.

class libp2p.io.abc.Encrypter

Bases: ABC

abstract decrypt(data: bytes) bytes
abstract encrypt(data: bytes) bytes
class libp2p.io.abc.MsgReadWriteCloser

Bases: MsgReader, MsgWriter, Closer

class libp2p.io.abc.MsgReader

Bases: ABC

abstract async read_msg() bytes
class libp2p.io.abc.MsgWriter

Bases: ABC

abstract async write_msg(msg: bytes) None
class libp2p.io.abc.ReadCloser

Bases: Reader, Closer

class libp2p.io.abc.ReadWriteCloser

Bases: Reader, Writer, Closer

class libp2p.io.abc.ReadWriter

Bases: Reader, Writer

class libp2p.io.abc.Reader

Bases: ABC

abstract async read(n: int | None = None) bytes
class libp2p.io.abc.WriteCloser

Bases: Writer, Closer

class libp2p.io.abc.Writer

Bases: ABC

abstract async write(data: bytes) None

libp2p.io.exceptions module

exception libp2p.io.exceptions.DecryptionFailedException

Bases: MsgioException

exception libp2p.io.exceptions.IOException

Bases: BaseLibp2pError

exception libp2p.io.exceptions.IncompleteReadError

Bases: IOException

Fewer bytes were read than requested.

exception libp2p.io.exceptions.MessageTooLarge

Bases: MsgioException

exception libp2p.io.exceptions.MissingLengthException

Bases: MsgioException

exception libp2p.io.exceptions.MissingMessageException

Bases: MsgioException

exception libp2p.io.exceptions.MsgioException

Bases: IOException

libp2p.io.msgio module

msgio is an implementation of https://github.com/libp2p/go-msgio.

from that repo: “a simple package to r/w length-delimited slices.”

NOTE: currently missing the capability to indicate lengths by “varint” method.

class libp2p.io.msgio.BaseMsgReadWriter(read_write_closer: ReadWriteCloser)

Bases: MsgReadWriteCloser

async close() None
abstract encode_msg(msg: bytes) bytes
abstract async next_msg_len() int
async read_msg() bytes
read_write_closer: ReadWriteCloser
size_len_bytes: int
async write_msg(msg: bytes) None
class libp2p.io.msgio.FixedSizeLenMsgReadWriter(read_write_closer: ReadWriteCloser)

Bases: BaseMsgReadWriter

encode_msg(msg: bytes) bytes
async next_msg_len() int
size_len_bytes: int
class libp2p.io.msgio.VarIntLengthMsgReadWriter(read_write_closer: ReadWriteCloser)

Bases: BaseMsgReadWriter

encode_msg(msg: bytes) bytes
max_msg_size: int
async next_msg_len() int
libp2p.io.msgio.encode_msg_with_length(msg_bytes: bytes, size_len_bytes: int) bytes
async libp2p.io.msgio.read_length(reader: Reader, size_len_bytes: int) int

libp2p.io.trio module

class libp2p.io.trio.TrioTCPStream(stream: SocketStream)

Bases: ReadWriteCloser

async close() None
async read(n: int | None = None) bytes
read_lock: Lock
stream: SocketStream
async write(data: bytes) None

Raise RawConnError if the underlying connection breaks.

write_lock: Lock

libp2p.io.utils module

async libp2p.io.utils.read_exactly(reader: Reader, n: int, retry_count: int = 100) bytes

NOTE: relying on exceptions to break out on erroneous conditions, like EOF

Module contents