- All Implemented Interfaces:
Runnable, EventDispatcher
- Direct Known Subclasses:
I2PSOCKSIRCTunnel
This class implements a SOCKS4a/5 proxy server that accepts local SOCKS connections and forwards them to I2P destinations or configured outproxies. It supports both I2P destination routing (for .i2p addresses) and outproxy routing for clearnet access, with authentication and port-specific proxy configuration.
The tunnel provides dynamic destination resolution, connection management, and serves as a flexible proxy solution for applications that support SOCKS protocol, enabling seamless I2P integration for various clients.
Field Summary
Modifier and TypeFieldDescriptionstatic final StringThe HTTP auth realm presented to clients that authenticate.static final StringThe key used for the default (first) proxy.protected static final intThis is a standard soTimeout, not a total timeout.static final StringThe property naming the outproxy type ("none", "HTTP", "SOCKS", "SOCKS4a").static final StringThe full property name of the default proxy.static final StringPrefix of the per-port proxy property names.Proxy settings by port, with a "default" entry for the restFields inherited from class I2PTunnelClientBase
_clientId, _context, _executor, _log, _ownDest, DEFAULT_MAX_CONNECTIONS, DEFAULT_SOCKET_OPEN_TIMEOUT, dest, l, listenerReady, mySockets, PROP_MAX_CONNECTIONS, PROP_USE_SSL, 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.static final intDefault cap on concurrently handled client connections.static final longDefault socket open timeout in ms, after whichI2PTunnelClientBase.close(boolean)will proceed even with active sockets.protected DestinationThe destination.protected final LoggingThe logging instance.protected booleanProtected for I2Ping since 0.9.11.List of active sockets.static final StringProperty name: max concurrently active client connections handled by one client tunnel.static final StringProperty turning on SSL between the proxy and the client.protected final ObjectGuards sockMgr and mySockets.protected I2PSocketManagerThe socket manager.protected ServerSocketServer socket.Constructor Summary
ConstructorsConstructorDescriptionI2PSOCKSTunnel(int localPort, Logging l, boolean ownDest, EventDispatcher notifyThis, I2PTunnel tunnel, String pkf) Create a SOCKS proxy on the given local port.Method Summary
Modifier and TypeMethodDescriptionbuildOptions(Properties overrides) Build socket options from the tunnel config merged with overrides.protected voidManage a connection in a separate thread.Get the default proxy list.getProxies(int port) Gets the proxy list for a specific port.Gets the proxy map for all configured ports.voidoptionsUpdated(I2PTunnel tunnel) Update the outproxy list then call super.private voidReads the proxy settings out of the tunnel's options.Methods inherited from class I2PTunnelClientBase
buildSocketManager, buildSocketManager, buildSocketManager, buildSocketManager, close, closeSocket, createI2PSocket, createI2PSocket, createI2PSocket, destroy, getDefaultOptions, getDefaultOptions, getListenHost, getLocalPort, getSocketManager, getSocketManager, getSocketOpenTimeout, manageConnection, poolIsDefinitivelyDown, poolState, run, startRunning, 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.booleanclose(boolean forced) Note that the tunnel can be reopened after this by calling startRunning().static voidClose a socket silently.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.booleandestroy()Note that the tunnel cannot be reopened after this by calling startRunning(), as it will destroy the underlying socket manager.protected I2PSocketOptionsCreate the default options (using the default timeout, etc).protected I2PSocketOptionsgetDefaultOptions(Properties overrides) Create the default options (using the default timeout, etc).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.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.voidrun()Non-final since 0.9.11.voidActually open the local socket and start working on incoming connections.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
INITIAL_SO_TIMEOUT
protected static final int INITIAL_SO_TIMEOUTThis is a standard soTimeout, not a total timeout. We have no slowloris protection on the client side. See I2PTunnelHTTPServer or SAM's ReadLine if we need that.- See Also:
proxies
AUTH_REALM
The HTTP auth realm presented to clients that authenticate.- See Also:
PROP_OUTPROXY_TYPE
The property naming the outproxy type ("none", "HTTP", "SOCKS", "SOCKS4a").- See Also:
PROP_PROXY_PREFIX
Prefix of the per-port proxy property names.- See Also:
DEFAULT
The key used for the default (first) proxy.- See Also:
PROP_PROXY_DEFAULT
The full property name of the default proxy.- See Also:
Constructor Details
I2PSOCKSTunnel
public I2PSOCKSTunnel(int localPort, Logging l, boolean ownDest, EventDispatcher notifyThis, I2PTunnel tunnel, String pkf) Create a SOCKS proxy on the given local port.Since 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- the local port to listen onl- the logging instanceownDest- whether to use own destinationnotifyThis- the event dispatcher for notificationstunnel- the I2P tunnelpkf- private key file name or null for transient key
Method Details
clientConnectionRun
Description copied from class:I2PTunnelClientBaseManage a connection in a separate thread. This only works if you do not overrideI2PTunnelClientBase.manageConnection(Socket).This is run in a thread from an unlimited-size thread pool, so it may block or run indefinitely.
- Specified by:
clientConnectionRunin classI2PTunnelClientBase- Parameters:
s- the socket to manage
optionsUpdated
Update the outproxy list then call super.- Overrides:
optionsUpdatedin classI2PTunnelClientBase- Parameters:
tunnel- the tunnel whose client options were updated
parseOptions
private void parseOptions()Reads the proxy settings out of the tunnel's options.getProxyMap
getDefaultProxies
getProxies
buildOptions
Build socket options from the tunnel config merged with overrides.- Parameters:
overrides- properties to override the default options- Returns:
- the built socket options