net.i2p.router.networkdb.kademlia

## Class LookupBanHammer

- java.lang.Object
- - net.i2p.router.networkdb.kademlia.LookupBanHammer

-     class LookupBanHammer
      extends Object

  Tracks the frequency of recent lookup requests targeting a specific reply peer/tunnel pair to provide basic denial-of-service (DOS) protection by banning excessive requesters.

  Uses burst detection over a sliding 1-second window and an overall lookup count threshold to decide when to ban peers. Bans last for a fixed duration and expire automatically.

  Thread-safe implementation utilizing concurrent data structures and finer-grained synchronization for improved performance under concurrent access.

  This mechanism is a partial DOS protection and does not prevent spoofed reply identifiers or multiple reply tunnels.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `LookupBanHammer()` Constructs a newly initialized LookupBanHammer instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) boolean` | `shouldBan(Hash key, TunnelId id)` Records a lookup request from a requester identified by key and tunnel ID, and determines whether the requester should be banned based on recent activity.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### LookupBanHammer

          LookupBanHammer()

      Constructs a newly initialized LookupBanHammer instance. Registers a periodic cleanup event to remove expired bans and reset counters.

  - ### Method Detail

    - #### shouldBan

          boolean shouldBan(Hash key,
                            TunnelId id)

      Records a lookup request from a requester identified by key and tunnel ID, and determines whether the requester should be banned based on recent activity.

      This method increments the request count for the requester, tracks burst-frequency within a sliding window, and enforces bans if thresholds are exceeded.

      Parameters:
        `key` - non-null Hash representing the requester identifying key
        `id` - TunnelId of the target reply tunnel, or null if direct lookups
      Returns:
        true if the requester is currently banned and should be blocked; false otherwise