java.lang.Object
net.i2p.util.EventDispatcherImpl
net.i2p.i2ptunnel.I2PTunnelTask
net.i2p.i2ptunnel.udpTunnel.I2PTunnelUDPClientBase
net.i2p.i2ptunnel.socks.SOCKSUDPTunnel
- All Implemented Interfaces:
Sink, Source, EventDispatcher
A Datagram Tunnel that can have multiple bidirectional ports on the UDP side.
TX: (multiple SOCKSUDPPorts -> ) I2PSink
RX: (SOCKSUDPWrapper in multiple SOCKSUDPPorts <- ) MultiSink <- I2PSource
The replies must be to the same I2CP toPort as the outbound fromPort. If the server does not honor that, the replies will be dropped.
The replies must be repliable. Raw datagrams are not supported, and would require a unique source port for each target.
Preliminary, untested, possibly incomplete.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MultiSink<SOCKSUDPPort> Hands each received datagram to its port.private final Map<Integer, SOCKSUDPPort> Open UDP ports, by SOCKS port number.Fields inherited from class I2PTunnelUDPClientBase
_clientId, _context, lModifier and TypeFieldDescriptionprotected longUnique client identifier.protected I2PAppContextThe I2P app context.protected LoggingLogging instance.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionintadd(InetAddress host, int port) Adds a new UDP port to the tunnel for bidirectional SOCKS UDP communication.booleanclose(boolean forced) Closes the tunnel and all associated ports.voidRemoves a UDP port from the tunnel and stops its associated resources.private voidstartall()You should really add() afterstartRunning().final voidStarts the tunnel and begins processing datagrams.private voidstopall()Closes every open UDP port.Methods inherited from class I2PTunnelUDPClientBase
send, setSink, startModifier and TypeMethodDescriptionvoidsend(Destination to, int fromPort, int toPort, byte[] data) Sends data through the I2P sink to the configured destination.voidSets the receiver of the UDP datagrams from I2P.voidstart()Starts the I2P source to begin receiving datagrams.Methods inherited from class I2PTunnelTask
connected, destroy, disconnected, errorOccurred, getBooleanOption, getId, getSocketManager, getTunnel, isOpen, optionsUpdated, reportAbuse, routerDisconnected, setId, setName, setTunnel, toStringModifier and TypeMethodDescriptionvoidconnected(I2PSession session) For tasks that don't callI2PTunnel.addSession(I2PSession)directly.booleandestroy()Note that the tunnel cannot be reopened after this by calling startRunning(), as it may destroy the underlying socket manager, depending on implementation.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.Returns the I2PSocketManager for this task, or null if not applicable.The I2PTunnel this task runs inside.booleanisOpen()Whether the tunnel is running and accepting connections.voidoptionsUpdated(I2PTunnel tunnel) Notify the task that I2PTunnel's options have been updated.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
ports
Open UDP ports, by SOCKS port number.demuxer
Hands each received datagram to its port.
Constructor Details
SOCKSUDPTunnel
Set up a tunnel with no UDP side yet. Use add() for each port.- Parameters:
tunnel- the parent tunnel supplying the logging facility, event dispatcher, I2CP session and client options for the UDP association
Method Details
add
Adds a new UDP port to the tunnel for bidirectional SOCKS UDP communication.- Parameters:
host- the local address to bind toport- the local port to bind to, or 0 for any available port- Returns:
- the actual port number the socket was bound to
remove
Removes a UDP port from the tunnel and stops its associated resources.- Parameters:
port- the UDP port number to remove
startRunning
public final void startRunning()Starts the tunnel and begins processing datagrams. Ports must be added after this call.- Overrides:
startRunningin classI2PTunnelUDPClientBase
close
public boolean close(boolean forced) Closes the tunnel and all associated ports.- Overrides:
closein classI2PTunnelUDPClientBase- Parameters:
forced- if true, force immediate close without graceful shutdown- Returns:
- true if closed successfully
startall
private void startall()You should really add() afterstartRunning().stopall
private void stopall()Closes every open UDP port.