Skip to content

Commit

Permalink
优化白名单 IP 检查性能
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Dec 5, 2024
1 parent 956a0e8 commit 0628749
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,7 +98,7 @@ public class PeerBanHelperServer implements Reloadable {
private final Deque<ScheduledBanListOperation> scheduledBanListOperations = new ConcurrentLinkedDeque<>();
private final List<Downloader> downloaders = new CopyOnWriteArrayList<>();
@Getter
private final List<IPAddress> ignoreAddresses = new ArrayList<>();
private final DualIPv4v6Tries ignoreAddresses = new DualIPv4v6Tries();
private final ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor();
@Getter
private final List<BanListInvoker> banListInvoker = new ArrayList<>();
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 0628749

Please sign in to comment.