Package net.i2p.i2ptunnel
Class I2PTunnelRunner
- java.lang.Object
-
- java.lang.Thread
-
- net.i2p.util.I2PThread
-
- net.i2p.util.I2PAppThread
-
- net.i2p.i2ptunnel.I2PTunnelRunner
-
- All Implemented Interfaces:
Runnable
,I2PSocket.SocketErrorListener
,LimitOutputStream.DoneCallback
- Direct Known Subclasses:
I2PTunnelHTTPClientRunner
public class I2PTunnelRunner extends I2PAppThread implements I2PSocket.SocketErrorListener, LimitOutputStream.DoneCallback
A thread that starts one more thread if keepAliveSocket is false, to forward traffic in each direction. When keepAliveSocket is true, we do not expect additional data and do not need a forwarding thread from the socket to I2P. Warning - not maintained as a stable API for external use.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
I2PTunnelRunner.FailCallback
For use in new constructorstatic interface
I2PTunnelRunner.SuccessCallback
-
Nested classes/interfaces inherited from class net.i2p.util.I2PThread
I2PThread.OOMEventListener
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
_keepAliveI2P
protected boolean
_keepAliveSocket
protected Log
_log
(package private) static int
MAX_PACKET_SIZE
max bytes streamed in a packet - smaller ones might be filled up to this size.(package private) static int
NETWORK_BUFFER_SIZE
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, byte[] initialSocketData, List<I2PSocket> sockList)
Deprecated.use FailCallback constructorI2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, byte[] initialSocketData, List<I2PSocket> sockList, Runnable onTimeout)
Deprecated.use FailCallback constructorI2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, byte[] initialSocketData, List<I2PSocket> sockList, I2PTunnelRunner.FailCallback onFail)
Recommended new constructor.I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, byte[] initialSocketData, List<I2PSocket> sockList, I2PTunnelRunner.FailCallback onFail, boolean keepAliveI2P, boolean keepAliveSocket)
With keepAlive args.I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, List<I2PSocket> sockList)
Deprecated.use FailCallback constructorI2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, List<I2PSocket> sockList, Runnable onTimeout)
Deprecated.use FailCallback constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
close(OutputStream out, InputStream in, OutputStream i2pout, InputStream i2pin, Socket s, I2PSocket i2ps, Thread t1, Thread t2)
Warning - overridden in I2PTunnelHTTPClientRunner.void
errorOccurred()
Deprecated.unused(package private) boolean
getKeepAliveI2P()
Should we keep the I2P socket open when done? On the client side, only true if the browser and the server side support it.(package private) boolean
getKeepAliveSocket()
Should we keep the local browser/server socket open when done? Usually true for client side.long
getLastActivityOn()
Deprecated.unusedprotected InputStream
getSocketIn()
protected OutputStream
getSocketOut()
long
getStartedOn()
When this runner started up transferring databoolean
isFinished()
Deprecated.unusedvoid
run()
void
setSuccessCallback(I2PTunnelRunner.SuccessCallback sc)
Will be called if we get any data back.void
streamDone()
The DoneCallback for the I2P socket.-
Methods inherited from class net.i2p.util.I2PAppThread
addOOMEventThreadListener, fireOOM, removeOOMEventThreadListener
-
Methods inherited from class net.i2p.util.I2PThread
addOOMEventListener, removeOOMEventListener, start
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
_log
protected final Log _log
-
MAX_PACKET_SIZE
static int MAX_PACKET_SIZE
max bytes streamed in a packet - smaller ones might be filled up to this size. Larger ones are not split (at least not on Sun's impl of BufferedOutputStream), but that is the streaming api's job...
-
NETWORK_BUFFER_SIZE
static final int NETWORK_BUFFER_SIZE
-
_keepAliveI2P
protected volatile boolean _keepAliveI2P
-
_keepAliveSocket
protected volatile boolean _keepAliveSocket
-
-
Constructor Detail
-
I2PTunnelRunner
@Deprecated public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, List<I2PSocket> sockList)
Deprecated.use FailCallback constructorStarts itself- Parameters:
slock
- the socket lock, non-nullinitialI2PData
- may be nullsockList
- may be null. Caller must add i2ps to the list! It will be removed here on completion. Will synchronize on slock when removing.
-
I2PTunnelRunner
@Deprecated public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, byte[] initialSocketData, List<I2PSocket> sockList)
Deprecated.use FailCallback constructorStarts itself- Parameters:
slock
- the socket lock, non-nullinitialI2PData
- may be nullinitialSocketData
- may be nullsockList
- may be null. Caller must add i2ps to the list! It will be removed here on completion. Will synchronize on slock when removing.
-
I2PTunnelRunner
@Deprecated public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, List<I2PSocket> sockList, Runnable onTimeout)
Deprecated.use FailCallback constructorStarts itself- Parameters:
slock
- the socket lock, non-nullinitialI2PData
- may be nullsockList
- may be null. Caller must add i2ps to the list! It will be removed here on completion. Will synchronize on slock when removing.onTimeout
- May be null. If non-null and no data (except initial data) was received, it will be run before closing s.
-
I2PTunnelRunner
@Deprecated public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, byte[] initialSocketData, List<I2PSocket> sockList, Runnable onTimeout)
Deprecated.use FailCallback constructorStarts itself- Parameters:
slock
- the socket lock, non-nullinitialI2PData
- may be nullinitialSocketData
- may be nullsockList
- may be null. Caller must add i2ps to the list! It will be removed here on completion. Will synchronize on slock when removing.onTimeout
- May be null. If non-null and no data (except initial data) was received, it will be run before closing s.
-
I2PTunnelRunner
public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, byte[] initialSocketData, List<I2PSocket> sockList, I2PTunnelRunner.FailCallback onFail)
Recommended new constructor. Does NOT start itself. Caller must call start().- Parameters:
slock
- the socket lock, non-nullinitialI2PData
- may be nullinitialSocketData
- may be nullsockList
- may be null. Caller must add i2ps to the list! It will be removed here on completion. Will synchronize on slock when removing.onFail
- May be null. If non-null and no data (except initial data) was received, it will be run before closing s.
-
I2PTunnelRunner
public I2PTunnelRunner(Socket s, I2PSocket i2ps, Object slock, byte[] initialI2PData, byte[] initialSocketData, List<I2PSocket> sockList, I2PTunnelRunner.FailCallback onFail, boolean keepAliveI2P, boolean keepAliveSocket)
With keepAlive args. Does NOT start itself. Caller must call start().- Parameters:
slock
- the socket lock, non-nullinitialI2PData
- may be nullinitialSocketData
- may be nullsockList
- may be null. Caller must add i2ps to the list! It will be removed here on completion. Will synchronize on slock when removing.onFail
- May be null. If non-null and no data (except initial data) was received, it will be run before closing s.keepAliveI2P
- Do not close the I2P socket when done.keepAliveSocket
- Do not close the local socket when done. For client side only; must be false for server side. NO data will be forwarded from the socket to the i2psocket other than initialI2PData if this is true.- Since:
- 0.9.62
-
-
Method Detail
-
isFinished
@Deprecated public boolean isFinished()
Deprecated.unusedhave we closed at least one (if not both) of the streams [aka we're done running the streams]?
-
getLastActivityOn
@Deprecated public long getLastActivityOn()
Deprecated.unusedWhen was the last data for this runner sent or received? As of 0.9.20, returns -1 always!- Returns:
- date (ms since the epoch), or -1 if no data has been transferred yet
-
getStartedOn
public long getStartedOn()
When this runner started up transferring data
-
setSuccessCallback
public void setSuccessCallback(I2PTunnelRunner.SuccessCallback sc)
Will be called if we get any data back. This is called after the first byte of data is received, not on completion. Only one of SuccessCallback, onTimeout, or onFail will be called.- Since:
- 0.9.39
-
getSocketIn
protected InputStream getSocketIn() throws IOException
- Throws:
IOException
-
getSocketOut
protected OutputStream getSocketOut() throws IOException
- Throws:
IOException
-
getKeepAliveI2P
boolean getKeepAliveI2P()
Should we keep the I2P socket open when done? On the client side, only true if the browser and the server side support it. On the server side, only true if the client supports it.- Since:
- 0.9.62
-
getKeepAliveSocket
boolean getKeepAliveSocket()
Should we keep the local browser/server socket open when done? Usually true for client side. Always false for server side.- Since:
- 0.9.62
-
streamDone
public void streamDone()
The DoneCallback for the I2P socket.- Specified by:
streamDone
in interfaceLimitOutputStream.DoneCallback
- Since:
- 0.9.62
-
close
protected void close(OutputStream out, InputStream in, OutputStream i2pout, InputStream i2pin, Socket s, I2PSocket i2ps, Thread t1, Thread t2) throws InterruptedException
Warning - overridden in I2PTunnelHTTPClientRunner. Here we ignore keepalive and always close both sides. The HTTP flavor handles keepalive.- Parameters:
out
- may be nullin
- may be nulli2pout
- may be nulli2pin
- may be nullt1
- may be nullt2
- may be null, ignored, we only join t1- Throws:
InterruptedException
-
errorOccurred
@Deprecated public void errorOccurred()
Deprecated.unusedDeprecated, unimplemented in streaming, never called.- Specified by:
errorOccurred
in interfaceI2PSocket.SocketErrorListener
-
-