forked from I2P_Developers/i2p.i2p
Only inspect the last threshold.seconds when determining if there is a breach. Otherwise older breaches would be counted as current
This commit is contained in:
@@ -28,16 +28,20 @@ class AccessCounter {
|
||||
|
||||
/**
|
||||
* @param threshold definition of a threshold
|
||||
* @param now current time
|
||||
* @return true if the given threshold has been breached
|
||||
*/
|
||||
boolean isBreached(Threshold threshold) {
|
||||
boolean isBreached(Threshold threshold, long now) {
|
||||
if (threshold.getConnections() == 0)
|
||||
return !accesses.isEmpty();
|
||||
if (accesses.size() < threshold.getConnections())
|
||||
return false;
|
||||
|
||||
long ignoreOlder = now - threshold.getSeconds() * 1000;
|
||||
for (int i = 0; i <= accesses.size() - threshold.getConnections(); i++) {
|
||||
long start = accesses.get(i);
|
||||
if (start < ignoreOlder)
|
||||
continue;
|
||||
long end = start + threshold.getSeconds() * 1000;
|
||||
if (accesses.get(i + threshold.getConnections() -1) <= end)
|
||||
return true;
|
||||
|
@@ -123,13 +123,14 @@ class AccessFilter implements StatefulConnectionFilter {
|
||||
}
|
||||
|
||||
private void record() throws IOException {
|
||||
final long now = context.clock().now();
|
||||
for (Recorder recorder : definition.getRecorders()) {
|
||||
Threshold threshold = recorder.getThreshold();
|
||||
File file = recorder.getFile();
|
||||
Set<String> breached = new HashSet<String>();
|
||||
synchronized(unknownDests) {
|
||||
for (DestTracker tracker : unknownDests.values()) {
|
||||
if (!tracker.getCounter().isBreached(threshold))
|
||||
if (!tracker.getCounter().isBreached(threshold, now))
|
||||
continue;
|
||||
breached.add(tracker.getHash().toBase32());
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ class DestTracker {
|
||||
*/
|
||||
synchronized boolean recordAccess(long now) {
|
||||
counter.recordAccess(now);
|
||||
return counter.isBreached(threshold);
|
||||
return counter.isBreached(threshold,now);
|
||||
}
|
||||
|
||||
synchronized boolean purge(long olderThan) {
|
||||
|
Reference in New Issue
Block a user