ip 请求次数限制16

This commit is contained in:
GYJ 2025-03-24 11:50:34 +08:00
parent 5b39f50ba9
commit 0488c84143
1 changed files with 10 additions and 3 deletions

View File

@ -63,12 +63,19 @@ public class IpAccessCounter {
removeCount.set(0);
long currentTime = System.currentTimeMillis();
Set<String> removedIps = new HashSet<>();
IP_ACCESS_TIMES.forEach((ip, accessTimes) -> {
for (Map.Entry<String, List<Long>> entry : IP_ACCESS_TIMES.entrySet()) {
List<Long> accessTimes = entry.getValue();
accessTimes.removeIf(time -> currentTime - time > ONE_MINUTE);
if (accessTimes.isEmpty()) {
removedIps.add(ip);
removedIps.add(entry.getKey());
}
});
}
// IP_ACCESS_TIMES.forEach((ip, accessTimes) -> {
// accessTimes.removeIf(time -> currentTime - time > ONE_MINUTE);
// if (accessTimes.isEmpty()) {
// removedIps.add(ip);
// }
// });
removedIps.forEach(IP_ACCESS_TIMES::remove);
Set<String> removedBlacklistIps = new HashSet<>();