java.lang.Object
net.i2p.router.message.GarlicMessageReceiver

public class GarlicMessageReceiverextends Object
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.

  • Field Details

    • _context

      private final RouterContext _context
      The router receiving the message.
    • _log

      private final Log _log
      Logger for this class.
    • _receiver

      private final GarlicMessageReceiver.CloveReceiver _receiver
      Where the opened cloves are handed on.
    • _clientDestination

      private final Hash _clientDestination
      The client the message is for.
    • _decryptFailCount

      private static final AtomicInteger _decryptFailCount
      Rate-limited decrypt failure counter. Individual failures are logged at DEBUG; a summary WARN is emitted every FAIL_WARN_INTERVAL failures to keep the log usable during normal LeaseSet rotation.
    • FAIL_WARN_INTERVAL

      private static final int FAIL_WARN_INTERVAL
      Failures between warnings in the log.
      See Also:
  • Constructor Details

    • GarlicMessageReceiver

      public GarlicMessageReceiver(RouterContext context, GarlicMessageReceiver.CloveReceiver receiver)
      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

      public void receive(GarlicMessage message)
      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

      private void handleClove(GarlicClove clove)
      Validates a GarlicClove and, if valid, passes it to the configured receiver.
      Parameters:
      clove - The garlic clove to validate and handle.
    • isValid

      private boolean isValid(GarlicClove clove)
      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.