- Thread magnet start if not connected

- Don't lose all DHT peers if we stop quickly
- Explore a kbucket if it's less than 3/4 full
- Change release torrent file names
This commit is contained in:
zzz
2012-10-23 19:34:35 +00:00
parent bb2363f68a
commit 2f69d16828
5 changed files with 13 additions and 7 deletions

View File

@ -518,6 +518,7 @@ public class KBucketSet<T extends SimpleDataStructure> {
/**
* For every bucket that hasn't been updated in this long,
* or isn't close to full,
* generate a random key that would be a member of that bucket.
* The returned keys may be searched for to "refresh" the buckets.
* @return non-null, closest first
@ -528,7 +529,7 @@ public class KBucketSet<T extends SimpleDataStructure> {
getReadLock();
try {
for (KBucket b : _buckets) {
if (b.getLastChanged() < old)
if (b.getLastChanged() < old || b.getKeyCount() < BUCKET_SIZE * 3 / 4)
rv.add(generateRandomKey(b));
}
} finally { releaseReadLock(); }

View File

@ -959,7 +959,7 @@ public class SnarkManager implements CompleteListener {
_snarks.put(name, torrent);
}
if (autoStart) {
torrent.startTorrent();
startTorrent(ih);
addMessage(_("Fetching {0}", name));
DHT dht = _util.getDHT();
boolean shouldWarn = _util.connected() &&

View File

@ -572,7 +572,9 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
_session.removeListener(I2PSession.PROTO_DATAGRAM_RAW, _rPort);
// clear the DHT and tracker
_tracker.stop();
PersistDHT.saveDHT(_knownNodes, _dhtFile);
// don't lose all our peers if we didn't have time to check them
boolean saveAll = _context.clock().now() - _started < 20*60*1000;
PersistDHT.saveDHT(_knownNodes, saveAll, _dhtFile);
_knownNodes.stop();
for (Iterator<ReplyWaiter> iter = _sentQueries.values().iterator(); iter.hasNext(); ) {
ReplyWaiter waiter = iter.next();

View File

@ -56,12 +56,15 @@ abstract class PersistDHT {
log.info("Loaded " + count + " nodes from " + file);
}
public static synchronized void saveDHT(DHTNodes nodes, File file) {
/**
* @param saveAll if true, don't check last seen time
*/
public static synchronized void saveDHT(DHTNodes nodes, boolean saveAll, File file) {
if (nodes.size() <= 0)
return;
Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistDHT.class);
int count = 0;
long maxAge = I2PAppContext.getGlobalContext().clock().now() - MAX_AGE;
long maxAge = saveAll ? 0 : I2PAppContext.getGlobalContext().clock().now() - MAX_AGE;
PrintWriter out = null;
try {
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(file), "ISO-8859-1")));

View File

@ -1554,7 +1554,7 @@
<arg value="i2pupdate.sud" />
</exec>
<!-- make torrent files -->
<copy file="i2pupdate.sud" tofile="i2pupdate_${release.number}.sud" />
<copy file="i2pupdate.sud" tofile="i2pupdate-${release.number}.sud" />
<java classname="org.klomp.snark.Storage" fork="true" failonerror="true">
<classpath>
<pathelement location="build/i2p.jar" />
@ -1562,7 +1562,7 @@
</classpath>
<arg value="i2pupdate_${release.number}.sud" />
</java>
<copy file="i2pupdate.su2" tofile="i2pupdate_${release.number}.su2" />
<copy file="i2pupdate.su2" tofile="i2pupdate-${release.number}.su2" />
<java classname="org.klomp.snark.Storage" fork="true" failonerror="true">
<classpath>
<pathelement location="build/i2p.jar" />