java.lang.Object
java.net.SocketAddress
net.i2p.client.streaming.I2PSocketAddress
All Implemented Interfaces:
Serializable

public class I2PSocketAddressextends SocketAddress
A SocketAddress (Destination + port) so we can have SocketChannels. Ports are not widely used in I2P, in most cases the port will be zero. See InetSocketAddress for javadocs.
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serial version unique identifier.
      See Also:
    • _port

      private final int _port
      Port number, 0 if not specified.
    • _dest

      private transient Destination _dest
      The I2P destination.
    • _host

      private final String _host
      Hostname from the constructor.
  • Constructor Details

    • I2PSocketAddress

      public I2PSocketAddress(String host)
      Convenience constructor that parses host:port. Does a naming service lookup to resolve the dest. May take several seconds for b32.
      Parameters:
      host - hostname or b64 dest or b32, may have :port appended
      Throws:
      IllegalArgumentException - for port < 0 or port > 65535 or invalid port
    • I2PSocketAddress

      public I2PSocketAddress(Destination dest, int port)
      Does not do a reverse lookup. Host will be null.
      Parameters:
      dest - the destination to address, which must not be null
      port - the TCP port on that destination, from 0 to 65535
      Throws:
      IllegalArgumentException - for port < 0 or port > 65535
    • I2PSocketAddress

      public I2PSocketAddress(String host, int port)
      Does a naming service lookup to resolve the dest. May take several seconds for b32.
      Parameters:
      host - the hostname to resolve, e.g. a b32 address or an .i2p name
      port - the TCP port on the resolved destination, from 0 to 65535
      Throws:
      IllegalArgumentException - for port < 0 or port > 65535
    • I2PSocketAddress

      private I2PSocketAddress(int port, String host)
      Creates an address without resolving anything.
      Parameters:
      port - the TCP port, from 0 to 65535
      host - the hostname or address, may be null
  • Method Details

    • createUnresolved

      public static I2PSocketAddress createUnresolved(String host, int port)
      Creates an unresolved address for the given host and port.
      Parameters:
      host - the hostname to record now and resolve on the first getAddress() call
      port - the TCP port on the destination, from 0 to 65535
      Returns:
      an address holding that host and port, with no destination yet
      Throws:
      IllegalArgumentException - for port < 0 or port > 65535
    • getPort

      public int getPort()
      The port number of this address.
      Returns:
      the port number, 0 if not specified
    • getAddress

      public Destination getAddress()
      Does a naming service lookup to resolve the dest if this was created unresolved or if the resolution failed in the constructor. If unresolved, this may take several seconds for b32.
      Returns:
      the resolved destination, or null if the lookup failed
    • getHostName

      public String getHostName()
      Host name of this address, as given in the constructor.
      Returns:
      the host only if given in the constructor. Does not do a reverse lookup.
    • isUnresolved

      public boolean isUnresolved()
      Whether the destination has not been resolved.
      Returns:
      true if this address was created unresolved or resolution failed
    • toString

      public String toString()
      String representation of this address.
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Whether this address equals another, comparing port, destination, and host.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Hash code of this address.
      Overrides:
      hashCode in class Object
      Returns:
      whether h code is present