ip 请求次数限制5
This commit is contained in:
parent
383f08ef4d
commit
029d6e5562
|
|
@ -61,12 +61,15 @@ public class IpAccessCounter {
|
|||
long currentTime = System.currentTimeMillis();
|
||||
List<Long> accessTimes = IP_ACCESS_TIMES.computeIfAbsent(ip, k -> new ArrayList<>());
|
||||
// 移除超过一分钟的访问时间记录
|
||||
accessTimes.removeIf(time -> currentTime - time > ONE_MINUTE);
|
||||
if (accessTimes.size() + 1 > maxAccessCount) {
|
||||
addToBlacklist(ip);
|
||||
log.info("IP {} 因一分钟内访问次数超过 {} 次,被加入黑名单", ip, maxAccessCount);
|
||||
return false;
|
||||
if (accessTimes != null) {
|
||||
accessTimes.removeIf(time -> currentTime - time > ONE_MINUTE);
|
||||
if (accessTimes.size() + 1 > maxAccessCount) {
|
||||
addToBlacklist(ip);
|
||||
log.info("IP {} 因一分钟内访问次数超过 {} 次,被加入黑名单", ip, maxAccessCount);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
accessTimes.add(currentTime);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue