forked from TuxCoding/FastLogin
Fix rate limiter blocking the first requests
If the server just started, expireTime can become negative. Therefore, the first uninitialized values will not be made available.
This commit is contained in:
@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.github.games647.fastlogin.core;
|
package com.github.games647.fastlogin.core;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Limit the number of requests with a maximum size. Each requests expire after the specified time making it available
|
* Limit the number of requests with a maximum size. Each requests expire after the specified time making it available
|
||||||
* for another request.
|
* for another request.
|
||||||
@ -38,6 +40,9 @@ public class RateLimiter {
|
|||||||
public RateLimiter(int maxLimit, long expireTime) {
|
public RateLimiter(int maxLimit, long expireTime) {
|
||||||
this.requests = new long[maxLimit];
|
this.requests = new long[maxLimit];
|
||||||
this.expireTime = expireTime;
|
this.expireTime = expireTime;
|
||||||
|
|
||||||
|
// fill the array with the lowest values, so that the first uninitialized values will always expire
|
||||||
|
Arrays.fill(requests, Long.MIN_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user