java.lang.Object
net.i2p.router.transport.udp.UDPReceiver

class UDPReceiverextends Object
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.

  • Field Details

    • _context

      private final RouterContext _context
      The router context.
    • _log

      private final Log _log
      Logger for the UDP receiver.
    • _socket

      private final DatagramSocket _socket
      The socket being read.
    • _name

      private String _name
      Thread name of the receiver.
    • _keepRunning

      private volatile boolean _keepRunning
      True while the receiver should run.
    • _runner

      private final UDPReceiver.Runner _runner
      The thread reading the socket.
    • _transport

      private final UDPTransport _transport
      The transport that owns this receiver.
    • _handler

      private final PacketHandler _handler
      Handler of the received packets.
    • _endpoint

      private final SocketListener _endpoint
      Listener for the socket events.
    • _bandwidthRequest

      private FIFOBandwidthLimiter.Request _bandwidthRequest
      Reused inbound bandwidth request, only touched on the runner thread.
    • IS_ANDROID

      private static final boolean IS_ANDROID
      True when running on Android.
    • THROTTLE_WAIT_MS

      private static final int THROTTLE_WAIT_MS
      How 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 statistics
      transport - the transport whose PacketHandler queue receives the inbound packets
      socket - the bound datagram socket the receiver thread reads from
      name - the thread name to give the receiver thread
      lsnr - 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

      private int receive(UDPPacket packet)
      Receive a UDP packet.
      Parameters:
      packet - the received packet to process
      Returns:
      zero (was queue size)
    • doReceive

      private final int doReceive(UDPPacket packet)
      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)