java.lang.Object
net.i2p.router.transport.ntcp.NTCPConnection.BlockPool
- Enclosing class:
NTCPConnection
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 Summary
FieldsModifier and TypeFieldDescription(package private) final List<NTCP2Payload.Block> Blocks allocated for the frame being built.private final List<NTCP2Payload.I2NPBlock> I2NP blocks of the payload being built.private final List<NTCP2Payload.PaddingBlock> Padding blocks of the payload being built.Constructor Summary
ConstructorsConstructorDescriptionA pool with nothing reclaimed yet; all three lists start empty and grow only throughrelease(List).Method Summary
All MethodsModifier and TypeMethodDescription(package private) NTCP2Payload.I2NPBlockGet an I2NP block, reusing a pooled one if available.(package private) NTCP2Payload.PaddingBlockacquirePadding(int size) Get a padding block, reusing a pooled one if available.(package private) voidrelease(List<NTCP2Payload.Block> blocks) Return the pooled block types to the pool; other types are dropped.
Field Details
blocks
Blocks allocated for the frame being built.i2npBlocks
I2NP blocks of the payload being built.paddingBlocks
Padding blocks of the payload being built.
Constructor Details
BlockPool
BlockPool()A pool with nothing reclaimed yet; all three lists start empty and grow only throughrelease(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
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
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