forked from I2P_Developers/i2p.i2p
* i2psnark: Fix inaccuracy in the completed bytes display
This commit is contained in:
@ -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
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user