libp2p.discovery.upnp package

Submodules

libp2p.discovery.upnp.upnp module

class libp2p.discovery.upnp.upnp.UpnpManager

Bases: object

A simple, self-contained manager for UPnP port mapping that can be used alongside a libp2p Host.

async add_port_mapping(port: int, protocol: str = 'TCP') bool

Request a new port mapping from the gateway.

Parameters:
  • port – the internal port to map

  • protocol – the protocol to map (TCP or UDP)

Returns:

True on success, False otherwise

async discover() bool

Discover the UPnP IGD on the network.

Returns:

True if a gateway is found, False otherwise.

get_external_ip() str | None
async remove_port_mapping(port: int, protocol: str = 'TCP') bool

Remove an existing port mapping.

Parameters:
  • port – the external port to unmap

  • protocol – the protocol (TCP or UDP)

Returns:

True on success, False otherwise

Module contents