NetDB: Negative cache LS received with zero leases

Ratchet: Don't schedule a reply to a LS with zero leases
This commit is contained in:
zzz
2021-04-01 08:12:35 -04:00
parent 562b86636a
commit 9b361ce71c
3 changed files with 13 additions and 3 deletions

View File

@@ -1479,6 +1479,9 @@ public final class ECIESAEADEngine {
if (entry.getType() != DatabaseEntry.KEY_TYPE_LS2)
continue;
LeaseSet2 ls2 = (LeaseSet2) entry;
// i2pd bug?
if (ls2.getLeaseCount() == 0)
return;
if (!ls2.isCurrent(Router.CLOCK_FUDGE_FACTOR))
continue;
PublicKey pk = ls2.getEncryptionKey(LeaseSetKeys.SET_EC);

View File

@@ -929,12 +929,19 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
long age = now - earliest;
Destination dest = leaseSet.getDestination();
String id = dest != null ? dest.toBase32() : leaseSet.getHash().toBase32();
if (_log.shouldLog(Log.WARN))
if (_log.shouldWarn())
_log.warn("Old leaseSet! not storing it: "
+ id
+ " first exp. " + new Date(earliest)
+ " last exp. " + new Date(latest),
+ " last exp. " + new Date(latest) + '\n' + leaseSet,
new Exception("Rejecting store"));
// i2pd bug?
// So we don't immediately go try to fetch it for a reply
if (leaseSet.getLeaseCount() == 0) {
for (int i = 0; i < NegativeLookupCache.MAX_FAILS; i++) {
lookupFailed(key);
}
}
return "Expired leaseSet for " + id
+ " expired " + DataHelper.formatDuration(age) + " ago";
}

View File

@@ -20,7 +20,7 @@ class NegativeLookupCache {
private final Map<Hash, Destination> badDests;
private final int _maxFails;
private static final int MAX_FAILS = 3;
static final int MAX_FAILS = 3;
private static final int MAX_BAD_DESTS = 128;
private static final long CLEAN_TIME = 2*60*1000;