Skip to content

Commit

Permalink
Merge pull request #267 from PBH-BTN/master
Browse files Browse the repository at this point in the history
v5.0.4
  • Loading branch information
Ghost-chu authored Jul 20, 2024
2 parents 955b02a + 06a3353 commit ce20485
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 260 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ server:

不是的,进度检查器会累加此 IP 地址在特定种子上的下载进度。如果对方出现进度回退、断开更换端口重连、更换 PeerID、更换 Client name 重新下载时,下载器会认为这是一个新客户端,并从头开始计算下载数据(吸血者也使用此手段绕过吸血检查)。但对于 PBH 来说,只要对方 IP 地址未改变(或者处于特定区间内),并且下载的种子未更换的情况下,下载进度会持续增量累积,避免对方欺骗反吸血检查。例如一个文件大小是 1000MB,对方下载 102% 代表对方在这个 1000MB 大小的种子上,实际下载了 1020MB 的数据。

### PBH 提示我的下载器 “连续多次登录失败” ,并暂停了该怎么办?

您可以点击下载器的编辑按钮,然后直接点击确定保存。PBH 将会解除暂停状态并重新尝试登陆,此时会显示登陆失败的原因。请根据原因进行故障排查(例如:网络连接问题、WebUI
是否启用、用户名密码是否正确等)

## Install4j

