cleaned up the validation of leaseSet/routerInfo elements being accepted so we validate only in one place (in the facade instead of both the facade and the dataStore)

don't accept entries created (too far) in the future
This commit is contained in:
jrandom
2004-08-10 16:55:54 +00:00
committed by zzz
parent 97e5952544
commit b89e26c460
2 changed files with 14 additions and 14 deletions

View File

@@ -428,6 +428,9 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
}
}
/** I don't think it'll ever make sense to have a lease last for a full day */
private static final long MAX_LEASE_FUTURE = 24*60*60*1000;
public LeaseSet store(Hash key, LeaseSet leaseSet) {
long start = _context.clock().now();
if (!_initialized) return null;
@@ -444,6 +447,10 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
if (_log.shouldLog(Log.WARN))
_log.warn("Old leaseSet! not storing it: " + leaseSet);
return null;
} else if (leaseSet.getEarliestLeaseDate() > _context.clock().now() + MAX_LEASE_FUTURE) {
if (_log.shouldLog(Log.WARN))
_log.warn("LeaseSet to expire too far in the future: " + leaseSet);
return null;
}
LeaseSet rv = null;
@@ -499,6 +506,11 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
+ " peers left (curPeer: " + key.toBase64() + " published on "
+ new Date(routerInfo.getPublished()));
}
} else if (routerInfo.getPublished() > start + Router.CLOCK_FUDGE_FACTOR) {
if (_log.shouldLog(Log.ERROR))
_log.error("Peer " + key.toBase64() + " published their leaseSet in the future?! ["
+ new Date(routerInfo.getPublished()) + "]");
return null;
}
RouterInfo rv = null;

View File

@@ -215,13 +215,7 @@ class PersistentDataStore extends TransientDataStore {
fis = new FileInputStream(_leaseFile);
LeaseSet ls = new LeaseSet();
ls.readBytes(fis);
if (ls.isCurrent(Router.CLOCK_FUDGE_FACTOR)) {
_log.info("Reading in new LeaseSet: " + ls.getDestination().calculateHash());
accept(ls);
} else {
_log.warn("Expired LeaseSet found for " + ls.getDestination().calculateHash() + ": Deleting");
corrupt = true;
}
_facade.store(ls.getDestination().calculateHash(), ls);
} catch (DataFormatException dfe) {
_log.warn("Error reading the leaseSet from " + _leaseFile.getAbsolutePath(), dfe);
corrupt = true;
@@ -272,13 +266,7 @@ class PersistentDataStore extends TransientDataStore {
fis = new FileInputStream(_routerFile);
RouterInfo ri = new RouterInfo();
ri.readBytes(fis);
if (ri.isValid()) {
_log.info("Reading in new RouterInfo: " + ri.getIdentity().getHash());
accept(ri);
} else {
_log.warn("Invalid routerInfo found for " + ri.getIdentity().getHash() + ": " + ri);
corrupt = true;
}
_facade.store(ri.getIdentity().getHash(), ri);
} catch (DataFormatException dfe) {
_log.warn("Error reading the routerInfo from " + _routerFile.getAbsolutePath(), dfe);
corrupt = true;