Changeset 904bf2a for apps


Ignore:
Timestamp:
Apr 6, 2019 3:35:20 PM (12 months ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
cca68f9
Parents:
8a001ad
Message:

Only inspect the last threshold.seconds when determining if there is a breach. Otherwise older breaches would be counted as current

Location:
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/AccessCounter.java

    r8a001ad r904bf2a  
    2929    /**
    3030     * @param threshold definition of a threshold
     31     * @param now current time
    3132     * @return true if the given threshold has been breached
    3233     */
    33     boolean isBreached(Threshold threshold) {
     34    boolean isBreached(Threshold threshold, long now) {
    3435        if (threshold.getConnections() == 0)
    3536            return !accesses.isEmpty();
     
    3738            return false;
    3839       
     40        long ignoreOlder = now - threshold.getSeconds() * 1000;
    3941        for (int i = 0; i <= accesses.size() - threshold.getConnections(); i++) {
    4042            long start = accesses.get(i);
     43            if (start < ignoreOlder)
     44                continue;
    4145            long end = start + threshold.getSeconds() * 1000;
    4246            if (accesses.get(i + threshold.getConnections() -1) <= end)
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/AccessFilter.java

    r8a001ad r904bf2a  
    124124
    125125    private void record() throws IOException {
     126        final long now = context.clock().now();
    126127        for (Recorder recorder : definition.getRecorders()) {
    127128            Threshold threshold = recorder.getThreshold();
     
    130131            synchronized(unknownDests) {
    131132                for (DestTracker tracker : unknownDests.values()) {
    132                     if (!tracker.getCounter().isBreached(threshold))
     133                    if (!tracker.getCounter().isBreached(threshold, now))
    133134                        continue;
    134135                    breached.add(tracker.getHash().toBase32());
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/DestTracker.java

    r8a001ad r904bf2a  
    3737    synchronized boolean recordAccess(long now) {
    3838        counter.recordAccess(now);
    39         return counter.isBreached(threshold);
     39        return counter.isBreached(threshold,now);
    4040    }
    4141
Note: See TracChangeset for help on using the changeset viewer.