public class DecayingBloomFilter extends Object
Provides a series of Bloom filters with automatic time-based decay to handle time-sensitive data with minimal false positive rates. Uses fixed-size buffers with periodic switching to maintain consistent memory usage while allowing high-throughput operations.
Optimized for scenarios requiring hundreds of entries per second with virtually no false positive rate. Memory usage is carefully controlled through configurable filter parameters and buffer sizes.
Performance characteristics:
Suitable for high-throughput applications like message validation, tunnel IV filtering, and router message processing where memory efficiency and low false positive rates are critical.
DecayingHashSet,
BloomFilterIVValidator| Modifier and Type | Field and Description |
|---|---|
protected I2PAppContext | _contextThe I2P app context |
protected AtomicLong | _currentDuplicatesCounter for current duplicates |
protected SimpleTimer2.TimedEvent | _decayEventThe decay timer event |
protected int | _durationMsDuration of each filter in ms |
protected int | _entryBytesSize of entries in bytes |
protected boolean | _keepDecayingWhether decay is still running |
protected Log | _logThe logger |
protected String | _namejust for logging |
protected ReentrantReadWriteLock | _reorganizeLocksynchronize against this lock when switching double buffers |
| Modifier | Constructor and Description |
|---|---|
| DecayingBloomFilter(I2PAppContext context,
int durationMs,
int entryBytes)Create a bloom filter that will decay its entries over time. |
| DecayingBloomFilter(I2PAppContext context,
int durationMs,
int entryBytes,
String name)Uses default m of 23, memory usage is 2 MB. |
| DecayingBloomFilter(I2PAppContext context,
int durationMs,
int entryBytes,
String name,
int m)Memory usage is 2 * (2**m) bits or 2**(m-2) bytes. |
protected | DecayingBloomFilter(int durationMs,
int entryBytes,
String name,
I2PAppContext context)Only for extension by DecayingHashSet |
| Modifier and Type | Method and Description |
|---|---|
boolean | add(byte[] entry)Add a byte array entry to the filter |
boolean | add(byte[] entry,
int off,
int len)Add a byte array entry at the specified offset and length |
boolean | add(long entry)Add a long entry to the filter. |
void | clear()Clear all filters and reset counts |
protected void | decay()decay. |
long | getCurrentDuplicateCount() |
double | getFalsePositiveRate()Get the false positive rate |
int | getInsertedCount()unsynchronized but only used for logging elsewhere |
protected void | getReadLock()Acquire the read lock |
protected boolean | getWriteLock()Acquire the write lock |
boolean | isKnown(long entry)Check if an entry is already known without adding it |
protected void | releaseReadLock()Release the read lock |
protected void | releaseWriteLock()Release the write lock |
void | stopDecaying()Stop the decay process |
protected final I2PAppContext _context
protected final AtomicLong _currentDuplicates
protected final SimpleTimer2.TimedEvent _decayEvent
protected final int _durationMs
protected final int _entryBytes
protected volatile boolean _keepDecaying
protected final Log _log
protected final String _name
protected final ReentrantReadWriteLock _reorganizeLock
public DecayingBloomFilter(I2PAppContext context, int durationMs, int entryBytes)
context - the I2P app contextdurationMs - entries last for at least this long, but no more than twice this longentryBytes - how large are the entries to be added? if this is less than 32 bytes,
the entries added will be expanded by concatenating their XORing
against with sufficient random values.public DecayingBloomFilter(I2PAppContext context, int durationMs, int entryBytes, String name)
context - the I2P app contextdurationMs - entries last for at least this longentryBytes - how large are the entriesname - just for logging / debugging / statspublic DecayingBloomFilter(I2PAppContext context, int durationMs, int entryBytes, String name, int m)
context - the I2P app contextdurationMs - entries last for at least this longentryBytes - how large are the entriesname - filter name for loggingm - filter size exponent, max is 29protected DecayingBloomFilter(int durationMs,
int entryBytes,
String name,
I2PAppContext context)durationMs - entries last for at least this longentryBytes - how large are the entriesname - filter name for loggingcontext - the I2P app contextpublic boolean add(byte[] entry)
entry - the entry to addpublic boolean add(byte[] entry,
int off,
int len)entry - the entry dataoff - the offsetlen - the lengthpublic boolean add(long entry)
entry - the long value to addpublic void clear()
protected void decay()
public long getCurrentDuplicateCount()
public double getFalsePositiveRate()
public int getInsertedCount()
protected void getReadLock()
protected boolean getWriteLock()
public boolean isKnown(long entry)
entry - the long value to checkprotected void releaseReadLock()
protected void releaseWriteLock()
public void stopDecaying()