I2PTunnel: Start/stop POST throttle timer

This commit is contained in:
zzz
2019-04-03 13:21:41 +00:00
parent b7d980df06
commit d389b3b57c
3 changed files with 43 additions and 5 deletions

View File

@ -39,8 +39,12 @@ class ConnThrottler {
private final String _action;
private final Log _log;
private final DateFormat _fmt;
private final SimpleTimer2.TimedEvent _cleaner;
private boolean _isRunning;
/*
* Caller MUST call start()
*
* @param max per-peer, 0 for unlimited
* @param totalMax for all peers, 0 for unlimited
* @param period check window (ms)
@ -57,7 +61,30 @@ class ConnThrottler {
// for logging
_fmt = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
_fmt.setTimeZone(SystemVersion.getSystemTimeZone());
new Cleaner();
_cleaner = new Cleaner();
}
/*
* If already started, has no effect.
*
* @since 0.9.40
*/
public synchronized void start() {
if (_isRunning)
return;
_isRunning = true;
_cleaner.schedule(_checkPeriod);
}
/*
* May be restarted.
*
* @since 0.9.40
*/
public synchronized void stop() {
_isRunning = false;
_cleaner.cancel();
clear();
}
/*
@ -176,9 +203,9 @@ class ConnThrottler {
}
private class Cleaner extends SimpleTimer2.TimedEvent {
/** schedules itself */
/** must call schedule() later */
public Cleaner() {
super(SimpleTimer2.getInstance(), _checkPeriod);
super(SimpleTimer2.getInstance());
}
public void timeReached() {

View File

@ -233,6 +233,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
_postThrottler = new ConnThrottler(pp, pt, pw, pb, px, "POST/PUT", _log);
else
_postThrottler.updateLimits(pp, pt, pw, pb, px);
_postThrottler.start();
}
}
}
@ -254,7 +255,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
public boolean close(boolean forced) {
synchronized(this) {
if (_postThrottler != null)
_postThrottler.clear();
_postThrottler.stop();
}
return super.close(forced);
}

View File

@ -1,5 +1,15 @@
2019-04-03 zzz
* I2PTunnel: Start/stop POST throttle timer
2019-04-02 zab
* I2PTunnel: mplement access filtering (ticket #2464
* I2PTunnel: Implement access filtering (ticket #2464)
2019-03-31 zzz
* Data: Implement Destroyable for private keys (ticket #2462)
2019-03-29 zzz
* Crypto: SigContext (WIP) (proposal #148)
* NetDB: Persist cached blinding data (proposal #123)
2019-03-27 zzz
* NetDB: Cache blinding data for lookups and decryption (proposal #123)