From 0c32251ed80f04d1a98d1047fb4a800b2298878d Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Sun, 17 Nov 2024 03:00:33 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20completedSize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../downloader/impl/biglybt/BiglyBT.java | 1 + .../downloader/impl/bitcomet/BitComet.java | 1 + .../impl/bitcomet/resp/BCTaskTorrentResponse.java | 4 ++-- .../peerbanhelper/downloader/impl/deluge/Deluge.java | 1 + .../downloader/impl/deluge/DelugeTorrent.java | 1 + .../impl/qbittorrent/impl/QBittorrentTorrent.java | 9 +++++++-- .../downloader/impl/transmission/TRTorrent.java | 5 +++++ .../com/ghostchu/peerbanhelper/torrent/Torrent.java | 11 +++++++++-- .../ghostchu/peerbanhelper/torrent/TorrentImpl.java | 9 ++++++++- .../peerbanhelper/wrapper/TorrentWrapper.java | 2 ++ .../deluge/responses/PBHActiveTorrentsResponse.java | 2 ++ 11 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/biglybt/BiglyBT.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/biglybt/BiglyBT.java index 3b1225a0f2..6e9ba44fc1 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/biglybt/BiglyBT.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/biglybt/BiglyBT.java @@ -174,6 +174,7 @@ public List getTorrents() { detail.getName(), detail.getTorrent().getInfoHash(), detail.getTorrent().getSize(), + -1, // TODO detail.getStats().getCompletedInThousandNotation() / 1000d, detail.getStats().getRtUploadSpeed(), detail.getStats().getRtDownloadSpeed(), diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/bitcomet/BitComet.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/bitcomet/BitComet.java index e2a6f6ab1a..a15a755320 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/bitcomet/BitComet.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/bitcomet/BitComet.java @@ -294,6 +294,7 @@ public List 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(), diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/bitcomet/resp/BCTaskTorrentResponse.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/bitcomet/resp/BCTaskTorrentResponse.java index 8b3c328631..1ddca99ad6 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/bitcomet/resp/BCTaskTorrentResponse.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/bitcomet/resp/BCTaskTorrentResponse.java @@ -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") diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/deluge/Deluge.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/deluge/Deluge.java index aff8695804..6224500456 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/deluge/Deluge.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/deluge/Deluge.java @@ -132,6 +132,7 @@ public List getTorrents() { activeTorrent.getInfoHash(), activeTorrent.getProgress() / 100.0d, activeTorrent.getSize(), + activeTorrent.getCompletedSize(), activeTorrent.getUploadPayloadRate(), activeTorrent.getDownloadPayloadRate(), peers, diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/deluge/DelugeTorrent.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/deluge/DelugeTorrent.java index 00d15b05ab..7bc275878c 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/deluge/DelugeTorrent.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/deluge/DelugeTorrent.java @@ -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 peers; diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/impl/QBittorrentTorrent.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/impl/QBittorrentTorrent.java index aa889d7699..82ceb4977a 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/impl/QBittorrentTorrent.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/impl/QBittorrentTorrent.java @@ -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; // // @SerializedName("completion_on") // private Long completionOn; @@ -190,6 +190,11 @@ public long getSize() { return totalSize; } + @Override + public long getCompletedSize() { + return completed; + } + @Override public long getRtUploadSpeed() { return upspeed; diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/transmission/TRTorrent.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/transmission/TRTorrent.java index 5e19a3815e..d7aaba8e9f 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/transmission/TRTorrent.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/transmission/TRTorrent.java @@ -40,6 +40,11 @@ public long getSize() { return backend.getTotalSize(); } + @Override + public long getCompletedSize() { + return -1; // TODO + } + @Override public long getRtUploadSpeed() { return backend.getRateUpload(); diff --git a/src/main/java/com/ghostchu/peerbanhelper/torrent/Torrent.java b/src/main/java/com/ghostchu/peerbanhelper/torrent/Torrent.java index 8a9af82be5..42ebabfde2 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/torrent/Torrent.java +++ b/src/main/java/com/ghostchu/peerbanhelper/torrent/Torrent.java @@ -32,12 +32,19 @@ public interface Torrent { double getProgress(); /** - * 获取目前该 Torrent 的共计大小 + * 获取该 Torrent 的总大小 * - * @return 共计大小 + * @return 总大小 */ long getSize(); + /** + * 获取该 Torrent 已保存的数据量 (也就是最大可以提供的上传量) + * + * @return 已保存的数据量 + */ + long getCompletedSize(); + /** * 实时下载速度 * diff --git a/src/main/java/com/ghostchu/peerbanhelper/torrent/TorrentImpl.java b/src/main/java/com/ghostchu/peerbanhelper/torrent/TorrentImpl.java index b458b96642..25ac615613 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/torrent/TorrentImpl.java +++ b/src/main/java/com/ghostchu/peerbanhelper/torrent/TorrentImpl.java @@ -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; this.progress = progress; this.rtUploadSpeed = rtUploadSpeed; this.rtDownloadSpeed = rtDownloadSpeed; @@ -49,6 +51,11 @@ public long getSize() { return size; } + @Override + public long getCompletedSize() { + return completedSize; + } + @Override public long getRtUploadSpeed() { return rtUploadSpeed; diff --git a/src/main/java/com/ghostchu/peerbanhelper/wrapper/TorrentWrapper.java b/src/main/java/com/ghostchu/peerbanhelper/wrapper/TorrentWrapper.java index 58b4f0cf28..12eff89cde 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/wrapper/TorrentWrapper.java +++ b/src/main/java/com/ghostchu/peerbanhelper/wrapper/TorrentWrapper.java @@ -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; @@ -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(); diff --git a/src/main/java/raccoonfink/deluge/responses/PBHActiveTorrentsResponse.java b/src/main/java/raccoonfink/deluge/responses/PBHActiveTorrentsResponse.java index 368d77ddab..1f699cfba7 100644 --- a/src/main/java/raccoonfink/deluge/responses/PBHActiveTorrentsResponse.java +++ b/src/main/java/raccoonfink/deluge/responses/PBHActiveTorrentsResponse.java @@ -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") From 6ff661857a1e7ba02e03cc866d06553520215656 Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Sun, 17 Nov 2024 03:11:17 +0800 Subject: [PATCH 02/13] =?UTF-8?q?PCB=20=E6=94=AF=E6=8C=81=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E4=B8=8D=E5=AE=8C=E6=95=B4=E4=BB=BB=E5=8A=A1=E7=9A=84?= =?UTF-8?q?=E8=BF=87=E9=87=8F=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/rule/ProgressCheatBlocker.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java b/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java index 976b7beee7..a980efbcd1 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java +++ b/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java @@ -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(); // 过滤 if (torrentSize <= 0) { return pass(); @@ -253,17 +254,31 @@ 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), - new TranslationComponent(Lang.MODULE_PCB_EXCESSIVE_DOWNLOAD, - torrentSize, - actualUploaded, - maxAllowedExcessiveThreshold)); + if (actualUploaded != -1 && blockExcessiveClients) { + if (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), + new TranslationComponent(Lang.MODULE_PCB_EXCESSIVE_DOWNLOAD, + torrentSize, + actualUploaded, + maxAllowedExcessiveThreshold)); + } + } else if (completedSize > 0 && (actualUploaded > completedSize)) { + // 下载量超过任务大小,检查 + long maxAllowedExcessiveThreshold = (long) (completedSize * 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), + new TranslationComponent(Lang.MODULE_PCB_EXCESSIVE_DOWNLOAD, + completedSize, + actualUploaded, + maxAllowedExcessiveThreshold)); + } } } // 如果客户端报告自己进度更多,则跳过检查 From 5d77cd8363c8dbdb1c2b59e9ccab496166d52da3 Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Sun, 17 Nov 2024 03:43:55 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E5=90=AC=E5=85=94=E5=AD=90=E7=9A=84?= =?UTF-8?q?=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../impl/rule/ProgressCheatBlocker.java | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java b/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java index a980efbcd1..ca4024d3d0 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java +++ b/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java @@ -255,31 +255,22 @@ private void reloadConfig() { final double clientProgress = peer.getProgress(); // 客户端汇报进度 // actualUploaded = -1 代表客户端不支持统计此 Peer 总上传量 if (actualUploaded != -1 && blockExcessiveClients) { - if (actualUploaded > torrentSize) { - // 下载量超过种子大小,检查 - long maxAllowedExcessiveThreshold = (long) (torrentSize * excessiveThreshold); + long referenceSize = (completedSize > 0 && actualUploaded > completedSize) ? completedSize : torrentSize; + if (actualUploaded > referenceSize) { + long maxAllowedExcessiveThreshold = (long) (referenceSize * 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), - new TranslationComponent(Lang.MODULE_PCB_EXCESSIVE_DOWNLOAD, - torrentSize, - actualUploaded, - maxAllowedExcessiveThreshold)); - } - } else if (completedSize > 0 && (actualUploaded > completedSize)) { - // 下载量超过任务大小,检查 - long maxAllowedExcessiveThreshold = (long) (completedSize * 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), - new TranslationComponent(Lang.MODULE_PCB_EXCESSIVE_DOWNLOAD, - completedSize, - actualUploaded, - maxAllowedExcessiveThreshold)); + 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, + referenceSize, + actualUploaded, + maxAllowedExcessiveThreshold)); } } + } + } } // 如果客户端报告自己进度更多,则跳过检查 if (actualProgress <= clientProgress) { From 512094a8c9ac11f085b07dbb3eee9f61db602b95 Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Sun, 17 Nov 2024 03:49:31 +0800 Subject: [PATCH 04/13] fix build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 坏兔子 --- .../peerbanhelper/module/impl/rule/ProgressCheatBlocker.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java b/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java index ca4024d3d0..c8fea5fb7d 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java +++ b/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java @@ -256,6 +256,7 @@ private void reloadConfig() { // actualUploaded = -1 代表客户端不支持统计此 Peer 总上传量 if (actualUploaded != -1 && blockExcessiveClients) { long referenceSize = (completedSize > 0 && actualUploaded > completedSize) ? completedSize : torrentSize; + // 下载量超过种子大小或者超过已下载大小,检查 if (actualUploaded > referenceSize) { long maxAllowedExcessiveThreshold = (long) (referenceSize * excessiveThreshold); if (actualUploaded > maxAllowedExcessiveThreshold) { @@ -269,8 +270,6 @@ private void reloadConfig() { maxAllowedExcessiveThreshold)); } } - } - } } // 如果客户端报告自己进度更多,则跳过检查 if (actualProgress <= clientProgress) { From 30829134ffa31bb045496ee810014bcc4c679a10 Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Sun, 17 Nov 2024 18:44:48 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E5=AE=8C=E5=96=84=20BiglyBT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ghostchu/peerbanhelper/downloader/impl/biglybt/BiglyBT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/biglybt/BiglyBT.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/biglybt/BiglyBT.java index 6e9ba44fc1..3a99579d23 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/biglybt/BiglyBT.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/biglybt/BiglyBT.java @@ -174,7 +174,7 @@ public List getTorrents() { detail.getName(), detail.getTorrent().getInfoHash(), detail.getTorrent().getSize(), - -1, // TODO + detail.getTorrent().getSize() - detail.getStats().getRemainingBytes(), // 种子总大小 减去 (包含未选择文件的)尚未下载大小 等于 已下载内容大小 detail.getStats().getCompletedInThousandNotation() / 1000d, detail.getStats().getRtUploadSpeed(), detail.getStats().getRtDownloadSpeed(), From 1d66a33a980013eb157b79802fcd710c1f3aa645 Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:00:13 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20pbh.pcb.disable-comp?= =?UTF-8?q?leted-excessive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../peerbanhelper/module/impl/rule/ProgressCheatBlocker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java b/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java index c8fea5fb7d..daf52bfee9 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java +++ b/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java @@ -255,7 +255,7 @@ private void reloadConfig() { final double clientProgress = peer.getProgress(); // 客户端汇报进度 // actualUploaded = -1 代表客户端不支持统计此 Peer 总上传量 if (actualUploaded != -1 && blockExcessiveClients) { - long referenceSize = (completedSize > 0 && actualUploaded > completedSize) ? completedSize : torrentSize; + long referenceSize = (System.getProperty("pbh.pcb.disable-completed-excessive") == null && completedSize > 0 && actualUploaded > completedSize) ? completedSize : torrentSize; // 下载量超过种子大小或者超过已下载大小,检查 if (actualUploaded > referenceSize) { long maxAllowedExcessiveThreshold = (long) (referenceSize * excessiveThreshold); From c716e6be560347b3e01fdb1413c06d384128b663 Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:53:06 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E5=AE=8C=E5=96=84=20Transmission?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../peerbanhelper/downloader/impl/transmission/TRTorrent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/transmission/TRTorrent.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/transmission/TRTorrent.java index d7aaba8e9f..20adf74606 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/transmission/TRTorrent.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/transmission/TRTorrent.java @@ -42,7 +42,7 @@ public long getSize() { @Override public long getCompletedSize() { - return -1; // TODO + return (long) (backend.getSizeWhenDone() * backend.getPercentDone()); } @Override From 0971a576e498bc1d5e2347b07da4bbf2f40e04ef Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Wed, 20 Nov 2024 03:26:13 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/lang/en_us/messages.yml | 2 +- src/main/resources/lang/messages_fallback.yml | 2 +- src/main/resources/lang/zh_cn/messages.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/lang/en_us/messages.yml b/src/main/resources/lang/en_us/messages.yml index e116ff446b..e8ba0f2b60 100644 --- a/src/main/resources/lang/en_us/messages.yml +++ b/src/main/resources/lang/en_us/messages.yml @@ -25,7 +25,7 @@ MODULE_IBL_MATCH_CITY: "Match city rule: {}" MODULE_IBL_EXCEPTION_GEOIP: "An exception occurred while matching GeoIP information, please report the error to the developer" MODULE_IBL_MATCH_PORT: "Match Port rule: {}" MODULE_PID_MATCH_PEER_ID: "Match PeerId rule: {}" -MODULE_PCB_EXCESSIVE_DOWNLOAD: "Client excessive download: Torrent size: {}, total uploaded to this peer: {}, maximum allowed excessive download total: {}" +MODULE_PCB_EXCESSIVE_DOWNLOAD: "Client excessive download: Resource size: {}, total uploaded to this peer: {}, maximum allowed excessive download total: {}" MODULE_PCB_PEER_MORE_THAN_LOCAL_SKIP: "Client progress: {}, calculated minimal progress: {}, client progress more than local progress, skipping detection" MODULE_PCB_PEER_BAN_INCORRECT_PROGRESS: "Client progress: {}, calculated minimal: {}, difference: {}" MODULE_PCB_PEER_BAN_REWIND: "Client progress: {}, calculated minimal progress: {}; last time recorded progress: {}, rewind progress: {}, max allowed rewind threshold: {}" diff --git a/src/main/resources/lang/messages_fallback.yml b/src/main/resources/lang/messages_fallback.yml index 0ae4975f67..c7d513431b 100644 --- a/src/main/resources/lang/messages_fallback.yml +++ b/src/main/resources/lang/messages_fallback.yml @@ -25,7 +25,7 @@ MODULE_IBL_EXCEPTION_GEOIP: "匹配 GeoIP 信息时出现异常,请反馈错 MODULE_IBL_MATCH_PORT: "匹配 Port 规则: {}" MODULE_PID_MATCH_PEER_ID: "匹配 PeerId 规则: {}" MODULE_IBL_MATCH_CITY: "匹配城市名称规则: {}" -MODULE_PCB_EXCESSIVE_DOWNLOAD: "客户端下载过量:种子大小:{},上传给此对等体的总量:{},最大允许的过量下载总量:{}" +MODULE_PCB_EXCESSIVE_DOWNLOAD: "客户端下载过量:资源大小:{},上传给此对等体的总量:{},最大允许的过量下载总量:{}" MODULE_PCB_PEER_MORE_THAN_LOCAL_SKIP: "客户端进度:{},实际进度:{},客户端的进度多于本地进度,跳过检测" MODULE_PCB_PEER_BAN_INCORRECT_PROGRESS: "客户端进度:{},实际进度:{},差值:{}" MODULE_PCB_PEER_BAN_REWIND: "客户端进度:{},实际进度:{},上次记录进度:{},本次回退进度:{},差值:{}" diff --git a/src/main/resources/lang/zh_cn/messages.yml b/src/main/resources/lang/zh_cn/messages.yml index ad580d6e73..5e1ddf16a8 100644 --- a/src/main/resources/lang/zh_cn/messages.yml +++ b/src/main/resources/lang/zh_cn/messages.yml @@ -25,7 +25,7 @@ MODULE_IBL_EXCEPTION_GEOIP: "匹配 GeoIP 信息时出现异常,请反馈错 MODULE_IBL_MATCH_PORT: "匹配 Port 规则: {}" MODULE_PID_MATCH_PEER_ID: "匹配 PeerId 规则: {}" MODULE_IBL_MATCH_CITY: "匹配城市名称规则: {}" -MODULE_PCB_EXCESSIVE_DOWNLOAD: "客户端下载过量:种子大小:{},上传给此对等体的总量:{},最大允许的过量下载总量:{}" +MODULE_PCB_EXCESSIVE_DOWNLOAD: "客户端下载过量:资源大小:{},上传给此对等体的总量:{},最大允许的过量下载总量:{}" MODULE_PCB_PEER_MORE_THAN_LOCAL_SKIP: "客户端进度:{},实际进度:{},客户端的进度多于本地进度,跳过检测" MODULE_PCB_PEER_BAN_INCORRECT_PROGRESS: "客户端进度:{},实际进度:{},差值:{}" MODULE_PCB_PEER_BAN_REWIND: "客户端进度:{},实际进度:{},上次记录进度:{},本次回退进度:{},差值:{}" From e88e7b44b7ecaf61d214b14a7107437921fa7e5e Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:06:55 +0800 Subject: [PATCH 09/13] =?UTF-8?q?Revert=20"=E5=90=AC=E5=85=94=E5=AD=90?= =?UTF-8?q?=E7=9A=84=E8=AF=9D"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 5d77cd8363c8dbdb1c2b59e9ccab496166d52da3. --- .../impl/rule/ProgressCheatBlocker.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java b/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java index daf52bfee9..f938818ebb 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java +++ b/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java @@ -255,19 +255,29 @@ private void reloadConfig() { final double clientProgress = peer.getProgress(); // 客户端汇报进度 // actualUploaded = -1 代表客户端不支持统计此 Peer 总上传量 if (actualUploaded != -1 && blockExcessiveClients) { - long referenceSize = (System.getProperty("pbh.pcb.disable-completed-excessive") == null && completedSize > 0 && actualUploaded > completedSize) ? completedSize : torrentSize; - // 下载量超过种子大小或者超过已下载大小,检查 - if (actualUploaded > referenceSize) { - long maxAllowedExcessiveThreshold = (long) (referenceSize * excessiveThreshold); + if (actualUploaded > torrentSize) { + // 下载量超过种子大小,检查 + long maxAllowedExcessiveThreshold = (long) (torrentSize * 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, - referenceSize, - actualUploaded, - maxAllowedExcessiveThreshold)); + progressRecorder.invalidate(client); // 封禁时,移除缓存 + 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)); + } + } else if (System.getProperty("pbh.pcb.disable-completed-excessive") == null && completedSize > 0 && actualUploaded > completedSize) { + // 下载量超过任务大小,检查 + long maxAllowedExcessiveThreshold = (long) (completedSize * 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), + new TranslationComponent(Lang.MODULE_PCB_EXCESSIVE_DOWNLOAD, + completedSize, + actualUploaded, + maxAllowedExcessiveThreshold)); } } } From af271961bf4e0b808ec2dbf4f7234e9fe0b136e8 Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:12:47 +0800 Subject: [PATCH 10/13] =?UTF-8?q?=E5=86=8D=E6=AC=A1=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../peerbanhelper/module/impl/rule/ProgressCheatBlocker.java | 3 ++- src/main/java/com/ghostchu/peerbanhelper/text/Lang.java | 1 + src/main/resources/lang/en_us/messages.yml | 3 ++- src/main/resources/lang/messages_fallback.yml | 3 ++- src/main/resources/lang/zh_cn/messages.yml | 3 ++- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java b/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java index f938818ebb..bdc841238f 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java +++ b/src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java @@ -274,7 +274,8 @@ private void reloadConfig() { clientTask.setBanDelayWindowEndAt(0L); progressRecorder.invalidate(client); // 封禁时,移除缓存 return new CheckResult(getClass(), PeerAction.BAN, banDuration, new TranslationComponent(Lang.PCB_RULE_REACHED_MAX_ALLOWED_EXCESSIVE_THRESHOLD), - new TranslationComponent(Lang.MODULE_PCB_EXCESSIVE_DOWNLOAD, + new TranslationComponent(Lang.MODULE_PCB_EXCESSIVE_DOWNLOAD_INCOMPLETE, + torrentSize, completedSize, actualUploaded, maxAllowedExcessiveThreshold)); diff --git a/src/main/java/com/ghostchu/peerbanhelper/text/Lang.java b/src/main/java/com/ghostchu/peerbanhelper/text/Lang.java index 64248f103d..6d88cc35a2 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/text/Lang.java +++ b/src/main/java/com/ghostchu/peerbanhelper/text/Lang.java @@ -28,6 +28,7 @@ public enum Lang { MODULE_IBL_MATCH_PORT, MODULE_PID_MATCH_PEER_ID, MODULE_PCB_EXCESSIVE_DOWNLOAD, + MODULE_PCB_EXCESSIVE_DOWNLOAD_INCOMPLETE, MODULE_PCB_PEER_MORE_THAN_LOCAL_SKIP, MODULE_PCB_PEER_BAN_INCORRECT_PROGRESS, MODULE_PCB_PEER_BAN_REWIND, diff --git a/src/main/resources/lang/en_us/messages.yml b/src/main/resources/lang/en_us/messages.yml index e8ba0f2b60..c022955665 100644 --- a/src/main/resources/lang/en_us/messages.yml +++ b/src/main/resources/lang/en_us/messages.yml @@ -25,7 +25,8 @@ MODULE_IBL_MATCH_CITY: "Match city rule: {}" MODULE_IBL_EXCEPTION_GEOIP: "An exception occurred while matching GeoIP information, please report the error to the developer" MODULE_IBL_MATCH_PORT: "Match Port rule: {}" MODULE_PID_MATCH_PEER_ID: "Match PeerId rule: {}" -MODULE_PCB_EXCESSIVE_DOWNLOAD: "Client excessive download: Resource size: {}, total uploaded to this peer: {}, maximum allowed excessive download total: {}" +MODULE_PCB_EXCESSIVE_DOWNLOAD: "Client excessive download: Torrent size: {}, total uploaded to this peer: {}, maximum allowed excessive download total: {}" +MODULE_PCB_EXCESSIVE_DOWNLOAD_INCOMPLETE: "Client excessive download: Torrent size: {} ({} downloaded), total uploaded to this peer: {}, maximum allowed excessive download total: {}" MODULE_PCB_PEER_MORE_THAN_LOCAL_SKIP: "Client progress: {}, calculated minimal progress: {}, client progress more than local progress, skipping detection" MODULE_PCB_PEER_BAN_INCORRECT_PROGRESS: "Client progress: {}, calculated minimal: {}, difference: {}" MODULE_PCB_PEER_BAN_REWIND: "Client progress: {}, calculated minimal progress: {}; last time recorded progress: {}, rewind progress: {}, max allowed rewind threshold: {}" diff --git a/src/main/resources/lang/messages_fallback.yml b/src/main/resources/lang/messages_fallback.yml index c7d513431b..9e7e9e62cb 100644 --- a/src/main/resources/lang/messages_fallback.yml +++ b/src/main/resources/lang/messages_fallback.yml @@ -25,7 +25,8 @@ MODULE_IBL_EXCEPTION_GEOIP: "匹配 GeoIP 信息时出现异常,请反馈错 MODULE_IBL_MATCH_PORT: "匹配 Port 规则: {}" MODULE_PID_MATCH_PEER_ID: "匹配 PeerId 规则: {}" MODULE_IBL_MATCH_CITY: "匹配城市名称规则: {}" -MODULE_PCB_EXCESSIVE_DOWNLOAD: "客户端下载过量:资源大小:{},上传给此对等体的总量:{},最大允许的过量下载总量:{}" +MODULE_PCB_EXCESSIVE_DOWNLOAD: "客户端下载过量:种子大小:{},上传给此对等体的总量:{},最大允许的过量下载总量:{}" +MODULE_PCB_EXCESSIVE_DOWNLOAD_INCOMPLETE: "客户端下载过量:种子大小:{} ({} 已下载),上传给此对等体的总量:{},最大允许的过量下载总量:{}" MODULE_PCB_PEER_MORE_THAN_LOCAL_SKIP: "客户端进度:{},实际进度:{},客户端的进度多于本地进度,跳过检测" MODULE_PCB_PEER_BAN_INCORRECT_PROGRESS: "客户端进度:{},实际进度:{},差值:{}" MODULE_PCB_PEER_BAN_REWIND: "客户端进度:{},实际进度:{},上次记录进度:{},本次回退进度:{},差值:{}" diff --git a/src/main/resources/lang/zh_cn/messages.yml b/src/main/resources/lang/zh_cn/messages.yml index 5e1ddf16a8..2a9f92e558 100644 --- a/src/main/resources/lang/zh_cn/messages.yml +++ b/src/main/resources/lang/zh_cn/messages.yml @@ -25,7 +25,8 @@ MODULE_IBL_EXCEPTION_GEOIP: "匹配 GeoIP 信息时出现异常,请反馈错 MODULE_IBL_MATCH_PORT: "匹配 Port 规则: {}" MODULE_PID_MATCH_PEER_ID: "匹配 PeerId 规则: {}" MODULE_IBL_MATCH_CITY: "匹配城市名称规则: {}" -MODULE_PCB_EXCESSIVE_DOWNLOAD: "客户端下载过量:资源大小:{},上传给此对等体的总量:{},最大允许的过量下载总量:{}" +MODULE_PCB_EXCESSIVE_DOWNLOAD: "客户端下载过量:种子大小:{},上传给此对等体的总量:{},最大允许的过量下载总量:{}" +MODULE_PCB_EXCESSIVE_DOWNLOAD_INCOMPLETE: "客户端下载过量:种子大小:{} ({} 已下载),上传给此对等体的总量:{},最大允许的过量下载总量:{}" MODULE_PCB_PEER_MORE_THAN_LOCAL_SKIP: "客户端进度:{},实际进度:{},客户端的进度多于本地进度,跳过检测" MODULE_PCB_PEER_BAN_INCORRECT_PROGRESS: "客户端进度:{},实际进度:{},差值:{}" MODULE_PCB_PEER_BAN_REWIND: "客户端进度:{},实际进度:{},上次记录进度:{},本次回退进度:{},差值:{}" From 12377d475ce44b52ed3fcb1071efe9ec7268bea6 Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Thu, 21 Nov 2024 06:09:39 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E5=AE=8C=E5=96=84=20qB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/qbittorrent/AbstractQbittorrent.java | 78 ++++++++++--------- .../qbittorrent/impl/QBittorrentTorrent.java | 8 +- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/AbstractQbittorrent.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/AbstractQbittorrent.java index 1b687a393b..2e289e6eec 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/AbstractQbittorrent.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/AbstractQbittorrent.java @@ -49,7 +49,7 @@ public abstract class AbstractQbittorrent extends AbstractDownloader { protected final String apiEndpoint; protected final HttpClient httpClient; protected final QBittorrentConfig config; - protected final Cache isPrivateCache; + protected final Cache torrentPropertiesCache; public AbstractQbittorrent(String name, QBittorrentConfig config, AlertManager alertManager) { super(name, alertManager); @@ -77,7 +77,7 @@ public PasswordAuthentication requestPasswordAuthenticationInstance(String host, this.httpClient = builder.build(); YamlConfiguration profileConfig = Main.getProfileConfig(); - this.isPrivateCache = CacheBuilder.newBuilder() + this.torrentPropertiesCache = CacheBuilder.newBuilder() .maximumSize(2000) .expireAfterAccess( profileConfig.getLong("check-interval", 5000) + (1000 * 60), @@ -156,56 +156,60 @@ public List getTorrents() { List qbTorrent = JsonUtil.getGson().fromJson(request.body(), new TypeToken>() { }.getType()); - if (config.isIgnorePrivate()) { - fillTorrentPrivateField(qbTorrent); - } + fillTorrentProperties(qbTorrent); + return qbTorrent.stream().map(t -> (Torrent) t) .filter(t -> !config.isIgnorePrivate() || !t.isPrivate()) .collect(Collectors.toList()); } - protected void fillTorrentPrivateField(List qbTorrent) { - Semaphore privateStatusLimit = new Semaphore(5); + protected void fillTorrentProperties(List qbTorrent) { + Semaphore torrentPropertiesLimit = new Semaphore(5); try (ExecutorService service = Executors.newVirtualThreadPerTaskExecutor()) { qbTorrent.stream() - .filter(torrent -> torrent.getPrivateTorrent() == null) + .filter(torrent -> (config.isIgnorePrivate() && torrent.getPrivateTorrent() == null) + || torrent.getPieceSize() <= 0 || torrent.getPiecesHave() <= 0) .forEach(detail -> service.submit(() -> { - if (detail.getPrivateTorrent() == null) { - try { - privateStatusLimit.acquire(); - detail.setPrivateTorrent(getPrivateStatus(detail)); - } catch (Exception e) { - log.debug("Failed to load private cache", e); - } finally { - privateStatusLimit.release(); + try { + torrentPropertiesLimit.acquire(); + TorrentProperties properties = getTorrentProperties(detail); + if (detail.getCompleted() != properties.completed) { + // completed value changed, invalidate cache and fetch again. + torrentPropertiesCache.invalidate(detail.getHash()); + properties = getTorrentProperties(detail); + } + if (config.isIgnorePrivate() && detail.getPrivateTorrent() == null) { + log.debug("Field is_private is not present, query from properties api, hash: {}", detail.getHash()); + detail.setPrivateTorrent(properties.isPrivate); + } + if (detail.getPieceSize() <= 0 || detail.getPiecesHave() <= 0) { + log.debug("Field piece_size,pieces_have is not present, query from properties api, hash: {}", detail.getHash()); + detail.setPieceSize(properties.pieceSize); + detail.setPiecesHave(properties.piecesHave); } + } catch (Exception e) { + log.debug("Failed to load properties cache", e); + } finally { + torrentPropertiesLimit.release(); } })); } } - protected Boolean getPrivateStatus(QBittorrentTorrent torrent) { - if (torrent.getPrivateTorrent() != null) { - return torrent.getPrivateTorrent(); - } + protected TorrentProperties getTorrentProperties(QBittorrentTorrent torrent) { try { - return isPrivateCache.get(torrent.getHash(), () -> { - try { - log.debug("Field is_private is not present and cache miss, query from properties api, hash: {}", torrent.getHash()); - HttpResponse res = httpClient.send( - MutableRequest.GET(apiEndpoint + "/torrents/properties?hash=" + torrent.getHash()), - HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8) - ); - if (res.statusCode() == 200) { - var newDetail = JsonUtil.getGson().fromJson(res.body(), QBittorrentTorrent.class); - return newDetail.getPrivateTorrent(); - } else { - log.warn("Error fetching properties for torrent hash: {}, status: {}", torrent.getHash(), res.statusCode()); - } - } catch (Exception e) { - log.warn("Error fetching properties for torrent hash: {}", torrent.getHash(), e); + return torrentPropertiesCache.get(torrent.getHash(), () -> { + log.debug("torrent properties cache miss, query from properties api, hash: {}", torrent.getHash()); + HttpResponse res = httpClient.send( + MutableRequest.GET(apiEndpoint + "/torrents/properties?hash=" + torrent.getHash()), + HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8) + ); + if (res.statusCode() == 200) { + var newDetail = JsonUtil.getGson().fromJson(res.body(), QBittorrentTorrent.class); + return new TorrentProperties(newDetail.getPrivateTorrent(), torrent.getCompleted(), newDetail.getPieceSize(), newDetail.getPiecesHave()); } - return null; + // loader must not return null; it may either return a non-null value or throw an exception. + throw new IllegalStateException(String.format("Error fetching properties for torrent hash: %s, status: %d", torrent.getHash(), res.statusCode())); }); } catch (Exception e) { return null; @@ -322,5 +326,5 @@ public void close() throws Exception { } - + public record TorrentProperties(boolean isPrivate, long completed, long pieceSize, long piecesHave) {} } diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/impl/QBittorrentTorrent.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/impl/QBittorrentTorrent.java index 82ceb4977a..6315268d4e 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/impl/QBittorrentTorrent.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/impl/QBittorrentTorrent.java @@ -54,6 +54,12 @@ public final class QBittorrentTorrent implements Torrent { // @SerializedName("f_l_piece_prio") // private Boolean fLPiecePrio; + @SerializedName("piece_size") + private long pieceSize; + + @SerializedName("pieces_have") + private long piecesHave; + @SerializedName("force_start") private boolean forceStart; @@ -192,7 +198,7 @@ public long getSize() { @Override public long getCompletedSize() { - return completed; + return (pieceSize > 0 && piecesHave > 0) ? pieceSize * piecesHave : -1; } @Override From cbdc428eea3cdcd7279bb935899490454983e737 Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Thu, 21 Nov 2024 06:34:03 +0800 Subject: [PATCH 12/13] =?UTF-8?q?=E5=90=AC=E5=85=94=E5=AD=90=E7=9A=84?= =?UTF-8?q?=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../impl/qbittorrent/AbstractQbittorrent.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/AbstractQbittorrent.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/AbstractQbittorrent.java index 2e289e6eec..7364eea240 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/AbstractQbittorrent.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/AbstractQbittorrent.java @@ -173,17 +173,25 @@ protected void fillTorrentProperties(List qbTorrent) { try { torrentPropertiesLimit.acquire(); TorrentProperties properties = getTorrentProperties(detail); + if (properties == null) { + log.warn("Failed to retrieve properties for torrent: {}", detail.getHash()); + return; + } if (detail.getCompleted() != properties.completed) { // completed value changed, invalidate cache and fetch again. torrentPropertiesCache.invalidate(detail.getHash()); properties = getTorrentProperties(detail); + if (properties == null) { + log.warn("Failed to retrieve properties after cache invalidation for torrent: {}", detail.getHash()); + return; + } } if (config.isIgnorePrivate() && detail.getPrivateTorrent() == null) { - log.debug("Field is_private is not present, query from properties api, hash: {}", detail.getHash()); + log.debug("Field is_private is not present, querying from properties API, hash: {}", detail.getHash()); detail.setPrivateTorrent(properties.isPrivate); } if (detail.getPieceSize() <= 0 || detail.getPiecesHave() <= 0) { - log.debug("Field piece_size,pieces_have is not present, query from properties api, hash: {}", detail.getHash()); + log.debug("Field piece_size or pieces_have is not present, querying from properties API, hash: {}", detail.getHash()); detail.setPieceSize(properties.pieceSize); detail.setPiecesHave(properties.piecesHave); } From a1b05e0806173b0598f52062bb5ce723045fac84 Mon Sep 17 00:00:00 2001 From: paulzzh <28055560+paulzzh@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:52:20 +0800 Subject: [PATCH 13/13] =?UTF-8?q?=E6=8D=A2=E6=88=90=20long?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../downloader/impl/qbittorrent/impl/QBittorrentTorrent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/impl/QBittorrentTorrent.java b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/impl/QBittorrentTorrent.java index 6315268d4e..aeb8c9409f 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/impl/QBittorrentTorrent.java +++ b/src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/impl/QBittorrentTorrent.java @@ -26,7 +26,7 @@ public final class QBittorrentTorrent implements Torrent { private String category; @SerializedName("completed") - private Long completed; + private long completed; // // @SerializedName("completion_on") // private Long completionOn;