I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit ff313e03 authored by zzz's avatar zzz
Browse files

* i2psnark: Use smaller piece size for small torrents

parent 85001d26
No related branches found
No related tags found
No related merge requests found
...@@ -77,7 +77,7 @@ public class Storage ...@@ -77,7 +77,7 @@ public class Storage
private final AtomicInteger _allocateCount = new AtomicInteger(); private final AtomicInteger _allocateCount = new AtomicInteger();
/** The default piece size. */ /** The default piece size. */
private static final int MIN_PIECE_SIZE = 256*1024; private static final int DEFAULT_PIECE_SIZE = 256*1024;
/** note that we start reducing max number of peer connections above 1MB */ /** note that we start reducing max number of peer connections above 1MB */
public static final int MAX_PIECE_SIZE = 2*1024*1024; public static final int MAX_PIECE_SIZE = 2*1024*1024;
/** The maximum number of pieces in a torrent. */ /** The maximum number of pieces in a torrent. */
...@@ -146,7 +146,13 @@ public class Storage ...@@ -146,7 +146,13 @@ public class Storage
if (total > MAX_TOTAL_SIZE) if (total > MAX_TOTAL_SIZE)
throw new IOException("Torrent too big (" + total + " bytes), max is " + MAX_TOTAL_SIZE); throw new IOException("Torrent too big (" + total + " bytes), max is " + MAX_TOTAL_SIZE);
int pc_size = MIN_PIECE_SIZE; int pc_size;
if (total <= 5*1024*1024)
pc_size = DEFAULT_PIECE_SIZE / 4;
else if (total <= 10*1024*1024)
pc_size = DEFAULT_PIECE_SIZE / 2;
else
pc_size = DEFAULT_PIECE_SIZE;
int pcs = (int) ((total - 1)/pc_size) + 1; int pcs = (int) ((total - 1)/pc_size) + 1;
while (pcs > MAX_PIECES && pc_size < MAX_PIECE_SIZE) while (pcs > MAX_PIECES && pc_size < MAX_PIECE_SIZE)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment