forked from I2P_Developers/i2p.i2p
NetDB: Remove duplicate store in FloodOnlyLookupMatchJob
which bypassed all the checks in HandleFloodfillDatabaseStoreMessageJob Don't store an entry which is older
This commit is contained in:
@@ -5,7 +5,6 @@ import net.i2p.data.LeaseSet;
|
|||||||
import net.i2p.data.i2np.DatabaseSearchReplyMessage;
|
import net.i2p.data.i2np.DatabaseSearchReplyMessage;
|
||||||
import net.i2p.data.i2np.DatabaseStoreMessage;
|
import net.i2p.data.i2np.DatabaseStoreMessage;
|
||||||
import net.i2p.data.i2np.I2NPMessage;
|
import net.i2p.data.i2np.I2NPMessage;
|
||||||
import net.i2p.data.router.RouterInfo;
|
|
||||||
import net.i2p.router.JobImpl;
|
import net.i2p.router.JobImpl;
|
||||||
import net.i2p.router.ReplyJob;
|
import net.i2p.router.ReplyJob;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
@@ -14,6 +13,7 @@ import net.i2p.util.Log;
|
|||||||
class FloodOnlyLookupMatchJob extends JobImpl implements ReplyJob {
|
class FloodOnlyLookupMatchJob extends JobImpl implements ReplyJob {
|
||||||
private final Log _log;
|
private final Log _log;
|
||||||
private final FloodSearchJob _search;
|
private final FloodSearchJob _search;
|
||||||
|
private volatile boolean _success;
|
||||||
|
|
||||||
public FloodOnlyLookupMatchJob(RouterContext ctx, FloodSearchJob job) {
|
public FloodOnlyLookupMatchJob(RouterContext ctx, FloodSearchJob job) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
@@ -22,13 +22,15 @@ class FloodOnlyLookupMatchJob extends JobImpl implements ReplyJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void runJob() {
|
public void runJob() {
|
||||||
if (getContext().netDb().lookupLocally(_search.getKey()) != null) {
|
if (_success) {
|
||||||
if (_log.shouldLog(Log.INFO))
|
if (_log.shouldLog(Log.INFO))
|
||||||
_log.info(_search.getJobId() + ": search match and found locally");
|
_log.info(_search.getJobId() + ": search match for " + _search.getKey());
|
||||||
_search.success();
|
_search.success();
|
||||||
} else {
|
} else {
|
||||||
// In practice, we always have zero remaining when this is called,
|
// In practice, we always have zero remaining when this is called,
|
||||||
// because the selector only returns true when there is zero remaining
|
// because the selector only returns true when there is zero remaining
|
||||||
|
if (_log.shouldLog(Log.INFO))
|
||||||
|
_log.info(_search.getJobId() + ": search failed for " + _search.getKey());
|
||||||
_search.failed();
|
_search.failed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,22 +38,25 @@ class FloodOnlyLookupMatchJob extends JobImpl implements ReplyJob {
|
|||||||
public String getName() { return "NetDb flood search match"; }
|
public String getName() { return "NetDb flood search match"; }
|
||||||
|
|
||||||
public void setMessage(I2NPMessage message) {
|
public void setMessage(I2NPMessage message) {
|
||||||
if (message.getType() == DatabaseSearchReplyMessage.MESSAGE_TYPE) {
|
int mtype = message.getType();
|
||||||
|
if (mtype == DatabaseSearchReplyMessage.MESSAGE_TYPE) {
|
||||||
// DSRM processing now in FloodOnlyLookupSelector instead of here,
|
// DSRM processing now in FloodOnlyLookupSelector instead of here,
|
||||||
// a dsrm is only passed in when there are no more lookups remaining
|
// a dsrm is only passed in when there are no more lookups remaining
|
||||||
// so that all DSRM's are processed, not just the last one.
|
// so that all DSRM's are processed, not just the last one.
|
||||||
_search.failed();
|
_search.failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
if (mtype != DatabaseStoreMessage.MESSAGE_TYPE)
|
||||||
|
return;
|
||||||
|
|
||||||
DatabaseStoreMessage dsm = (DatabaseStoreMessage)message;
|
DatabaseStoreMessage dsm = (DatabaseStoreMessage)message;
|
||||||
if (_log.shouldLog(Log.INFO))
|
if (_log.shouldLog(Log.INFO))
|
||||||
_log.info(_search.getJobId() + ": got a DSM for "
|
_log.info(_search.getJobId() + ": got a DSM for "
|
||||||
+ dsm.getKey().toBase64());
|
+ dsm.getKey().toBase64());
|
||||||
// This store will be duplicated by HFDSMJ
|
// This store will handled by HFDSMJ.
|
||||||
// We do it here first to make sure it is in the DB before
|
// Just note success here.
|
||||||
// runJob() and search.success() is called???
|
if (dsm.getKey().equals(_search.getKey()))
|
||||||
// Should we just pass the DataStructure directly back to somebody?
|
_success = true;
|
||||||
DatabaseEntry entry = dsm.getEntry();
|
DatabaseEntry entry = dsm.getEntry();
|
||||||
int type = entry.getType();
|
int type = entry.getType();
|
||||||
if (DatabaseEntry.isLeaseSet(type)) {
|
if (DatabaseEntry.isLeaseSet(type)) {
|
||||||
@@ -60,20 +65,6 @@ class FloodOnlyLookupMatchJob extends JobImpl implements ReplyJob {
|
|||||||
// so don't do that.
|
// so don't do that.
|
||||||
LeaseSet ls = (LeaseSet) dsm.getEntry();
|
LeaseSet ls = (LeaseSet) dsm.getEntry();
|
||||||
ls.setReceivedAsReply();
|
ls.setReceivedAsReply();
|
||||||
getContext().netDb().store(dsm.getKey(), ls);
|
|
||||||
} else if (type == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
|
|
||||||
getContext().netDb().store(dsm.getKey(), (RouterInfo) dsm.getEntry());
|
|
||||||
} else {
|
|
||||||
if (_log.shouldWarn())
|
|
||||||
_log.warn(_search.getJobId() + ": got a DSM of unknown type " + type
|
|
||||||
+ " for " + dsm.getKey().toBase64());
|
|
||||||
}
|
|
||||||
} catch (UnsupportedCryptoException uce) {
|
|
||||||
_search.failed();
|
|
||||||
return;
|
|
||||||
} catch (IllegalArgumentException iae) {
|
|
||||||
if (_log.shouldLog(Log.WARN))
|
|
||||||
_log.warn(_search.getJobId() + ": Received an invalid store reply", iae);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -973,10 +973,12 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
|
|||||||
public LeaseSet store(Hash key, LeaseSet leaseSet) throws IllegalArgumentException {
|
public LeaseSet store(Hash key, LeaseSet leaseSet) throws IllegalArgumentException {
|
||||||
if (!_initialized) return null;
|
if (!_initialized) return null;
|
||||||
|
|
||||||
LeaseSet rv = null;
|
LeaseSet rv;
|
||||||
try {
|
try {
|
||||||
rv = (LeaseSet)_ds.get(key);
|
rv = (LeaseSet)_ds.get(key);
|
||||||
if ( (rv != null) && (rv.equals(leaseSet)) ) {
|
if (rv != null && rv.getEarliestLeaseDate() >= leaseSet.getEarliestLeaseDate()) {
|
||||||
|
if (_log.shouldDebug())
|
||||||
|
_log.debug("Not storing older " + key);
|
||||||
// if it hasn't changed, no need to do anything
|
// if it hasn't changed, no need to do anything
|
||||||
// except copy over the flags
|
// except copy over the flags
|
||||||
Hash to = leaseSet.getReceivedBy();
|
Hash to = leaseSet.getReceivedBy();
|
||||||
@@ -1239,11 +1241,13 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
|
|||||||
RouterInfo store(Hash key, RouterInfo routerInfo, boolean persist) throws IllegalArgumentException {
|
RouterInfo store(Hash key, RouterInfo routerInfo, boolean persist) throws IllegalArgumentException {
|
||||||
if (!_initialized) return null;
|
if (!_initialized) return null;
|
||||||
|
|
||||||
RouterInfo rv = null;
|
RouterInfo rv;
|
||||||
try {
|
try {
|
||||||
rv = (RouterInfo)_ds.get(key, persist);
|
rv = (RouterInfo)_ds.get(key, persist);
|
||||||
if ( (rv != null) && (rv.equals(routerInfo)) ) {
|
if (rv != null && rv.getPublished() >= routerInfo.getPublished()) {
|
||||||
// no need to validate
|
if (_log.shouldDebug())
|
||||||
|
_log.debug("Not storing older " + key);
|
||||||
|
// quick check without calling validate()
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
|
Reference in New Issue
Block a user