java.lang.Object
net.i2p.client.streaming.impl.PacketQueue
All Implemented Interfaces:
Closeable, AutoCloseable, SendMessageStatusListener

class PacketQueueextends Object implements SendMessageStatusListener, Closeable
Queue out packets to be sent through the session. Well, that's the theory at least... in practice we just send them immediately with no blocking, since the mode=bestEffort doesn't block in the SDK.

MessageOutputStream -> ConnectionDataReceiver -> Connection -> PacketQueue -> I2PSession.

  • Field Details

    • _context

      private final I2PAppContext _context
      The app context.
    • _log

      private final Log _log
      Logger for the packet queue.
    • _cache

      private final ByteCache _cache
      Cache supplying the packet buffers.
    • _messageStatusMap

      private final Map<Long, Connection> _messageStatusMap
      Connections awaiting status, by message id.
    • _dead

      private volatile boolean _dead
      True once the queue is shut down.
    • FLAGS_INITIAL_TAGS

      private static final int FLAGS_INITIAL_TAGS
      Flags of the first tags packet.
      See Also:
    • FLAGS_FINAL_TAGS

      private static final int FLAGS_FINAL_TAGS
      Flags of the final tags packet.
      See Also:
    • INITIAL_TAGS_TO_SEND

      private static final int INITIAL_TAGS_TO_SEND
      Tags sent in the first packet.
      See Also:
    • MIN_TAG_THRESHOLD

      private static final int MIN_TAG_THRESHOLD
      Tags kept in hand before sending more.
      See Also:
    • TAG_WINDOW_FACTOR

      private static final int TAG_WINDOW_FACTOR
      Window share of the tags sent per packet.
      See Also:
    • FINAL_TAGS_TO_SEND

      private static final int FINAL_TAGS_TO_SEND
      Tags sent in the final packet.
      See Also:
    • FINAL_TAG_THRESHOLD

      private static final int FINAL_TAG_THRESHOLD
      Tags left before the final packet.
      See Also:
    • REMOVE_EXPIRED_TIME

      private static final long REMOVE_EXPIRED_TIME
      Interval of the expired message cleanup.
      See Also:
    • ENABLE_STATUS_LISTEN

      private static final boolean ENABLE_STATUS_LISTEN
      True to request the send status callbacks.
      See Also:
    • I2CP_EXPIRATION_ADJUST

      private static final long I2CP_EXPIRATION_ADJUST
      Latitude allowed on the I2CP expiration times.
    • TELEMETRY_SAMPLE_PERIOD

      private static final int TELEMETRY_SAMPLE_PERIOD
      Record every Nth send-size stat sample. Per-packet RateStat updates lock each period's Rate; these size stats are display-only telemetry, so sampling the aggregate (scaling the recorded value by the period) preserves the graph with a fraction of the monitor traffic.
      See Also:
    • _sendMsgSizeCnt

      private int _sendMsgSizeCnt
      Sample counters for the per-packet size stats (one per call site).
    • _sendDupMsgSizeCnt

      private int _sendDupMsgSizeCnt
      Times a duplicate message size was seen.
  • Constructor Details

    • PacketQueue

      public PacketQueue(I2PAppContext context, SimpleTimer2 timer)
      Opens the log, creates the status map and starts expiring old entries.
      Parameters:
      context - the application context, used for logging
      timer - timer used to schedule removal of expired status entries
  • Method Details

    • close

      public void close()
      Cannot be restarted.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • enqueue

      public boolean enqueue(PacketLocal packet)
      Add a new packet to be sent out ASAP. This updates the acks. keys and tags disabled since dropped in I2PSession.
      Parameters:
      packet - the packet to send ahead of the queue, updating the acks
      Returns:
      true if sent
    • messageStatus

      public void messageStatus(I2PSession session, long msgId, int status)
      SendMessageStatusListener interface

      Tell the client of an update in the send status for a message previously sent with I2PSession.sendMessage(Destination, byte[]). Multiple calls for a single message ID are possible.

      Specified by:
      messageStatus in interface SendMessageStatusListener
      Parameters:
      session - the session reporting the new status, not otherwise consulted
      msgId - message number returned from a previous sendMessage() call
      status - of the message, as defined in MessageStatusMessage and this class.