libp2p.host.autonat package

Subpackages

Submodules

libp2p.host.autonat.autonat module

class libp2p.host.autonat.autonat.AutoNATService(host: BasicHost)

Bases: object

AutoNAT Service Implementation.

A service that helps libp2p nodes determine their NAT status by attempting to establish connections with other peers. The service maintains a record of dial attempts and their results to classify the node as either public or private.

get_status() int

Retrieve the current AutoNAT status.

Returns

int

The current NAT status: - AutoNATStatus.UNKNOWN (0): Status not yet determined - AutoNATStatus.PUBLIC (1): Node is publicly reachable - AutoNATStatus.PRIVATE (2): Node is behind NAT

async handle_stream(stream: NetStream) None

Process an incoming AutoNAT stream.

Parameters

streamNetStream

The network stream to handle for AutoNAT protocol communication.

update_status() None

Update the AutoNAT status based on dial results.

Analyzes the accumulated dial attempt results to determine if the node is publicly reachable. The node is considered public if at least two successful dial attempts have been recorded.

class libp2p.host.autonat.autonat.AutoNATStatus

Bases: object

AutoNAT Status Enumeration.

Defines the possible states of NAT traversal for a libp2p node: - UNKNOWN (0): Initial state, NAT status not yet determined - PUBLIC (1): Node is publicly reachable from the internet - PRIVATE (2): Node is behind NAT, not directly reachable

PRIVATE = 2
PUBLIC = 1
UNKNOWN = 0

Module contents

AutoNAT module for libp2p.

class libp2p.host.autonat.AutoNATService(host: BasicHost)

Bases: object

AutoNAT Service Implementation.

A service that helps libp2p nodes determine their NAT status by attempting to establish connections with other peers. The service maintains a record of dial attempts and their results to classify the node as either public or private.

get_status() int

Retrieve the current AutoNAT status.

Returns

int

The current NAT status: - AutoNATStatus.UNKNOWN (0): Status not yet determined - AutoNATStatus.PUBLIC (1): Node is publicly reachable - AutoNATStatus.PRIVATE (2): Node is behind NAT

async handle_stream(stream: NetStream) None

Process an incoming AutoNAT stream.

Parameters

streamNetStream

The network stream to handle for AutoNAT protocol communication.

update_status() None

Update the AutoNAT status based on dial results.

Analyzes the accumulated dial attempt results to determine if the node is publicly reachable. The node is considered public if at least two successful dial attempts have been recorded.

class libp2p.host.autonat.AutoNATStatus

Bases: object

AutoNAT Status Enumeration.

Defines the possible states of NAT traversal for a libp2p node: - UNKNOWN (0): Initial state, NAT status not yet determined - PUBLIC (1): Node is publicly reachable from the internet - PRIVATE (2): Node is behind NAT, not directly reachable

PRIVATE = 2
PUBLIC = 1
UNKNOWN = 0