Changeset 3498ab0


Ignore:
Timestamp:
Apr 4, 2019 7:31:54 AM (15 months ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
1c90985
Parents:
d809b59
Message:

define thresholds in seconds, not minutes

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

Legend:

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

    rd809b59 r3498ab0  
    3939        for (int i = 0; i <= accesses.size() - threshold.getConnections(); i++) {
    4040            long start = accesses.get(i);
    41             long end = start + threshold.getMinutes() * 60000;
     41            long end = start + threshold.getSeconds() * 1000;
    4242            if (accesses.get(i + threshold.getConnections() -1) <= end)
    4343                return true;
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/AccessFilter.java

    rd809b59 r3498ab0  
    157157
    158158    private void purge() {
    159         long olderThan = context.clock().now() - definition.getPurgeMinutes() * 60000;
     159        long olderThan = context.clock().now() - definition.getPurgeSeconds() * 1000;
    160160       
    161161        synchronized(knownDests) {
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/DefinitionParser.java

    rd809b59 r3498ab0  
    4444     * <p>
    4545     * A threshold is defined by the number of connection attempts a remote destination is
    46      * permitted to perform over a specified number of minutes before a "breach" occurs.
     46     * permitted to perform over a specified number of seconds before a "breach" occurs.
    4747     * For example the following threshold definition "15/5" means that the same remote
    48      * destination is allowed to make 14 connection attempts over a 5 minute period,  If
     48     * destination is allowed to make 14 connection attempts over a 5 second period,  If
    4949     * it makes one more attempt within the same period, the threshold will be breached.
    5050     * </p>
     
    5353     * </p>
    5454     * <ul>
    55      * <li>Numeric definition of number of connections over number minutes - "15/5",
     55     * <li>Numeric definition of number of connections over number seconds - "15/5",
    5656     *   "30/60", and so on.  Note that if the number of connections is 1 (as for
    5757     *   example in "1/1") the first connection attempt will result in a breach.</li>
     
    101101     * and then use that same file to throttle them.  For example, the following snippet will
    102102     * define a filter that initially allows all connection attempts, but if any single
    103      * destination exceeds 30 attempts per 5 minutes it gets throttled down to 15 attempts per
    104      * 5 minutes:
     103     * destination exceeds 30 attempts per 5 seconds it gets throttled down to 15 attempts per
     104     * 5 seconds:
    105105     * </p>
    106106     * <pre>
     
    177177        try {
    178178            int connections = Integer.parseInt(split[0]);
    179             int minutes = Integer.parseInt(split[1]);
     179            int seconds = Integer.parseInt(split[1]);
    180180            if (connections < 0)
    181181                throw new InvalidDefinitionException("Number of connections cannot be negative " + s);
    182             if (minutes < 1)
    183                 throw new InvalidDefinitionException("Number of minutes must be at least 1 " + s);
    184             return new Threshold(connections, minutes);
     182            if (seconds < 1)
     183                throw new InvalidDefinitionException("Number of seconds must be at least 1 " + s);
     184            return new Threshold(connections, seconds);
    185185        } catch (NumberFormatException bad) {
    186186            throw new InvalidDefinitionException("Invalid threshold", bad);
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/FilterDefinition.java

    rd809b59 r3498ab0  
    1313    private final FilterDefinitionElement[] elements;
    1414    private final Recorder[] recorders;
    15     private final int purgeMinutes;
     15    private final int purgeSeconds;
    1616
    1717    /**
     
    2727        this.recorders = recorders;
    2828
    29         int maxMinutes = defaultThreshold.getMinutes();
     29        int maxSeconds = defaultThreshold.getSeconds();
    3030        for (FilterDefinitionElement element : elements)
    31             maxMinutes = Math.max(maxMinutes, element.getThreshold().getMinutes());
     31            maxSeconds = Math.max(maxSeconds, element.getThreshold().getSeconds());
    3232        for (Recorder recorder : recorders)
    33             maxMinutes = Math.max(maxMinutes, recorder.getThreshold().getMinutes());
     33            maxSeconds = Math.max(maxSeconds, recorder.getThreshold().getSeconds());
    3434
    35         this.purgeMinutes = maxMinutes;
     35        this.purgeSeconds = maxSeconds;
    3636    }
    3737
     
    4848    }
    4949
    50     int getPurgeMinutes() {
    51         return purgeMinutes;
     50    int getPurgeSeconds() {
     51        return purgeSeconds;
    5252    }
    5353}
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/Threshold.java

    rd809b59 r3498ab0  
    44 * Definition of a Threshold. 
    55 *
    6  * A Threshold is defined by a number of connections over a period of minutes
     6 * A Threshold is defined by a number of connections over a period of seconds
    77 *
    88 * @since 0.9.40
     
    1616
    1717    private final int connections;
    18     private final int minutes;
     18    private final int seconds;
    1919
    20     Threshold(int connections, int minutes) {
    21         if (minutes < 1)
    22             throw new IllegalArgumentException("Threshold must be defined over at least 1 minute");
     20    Threshold(int connections, int seconds) {
     21        if (seconds < 1)
     22            throw new IllegalArgumentException("Threshold must be defined over at least 1 second");
    2323        if (connections < 0)
    2424            throw new IllegalArgumentException("Accesses cannot be negative");
    2525        this.connections = connections;
    26         this.minutes = minutes;
     26        this.seconds = seconds;
    2727    }
    2828
     
    3131    }
    3232   
    33     int getMinutes() {
    34         return minutes;
     33    int getSeconds() {
     34        return seconds;
    3535    }
    3636}
Note: See TracChangeset for help on using the changeset viewer.