net.i2p.i2ptunnel
Class I2PTunnelClientBase

java.lang.Object
  extended by net.i2p.i2ptunnel.I2PTunnelTask
      extended by net.i2p.i2ptunnel.I2PTunnelClientBase
All Implemented Interfaces:
java.lang.Runnable, EventDispatcher
Direct Known Subclasses:
I2PSOCKSTunnel, I2PTunnelClient, I2PTunnelConnectClient, I2PTunnelHTTPClient, I2PTunnelIRCClient

public abstract class I2PTunnelClientBase
extends I2PTunnelTask
implements java.lang.Runnable


Field Summary
protected  long _clientId
           
protected  I2PAppContext _context
           
protected  boolean _ownDest
           
protected  java.util.List _waitingSockets
          List of Socket for those accept()ed but not yet started up
(package private) static long DEFAULT_CONNECT_TIMEOUT
           
protected  Destination dest
           
protected  Logging l
           
protected  java.util.List mySockets
           
static java.lang.String PROP_MAX_WAIT_TIME
          How long will we let a socket wait after being accept()ed without getting pumped through a connection builder (in milliseconds).
static java.lang.String PROP_NUM_CONNECTION_BUILDERS
          How many concurrent connections this I2PTunnel instance will allow to be in the process of connecting (or if less than 1, there is no limit)?
protected  java.lang.Object sockLock
           
protected  I2PSocketManager sockMgr
           
 
Fields inherited from class net.i2p.i2ptunnel.I2PTunnelTask
open
 
Constructor Summary
I2PTunnelClientBase(int localPort, boolean ownDest, Logging l, EventDispatcher notifyThis, java.lang.String handlerName, I2PTunnel tunnel)
           
I2PTunnelClientBase(int localPort, boolean ownDest, Logging l, EventDispatcher notifyThis, java.lang.String handlerName, I2PTunnel tunnel, java.lang.String pkf)
           
I2PTunnelClientBase(int localPort, Logging l, I2PSocketManager sktMgr, I2PTunnel tunnel, EventDispatcher notifyThis, long clientId)
           
 
Method Summary
protected  I2PSocketManager buildSocketManager()
           
protected static I2PSocketManager buildSocketManager(I2PTunnel tunnel)
           
protected static I2PSocketManager buildSocketManager(I2PTunnel tunnel, java.lang.String pkf)
           
protected abstract  void clientConnectionRun(java.net.Socket s)
          Manage a connection in a separate thread.
 boolean close(boolean forced)
           
static void closeSocket(java.net.Socket s)
           
 I2PSocket createI2PSocket(Destination dest)
          Create a new I2PSocket towards to the specified destination, adding it to the list of connections actually managed by this tunnel.
 I2PSocket createI2PSocket(Destination dest, I2PSocketOptions opt)
          Create a new I2PSocket towards to the specified destination, adding it to the list of connections actually managed by this tunnel.
protected  I2PSocketOptions getDefaultOptions()
          create the default options (using the default timeout, etc)
protected  I2PSocketOptions getDefaultOptions(java.util.Properties overrides)
          create the default options (using the default timeout, etc)
protected  java.net.InetAddress getListenHost(Logging l)
           
 int getLocalPort()
           
protected  I2PSocketManager getSocketManager()
          this is ONLY for shared clients
protected static I2PSocketManager getSocketManager(I2PTunnel tunnel)
          this is ONLY for shared clients
protected static I2PSocketManager getSocketManager(I2PTunnel tunnel, java.lang.String pkf)
          this is ONLY for shared clients
protected  void manageConnection(java.net.Socket s)
          Manage the connection just opened on the specified socket
 void run()
           
 void startRunning()
          Actually start working on incoming connections.
protected  void verifySocketManager()
          Sets the this.sockMgr field if it is null, or if we want a new one We need a socket manager before getDefaultOptions() and most other things
 
Methods inherited from class net.i2p.i2ptunnel.I2PTunnelTask
attachEventDispatcher, detachEventDispatcher, disconnected, errorOccurred, getEventDispatcher, getEvents, getEventValue, getId, getTunnel, ignoreEvents, isOpen, notifyEvent, reportAbuse, routerDisconnected, setId, setName, setTunnel, toString, unIgnoreEvents, waitEventValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_context

protected I2PAppContext _context

l

protected Logging l

DEFAULT_CONNECT_TIMEOUT

static final long DEFAULT_CONNECT_TIMEOUT
See Also:
Constant Field Values

_clientId

protected long _clientId

sockLock

protected final java.lang.Object sockLock

sockMgr

protected I2PSocketManager sockMgr

mySockets

protected java.util.List mySockets

_ownDest

protected boolean _ownDest

dest

protected Destination dest

_waitingSockets

protected final java.util.List _waitingSockets
List of Socket for those accept()ed but not yet started up


