java.lang.Object
net.i2p.util.EventDispatcherImpl
net.i2p.i2ptunnel.I2PTunnelTask
net.i2p.i2ptunnel.udpTunnel.I2PTunnelUDPServerBase
- All Implemented Interfaces:
Sink, Source, EventDispatcher
- Direct Known Subclasses:
StreamrProducer
Base client class that sets up an I2P Datagram server destination. The UDP side is not implemented here, as there are at least two possibilities:
1) UDP side is a "client" Example: Streamr Producer - configure an inbound port - External application receives no data - Extending class must have a constructor with a port argument
2) UDP side is a client/server Example: DNS - 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 SinkSends datagrams out over I2P.private SourceReads datagrams arriving from I2P.private final LogThe log this server writes to, distinct from the console-boundl.private I2PSessionThe session carrying the datagrams.private static final longReads wait forever unless the config says otherwise.protected LoggingThe logging facility the owning tunnel reports through.private final ObjectHeld while shutting down and reconfiguring, so those cannot overlap.protected longDefault timeout to 3 minutes - override if desired.protected ObjectHeld while a read or write is in flight on the client's socket.Constructor Summary
ConstructorsConstructorDescriptionI2PTunnelUDPServerBase(File privkey, String privkeyname, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel) Creates a UDP server tunnel using the private key in the given file.Method Summary
Modifier and TypeMethodDescriptionbooleanclose(boolean forced) Closes the tunnel and destroys the session.longRead idle timeout for newly-created connections (in milliseconds).private voidinit(InputStream privData, Logging l) Opens the session and wires up the source and sink.voidsend(Destination to, int fromPort, int toPort, byte[] data) Sends data through the I2P sink.voidsetReadTimeout(long ms) Sets the read idle timeout for newly-created connections (in milliseconds).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
_log
lock
Held while shutting down and reconfiguring, so those cannot overlap.slock
Held while a read or write is in flight on the client's socket.l
The logging facility the owning tunnel reports through.DEFAULT_READ_TIMEOUT
private static final long DEFAULT_READ_TIMEOUTReads wait forever unless the config says otherwise.- See Also:
readTimeout
protected long readTimeoutDefault timeout to 3 minutes - override if desired._session
The session carrying the datagrams._i2pSource
Reads datagrams arriving from I2P._i2pSink
Sends datagrams out over I2P.
Constructor Details
I2PTunnelUDPServerBase
public I2PTunnelUDPServerBase(File privkey, String privkeyname, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel) Creates a UDP server tunnel using the private key in the given file.- Parameters:
privkey- file containing the private key for the destinationprivkeyname- name of the private key filel- the logging facility reporting to the console and logsnotifyThis- event dispatcher for notificationstunnel- the owning I2PTunnel, which supplies the client options and context- Throws:
IllegalArgumentException- if the I2CP configuration is b0rked so badly that we cant create a socketManager
Method Details
init
Opens the session and wires up the source and sink.- Parameters:
privData- the private key data to open withl- where to log
startRunning
public void startRunning()Starts the tunnel and begins processing datagrams. Classes should override to start UDP side as well.setReadTimeout
public void setReadTimeout(long ms) Sets the read idle timeout for newly-created connections (in milliseconds). After this time expires without data being received from the I2P network, the connection itself will be closed.- Parameters:
ms- the timeout in milliseconds, or -1 for no timeout
getReadTimeout
public long getReadTimeout()Read idle timeout for newly-created connections (in milliseconds).- Returns:
- the read timeout used for connections, or -1 for no timeout
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.- Specified by:
sendin interfaceSink- Parameters:
to- the destination to send tofromPort- I2CP source port, 0-65535toPort- I2CP destination port, 0-65535data- the data to send- Throws:
RuntimeException- if the session is closed