java.lang.Object
net.i2p.client.streaming.impl.I2PSocketOptionsImpl
All Implemented Interfaces:
I2PSocketOptions
Direct Known Subclasses:
ConnectionOptions

class I2PSocketOptionsImplextends Object implements I2PSocketOptions
Define the configuration for streaming and verifying data on the socket. Use I2PSocketManager.buildOptions() to get one of these.
  • Field Details

    • _connectTimeout

      private long _connectTimeout
      How long a connect may wait, in ms.
    • _readTimeout

      private long _readTimeout
      How long a read may wait, in ms.
    • _writeTimeout

      private long _writeTimeout
      How long a write may wait, in ms.
    • _maxBufferSize

      private int _maxBufferSize
      Largest send or receive buffer allowed, in bytes.
    • _localPort

      private int _localPort
      The local port of the socket.
    • _remotePort

      private int _remotePort
      The remote port of the socket.
    • DEFAULT_BUFFER_SIZE

      public static final int DEFAULT_BUFFER_SIZE
      Default max buffer size. Platform-dependent: a slow system, or one reporting less than 512 MB of memory, gets 512 KB, everything else 1 MB (see the sizing below).
    • DEFAULT_READ_TIMEOUT

      public static final int DEFAULT_READ_TIMEOUT
      Default read timeout in ms; -1 means block forever.
      See Also:
    • DEFAULT_WRITE_TIMEOUT

      public static final int DEFAULT_WRITE_TIMEOUT
      Default write timeout in ms; -1 means never time out.
      See Also:
    • DEFAULT_CONNECT_TIMEOUT

      public static final int DEFAULT_CONNECT_TIMEOUT
      Default base connect timeout in ms (30 seconds). This is the pre-scaling window only: the effective window is scaled by the connect timeout multiplier and capped at the absolute max connect timeout (75 seconds by default), so a caller setting a longer value still waits no longer than the cap.
      See Also:
  • Constructor Details

    • I2PSocketOptionsImpl

      public I2PSocketOptionsImpl()
      Max buffer size, connect timeout, read timeout, and write timeout from System properties. Does not set local port or remote port.
    • I2PSocketOptionsImpl

      public I2PSocketOptionsImpl(I2PSocketOptions opts)
      Initializes from System properties then copies over all options.
      Parameters:
      opts - may be null
    • I2PSocketOptionsImpl

      public I2PSocketOptionsImpl(Properties opts)
      Max buffer size, connect timeout, read timeout, and write timeout from properties. Does not set local port or remote port.

      A property absent from opts, or one that does not parse as an integer, falls back to the corresponding default.

      Parameters:
      opts - may be null
  • Method Details

    • setProperties

      public void setProperties(Properties opts)
      Max buffer size, connect timeout, read timeout, and write timeout from properties. Does not set local port or remote port.

      Only the properties present in opts are applied. Anything absent from opts keeps the value this object already has, so a partial opts overrides only what it names.

      Parameters:
      opts - may be null
    • init

      protected void init(Properties opts)
      Max buffer size, connect timeout, read timeout, and write timeout from properties. Does not set local port or remote port.
      Parameters:
      opts - options properties to read the four settings from
    • getInt

      protected static int getInt(Properties opts, String name, int defaultVal)
      Parse an integer property value, with a default on failure.
      Parameters:
      opts - properties to read from, null yields the default
      name - the property name to look up
      defaultVal - returned when the property is absent or not an integer
      Returns:
      the parsed integer, or defaultVal when absent or unparseable
    • getDouble

      static double getDouble(Properties opts, String name, double defaultVal)
      Not part of the API, not for external use.
      Parameters:
      opts - properties to read from, null yields the default
      name - the property name to look up
      defaultVal - returned when the property is absent or not a number
      Returns:
      the parsed property value, or defaultVal if it cannot be parsed
    • getConnectTimeout

      public long getConnectTimeout()
      Base time to wait for the ACK from a SYN, in milliseconds.

      The stored value is un-scaled; the effective connect window adds the connect delay on the delayed-SYN path, is scaled by the connect timeout multiplier, and is capped at the absolute max connect timeout, so a stored value above that cap waits no longer than the cap.

      Default 30 seconds.

      Specified by:
      getConnectTimeout in interface I2PSocketOptions
      Returns:
      milliseconds to wait, or a non-positive value for no connect timeout, i.e. the handshake is not given up on a timer
    • setConnectTimeout

      public void setConnectTimeout(long ms)
      Define how long we will wait for the ACK from a SYN, in milliseconds.

      The value is stored un-scaled; see getConnectTimeout().

      Default 30 seconds.

      Specified by:
      setConnectTimeout in interface I2PSocketOptions
      Parameters:
      ms - timeout in ms, <= 0 for no connect timeout
    • getReadTimeout

      public long getReadTimeout()
      What is the longest we'll block on the input stream while waiting for more data. If this value is exceeded, the read() throws SocketTimeoutException.

      WARNING: Default -1 (unlimited), which is probably not what you want.

      Specified by:
      getReadTimeout in interface I2PSocketOptions
      Returns:
      timeout in ms, 0 for nonblocking, -1 for forever
    • setReadTimeout

      public void setReadTimeout(long ms)
      What is the longest we'll block on the input stream while waiting for more data. If this value is exceeded, the read() throws SocketTimeoutException.

      WARNING: Default -1 (unlimited), which is probably not what you want.

      Specified by:
      setReadTimeout in interface I2PSocketOptions
      Parameters:
      ms - timeout in ms, 0 for nonblocking, -1 for forever
    • getMaxBufferSize

      public int getMaxBufferSize()
      How much data will we accept that hasn't been written out yet. After this amount has been exceeded, subsequent .write calls will block until either some data is removed or the connection is closed. If this is less than or equal to zero, there is no limit (warning: can eat ram)

      Default is DEFAULT_BUFFER_SIZE, which is platform-dependent.

      Specified by:
      getMaxBufferSize in interface I2PSocketOptions
      Returns:
      buffer size limit, in bytes
    • setMaxBufferSize

      public void setMaxBufferSize(int numBytes)
      How much data will we accept that hasn't been written out yet. After this amount has been exceeded, subsequent .write calls will block until either some data is removed or the connection is closed. If this is less than or equal to zero, there is no limit (warning: can eat ram)

      Default is DEFAULT_BUFFER_SIZE, which is platform-dependent.

      Specified by:
      setMaxBufferSize in interface I2PSocketOptions
      Parameters:
      numBytes - How much data will we accept that hasn't been written out yet.
    • getWriteTimeout

      public long getWriteTimeout()
      What is the longest we'll block on the output stream while waiting for the data to flush. If this value is exceeded, the write() throws InterruptedIOException. If this is less than or equal to zero, there is no timeout.

      Default -1 (unlimited).

      Specified by:
      getWriteTimeout in interface I2PSocketOptions
      Returns:
      the write timeout
    • setWriteTimeout

      public void setWriteTimeout(long ms)
      What is the longest we'll block on the output stream while waiting for the data to flush. If this value is exceeded, the write() throws InterruptedIOException. If this is less than or equal to zero, there is no timeout.

      Default -1 (unlimited).

      Specified by:
      setWriteTimeout in interface I2PSocketOptions
      Parameters:
      ms - wait time to block on the output stream while waiting for the data to flush.
    • getPort

      public int getPort()
      The remote port.
      Specified by:
      getPort in interface I2PSocketOptions
      Returns:
      Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
    • setPort

      public void setPort(int port)
      The remote port.
      Specified by:
      setPort in interface I2PSocketOptions
      Parameters:
      port - 0 - 65535
      Throws:
      IllegalArgumentException - if port is outside 0 - 65535
    • getLocalPort

      public int getLocalPort()
      The local port.
      Specified by:
      getLocalPort in interface I2PSocketOptions
      Returns:
      Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
    • setLocalPort

      public void setLocalPort(int port)
      The local port. Zero (default) means you will receive traffic on all ports. Nonzero means you will get traffic ONLY for that port, use with care, as most applications do not specify a remote port.
      Specified by:
      setLocalPort in interface I2PSocketOptions
      Parameters:
      port - 0 - 65535
      Throws:
      IllegalArgumentException - if port is outside 0 - 65535