public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runnable
Manages I2PSocketManager creation, local server socket setup, connection threading, and framework for shared and non-shared client tunnels. Handles SSL configuration, connection timeouts, and provides abstract methods for connection-specific implementations.
Extended by specific tunnel types like HTTP clients, SOCKS proxies, and standard TCP tunnels.
| Modifier and Type | Field and Description |
|---|---|
protected long | _clientIdThis client's ID |
protected I2PAppContext | _contextThe application context |
protected ThreadPoolExecutor | _executorThread pool executor |
protected Log | _logThe logger |
protected boolean | _ownDestWhether we own our destination |
(package private) static long | DEFAULT_CONNECT_TIMEOUTDefault connect timeout |
protected Destination | destThe destination |
protected Logging | lThe logging instance |
protected boolean | listenerReadyProtected for I2Ping since 0.9.11. |
protected List<I2PSocket> | mySocketsList of active sockets |
static String | PROP_USE_SSLProperty for SSL enable |
protected Object | sockLockGuards sockMgr and mySockets |
protected I2PSocketManager | sockMgrThe socket manager |
protected ServerSocket | ssServer socket |
open, tunnel| Constructor and Description |
|---|
I2PTunnelClientBase(int localPort,
boolean ownDest,
Logging l,
EventDispatcher notifyThis,
String handlerName,
I2PTunnel tunnel)The main constructor. |
I2PTunnelClientBase(int localPort,
boolean ownDest,
Logging l,
EventDispatcher notifyThis,
String handlerName,
I2PTunnel tunnel,
String pkf)Use this to build a client with a persistent private key. |
I2PTunnelClientBase(int localPort,
Logging l,
I2PSocketManager sktMgr,
I2PTunnel tunnel,
EventDispatcher notifyThis,
long clientId)This constructor is used to add a client to an existing socket manager. |
| Modifier and Type | Method and Description |
|---|---|
protected I2PSocketManager | buildSocketManager()For NON-SHARED clients (ownDest = true). |
protected static I2PSocketManager | buildSocketManager(I2PTunnel tunnel)As of 0.9.20 this is fast, and does NOT connect the manager to the router. |
protected static I2PSocketManager | buildSocketManager(I2PTunnel tunnel,
String pkf)As of 0.9.20 this is fast, and does NOT connect the manager to the router. |
protected static I2PSocketManager | buildSocketManager(I2PTunnel tunnel,
String pkf,
Logging log)As of 0.9.20 this is fast, and does NOT connect the manager to the router. |
protected abstract void | clientConnectionRun(Socket s)Manage a connection in a separate thread. |
boolean | close(boolean forced)Note that the tunnel can be reopened after this by calling startRunning(). |
static void | closeSocket(Socket s)Close a socket silently. |
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. |
I2PSocket | createI2PSocket(Destination dest,
int port)Create a new I2PSocket towards to the specified destination,
adding it to the list of connections actually managed by this
tunnel. |
boolean | destroy()Note that the tunnel cannot be reopened after this by calling startRunning(),
as it will destroy the underlying socket manager. |
protected I2PSocketOptions | getDefaultOptions()Create the default options (using the default timeout, etc). |
protected I2PSocketOptions | getDefaultOptions(Properties overrides)Create the default options (using the default timeout, etc). |
protected InetAddress | getListenHost(Logging l)Get the listen host address. |
int | getLocalPort()Get the local port. |
I2PSocketManager | getSocketManager()Returns the I2PSocketManager for this task. |
protected static I2PSocketManager | getSocketManager(I2PTunnel tunnel)This is ONLY for shared clients. |
protected static I2PSocketManager | getSocketManager(I2PTunnel tunnel,
String pkf)This is ONLY for shared clients. |
protected static void | killSharedClient()Kill the shared client, so that on restart in android
we won't latch onto the old one |
protected void | manageConnection(Socket s)Manage the connection just opened on the specified socket |
void | optionsUpdated(I2PTunnel tunnel)Update the I2PSocketManager. |
void | run()Non-final since 0.9.11. |
void | startRunning()Actually open the local socket and start working on incoming connections. |
protected void | verifySocketManager()Create the manager if it doesn't exist, AND connect it to the router and build tunnels. |
connected, disconnected, errorOccurred, getBooleanOption, getId, getTunnel, isOpen, reportAbuse, routerDisconnected, setId, setName, setTunnel, toStringattachEventDispatcher, detachEventDispatcher, getEventDispatcher, getEvents, getEventValue, ignoreEvents, notifyEvent, unIgnoreEvents, waitEventValueprotected long _clientId
protected final I2PAppContext _context
protected volatile ThreadPoolExecutor _executor
protected final Log _log
protected boolean _ownDest
static final long DEFAULT_CONNECT_TIMEOUT
protected Destination dest
protected final Logging l
protected boolean listenerReady
public static final String PROP_USE_SSL
protected final Object sockLock
protected I2PSocketManager sockMgr
protected ServerSocket ss
public I2PTunnelClientBase(int localPort,
boolean ownDest,
Logging l,
EventDispatcher notifyThis,
String handlerName,
I2PTunnel tunnel)
throws IllegalArgumentExceptionAs of 0.9.21 this is fast, and does NOT connect the manager to the router, or open the local socket. You MUST call startRunning() for that.
(0.9.20 claimed to be fast, but due to a bug it DID connect the manager to the router. It did NOT open the local socket however, so it was still necessary to call startRunning() for that.)
localPort - if 0, use any port, get actual port selected with getLocalPort()ownDest - whether to use an owned destinationl - the logging instancenotifyThis - the event dispatcher for notificationshandlerName - the handler nametunnel - the I2PTunnel instanceIllegalArgumentException - if the I2CP configuration is b0rked so
badly that we can't create a socketManagerpublic I2PTunnelClientBase(int localPort,
boolean ownDest,
Logging l,
EventDispatcher notifyThis,
String handlerName,
I2PTunnel tunnel,
String pkf)
throws IllegalArgumentExceptionAs of 0.9.21 this is fast, and does NOT connect the manager to the router, or open the local socket. You MUST call startRunning() for that.
(0.9.20 claimed to be fast, but due to a bug it DID connect the manager to the router. It did NOT open the local socket however, so it was still necessary to call startRunning() for that.)
localPort - if 0, use any port, get actual port selected with getLocalPort()ownDest - whether to use an owned destinationl - the logging instancenotifyThis - the event dispatcher for notificationshandlerName - the handler nametunnel - the I2PTunnel instancepkf - Path to the private key file, or null to generate a transient keyIllegalArgumentException - if the I2CP configuration is b0rked so
badly that we can't create a socketManagerpublic I2PTunnelClientBase(int localPort,
Logging l,
I2PSocketManager sktMgr,
I2PTunnel tunnel,
EventDispatcher notifyThis,
long clientId)
throws IllegalArgumentExceptionAs of 0.9.21 this does NOT open the local socket. You MUST call
startRunning() for that. The local socket will be opened
immediately (ignoring the i2cp.delayOpen option).
localPort - if 0, use any port, get actual port selected with getLocalPort()l - the logging instancesktMgr - the existing socket managertunnel - the I2PTunnel instancenotifyThis - the event dispatcher for notificationsclientId - the client identifierIllegalArgumentExceptionprotected I2PSocketManager buildSocketManager()
IllegalArgumentException - if the I2CP configuration is b0rked so
badly that we cant create a socketManagerprotected static I2PSocketManager buildSocketManager(I2PTunnel tunnel)
tunnel - the I2PTunnel instanceIllegalArgumentException - if the I2CP configuration is b0rked so
badly that we cant create a socketManagerprotected static I2PSocketManager buildSocketManager(I2PTunnel tunnel, String pkf)
tunnel - the I2PTunnel instancepkf - absolute path or nullIllegalArgumentException - if the I2CP configuration is b0rked so
badly that we cant create a socketManagerprotected static I2PSocketManager buildSocketManager(I2PTunnel tunnel, String pkf, Logging log)
tunnel - the I2PTunnel instancepkf - absolute path or nulllog - the logging instanceIllegalArgumentException - if the I2CP configuration is b0rked so
badly that we cant create a socketManagerprotected abstract void clientConnectionRun(Socket s)
s - the socket to managepublic boolean close(boolean forced)
close in class I2PTunnelTaskpublic static void closeSocket(Socket s)
s - the socket to closepublic I2PSocket createI2PSocket(Destination dest) throws I2PException, ConnectException, NoRouteToHostException, InterruptedIOException
dest - The destination to connect to, non-nullI2PException - if there is an I2P-related problemConnectException - if the peer refuses the connectionNoRouteToHostException - if the peer is not found or not reachableInterruptedIOException - if the connection times outpublic I2PSocket createI2PSocket(Destination dest, I2PSocketOptions opt) throws I2PException, ConnectException, NoRouteToHostException, InterruptedIOException
dest - The destination to connect to, non-nullopt - Option to be used to open when opening the socketConnectException - if the peer refuses the connectionNoRouteToHostException - if the peer is not found or not reachableInterruptedIOException - if the connection timeoutsI2PException - if there is some other I2P-related problempublic I2PSocket createI2PSocket(Destination dest, int port) throws I2PException, ConnectException, NoRouteToHostException, InterruptedIOException
dest - The destination to connect to, non-nullport - The destination port to connect to 0 - 65535I2PException - if there is an I2P-related problemConnectException - if the peer refuses the connectionNoRouteToHostException - if the peer is not found or not reachableInterruptedIOException - if the connection times outpublic boolean destroy()
destroy in class I2PTunnelTaskprotected I2PSocketOptions getDefaultOptions()
protected I2PSocketOptions getDefaultOptions(Properties overrides)
overrides - the properties to overrideprotected final InetAddress getListenHost(Logging l)
l - the logging instancepublic final int getLocalPort()
public I2PSocketManager getSocketManager()
getSocketManager in class I2PTunnelTaskprotected static I2PSocketManager getSocketManager(I2PTunnel tunnel)
tunnel - the I2PTunnel instanceIllegalArgumentException - if the I2CP configuration is b0rked so
badly that we cant create a socketManagerprotected static I2PSocketManager getSocketManager(I2PTunnel tunnel, String pkf)
tunnel - the I2PTunnel instancepkf - the private key file path, or nullIllegalArgumentException - if the I2CP configuration is b0rked so
badly that we cant create a socketManagerprotected static void killSharedClient()
protected void manageConnection(Socket s)
s - Socket to take care ofpublic void optionsUpdated(I2PTunnel tunnel)
optionsUpdated in class I2PTunnelTaskpublic void run()
public void startRunning()
protected void verifySocketManager()
IllegalArgumentException - if the I2CP configuration is b0rked so
badly that we cant create a socketManager