net.i2p.i2ptunnel
Class I2PTunnelServer

java.lang.Object
  extended by net.i2p.util.EventDispatcherImpl
      extended by net.i2p.i2ptunnel.I2PTunnelTask
          extended by net.i2p.i2ptunnel.I2PTunnelServer
All Implemented Interfaces:
Runnable, EventDispatcher
Direct Known Subclasses:
I2PTunnelDCCServer, I2PTunnelHTTPServer, I2PTunnelIRCServer

public class I2PTunnelServer
extends I2PTunnelTask
implements Runnable


Field Summary
protected static long __serverId
          apparently unused
protected  ThreadPoolExecutor _clientExecutor
           
protected  Log _log
           
protected  boolean bidir
           
protected  I2PServerSocket i2pss
           
protected  Logging l
           
protected  int localPort
           
static String PROP_UNIQUE_LOCAL
           
static String PROP_USE_SSL
           
protected  long readTimeout
          default timeout to 5 minutes - override if desired
protected  InetAddress remoteHost
           
protected  int remotePort
           
protected  Object slock
           
protected  I2PSocketManager sockMgr
           
protected  Object sslLock
           
protected  I2PTunnelTask task
           
 
Fields inherited from class net.i2p.i2ptunnel.I2PTunnelTask
open
 
Constructor Summary
I2PTunnelServer(InetAddress host, int port, File privkey, String privkeyname, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)
          Non-blocking
I2PTunnelServer(InetAddress host, int port, I2PSocketManager sktMgr, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)
          Non-blocking
I2PTunnelServer(InetAddress host, int port, InputStream privData, String privkeyname, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)
          Non-blocking
I2PTunnelServer(InetAddress host, int port, String privData, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)
          Non-blocking
 
Method Summary
protected  void blockingHandle(I2PSocket socket)
          This is run in a thread from a limited-size thread pool via Handler.run(), except for a standard server (this class, no extension, as determined in getUsePool()), it is run directly in the acceptor thread (see run()).
 boolean close(boolean forced)
          Note that the tunnel can be reopened after this by calling startRunning().
 boolean destroy()
          Note that the tunnel cannot be reopened after this by calling startRunning(), as it will destroy the underlying socket manager.
protected  int getHandlerCount()
           
 long getReadTimeout()
          Get the read idle timeout for newly-created connections (in milliseconds).
protected  Socket getSocket(Hash from, InetAddress remoteHost, int remotePort)
          Get a regular or SSL socket depending on config.
protected  Socket getSocket(Hash from, int incomingPort)
          Get a regular or SSL socket depending on config and the incoming port.
 void optionsUpdated(I2PTunnel tunnel)
          Update the I2PSocketManager.
 void run()
          If usePool is set, this starts the executor pool.
 void setReadTimeout(long ms)
          Set the read idle timeout for newly-created connections (in milliseconds).
 boolean shouldUsePool()
           
 void startRunning()
          Start running the I2PTunnelServer.
 
Methods inherited from class net.i2p.i2ptunnel.I2PTunnelTask
connected, disconnected, errorOccurred, getId, getTunnel, isOpen, reportAbuse, routerDisconnected, setId, setName, setTunnel, toString
 
Methods inherited from class net.i2p.util.EventDispatcherImpl
attachEventDispatcher, detachEventDispatcher, getEventDispatcher, getEvents, getEventValue, ignoreEvents, notifyEvent, unIgnoreEvents, waitEventValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_log

protected final Log _log

sockMgr

protected final I2PSocketManager sockMgr

i2pss

protected volatile I2PServerSocket i2pss

slock

protected final Object slock

sslLock

protected final Object sslLock

remoteHost

protected InetAddress remoteHost

remotePort

protected int remotePort

l

protected final Logging l

readTimeout

protected long readTimeout
default timeout to 5 minutes - override if desired


PROP_USE_SSL

public static final String PROP_USE_SSL
See Also:
Constant Field Values

PROP_UNIQUE_LOCAL

public static final String PROP_UNIQUE_LOCAL
See Also:
Constant Field Values

__serverId

protected static volatile long __serverId
apparently unused


task

protected I2PTunnelTask task

bidir

protected boolean bidir

_clientExecutor

protected volatile ThreadPoolExecutor _clientExecutor

localPort

protected int localPort
Constructor Detail

I2PTunnelServer

public I2PTunnelServer(InetAddress host,
                       int port,
                       String privData,
                       Logging l,
                       EventDispatcher notifyThis,
                       I2PTunnel tunnel)
