From 06287497908115fd642c1cd26a949c37af84b48f Mon Sep 17 00:00:00 2001 From: Ghost_chu Date: Thu, 5 Dec 2024 17:49:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=99=BD=E5=90=8D=E5=8D=95?= =?UTF-8?q?=20IP=20=E6=A3=80=E6=9F=A5=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../peerbanhelper/PeerBanHelperServer.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java b/src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java index ef3375631..2de6f12fd 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java +++ b/src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java @@ -57,6 +57,7 @@ import com.googlecode.aviator.Options; import com.googlecode.aviator.runtime.JavaMethodReflectionFunctionMissing; import inet.ipaddr.IPAddress; +import inet.ipaddr.format.util.DualIPv4v6Tries; import io.javalin.util.JavalinBindException; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -97,7 +98,7 @@ public class PeerBanHelperServer implements Reloadable { private final Deque scheduledBanListOperations = new ConcurrentLinkedDeque<>(); private final List downloaders = new CopyOnWriteArrayList<>(); @Getter - private final List ignoreAddresses = new ArrayList<>(); + private final DualIPv4v6Tries ignoreAddresses = new DualIPv4v6Tries(); private final ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor(); @Getter private final List banListInvoker = new ArrayList<>(); @@ -170,10 +171,8 @@ public ReloadResult reloadModule() throws Exception { private void unbanWhitelistedPeers() { for (PeerAddress peerAddress : BAN_LIST.keySet()) { - for (IPAddress ignoreAddress : ignoreAddresses) { - if (ignoreAddress.equals(peerAddress.getAddress()) || ignoreAddress.contains(peerAddress.getAddress())) { - scheduleUnBanPeer(peerAddress); - } + if (ignoreAddresses.elementContains(peerAddress.getAddress())) { + scheduleUnBanPeer(peerAddress); } } } @@ -833,10 +832,8 @@ public CheckResult checkBan(@NotNull Torrent torrent, @NotNull Peer peer, @NotNu if (peer.getPeerAddress().getAddress().isAnyLocal()) { return new CheckResult(getClass(), PeerAction.SKIP, 0, new TranslationComponent("general-rule-local-address"), new TranslationComponent("general-reason-skip-local-peers")); } - for (IPAddress ignoreAddress : ignoreAddresses) { - if (ignoreAddress.contains(peer.getPeerAddress().getAddress())) { - return new CheckResult(getClass(), PeerAction.SKIP, 0, new TranslationComponent("general-rule-ignored-address"), new TranslationComponent("general-reason-skip-ignored-peers")); - } + if (ignoreAddresses.elementContains(peer.getPeerAddress().getAddress())) { + return new CheckResult(getClass(), PeerAction.SKIP, 0, new TranslationComponent("general-rule-ignored-address"), new TranslationComponent("general-reason-skip-ignored-peers")); } try { for (FeatureModule registeredModule : moduleManager.getModules()) {