Package org.graylog2.utilities
Class CIDRPatriciaTrie
java.lang.Object
org.graylog2.utilities.CIDRPatriciaTrie
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a deep copy of this CIDRPatriciaTrie with any expired nodes removed.voidinsertCIDR(String cidr, String rangeName) voidinsertCIDR(String cidr, String rangeName, long expireAfter) Insert a CIDR range into the trie with a time-to-livelongestPrefixRangeLookupWithTtl(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.voidrecalculateShortestPrefix(boolean isIPV6) voidremoveCIDR(String cidr) Remove a CIDR range from the trie and cleanup any empty nodes after removal.
-
Constructor Details
-
CIDRPatriciaTrie
public CIDRPatriciaTrie()
-
-
Method Details
-
cleanCopy
Returns a deep copy of this CIDRPatriciaTrie with any expired nodes removed.- Returns:
- deep copy of this trie
-
insertCIDR
-
insertCIDR
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 addressrangeName- the name of the CIDR rangeexpireAfter- epoch time in millis after which the CIDR should be expired
-
longestPrefixRangeLookup
-
longestPrefixRangeLookupWithTtl
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 rangeslookupTimeMillis- 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
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)
-