java.lang.Object
net.i2p.sam.SAMv3StreamSession.Pipe
- Enclosing class:
SAMv3StreamSession
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final SAMBridgeThe bridge that started the session.private final ByteBufferBuffer used for the copies.private final ReadableByteChannelChannel the data is read from.private longWhen data last flowed in either direction.private final StringNickname of the session, for the logs.private final WritableByteChannelChannel the data is written to.Constructor Summary
ConstructorsConstructorDescriptionPipe(ReadableByteChannel in, WritableByteChannel out, SAMBridge bridge) Create a pipe without session tracking.Pipe(ReadableByteChannel in, WritableByteChannel out, SAMBridge bridge, String nick) Create a pipe with session tracking.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidrun()Pump bytes between the I2P connection and the SAM client's socket until either side closes or the thread is interrupted.voidStop forwarding incoming I2P connections to the SAM client, and close the client-side socket.
Field Details
in
Channel the data is read from.out
Channel the data is written to.buf
Buffer used for the copies.bridge
The bridge that started the session.nick
Nickname of the session, for the logs.lastTouch
private long lastTouchWhen data last flowed in either direction.
Constructor Details
Pipe
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
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 nullnick- session nickname for database touch; may be null
Method Details
run
stopHandling
public void stopHandling()Stop forwarding incoming I2P connections to the SAM client, and close the client-side socket.- Specified by:
stopHandlingin interfaceHandler