java.lang.Object
net.i2p.router.transport.udp.UDPAddress

class UDPAddressextends Object
Parses and caches the host, port, introducer list, MTU, and key data from a RouterAddress for the SSU and SSU2 transport styles.
  • Field Details

    • _host

      private final String _host
      The host name or literal address.
    • _hostAddress

      private InetAddress _hostAddress
      The resolved host address.
    • _port

      private final int _port
      The UDP port.
    • _introKey

      private final byte[] _introKey
      Our introduction key.
    • _introHosts

      private final String[] _introHosts
      The introducer host names.
    • _introAddresses

      private final InetAddress[] _introAddresses
      The resolved introducer addresses.
    • _introPorts

      private final int[] _introPorts
      The introducer ports.
    • _introKeys

      private final byte[][] _introKeys
      The introducer keys.
    • _introTags

      private final long[] _introTags
      The introducer tags.
    • _introExps

      private final long[] _introExps
      When the introducers expire.
    • _introHashes

      private final Hash[] _introHashes
      The introducer hashes.
    • _mtu

      private final int _mtu
      The MTU of the address.
    • _isIPv4

      private final boolean _isIPv4
      True if the address supports IPv4, both flags if both.
    • _isIPv6

      private final boolean _isIPv6
      True if the address supports IPv6.
    • PROP_PORT

      public static final String PROP_PORT
      Config key for SSU port.
      See Also:
    • PROP_HOST

      public static final String PROP_HOST
      Config key for SSU host.
      See Also:
    • PROP_INTRO_KEY

      public static final String PROP_INTRO_KEY
      Introduction key.
      See Also:
    • PROP_MTU

      public static final String PROP_MTU
      Property key for MTU.
      See Also:
    • PROP_CAPACITY

      public static final String PROP_CAPACITY
      Property key for capabilities.
      See Also:
    • CAPACITY_TESTING

      public static final char CAPACITY_TESTING
      'B'.
      See Also:
    • CAPACITY_INTRODUCER

      public static final char CAPACITY_INTRODUCER
      'C'.
      See Also:
    • PROP_INTRO_HOST_PREFIX

      public static final String PROP_INTRO_HOST_PREFIX
      Introducer host.
      See Also:
    • PROP_INTRO_PORT_PREFIX

      public static final String PROP_INTRO_PORT_PREFIX
      Introducer port.
      See Also:
    • PROP_INTRO_KEY_PREFIX

      public static final String PROP_INTRO_KEY_PREFIX
      Introducer key.
      See Also:
    • PROP_INTRO_TAG_PREFIX

      public static final String PROP_INTRO_TAG_PREFIX
      Introducer tag.
      See Also:
    • PROP_INTRO_EXP_PREFIX

      public static final String PROP_INTRO_EXP_PREFIX
      Introduction expiration prefix.
      See Also:
    • PROP_INTRO_HASH_PREFIX

      public static final String PROP_INTRO_HASH_PREFIX
      Introduction hash prefix for SSU2.
      See Also:
    • MAX_INTRODUCERS

      static final int MAX_INTRODUCERS
      Maximum number of introducers per address.
      See Also:
    • PROP_INTRO_HOST

      private static final String[] PROP_INTRO_HOST
      Config keys of the introducer hosts.
    • PROP_INTRO_PORT

      private static final String[] PROP_INTRO_PORT
      Config keys of the introducer ports.
    • PROP_INTRO_IKEY

      private static final String[] PROP_INTRO_IKEY
      Config keys of the introducer keys.
    • PROP_INTRO_TAG

      static final String[] PROP_INTRO_TAG
      Introducer tag property names indexed by position.
    • PROP_INTRO_EXP

      private static final String[] PROP_INTRO_EXP
      Config keys of the introducer expirations.
    • PROP_INTRO_HASH

      private static final String[] PROP_INTRO_HASH
      Config keys of the introducer hashes.
    • _inetAddressCache

      private static final Map<String, InetAddress> _inetAddressCache
      Textual IP to InetAddress, because InetAddress.getByName(String) is slow. Copied from Addresses.java, but caching InetAddress rather than byte[].
  • Constructor Details

    • UDPAddress

      public UDPAddress(RouterAddress addr)
      Parse and cache router address data.
      Parameters:
      addr - the address to parse, null for an invalid address
  • Method Details

    • tooManyIntroducers

      static boolean tooManyIntroducers(RouterAddress addr)
      Check whether a peer address declares more introducers than the spec allows. Each introducer requires a tag property, so any tag at or beyond our cap means the peer is out of spec.
      Parameters:
      addr - the peer's transport address
      Returns:
      true if introducer properties beyond MAX_INTRODUCERS are present
    • overCapIntroducerKey

      static boolean overCapIntroducerKey(String msg)
      Check whether a property-order parse error names an introducer property beyond our cap, e.g. "iexp10". Such a peer wrote its introducer options numerically instead of in the required sorted order, which only happens with more introducers than we support.
      Parameters:
      msg - the DataFormatException message
      Returns:
      true if an over-cap introducer key appears in the message
    • getHost

      public String getHost()
      Host string from the router address.
      Returns:
      the host, null when the address is invalid
    • getHostAddress

      InetAddress getHostAddress()
      The InetAddress for the router address's host, looked up on first use.

      Hostnames are not resolved; a host that is not a literal IP address gives a null address.

      Returns:
      InetAddress or null
    • getPort

      public int getPort()
      Port number from the router address.
      Returns:
      the port, 0 when the address is invalid
    • getIntroKey

      byte[] getIntroKey()
      The key this address is introduced under.
      Returns:
      shouldn't be null but will be if invalid
    • getIntroducerCount

      int getIntroducerCount()
      How many introducers this address carries.
      Returns:
      the introducer count, 0 when there are none
    • getIntroducerHost

      InetAddress getIntroducerHost(int i)
      The InetAddress for the introducer at index i, looked up on first use.

      Hostnames are not resolved; a host that is not a literal IP address gives a null address.

      Parameters:
      i - the introducer index, from 0
      Returns:
      null if invalid or for SSU2
    • getIntroducerPort

      int getIntroducerPort(int i)
      Port number for the given introducer.
      Parameters:
      i - the introducer index, from 0
      Returns:
      greater than zero or zero for SSU2
    • getIntroducerKey

      byte[] getIntroducerKey(int i)
      Introducer key for the given introducer.
      Parameters:
      i - the introducer index, from 0
      Returns:
      null if no keys or for SSU2
    • getIntroducerTag

      long getIntroducerTag(int i)
      Introducer tag for the given introducer.
      Parameters:
      i - the introducer index, from 0
      Returns:
      greater than zero
    • getIntroducerExpiration

      long getIntroducerExpiration(int i)
      Expiration for the given introducer.
      Parameters:
      i - the introducer index, from 0
      Returns:
      ms since epoch, zero if unset
    • getIntroducerHash

      Hash getIntroducerHash(int i)
      Introducer hash for the given introducer.
      Parameters:
      i - the introducer index, from 0
      Returns:
      the introducer hash, null when unset or out of range
    • isIPv4

      boolean isIPv4()
      Whether this address is IPv4.
      Returns:
      true when the address is IPv4
    • isIPv6

      boolean isIPv6()
      Whether this address is IPv6.
      Returns:
      true when the address is IPv6
    • getMTU

      int getMTU()
      The MTU to use for this address.
      Returns:
      0 if unset or invalid; rectified via MTU.rectify(boolean, int)
    • toString

      public String toString()
      String representation.
      Overrides:
      toString in class Object
      Returns:
      a human readable description of this address
    • getByName

      private static InetAddress getByName(String host)
      Caching version of getByName(host), which is slow. Caches numeric IPs only. As of 0.9.32, will NOT resolve hostnames.

      Unlike InetAddress.getByName(String), we do NOT allow numeric IPs of the form d.d.d, d.d, or d, as these are almost certainly mistakes.

      Parameters:
      host - literal IPv4 or IPv6; if null or hostname, returns null
      Returns:
      InetAddress or null
    • clearCache

      static void clearCache()
      Clear cache.