java.lang.Object
net.i2p.i2ptunnel.irc.EventReceiver
net.i2p.i2ptunnel.irc.DCCClientManager
- All Implemented Interfaces:
EventDispatcher
Start, track, and expire the I2PTunnelDCCClients.
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 ----->
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentHashMap<Integer, I2PTunnelDCCClient> Key is the DCC client's local port.private final ConcurrentHashMap<Integer, I2PTunnelDCCClient> Key is the DCC client's local port.private final EventDispatcherDispatches the events the DCC clients raise.private final ConcurrentHashMap<Integer, I2PTunnelDCCClient> Key is the DCC client's local port.private final LogLogger for this class.private final I2PTunnelThe IRC tunnel being served.private static longCounter for generating unique DCC session ids.private final LoggingSends status lines to the IRC client.private static final intMost inbound DCC tunnels running at once.private static final intMost inbound DCC tunnels waiting to be accepted.private final I2PSocketManagerOpens the DCC tunnels.Constructor Summary
ConstructorsConstructorDescriptionDCCClientManager(I2PSocketManager sktMgr, Logging logging, EventDispatcher dispatch, I2PTunnel tunnel) Create a new manager for DCC client tunnels.Method Summary
Modifier and TypeMethodDescriptionintacceptIncoming(int port) Handle an incoming DCC ACCEPT response from the remote peer.booleanclose(boolean forced) Close all DCC client tunnels managed by this manager.private voidconnStarted(I2PTunnelDCCClient client) Called when a DCC client connection has started successfully.private voidconnStopped(Integer lport) Called when a DCC client connection has stopped.private voidExpires timed-out inbound and complete DCC client tunnels.private intnewIncoming(String b32, int port, int localPort) Register an incoming DCC session, returning its id.intnewIncoming(String b32, int port, String type) Handle an incoming DCC request from a remote peer.voidnotifyEvent(String eventName, Object args) EventReceiver callback for DCC client connection events.intresumeOutgoing(int port) Handle an outgoing DCC RESUME request.Methods inherited from class EventReceiver
attachEventDispatcher, detachEventDispatcher, getEventDispatcher, getEvents, getEventValue, ignoreEvents, unIgnoreEvents, waitEventValueModifier and TypeMethodDescriptionvoidSubscribe to IRC events.voidUnsubscribe from IRC events.Object to be used to deliver events (usuallythis, but YMMV).All registered event names.getEventValue(String name) Value of the last fired event.voidStop waiting for events.voidAlmost like the method above :-).waitEventValue(String name) Block until the event fires and return its value.
Field Details
sockMgr
Opens the DCC tunnels._dispatch
Dispatches the events the DCC clients raise.l
Sends status lines to the IRC client._tunnel
The IRC tunnel being served._log
Logger for this class._incoming
Key is the DCC client's local port._active
Key is the DCC client's local port._complete
Key is the DCC client's local port.id
private static long idCounter for generating unique DCC session ids.MAX_INCOMING_PENDING
private static final int MAX_INCOMING_PENDINGMost inbound DCC tunnels waiting to be accepted.- See Also:
MAX_INCOMING_ACTIVE
private static final int MAX_INCOMING_ACTIVEMost inbound DCC tunnels running at once.- See Also:
Constructor Details
DCCClientManager
public DCCClientManager(I2PSocketManager sktMgr, Logging logging, EventDispatcher dispatch, I2PTunnel tunnel) Create a new manager for DCC client tunnels.- Parameters:
sktMgr- the socket manager for creating connectionslogging- the logging facilitydispatch- the event dispatcher for tunnel eventstunnel- the parent I2PTunnel instance
Method Details
close
public boolean close(boolean forced) Close all DCC client tunnels managed by this manager. Stops all incoming, active, and complete client tunnels and clears the internal maps.- Parameters:
forced- unused parameter, retained for compatibility- Returns:
- true always, indicating all tunnels were closed
newIncoming
Handle an incoming DCC request from a remote peer. Validates the base32 address and creates a new DCC client tunnel.- Parameters:
b32- the remote DCC server's base32 destination (60 chars, ending in .b32.i2p)port- the remote DCC server's I2P porttype- the DCC type (currently ignored)- Returns:
- the local DCC client tunnel port, or -1 on error (invalid address or too many connections)
newIncoming
Register an incoming DCC session, returning its id.- Parameters:
b32- the base32 destination address of the peer offering the sessionport- the remote DCC portlocalPort- bind to port or 0; if nonzero it will be the rv- Returns:
- the new session id, or -1 if the address is invalid
resumeOutgoing
public int resumeOutgoing(int port) Handle an outgoing DCC RESUME request. Stops the existing client tunnel for the given local port.- Parameters:
port- the local DCC client tunnel port to resume- Returns:
- the local port of the stopped tunnel, or -1 if no matching tunnel was found
acceptIncoming
public int acceptIncoming(int port) Handle an incoming DCC ACCEPT response from the remote peer. Searches for a matching tunnel in complete, active, or incoming states and creates a new incoming connection with the original parameters.- Parameters:
port- the remote DCC server's I2P port from the ACCEPT message- Returns:
- the local DCC client tunnel port for the new connection, or -1 if no match found
notifyEvent
EventReceiver callback for DCC client connection events. Handles connection start and stop events to update tunnel state.- Specified by:
notifyEventin interfaceEventDispatcher- Specified by:
notifyEventin classEventReceiver- Parameters:
eventName- the event name (CONNECT_START_EVENT or CONNECT_STOP_EVENT)args- the event arguments (I2PTunnelDCCClient for start, Integer port for stop)
connStarted
Called when a DCC client connection has started successfully. Moves the tunnel from incoming to active state.- Parameters:
client- the DCC client tunnel that has started
connStopped
Called when a DCC client connection has stopped. Moves the tunnel from incoming or active to complete state.- Parameters:
lport- the local port of the tunnel that stopped
expireInbound
private void expireInbound()Expires timed-out inbound and complete DCC client tunnels. Removes and stops any tunnels whose expiration time has passed.