PROP_NUM_CONNECTION_BUILDERS

public static final java.lang.String PROP_NUM_CONNECTION_BUILDERS
How many concurrent connections this I2PTunnel instance will allow to be in the process of connecting (or if less than 1, there is no limit)?

See Also:
Constant Field Values

PROP_MAX_WAIT_TIME

public static final java.lang.String PROP_MAX_WAIT_TIME
How long will we let a socket wait after being accept()ed without getting pumped through a connection builder (in milliseconds). If this time is reached, the socket is unceremoniously closed and discarded. If the max wait time is less than 1, there is no limit.

See Also:
Constant Field Values
Constructor Detail

I2PTunnelClientBase

public I2PTunnelClientBase(int localPort,
                           Logging l,
                           I2PSocketManager sktMgr,
                           I2PTunnel tunnel,
                           EventDispatcher notifyThis,
                           long clientId)
                    throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

I2PTunnelClientBase

public I2PTunnelClientBase(int localPort,
                           boolean ownDest,
                           Logging l,
                           EventDispatcher notifyThis,
                           java.lang.String handlerName,
                           I2PTunnel tunnel)
                    throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

I2PTunnelClientBase

public I2PTunnelClientBase(int localPort,
                           boolean ownDest,
                           Logging l,
                           EventDispatcher notifyThis,
                           java.lang.String handlerName,
                           I2PTunnel tunnel,
                           java.lang.String pkf)
                    throws java.lang.IllegalArgumentException
Parameters:
pkf - null to generate a transient key
Throws:
java.lang.IllegalArgumentException - if the I2CP configuration is b0rked so badly that we cant create a socketManager
Method Detail

verifySocketManager

protected void verifySocketManager()
Sets the this.sockMgr field if it is null, or if we want a new one We need a socket manager before getDefaultOptions() and most other things


getSocketManager

protected I2PSocketManager getSocketManager()
this is ONLY for shared clients


getSocketManager

protected static I2PSocketManager getSocketManager(I2PTunnel tunnel)
this is ONLY for shared clients


getSocketManager

protected static I2PSocketManager getSocketManager(I2PTunnel tunnel,
                                                   java.lang.String pkf)
this is ONLY for shared clients


buildSocketManager

protected I2PSocketManager buildSocketManager()

buildSocketManager

protected static I2PSocketManager buildSocketManager(I2PTunnel tunnel)

buildSocketManager

protected static I2PSocketManager buildSocketManager(I2PTunnel tunnel,
                                                     java.lang.String pkf)
Parameters:
pkf - absolute path or null

getLocalPort

public final int getLocalPort()

getListenHost

protected final java.net.InetAddress getListenHost(Logging l)

startRunning

public void startRunning()
Actually start working on incoming connections. *Must* be called by derived classes after initialization.


getDefaultOptions

protected I2PSocketOptions getDefaultOptions()
create the default options (using the default timeout, etc)


getDefaultOptions

protected I2PSocketOptions getDefaultOptions(java.util.Properties overrides)
create the default options (using the default timeout, etc)


createI2PSocket

public I2PSocket createI2PSocket(Destination dest)
                          throws I2PException,
                                 java.net.ConnectException,
                                 java.net.NoRouteToHostException,
                                 java.io.InterruptedIOException
Create a new I2PSocket towards to the specified destination, adding it to the list of connections actually managed by this tunnel.

Parameters:
dest - The destination to connect to
Returns:
a new I2PSocket
Throws:
I2PException
java.net.ConnectException
java.net.NoRouteToHostException
java.io.InterruptedIOException

createI2PSocket

public I2PSocket createI2PSocket(Destination dest,
                                 I2PSocketOptions opt)
                          throws I2PException,
                                 java.net.ConnectException,
                                 java.net.NoRouteToHostException,
                                 java.io.InterruptedIOException
Create a new I2PSocket towards to the specified destination, adding it to the list of connections actually managed by this tunnel.

Parameters:
dest - The destination to connect to
opt - Option to be used to open when opening the socket
Returns:
a new I2PSocket
Throws:
java.net.ConnectException - if the peer refuses the connection
java.net.NoRouteToHostException - if the peer is not found or not reachable
java.io.InterruptedIOException - if the connection timeouts
I2PException - if there is some other I2P-related problem

run

public final void run()
Specified by:
run in interface java.lang.Runnable

manageConnection

protected void manageConnection(java.net.Socket s)
Manage the connection just opened on the specified socket

Parameters:
s - Socket to take care of

close

public boolean close(boolean forced)
Specified by:
close in class I2PTunnelTask

closeSocket

public static void closeSocket(java.net.Socket s)

clientConnectionRun

protected abstract void clientConnectionRun(java.net.Socket s)
Manage a connection in a separate thread. This only works if you do not override manageConnection()