java.lang.Object
net.i2p.router.MessageValidator

public class MessageValidatorextends Object
Singleton to manage the logic (and historical data) to determine whether a message is valid or not (meaning it isn't expired and hasn't already been received). We'll need a revamp once we start dealing with long message expirations (since it might involve keeping a significant number of entries in memory), but that probably won't be necessary until I2P 3.0.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final RouterContext
    The router validating messages.
    Recent message ids, to catch replays.
    private final Log
    Logger for this class.
    private static final long
    Bits of the timestamp that form the filter's time window.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Registers the duplicate and expiry rate stats the validator reports into.
  • Method Summary

    Modifier and Type
    Method
    Description
    private boolean
    noteReception(long messageId, long messageExpiration)
    Mark the message as having been received to detect duplicates.
    (package private) void
    Stop the message validator and clean up resources.
    void
    Start the message validator, initializing the duplicate detection filter.
    validateMessage(long expiration)
    Only check the expiration for the message.
    validateMessage(long messageId, long expiration)
    Determine if this message should be accepted as valid (not expired, not a duplicate).

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _log

      private final Log _log
      Logger for this class.
    • _context

      private final RouterContext _context
      The router validating messages.
    • _filter

      private DecayingBloomFilter _filter
      Recent message ids, to catch replays.
    • TIME_MASK

      private static final long TIME_MASK
      Bits of the timestamp that form the filter's time window.
      See Also:
  • Constructor Details

    • MessageValidator

      public MessageValidator(RouterContext context)
      Registers the duplicate and expiry rate stats the validator reports into.
      Parameters:
      context - the router context supplying the log, clock and stats used to validate messages
  • Method Details

    • validateMessage

      public String validateMessage(long messageId, long expiration)
      Determine if this message should be accepted as valid (not expired, not a duplicate).
      Parameters:
      messageId - the message ID to remember as received, so a second copy with the same ID is rejected as a duplicate
      expiration - the message expiry date in milliseconds since the epoch
      Returns:
      reason why the message is invalid (or null if the message is valid)
    • validateMessage

      public String validateMessage(long expiration)
      Only check the expiration for the message.
      Parameters:
      expiration - the message expiry date in milliseconds since the epoch, compared against the current time with the clock fudge factor
      Returns:
      reason why the message is invalid (or null if the message is valid)
    • noteReception

      private boolean noteReception(long messageId, long messageExpiration)
      Mark the message as having been received to detect duplicates. Uses a decaying bloom filter to track recently received messages.
      Parameters:
      messageId - the unique message identifier
      messageExpiration - the expiration time of the message
      Returns:
      true if we have already seen this message (duplicate), false if new
    • startup

      public void startup()
      Start the message validator, initializing the duplicate detection filter.
    • shutdown

      void shutdown()
      Stop the message validator and clean up resources.