* i2psnark: Fix inaccuracy in the completed bytes display

This commit is contained in:
zzz
2011-09-12 14:03:51 +00:00
parent 540172117f
commit 61831b11dc
3 changed files with 22 additions and 2 deletions

View File

@ -779,6 +779,26 @@ public class Snark
return -1;
}
/**
* @return exact value. or -1 if no storage yet.
* getNeeded() * pieceLength(0) isn't accurate if last piece
* is still needed.
* @since 0.8.9
*/
public long getRemainingLength() {
if (meta != null && storage != null) {
long needed = storage.needed();
long length0 = meta.getPieceLength(0);
long remaining = needed * length0;
// fixup if last piece is needed
int last = meta.getPieces() - 1;
if (last != 0 && !storage.getBitField().get(last))
remaining -= length0 - meta.getPieceLength(last);
return remaining;
}
return -1;
}
/**
* @return number of pieces still needed (magnet mode or not), or -1 if unknown
* @since 0.8.4

View File

@ -765,8 +765,7 @@ public class I2PSnarkServlet extends Default {
}
}
long total = snark.getTotalLength();
// Early typecast, avoid possibly overflowing a temp integer
long remaining = (long) snark.getNeeded() * (long) snark.getPieceLength(0);
long remaining = snark.getRemainingLength();
if (remaining > total)
remaining = total;
long downBps = snark.getDownloadRate();