java.lang.Object
net.i2p.router.message.GarlicMessageReceiver
Handles the reception and decryption of GarlicMessages. Decrypts the garlic message using the appropriate keys, validates each garlic clove, and passes valid cloves to the configured
GarlicMessageReceiver.CloveReceiver for dispatch.This class supports decryption keys of various types including ElGamal, ECIES, and PQ keys, and performs key selection based on availability.
The receiver can be configured to target a specific client destination, allowing session-key and tunnel settings to be applied accordingly.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for handling decrypted garlic cloves.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final HashThe client the message is for.private final RouterContextThe router receiving the message.private static final AtomicIntegerRate-limited decrypt failure counter.private final LogLogger for this class.private final GarlicMessageReceiver.CloveReceiverWhere the opened cloves are handed on.private static final intFailures between warnings in the log.Constructor Summary
ConstructorsConstructorDescriptionGarlicMessageReceiver(RouterContext context, GarlicMessageReceiver.CloveReceiver receiver) Garlic message receiver that does not target a specific client destination.GarlicMessageReceiver(RouterContext context, GarlicMessageReceiver.CloveReceiver receiver, Hash clientDestination) Garlic message receiver targeting a specific client destination.Method Summary
Modifier and TypeMethodDescriptionprivate voidhandleClove(GarlicClove clove) Validates a GarlicClove and, if valid, passes it to the configured receiver.private booleanisValid(GarlicClove clove) Checks if the given clove is valid according to expiration and message validation rules.voidreceive(GarlicMessage message) Processes a received GarlicMessage by attempting to decrypt it with the appropriate keys.
Field Details
_context
The router receiving the message._log
Logger for this class._receiver
Where the opened cloves are handed on._clientDestination
The client the message is for._decryptFailCount
Rate-limited decrypt failure counter. Individual failures are logged at DEBUG; a summary WARN is emitted everyFAIL_WARN_INTERVALfailures to keep the log usable during normal LeaseSet rotation.FAIL_WARN_INTERVAL
private static final int FAIL_WARN_INTERVALFailures between warnings in the log.- See Also:
Constructor Details
GarlicMessageReceiver
Garlic message receiver that does not target a specific client destination.- Parameters:
context- The router context containing necessary services.receiver- The non-null CloveReceiver to handle valid cloves.
GarlicMessageReceiver
public GarlicMessageReceiver(RouterContext context, GarlicMessageReceiver.CloveReceiver receiver, Hash clientDestination) Garlic message receiver targeting a specific client destination.- Parameters:
context- The router context containing necessary services.receiver- The non-null CloveReceiver to handle valid cloves.clientDestination- The client destination hash this receiver targets, or null to target self.
Method Details
receive
Processes a received GarlicMessage by attempting to decrypt it with the appropriate keys. Valid cloves are passed to the configured CloveReceiver. If decryption fails, statistics and message history are updated accordingly.- Parameters:
message- The incoming GarlicMessage to be processed.
handleClove
Validates a GarlicClove and, if valid, passes it to the configured receiver.- Parameters:
clove- The garlic clove to validate and handle.
isValid
Checks if the given clove is valid according to expiration and message validation rules. Logs debug or warning messages if invalid.- Parameters:
clove- The garlic clove to validate.- Returns:
- true if the clove is valid; false otherwise.