Skip to content

Commit

Permalink
修复进度检查器的上次进度记录总是为0的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Feb 7, 2024
1 parent 2f882c0 commit cce2eff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
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>1.1</version>
<version>1.2</version>

<name>PeerBanHelper</name>

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/ghostchu/peerbanhelper/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
@Slf4j
public class Main {
public static void main(String[] args) throws InterruptedException {
log.info("PeerBanHelper - v1.1 - by Ghost_chu");
log.info("PeerBanHelper - v1.2 - by Ghost_chu");
Unirest.config()
.setDefaultHeader("User-Agent", "PeerBanHelper/1.1")
.setDefaultHeader("User-Agent", "PeerBanHelper/1.2")
.enableCookieManagement(true);
List<Downloader> downloaderList = new ArrayList<>();
log.info("加载配置文件……");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public BanResult shouldBanPeer(Torrent torrent, Peer peer) {
final double actualProgress = (double) uploaded / torrentSize;
final double clientProgress = peer.getProgress();

if(getConfig().getBoolean("block-excessive-clients") && (uploaded > torrentSize)){
if (getConfig().getBoolean("block-excessive-clients") && (uploaded > torrentSize)) {
// 下载过量,检查
long maxAllowedExcessiveThreshold = (long) (torrentSize * getConfig().getDouble("excessive-threshold"));
if(uploaded > maxAllowedExcessiveThreshold){
return new BanResult(true, "客户端下载过量:种子大小:"+torrentSize+",上传给此对等体的总量:"+uploaded+",最大允许的过量下载总量:"+maxAllowedExcessiveThreshold);
if (uploaded > maxAllowedExcessiveThreshold) {
return new BanResult(true, "客户端下载过量:种子大小:" + torrentSize + ",上传给此对等体的总量:" + uploaded + ",最大允许的过量下载总量:" + maxAllowedExcessiveThreshold);
}
}

Expand All @@ -59,11 +59,13 @@ public BanResult shouldBanPeer(Torrent torrent, Peer peer) {
double rewindAllow = getConfig().getDouble("rewind-maximum-difference");
if (rewindAllow > 0) {
Double lastRecordedProgress = progressRecorder.getIfPresent(peer.getAddress());
progressRecorder.put(peer.getAddress(), peer.getProgress());
if (lastRecordedProgress != null) {
double rewind = lastRecordedProgress - peer.getProgress();
boolean ban = rewind > rewindAllow;
return new BanResult(ban, "客户端进度:" + formatPercent(clientProgress) + ",实际进度:" + formatPercent(actualProgress) + ",上次记录进度:" + formatPercent(lastRecordedProgress) + ",本次进度:" + formatPercent(rewind) + ",差值:" + formatPercent(rewindAllow));
}

}
return new BanResult(false, "客户端进度:" + formatPercent(clientProgress) + ",实际进度:" + formatPercent(actualProgress) + ",差值:" + formatPercent(difference));
}
Expand Down

0 comments on commit cce2eff

Please sign in to comment.