PeerBanHelper 使用 [Install4j multi-platform installer builder](https://www.ej-technologies.com/products/install4j/overview.html) 打包多平台安装程序。感谢 ej-technolgies 的开放源代码许可证。点击链接或者下面的图片下载 install4j。
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.ghostchu.peerbanhelper</groupId>
<artifactId>peerbanhelper</artifactId>
<version>5.0.3</version>
<version>5.0.4</version>
<packaging>takari-jar</packaging>

<name>PeerBanHelper</name>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/ghostchu/peerbanhelper/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
Expand All @@ -36,7 +37,6 @@
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;

@Slf4j
public class Main {
Expand Down Expand Up @@ -131,17 +131,21 @@ private static void setupProxySettings() {
if (proxySection == null) return;
String host = proxySection.getString("host");
String port = String.valueOf(proxySection.getInt("port"));
String nonProxyHost = proxySection.getString("non-proxy-hosts", "");
switch (proxySection.getInt("setting")) {
case 1 -> System.setProperty("java.net.useSystemProxies", "true");
case 2 -> {
System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPort", port);
System.setProperty("https.proxyHost", host);
System.setProperty("https.proxyPort", port);
System.setProperty("http.nonProxyHosts", nonProxyHost);
System.setProperty("https.nonProxyHosts", nonProxyHost);
}
case 3 -> {
System.setProperty("socksProxyHost", host);
System.setProperty("socksProxyPort", port);
System.setProperty("socksNonProxyHosts", nonProxyHost);
}
default -> System.setProperty("java.net.useSystemProxies", "false");
}
Expand Down Expand Up @@ -180,7 +184,7 @@ private static YamlConfiguration loadConfiguration(File file) {
configuration.load(file);
} catch (IOException | InvalidConfigurationException e) {
log.error("Unable to load configuration: invalid YAML configuration // 无法加载配置文件:无效的 YAML 配置,请检查是否有语法错误", e);
guiManager.createDialog(Level.SEVERE, "Invalid YAML configuration | 无效 YAML 配置文件", String.format("Failed to read configuration: %s", file));
JOptionPane.showMessageDialog(null, "Invalid/Corrupted YAML configuration | 无效或损坏的 YAML 配置文件", String.format("Failed to read configuration: %s", file), JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
return configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.ghostchu.peerbanhelper.database.dao.impl.BanListDao;
import com.ghostchu.peerbanhelper.downloader.Downloader;
import com.ghostchu.peerbanhelper.downloader.DownloaderLastStatus;
import com.ghostchu.peerbanhelper.downloader.DownloaderLoginResult;
import com.ghostchu.peerbanhelper.downloader.impl.biglybt.BiglyBT;
import com.ghostchu.peerbanhelper.downloader.impl.deluge.Deluge;
import com.ghostchu.peerbanhelper.downloader.impl.qbittorrent.QBittorrent;
Expand Down Expand Up @@ -344,7 +345,7 @@ private void registerBanWaveTimer() {
return thread;
});
log.info(tlUI(Lang.PBH_BAN_WAVE_STARTED));
BAN_WAVE_SERVICE.scheduleAtFixedRate(this::banWave, 1, profileConfig.getLong("check-interval", 5000), TimeUnit.MILLISECONDS);
BAN_WAVE_SERVICE.scheduleWithFixedDelay(this::banWave, 1, profileConfig.getLong("check-interval", 5000), TimeUnit.MILLISECONDS);
}


Expand Down Expand Up @@ -598,6 +599,9 @@ public Map<Torrent, List<Peer>> collectPeers(Downloader downloader) {
if (!loginResult.success()) {
log.error(tlUI(Lang.ERR_CLIENT_LOGIN_FAILURE_SKIP, downloader.getName(), downloader.getEndpoint(), tlUI(loginResult.getMessage())));
downloader.setLastStatus(DownloaderLastStatus.ERROR, loginResult.getMessage());
if (loginResult.getStatus() == DownloaderLoginResult.Status.MISSING_COMPONENTS || loginResult.getStatus() == DownloaderLoginResult.Status.REQUIRE_TAKE_ACTIONS) {
downloader.setLastStatus(DownloaderLastStatus.NEED_TAKE_ACTION, loginResult.getMessage());
}
return Collections.emptyMap();
}
List<Torrent> torrents = downloader.getTorrents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ private void validate() {
}
}

@UpdateScript(version = 14)
public void proxyServerConfigSectionEnhanced() {
conf.set("proxy.non-proxy-host", "127.0.0.1|localhost");
}
@UpdateScript(version = 13)
public void proxyServerConfigSection() {
conf.set("proxy.setting", 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public TorrentDao(@Autowired Database database) throws SQLException {

@Override
public synchronized TorrentEntity createIfNotExists(TorrentEntity data) throws SQLException {
List<TorrentEntity> list = queryForMatchingArgs(data);
List<TorrentEntity> list = queryForEq("infoHash", data.getInfoHash());
if (list.isEmpty()) {
return super.createIfNotExists(data);
long id = create(data);
data.setId(id);
return data;
}
return list.getFirst();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
public final class TorrentEntity {
@DatabaseField(generatedId = true)
private Long id;
@DatabaseField(canBeNull = false, uniqueIndex = true, uniqueCombo = true)
@DatabaseField(canBeNull = false, uniqueIndex = true)
private String infoHash;
@DatabaseField(canBeNull = false, uniqueCombo = true)
@DatabaseField(canBeNull = false)
private String name;
@DatabaseField(canBeNull = false)
private Long size;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.ghostchu.peerbanhelper.downloader;

import com.ghostchu.peerbanhelper.text.Lang;
import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.ghostchu.peerbanhelper.util.MsgUtil;

import java.util.Date;

public abstract class AbstractDownloader implements Downloader {
protected String name;
private DownloaderLastStatus lastStatus = DownloaderLastStatus.UNKNOWN;
private TranslationComponent statusMessage;
private int failedLoginAttempts = 0;
private long nextLoginTry = 0L;

public AbstractDownloader(String name) {
this.name = name;
}

@Override
public DownloaderLoginResult login() {
if (nextLoginTry >= System.currentTimeMillis()) {
return new DownloaderLoginResult(DownloaderLoginResult.Status.REQUIRE_TAKE_ACTIONS
, new TranslationComponent(Lang.TOO_MANY_FAILED_ATTEMPT, MsgUtil.getDateFormatter().format(new Date(nextLoginTry)))
);
}
DownloaderLoginResult result;
try {
result = login0();
if (result.success()) {
failedLoginAttempts = 0;
return result;
}
failedLoginAttempts++;
return result;
} catch (Throwable e) {
failedLoginAttempts++;
throw e;
} finally {
if (failedLoginAttempts >= 15) {
nextLoginTry = System.currentTimeMillis() + (1000 * 60 * 30);
failedLoginAttempts = 0;
}
}
}

public abstract DownloaderLoginResult login0();

@Override
public DownloaderLastStatus getLastStatus() {
return lastStatus;
}

@Override
public void setLastStatus(DownloaderLastStatus lastStatus, TranslationComponent statusMessage) {
this.lastStatus = lastStatus;
this.statusMessage = statusMessage;
}

@Override
public TranslationComponent getLastStatusMessage() {
return statusMessage;
}

@Override
public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum Status {
INCORRECT_CREDENTIAL,
MISSING_COMPONENTS,
NETWORK_ERROR,
EXCEPTION
EXCEPTION,
REQUIRE_TAKE_ACTIONS
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ghostchu.peerbanhelper.downloader.impl.biglybt;

import com.ghostchu.peerbanhelper.downloader.Downloader;
import com.ghostchu.peerbanhelper.downloader.DownloaderLastStatus;
import com.ghostchu.peerbanhelper.downloader.AbstractDownloader;
import com.ghostchu.peerbanhelper.downloader.DownloaderLoginResult;
import com.ghostchu.peerbanhelper.downloader.impl.biglybt.network.bean.clientbound.BanBean;
import com.ghostchu.peerbanhelper.downloader.impl.biglybt.network.bean.clientbound.BanListReplacementBean;
Expand Down Expand Up @@ -47,17 +46,14 @@

import static com.ghostchu.peerbanhelper.text.TextManager.tlUI;

public class BiglyBT implements Downloader {
public class BiglyBT extends AbstractDownloader {
private static final Logger log = org.slf4j.LoggerFactory.getLogger(BiglyBT.class);
private final String apiEndpoint;
private final HttpClient httpClient;
private final Config config;
private DownloaderLastStatus lastStatus = DownloaderLastStatus.UNKNOWN;
private String name;
private TranslationComponent statusMessage;

public BiglyBT(String name, Config config) {
this.name = name;
super(name);
this.config = config;
this.apiEndpoint = config.getEndpoint();
CookieManager cm = new CookieManager();
Expand Down Expand Up @@ -100,7 +96,8 @@ public YamlConfiguration saveDownloader() {
return config.saveToYaml();
}

public DownloaderLoginResult login() {
@Override
public DownloaderLoginResult login0() {
HttpResponse<Void> resp;
try {
resp = httpClient.send(MutableRequest.GET(apiEndpoint + "/metadata"), HttpResponse.BodyHandlers.discarding());
Expand All @@ -114,39 +111,13 @@ public DownloaderLoginResult login() {
} catch (Exception e) {
return new DownloaderLoginResult(DownloaderLoginResult.Status.NETWORK_ERROR, new TranslationComponent(Lang.DOWNLOADER_LOGIN_IO_EXCEPTION, e.getClass().getName() + ": " + e.getMessage()));
}

}

@Override
public String getEndpoint() {
return apiEndpoint;
}

// @Override
// public String getWebUIEndpoint() {
// return config.getEndpoint();
// }

// @Override
// public @Nullable DownloaderBasicAuth getDownloaderBasicAuth() {
// return null;
// }
//
// @Override
// public @Nullable WebViewScriptCallback getWebViewJavaScript() {
// return null;
// }
//
// @Override
// public boolean isSupportWebview() {
// return false;
// }

@Override
public String getName() {
return name;
}

@Override
public String getType() {
return "BiglyBT";
Expand Down Expand Up @@ -267,22 +238,6 @@ private void setBanListFull(Collection<PeerAddress> peerAddresses) {
}
}

@Override
public DownloaderLastStatus getLastStatus() {
return lastStatus;
}

@Override
public void setLastStatus(DownloaderLastStatus lastStatus, TranslationComponent statusMessage) {
this.lastStatus = lastStatus;
this.statusMessage = statusMessage;
}

@Override
public TranslationComponent getLastStatusMessage() {
return statusMessage;
}

@Override
public void close() {

Expand Down
Loading

0 comments on commit ce20485

Please sign in to comment.