java.lang.Object
net.i2p.util.EventDispatcherImpl
net.i2p.i2ptunnel.I2PTunnelTask
net.i2p.i2ptunnel.I2PTunnelServer
net.i2p.i2ptunnel.I2PTunnelIRCServer
- All Implemented Interfaces:
Runnable, EventDispatcher
IRC server tunnel that filters registration to pass client destination hash as hostname.
Enables IRC servers to track users across nick changes. Requires IRC daemon to use client-provided hostname rather than IP. Many IRCds ignore hostname in USER message (easily spoofed) unless from another server. May require IRCd configuration; not configurable in unrealircd/ngircd.
Destination mangling options (in i2ptunnel custom options):
ircserver.method unset: Defaults to user method ircserver.method=user: Use described method ircserver.method=webirc: Use WEBIRC protocol ircserver.cloakKey unset: Random persistent cloaking (default) ircserver.cloakKey=pass: Consistent cloaking via passphrase hash ircserver.webircPassword=pw: WEBIRC protocol password ircserver.webircSpoofIP=IP: Spoofed IP for WEBIRC ircserver.fakeHostname=%f.b32.i2p: Fake hostname (%f=full B32, %c=cloaked)Note: No quotes/spaces in passphrase for GUI compatibility. No outbound filtering.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThrown when a client's registration sequence is unacceptable and the connection is dropped.Field Summary
Modifier and TypeFieldDescriptionprivate static final String[]IRC protocol options stripped from the client's request.private final byte[]The key used to cloak the client addresses.private static final longDefault idle time before the drop, the client should time out first.private static final StringError line sent when the connection closes early.private static final StringError line sent when the registration fails.private static final StringError line sent when the connection times out.private static final StringError line sent when the destination is unavailable.private static final longTime allowed for one line of the server greeting.private final StringThe hostname sent to the IRC server.private static final intLongest IRC line accepted.private final StringThe webirc method name, if any.static final StringConfig key for the cloak passphrase, where unset means random persistent cloaking.static final StringConfig key for the fake hostname template, where%fis the full B32 destination.static final StringDefault forPROP_HOSTNAME, the full B32 destination as a hostname.static final StringConfig key for the registration method,user(default) orwebirc.static final StringDefault forPROP_METHOD, selecting the USER-based hostname mangling.static final StringConfig key for the password sent in the WEBIRC handshake, with no quotes or spaces.static final StringConfig key for the IP address spoofed in the WEBIRC handshake.static final StringDefault forPROP_WEBIRC_SPOOF_IP, the loopback address.private static final longTotal time allowed for the server greeting.private final StringThe webirc password, if any.private final StringThe IP the webirc handshake spoofs.Fields inherited from class I2PTunnelServer
_clientExecutor, _log, _tcg, bidir, DEFAULT_HANDLE_MS, i2pss, l, localPort, MAX_QUEUE_DRAIN_MS, PROP_ALT_PKF, PROP_MAX_CONNECTIONS, PROP_READ_TIMEOUT, PROP_SERVER_THREADS, PROP_UNIQUE_LOCAL, PROP_USE_SSL, PROP_WRITE_TIMEOUT, readTimeout, remoteHost, remotePort, serverId, slock, sockMgr, sslLock, taskModifier and TypeFieldDescriptionprotected ThreadPoolExecutorPool running the per-connection client handlers, taken from the TunnelControllerGroup so server load stays inside its own thread budget.protected final LogLogger for this tunnel server.protected TunnelControllerGroupThe controller group that owns this tunnel's runner pool, cached fromTunnelControllerGroup.getInstance()once inI2PTunnelServer.run().protected booleanTrue for HTTP bidirectional server mode.(package private) static final longFallback average handler time (ms) when no recent blockingHandleTime sample is available for the drain estimate.protected I2PServerSocketThe listening server socket, null until the tunnel is started.protected final LoggingClient-visible log channel: every lifecycle notice and warning reported to the I2P client (bad option values, unresolvable hosts, lingering connections).protected intLocal port a HTTP bidir subclass hands to its proxy, replacing theI2PTunnelServer.DEFAULT_LOCAL_PORTplaceholder.(package private) static final longReject only when a fully busy pool would need longer than this to drain the queue.static final StringConfig key naming an alternate private key file.static final StringConfig key to cap concurrent inbound connections; 0 (default) = unlimited.static final StringConfig key to override the socket read timeout in ms; 0 (default) = shut down silent connections promptly (HTTP server falls back to SERVER_READ_TIMEOUT_GET).static final StringConfig key to cap this tunnel's private server handler pool in threads.static final StringConfig key to enable unique local address.static final StringConfig key to enable SSL.static final StringConfig key to override the outbound write timeout in ms (0 = use the streaming default, which can be the full 120s disconnect timeout with no ACK progress).protected longDefault timeout - override if desired.protected InetAddressRemote endpoint of the current connection, null for the listening server.protected intRemote port of the current connection, 0 for the listening server.protected static longServer ID for HTTP bidirectional proxies; not incremented, always 0.protected final ObjectPassed to each I2PTunnelRunner so connection teardown serializes on it.protected final I2PSocketManagerBuilds the outbound sockets used to reach each configured destination.protected final ObjectGuards lazy creation of _sslFactory.protected I2PTunnelTaskHTTP bidirectional server task, null for standard tunnel server.Constructor Summary
ConstructorsConstructorDescriptionI2PTunnelIRCServer(InetAddress host, int port, File privkey, String privkeyname, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel) Construct an IRC client tunnel server.Method Summary
Modifier and TypeMethodDescriptionprotected voidblockingHandle(I2PSocket socket) Register one incoming IRC client connection, blocking until it closes.private String(Optionally) append 32 bytes of crap to the destination then return the first few characters of the hash of the whole thing, + ".i2p".private static StringfilterRegistration(I2PSocket socket, String newHostname) Keep reading until we see USER or SERVER.private static StringRead a line terminated by newline, with a total read timeout.Methods inherited from class I2PTunnelServer
acquireConnectionSlot, close, destroy, effectiveWriteTimeout, getReadTimeout, getSocket, getSocket, getSocketManager, getSocketString, optionsUpdated, parseServerThreadOverride, rejectConnection, rejectConnection, releaseConnection, releaseConnectionSlot, run, setReadTimeout, shouldRejectOnQueue, shouldRejectOnQueue, startRunning, tryAcquireConnectionModifier and TypeMethodDescription(package private) static booleanacquireConnectionSlot(int maxConnections, AtomicInteger active) Decide whether a concurrent-connection slot is available and, if so, reserve it.booleanclose(boolean forced) Note that the tunnel can be reopened after this by calling startRunning().booleandestroy()Note that the tunnel cannot be reopened after this by calling startRunning(), as it will destroy the underlying socket manager.(package private) static longeffectiveWriteTimeout(Properties props) Determine the write timeout to bind the outbound I2P stream to, in ms.longGet the read idle timeout for newly-created connections (in milliseconds).protected SocketCreates a TCP socket connection to the configured destination.protected SocketgetSocket(Hash from, InetAddress remoteHost, int remotePort) Creates a TCP socket connection to the specified destination.Return the socket manager, or null if destroyed.protected StringgetSocketString(int incomingPort) Gets a human-readable string representation of the target socket.voidoptionsUpdated(I2PTunnel tunnel) Update the I2PSocketManager.(package private) static intParse the per-tunnel server handler pool override.protected voidrejectConnection(I2PSocket socket) Refuse an inbound connection when the gate cap is exceeded.protected voidrejectConnection(I2PSocket socket, boolean queueFull) Refuse an inbound connection with an accurate reason.protected voidRelease a reservation taken byI2PTunnelServer.tryAcquireConnection().(package private) static voidreleaseConnectionSlot(AtomicInteger active) Release a slot reserved byI2PTunnelServer.acquireConnectionSlot(int, AtomicInteger).voidrun()Runs the I2PTunnelServer to accept and handle incoming connections asynchronously.voidsetReadTimeout(long ms) Set the read idle timeout for newly-created connections (in milliseconds).(package private) static booleanshouldRejectOnQueue(int queueDepth, int capacity, int active, int threads) Back-compat overload when the caller has no handle-time sample yet.(package private) static booleanshouldRejectOnQueue(int queueDepth, int capacity, int active, int threads, long avgHandleMs) Decide whether a connection should be rejected because the handler queue is already drowning.voidStart running the I2PTunnelServer.protected booleanTry to reserve a slot in the concurrent-connection gate.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
cloakKey
private final byte[] cloakKeyThe key used to cloak the client addresses.hostname
The hostname sent to the IRC server.method
The webirc method name, if any.webircPassword
The webirc password, if any.webircSpoofIP
The IP the webirc handshake spoofs.PROP_METHOD
Config key for the registration method,user(default) orwebirc.- See Also:
PROP_METHOD_DEFAULT
Default forPROP_METHOD, selecting the USER-based hostname mangling.- See Also:
PROP_CLOAK
Config key for the cloak passphrase, where unset means random persistent cloaking.- See Also:
PROP_WEBIRC_PASSWORD
Config key for the password sent in the WEBIRC handshake, with no quotes or spaces.- See Also:
PROP_WEBIRC_SPOOF_IP
Config key for the IP address spoofed in the WEBIRC handshake.- See Also:
PROP_WEBIRC_SPOOF_IP_DEFAULT
Default forPROP_WEBIRC_SPOOF_IP, the loopback address.- See Also:
PROP_HOSTNAME
Config key for the fake hostname template, where%fis the full B32 destination.- See Also:
PROP_HOSTNAME_DEFAULT
Default forPROP_HOSTNAME, the full B32 destination as a hostname.- See Also:
HEADER_TIMEOUT
private static final long HEADER_TIMEOUTTime allowed for one line of the server greeting.- See Also:
TOTAL_HEADER_TIMEOUT
private static final long TOTAL_HEADER_TIMEOUTTotal time allowed for the server greeting.- See Also:
MAX_LINE_LENGTH
DEFAULT_IRC_READ_TIMEOUT
private static final long DEFAULT_IRC_READ_TIMEOUTDefault idle time before the drop, the client should time out first.- See Also:
ERR_UNAVAILABLE
Error line sent when the destination is unavailable.- See Also:
ERR_REGISTRATION
Error line sent when the registration fails.- See Also:
ERR_TIMEOUT
Error line sent when the connection times out.- See Also:
ERR_EOF
Error line sent when the connection closes early.- See Also:
BAD_PROTOCOLS
IRC protocol options stripped from the client's request.
Constructor Details
I2PTunnelIRCServer
public I2PTunnelIRCServer(InetAddress host, int port, File privkey, String privkeyname, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel) Construct an IRC client tunnel server.The cloak key is generated on first use from a random 32 bytes when no passphrase is configured. The options supply the WEBIRC and cloaking settings, and the configuration must be valid to contact the router.
- Parameters:
host- the IRC server to connect to on the far side of the tunnelport- the port on that server to connect toprivkey- the file holding this tunnel's private key, or null if theprivkeyname- the name to show for the key in the console and logsl- the logging implementation shared with the owning I2PTunnelnotifyThis- dispatcher told about connection events for this clienttunnel- the I2PTunnel this IRC client belongs to, whose client- Throws:
IllegalArgumentException- if the I2PTunnel does not contain
Method Details
blockingHandle
Register one incoming IRC client connection, blocking until it closes.- Overrides:
blockingHandlein classI2PTunnelServer- Parameters:
socket- the accepted connection from a local IRC client- See Also:
cloakDest
(Optionally) append 32 bytes of crap to the destination then return the first few characters of the hash of the whole thing, + ".i2p". Or do we want the full hash if the ircd is going to use this for nickserv auto-login? Or even Base32 if it will be used in a case-insensitive manner?- Parameters:
d- the destination to cloak- Returns:
- the hostname template with %f replaced by the destination hash prefix and %c by the cloaked hash prefix
filterRegistration
Keep reading until we see USER or SERVER. This modifies the socket readTimeout, caller must save and restore.- Parameters:
socket- the client socket to read the registration lines fromnewHostname- the cloaked .i2p hostname substituted into the USER line- Returns:
- the rewritten registration lines ending at the USER or SERVER line
- Throws:
SocketTimeoutException- if timeout is reached before newlineEOFException- if EOF is reached before newlineI2PTunnelIRCServer.RegistrationException- if line too longIOException- on other errors in the underlying stream
readLine
Read a line terminated by newline, with a total read timeout.Warning - strips \n but not \r Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded Warning - not UTF-8.
- Parameters:
socket- the socket to read one line fromtimeout- throws SocketTimeoutException immediately if zero or negative- Returns:
- the line without the terminating newline, carriage returns kept
- Throws:
SocketTimeoutException- if timeout is reached before newlineEOFException- if EOF is reached before newlineI2PTunnelIRCServer.RegistrationException- if line too longIOException- on other errors in the underlying stream