java.lang.Object
net.i2p.client.streaming.impl.I2PSocketManagerFull
All Implemented Interfaces:
I2PSocketManager

public class I2PSocketManagerFullextends Object implements I2PSocketManager
Centralize the coordination and multiplexing of the local client's streaming. There should be one I2PSocketManager for each I2PSession, and if an application is sending and receiving data through the streaming library using an I2PSocketManager, it should not attempt to call I2PSession's setSessionListener or receive any messages with its .receiveMessage

This is what I2PSocketManagerFactory.createManager() returns. Direct instantiation by others is deprecated.

  • Field Details

  • Constructor Details

  • Method Details

    • buildOptions

      public I2PSocketOptions buildOptions()
      Create a copy of the current options, to be used in a setDefaultOptions() call.
      Specified by:
      buildOptions in interface I2PSocketManager
      Returns:
      a copy of the current default options
    • buildOptions

      public I2PSocketOptions buildOptions(Properties opts)
      Create a modified copy of the current options, to be used in a setDefaultOptions() call.

      Defaults in opts are honored: a property absent from opts keeps its current value rather than reverting to the default.

      Specified by:
      buildOptions in interface I2PSocketManager
      Parameters:
      opts - The new options, may be null
      Returns:
      a new options object with the specified modifications
    • getSession

      public I2PSession getSession()
      The I2P session for this socket manager.
      Specified by:
      getSession in interface I2PSocketManager
      Returns:
      the session, non-null
    • addSubsession

      public I2PSession addSubsession(InputStream privateKeyStream, Properties opts) throws I2PSessionException
      For a server, you must call connect() on the returned object. Connecting the primary session does NOT connect any subsessions. If the primary session is not connected, connecting a subsession will connect the primary session first.
      Specified by:
      addSubsession in interface I2PSocketManager
      Parameters:
      privateKeyStream - null for transient, if non-null must have same encryption keys as primary session and different signing keys
      opts - subsession options if any, may be null
      Returns:
      a new subsession, non-null
      Throws:
      I2PSessionException - if the router does not support sub-sessions, if a sub-session request is already pending, or if the new session duplicates an existing one by private key
    • removeSubsession

      public void removeSubsession(I2PSession session)
      Remove the subsession.
      Specified by:
      removeSubsession in interface I2PSocketManager
      Parameters:
      session - the subsession to remove
    • getSubsessions

      public List<I2PSession> getSubsessions()
      Subsession list, not including the primary session.
      Specified by:
      getSubsessions in interface I2PSocketManager
      Returns:
      a list of subsessions, non-null, does not include the primary session
    • getConnectionManager

      public ConnectionManager getConnectionManager()
      Connection manager for this socket manager.
      Returns:
      the connection manager
    • receiveSocket

      The accept() call.

      This only listens on the primary session. There is no way to get incoming connections on a subsession.

      Returns:
      connected I2PSocket, never null
      Throws:
      I2PException - if session is closed
      RouterRestartException - (extends I2PException) if the router is apparently restarting
      ConnectException - if the I2PServerSocket is closed, or if interrupted
      SocketTimeoutException - if a timeout was previously set with setSoTimeout and the timeout has been reached.
    • ping

      public boolean ping(Destination peer, long timeoutMs)
      Ping the specified peer, returning true if they replied to the ping within the timeout specified, false otherwise. This call blocks.

      Uses the ports from the default options.

      Specified by:
      ping in interface I2PSocketManager
      Parameters:
      peer - Destination to ping
      timeoutMs - timeout in ms, greater than zero
      Returns:
      true on success, false on failure
      Throws:
      IllegalArgumentException - if timeoutMs is not greater than zero
    • ping

      public boolean ping(Destination peer, int localPort, int remotePort, long timeoutMs)
      Ping the specified peer, returning true if they replied to the ping within the timeout specified, false otherwise. This call blocks.

      Uses the ports specified.

      Specified by:
      ping in interface I2PSocketManager
      Parameters:
      peer - Destination to ping
      localPort - 0 - 65535
      remotePort - 0 - 65535
      timeoutMs - timeout in ms, greater than zero
      Returns:
      success or failure
      Throws:
      IllegalArgumentException - if ports or timeout are invalid
    • ping

      public boolean ping(Destination peer, I2PSession session, int localPort, int remotePort, long timeoutMs)
      Ping the specified peer through a specific subsession, returning true if they replied to the ping within the timeout specified, false otherwise. This call blocks.
      Parameters:
      peer - Destination to ping
      session - the subsession to use
      localPort - 0 - 65535
      remotePort - 0 - 65535
      timeoutMs - timeout in ms, greater than zero
      Returns:
      success or failure
      Throws:
      IllegalArgumentException - if ports or timeout are invalid
    • ping

      public byte[] ping(Destination peer, int localPort, int remotePort, long timeoutMs, byte[] payload)
      Ping the specified peer, returning true if they replied to the ping within the timeout specified, false otherwise. This call blocks.

      Uses the ports specified.

      Specified by:
      ping in interface I2PSocketManager
      Parameters:
      peer - Destination to ping
      localPort - 0 - 65535
      remotePort - 0 - 65535
      timeoutMs - timeout in ms, greater than zero
      payload - to include in the ping
      Returns:
      the payload received in the pong, zero-length if none, null on failure or timeout
      Throws:
      IllegalArgumentException - if ports or timeout are invalid
    • ping

      public byte[] ping(Destination peer, I2PSession session, int localPort, int remotePort, long timeoutMs, byte[] payload)
      Ping the specified peer through a specific subsession, returning true if they replied to the ping within the timeout specified, false otherwise. This call blocks.
      Parameters:
      peer - Destination to ping
      session - the subsession to use
      localPort - 0 - 65535
      remotePort - 0 - 65535
      timeoutMs - timeout in ms, greater than zero
      payload - to include in the ping
      Returns:
      the payload received in the pong, zero-length if none, null on failure or timeout
      Throws:
      IllegalArgumentException - if ports or timeout are invalid
    • setAcceptTimeout

      public void setAcceptTimeout(long ms)
      Set the accept timeout in milliseconds.
      Specified by:
      setAcceptTimeout in interface I2PSocketManager
      Parameters:
      ms - the accept timeout in milliseconds
    • getAcceptTimeout

      public long getAcceptTimeout()
      Accept timeout in milliseconds.
      Specified by:
      getAcceptTimeout in interface I2PSocketManager
      Returns:
      the accept timeout in milliseconds
    • setDefaultOptions

      public void setDefaultOptions(I2PSocketOptions options)
      Update the options on a running socket manager. Parameters in the I2PSocketOptions interface may be changed directly with the setters; no need to use this method for those. This does NOT update the underlying I2CP or tunnel options; use getSession().updateOptions() for that.
      Specified by:
      setDefaultOptions in interface I2PSocketManager
      Parameters:
      options - as created from a call to buildOptions(properties), non-null
    • setDefaultOptions

      public void setDefaultOptions(I2PSession session, I2PSocketOptions options)
      Update the options on a running subsession. Parameters in the I2PSocketOptions interface may be changed directly with the setters; no need to use this method for those. This does NOT update the underlying I2CP or tunnel options.
      Parameters:
      session - the subsession to update
      options - as created from a call to buildOptions(properties), non-null
    • getDefaultOptions

      public I2PSocketOptions getDefaultOptions()
      Returns the current default options. This does NOT update the underlying I2CP or tunnel options; use getSession().updateOptions() for that.
      Specified by:
      getDefaultOptions in interface I2PSocketManager
      Returns:
      the default options
    • getServerSocket

      public I2PServerSocket getServerSocket()
      Returns non-null socket. This method does not throw exceptions, but methods on the returned socket may throw exceptions if the socket or socket manager is closed.

      This only listens on the primary session. There is no way to get incoming connections on a subsession.

      Specified by:
      getServerSocket in interface I2PSocketManager
      Returns:
      non-null
    • getStandardServerSocket

      public ServerSocket getStandardServerSocket() throws IOException
      Like getServerSocket but returns a real ServerSocket for easier porting of apps.

      This only listens on the primary session. There is no way to get incoming connections on a subsession.

      Specified by:
      getStandardServerSocket in interface I2PSocketManager
      Returns:
      the standard server socket
      Throws:
      IOException - on I/O error
    • connect

      Create a new connected socket. Blocks until the socket is created, unless the connectDelay option (i2p.streaming.connectDelay) is set and greater than zero. If so this will return immediately, and the client may quickly write initial data to the socket and this data will be bundled in the SYN packet.
      Specified by:
      connect in interface I2PSocketManager
      Parameters:
      peer - Destination to connect to
      options - I2P socket options to be used for connecting, may be null
      Returns:
      I2PSocket if successful
      Throws:
      NoRouteToHostException - if the peer is not found or not reachable
      I2PException - if there is some other I2P-related problem
    • connect

      Create a new connected socket. Blocks until the socket is created, unless the connectDelay option (i2p.streaming.connectDelay) is set and greater than zero in the default options. If so this will return immediately, and the client may quickly write initial data to the socket and this data will be bundled in the SYN packet.
      Specified by:
      connect in interface I2PSocketManager
      Parameters:
      peer - Destination to connect to
      Returns:
      I2PSocket if successful
      Throws:
      NoRouteToHostException - if the peer is not found or not reachable
      I2PException - if there is some other I2P-related problem
    • connectToSocket

      public Socket connectToSocket(Destination peer) throws IOException
      Like connect() but returns a real Socket, and throws only IOE, for easier porting of apps.
      Specified by:
      connectToSocket in interface I2PSocketManager
      Parameters:
      peer - destination to connect to
      Returns:
      a connected Socket
      Throws:
      IOException - on I/O error
    • connectToSocket

      public Socket connectToSocket(Destination peer, int timeout) throws IOException
      Like connect() but returns a real Socket, and throws only IOE, for easier porting of apps.
      Specified by:
      connectToSocket in interface I2PSocketManager
      Parameters:
      peer - destination to connect to
      timeout - ms if > 0, forces blocking (disables connectDelay)
      Returns:
      a connected Socket
      Throws:
      IOException - on I/O error
    • destroySocketManager

      public void destroySocketManager()
      Destroy the socket manager, freeing all the associated resources. This method will block until all the managed sockets are closed.

      CANNOT be restarted.

      Specified by:
      destroySocketManager in interface I2PSocketManager
    • isDestroyed

      public boolean isDestroyed()
      Has the socket manager been destroyed?
      Specified by:
      isDestroyed in interface I2PSocketManager
      Returns:
      true once destroySocketManager() has completed; the flag is set at the start of that method, so it also guards against a second destroy
    • listSockets

      public Set<I2PSocket> listSockets()
      Retrieve a set of currently connected I2PSockets, either initiated locally or remotely.
      Specified by:
      listSockets in interface I2PSocketManager
      Returns:
      set of currently connected I2PSockets
    • getName

      public String getName()
      For logging / diagnostics only.
      Specified by:
      getName in interface I2PSocketManager
      Returns:
      the name this manager was constructed with, suffixed with a sequence number that distinguishes concurrent managers
    • setName

      public void setName(String name)
      For logging / diagnostics only.
      Specified by:
      setName in interface I2PSocketManager
      Parameters:
      name - the label reported in logs and console output
    • addDisconnectListener

      public void addDisconnectListener(I2PSocketManager.DisconnectListener lsnr)
      Add a disconnect listener.
      Specified by:
      addDisconnectListener in interface I2PSocketManager
      Parameters:
      lsnr - the disconnect listener to add
    • removeDisconnectListener

      public void removeDisconnectListener(I2PSocketManager.DisconnectListener lsnr)
      Remove a disconnect listener.
      Specified by:
      removeDisconnectListener in interface I2PSocketManager
      Parameters:
      lsnr - the disconnect listener to remove
    • getInitialWindowSize

      public static int getInitialWindowSize()
      Initial window size.
      Returns:
      the initial window size
    • setInitialWindowSize

      public static void setInitialWindowSize(int val)
      Initial window size.
      Parameters:
      val - the new initial window size
    • getInitialRTO

      public static int getInitialRTO()
      Initial retransmission timeout.
      Returns:
      the initial retransmission timeout
    • setInitialRTO

      public static void setInitialRTO(int val)
      Initial retransmission timeout.
      Parameters:
      val - the new initial retransmission timeout
    • getDefaultInitialAckDelay

      public static int getDefaultInitialAckDelay()
      Default initial ACK delay.
      Returns:
      the default initial ACK delay
    • setDefaultInitialAckDelay

      public static void setDefaultInitialAckDelay(int val)
      Default initial ACK delay.
      Parameters:
      val - the new default initial ACK delay
    • getDefaultPassiveFlushDelay

      public static int getDefaultPassiveFlushDelay()
      Default passive flush delay.
      Returns:
      the default passive flush delay
    • setDefaultPassiveFlushDelay

      public static void setDefaultPassiveFlushDelay(int val)
      Default passive flush delay.
      Parameters:
      val - the new default passive flush delay
    • getDefaultInactivityTimeout

      public static int getDefaultInactivityTimeout()
      Default inactivity timeout.
      Returns:
      the default inactivity timeout
    • setDefaultInactivityTimeout

      public static void setDefaultInactivityTimeout(int val)
      Default inactivity timeout.
      Parameters:
      val - the new default inactivity timeout
    • getMaxInboundBuffer

      public static int getMaxInboundBuffer()
      Maximum inbound buffer cap.
      Returns:
      the maximum inbound buffer cap (bytes)
    • setMaxInboundBuffer

      public static void setMaxInboundBuffer(int val)
      Maximum inbound buffer cap.
      Parameters:
      val - the new maximum inbound buffer cap (bytes)
    • getMaxStreamsOverride

      public static int getMaxStreamsOverride()
      The Tuner's reactive cap on concurrent streams; 0 = not armed (each manager uses its own configured maxConcurrentStreams).
      Returns:
      the current override, or 0 if disabled
    • setMaxStreamsOverride

      public static void setMaxStreamsOverride(int val)
      Arm or clear the Tuner's reactive stream-cap override. Clamped to [0, maxMaxConcurrentStreams]; a manager enforces min(config, override).
      Parameters:
      val - the new override cap, or 0 to disable
    • getReceiveWorkerThreads

      public static int getReceiveWorkerThreads()
      The Tuner-managed default for inbound packet receive workers; 0 = no override (each manager uses its configured value or the core count).
      Returns:
      the current default worker count, or 0 if disabled
    • setReceiveWorkerThreads

      public static void setReceiveWorkerThreads(int val)
      Set the Tuner-managed default for inbound packet receive workers. Clamped to [0, 8]; 0 disables the override.
      Parameters:
      val - the new default worker count, or 0 to disable
    • resizeReceiveWorkers

      public static void resizeReceiveWorkers(int val)
      Apply a new receive-worker default and resize every live dispatcher to match, so existing managers (not just ones created afterwards) follow the Tuner. The resize drains each dispatcher's shard queues before rebuilding, so per-connection ordering and the never-drop guarantee are preserved.
      Parameters:
      val - the new worker count, clamped to [1, 8]; 0 only updates the default for future managers
    • getMaxMaxConcurrentStreams

      public static int getMaxMaxConcurrentStreams()
      The operator-tunable ceiling for the Tuner's stream-cap override. Reads from i2p.streaming.maxMaxConcurrentStreams in router.config.
      Returns:
      the current ceiling
    • setMaxMaxConcurrentStreams

      public static void setMaxMaxConcurrentStreams(int val)
      Set the operator-tunable ceiling for the Tuner's stream-cap override.
      Parameters:
      val - the new ceiling, clamped to [64, 8192]
    • getMaxSYNQueueSize

      public static int getMaxSYNQueueSize()
      Max SYN queue size, dynamically adjustable by the Tuner.
      Returns:
      the current max SYN queue size
    • setMaxSYNQueueSize

      public static void setMaxSYNQueueSize(int val)
      Max SYN queue size, dynamically adjustable by the Tuner.
      Parameters:
      val - the new max SYN queue size
    • getRttSynTimeoutScale

      public static int getRttSynTimeoutScale()
      Scale factor applied to a sampled recent round-trip time when computing the adaptive SYN accept-queue timeout under tunnel stress. A slow-but-alive fabric (high RTT) must keep a longer window than a fast one so that SYNs aren't expired before the handshake completes. Dynamically adjustable by the Tuner.

      0 (the unset default) selects ConnectionHandler.SYN_RTT_SCALE_DEFAULT (4), so the RTT-aware floor stays active out of the box.

      Returns:
      the RTT scale factor, or 0 for the built-in default
    • setRttSynTimeoutScale

      public static void setRttSynTimeoutScale(int val)
      Multiplier applied to recent RTT when sizing the adaptive SYN timeout.
      Parameters:
      val - the new scale factor; 0 or a negative value selects the built-in default (4)
    • getSynExprExpireThresh

      public static int getSynExprExpireThresh()
      Fraction (percent) of recent SYN-queue entries that must expire un-accepted before the adaptive timeout clamp is armed, in addition to low tunnel build success. Requiring positive stall evidence keeps a slow-but-alive server from being punished by its own latency. Dynamically adjustable by the Tuner.
      Returns:
      the expire-rate threshold as a percent [0,100], 100 disables the clamp
    • setSynExprExpireThresh

      public static void setSynExprExpireThresh(int val)
      Fraction of recent SYNs that must expire un-accepted to arm the clamp.
      Parameters:
      val - the new threshold percent; 100 disables the clamp entirely
    • getAcceptWorkerThreads

      public static int getAcceptWorkerThreads()
      Number of accept worker threads, dynamically adjustable by the Tuner.
      Returns:
      the current number of accept worker threads
    • setAcceptWorkerThreads

      public static void setAcceptWorkerThreads(int val)
      Number of accept worker threads, dynamically adjustable by the Tuner.
      Parameters:
      val - the new number of accept worker threads (clamped to [0, 16])