Skip to content

Commit

Permalink
Merge pull request #148 from PBH-BTN/master
Browse files Browse the repository at this point in the history
4.0.7
  • Loading branch information
Ghost-chu authored Jun 9, 2024
2 parents 187f94e + 3cddce2 commit a6f9a28
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
| --- | ---- | ---- |
| [查看](https://github.com/PBH-BTN/PeerBanHelper/wiki/Docker-%E9%83%A8%E7%BD%B2) | [查看](https://github.com/PBH-BTN/PeerBanHelper/wiki/Windows-%E6%89%8B%E5%8A%A8%E9%83%A8%E7%BD%B2) | [查看](https://github.com/PBH-BTN/PeerBanHelper/wiki/Linux-%E6%89%8B%E5%8A%A8%E9%83%A8%E7%BD%B2) |

## 运行环境要求

* 一台支持 OpenJDK 的设备,可为 JVM 预留 200MB 内存,PBH(无GUI模式)至少需要 72MB Heap 内存来运行(-Xmx72M),长期稳定运行建议分配 128MB~256MB Heap RAM
* 由于 SQLite 数据库支持,CPU 架构需要是其中之一:aarch64, arm, armv6, armv7, ppc64, x86, x86_64,因此 riscv 等新兴 CPU 架构暂不兼容

## 支持的客户端

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>4.0.6</version>
<version>4.0.7</version>

<name>PeerBanHelper</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ public void banWave() {
try {
// 重置所有下载器状态为健康,这样后面失败就会对其降级
banWaveWatchDog.setLastOperation("Reset last status");
downloaders.forEach(downloader -> downloader.setLastStatus(DownloaderLastStatus.HEALTHY));
// 声明基本集合
// 需要重启的种子列表
Map<Downloader, Collection<Torrent>> needRelaunched = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -431,6 +430,8 @@ public void updateDownloader(@NotNull Downloader downloader, boolean updateBanLi
log.warn(Lang.ERR_CLIENT_LOGIN_FAILURE_SKIP, downloader.getName(), downloader.getEndpoint());
downloader.setLastStatus(DownloaderLastStatus.ERROR);
return;
} else {
downloader.setLastStatus(DownloaderLastStatus.HEALTHY);
}
downloader.setBanList(BAN_LIST.keySet(), added, removed);
downloader.relaunchTorrentIfNeeded(needToRelaunch);
Expand Down Expand Up @@ -518,6 +519,7 @@ public Map<Torrent, List<Peer>> collectPeers(Downloader downloader) {
parallelReqRestrict.release();
}
}));
downloader.setLastStatus(DownloaderLastStatus.HEALTHY);
}

return peers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public List<Torrent> getTorrents() {
}.getType());
List<Torrent> torrents = new ArrayList<>();
for (TorrentDetail detail : torrentDetail) {
torrents.add(new TorrentImpl(detail.getHash(), detail.getName(), detail.getHash(), detail.getTotalSize(), detail.getProgress()));
torrents.add(new TorrentImpl(detail.getHash(), detail.getName(), detail.getHash(), detail.getTotalSize(), detail.getProgress(), detail.getUpspeed(), detail.getDlspeed()));
}
return torrents;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public long getSize() {
return backend.getTotalSize();
}

@Override
public long getRtUploadSpeed() {
return backend.getRateUpload();
}

@Override
public long getRtDownloadSpeed() {
return backend.getRateDownload();
}

