fix merge

Signed-off-by: Olivier Lamy <oliver.lamy@gmail.com>
This commit is contained in:
Olivier Lamy 2022-06-07 14:11:33 +10:00
parent b52f6182c6
commit 1eaa050163
2 changed files with 7 additions and 7 deletions

View File

@ -322,7 +322,7 @@ public class DoSFilter implements Filter
tracker = getRateTracker(request);
// Calculate the rate and check if it is over the allowed limit
final OverLimit overLimit = tracker.isRateExceeded(System.currentTimeMillis());
final OverLimit overLimit = tracker.isRateExceeded(System.nanoTime());
// Pass it through if we are not currently over the rate limit.
if (overLimit == null)
@ -1182,8 +1182,8 @@ public class DoSFilter implements Filter
}
/**
* @param now the time now (in milliseconds)
* @return the current calculated request rate over the last second
* @param now the time now (in nanoseconds) used to calculate elapsed time since previous requests.
* @return the current calculated request rate over the last second if rate exceeded, else null.
*/
public OverLimit isRateExceeded(long now)
{
@ -1201,9 +1201,9 @@ public class DoSFilter implements Filter
}
long rate = (now - last);
if (rate < 1000L)
if (TimeUnit.NANOSECONDS.toSeconds(rate) < 1L)
{
return new Overage(Duration.ofMillis(rate), _maxRequestsPerSecond);
return new Overage(Duration.ofNanos(rate), _maxRequestsPerSecond);
}
return null;
}
@ -1292,7 +1292,7 @@ public class DoSFilter implements Filter
int latestIndex = _next == 0 ? (_timestamps.length - 1) : (_next - 1);
long last = _timestamps[latestIndex];
boolean hasRecentRequest = last != 0 && (System.currentTimeMillis() - last) < 1000L;
boolean hasRecentRequest = last != 0 && TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - last) < 1L;
DoSFilter filter = (DoSFilter)_context.getAttribute(_filterName);

View File

@ -200,7 +200,7 @@ public class DoSFilterTest extends AbstractDoSFilterTest
for (int i = 0; i < 5; i++)
{
Thread.sleep(sleep);
if (rateTracker.isRateExceeded(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())) != null)
if (rateTracker.isRateExceeded(System.nanoTime()) != null)
exceeded = true;
}
return exceeded;