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

改进 ProgressCheatBlocker #591

Merged
merged 1 commit into from
Oct 13, 2024
Merged
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 @@ -239,12 +239,9 @@ private void reloadConfig() {
if (torrentSize <= 0) {
return pass();
}
if (torrentSize < torrentMinimumSize) {
return pass();
}

// 是否需要进行快速 PCB 测试
if (fastPcbTestPercentage > 0) {
if (fastPcbTestPercentage > 0 && !fileTooSmall(torrentSize)) {
// 只在 <= 0(也就是从未测试过)的情况下对其进行测试
if (clientTask.getFastPcbTestExecuteAt() <= 0) {
// 如果上传量大于设置的比率,我们主动断开一次连接,封禁 Peer 一段时间,并尽快解除封禁
Expand Down Expand Up @@ -281,7 +278,7 @@ private void reloadConfig() {
}
// 计算进度差异
double difference = Math.abs(actualProgress - clientProgress);
if (difference > maximumDifference) {
if (difference > maximumDifference && !fileTooSmall(torrentSize)) {
if (banPeerIfConditionReached(clientTask)) {
clientTask.setProgressDifferenceCounter(clientTask.getProgressDifferenceCounter() + 1);
clientTask.setBanDelayWindowEndAt(0L);
Expand All @@ -294,7 +291,7 @@ private void reloadConfig() {
}

}
if (rewindMaximumDifference > 0) {
if (rewindMaximumDifference > 0 && !fileTooSmall(torrentSize)) {
double lastRecord = clientTask.getLastReportProgress();
double rewind = lastRecord - peer.getProgress();
boolean ban = rewind > rewindMaximumDifference;
Expand All @@ -321,6 +318,10 @@ private void reloadConfig() {
}
}

private boolean fileTooSmall(long torrentSize) {
return torrentSize < torrentMinimumSize;
}

private boolean banPeerIfConditionReached(ClientTask clientTask) {
if (clientTask.getBanDelayWindowEndAt() == 0L) {
clientTask.setBanDelayWindowEndAt(System.currentTimeMillis() + this.maxWaitDuration);
Expand Down
Loading