Class SettingsPack

java.lang.Object
com.frostwire.jlibtorrent.SettingsPack

public final class SettingsPack extends Object
The ``settings_pack`` struct, contains the names of all settings as enum values. These values are passed in to the ``set_str()``, ``set_int()``, ``set_bool()`` functions, to specify the setting to change.
  • Constructor Details

    • SettingsPack

      public SettingsPack(com.frostwire.jlibtorrent.swig.settings_pack sp)
    • SettingsPack

      public SettingsPack()
      Example, how to turn on the DHT using SettingsPack.
      
       SettingsPack pack = new SettingsPack();
       pack.setBoolean(settings_pack.bool_types.enable_dht.swigValue(), on);
       s.applySettings(pack);
       
  • Method Details

    • swig

      public com.frostwire.jlibtorrent.swig.settings_pack swig()
      Returns:
    • getBoolean

      public boolean getBoolean(int name)
      Parameters:
      name -
      Returns:
    • setBoolean

      public SettingsPack setBoolean(int name, boolean value)
      Parameters:
      name -
      value -
    • getInteger

      public int getInteger(int name)
      Parameters:
      name -
      Returns:
    • setInteger

      public SettingsPack setInteger(int name, int value)
      Parameters:
      name -
      value -
    • getString

      public String getString(int name)
      Parameters:
      name -
      Returns:
    • setString

      public SettingsPack setString(int name, String value)
      Parameters:
      name -
      value -
    • getBytes

      public byte[] getBytes(int name)
    • setBytes

      public void setBytes(int name, byte[] value)
    • clear

      public void clear()
    • clear

      public void clear(int name)
    • hasValue

      public boolean hasValue(int name)
      Queries whether the specified configuration option has a value set in this pack. ``name`` can be any enumeration value from string_types, int_types or bool_types.
      Parameters:
      name - name id of the setting
      Returns:
      true if present
    • getPeerFingerprint

      public byte[] getPeerFingerprint()
      The fingerprint for the client. It will be used as the prefix to the peer-id. If this is 20 bytes (or longer) it will be truncated to 20 bytes and used as the entire peer-id.
    • setPeerFingerprint

      public void setPeerFingerprint(byte[] value)
      The fingerprint for the client. It will be used as the prefix to the peer-id. If this is 20 bytes (or longer) it will be truncated to 20 bytes and used as the entire peer-id.
    • downloadRateLimit

      public int downloadRateLimit()
      Returns:
      the session-global download rate limit in bytes per second. (0 for unlimited)
    • downloadRateLimit

      public SettingsPack downloadRateLimit(int value)
      Sets the session-global limits of download rate limit, in bytes per second.

      A value of 0 means unlimited.

      Parameters:
      value -
    • uploadRateLimit

      public int uploadRateLimit()
      Returns:
      the session-global upload rate limit in bytes per second. (0 for unlimited)
    • uploadRateLimit

      public SettingsPack uploadRateLimit(int value)
      Sets the session-global limits of upload rate limit, in bytes per second.

      A value of 0 means unlimited.

      Parameters:
      value -
    • activeDownloads

      public int activeDownloads()
      active_downloads controls how many active downloading torrents the queuing mechanism allows.

      The target number of active torrents is min(active_downloads + active_seeds, active_limit). active_downloads and active_seeds are upper limits on the number of downloading torrents and seeding torrents respectively. Setting the value to -1 means unlimited.

      For auto managed torrents, these are the limits they are subject to. If there are too many torrents some of the auto managed ones will be paused until some slots free up.

      You can have more torrents *active*, even though they are not announced to the DHT, lsd or their tracker. If some peer knows about you for any reason and tries to connect, it will still be accepted, unless the torrent is paused, which means it won't accept any connections.

      For example if there are 10 seeding torrents and 10 downloading torrents, and ``active_downloads`` is 4 and ``active_seeds`` is 4, there will be 4 seeds active and 4 downloading torrents. If the settings are ``active_downloads`` = 2 and ``active_seeds`` = 4, then there will be 2 downloading torrents and 4 seeding torrents active. Torrents that are not auto managed are also counted against these limits. If there are non-auto managed torrents that use up all the slots, no auto managed torrent will be activated.

      Returns:
    • activeDownloads

      public SettingsPack activeDownloads(int value)
      Parameters:
      value -
      See Also:
    • activeSeeds

      public int activeSeeds()
      active_seeds controls how many active seeding torrents the queuing mechanism allows.
      Returns:
      See Also:
    • activeSeeds

      public SettingsPack activeSeeds(int value)
      Parameters:
      value -
      See Also:
    • activeChecking

      public int activeChecking()
      active_checking is the limit of number of simultaneous checking torrents.
      Returns:
      See Also:
    • activeChecking

      public SettingsPack activeChecking(int value)
      Parameters:
      value -
      See Also:
    • activeDhtLimit

      public int activeDhtLimit()
      active_dht_limit is the max number of torrents to announce to the DHT. By default this is set to 88, which is no more than one DHT announce every 10 seconds.
      Returns:
      See Also:
    • activeDhtLimit

      public SettingsPack activeDhtLimit(int value)
      Parameters:
      value -
      See Also:
    • dhtUploadRate

      public int dhtUploadRate()
    • dhtUploadRate

      public SettingsPack dhtUploadRate(int value)
    • activeTrackerLimit

      public int activeTrackerLimit()
      active_tracker_limit is the max number of torrents to announce to their trackers. By default this is 360, which is no more than one announce every 5 seconds.
      Returns:
      See Also:
    • activeTrackerLimit

      public SettingsPack activeTrackerLimit(int value)
      Parameters:
      value -
      See Also:
    • activeLsdLimit

      public int activeLsdLimit()
      active_lsd_limit is the max number of torrents to announce to the local network over the local service discovery protocol. By default this is 80, which is no more than one announce every 5 seconds (assuming the default announce interval of 5 minutes).
      Returns:
      See Also:
    • activeLsdLimit

      public SettingsPack activeLsdLimit(int value)
      Parameters:
      value -
      See Also:
    • activeLimit

      public int activeLimit()
      active_limit is a hard limit on the number of active (auto managed) torrents. This limit also applies to slow torrents.
      Returns:
      the value
      See Also:
    • activeLimit

      public SettingsPack activeLimit(int value)
      active_limit is a hard limit on the number of active (auto managed) torrents. This limit also applies to slow torrents.
      Parameters:
      value - the value
      See Also:
    • connectionsLimit

      public int connectionsLimit()
      Returns:
      global limit on the number of connections opened.
    • connectionsLimit

      public SettingsPack connectionsLimit(int value)
      Sets a global limit on the number of connections opened. The number of connections is set to a hard minimum of at least two per torrent, so if you set a too low connections limit, and open too many torrents, the limit will not be met.
      Parameters:
      value -
    • maxPeerlistSize

      public int maxPeerlistSize()
      Returns:
      the maximum number of peers in the list of known peers. (0 for unlimited)
    • maxPeerlistSize

      public SettingsPack maxPeerlistSize(int value)
      Sets the maximum number of peers in the list of known peers. These peers are not necessarily connected, so this number should be much greater than the maximum number of connected peers. Peers are evicted from the cache when the list grows passed 90% of this limit, and once the size hits the limit, peers are no longer added to the list. If this limit is set to 0, there is no limit on how many peers we'll keep in the peer list.
      Parameters:
      value -
    • maxQueuedDiskBytes

      public int maxQueuedDiskBytes()
      Returns:
      the maximum number of bytes a connection may have pending in the disk write queue before its download rate is being throttled.
    • maxQueuedDiskBytes

      public SettingsPack maxQueuedDiskBytes(int value)
      Sets the maximum number of bytes a connection may have pending in the disk write queue before its download rate is being throttled. This prevents fast downloads to slow medias to allocate more memory indefinitely. This should be set to at least 16 kB to not completely disrupt normal downloads. If it's set to 0, you will be starving the disk thread and nothing will be written to disk. this is a per session setting.

      When this limit is reached, the peer connections will stop reading data from their sockets, until the disk thread catches up. Setting this too low will severely limit your download rate.

      Parameters:
      value -
    • sendBufferWatermark

      public int sendBufferWatermark()
      Returns:
      the upper limit of the send buffer low-watermark.
    • sendBufferWatermark

      public SettingsPack sendBufferWatermark(int value)
      Sets the upper limit of the send buffer low-watermark.

      if the send buffer has fewer bytes than this, we'll read another 16kB block onto it. If set too small, upload rate capacity will suffer. If set too high, memory will be wasted. The actual watermark may be lower than this in case the upload rate is low, this is the upper limit.

      Parameters:
      value -
    • tickInterval

      public int tickInterval()
      Returns:
    • tickInterval

      public SettingsPack tickInterval(int value)
      Specifies the number of milliseconds between internal ticks. This is the frequency with which bandwidth quota is distributed to peers. It should not be more than one second (i.e. 1000 ms). Setting this to a low value (around 100) means higher resolution bandwidth quota distribution, setting it to a higher value saves CPU cycles.
      Parameters:
      value -
    • inactivityTimeout

      public int inactivityTimeout()
      Returns:
    • inactivityTimeout

      public SettingsPack inactivityTimeout(int value)
      if a peer is uninteresting and uninterested for longer than this number of seconds, it will be disconnected. default is 10 minutes
      Parameters:
      value -
    • seedingOutgoingConnections

      public boolean seedingOutgoingConnections()
      Returns:
    • seedingOutgoingConnections

      public SettingsPack seedingOutgoingConnections(boolean value)
      Determines if seeding (and finished) torrents should attempt to make outgoing connections or not. By default this is true. It may be set to false in very specific applications where the cost of making outgoing connections is high, and there are no or small benefits of doing so. For instance, if no nodes are behind a firewall or a NAT, seeds don't need to make outgoing connections.
      Parameters:
      value -
    • anonymousMode

      public boolean anonymousMode()
      Returns:
    • anonymousMode

      public SettingsPack anonymousMode(boolean value)
      defaults to false. When set to true, the client tries to hide its identity to a certain degree. The peer-ID will no longer include the client's fingerprint. The user-agent will be reset to an empty string. It will also try to not leak other identifying information, such as your local listen port, your IP etc.

      If you're using I2P, a VPN or a proxy, it might make sense to enable anonymous mode.

      Parameters:
      value -
    • isEnableDht

      public boolean isEnableDht()
      Starts the dht node and makes the trackerless service available to torrents.
      Returns:
      true if enable
    • setEnableDht

      public void setEnableDht(boolean value)
      Starts the dht node and makes the trackerless service available to torrents.
      Parameters:
      value - true if enable
    • isEnableLsd

      public boolean isEnableLsd()
      Starts and stops Local Service Discovery. This service will broadcast the info-hashes of all the non-private torrents on the local network to look for peers on the same swarm within multicast reach.
      Returns:
      true if enable
    • setEnableLsd

      public void setEnableLsd(boolean value)
      Starts and stops Local Service Discovery. This service will broadcast the info-hashes of all the non-private torrents on the local network to look for peers on the same swarm within multicast reach.
      Parameters:
      value - true if enable
    • getMaxMetadataSize

      public int getMaxMetadataSize()
      The maximum allowed size (in bytes) to be received by the metadata extension, i.e. magnet links.
    • setMaxMetadataSize

      public void setMaxMetadataSize(int value)
      The maximum allowed size (in bytes) to be received by the metadata extension, i.e. magnet links.
      Parameters:
      value - true if enable
    • getDhtBootstrapNodes

      public String getDhtBootstrapNodes()
      This is a comma-separated list of IP port-pairs. They will be added to the DHT node (if it's enabled) as back-up nodes in case we don't know of any.

      Changing these after the DHT has been started may not have any effect until the DHT is restarted.

    • setDhtBootstrapNodes

      public void setDhtBootstrapNodes(String value)
      This is a comma-separated list of IP port-pairs. They will be added to the DHT node (if it's enabled) as back-up nodes in case we don't know of any.

      Changing these after the DHT has been started may not have any effect until the DHT is restarted.

      Parameters:
      value - the IP port-pairs list
    • getWebtorrentStunServer

      public String getWebtorrentStunServer()
      This is the STUN server used by WebTorrent to enable ICE NAT traversal for WebRTC. It must have the format ``hostname:port``. TODO: Uncomment code below when settings_pack.hpp from libtorrent master is merged to RC_2_0 See https://github.com/arvidn/libtorrent/blob/master/include/libtorrent/settings_pack.hpp#L370
    • setWebtorrentStunServer

      public void setWebtorrentStunServer(String value)
      This is the STUN server used by WebTorrent to enable ICE NAT traversal for WebRTC. It must have the format ``hostname:port``. TODO: Uncomment code below when settings_pack.hpp from libtorrent master is merged to RC_2_0 See https://github.com/arvidn/libtorrent/blob/master/include/libtorrent/settings_pack.hpp#L370
      Parameters:
      value - the STUN server endpoint
    • listenInterfaces

      public String listenInterfaces()
      Returns:
    • listenInterfaces

      public SettingsPack listenInterfaces(String value)
      Parameters:
      value -
      Returns:
      this
    • stopTrackerTimeout

      public int stopTrackerTimeout()
      Returns:
      the current value
      See Also:
    • stopTrackerTimeout

      public SettingsPack stopTrackerTimeout(int value)
      stop_tracker_timeout is the number of seconds to wait when sending a stopped message before considering a tracker to have timed out. This is usually shorter, to make the client quit faster. If the value is set to 0, the connections to trackers with the stopped event are suppressed.
      Parameters:
      value - the new value
      Returns:
      this
    • alertQueueSize

      public int alertQueueSize()
      Returns:
      the current value
      See Also:
    • alertQueueSize

      public SettingsPack alertQueueSize(int value)
      alert_queue_size is the maximum number of alerts queued up internally. If alerts are not popped, the queue will eventually fill up to this level.
      Parameters:
      value - the new value
      Returns:
      this
    • validateHttpsTrackers

      public SettingsPack validateHttpsTrackers(boolean value)
      validate_https_trackers when set to true, the certificate of HTTPS trackers and HTTPS web seeds will be validated against the system's certificate store (as defined by OpenSSL). If the system does not have a certificate store, this option may have to be disabled in order to get trackers and web seeds to work).
    • validateHttpsTrackers

      public boolean validateHttpsTrackers()
    • diskDisableCopyOnWrite

      public boolean diskDisableCopyOnWrite()
      Returns whether the disk copy-on-write optimization is disabled.

      When disabled, libtorrent will not use the operating system's copy-on-write mechanism for memory-mapped files. Disabling copy-on-write can improve disk I/O performance on certain filesystems (e.g., Btrfs, APFS, ZFS) where copy-on-write introduces additional overhead for torrent workloads.

      By default this is true (copy-on-write is disabled) in current libtorrent builds, as CoW tends to hurt torrent workload performance.

      Example:

      
       SettingsPack pack = new SettingsPack();
      
       // Check current setting
       boolean cowDisabled = pack.diskDisableCopyOnWrite();
      
       // Disable copy-on-write for better performance on CoW filesystems
       pack.diskDisableCopyOnWrite(true);
      
       // Apply settings to session
       sessionManager.applySettings(pack);
      
       // Or use fluent API during session setup
       SettingsPack settings = new SettingsPack()
           .diskDisableCopyOnWrite(true)
           .downloadRateLimit(0)
           .uploadRateLimit(0);
       
      Returns:
      true if copy-on-write is disabled, false otherwise
      See Also:
    • diskDisableCopyOnWrite

      public SettingsPack diskDisableCopyOnWrite(boolean value)
      Sets whether to disable the disk copy-on-write optimization.

      When set to true, libtorrent will not use the operating system's copy-on-write mechanism for memory-mapped files. This can improve disk I/O performance on filesystems that use copy-on-write by default (e.g., Btrfs, APFS, ZFS), where the CoW behavior introduces extra overhead for random-write workloads typical of BitTorrent downloads.

      When to use:

      • On Btrfs/ZFS/APFS filesystems where CoW causes fragmentation
      • When downloading to SSDs where CoW write amplification is a concern
      • When experiencing slower-than-expected disk I/O throughput

      Example:

      
       SettingsPack pack = new SettingsPack()
           .diskDisableCopyOnWrite(true)
           .downloadRateLimit(0);
      
       sessionManager.applySettings(pack);
       
      Parameters:
      value - true to disable copy-on-write, false to leave it enabled
      Returns:
      this SettingsPack for fluent chaining
      See Also:
    • natpmpGateway

      public String natpmpGateway()
      Returns the override address for NAT-PMP (NAT Port Mapping Protocol) gateway requests.

      By default libtorrent auto-detects the local gateway by inspecting the routing table. In certain topologies — VPN tunnels, multi-homed hosts, containers, or networks where the default route does not own the public IP — this auto-detection picks the wrong interface and port mappings fail silently. This getter returns the currently configured gateway override; an empty string means "let libtorrent auto-detect".

      When to use:

      • VPN client networks where the tun/tap interface is the default route but the VPN provider does not support NAT-PMP
      • Multi-WAN or policy-routing setups where the gateway owning the public IP is not the default route
      • Docker / LXC containers where the container gateway differs from the host gateway

      Default: "" (empty string — auto-detect)

      Example:

      
       SettingsPack pack = new SettingsPack();
      
       // Check current override (will be empty on fresh pack)
       String current = pack.natpmpGateway();
       if (current.isEmpty()) {
           System.out.println("Auto-detect enabled");
       }
      
       // Force NAT-PMP through a known gateway on a VPN subnet
       pack.natpmpGateway("10.8.0.1");
      
       // Apply and start session
       SessionManager session = new SessionManager();
       session.start();
       session.applySettings(pack);
       
      Returns:
      the configured NAT-PMP gateway address, or empty string when auto-detect is in effect
      Since:
      2.0.12.9
      See Also:
    • natpmpGateway

      public SettingsPack natpmpGateway(String value)
      Overrides the gateway address used for NAT-PMP (NAT Port Mapping Protocol) requests.

      Setting a non-empty value forces libtorrent to send NAT-PMP map-request packets to the supplied IPv4 address instead of querying the operating-system routing table. This is the only reliable way to make port-mapping work when the default route does not own the public IP (e.g., VPN split-tunnel, multi-homed server, container bridge). If the string is empty (the default) libtorrent falls back to automatic gateway discovery.

      When to use:

      • When portmap_log alerts show "no router" but you know a NAT-PMP-enabled gateway exists on a secondary interface
      • After switching from Wi-Fi to wired Ethernet and the gateway changes subnet (e.g. 192.168.1.1 → 192.168.50.1)
      • On seed-boxes with multiple upstream ISPs where only one router supports NAT-PMP / UPnP

      Constraints & edge cases:

      • The value must be a valid dotted IPv4 address. Hostnames are not resolved by libtorrent.
      • Changing this setting at runtime invalidates existing port maps; libtorrent will re-map through the new gateway on the next refresh cycle.
      • Has no effect when UPnP is used instead of NAT-PMP.

      Default: "" (empty string — auto-detect)

      Example:

      
       // Detect auto-detect failure from portmap alerts, then override
       SessionManager session = new SessionManager();
       session.start();
      
       SettingsPack pack = new SettingsPack();
       pack.setEnableDht(true)
           .portRangeStart(6881)
           .portRangeEnd(6889);
      
       // After observing "no router" portmap_log alerts, pin the gateway
       pack.natpmpGateway("192.168.50.1");
      
       session.applySettings(pack);
       
      Parameters:
      value - the NAT-PMP gateway IPv4 address, or empty string to restore auto-detect
      Returns:
      this SettingsPack for fluent chaining
      Since:
      2.0.12.9
      See Also:
    • allowMultipleConnectionsPerPid

      public boolean allowMultipleConnectionsPerPid()
      Returns whether libtorrent allows more than one simultaneous connection from peers that share the same peer ID (PID).

      The BitTorrent protocol nominally assigns a unique peer ID to every client instance, but in practice multiple peers behind the same NAT may expose the same PID because they run the same client version and port, or because a buggy tracker hands out identical IDs. By default (value false) libtorrent keeps only the first connection and drops duplicates as a anti-DDoS / anti-loop measure.

      When to use:

      • Swarms with many peers behind carrier-grade NAT (CGNAT) where distinct users legitimately share the same public IP and PID
      • Private trackers that intentionally assign identical peer IDs to sibling instances for accounting
      • Testing / debugging scenarios where you run multiple local clients with the same peer_id prefix

      Default: false (duplicate peer IDs are rejected)

      Example:

      
       SettingsPack pack = new SettingsPack();
      
       // Check whether duplicates are currently allowed
       boolean allowed = pack.allowMultipleConnectionsPerPid();
       System.out.println("Duplicates allowed: " + allowed); // false
      
       // Only enable for a specific private swarm known to use CGNAT
       if (swarmIsBehindCGNAT()) {
           pack.allowMultipleConnectionsPerPid(true);
       }
      
       session.applySettings(pack);
       
      Returns:
      true if multiple connections per peer ID are allowed, false if duplicates are dropped
      Since:
      2.0.12.9
      See Also:
    • allowMultipleConnectionsPerPid

      public SettingsPack allowMultipleConnectionsPerPid(boolean value)
      Controls whether libtorrent accepts multiple simultaneous connections from peers that present the same peer ID.

      Disabling the duplicate-PID guard (false, the default) is the safest choice for public swarms because it prevents:

      • Connection loops created by mis-configured port-forwarding
      • Accidental (or intentional) connection-flooding from a single hostile client re-using one peer ID
      • Wasted upload bandwidth to the same remote client instance

      Enabling it (true) relaxes that safety check and is appropriate only when you know the swarm contains multiple legitimate peers sharing a PID — typically because of NAT or tracker behaviour, not malice.

      When to use:

      • Enterprise or campus networks with symmetric NAT where many identical client versions appear behind one public IP
      • Swarms served by a tracker that assigns peer IDs based on ASN rather than per-user nonce
      • Integration tests that spawn many local libtorrent instances with the same fingerprint

      Constraints & security warning:

      • Do not enable on public, untrusted swarms — a single attacker can exhaust your connection limit by reconnecting under the same peer ID.
      • This setting interacts with connectionsLimit(); if the limit is low, duplicate-PID connections may crowd out unique peers.
      • Changes take effect immediately for new incoming connections; existing duplicates are not retroactively killed.

      Default: false

      Example:

      
       SettingsPack pack = new SettingsPack();
      
       // Default: safe mode — reject duplicate peer IDs
       pack.allowMultipleConnectionsPerPid(false);
      
       // For a controlled, private swarm behind the same corporate NAT:
       if (torrent.isPrivate() && network.isCorporateNAT()) {
           pack.allowMultipleConnectionsPerPid(true)
               .connectionsLimit(500);  // raise limit to absorb extra peers
       }
      
       session.applySettings(pack);
       
      Parameters:
      value - true to allow multiple connections per peer ID, false to reject duplicates
      Returns:
      this SettingsPack for fluent chaining
      Since:
      2.0.12.9
      See Also:
    • natpmpLeaseDuration

      public int natpmpLeaseDuration()
      Returns the lease duration, in seconds, requested for NAT-PMP port mappings.

      When libtorrent asks a NAT-PMP-enabled router to open a port, it proposes a lifetime for that mapping. The router may honour the request or substitute its own maximum. A longer lease means fewer renewal packets and lower background traffic; a shorter lease means the mapping vanishes quickly if the client crashes, keeping the router's NAT table small and friendly to other devices.

      When to use shorter leases:

      • Short interactive sessions (e.g., a mobile app that seeds only while the user is watching)
      • Routers with tiny NAT tables that evict long-lived mappings
      • Development / CI environments where the session is torn down within minutes
      When to use longer leases:
      • 24/7 seed-boxes or dedicated home servers
      • Connections over satellite or high-latency links where every extra packet is expensive
      • Routers known to rate-limit NAT-PMP renewals

      Default: 3600 seconds (1 hour)

      Example:

      
       SettingsPack pack = new SettingsPack();
      
       // Default is 3600s — fine for a typical desktop session
       int current = pack.natpmpLeaseDuration();
       System.out.println("Current lease: " + current + "s");
      
       // For a short-lived mobile session, reduce to 5 minutes
       pack.natpmpLeaseDuration(300);
      
       // For a long-running seeder on a stable home network, extend to 2h
       if (sessionType == SEED_BOX) {
           pack.natpmpLeaseDuration(7200);
       }
      
       session.applySettings(pack);
       
      Returns:
      the NAT-PMP lease duration in seconds
      Since:
      2.0.12.9
      See Also:
    • natpmpLeaseDuration

      public SettingsPack natpmpLeaseDuration(int value)
      Sets the requested lease duration for NAT-PMP port mappings in seconds.

      Every mapping created via NAT-PMP (and by extension PCP) carries a lifetime. libtorrent renews the mapping automatically at roughly 50 % of the lease elapsed time, so the chosen value directly controls background chatter: a 3600-second lease generates a renewal every ~30 minutes, while a 300-second lease renews every ~2.5 minutes.

      Choose the value based on your session's expected lifetime and the router's behaviour. Many consumer routers silently cap leases at 7200 s (2 h) regardless of what the client asks, so values above that may not produce any benefit. Conversely, values below 60 s can trigger aggressive renewal loops or be rejected outright by picky firmware.

      Constraints & edge cases:

      • Values < 60 are allowed but may be rounded up by the router or cause excessive renewal traffic.
      • Zero is technically valid in the NAT-PMP spec but is interpreted by many routers as "delete this mapping immediately"; avoid it unless you explicitly want to un-map.
      • Changing this setting does not alter the lifetime of already active mappings — only new requests use the updated value.
      • Has no effect on UPnP-IGD mappings, which usually follow the router's own lease policy.

      Default: 3600 seconds (1 hour)

      Example:

      
       // Dynamic adjustment based on session type
       SettingsPack pack = new SettingsPack()
           .setEnableDht(true)
           .portRangeStart(50000)
           .portRangeEnd(50050);
      
       switch (sessionProfile) {
           case MOBILE_TEMPORARY:
               // 5 min — router table stays small, user won't notice renewals
               pack.natpmpLeaseDuration(300);
               break;
           case DESKTOP_STANDARD:
               // 1 hour — default, balanced
               pack.natpmpLeaseDuration(3600);
               break;
           case SEED_BOX:
               // 2 hours — minimise packet count on a stable server
               pack.natpmpLeaseDuration(7200);
               break;
       }
      
       session.applySettings(pack);
       
      Parameters:
      value - the NAT-PMP lease duration in seconds
      Returns:
      this SettingsPack for fluent chaining
      Since:
      2.0.12.9
      See Also: