java.lang.Object
net.i2p.sam.SAMv3StreamSession.Pipe
All Implemented Interfaces:
Runnable, Handler
Enclosing class:
SAMv3StreamSession

private static class SAMv3StreamSession.Pipeextends Object implements Runnable, Handler
Bidirectional byte copier between a local socket and an I2P socket. Created by CONNECT and FORWARDDIRECT handlers to shuttle data between the SAM client's TCP connection and the I2P network.

Instances are registered as handlers in SessionsDB so that the client's worker thread can return immediately and data transfer continues on the NIO thread pool. The handler's run() method copies available data on each NIO select tick.

When either side reaches end-of-stream, Handler.stopHandling() is called to tear down both channels and remove this handler from the sessions database. Idle timeout is checked periodically in handle() and forces a close if no data flows for IDLE_TIMEOUT_SECS seconds.

  • Field Details

    • in

      private final ReadableByteChannel in
      Channel the data is read from.
    • out

      private final WritableByteChannel out
      Channel the data is written to.
    • buf

      private final ByteBuffer buf
      Buffer used for the copies.
    • bridge

      private final SAMBridge bridge
      The bridge that started the session.
    • nick

      private final String nick
      Nickname of the session, for the logs.
    • lastTouch

      private long lastTouch
      When data last flowed in either direction.
  • Constructor Details

    • Pipe

      public Pipe(ReadableByteChannel in, WritableByteChannel out, SAMBridge bridge)
      Create a pipe without session tracking. Used for short-lived forwarding (e.g., host-anonymous).
      Parameters:
      in - source channel (local socket input)
      out - destination channel (I2P socket output)
      bridge - the SAM bridge for idle timeout; may be null
    • Pipe

      public Pipe(ReadableByteChannel in, WritableByteChannel out, SAMBridge bridge, String nick)
      Create a pipe with session tracking. Touches the sessions database periodically so the idle scanner does not reclaim this session while data is flowing.
      Parameters:
      in - source channel (local socket input)
      out - destination channel (I2P socket output)
      bridge - the SAM bridge for idle timeout; may be null
      nick - session nickname for database touch; may be null
  • Method Details

    • run

      public void run()
      Pump bytes between the I2P connection and the SAM client's socket until either side closes or the thread is interrupted.
      Specified by:
      run in interface Runnable
    • stopHandling

      public void stopHandling()
      Stop forwarding incoming I2P connections to the SAM client, and close the client-side socket.
      Specified by:
      stopHandling in interface Handler