Class CIDRPatriciaTrie

java.lang.Object
org.graylog2.utilities.CIDRPatriciaTrie

public class CIDRPatriciaTrie extends Object
PatriciaTrie used to for efficient lookups in CIDR data adapters. NOTE: This class is NOT thread-safe. Use cleanCopy() to clone the trie, make modifications, and then atomically replace the in-use copy if needed.
  • Constructor Details

    • CIDRPatriciaTrie

      public CIDRPatriciaTrie()
  • Method Details

    • cleanCopy

      public CIDRPatriciaTrie cleanCopy()
      Returns a deep copy of this CIDRPatriciaTrie with any expired nodes removed.
      Returns:
      deep copy of this trie
    • insertCIDR

      public void insertCIDR(String cidr, String rangeName)
    • insertCIDR

      public void insertCIDR(String cidr, String rangeName, long expireAfter)
      Insert a CIDR range into the trie with a time-to-live
      Parameters:
      cidr - properly formatted CIDR address (must include '/rangePrefix' even if it is a single address
      rangeName - the name of the CIDR range
      expireAfter - epoch time in millis after which the CIDR should be expired
    • longestPrefixRangeLookup

      public String longestPrefixRangeLookup(String ip)
    • longestPrefixRangeLookupWithTtl

      public String longestPrefixRangeLookupWithTtl(String ip, long lookupTimeMillis)
      Returns the rangeName of the range with the longest prefix that contains the IP address or null if one does not exist.
      Parameters:
      ip - IP address to check against the collection of ranges
      lookupTimeMillis - time lookup was performed in epoch time milliseconds or 0 if node expiry is not a concern
      Returns:
      the name of the range with the longest prefix that contains the IP if it exists, null otherwise
    • removeCIDR

      public void removeCIDR(String cidr)
      Remove a CIDR range from the trie and cleanup any empty nodes after removal.
      Parameters:
      cidr - range to remove
    • recalculateShortestPrefix

      public void recalculateShortestPrefix(boolean isIPV6)