java.lang.Object
net.i2p.router.transport.ntcp.NTCPConnection.BlockPool
Enclosing class:
NTCPConnection

static class NTCPConnection.BlockPoolextends Object
Reusable NTCP2 payload block list and blocks, per writer thread. The list and the pooled blocks are only used within the prepareNextWriteNTCP2(), sendRouterInfo(), and sendTermination() call stacks, so no other thread can observe or modify them mid-write. Package-private for testing.
  • Field Details

  • Constructor Details

    • BlockPool

      BlockPool()
      A pool with nothing reclaimed yet; all three lists start empty and grow only through release(List).
  • Method Details

    • acquireI2NP

      Get an I2NP block, reusing a pooled one if available.
      Parameters:
      m - the message the block will carry on the wire
      Returns:
      a pooled block rebound to the message, or a newly allocated one
    • acquirePadding

      NTCP2Payload.PaddingBlock acquirePadding(int size)
      Get a padding block, reusing a pooled one if available.
      Parameters:
      size - the number of padding bytes the block must hold
      Returns:
      a pooled block resized to the requested length, or a newly allocated one
    • release

      void release(List<NTCP2Payload.Block> blocks)
      Return the pooled block types to the pool; other types are dropped.
      Parameters:
      blocks - the blocks written this frame, to be reclaimed for later reuse