All Implemented Interfaces:
Runnable, EventDispatcher
Direct Known Subclasses:
I2PSOCKSIRCTunnel

public class I2PSOCKSTunnelextends I2PTunnelClientBase
SOCKS proxy server that routes TCP connections through I2P network.

This class implements a SOCKS4a/5 proxy server that accepts local SOCKS connections and forwards them to I2P destinations or configured outproxies. It supports both I2P destination routing (for .i2p addresses) and outproxy routing for clearnet access, with authentication and port-specific proxy configuration.

The tunnel provides dynamic destination resolution, connection management, and serves as a flexible proxy solution for applications that support SOCKS protocol, enabling seamless I2P integration for various clients.

  • Field Details

    • INITIAL_SO_TIMEOUT

      protected static final int INITIAL_SO_TIMEOUT
      This is a standard soTimeout, not a total timeout. We have no slowloris protection on the client side. See I2PTunnelHTTPServer or SAM's ReadLine if we need that.
      See Also:
    • proxies

      private final HashMap<String, List<String>> proxies
      Proxy settings by port, with a "default" entry for the rest
    • AUTH_REALM

      public static final String AUTH_REALM
      The HTTP auth realm presented to clients that authenticate.
      See Also:
    • PROP_OUTPROXY_TYPE

      public static final String PROP_OUTPROXY_TYPE
      The property naming the outproxy type ("none", "HTTP", "SOCKS", "SOCKS4a").
      See Also:
    • PROP_PROXY_PREFIX

      public static final String PROP_PROXY_PREFIX
      Prefix of the per-port proxy property names.
      See Also:
    • DEFAULT

      public static final String DEFAULT
      The key used for the default (first) proxy.
      See Also:
    • PROP_PROXY_DEFAULT

      public static final String PROP_PROXY_DEFAULT
      The full property name of the default proxy.
      See Also:
  • Constructor Details

    • I2PSOCKSTunnel

      public I2PSOCKSTunnel(int localPort, Logging l, boolean ownDest, EventDispatcher notifyThis, I2PTunnel tunnel, String pkf)
      Create a SOCKS proxy on the given local port.

      Since 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 - the local port to listen on
      l - the logging instance
      ownDest - whether to use own destination
      notifyThis - the event dispatcher for notifications
      tunnel - the I2P tunnel
      pkf - private key file name or null for transient key
  • Method Details

    • clientConnectionRun

      protected void clientConnectionRun(Socket s)
      Description copied from class: I2PTunnelClientBase
      Manage a connection in a separate thread. This only works if you do not override I2PTunnelClientBase.manageConnection(Socket).

      This is run in a thread from an unlimited-size thread pool, so it may block or run indefinitely.

      Specified by:
      clientConnectionRun in class I2PTunnelClientBase
      Parameters:
      s - the socket to manage
    • optionsUpdated

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

      private void parseOptions()
      Reads the proxy settings out of the tunnel's options.
    • getProxyMap

      public HashMap<String, List<String>> getProxyMap()
      Gets the proxy map for all configured ports.
      Returns:
      a map of port strings to proxy lists
    • getDefaultProxies

      public List<String> getDefaultProxies()
      Get the default proxy list.
      Returns:
      the default proxy list
    • getProxies

      public List<String> getProxies(int port)
      Gets the proxy list for a specific port.

      If no proxies are configured for the port, returns the default proxies.

      Parameters:
      port - the local port to get proxies for
      Returns:
      the list of proxy destinations for the port, or default proxies
    • buildOptions

      public I2PSocketOptions buildOptions(Properties overrides)
      Build socket options from the tunnel config merged with overrides.
      Parameters:
      overrides - properties to override the default options
      Returns:
      the built socket options