|
23 | 23 | import com.ghostchu.peerbanhelper.invoker.impl.IPFilterInvoker;
|
24 | 24 | import com.ghostchu.peerbanhelper.ipdb.IPDB;
|
25 | 25 | import com.ghostchu.peerbanhelper.ipdb.IPGeoData;
|
| 26 | +import com.ghostchu.peerbanhelper.lab.Experiments; |
26 | 27 | import com.ghostchu.peerbanhelper.lab.Laboratory;
|
27 | 28 | import com.ghostchu.peerbanhelper.metric.BasicMetrics;
|
28 | 29 | import com.ghostchu.peerbanhelper.module.*;
|
|
34 | 35 | import com.ghostchu.peerbanhelper.text.TranslationComponent;
|
35 | 36 | import com.ghostchu.peerbanhelper.torrent.Torrent;
|
36 | 37 | import com.ghostchu.peerbanhelper.util.*;
|
| 38 | +import com.ghostchu.peerbanhelper.util.dns.DNSLookup; |
37 | 39 | import com.ghostchu.peerbanhelper.util.encrypt.RSAUtils;
|
38 | 40 | import com.ghostchu.peerbanhelper.util.json.JsonUtil;
|
39 | 41 | import com.ghostchu.peerbanhelper.util.paging.Pageable;
|
|
59 | 61 | import inet.ipaddr.format.util.DualIPv4v6Tries;
|
60 | 62 | import io.javalin.util.JavalinBindException;
|
61 | 63 | import lombok.Getter;
|
| 64 | +import lombok.SneakyThrows; |
62 | 65 | import lombok.extern.slf4j.Slf4j;
|
63 | 66 | import org.apache.commons.lang3.StringUtils;
|
64 | 67 | import org.bspfsystems.yamlconfiguration.configuration.ConfigurationSection;
|
@@ -139,6 +142,8 @@ public class PeerBanHelperServer implements Reloadable {
|
139 | 142 | private BanListDao banListDao;
|
140 | 143 | @Autowired
|
141 | 144 | private Laboratory laboratory;
|
| 145 | + @Autowired |
| 146 | + private DNSLookup dnsLookup; |
142 | 147 | // @Autowired
|
143 | 148 | // private IPFSBanListShare share;
|
144 | 149 |
|
@@ -197,7 +202,15 @@ public void start() throws SQLException {
|
197 | 202 | Main.getReloadManager().register(this);
|
198 | 203 | Main.getEventBus().post(new PBHServerStartedEvent(this));
|
199 | 204 | sendSnapshotAlert();
|
| 205 | + runTestCode(); |
| 206 | + } |
200 | 207 |
|
| 208 | + @SneakyThrows |
| 209 | + private void runTestCode() { |
| 210 | + if (!"LiveDebug".equalsIgnoreCase(System.getProperty("pbh.release"))) { |
| 211 | + return; |
| 212 | + } |
| 213 | + // run some junky test code here |
201 | 214 | }
|
202 | 215 |
|
203 | 216 | private void setupScriptEngine() {
|
@@ -675,7 +688,7 @@ public void updateDownloader(@NotNull Downloader downloader, boolean updateBanLi
|
675 | 688 | try {
|
676 | 689 | var loginResult = downloader.login();
|
677 | 690 | if (!loginResult.success()) {
|
678 |
| - if(loginResult.getStatus() != DownloaderLoginResult.Status.PAUSED) { |
| 691 | + if (loginResult.getStatus() != DownloaderLoginResult.Status.PAUSED) { |
679 | 692 | log.error(tlUI(Lang.ERR_CLIENT_LOGIN_FAILURE_SKIP, downloader.getName(), downloader.getEndpoint(), tlUI(loginResult.getMessage())));
|
680 | 693 | downloader.setLastStatus(DownloaderLastStatus.ERROR, loginResult.getMessage());
|
681 | 694 | }
|
@@ -769,7 +782,7 @@ public Map<Torrent, List<Peer>> collectPeers(Downloader downloader) {
|
769 | 782 | Map<Torrent, List<Peer>> peers = new ConcurrentHashMap<>();
|
770 | 783 | var loginResult = downloader.login();
|
771 | 784 | if (!loginResult.success()) {
|
772 |
| - if(loginResult.getStatus() != DownloaderLoginResult.Status.PAUSED){ |
| 785 | + if (loginResult.getStatus() != DownloaderLoginResult.Status.PAUSED) { |
773 | 786 | log.error(tlUI(Lang.ERR_CLIENT_LOGIN_FAILURE_SKIP, downloader.getName(), downloader.getEndpoint(), tlUI(loginResult.getMessage())));
|
774 | 787 | downloader.setLastStatus(DownloaderLastStatus.ERROR, loginResult.getMessage());
|
775 | 788 | if (loginResult.getStatus() == DownloaderLoginResult.Status.MISSING_COMPONENTS || loginResult.getStatus() == DownloaderLoginResult.Status.REQUIRE_TAKE_ACTIONS) {
|
@@ -920,9 +933,19 @@ private void banPeer(@NotNull Collection<PeerAddress> compareWith, @NotNull BanM
|
920 | 933 | banMetadata.setReverseLookup("N/A");
|
921 | 934 | if (Main.getMainConfig().getBoolean("lookup.dns-reverse-lookup")) {
|
922 | 935 | executor.submit(() -> {
|
923 |
| - String hostName = peer.getPeerAddress().getAddress().toInetAddress().getHostName(); |
924 |
| - if (!peer.getPeerAddress().getIp().equals(hostName)) { |
925 |
| - banMetadata.setReverseLookup(peer.getPeerAddress().getAddress().toInetAddress().getHostName()); |
| 936 | + if (laboratory.isExperimentActivated(Experiments.DNSJAVA.getExperiment())) { |
| 937 | + dnsLookup.ptr(peer.getPeerAddress().getAddress().toReverseDNSLookupString()).thenAccept(hostName -> { |
| 938 | + if (hostName.isPresent()) { |
| 939 | + if (!peer.getPeerAddress().getIp().equals(hostName.get())) { |
| 940 | + banMetadata.setReverseLookup(hostName.get()); |
| 941 | + } |
| 942 | + } |
| 943 | + }); |
| 944 | + } else { |
| 945 | + String hostName = peer.getPeerAddress().getAddress().toInetAddress().getHostName(); |
| 946 | + if (!peer.getPeerAddress().getIp().equals(hostName)) { |
| 947 | + banMetadata.setReverseLookup(peer.getPeerAddress().getAddress().toInetAddress().getHostName()); |
| 948 | + } |
926 | 949 | }
|
927 | 950 | });
|
928 | 951 | }
|
|
0 commit comments