Skip to content

Commit

Permalink
允许用户禁用 DNS 反查,避免增加 DNS 服务器压力
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed May 9, 2024
1 parent 07f2bea commit fb0f2e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -524,18 +524,22 @@ public void banPeer(@NotNull PeerAddress peer, @NotNull BanMetadata banMetadata,
BAN_LIST.put(peer, banMetadata);
metrics.recordPeerBan(peer, banMetadata);
banListInvoker.forEach(i -> i.add(peer, banMetadata));
CompletableFuture.runAsync(() -> {
try {
InetAddress address = InetAddress.getByName(peer.getAddress().toString());
if (!address.getCanonicalHostName().equals(peer.getIp())) {
banMetadata.setReverseLookup(address.getCanonicalHostName());
} else {
if (mainConfig.getBoolean("lookup.dns-reverse-lookup")) {
CompletableFuture.runAsync(() -> {
try {
InetAddress address = InetAddress.getByName(peer.getAddress().toString());
if (!address.getCanonicalHostName().equals(peer.getIp())) {
banMetadata.setReverseLookup(address.getCanonicalHostName());
} else {
banMetadata.setReverseLookup("N/A");
}
} catch (UnknownHostException ignored) {
banMetadata.setReverseLookup("N/A");
}
} catch (UnknownHostException ignored) {
banMetadata.setReverseLookup("N/A");
}
}, generalExecutor);
}, generalExecutor);
} else {
banMetadata.setReverseLookup("N/A");
}
Main.getEventBus().post(new PeerBanEvent(peer, banMetadata, torrentObj, peerObj));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public MainConfigUpdateScript(YamlConfiguration conf) {
this.conf = conf;
}

@UpdateScript(version = 5)
public void optionForDnsReserveLookup() {
conf.set("lookup.dns-reverse-lookup", false);
}

@UpdateScript(version = 4)
public void defTurnOffIncrementBans() {
ConfigurationSection section = conf.getConfigurationSection("client");
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
config-version: 4
config-version: 5
# 客户端设置
client:
# 名字,可以自己起,会在日志中显示,只能由字母数字横线组成,数字不能打头
Expand Down Expand Up @@ -49,6 +49,9 @@ logger:
# 是否隐藏 [完成] 已检查 XX 的 X 个活跃 Torrent 和 X 个对等体 的日志消息?
# 在 DSM 的 ContainerManager 上有助于大幅度减少日志数量,并仅记录有价值的封禁等日志条目
hide-finish-log: false
lookup:
# 启用 DNS 反查,能够通过 IP 反查域名,但可能增加你所使用 DNS 服务器的压力,并可能导致 DNS 服务器对你采取降低服务质量的措施
dns-reverse-lookup: false
# 线程控制
threads:
# 全局检查线程池并发等级
Expand Down

0 comments on commit fb0f2e7

Please sign in to comment.