java.lang.Object
net.i2p.router.tunnel.TrivialPreprocessor
net.i2p.router.tunnel.BatchedPreprocessor
net.i2p.router.tunnel.BatchedRouterPreprocessor
- All Implemented Interfaces:
TunnelGateway.QueuePreprocessor
Honor the 'batchFrequency' tunnel pool setting or the '
router.batchFrequency' router config setting, and track fragmentation.Field Summary
Modifier and TypeFieldDescriptionprivate final TunnelCreatorConfigThe tunnel the batch is built for.protected final HopConfigThe hop config for inbound gateways.private final longDelay before the first batch is sent, in ms.static final intFor IBGWs for efficiency (not our data).static final intFor client OBGWs only (our data).static final intFor exploratory OBGWs only (our tunnel tests and build messages).static final StringHow frequently should we flush non-full messages, in milliseconds This goes in I2CP custom options for the pool.static final StringThis goes in router advanced config.Fields inherited from class BatchedPreprocessor
DEFAULT_DELAY, MIN_FLUSH_DELAYModifier and TypeFieldDescription(package private) static longNot final or private so the test code can adjust.(package private) static final longMinimum delay even under full pressure (ms) -- avoids busy-wait retry storms.Fields inherited from class TrivialPreprocessor
_context, _dataCache, _log, IV_SIZE, PREPROCESSED_SIZEModifier and TypeFieldDescriptionprotected final RouterContextThe router context.protected static final ByteCacheHere in tunnels, we take from the cache but never add to it.protected final LogThe logger.protected static final intLength of the IV.static final intSize of preprocessed data blocks.Constructor Summary
ConstructorsConstructorDescriptionBatchedRouterPreprocessor(RouterContext ctx, HopConfig cfg) Create a preprocessor for inbound gateway tunnels.Create a preprocessor for outbound gateway tunnels.Method Summary
Modifier and TypeMethodDescriptionprivate static StringNames a hop for the log.private static StringNames a tunnel for the log.protected longHow long we should wait before flushing a batch.private longChooses the delay before the first batch is sent, extending the batching time for exploratory OBGWs: they carry many small tunnel test messages and build messages that don't fit perfectly, and those are not as delay-sensitive.protected voidnotePreprocessing(long messageId, int numFragments, int totalLength, List<Long> messageIds, String msg) Note preprocessing statistics.Methods inherited from class BatchedPreprocessor
getDelayAmount, preprocessQueue, sendModifier and TypeMethodDescriptionlongHow long to wait before flushing a queued message.booleanpreprocessQueue(List<PendingGatewayMessage> pending, TunnelGateway.Sender sender, TunnelGateway.Receiver rec) Return true if there were messages remaining, and we should queue up a delayed flush to clear themprotected voidsend(List<PendingGatewayMessage> pending, int startAt, int sendThrough, TunnelGateway.Sender sender, TunnelGateway.Receiver rec) Preprocess the messages from the pending list, grouping items startAt through sendThrough (though only part of the last one may be fully sent), delivering them through the sender/receiver.Methods inherited from class TrivialPreprocessor
getInstructionAugmentationSize, getInstructionsSize, preprocess, writeFirstFragment, writeSubsequentFragmentModifier and TypeMethodDescriptionprotected static intgetInstructionAugmentationSize(PendingGatewayMessage msg, int offset, int instructionsSize) Get the augmentation size for instructions if fragmentation is needed.protected static intCalculate the size of the instructions for a pending message.protected voidpreprocess(byte[] fragments, int fragmentLength) Wrap the preprocessed fragments with the necessary padding / checksums to act as a tunnel message.protected intwriteFirstFragment(PendingGatewayMessage msg, byte[] target, int offset) Write the first fragment of a tunnel message.protected intwriteSubsequentFragment(PendingGatewayMessage msg, byte[] target, int offset) Write a subsequent fragment of a tunnel message.
Field Details
_config
The tunnel the batch is built for._hopConfig
The hop config for inbound gateways._sendDelay
private final long _sendDelayDelay before the first batch is sent, in ms.PROP_BATCH_FREQUENCY
How frequently should we flush non-full messages, in milliseconds This goes in I2CP custom options for the pool. Only applies to OBGWs.- See Also:
PROP_ROUTER_BATCH_FREQUENCY
This goes in router advanced config.- See Also:
OB_CLIENT_BATCH_FREQ
public static final int OB_CLIENT_BATCH_FREQFor client OBGWs only (our data).OB_EXPL_BATCH_FREQ
public static final int OB_EXPL_BATCH_FREQFor exploratory OBGWs only (our tunnel tests and build messages).DEFAULT_BATCH_FREQUENCY
public static final int DEFAULT_BATCH_FREQUENCYFor IBGWs for efficiency (not our data).
Constructor Details
BatchedRouterPreprocessor
Create a preprocessor for outbound gateway tunnels.- Parameters:
ctx- the router contextcfg- the tunnel creator config
BatchedRouterPreprocessor
Create a preprocessor for inbound gateway tunnels.- Parameters:
ctx- the router contextcfg- the hop config
Method Details
getName
getName
Names a tunnel for the log.- Parameters:
cfg- the tunnel's configuration- Returns:
- the name to show
getSendDelay
protected long getSendDelay()How long we should wait before flushing a batch.- Overrides:
getSendDelayin classBatchedPreprocessor- Returns:
- the send delay, in ms
initialSendDelay
private long initialSendDelay()Chooses the delay before the first batch is sent, extending the batching time for exploratory OBGWs: they carry many small tunnel test messages and build messages that don't fit perfectly, and those are not as delay-sensitive. Config changes are not picked up after the preprocessor is created, but a preprocessor's lifetime is only 10 minutes, so just wait.- Returns:
- the delay, in ms
notePreprocessing
protected void notePreprocessing(long messageId, int numFragments, int totalLength, List<Long> messageIds, String msg) Description copied from class:TrivialPreprocessorNote preprocessing statistics. No-op - intentionally empty.- Overrides:
notePreprocessingin classTrivialPreprocessor- Parameters:
messageId- the message this fragment carries data fornumFragments- the fragment number within that messagetotalLength- the total length of the message the fragment belongs tomessageIds- the message ids of everything coalesced into this fragmentmsg- a description of the flush event, for debugging output