java.lang.Object
net.i2p.router.TunnelPoolSettings

public class TunnelPoolSettingsextends Object
Wrap up the settings for a pool of tunnels.
  • Field Details

    • _destination

      private final Hash _destination
      The tunnel's destination hash.
    • _destinationNickname

      private String _destinationNickname
      Nickname for the destination, may be null.
    • _quantity

      private int _quantity
      Active tunnels wanted.
    • _backupQuantity

      private int _backupQuantity
      Backup tunnels wanted.
    • _length

      private int _length
      Hop count of the tunnels.
    • _lengthVariance

      private int _lengthVariance
      Allowed random variation of the hop count.
    • _lengthOverride

      private int _lengthOverride
      Hop count override for the next tunnels, -1 if none.
    • _isInbound

      private final boolean _isInbound
      True for an inbound tunnel pool.
    • _isExploratory

      private final boolean _isExploratory
      True for the exploratory pools.
    • _allowZeroHop

      private boolean _allowZeroHop
      True to allow zero-hop tunnels.
    • _shouldTest

      private boolean _shouldTest
      True to test the tunnels.
    • _IPRestriction

      private int _IPRestriction
      IP restriction level of the pool.
    • _unknownOptions

      private final Properties _unknownOptions
      Session options this version does not know.
    • _randomKey

      private SessionKey _randomKey
      Random key used for strict peer ordering.
    • _priority

      private int _priority
      Priority of the pool for bandwidth and builds.
    • _aliases

      private final Set<Hash> _aliases
      Destination hashes aliasing this pool.
    • _aliasOf

      private Hash _aliasOf
      Destination this pool is an alias of, null if none.
    • _firstPeerExclusions

      private Set<Hash> _firstPeerExclusions
      Peers excluded as the first hop of a new tunnel, for diversity. Null if none are configured.
    • _lastPeerExclusions

      private Set<Hash> _lastPeerExclusions
      Peers excluded as the last hop of a new tunnel, for diversity. Null if none are configured.
    • PREFIX_INBOUND_EXPLORATORY

      public static final String PREFIX_INBOUND_EXPLORATORY
      Prefix used to configure the inbound exploratory pool.
      See Also:
    • PREFIX_OUTBOUND_EXPLORATORY

      public static final String PREFIX_OUTBOUND_EXPLORATORY
      Prefix used to configure the outbound exploratory pool.
      See Also:
    • PROP_NICKNAME

      public static final String PROP_NICKNAME
      Pool property naming the client a client pool serves.
      See Also:
    • PROP_QUANTITY

      public static final String PROP_QUANTITY
      Pool property for how many tunnels to keep available.
      See Also:
    • PROP_BACKUP_QUANTITY

      public static final String PROP_BACKUP_QUANTITY
      Pool property for how many spare tunnels to keep on hand.
      See Also:
    • PROP_DURATION

      public static final String PROP_DURATION
      Pool property for how long a tunnel is kept before being expired, in minutes.
      See Also:
    • PROP_LENGTH

      public static final String PROP_LENGTH
      Pool property for the number of hops in each tunnel.
      See Also:
    • PROP_LENGTH_VARIANCE

      public static final String PROP_LENGTH_VARIANCE
      Pool property for how much the hop count may vary around PROP_LENGTH.
      See Also:
    • PROP_ALLOW_ZERO_HOP

      public static final String PROP_ALLOW_ZERO_HOP
      Config property allowing zero-hop tunnels; unreliable, zero hops are always possible.
      See Also:
    • PROP_SHOULD_TEST

      public static final String PROP_SHOULD_TEST
      Pool property for whether the pool's tunnels are tested.
      See Also:
    • PROP_IP_RESTRICTION

      public static final String PROP_IP_RESTRICTION
      Pool property for the IP address class the peers are drawn from, 0 to 4.
      See Also:
    • PROP_PRIORITY

      public static final String PROP_PRIORITY
      Pool property for the outbound selection priority, -25 to 25.
      See Also:
    • PROP_RANDOM_KEY

      public static final String PROP_RANDOM_KEY
      Pool property holding the base64 random key used to order peer selection.
      See Also:
    • DEFAULT_QUANTITY

      public static final int DEFAULT_QUANTITY
      Default tunnels to keep available in a pool.
      See Also:
    • DEFAULT_BACKUP_QUANTITY

      public static final int DEFAULT_BACKUP_QUANTITY
      Default spare tunnels to keep on hand in a pool.
      See Also:
    • DEFAULT_DURATION

      public static final int DEFAULT_DURATION
      Default tunnel lifetime in milliseconds.
      See Also:
    • IS_SLOW

      private static final boolean IS_SLOW
      True on devices where defaults are reduced.
    • DEFAULT_IB_LENGTH

      private static final int DEFAULT_IB_LENGTH
      Default inbound tunnel length for client pools.
      See Also:
    • DEFAULT_OB_LENGTH

      private static final int DEFAULT_OB_LENGTH
      Default hop count of outbound tunnels.
      See Also:
    • DEFAULT_LENGTH_VARIANCE

      private static final int DEFAULT_LENGTH_VARIANCE
      Default hop count variance.
      See Also:
    • DEFAULT_IB_EXPL_LENGTH

      private static final int DEFAULT_IB_EXPL_LENGTH
      Default inbound tunnel length for exploratory pools.
    • DEFAULT_OB_EXPL_LENGTH

      private static final int DEFAULT_OB_EXPL_LENGTH
      Default outbound exploratory hop count.
    • DEFAULT_IB_EXPL_LENGTH_VARIANCE

      private static final int DEFAULT_IB_EXPL_LENGTH_VARIANCE
      Default inbound exploratory hop variance.
    • DEFAULT_OB_EXPL_LENGTH_VARIANCE

      private static final int DEFAULT_OB_EXPL_LENGTH_VARIANCE
      Default outbound exploratory hop variance.
    • DEFAULT_ALLOW_ZERO_HOP

      public static final boolean DEFAULT_ALLOW_ZERO_HOP
      Default for PROP_ALLOW_ZERO_HOP: zero-hop tunnels are off.
      See Also:
    • DEFAULT_IP_RESTRICTION

      public static final int DEFAULT_IP_RESTRICTION
      Default for PROP_IP_RESTRICTION, restricting peers to a class B (/16) address range.
      See Also:
    • MIN_PRIORITY

      private static final int MIN_PRIORITY
      Lowest tunnel priority allowed.
      See Also:
    • MAX_PRIORITY

      private static final int MAX_PRIORITY
      Highest tunnel priority allowed.
      See Also:
    • EXPLORATORY_PRIORITY

      private static final int EXPLORATORY_PRIORITY
      Priority of the exploratory pools.
      See Also:
    • _msgIDBloomXor

      private final long _msgIDBloomXor
      XOR value randomizing the message id bloom filter.
  • Constructor Details

    • TunnelPoolSettings

      public TunnelPoolSettings(boolean isInbound)
      An exploratory pool, with no destination and every default.
      Parameters:
      isInbound - true for the inbound pool, false for the outbound one
    • TunnelPoolSettings

      public TunnelPoolSettings(Hash dest, boolean isInbound)
      A pool with the defaults, exploratory if dest is null and a client pool otherwise.
      Parameters:
      dest - the client destination, or null for an exploratory pool
      isInbound - true for the inbound pool, false for the outbound one
  • Method Details

    • getQuantity

      public int getQuantity()
      How many tunnels should be available at all times.
      Returns:
      the desired quantity
    • setQuantity

      public void setQuantity(int quantity)
      How many tunnels should be available at all times.
      Parameters:
      quantity - the desired quantity
    • getBackupQuantity

      public int getBackupQuantity()
      How many backup tunnels should be kept waiting in the wings.
      Returns:
      the desired backup quantity
    • setBackupQuantity

      public void setBackupQuantity(int quantity)
      How many backup tunnels should be kept waiting in the wings.
      Parameters:
      quantity - the desired backup quantity
    • getTotalQuantity

      public int getTotalQuantity()
      Adds the primary and backup quantities into one target total.
      Returns:
      getQuantity() + getBackupQuantity()
    • getLength

      public int getLength()
      How many remote hops should be in the tunnel NOT including us.
      Returns:
      0 to 7
    • setLength

      public void setLength(int length)
      How many remote hops should be in the tunnel NOT including us.
      Parameters:
      length - 0 to 7 (not enforced here)
    • getAllowZeroHop

      public boolean getAllowZeroHop()
      If there are no tunnels to build with, will this pool allow 0 hop tunnels?

      As of 0.9.44, same goes for exploratory: Prior to 0.9.35, generally true for client. As of 0.9.35, generally false for client, but true if getLength() + min(getLengthVariance(), 0) <= 0, OR if getLengthOverride() == 0.

      Returns:
      the allow zero hop
    • isZeroHop

      public boolean isZeroHop()
      Whether the pool is expressly configured for zero-hop tunnels, by length 0 or lengthOverride 0. Excludes the allowZeroHop fallback flag, which permits zero hops only as a last resort.
      Returns:
      true if zero hops are the configured tunnel length
    • shouldTest

      public boolean shouldTest()
      Should tunnels in this pool be tested?
      Returns:
      true for normal pools, false for hostchecker/ping tunnels
    • getLengthVariance

      public int getLengthVariance()
      How the length should be varied. If negative, this randomly skews from (length - variance) to (length + variance), or if positive, from length to (length + variance), inclusive.
      Returns:
      the length variance
    • setLengthVariance

      public void setLengthVariance(int variance)
      How the length should be varied.
      Parameters:
      variance - the length variance
    • getLengthOverride

      public int getLengthOverride()
      A temporary length to be used due to network conditions. If less than zero, the standard length should be used. Unused until 0.8.11.
      Returns:
      the length override
    • setLengthOverride

      public void setLengthOverride(int length)
      A temporary length to be used due to network conditions. If less than zero, the standard length will be used. Unused until 0.8.11.
      Parameters:
      length - the override in hops, or negative for the standard length
    • isInbound

      public boolean isInbound()
      Is this an inbound tunnel?
      Returns:
      true if the pool builds inbound tunnels
    • isExploratory

      public boolean isExploratory()
      Is this an exploratory tunnel (or a client tunnel)?
      Returns:
      true if the pool has no destination
    • getDestination

      public Hash getDestination()
      What destination is this a client tunnel for (or null if exploratory)?
      Returns:
      the client destination, or null for an exploratory pool
    • getAliases

      public Set<Hash> getAliases()
      Other destinations that use the same tunnel (or null if exploratory). Modifiable, concurrent, not a copy.
      Returns:
      the live alias set, modifiable and concurrent, or null for an exploratory pool
    • getAliasOf

      public Hash getAliasOf()
      Other destination that this is an alias of (or null). If non-null, don't build tunnels.
      Returns:
      the alias of
    • setAliasOf

      public void setAliasOf(Hash h)
      Other destination that this is an alias of (or null). If non-null, don't build tunnels.
      Parameters:
      h - the destination this pool is an alias of, or null
    • getFirstPeerExclusions

      public Set<Hash> getFirstPeerExclusions()
      First peer exclusions for diversity. These are peers that should not be used as the first hop in new tunnels.
      Returns:
      Set of peer hashes to exclude, or null if none set
    • setFirstPeerExclusions

      public void setFirstPeerExclusions(Set<Hash> exclusions)
      First peer exclusions for diversity.
      Parameters:
      exclusions - Set of peer hashes to exclude, or null to clear
    • getLastPeerExclusions

      public Set<Hash> getLastPeerExclusions()
      Last peer exclusions for diversity. These are peers that should not be used as the last hop in new tunnels.
      Returns:
      Set of peer hashes to exclude, or null if none set
    • setLastPeerExclusions

      public void setLastPeerExclusions(Set<Hash> exclusions)
      Last peer exclusions for diversity.
      Parameters:
      exclusions - Set of peer hashes to exclude, or null to clear
    • getRandomKey

      public SessionKey getRandomKey()
      Random key used for peer ordering.
      Returns:
      non-null
    • getDestinationNickname

      public String getDestinationNickname()
      What user supplied name was given to the client connected (can be null).
      Returns:
      the nickname, or null if none was supplied
    • setDestinationNickname

      public void setDestinationNickname(String name)
      User supplied name given to the connected client.
      Parameters:
      name - the nickname, or null
    • getIPRestriction

      public int getIPRestriction()
      How many bytes to match to determine if a router's IP is too close to another's to be in the same tunnel (1-4, 0 to disable)

      Support removed in the ClientPeerSelector in 0.8.6; restored in 0.9.53.

      Returns:
      0-4 Number of bytes to match to determine if peers in the same IP range should not be in the same tunnel. 0 = disable check; 1 = /8; 2 = /16; 3 = /24; 4 = exact IP match
    • getPriority

      public int getPriority()
      Outbound message priority - for outbound tunnels only.
      Returns:
      -25 to +30, default 30 for outbound exploratory and 0 for others
    • getUnknownOptions

      public Properties getUnknownOptions()
      Options not recognized when reading from properties.
      Returns:
      non-null
    • getMsgIdBloomXor

      public long getMsgIdBloomXor()
      The msg ID bloom xor value used to randomize message IDs.
      Returns:
      the msg id bloom xor
    • readFromProperties

      public void readFromProperties(String prefix, Properties props)
      Defaults in props are NOT honored. In-JVM client side must promote defaults to the primary map.
      Parameters:
      prefix - the pool prefix to match, non-null
      props - the properties to read, every entry starting with prefix is considered
    • writeToProperties

      public void writeToProperties(String prefix, Properties props)
      Write the settings into the given properties map. Does nothing if props is null.
      Parameters:
      prefix - the pool prefix to write each property under, non-null
      props - the map to write into, or null to skip
    • toString

      public String toString()
      String representation of these settings for debugging.
      Overrides:
      toString in class Object
    • generateRandomKey

      private static SessionKey generateRandomKey()
      Generates the random key for peer ordering.
      Returns:
      the new key
    • getBoolean

      private static final boolean getBoolean(String str, boolean defaultValue)
      Parses a boolean option with a fallback.
      Parameters:
      str - the option text, may be null
      defaultValue - the value to return if unparseable
      Returns:
      the parsed value
    • getInt

      private static final int getInt(String str, int defaultValue)
      Parses an integer option with a fallback.
      Parameters:
      str - the option text, may be null
      defaultValue - the value to return if unparseable
      Returns:
      the parsed value
    • getLong

      private static final long getLong(String str, long defaultValue)
      Parses a long option with a fallback.
      Parameters:
      str - the option text, may be null
      defaultValue - the value to return if unparseable
      Returns:
      the parsed value