All Implemented Interfaces:
Runnable, EventDispatcher

public class I2PTunnelConnectClientextends I2PTunnelHTTPClientBase implements Runnable
SSL tunnel through HTTP proxy using CONNECT method.

Supports various host formats (example.i2p, .b32.i2p, base64, external domains) and CONNECT syntax variations. Protocol ignored for I2P destinations.

Additional lines after CONNECT are stripped. CONNECT line removed for .i2p accesses, passed through for outproxy accesses.

Reference: RFC draft-luotonen-ssl-tunneling-03.txt (1997) "Tunneling SSL Through a WWW Proxy".

  • Field Details

  • Constructor Details

    • I2PTunnelConnectClient

      public I2PTunnelConnectClient(int localPort, Logging l, boolean ownDest, String wwwProxy, EventDispatcher notifyThis, I2PTunnel tunnel) throws IllegalArgumentException
      Create an HTTPS proxy tunnel for connecting out to arbitrary destinations, with optional outproxy chaining. 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 - the local port to bind to
      l - the Logging instance this tunnel's status messages are sent to
      ownDest - whether to use our own destination
      wwwProxy - the outproxy destinations, separated by commas or spaces, or null for none
      notifyThis - event dispatcher for notifications
      tunnel - the parent I2PTunnel instance, supplying the listening host and client options
      Throws:
      IllegalArgumentException - if the I2PTunnel does not contain valid config to contact the router
  • Method Details

    • getDefaultOptions

      protected I2PSocketOptions getDefaultOptions()
      Create the default options (using the default timeout, etc). Warning, this does not make a copy of I2PTunnel's client options, it modifies them directly.
      Overrides:
      getDefaultOptions in class I2PTunnelClientBase
      Returns:
      the default options
    • executeTask

      private void executeTask(Runnable task)
      Execute a runnable task on the thread pool, freeing the accept thread to handle the next connection.

      Both I2PTunnelRunner and I2PTunnelOutproxyRunner manage their own socket cleanup in their finally blocks, so the caller no longer needs to close sockets after this returns.

      Parameters:
      task - Runnable task to execute
    • startRunning

      public void startRunning()
      Starts the CONNECT proxy and registers with port mapper.
      Overrides:
      startRunning in class I2PTunnelClientBase
    • close

      public boolean close(boolean forced)
      Closes the CONNECT proxy and unregisters from 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
    • getRealm

      protected String getRealm()
      Authentication realm for the HTTP proxy.
      Specified by:
      getRealm in class I2PTunnelHTTPClientBase
      Returns:
      AUTH_REALM, the realm this client sends in its Digest authentication challenge to the proxy
    • clientConnectionRun

      protected void clientConnectionRun(Socket s)
      Handle an incoming CONNECT proxy connection. Parses the CONNECT request, resolves the destination, and forwards data.
      Specified by:
      clientConnectionRun in class I2PTunnelClientBase
      Parameters:
      s - the local client socket connection
    • writeErrorMessage

      private static void writeErrorMessage(String errMessage, OutputStream out) throws IOException
      Write an error message to the output stream and close it.
      Parameters:
      errMessage - the HTML error response to send
      out - the output stream to write to, may be null
      Throws:
      IOException - if an I/O error occurs