java.lang.Object
net.i2p.i2ptunnel.I2PTunnelRunner.StreamForwarder
All Implemented Interfaces:
Runnable
Enclosing class:
I2PTunnelRunner

private class I2PTunnelRunner.StreamForwarderextends Object implements Runnable
Forward data in one direction between two streams. Reads from the input stream and writes to the output stream until the stream is closed or an error occurs.
  • Field Details

    • in

      private final InputStream in
      Stream the bytes are read from.
    • out

      private final OutputStream out
      Stream the bytes are written to.
    • direction

      private final String direction
      Direction label for the logs.
    • _toI2P

      private final boolean _toI2P
      True when copying toward I2P.
    • _cache

      private final ByteCache _cache
      Pooled buffer used for the copies.
    • _callback

      private final I2PTunnelRunner.SuccessCallback _callback
      Run when the stream ends normally.
    • _failure

      private volatile Exception _failure
      Exception that ended the forward, null until then.
    • done

      public volatile boolean done
      Flag to signal this forwarder should stop.
    • _stallArmed

      private boolean _stallArmed
      True once the stall read-timeout has been armed on the I2P socket.
  • Constructor Details

    • StreamForwarder

      public StreamForwarder(InputStream in, OutputStream out, boolean toI2P, I2PTunnelRunner.SuccessCallback cb)
      Forwards data between a local socket and the tunnel.
      Parameters:
      in - the stream to read bytes from
      out - the stream to write bytes to
      toI2P - true when forwarding from the local socket to the I2P stream
      cb - may be null, only used for toI2P == false
  • Method Details

    • run

      public void run()
      Pumps bytes between one socket and the I2P stream until either side closes.
      Specified by:
      run in interface Runnable
    • getFailure

      public Exception getFailure()
      The exception that ended the forward, if any.
      Returns:
      the exception that ended this direction, or null if it ran to completion