java.lang.Object
net.i2p.router.crypto.ratchet.ECIESAEADEngine.BlockPool
Enclosing class:
ECIESAEADEngine

static class ECIESAEADEngine.BlockPoolextends Object
Per-thread pool of payload block objects and the block list, to avoid allocation per outbound payload.
  • Field Details

  • Constructor Details

    • BlockPool

      BlockPool()
      Constructs an empty pool. Every list is initialised inline, so a bare instance is immediately usable by the acquire methods.
  • Method Details

    • getBlocks

      The reusable block list, already cleared.
      Returns:
      the empty mutable list the caller fills with this payload's blocks
    • acquireClove

      Take a pooled GarlicBlock for this clove, or allocate one.
      Parameters:
      clove - the clove to wrap, borrowed for the payload's lifetime
      Returns:
      a GarlicBlock holding clove, ready to be serialized
    • acquirePadding

      RatchetPayload.PaddingBlock acquirePadding(int size)
      Take a pooled PaddingBlock of this size, or allocate one.
      Parameters:
      size - the padding length in bytes, 0 or more
      Returns:
      a PaddingBlock writing that many zero bytes
    • acquireDateTime

      RatchetPayload.DateTimeBlock acquireDateTime(long time)
      Take a pooled DateTimeBlock for this expiry, or allocate one.
      Parameters:
      time - the expiry in ms since the epoch (4-byte seconds on the wire)
      Returns:
      a DateTimeBlock carrying time
    • acquireNextKey

      Take a pooled NextKeyBlock for this key, or allocate one.
      Parameters:
      nextKey - the next ratchet key to hand to the recipient
      Returns:
      a NextKeyBlock carrying nextKey
    • acquireAck

      Take a pooled AckBlock for these acknowledgements, or allocate one.
      Parameters:
      acks - the packed acks, each id << 16 | n, for the messages being acknowledged
      Returns:
      an AckBlock listing acks, in the order given
    • acquireAckReq

      Take a pooled AckRequestBlock, or allocate one.
      Returns:
      an empty AckRequestBlock, asking the recipient to acknowledge
    • release

      void release(List<RatchetPayload.Block> blocks)
      Return all blocks to their pools and clear the list.

      A pooled block is handed back with whatever it last carried still reachable from it, so the reference-holding types are cleared on the way in: a GarlicBlock pins the whole clove and everything the clove holds, and a NextKeyBlock pins a live session key. The pools are per-thread, so an uncleared block keeps that object for the life of the transport thread. Every acquire re-arms the field before the block is returned to the caller, so a cleared block is never read.

      Parameters:
      blocks - the block list to recycle, emptied by this call