forked from I2P_Developers/i2p.i2p
i2psnark: Sequential piece priority within each file (ticket #2234)
This commit is contained in:
@ -573,7 +573,6 @@ public class Storage implements Closeable
|
||||
for (int i = 0; i < rv.length; i++) {
|
||||
pcEnd += piece_size;
|
||||
int pri = _torrentFiles.get(file).priority;
|
||||
// TODO if (_inOrder) ...
|
||||
while (fileEnd <= pcEnd && file < _torrentFiles.size() - 1) {
|
||||
file++;
|
||||
TorrentFile tf = _torrentFiles.get(file);
|
||||
@ -584,6 +583,25 @@ public class Storage implements Closeable
|
||||
}
|
||||
rv[i] = pri;
|
||||
}
|
||||
if (_inOrder) {
|
||||
// Do a second pass to set the priority of the pieces within each file
|
||||
// this only works because MAX_PIECES * MAX_FILES_PER_TORRENT < Integer.MAX_VALUE
|
||||
// the base file priority
|
||||
int pri = PRIORITY_SKIP;
|
||||
for (int i = 0; i < rv.length; i++) {
|
||||
int val = rv[i];
|
||||
if (val <= PRIORITY_NORMAL)
|
||||
continue;
|
||||
if (val != pri) {
|
||||
pri = val;
|
||||
// new file
|
||||
rv[i] *= MAX_PIECES;
|
||||
} else {
|
||||
// same file, decrement priority from previous piece
|
||||
rv[i] = rv[i-1] - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user