java.lang.Object
net.i2p.router.MessageValidator
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
FieldsModifier and TypeFieldDescriptionprivate final RouterContextThe router validating messages.private DecayingBloomFilterRecent message ids, to catch replays.private final LogLogger for this class.private static final longBits of the timestamp that form the filter's time window.Constructor Summary
ConstructorsConstructorDescriptionMessageValidator(RouterContext context) Registers the duplicate and expiry rate stats the validator reports into.Method Summary
Modifier and TypeMethodDescriptionprivate booleannoteReception(long messageId, long messageExpiration) Mark the message as having been received to detect duplicates.(package private) voidshutdown()Stop the message validator and clean up resources.voidstartup()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).
Field Details
_log
Logger for this class._context
The router validating messages._filter
Recent message ids, to catch replays.TIME_MASK
private static final long TIME_MASKBits of the timestamp that form the filter's time window.- See Also:
Constructor Details
MessageValidator
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
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 duplicateexpiration- the message expiry date in milliseconds since the epoch- Returns:
- reason why the message is invalid (or null if the message is valid)
validateMessage
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 identifiermessageExpiration- 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.