java.lang.Object
net.i2p.util.EventDispatcherImpl
net.i2p.i2ptunnel.I2PTunnelTask
net.i2p.i2ptunnel.udpTunnel.I2PTunnelUDPClientBase
- All Implemented Interfaces:
Sink, Source, EventDispatcher
- Direct Known Subclasses:
SOCKSUDPTunnel, StreamrConsumer
Base client class that sets up an I2P Datagram client destination. The UDP side is not implemented here, as there are at least two possibilities:
1) UDP side is a "server" Example: Streamr Consumer - Configure a destination host and port - External application sends no data - Extending class must have a constructor with host and port arguments
2) UDP side is a client/server Example: SOCKS UDP (DNS requests?) - configure an inbound port and a destination host and port - External application sends and receives data - Extending class must have a constructor with host and 2 port arguments
So the implementing class must create a UDPSource and/or UDPSink, and must call setSink(Sink).
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final AtomicLongCounts the client ids handed out.protected longUnique client identifier.protected I2PAppContextThe I2P app context.private final SinkSends datagrams out over I2P.private final SourceReads datagrams arriving from I2P.private final I2PSessionThe session carrying the datagrams.(package private) static final longDefault connect timeout.protected LoggingLogging instance.private final ObjectGuards starting the destination's sockets.Constructor Summary
ConstructorsConstructorDescriptionI2PTunnelUDPClientBase(String destination, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel) Set up the I2P client, destination keypair, and I2CP session for this tunnel.Method Summary
All MethodsModifier and TypeMethodDescriptionbooleanclose(boolean forced) Closes the tunnel and destroys the session.voidsend(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.voidStarts the tunnel and begins processing 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
_context
The I2P app context.l
Logging instance.DEFAULT_CONNECT_TIMEOUT
__clientId
Counts the client ids handed out._clientId
protected long _clientIdUnique client identifier.startLock
Guards starting the destination's sockets._session
The session carrying the datagrams._i2pSource
Reads datagrams arriving from I2P._i2pSink
Sends datagrams out over I2P.
Constructor Details
I2PTunnelUDPClientBase
public I2PTunnelUDPClientBase(String destination, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel) throws IllegalArgumentException Set up the I2P client, destination keypair, and I2CP session for this tunnel.- Parameters:
destination- I2P destination to send to; null for send-to-anyonel- the logging facility used for this tunnel's outputnotifyThis- event dispatcher for notificationstunnel- the parent tunnel, supplying the context and I2CP options- Throws:
IllegalArgumentException- if the I2CP configuration is so broken that we can't create a socketManager
Method Details
startRunning
public void startRunning()Starts the tunnel and begins processing datagrams. Classes should override to start UDP side as well.close
public boolean close(boolean forced) Closes the tunnel and destroys the session.- Specified by:
closein classI2PTunnelTask- Parameters:
forced- if true, force immediate close without graceful shutdown- Returns:
- true if closed successfully
setSink
start
send
Sends data through the I2P sink to the configured destination.- Specified by:
sendin interfaceSink- Parameters:
to- the destination to send to, ignored if configured for a single destinationfromPort- I2CP source port, 0-65535toPort- I2CP destination port, 0-65535data- the data to send- Throws:
RuntimeException- if the session is closed