@NotNull
public List<Peer> getPeers() {
return backend.getPeers().stream().map(TRPeer::new).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.bspfsystems.yamlconfiguration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;

public class PBHMetadataController extends AbstractFeatureModule {
public PBHMetadataController(PeerBanHelperServer server, YamlConfiguration profile) {
super(server, profile);
Expand Down Expand Up @@ -36,11 +39,20 @@ public void onEnable() {

private void handleManifest(Context ctx) {
ctx.status(HttpStatus.OK);
ctx.json(Main.getMeta());
Map<String, Object> data = new HashMap<>();
data.put("version", Main.getMeta());
data.put("modules", getServer().getModuleManager().getModules().stream().map(f -> new ModuleRecord(f.getClass().getName(), f.getConfigName())).toList());
ctx.json(data);
}

@Override
public void onDisable() {

}

record ModuleRecord(
String className,
String configName
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void onEnable() {
// 新增订阅规则
.put("/api/sub/rule", ctx -> save(ctx, null, true), Role.USER_WRITE)
// 更新订阅规则
.get("/api/sub/rule/update/{ruleId}", ctx -> ctx.json(update(ctx.pathParam("ruleId"))), Role.USER_READ)
.post("/api/sub/rule/{ruleId}/update", ctx -> ctx.json(update(ctx.pathParam("ruleId"))), Role.USER_READ)
// 查询订阅规则
.get("/api/sub/rule/{ruleId}", ctx -> ctx.json(get(ctx.pathParam("ruleId"))), Role.USER_READ)
// 修改订阅规则
Expand All @@ -65,7 +65,7 @@ public void onEnable() {
// 查询订阅规则列表
.get("/api/sub/rules", ctx -> ctx.json(list()), Role.USER_READ)
// 手动更新全部订阅规则
.get("/api/sub/rules/update", ctx -> ctx.json(updateAll()), Role.USER_WRITE)
.post("/api/sub/rules/update", ctx -> ctx.json(updateAll()), Role.USER_WRITE)
// 查询全部订阅规则更新日志
.get("/api/sub/logs", ctx -> logs(ctx, null), Role.USER_READ)
// 查询订阅规则更新日志
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/ghostchu/peerbanhelper/torrent/Torrent.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ public interface Torrent {
*/
long getSize();

/**
* 实时下载速度
*
* @return 实时下载速度
*/
long getRtUploadSpeed();

/**
* 实时上传速度
*
* @return 实时上传速度
*/
long getRtDownloadSpeed();

/**
* 获取种子不可逆匿名识别符
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
public class TorrentImpl implements Torrent {
private final double progress;
@Setter
private long rtUploadSpeed;
@Setter
private long rtDownloadSpeed;
@Setter
private String hash;
@Setter
private String id;
Expand All @@ -13,12 +17,14 @@ public class TorrentImpl implements Torrent {
@Setter
private long size;

public TorrentImpl(String id, String name, String hash, long size,double progress) {
public TorrentImpl(String id, String name, String hash, long size, double progress, long rtUploadSpeed, long rtDownloadSpeed) {
this.id = id;
this.name = name;
this.hash = hash;
this.size = size;
this.progress = progress;
this.rtUploadSpeed = rtUploadSpeed;
this.rtDownloadSpeed = rtDownloadSpeed;
}

@Override
Expand Down Expand Up @@ -46,5 +52,13 @@ public long getSize() {
return size;
}

@Override
public long getRtUploadSpeed() {
return rtUploadSpeed;
}

@Override
public long getRtDownloadSpeed() {
return rtDownloadSpeed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public static <T> CompletableFuture<HttpResponse<T>> retryableSend(HttpClient cl
public static <T> CompletableFuture<HttpResponse<T>> retryableSendProgressTracking(HttpClient client, HttpRequest request, HttpResponse.BodyHandler<T> bodyHandler) {
bodyHandler = tracker.tracking(bodyHandler, HTTPUtil::onProgress);
HttpResponse.BodyHandler<T> finalBodyHandler = bodyHandler;

return client.sendAsync(request, bodyHandler)
.handleAsync((r, t) -> tryResend(client, request, finalBodyHandler, 1, r, t), executor)
.thenCompose(Function.identity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ public class TorrentWrapper {
private String name;
private String hash;
private double progress;
private long rtUploadSpeed;
private long rtDownloadSpeed;

public TorrentWrapper(Torrent torrent) {
this.id = torrent.getId();
this.size = torrent.getSize();
this.name = torrent.getName();
this.hash = torrent.getHash();
this.progress = torrent.getProgress();
this.rtDownloadSpeed = torrent.getRtDownloadSpeed();
this.rtUploadSpeed = torrent.getRtUploadSpeed();
}
}

0 comments on commit a6f9a28

Please sign in to comment.