java.lang.Object
net.i2p.router.crypto.ratchet.ECIESAEADEngine.BlockPool
- Enclosing class:
ECIESAEADEngine
Per-thread pool of payload block objects and the block list, to avoid allocation per outbound payload.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<RatchetPayload.AckBlock> Pooled ack blocks.private final List<RatchetPayload.AckRequestBlock> Pooled ack-request blocks.private final List<RatchetPayload.Block> Blocks taken from the pool, returned on release.private final List<RatchetPayload.GarlicBlock> Pooled garlic blocks.private final List<RatchetPayload.DateTimeBlock> Pooled datetime blocks.private final List<RatchetPayload.NextKeyBlock> Pooled next-key blocks.private final List<RatchetPayload.PaddingBlock> Pooled padding blocks.Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescription(package private) RatchetPayload.AckBlockacquireAck(List<Integer> acks) Take a pooled AckBlock for these acknowledgements, or allocate one.(package private) RatchetPayload.AckRequestBlockTake a pooled AckRequestBlock, or allocate one.(package private) RatchetPayload.GarlicBlockacquireClove(GarlicClove clove) Take a pooled GarlicBlock for this clove, or allocate one.(package private) RatchetPayload.DateTimeBlockacquireDateTime(long time) Take a pooled DateTimeBlock for this expiry, or allocate one.(package private) RatchetPayload.NextKeyBlockacquireNextKey(NextSessionKey nextKey) Take a pooled NextKeyBlock for this key, or allocate one.(package private) RatchetPayload.PaddingBlockacquirePadding(int size) Take a pooled PaddingBlock of this size, or allocate one.(package private) List<RatchetPayload.Block> The reusable block list, already cleared.(package private) voidrelease(List<RatchetPayload.Block> blocks) Return all blocks to their pools and clear the list.
Field Details
blocks
Blocks taken from the pool, returned on release.cloveBlocks
Pooled garlic blocks.paddingBlocks
Pooled padding blocks.datetimeBlocks
Pooled datetime blocks.nextKeyBlocks
Pooled next-key blocks.ackBlocks
Pooled ack blocks.ackReqBlocks
Pooled ack-request blocks.
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
List<RatchetPayload.Block> 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
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
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
RatchetPayload.AckRequestBlock acquireAckReq()Take a pooled AckRequestBlock, or allocate one.- Returns:
- an empty AckRequestBlock, asking the recipient to acknowledge
release
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