* i2psnark:

- Adjust DHT timeouts
   - Add max peers per-torrent in tracker
   - Remove duplicate clean task for nodes
   - Fix another DHT warning message
This commit is contained in:
zzz
2012-08-17 14:09:49 +00:00
parent e01521618f
commit 3cac01ff27
5 changed files with 33 additions and 26 deletions

View File

@ -825,7 +825,7 @@ public class SnarkManager implements Snark.CompleteListener {
if (!TrackerClient.isValidAnnounce(info.getAnnounce())) {
if (info.isPrivate()) {
addMessage(_("ERROR - No I2P trackers in private torrent \"{0}\"", info.getName()));
} else if (_util.shouldUseOpenTrackers() && _util.getOpenTrackers() != null) {
} else if (!_util.getOpenTrackers().isEmpty()) {
addMessage(_("Warning - No I2P trackers in \"{0}\", will announce to I2P open trackers and DHT only.", info.getName()));
//addMessage(_("Warning - No I2P trackers in \"{0}\", will announce to I2P open trackers only.", info.getName()));
} else if (_util.shouldUseDHT()) {
@ -908,10 +908,13 @@ public class SnarkManager implements Snark.CompleteListener {
if (shouldAutoStart()) {
torrent.startTorrent();
addMessage(_("Fetching {0}", name));
boolean haveSavedPeers = false;
if ((_util.connected()) && !haveSavedPeers) {
addMessage(_("We have no saved peers and no other torrents are running. " +
"Fetch of {0} will not succeed until you start another torrent.", name));
DHT dht = _util.getDHT();
boolean shouldWarn = _util.connected() &&
_util.getOpenTrackers().isEmpty() &&
((!_util.shouldUseDHT()) || dht == null || dht.size() <= 0);
if (shouldWarn) {
addMessage(_("Open trackers are disabled and we have no DHT peers. " +
"Fetch of {0} may not succeed until you start another torrent, enable open trackers, or enable DHT.", name));
}
} else {
addMessage(_("Adding {0}", name));

View File

@ -38,11 +38,12 @@ class DHTNodes {
private volatile boolean _isRunning;
/** stagger with other cleaners */
private static final long CLEAN_TIME = 237*1000;
private static final long MAX_EXPIRE_TIME = 60*60*1000;
private static final long MIN_EXPIRE_TIME = 5*60*1000;
private static final long DELTA_EXPIRE_TIME = 7*60*1000;
private static final int MAX_PEERS = 999;
private static final long CLEAN_TIME = 187*1000;
/** how long since last heard from do we delete - BEP 5 says 15 minutes */
private static final long MAX_EXPIRE_TIME = 30*60*1000;
private static final long MIN_EXPIRE_TIME = 10*60*1000;
private static final long DELTA_EXPIRE_TIME = 3*60*1000;
private static final int MAX_PEERS = 799;
public DHTNodes(I2PAppContext ctx, NID me) {
_context = ctx;

View File

@ -34,11 +34,11 @@ class DHTTracker {
/** stagger with other cleaners */
private static final long CLEAN_TIME = 199*1000;
/** make this longer than postman's tracker */
private static final long MAX_EXPIRE_TIME = 95*60*1000;
private static final long MIN_EXPIRE_TIME = 5*60*1000;
private static final long DELTA_EXPIRE_TIME = 7*60*1000;
private static final long MAX_EXPIRE_TIME = 45*60*1000;
private static final long MIN_EXPIRE_TIME = 15*60*1000;
private static final long DELTA_EXPIRE_TIME = 3*60*1000;
private static final int MAX_PEERS = 2000;
private static final int MAX_PEERS_PER_TORRENT = 150;
DHTTracker(I2PAppContext ctx) {
_context = ctx;
@ -134,10 +134,20 @@ class DHTTracker {
peerCount++;
}
}
if (recent <= 0)
iter.remove();
else
if (recent > MAX_PEERS_PER_TORRENT) {
// too many, delete at random
// TODO per-torrent adjustable expiration?
for (Iterator<Peer> iterp = p.values().iterator(); iterp.hasNext() && p.size() > MAX_PEERS_PER_TORRENT; ) {
iterp.next();
iterp.remove();
peerCount--;
}
torrentCount++;
} else if (recent <= 0) {
iter.remove();
} else {
torrentCount++;
}
}
if (peerCount > MAX_PEERS)

View File

@ -135,10 +135,8 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
public static final boolean SECURE_NID = true;
/** how long since last heard from do we delete - BEP 5 says 15 minutes */
private static final long MAX_NODEINFO_AGE = 60*60*1000;
/** how long since generated do we delete - BEP 5 says 10 minutes */
private static final long MAX_TOKEN_AGE = 60*60*1000;
private static final long MAX_TOKEN_AGE = 15*60*1000;
private static final long MAX_INBOUND_TOKEN_AGE = MAX_TOKEN_AGE - 5*60*1000;
/** how long since sent do we wait for a reply */
private static final long MAX_MSGID_AGE = 2*60*1000;
@ -1469,11 +1467,6 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
iter.remove();
}
// TODO sent queries?
for (Iterator<NodeInfo> iter = _knownNodes.values().iterator(); iter.hasNext(); ) {
NodeInfo ni = iter.next();
if (ni.lastSeen() < now - MAX_NODEINFO_AGE)
iter.remove();
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("KRPC cleaner done, now with " +
_outgoingTokens.size() + " sent Tokens, " +

View File

@ -16,6 +16,6 @@ import net.i2p.data.Hash;
class Peers extends ConcurrentHashMap<Hash, Peer> {
public Peers() {
super();
super(8);
}
}