diff --git a/src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java b/src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java index a9613c49b2..062227ff79 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java +++ b/src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java @@ -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)); } diff --git a/src/main/java/com/ghostchu/peerbanhelper/config/MainConfigUpdateScript.java b/src/main/java/com/ghostchu/peerbanhelper/config/MainConfigUpdateScript.java index 3732546cfd..d19f654b96 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/config/MainConfigUpdateScript.java +++ b/src/main/java/com/ghostchu/peerbanhelper/config/MainConfigUpdateScript.java @@ -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"); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index dab8a3a788..4609814b27 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,4 +1,4 @@ -config-version: 4 +config-version: 5 # 客户端设置 client: # 名字,可以自己起,会在日志中显示,只能由字母数字横线组成,数字不能打头 @@ -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: # 全局检查线程池并发等级