forked from I2P_Developers/i2p.i2p
* i2psnark:
- Choke slower when at bandwidth limit - Fix completion % for small files - Use Random from context
This commit is contained in:
@ -26,6 +26,8 @@ import java.util.List;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TimerTask that checks for good/bad up/downloader. Works together
|
* TimerTask that checks for good/bad up/downloader. Works together
|
||||||
* with the PeerCoordinator to select which Peers get (un)choked.
|
* with the PeerCoordinator to select which Peers get (un)choked.
|
||||||
@ -43,7 +45,7 @@ class PeerCheckerTask extends TimerTask
|
|||||||
this.coordinator = coordinator;
|
this.coordinator = coordinator;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Random random = new Random();
|
private static final Random random = I2PAppContext.getGlobalContext().random();
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
@ -113,10 +115,10 @@ class PeerCheckerTask extends TimerTask
|
|||||||
+ " C: " + peer.isChoked(),
|
+ " C: " + peer.isChoked(),
|
||||||
Snark.DEBUG);
|
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.
|
// unless this torrent is over the limit all by itself.
|
||||||
boolean overBWLimitChoke = upload > 0 &&
|
boolean overBWLimitChoke = upload > 0 &&
|
||||||
((overBWLimit && random.nextBoolean()) ||
|
((overBWLimit && random.nextInt(3) == 0) ||
|
||||||
(coordinator.overUpBWLimit(uploaded)));
|
(coordinator.overUpBWLimit(uploaded)));
|
||||||
|
|
||||||
// If we are at our max uploaders and we have lots of other
|
// If we are at our max uploaders and we have lots of other
|
||||||
|
@ -97,7 +97,7 @@ public class PeerCoordinator implements PeerListener
|
|||||||
// Install a timer to check the uploaders.
|
// Install a timer to check the uploaders.
|
||||||
// Randomize the first start time so multiple tasks are spread out,
|
// Randomize the first start time so multiple tasks are spread out,
|
||||||
// this will help the behavior with global limits
|
// 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);
|
timer.schedule(new PeerCheckerTask(_util, this), (CHECK_PERIOD / 2) + r.nextInt((int) CHECK_PERIOD), CHECK_PERIOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ public class Snark
|
|||||||
// sixteen random bytes.
|
// sixteen random bytes.
|
||||||
byte snark = (((3 + 7 + 10) * (1000 - 8)) / 992) - 17;
|
byte snark = (((3 + 7 + 10) * (1000 - 8)) / 992) - 17;
|
||||||
id = new byte[20];
|
id = new byte[20];
|
||||||
Random random = new Random();
|
Random random = I2PAppContext.getGlobalContext().random();
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 9; i++)
|
for (i = 0; i < 9; i++)
|
||||||
id[i] = 0;
|
id[i] = 0;
|
||||||
|
@ -304,7 +304,7 @@ public class Storage
|
|||||||
int pc = (int) (bytes / psz);
|
int pc = (int) (bytes / psz);
|
||||||
long rv = 0;
|
long rv = 0;
|
||||||
if (!bitfield.get(pc))
|
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++) {
|
for (int j = pc + 1; j * psz < end; j++) {
|
||||||
if (!bitfield.get(j)) {
|
if (!bitfield.get(j)) {
|
||||||
if ((j+1)*psz < end)
|
if ((j+1)*psz < end)
|
||||||
|
@ -183,7 +183,7 @@ public class TrackerClient extends I2PAppThread
|
|||||||
boolean runStarted = false;
|
boolean runStarted = false;
|
||||||
boolean firstTime = true;
|
boolean firstTime = true;
|
||||||
int consecutiveFails = 0;
|
int consecutiveFails = 0;
|
||||||
Random r = new Random();
|
Random r = I2PAppContext.getGlobalContext().random();
|
||||||
while(!stop)
|
while(!stop)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
Reference in New Issue
Block a user