All Implemented Interfaces:
Runnable

public class I2PTunnelOutproxyRunnerextends I2PAppThread
I2PTunnelOutproxyRunner forwards data bidirectionally between two connected sockets: one representing an external socket connection and the other an I2P socket connection. It continuously transfers data until either side closes the connection or an error occurs.

The class manages two internal forwarding threads to handle each direction of the data flow, maintains counters of bytes sent and received, and allows optional initial data to be sent on either socket upon startup.

A user-provided callback can be invoked if no data (beyond initial data) is received before the connection closes, enabling handling of timeouts or failures.

This class is designed for internal use within the I2P tunnel infrastructure and is not maintained as a stable public API.

  • Field Details

    • _log

      protected final Log _log
      Class log, also used as the prefix for each runner's per-connection log.
    • __runnerId

      private static final AtomicLong __runnerId
      Sequence number of the created runners.
    • _runnerId

      private final long _runnerId
      This runner's position in that sequence.
    • MAX_PACKET_SIZE

      private static final int MAX_PACKET_SIZE
      Max bytes streamed in a packet - smaller packets might be filled up to this size.
      See Also:
    • NETWORK_BUFFER_SIZE

      private static final int NETWORK_BUFFER_SIZE
      Socket buffer size, in bytes.
      See Also:
    • s

      private final Socket s
      The clear side socket to the outproxy.
    • i2ps

      private final Socket i2ps
      The I2P side socket to the client.
    • slock

      private final Object slock
      Lock for closing the sockets.
    • finishLatch

      private final CountDownLatch finishLatch
      Latch signalling both directions have finished.
    • initialI2PData

      private final byte[] initialI2PData
      Data already read from the I2P side.
    • initialSocketData

      private final byte[] initialSocketData
      Data already read from the clear side.
    • startedOn

      private final long startedOn
      When the runner started up.
    • onTimeout

      private final I2PTunnelRunner.FailCallback onTimeout
      Thread that forwards data between local socket and I2PSocket.

      Stripped-down version of I2PTunnelRunner without SSL or read timeout support. Intended for outproxy use only. Not maintained as stable public API.

    • totalSent

      private final AtomicLong totalSent
      Bytes sent to the outproxy, counted across the copy threads.
    • totalReceived

      private final AtomicLong totalReceived
      Bytes received from the outproxy.
  • Constructor Details

    • I2PTunnelOutproxyRunner

      public I2PTunnelOutproxyRunner(Socket s, Socket i2ps, Object slock, byte[] initialI2PData, byte[] initialSocketData, I2PTunnelRunner.FailCallback onTimeout)
      Create a runner that forwards between one external socket and one tunnel.

      Does not start itself. Caller must call start().

      Parameters:
      s - external socket connection
      i2ps - I2P socket connection
      slock - socket lock object, non-null
      initialI2PData - initial data to send to I2P side, nullable
      initialSocketData - initial data to send to socket side, nullable
      onTimeout - fail callback if no data received (except initial), nullable
  • Method Details

    • getStartedOn

      public long getStartedOn()
      Get when this runner started transferring data.
      Returns:
      timestamp in ms
    • getSocketIn

      protected InputStream getSocketIn() throws IOException
      Get the input stream from the external socket.
      Returns:
      the socket's input stream
      Throws:
      IOException - if an I/O error occurs
    • getSocketOut

      protected OutputStream getSocketOut() throws IOException
      Get the output stream from the external socket.
      Returns:
      the socket's output stream
      Throws:
      IOException - if an I/O error occurs
    • run

      public void run()
      Start forwarding data bidirectionally between the external socket and the I2P socket. Sends any initial data first, then starts two forwarding threads and waits for both to complete. Invokes the timeout callback if no data was received.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class I2PThread
    • errorOccurred

      public void errorOccurred()
      Called to signal an error occurred and notify waiting threads.