Class RateLimiter

java.lang.Object
org.deltava.beans.system.RateLimiter

public class RateLimiter extends Object
A bean to track transaction volume by address and implement rate limiting.
Since:
11.6
Version:
11.6
Author:
Luke
  • Constructor Details

    • RateLimiter

      public RateLimiter(boolean doMerge, int minRequests, int minTime)
      Initializes the hunter.
      Parameters:
      doMerge - TRUE if requests should be assigned to their parent netblock, otherwise FALSE
      minRequests - the minimum number of requests
      minTime - the minimum amount of time in seconds
  • Method Details

    • load

      public void load(Collection<RequestCounter> data)
      Loads the limiter with data from an external source.
      Parameters:
      data - a Collection of RequestCounters
    • getMinRequests

      public int getMinRequests()
      Returns the minimum number of request required to be categorized as a Spider.
      Returns:
      the number of requests
    • getMinTime

      public Duration getMinTime()
      Returns the minimum time interval for Spider detection.
      Returns:
      the interval as a Duration
    • getCounters

      public List<RequestCounter> getCounters()
      Returns the request counters for each address.
      Returns:
      the request counters
    • setBlocking

      public void setBlocking(int reqs, int time)
      Sets whether the rate limiter should block high-volume clients.
      Parameters:
      reqs - the number of requests
      time - the block time in seconds
    • remove

      public void remove(String addr)
      Clears an address' totals.
      Parameters:
      addr - the remote address
    • get

      public RequestCounter get(String addr)
    • addAddress

      public RateLimiter.Result addAddress(String addr)
      Adds a remote address to the hunter.
      Parameters:
      addr - the remote address
      Returns:
      a Result
    • clear

      public void clear()
      Clears all statistics.
    • merge

      public Collection<RequestCounter> merge()
      Merges request counters based on their network blocks.
      Returns:
      the merged counters
    • purge

      public void purge()
      Purges all statistics exceeding the minimum detection time.