merge of '82b66240733c560b038d4874d1630bf59f5fbe1a'

and 'd6f8e674646687b5efb03d09b6cdca57c6bd8f50'
This commit is contained in:
dev
2010-05-23 19:52:49 +00:00
7 changed files with 30 additions and 9 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

View File

@@ -47,6 +47,8 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
private static final String NEWS_FILE = "docs/news.xml";
private static final String TEMP_NEWS_FILE = "news.xml.temp";
/** @since 0.7.14 not configurable */
private static final String BACKUP_NEWS_URL = "http://www.i2p2.i2p/_static/news/news.xml";
private NewsFetcher(I2PAppContext ctx) {
_context = ctx;
@@ -151,12 +153,20 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
try {
EepGet get = null;
if (shouldProxy)
get = new EepGet(_context, true, proxyHost, proxyPort, 2, _tempFile.getAbsolutePath(), newsURL, true, null, _lastModified);
get = new EepGet(_context, true, proxyHost, proxyPort, 0, _tempFile.getAbsolutePath(), newsURL, true, null, _lastModified);
else
get = new EepGet(_context, false, null, 0, 0, _tempFile.getAbsolutePath(), newsURL, true, null, _lastModified);
get.addStatusListener(this);
if (get.fetch())
if (get.fetch()) {
_lastModified = get.getLastModified();
} else {
// backup news location - always proxied
_tempFile.delete();
get = new EepGet(_context, true, proxyHost, proxyPort, 0, _tempFile.getAbsolutePath(), BACKUP_NEWS_URL, true, null, _lastModified);
get.addStatusListener(this);
if (get.fetch())
_lastModified = get.getLastModified();
}
} catch (Throwable t) {
_log.error("Error fetching the news", t);
}

View File

@@ -2,6 +2,15 @@
* core:
- fixed major security hole in DatagramDissector
2010-05-23 zzz
* i2psnark:
- Choke slower when at bandwidth limit
- Fix completion % for small files
- Use Random from context
* NewsFetcher:
- Add backup URL
- Change to 0 retries (was 2)
2010-05-21 zzz
* i2psnark:
- Spiff up dir listings