Non-blocking

Parameters:
privData - Base64-encoded private key data, format is specified in PrivateKeyFile
Throws:
IllegalArgumentException - if the I2CP configuration is b0rked so badly that we cant create a socketManager

I2PTunnelServer

public I2PTunnelServer(InetAddress host,
                       int port,
                       File privkey,
                       String privkeyname,
                       Logging l,
                       EventDispatcher notifyThis,
                       I2PTunnel tunnel)
Non-blocking

Parameters:
privkey - file containing the private key data, format is specified in PrivateKeyFile
privkeyname - the name of the privKey file, just for logging
Throws:
IllegalArgumentException - if the I2CP configuration is b0rked so badly that we cant create a socketManager

I2PTunnelServer

public I2PTunnelServer(InetAddress host,
                       int port,
                       InputStream privData,
                       String privkeyname,
                       Logging l,
                       EventDispatcher notifyThis,
                       I2PTunnel tunnel)
Non-blocking

Parameters:
privData - stream containing the private key data, format is specified in PrivateKeyFile
privkeyname - the name of the privKey file, just for logging
Throws:
IllegalArgumentException - if the I2CP configuration is b0rked so badly that we cant create a socketManager

I2PTunnelServer

public I2PTunnelServer(InetAddress host,
                       int port,
                       I2PSocketManager sktMgr,
                       Logging l,
                       EventDispatcher notifyThis,
                       I2PTunnel tunnel)
Non-blocking

Parameters:
sktMgr - the existing socket manager
Since:
0.8.9
Method Detail

startRunning

public void startRunning()
Start running the I2PTunnelServer. Warning, blocks while connecting to router and building tunnels;

Throws:
IllegalArgumentException - if the I2CP configuration is b0rked so badly that we cant create a socketManager

setReadTimeout

public void setReadTimeout(long ms)
Set the read idle timeout for newly-created connections (in milliseconds). After this time expires without data being reached from the I2P network, the connection itself will be closed.


getReadTimeout

public long getReadTimeout()
Get the read idle timeout for newly-created connections (in milliseconds).

Returns:
The read timeout used for connections

close

public boolean close(boolean forced)
Note that the tunnel can be reopened after this by calling startRunning(). This does not release all resources. In particular, the I2PSocketManager remains and it may have timer threads that continue running. To release all resources permanently, call destroy().

Specified by:
close in class I2PTunnelTask
Returns:
success

destroy

public boolean destroy()
Note that the tunnel cannot be reopened after this by calling startRunning(), as it will destroy the underlying socket manager. This releases all resources.

Overrides:
destroy in class I2PTunnelTask
Returns:
success
Since:
0.9.17

optionsUpdated

public void optionsUpdated(I2PTunnel tunnel)
Update the I2PSocketManager. And since 0.9.15, the target host and port.

Overrides:
optionsUpdated in class I2PTunnelTask
Since:
0.9.1

getHandlerCount

protected int getHandlerCount()

run

public void run()
If usePool is set, this starts the executor pool. Then, do the accept() loop, and either hands each I2P socket to the executor or runs it in-line.

Specified by:
run in interface Runnable

shouldUsePool

public boolean shouldUsePool()

blockingHandle

protected void blockingHandle(I2PSocket socket)
This is run in a thread from a limited-size thread pool via Handler.run(), except for a standard server (this class, no extension, as determined in getUsePool()), it is run directly in the acceptor thread (see run()). In either case, this method and any overrides must spawn a thread and return quickly. If blocking while reading the headers (as in HTTP and IRC), the thread pool may be exhausted. See PROP_USE_POOL, DEFAULT_USE_POOL, PROP_HANDLER_COUNT, DEFAULT_HANDLER_COUNT


getSocket

protected Socket getSocket(Hash from,
                           int incomingPort)
                    throws IOException
Get a regular or SSL socket depending on config and the incoming port. To configure a specific host:port as the server for incoming port xx, set option targetForPort.xx=host:port

Parameters:
from - may be used to construct local address since 0.9.13
Throws:
IOException
Since:
0.9.9

getSocket

protected Socket getSocket(Hash from,
                           InetAddress remoteHost,
                           int remotePort)
                    throws IOException
Get a regular or SSL socket depending on config. The SSL config applies to all hosts/ports.

Parameters:
from - may be used to construct local address since 0.9.13
Throws:
IOException
Since:
0.9.9