java.lang.Object
net.i2p.router.transport.udp.UDPReceiver
Receives raw UDP datagrams off the wire as fast as possible, controlled by the bandwidth limiter and the router's throttle. Pushes received packets into the PacketHandler queue.
There is a UDPReceiver for each UDPEndpoint. It contains a thread but no queue. Received packets are queued in the common PacketHandler queue.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classThread reading packets off the socket.Field Summary
FieldsModifier and TypeFieldDescriptionprivate FIFOBandwidthLimiter.RequestReused inbound bandwidth request, only touched on the runner thread.private final RouterContextThe router context.private final SocketListenerListener for the socket events.private final PacketHandlerHandler of the received packets.private booleanTrue while the receiver should run.private final LogLogger for the UDP receiver.private StringThread name of the receiver.private final UDPReceiver.RunnerThe thread reading the socket.private final DatagramSocketThe socket being read.private final UDPTransportThe transport that owns this receiver.private static final booleanTrue when running on Android.private static final intHow long to sleep between throttle checks while inbound is throttled.Constructor Summary
ConstructorsConstructorDescriptionUDPReceiver(RouterContext ctx, UDPTransport transport, DatagramSocket socket, String name, SocketListener lsnr) Constructor name parameter.Method Summary
Field Details
_context
The router context._log
Logger for the UDP receiver._socket
The socket being read._name
Thread name of the receiver._keepRunning
private volatile boolean _keepRunningTrue while the receiver should run._runner
The thread reading the socket._transport
The transport that owns this receiver._handler
Handler of the received packets._endpoint
Listener for the socket events._bandwidthRequest
Reused inbound bandwidth request, only touched on the runner thread.IS_ANDROID
private static final boolean IS_ANDROIDTrue when running on Android.THROTTLE_WAIT_MS
private static final int THROTTLE_WAIT_MSHow long to sleep between throttle checks while inbound is throttled.- See Also:
Constructor Details
UDPReceiver
public UDPReceiver(RouterContext ctx, UDPTransport transport, DatagramSocket socket, String name, SocketListener lsnr) Constructor name parameter.- Parameters:
ctx- the router context supplying the log and rate statisticstransport- the transport whose PacketHandler queue receives the inbound packetssocket- the bound datagram socket the receiver thread reads fromname- the thread name to give the receiver threadlsnr- the socket listener that owns this receiver and supplies the endpoint
Method Details
startup
public void startup()Cannot be restarted (socket is final).shutdown
public void shutdown()Stop the receiver thread and cease reading from the socket.receive
Receive a UDP packet.- Parameters:
packet- the received packet to process- Returns:
- zero (was queue size)
doReceive
BLOCKING if queue between here and PacketHandler is full.- Parameters:
packet- the received packet, queued for processing or released if it is invalid or from a drop-listed peer- Returns:
- zero (was queue size)