## net.i2p.router.tunnel
Class TrivialPreprocessor

    java.lang.Object
      net.i2p.router.tunnel.TrivialPreprocessor

All Implemented Interfaces:
  TunnelGateway.QueuePreprocessor

Direct Known Subclasses:
  BatchedPreprocessor, TrivialRouterPreprocessor

    public class TrivialPreprocessor

extends Object
implements TunnelGateway.QueuePreprocessor

Do the simplest thing possible for preprocessing - for each message available, turn it into the minimum number of fragmented preprocessed blocks, sending each of those out. This does not coallesce message fragments or delay for more optimal throughput. See FragmentHandler Javadoc for tunnel message fragment format

Field Summary
`protected RouterContext` `_context`
`protected static ByteCache` `_dataCache` Here in tunnels, we take from the cache but never add to it.
`protected Log` `_log`
`protected static int` `IV_SIZE`
`static int` `PREPROCESSED_SIZE`

Constructor Summary
`TrivialPreprocessor(RouterContext ctx)`

Method Summary
`long` `getDelayAmount()` how long do we want to wait before flushing
`protected int` `getInstructionAugmentationSize(TunnelGateway.Pending msg, int offset, int instructionsSize)`
`protected int` `getInstructionsSize(TunnelGateway.Pending msg)`
`protected void` `notePreprocessing(long messageId, int numFragments, int totalLength, List<Long> messageIds, String msg)`
`protected void` `preprocess(byte[] fragments, int fragmentLength)` Wrap the preprocessed fragments with the necessary padding / checksums to act as a tunnel message.
`boolean` `preprocessQueue(List<TunnelGateway.Pending> pending, TunnelGateway.Sender sender, TunnelGateway.Receiver rec)` Return true if there were messages remaining, and we should queue up a delayed flush to clear them NOTE: Unused here, see BatchedPreprocessor override, super is not called.
`protected int` `writeFirstFragment(TunnelGateway.Pending msg, byte[] target, int offset)`
`protected int` `writeSubsequentFragment(TunnelGateway.Pending msg, byte[] target, int offset)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### _context

    protected RouterContext _context

### _log

    protected Log _log

### PREPROCESSED_SIZE

    public static final int PREPROCESSED_SIZE

See Also:
  Constant Field Values

### IV_SIZE

    protected static final int IV_SIZE

See Also:
  Constant Field Values

### _dataCache

    protected static final ByteCache _dataCache

  Here in tunnels, we take from the cache but never add to it. In other words, we take advantage of other places in the router also using 1024-byte ByteCaches (since ByteCache only maintains once instance for each size) Used in BatchedPreprocessor; see add'l comments there

Constructor Detail

### TrivialPreprocessor

    public TrivialPreprocessor(RouterContext ctx)

Method Detail

### getDelayAmount

    public long getDelayAmount()

  how long do we want to wait before flushing

  Specified by:
    `getDelayAmount` in interface `TunnelGateway.QueuePreprocessor`

### preprocessQueue

    public boolean preprocessQueue(List<TunnelGateway.Pending> pending,
                                   TunnelGateway.Sender sender,
                                   TunnelGateway.Receiver rec)

  Return true if there were messages remaining, and we should queue up a delayed flush to clear them NOTE: Unused here, see BatchedPreprocessor override, super is not called.

  Specified by:
    `preprocessQueue` in interface `TunnelGateway.QueuePreprocessor`
  Parameters:
    `pending` - list of Pending objects for messages either unsent or partly sent. This list should be update with any values removed (the preprocessor owns the lock) Messages are not removed from the list until actually sent. The status of unsent and partially-sent messages is stored in the Pending structure.
  Returns:
    true if we should delay before preprocessing again

### notePreprocessing

    protected void notePreprocessing(long messageId,
                                     int numFragments,
                                     int totalLength,
                                     List<Long> messageIds,
                                     String msg)

### preprocess

    protected void preprocess(byte[] fragments,
                              int fragmentLength)

  Wrap the preprocessed fragments with the necessary padding / checksums to act as a tunnel message.

  Parameters:
    `fragmentLength` - fragments[0:fragmentLength] is used

### writeFirstFragment

    protected int writeFirstFragment(TunnelGateway.Pending msg,
                                     byte[] target,
                                     int offset)

### writeSubsequentFragment

    protected int writeSubsequentFragment(TunnelGateway.Pending msg,
                                          byte[] target,
                                          int offset)

### getInstructionsSize

    protected int getInstructionsSize(TunnelGateway.Pending msg)

  Returns:
    generally 3 or 35 or 39 for first fragment, 7 for subsequent fragments. Does NOT include 4 for the message ID if the message will be fragmented; call getInstructionAugmentationSize() for that.

### getInstructionAugmentationSize

    protected int getInstructionAugmentationSize(TunnelGateway.Pending msg,
                                                 int offset,
                                                 int instructionsSize)

  Returns:
    0 or 4