interface UPnPNATInit {
    autoConfirmAddress?: boolean;
    externalAddress?: string;
    externalAddressCheckInterval?: number;
    externalAddressCheckTimeout?: number;
    gatewaySearchInterval?: number;
    gatewaySearchMessageInterval?: number;
    gatewaySearchTimeout?: number;
    gateways?: string[];
    initialGatewaySearchInterval?: number;
    initialGatewaySearchMessageInterval?: number;
    initialGatewaySearchTimeout?: number;
    portMappingAutoRefresh?: boolean;
    portMappingClient?: UPnPNATClient;
    portMappingDescription?: string;
    portMappingRefreshThreshold?: number;
    portMappingTTL?: number;
}

Properties

autoConfirmAddress?: boolean

Any mapped addresses are added to the observed address list. These addresses require additional verification by the @libp2p/autonat protocol or similar before they are trusted.

To skip this verification and trust them immediately pass true here

Default

false
externalAddress?: string

By default we query discovered/configured gateways for their external address. To specify it manually instead, pass a value here.

Typically this would be an IPv4 address that the router performs NAT with.

externalAddressCheckInterval?: number

Check if the external address has changed this often in ms. Ignored if an external address is specified.

Default

30000
externalAddressCheckTimeout?: number

Do not take longer than this to check if the external address has changed in ms. Ignored if an external address is specified.

Default

10000
gatewaySearchInterval?: number

How often to search for network gateways in ms.

This interval is used after a gateway has been found on the network.

Default

300_000
gatewaySearchMessageInterval?: number

How often to send the M-SEARCH SSDP message during a gateway search in ms.

Some routers are flaky and may not respond to every query so decreasing this will increase the number of search messages sent before the timeout.

This interval is used after a gateway has been found on the network.

Default

10_000
gatewaySearchTimeout?: number

How long to search for gateways for before giving up in ms.

This timeout is used after a gateway has been found on the network.

Default

60_000
gateways?: string[]

By default we search for local gateways using SSDP M-SEARCH messages. To manually specify a gateway instead, pass values here.

A lot of ISP-provided gateway/routers are under powered so may need rebooting before they will respond to M-SEARCH messages.

Each value is an IPv4 or IPv6 URL of the UPnP device descriptor document, e.g. http://192.168.1.1:8080/description.xml. Please see the documentation of your gateway to discover the URL.

Note that some gateways will randomize the port/path the descriptor document is served from and even change it over time so you may be forced to use an SSDP search instead.

initialGatewaySearchInterval?: number

How often to search for network gateways in ms.

This interval is used before a gateway has been found on the network, after that it switches to gatewaySearchInterval which lowers the frequency of the search.

Default

5_000
initialGatewaySearchMessageInterval?: number

How often to send the M-SEARCH SSDP message during a gateway search in ms.

Some routers are flaky and may not respond to every query so decreasing this will increase the number of search messages sent before the timeout.

This interval is used before a gateway has been found on the network, after that it switches to gatewaySearchMessageInterval which lowers the frequency of search messages sent.

Default

1_000
initialGatewaySearchTimeout?: number

How long to search for gateways for before giving up in ms.

This timeout is used before a gateway has been found on the network, after that it switches to gatewaySearchTimeout which increases the timeout to give gateways more time to respond.

Default

5_000
portMappingAutoRefresh?: boolean

Whether to automatically refresh UPnP port mappings when their TTL is reached

Default

true
portMappingClient?: UPnPNATClient

A pre-configured instance of a NatAPI client can be passed as an option, otherwise one will be created

portMappingDescription?: string

A string value to use for the port mapping description on the gateway

portMappingRefreshThreshold?: number

How long before a port mapping expires to refresh it in ms

Default

60_000
portMappingTTL?: number

How long UPnP port mappings should last for in ms

Default

720_000