* i2psnark:

- Choke slower when at bandwidth limit
      - Fix completion % for small files
      - Use Random from context
This commit is contained in:
zzz
2010-05-23 16:18:10 +00:00
parent 48da98d0e4
commit 5d7c9ebf82
5 changed files with 9 additions and 7 deletions

View File

@ -26,6 +26,8 @@ import java.util.List;
import java.util.Random;
import java.util.TimerTask;
import net.i2p.I2PAppContext;
/**
* TimerTask that checks for good/bad up/downloader. Works together
* with the PeerCoordinator to select which Peers get (un)choked.
@ -43,7 +45,7 @@ class PeerCheckerTask extends TimerTask
this.coordinator = coordinator;
}
private Random random = new Random();
private static final Random random = I2PAppContext.getGlobalContext().random();
public void run()
{
@ -113,10 +115,10 @@ class PeerCheckerTask extends TimerTask
+ " C: " + peer.isChoked(),
Snark.DEBUG);
// Choke half of them rather than all so it isn't so drastic...
// Choke a third of them rather than all so it isn't so drastic...
// unless this torrent is over the limit all by itself.
boolean overBWLimitChoke = upload > 0 &&
((overBWLimit && random.nextBoolean()) ||
((overBWLimit && random.nextInt(3) == 0) ||
(coordinator.overUpBWLimit(uploaded)));
// If we are at our max uploaders and we have lots of other

View File

@ -97,7 +97,7 @@ public class PeerCoordinator implements PeerListener
// Install a timer to check the uploaders.
// Randomize the first start time so multiple tasks are spread out,
// this will help the behavior with global limits
Random r = new Random();
Random r = I2PAppContext.getGlobalContext().random();
timer.schedule(new PeerCheckerTask(_util, this), (CHECK_PERIOD / 2) + r.nextInt((int) CHECK_PERIOD), CHECK_PERIOD);
}

View File

@ -321,7 +321,7 @@ public class Snark
// sixteen random bytes.
byte snark = (((3 + 7 + 10) * (1000 - 8)) / 992) - 17;
id = new byte[20];
Random random = new Random();
Random random = I2PAppContext.getGlobalContext().random();
int i;
for (i = 0; i < 9; i++)
id[i] = 0;

View File

@ -304,7 +304,7 @@ public class Storage
int pc = (int) (bytes / psz);
long rv = 0;
if (!bitfield.get(pc))
rv = psz - (bytes % psz);
rv = Math.min(psz - (start % psz), lengths[i]);
for (int j = pc + 1; j * psz < end; j++) {
if (!bitfield.get(j)) {
if ((j+1)*psz < end)

View File

@ -183,7 +183,7 @@ public class TrackerClient extends I2PAppThread
boolean runStarted = false;
boolean firstTime = true;
int consecutiveFails = 0;
Random r = new Random();
Random r = I2PAppContext.getGlobalContext().random();
while(!stop)
{
try