java.lang.Object
net.i2p.util.EventDispatcherImpl
net.i2p.i2ptunnel.I2PTunnelTask
net.i2p.i2ptunnel.I2PTunnelServer
net.i2p.i2ptunnel.irc.I2PTunnelDCCServer
- All Implemented Interfaces:
Runnable, EventDispatcher
A standard server that only answers for registered ports, and each port can only be used once.
direct conn
<---> I2PTunnelDCCServer <--------------->I2PTunnelDCCClient <---->
originating responding
chat client chat client
CHAT ---> I2PTunnelIRCClient --> IRC server --> I2TunnelIRCClient ----->
SEND ---> I2PTunnelIRCClient --> IRC server --> I2TunnelIRCClient ----->
RESUME <--- I2PTunnelIRCClient <-- IRC server <-- I2TunnelIRCClient <-----
ACCEPT ---> I2PTunnelIRCClient --> IRC server --> I2TunnelIRCClient ----->
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classOne local address handed out for a DCC connection.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentHashMap<Integer, I2PTunnelDCCServer.LocalAddress> Key is the server's local I2P port.private final ConcurrentHashMap<Integer, I2PTunnelDCCServer.LocalAddress> Key is the server's local I2P port.private final ConcurrentHashMap<Integer, I2PTunnelDCCServer.LocalAddress> Key is the server's local I2P port.The open DCC sockets.private static final longDefault idle time before a DCC socket is dropped.private static final InetAddressJust to keep super() happy.private static final intLargest DCC port accepted.private static final intOutgoing DCC connections allowed open.private static final intOutgoing DCC connections allowed pending.private static final intSmallest DCC port accepted.private static final longTime before an unused local address expires.Fields inherited from class I2PTunnelServer
_clientExecutor, _log, _tcg, bidir, i2pss, l, localPort, 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.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.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
ConstructorsConstructorDescriptionI2PTunnelDCCServer(I2PSocketManager sktMgr, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel) There's no support for unsolicited incoming I2P connections, so there's no server host or port parameters.Method Summary
Modifier and TypeMethodDescriptionintacceptOutgoing(int port) An outgoing ACCEPT response.protected voidblockingHandle(I2PSocket socket) An incoming DCC connection, only accept for a known port.booleanclose(boolean forced) Closes all connections and clears all pending/outgoing/active maps.private voidDrops the expired outgoing DCC connections.private intnewOutgoing(byte[] ip, int port, int i2pPort) Register an outgoing DCC session, returning its id.intnewOutgoing(byte[] ip, int port, String type) An outgoing DCC request.intresumeIncoming(int port) An incoming RESUME request.Methods inherited from class I2PTunnelServer
destroy, getReadTimeout, getSocket, getSocket, getSocketManager, getSocketString, optionsUpdated, rejectConnection, rejectConnection, releaseConnection, run, setReadTimeout, startRunning, tryAcquireConnectionModifier and TypeMethodDescriptionbooleandestroy()Note that the tunnel cannot be reopened after this by calling startRunning(), as it will destroy the underlying socket manager.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.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().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).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
_outgoing
Key is the server's local I2P port._active
Key is the server's local I2P port._resume
Key is the server's local I2P port._sockList
DUMMY
Just to keep super() happy.MIN_I2P_PORT
MAX_I2P_PORT
MAX_OUTGOING_PENDING
private static final int MAX_OUTGOING_PENDINGOutgoing DCC connections allowed pending.- See Also:
MAX_OUTGOING_ACTIVE
private static final int MAX_OUTGOING_ACTIVEOutgoing DCC connections allowed open.- See Also:
OUTBOUND_EXPIRE
private static final long OUTBOUND_EXPIRETime before an unused local address expires.- See Also:
DEFAULT_DCC_READ_TIMEOUT
private static final long DEFAULT_DCC_READ_TIMEOUTDefault idle time before a DCC socket is dropped.- See Also:
Constructor Details
I2PTunnelDCCServer
public I2PTunnelDCCServer(I2PSocketManager sktMgr, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel) There's no support for unsolicited incoming I2P connections, so there's no server host or port parameters.- Parameters:
sktMgr- an existing socket managerl- the logging system the base class reports throughnotifyThis- the dispatcher notified of connection and transfer eventstunnel- the owning I2PTunnel supplying the router context and configuration- Throws:
IllegalArgumentException- if the I2PTunnel does not contain valid config to contact the router
Method Details
blockingHandle
An incoming DCC connection, only accept for a known port. Passed through without filtering.- Overrides:
blockingHandlein classI2PTunnelServer- Parameters:
socket- the incoming I2P socket connection- See Also:
close
public boolean close(boolean forced) Closes all connections and clears all pending/outgoing/active maps.- Overrides:
closein classI2PTunnelServer- Parameters:
forced- unused, for interface compatibility- Returns:
- true if closed successfully
newOutgoing
An outgoing DCC request.- Parameters:
ip- local irc client IPport- local irc client porttype- ignored; the overload always lets the router pick the I2P port- Returns:
- i2p port or -1 on error
newOutgoing
private int newOutgoing(byte[] ip, int port, int i2pPort) Register an outgoing DCC session, returning its id.- Parameters:
ip- local irc client IPport- local dcc server I2P port or 0 to pick one at randomi2pPort- the I2P port to reserve, or 0 to pick an unused one at random- Returns:
- the reserved I2P port, or -1 on error
resumeIncoming
public int resumeIncoming(int port) An incoming RESUME request.- Parameters:
port- local dcc server I2P port- Returns:
- local IRC client DCC port or -1 on error
acceptOutgoing
public int acceptOutgoing(int port) An outgoing ACCEPT response.- Parameters:
port- local irc client DCC port- Returns:
- local DCC server i2p port or -1 on error
expireOutbound
private void expireOutbound()Drops the expired outgoing DCC connections.