libp2p package

Subpackages

Submodules

libp2p.exceptions module

exception libp2p.exceptions.BaseLibp2pError

Bases: Exception

exception libp2p.exceptions.MultiError

Bases: libp2p.exceptions.BaseLibp2pError

Raised with multiple exceptions.

exception libp2p.exceptions.ParseError

Bases: libp2p.exceptions.BaseLibp2pError

exception libp2p.exceptions.ValidationError

Bases: libp2p.exceptions.BaseLibp2pError

Raised when something does not pass a validation check.

libp2p.typing module

libp2p.utils module

async libp2p.utils.decode_uvarint_from_stream(reader: libp2p.io.abc.Reader) → int

https://en.wikipedia.org/wiki/LEB128.

libp2p.utils.encode_delim(msg: bytes) → bytes
libp2p.utils.encode_uvarint(number: int) → bytes

Pack number into varint bytes.

libp2p.utils.encode_varint_prefixed(msg_bytes: bytes) → bytes
async libp2p.utils.read_delim(reader: libp2p.io.abc.Reader) → bytes
async libp2p.utils.read_varint_prefixed_bytes(reader: libp2p.io.abc.Reader) → bytes

Module contents

libp2p.generate_new_rsa_identity() → libp2p.crypto.keys.KeyPair
libp2p.generate_peer_id_from(key_pair: libp2p.crypto.keys.KeyPair) → libp2p.peer.id.ID
libp2p.new_host(key_pair: libp2p.crypto.keys.KeyPair = None, muxer_opt: Mapping[NewType.<locals>.new_type, Type[libp2p.stream_muxer.abc.IMuxedConn]] = None, sec_opt: Mapping[NewType.<locals>.new_type, libp2p.security.secure_transport_interface.ISecureTransport] = None, peerstore_opt: libp2p.peer.peerstore_interface.IPeerStore = None, disc_opt: libp2p.routing.interfaces.IPeerRouting = None) → libp2p.host.host_interface.IHost

Create a new libp2p host based on the given parameters.

Parameters
  • key_pair – optional choice of the KeyPair

  • muxer_opt – optional choice of stream muxer

  • sec_opt – optional choice of security upgrade

  • peerstore_opt – optional peerstore

  • disc_opt – optional discovery

Returns

return a host instance

libp2p.new_swarm(key_pair: libp2p.crypto.keys.KeyPair = None, muxer_opt: Mapping[NewType.<locals>.new_type, Type[libp2p.stream_muxer.abc.IMuxedConn]] = None, sec_opt: Mapping[NewType.<locals>.new_type, libp2p.security.secure_transport_interface.ISecureTransport] = None, peerstore_opt: libp2p.peer.peerstore_interface.IPeerStore = None) → libp2p.network.network_interface.INetworkService

Create a swarm instance based on the parameters.

Parameters
  • key_pair – optional choice of the KeyPair

  • muxer_opt – optional choice of stream muxer

  • sec_opt – optional choice of security upgrade

  • peerstore_opt – optional peerstore

Returns

return a default swarm instance