Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCB 支持检查未完成/不完整任务的过量下载 #748

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public List<Torrent> getTorrents() {
detail.getName(),
detail.getTorrent().getInfoHash(),
detail.getTorrent().getSize(),
detail.getTorrent().getSize() - detail.getStats().getRemainingBytes(), // 种子总大小 减去 (包含未选择文件的)尚未下载大小 等于 已下载内容大小
detail.getStats().getCompletedInThousandNotation() / 1000d,
detail.getStats().getRtUploadSpeed(),
detail.getStats().getRtDownloadSpeed(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ public List<Torrent> getTorrents() {
torrent.getTask().getTaskName(),
torrent.getTaskDetail().getInfohash() != null ? torrent.getTaskDetail().getInfohash() : torrent.getTaskDetail().getInfohashV2(),
torrent.getTaskDetail().getTotalSize(),
torrent.getTask().getSelectedDownloadedSize(),
torrent.getTaskStatus().getDownloadPermillage() / 1000.0d,
torrent.getTask().getUploadRate(),
torrent.getTask().getDownloadRate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public static class TaskDTO {
private long totalSize;
// @SerializedName("selected_size")
// private long selectedSize;
// @SerializedName("selected_downloaded_size")
// private long selectedDownloadedSize;
@SerializedName("selected_downloaded_size")
private long selectedDownloadedSize;
@SerializedName("download_rate")
private long downloadRate;
@SerializedName("upload_rate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public List<Torrent> getTorrents() {
activeTorrent.getInfoHash(),
activeTorrent.getProgress() / 100.0d,
activeTorrent.getSize(),
activeTorrent.getCompletedSize(),
activeTorrent.getUploadPayloadRate(),
activeTorrent.getDownloadPayloadRate(),
peers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public final class DelugeTorrent implements Torrent {
private String hash;
private double progress;
private long size;
private long completedSize;
private long rtUploadSpeed;
private long rtDownloadSpeed;
private List<Peer> peers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public final class QBittorrentTorrent implements Torrent {
@SerializedName("category")
private String category;

// @SerializedName("completed")
// private Long completed;
@SerializedName("completed")
private Long completed;
paulzzh marked this conversation as resolved.
Show resolved Hide resolved
//
// @SerializedName("completion_on")
// private Long completionOn;
Expand Down Expand Up @@ -190,6 +190,11 @@ public long getSize() {
return totalSize;
}

@Override
public long getCompletedSize() {
return completed;
}
paulzzh marked this conversation as resolved.
Show resolved Hide resolved

@Override
public long getRtUploadSpeed() {
return upspeed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public long getSize() {
return backend.getTotalSize();
}

@Override
public long getCompletedSize() {
return (long) (backend.getSizeWhenDone() * backend.getPercentDone());
}

@Override
public long getRtUploadSpeed() {
return backend.getRateUpload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ private void reloadConfig() {
final long actualUploaded = Math.max(peer.getUploaded(), Math.max(clientTask.getLastReportUploaded(), prefixTrackingUploadedIncreaseTotal));
try {
final long torrentSize = torrent.getSize();
final long completedSize = torrent.getCompletedSize();
paulzzh marked this conversation as resolved.
Show resolved Hide resolved
// 过滤
if (torrentSize <= 0) {
return pass();
Expand All @@ -253,17 +254,21 @@ private void reloadConfig() {
final double actualProgress = (double) actualUploaded / torrentSize; // 实际进度
final double clientProgress = peer.getProgress(); // 客户端汇报进度
// actualUploaded = -1 代表客户端不支持统计此 Peer 总上传量
if (actualUploaded != -1 && blockExcessiveClients && (actualUploaded > torrentSize)) {
// 下载过量,检查
long maxAllowedExcessiveThreshold = (long) (torrentSize * excessiveThreshold);
if (actualUploaded > maxAllowedExcessiveThreshold) {
clientTask.setBanDelayWindowEndAt(0L);
progressRecorder.invalidate(client); // 封禁时,移除缓存
return new CheckResult(getClass(), PeerAction.BAN, banDuration, new TranslationComponent(Lang.PCB_RULE_REACHED_MAX_ALLOWED_EXCESSIVE_THRESHOLD),
if (actualUploaded != -1 && blockExcessiveClients) {
long referenceSize = (System.getProperty("pbh.pcb.disable-completed-excessive") == null && completedSize > 0 && actualUploaded > completedSize) ? completedSize : torrentSize;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

更新一下配置文件,这样前端才能增加对应的配置项

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为保持BTN数据一致性,此功能应总是开启。

这个开关的作用完全是为了防止发版之后功能翻车,用户可以在不更新版本的情况下还原行为而设计的。

// 下载量超过种子大小或者超过已下载大小,检查
if (actualUploaded > referenceSize) {
long maxAllowedExcessiveThreshold = (long) (referenceSize * excessiveThreshold);
if (actualUploaded > maxAllowedExcessiveThreshold) {
clientTask.setBanDelayWindowEndAt(0L);
progressRecorder.invalidate(client); // Remove from cache upon banning
return new CheckResult(getClass(), PeerAction.BAN, banDuration,
new TranslationComponent(Lang.PCB_RULE_REACHED_MAX_ALLOWED_EXCESSIVE_THRESHOLD),
new TranslationComponent(Lang.MODULE_PCB_EXCESSIVE_DOWNLOAD,
torrentSize,
actualUploaded,
maxAllowedExcessiveThreshold));
referenceSize,
actualUploaded,
maxAllowedExcessiveThreshold));
}
}
}
// 如果客户端报告自己进度更多,则跳过检查
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/ghostchu/peerbanhelper/torrent/Torrent.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ public interface Torrent {
double getProgress();

/**
* 获取目前该 Torrent 的共计大小
* 获取该 Torrent 的总大小
*
* @return 共计大小
* @return 总大小
*/
long getSize();

/**
* 获取该 Torrent 已保存的数据量 (也就是最大可以提供的上传量)
*
* @return 已保存的数据量
*/
long getCompletedSize();

/**
* 实时下载速度
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ public class TorrentImpl implements Torrent {
private String id;
private String name;
private long size;
private long completedSize;

public TorrentImpl(String id, String name, String hash, long size, double progress, long rtUploadSpeed, long rtDownloadSpeed, boolean privateTorrent) {
public TorrentImpl(String id, String name, String hash, long size, long completedSize, double progress, long rtUploadSpeed, long rtDownloadSpeed, boolean privateTorrent) {
this.id = id;
this.name = name;
this.hash = hash;
this.size = size;
this.completedSize = completedSize;
paulzzh marked this conversation as resolved.
Show resolved Hide resolved
this.progress = progress;
this.rtUploadSpeed = rtUploadSpeed;
this.rtDownloadSpeed = rtDownloadSpeed;
Expand Down Expand Up @@ -49,6 +51,11 @@ public long getSize() {
return size;
}

@Override
public long getCompletedSize() {
return completedSize;
}

@Override
public long getRtUploadSpeed() {
return rtUploadSpeed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public final class TorrentWrapper {
private String id;
private long size;
private long completedSize;
private String name;
private String hash;
private double progress;
Expand All @@ -20,6 +21,7 @@ public final class TorrentWrapper {
public TorrentWrapper(Torrent torrent) {
this.id = torrent.getId();
this.size = torrent.getSize();
this.completedSize = torrent.getCompletedSize();
this.name = torrent.getName();
this.hash = torrent.getHash();
this.progress = torrent.getProgress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public static class ActiveTorrentsResponseDTO {
private Double progress;
@SerializedName("size")
private Long size;
@SerializedName("completed_size")
private Long completedSize;
@SerializedName("upload_payload_rate")
private Long uploadPayloadRate;
@SerializedName("download_payload_rate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
:width="800"
:visible="visible"
unmount-on-close
:hide-cancel="!isNew"
:hide-cancel="viewOnly"
@cancel="handleCancel"
@before-ok="handleOk"
>
<template #title>
{{
Expand All @@ -24,7 +25,7 @@
<a-spin />
</div>
<editor v-else v-model="content" :view-only="viewOnly" />
<template #footer>
<template v-if="!viewOnly" #footer>
<a-space fill style="display: flex; justify-content: space-between">
<a-form ref="formRef" :model="form" :disabled="!isNew" auto-label-width>
<a-form-item
Expand All @@ -40,8 +41,8 @@
</a-form>
<a-space>
<a-button @click="handleCancel">
{{ t('page.settings.tab.script.detail.action.cancel') }}</a-button
>
{{ t('page.settings.tab.script.detail.action.cancel') }}
</a-button>
<a-button
type="primary"
@click="
Expand Down
Loading