- All Implemented Interfaces:
Runnable, EventDispatcher
Listens on a local port and creates I2P connections to configured destinations when clients connect. Supports multiple destinations with random selection, configurable read timeouts, and port mapping for services like SMTP and POP.
Handles destination resolution, connection management, and data forwarding between local client socket and remote I2P destination.
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longIdle timeout in milliseconds for I2P socket reads on new connections.Fields inherited from class I2PTunnelClientBase
_clientId, _context, _executor, _log, _ownDest, DEFAULT_CONNECT_TIMEOUT, DEFAULT_MAX_CONNECTIONS, DEFAULT_SOCKET_OPEN_TIMEOUT, dest, l, listenerReady, MAX_TIMEOUT_FAILOVER, MIN_CONNECT_LEG_MS, mySockets, NO_DEADLINE, POOL_BUILD_DEADLINE_GRACE_MS, PROP_MAX_CONNECTIONS, PROP_USE_SSL, REQUEST_CONNECT_DEADLINE_MS, sockLock, sockMgr, ssModifier and TypeFieldDescriptionprotected longThis client's ID.protected final I2PAppContextThe application context.protected ThreadPoolExecutorThread pool executor.protected final LogThe logger.protected booleanWhether we own our destination.(package private) static final longDefault connect timeout.static final intDefault cap on concurrently handled client connections.static final longDefault socket open timeout in ms, after which close() will proceed even with active sockets.protected DestinationThe destination.protected final LoggingThe logging instance.protected booleanProtected for I2Ping since 0.9.11.(package private) static final intLegacy cap on consecutive connect timeouts before abandoning tunnel failover.(package private) static final longMinimum remaining budget for starting one connect leg.List of active sockets.(package private) static final longDeadline sentinel for callers that have not adopted the shared request budget (SOCKS, IRC, DCC, rawcreateI2PSocket): they keep their original per-call limits because this sentinel never reads as expired and never clamps.(package private) static final longOne-shot deadline extension granted while the outbound tunnel pool is still building (poolState() == 0) when the shared budget runs out.static final StringProperty name: max concurrently active client connections handled by one client tunnel.static final StringProperty for SSL enable.(package private) static final longSingle wall-clock budget for establishing one proxied request.protected final ObjectGuards sockMgr and mySockets.protected I2PSocketManagerThe socket manager.protected ServerSocketServer socket.Constructor Summary
ConstructorsConstructorDescriptionI2PTunnelClient(int localPort, String destinations, Logging l, boolean ownDest, EventDispatcher notifyThis, I2PTunnel tunnel, String pkf) Create a standard client tunnel listening on localPort, forwarding to the given destinations.Method Summary
All MethodsModifier and TypeMethodDescriptionprotected voidHandles an incoming local socket by selecting a remote destination and forwarding data.booleanclose(boolean forced) Overridden to unregister with port mapper.longGet the read idle timeout for newly-created connections (in milliseconds).voidoptionsUpdated(I2PTunnel tunnel) Update the dests then call super.voidsetReadTimeout(long ms) Set the read idle timeout for newly-created connections (in milliseconds).voidActually start working on incoming connections.Methods inherited from class I2PTunnelClientBase
buildSocketManager, buildSocketManager, buildSocketManager, buildSocketManager, clampToDeadlineMs, closeSocket, connectDeadlineFrom, createI2PSocket, createI2PSocket, createI2PSocket, createI2PSocket, destroy, extendDeadlineForBuildingPool, getDefaultOptions, getDefaultOptions, getEffectiveMaxConnections, getListenHost, getLocalPort, getSocketManager, getSocketManager, getSocketOpenTimeout, isConnectTimeout, isDeadlineExpired, legConnectTimeoutMs, manageConnection, poolIsDefinitivelyDown, poolState, resolveEffectiveMaxConnections, resolveMaxConnections, resolveRunnerCeiling, run, shouldContinueFailover, shouldContinueFailover, shouldOuterRetryConnect, shouldOuterRetryConnect, verifySocketManager, writeShedResponseModifier and TypeMethodDescriptionprotected I2PSocketManagerFor NON-SHARED clients (ownDest = true).protected static I2PSocketManagerbuildSocketManager(I2PTunnel tunnel) Create a disconnected socket manager for the tunnel, with no private key file.protected static I2PSocketManagerbuildSocketManager(I2PTunnel tunnel, String pkf) Create a disconnected socket manager for the tunnel, loading the persistent client dest from pkf if it is non-null.protected static I2PSocketManagerbuildSocketManager(I2PTunnel tunnel, String pkf, Logging log) Create a disconnected socket manager for the tunnel, loading the persistent client dest from pkf if it is non-null, and logging any key file error to log.(package private) static longclampToDeadlineMs(long requestedMs, long deadlineMs, long nowMs) Clamp a requested timeout to the time left before a shared deadline.static voidClose a socket silently.(package private) static longconnectDeadlineFrom(long nowMs) Compute the shared connect deadline for a request starting now.createI2PSocket(Destination dest) Create a new I2PSocket towards to the specified destination, adding it to the list of connections actually managed by this tunnel.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.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.(package private) I2PSocketcreateI2PSocket(Destination dest, I2PSocketOptions opt, long deadlineMs) Create a new I2PSocket bounded by a shared request deadline.booleandestroy()Note that the tunnel cannot be reopened after this by calling startRunning(), as it will destroy the underlying socket manager.(package private) static longextendDeadlineForBuildingPool(long deadlineMs, long nowMs, int poolState, boolean alreadyExtended) One-shot deadline extension for a request whose outbound tunnel pool is still building when the shared deadline runs out.protected I2PSocketOptionsCreate the default options (using the default timeout, etc).protected I2PSocketOptionsgetDefaultOptions(Properties overrides) Create the default options (using the default timeout, etc).(package private) intThe effective concurrent-connection cap for this tunnel at the moment the accept loop admits a connection.protected final InetAddressGet the listen host address.final intGet the local port.Returns the I2PSocketManager for this task.protected static I2PSocketManagergetSocketManager(I2PTunnel tunnel, String pkf) This is ONLY for shared clients.longReturns the socket open timeout in ms; close() will proceed after this even with active sockets.(package private) static booleanFor timeout wording.(package private) static booleanisDeadlineExpired(long deadlineMs, long nowMs) Whether a shared connect deadline has passed.(package private) static longlegConnectTimeoutMs(long requestedMs, long deadlineMs, long nowMs) Compute the connect timeout to apply to one failover leg under a shared deadline.protected voidManage the connection just opened on the specified socket.protected booleanAnd none are being built, so further connect retries cannot succeed.protected intRouter-context only, best-effort check of the client outbound tunnel pool.(package private) static intresolveEffectiveMaxConnections(boolean customized, int ownCap, int globalDefault) Pure decision helper forI2PTunnelClientBase.getEffectiveMaxConnections(): pick the per-tunnel override when one was explicitly configured, otherwise the Tuner-managed default cap.(package private) static intresolveMaxConnections(String configured) Resolve the max-concurrent-connections cap from the tunnel's configured value.(package private) static intresolveRunnerCeiling(boolean customized, int effectiveMax) Ceiling to pin on this tunnel's runner pool at creation time.voidrun()Non-final since 0.9.11.(package private) static booleanshouldContinueFailover(int tunnelCount, int attemptsMade, int timeoutFailures, boolean poolDown) Whether another tunnel-failover attempt is worthwhile after a connect failure.(package private) static booleanshouldContinueFailover(int tunnelCount, int attemptsMade, int timeoutFailures, boolean poolDown, boolean poolBuilding) Whether another tunnel-failover attempt is worthwhile after a connect failure.(package private) static booleanshouldOuterRetryConnect(int connectAttempts, int timeoutConnectAttempts, boolean timedOut, boolean poolDown, boolean poolBuilding, boolean browserClosed) Whether the outer HTTP connect loop should retry after a failure.(package private) static booleanshouldOuterRetryConnect(int connectAttempts, int timeoutConnectAttempts, boolean timedOut, int poolState, boolean deadlineExpired) Whether the outer HTTP connect loop should retry after a failure, given the single pool-state snapshot taken for that failure.protected voidCreate the manager if it doesn't exist, AND connect it to the router and build tunnels.protected voidBest-effort shed response on the browser-facing socket, then close it.Methods inherited from class I2PTunnelTask
connected, disconnected, errorOccurred, getBooleanOption, getId, getTunnel, isOpen, reportAbuse, routerDisconnected, setId, setName, setTunnel, toStringModifier and TypeMethodDescriptionvoidconnected(I2PSession session) For tasks that don't callI2PTunnel.addSession(I2PSession)directly.voiddisconnected(I2PSession session) Called when a session is disconnected.voiderrorOccurred(I2PSession session, String message, Throwable error) Does nothing here.protected booleangetBooleanOption(String opt, boolean dflt) Read a boolean client option from the tunnel's properties.intgetId()The id of the client list entry for this task.The I2PTunnel this task runs inside.booleanisOpen()Whether the tunnel is running and accepting connections.voidreportAbuse(I2PSession session, int severity) Does nothing here.protected voidTell the tunnel that the router connection has dropped.voidsetId(int id) Record the client list entry id for this task.protected voidRecord the display name for this task.voidRebind this task to a different tunnel.toString()The display name given to this task when it was constructed.Methods inherited from class EventDispatcherImpl
attachEventDispatcher, detachEventDispatcher, getEventDispatcher, getEvents, getEventValue, ignoreEvents, notifyEvent, unIgnoreEvents, waitEventValueModifier and TypeMethodDescriptionvoidAttach an EventDispatcher object to the events dispatching chain.voidDetach the specified EventDispatcher object from the events dispatching chain.Object to be used to deliver events (usuallythis, but YMMV).Retrieve the names of all the events that have been received.getEventValue(String name) Retrieve the value currently associated with the specified event value.voidIgnore further event notifications.voidnotifyEvent(String eventName, Object args) Deliver an event.voidAlmost like the method above :-).waitEventValue(String name) Wait until the given event has received a value.
Field Details
readTimeout
protected long readTimeoutIdle timeout in milliseconds for I2P socket reads on new connections. ≤ 0 means no timeout.
Constructor Details
I2PTunnelClient
public I2PTunnelClient(int localPort, String destinations, Logging l, boolean ownDest, EventDispatcher notifyThis, I2PTunnel tunnel, String pkf) throws IllegalArgumentException Create a standard client tunnel listening on localPort, forwarding to the given destinations. As of 0.9.20 this is fast, and does NOT connect the manager to the router, or open the local socket. You MUST call startRunning() for that.- Parameters:
localPort- if 0, use any port, get actual port selected with getLocalPort()destinations- peers we target, comma- or space-separated. Since 0.9.9, each dest may be appended with :portl- the logging instanceownDest- whether to use an owned destinationnotifyThis- the event dispatcher for notificationstunnel- the I2PTunnel instance, supplying the context and listen hostpkf- the path to a persistent private key file, or null to generate one- Throws:
IllegalArgumentException- if the I2PTunnel does not contain valid config to contact the router
Method Details
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.Less than or equal to 0 means forever. Default -1 (forever) as of 0.9.36 for standard tunnels, but extending classes may override. Prior to that, default was 5 minutes, but did not work due to streaming bugs.
Applies only to future connections; calling this does not affect existing connections.
- Parameters:
ms- the idle timeout in ms; zero or negative means forever
getReadTimeout
public long getReadTimeout()Get the read idle timeout for newly-created connections (in milliseconds).Less than or equal to 0 means forever. Default -1 (forever) as of 0.9.36 for standard tunnels, but extending classes may override. Prior to that, default was 5 minutes, but did not work due to streaming bugs.
- Returns:
- the idle timeout in ms; zero or negative means forever
clientConnectionRun
Handles an incoming local socket by selecting a remote destination and forwarding data.- Specified by:
clientConnectionRunin classI2PTunnelClientBase- Parameters:
s- the socket to manage
optionsUpdated
Update the dests then call super.- Overrides:
optionsUpdatedin classI2PTunnelClientBase- Parameters:
tunnel- the tunnel whose client options were updated
startRunning
public void startRunning()Actually start working on incoming connections. Overridden to register with port mapper.- Overrides:
startRunningin classI2PTunnelClientBase
close
public boolean close(boolean forced) Overridden to unregister with port mapper.- Overrides:
closein classI2PTunnelClientBase- Parameters:
forced- true to interrupt an in-progress build, false to close gracefully- Returns:
- true if the tunnel is closed, or false if connections were still active and the close was refused