All Implemented Interfaces:
Runnable, EventDispatcher

public class I2PTunnelClientextends I2PTunnelClientBase
Standard I2P client tunnel that forwards local TCP connections to I2P destinations.

Listens on a local port and creates I2P connections to configured destinations when clients connect. Supports multiple destinations with random selection, configurable read timeouts, and port mapping for services like SMTP and POP.

Handles destination resolution, connection management, and data forwarding between local client socket and remote I2P destination.

  • Field Details

    • readTimeout

      protected long readTimeout
      Idle timeout in milliseconds for I2P socket reads on new connections. ≤ 0 means no timeout.
  • Constructor Details

    • I2PTunnelClient

      public I2PTunnelClient(int localPort, String destinations, Logging l, boolean ownDest, EventDispatcher notifyThis, I2PTunnel tunnel, String pkf) throws IllegalArgumentException
      Create a standard client tunnel listening on localPort, forwarding to the given destinations. As of 0.9.20 this is fast, and does NOT connect the manager to the router, or open the local socket. You MUST call startRunning() for that.
      Parameters:
      localPort - if 0, use any port, get actual port selected with getLocalPort()
      destinations - peers we target, comma- or space-separated. Since 0.9.9, each dest may be appended with :port
      l - the logging instance
      ownDest - whether to use an owned destination
      notifyThis - the event dispatcher for notifications
      tunnel - the I2PTunnel instance, supplying the context and listen host
      pkf - the path to a persistent private key file, or null to generate one
      Throws:
      IllegalArgumentException - if the I2PTunnel does not contain valid config to contact the router
  • Method Details

    • setReadTimeout

      public void setReadTimeout(long ms)
      Set the read idle timeout for newly-created connections (in milliseconds). After this time expires without data being reached from the I2P network, the connection itself will be closed.

      Less than or equal to 0 means forever. Default -1 (forever) as of 0.9.36 for standard tunnels, but extending classes may override. Prior to that, default was 5 minutes, but did not work due to streaming bugs.

      Applies only to future connections; calling this does not affect existing connections.

      Parameters:
      ms - the idle timeout in ms; zero or negative means forever
    • getReadTimeout

      public long getReadTimeout()
      Get the read idle timeout for newly-created connections (in milliseconds).

      Less than or equal to 0 means forever. Default -1 (forever) as of 0.9.36 for standard tunnels, but extending classes may override. Prior to that, default was 5 minutes, but did not work due to streaming bugs.

      Returns:
      the idle timeout in ms; zero or negative means forever
    • clientConnectionRun

      protected void clientConnectionRun(Socket s)
      Handles an incoming local socket by selecting a remote destination and forwarding data.
      Specified by:
      clientConnectionRun in class I2PTunnelClientBase
      Parameters:
      s - the socket to manage
    • optionsUpdated

      public void optionsUpdated(I2PTunnel tunnel)
      Update the dests then call super.
      Overrides:
      optionsUpdated in class I2PTunnelClientBase
      Parameters:
      tunnel - the tunnel whose client options were updated
    • startRunning

      public void startRunning()
      Actually start working on incoming connections. Overridden to register with port mapper.
      Overrides:
      startRunning in class I2PTunnelClientBase
    • close

      public boolean close(boolean forced)
      Overridden to unregister with port mapper.
      Overrides:
      close in class I2PTunnelClientBase
      Parameters:
      forced - true to interrupt an in-progress build, false to close gracefully
      Returns:
      true if the tunnel is closed, or false if connections were still active and the close was refused