Router: INMP and netdb DSRM selector cleanup

This commit is contained in:
zzz
2020-05-07 13:25:31 +00:00
parent 5de76252ea
commit 3d56545210
4 changed files with 30 additions and 51 deletions

View File

@ -146,6 +146,9 @@ public class InNetMessagePool implements Service {
* (was queue length, long ago)
*/
public int add(I2NPMessage messageBody, RouterIdentity fromRouter, Hash fromRouterHash) {
final MessageHistory history = _context.messageHistory();
final boolean doHistory = history.getDoLog();
long exp = messageBody.getMessageExpiration();
if (_log.shouldDebug())
@ -180,15 +183,13 @@ public class InNetMessagePool implements Service {
_context.statManager().addRateData("inNetPool.dropped", 1);
// FIXME not necessarily a duplicate, could be expired too long ago / too far in future
_context.statManager().addRateData("inNetPool.duplicate", 1);
_context.messageHistory().droppedOtherMessage(messageBody, (fromRouter != null ? fromRouter.calculateHash() : fromRouterHash));
_context.messageHistory().messageProcessingError(messageBody.getUniqueId(),
if (doHistory) {
history.droppedOtherMessage(messageBody, (fromRouter != null ? fromRouter.calculateHash() : fromRouterHash));
history.messageProcessingError(messageBody.getUniqueId(),
messageBody.getClass().getSimpleName(),
"Duplicate/expired");
}
return -1;
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Message received [" + messageBody.getUniqueId()
+ " expiring on " + exp + "] is NOT a duplicate or exipired");
}
boolean jobFound = false;
@ -219,12 +220,11 @@ public class InNetMessagePool implements Service {
fromRouterHash);
if (job != null) {
_context.jobQueue().addJob(job);
jobFound = true;
} else {
// ok, we may not have *found* a job, per se, but we could have, the
// job may have just executed inline
jobFound = true;
}
jobFound = true;
}
}
break;
@ -237,7 +237,8 @@ public class InNetMessagePool implements Service {
// not handled as a reply
if (!jobFound) {
// was not handled via HandlerJobBuilder
_context.messageHistory().droppedOtherMessage(messageBody, (fromRouter != null ? fromRouter.calculateHash() : fromRouterHash));
if (doHistory)
history.droppedOtherMessage(messageBody, (fromRouter != null ? fromRouter.calculateHash() : fromRouterHash));
switch (type) {
case DeliveryStatusMessage.MESSAGE_TYPE:
@ -253,9 +254,12 @@ public class InNetMessagePool implements Service {
break;
case DatabaseSearchReplyMessage.MESSAGE_TYPE:
if (_log.shouldLog(Log.INFO))
_log.info("Dropping slow db lookup response: " + messageBody);
_context.statManager().addRateData("inNetPool.droppedDbLookupResponseMessage", 1);
// This is normal.
// The three netdb selectors,
// FloodOnlyLookupSelector, IterativeLookupSelector, and SearchMessageSelector
// never return true from isMatch() for a DSRM.
// IterativeLookupSelector.isMatch() queues a new IterativeLookupJob
// to fetch the responses.
break;
case DatabaseLookupMessage.MESSAGE_TYPE:
@ -273,19 +277,23 @@ public class InNetMessagePool implements Service {
break;
} // switch
} else {
String mtype = messageBody.getClass().getName();
_context.messageHistory().receiveMessage(mtype, messageBody.getUniqueId(),
if (doHistory) {
String mtype = messageBody.getClass().getName();
history.receiveMessage(mtype, messageBody.getUniqueId(),
messageBody.getMessageExpiration(),
fromRouterHash, true);
}
return 0; // no queue
}
}
}
String mtype = messageBody.getClass().getName();
_context.messageHistory().receiveMessage(mtype, messageBody.getUniqueId(),
if (doHistory) {
String mtype = messageBody.getClass().getName();
history.receiveMessage(mtype, messageBody.getUniqueId(),
messageBody.getMessageExpiration(),
fromRouterHash, true);
}
return 0; // no queue
}

View File

@ -44,15 +44,17 @@ class IterativeLookupSelector implements MessageSelector {
// is it worth making sure the reply came in on the right tunnel?
if (_search.getKey().equals(dsm.getKey())) {
_matchFound = true;
if (_log.shouldDebug())
_log.debug(_search.getJobId() + ": DSM match " + this);
return true;
}
} else if (type == DatabaseSearchReplyMessage.MESSAGE_TYPE) {
DatabaseSearchReplyMessage dsrm = (DatabaseSearchReplyMessage)message;
if (_search.getKey().equals(dsrm.getSearchKey())) {
// Got a netDb reply pointing us at other floodfills...
if (_log.shouldLog(Log.INFO)) {
if (_log.shouldDebug()) {
Hash from = dsrm.getFromHash();
_log.info(_search.getJobId() + ": Processing DSRM via IterativeLookupJob, apparently from " + from);
_log.debug(_search.getJobId() + ": Processing DSRM via IterativeLookupJob, apparently from " + from + ' ' + this);
}
// was inline, now in IterativeLookupJob due to deadlocks

View File

@ -65,10 +65,6 @@ class SearchMessageSelector implements MessageSelector {
public long getExpiration() { return _exp; }
public boolean isMatch(I2NPMessage message) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("[" + _id + "] isMatch("+message.getClass().getName()
+ ") [want dbStore or dbSearchReply from " + _peer
+ " for " + _state.getTarget() + "]");
int type = message.getType();
if (type == DatabaseStoreMessage.MESSAGE_TYPE) {
DatabaseStoreMessage msg = (DatabaseStoreMessage)message;
@ -79,10 +75,6 @@ class SearchMessageSelector implements MessageSelector {
+ "but DBStore doesn't include that info");
_found = true;
return true;
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("[" + _id + "] DBStore of a key we're not looking for");
return false;
}
} else if (type == DatabaseSearchReplyMessage.MESSAGE_TYPE) {
DatabaseSearchReplyMessage msg = (DatabaseSearchReplyMessage)message;
@ -93,21 +85,9 @@ class SearchMessageSelector implements MessageSelector {
+ "checking with for a key we're looking for");
_found = true;
return true;
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("[" + _id + "] Was a DBSearchReply from who we're checking "
+ "with but NOT for the key we're looking for");
return false;
}
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("[" + _id + "] DBSearchReply from someone we are not checking with ["
+ msg.getFromHash() + ", not " + _state.getTarget() + "]");
return false;
}
} else {
//_log.debug("Not a DbStore or DbSearchReply");
return false;
}
return false;
}
}

View File

@ -39,9 +39,6 @@ class StoreMessageSelector implements MessageSelector {
public long getExpiration() { return _expiration; }
public boolean isMatch(I2NPMessage message) {
//if (_log.shouldDebug())
// _log.debug(_storeJobId + ": isMatch(" + message.getClass().getSimpleName() + ") [want DSM from "
// + _peer + ']');
if (message.getType() == DeliveryStatusMessage.MESSAGE_TYPE) {
DeliveryStatusMessage msg = (DeliveryStatusMessage)message;
if (msg.getMessageId() == _waitingForId) {
@ -49,17 +46,9 @@ class StoreMessageSelector implements MessageSelector {
_log.info(_storeJobId + ": Found match for the key we're waiting for: " + _waitingForId);
_found = true;
return true;
} else {
//if (_log.shouldDebug())
// _log.debug(_storeJobId + ": DeliveryStatusMessage of " + msg.getMessageId() +
// " but waiting for " + _waitingForId);
return false;
}
} else {
//if (_log.shouldLog(Log.DEBUG))
// _log.debug(_storeJobId + ": Not a DeliveryStatusMessage");
return false;
}
return false;
}
@Override