-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0c32251
添加 completedSize
paulzzh 6ff6618
PCB 支持检查不完整任务的过量下载
paulzzh 5d77cd8
听兔子的话
paulzzh 512094a
fix build
paulzzh 3082913
完善 BiglyBT
paulzzh 1d66a33
添加 pbh.pcb.disable-completed-excessive
paulzzh c716e6b
完善 Transmission
paulzzh 0971a57
修改提示信息
paulzzh e88e7b4
Revert "听兔子的话"
paulzzh af27196
再次修改提示信息
paulzzh 0b20a9e
Merge remote-tracking branch 'origin/dev' into fixTorrentSize
paulzzh 12377d4
完善 qB
paulzzh cbdc428
听兔子的话
paulzzh a1b05e0
换成 long
paulzzh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 更新一下配置文件,这样前端才能增加对应的配置项 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
} | ||
} | ||
} | ||
// 如果客户端报告自己进度更多,则跳过检查 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add documentation and consider null safety
The
completed
field is crucial for the anti-leech functionality but lacks documentation. Additionally, usingLong
instead oflong
introduces potential null pointer risks ingetCompletedSize()
.Consider these improvements:
📝 Committable suggestion