added stat - crypto.garlic.decryptFail

formatting / logging
This commit is contained in:
jrandom
2004-04-18 03:36:12 +00:00
committed by zzz
parent 38091c3c25
commit 0d3d4b60ce

View File

@ -25,6 +25,7 @@ import net.i2p.router.KeyManager;
import net.i2p.router.LeaseSetKeys;
import net.i2p.router.MessageHistory;
import net.i2p.router.Router;
import net.i2p.stat.StatManager;
import net.i2p.util.Clock;
import net.i2p.util.Log;
@ -42,6 +43,10 @@ public class HandleGarlicMessageJob extends JobImpl {
private Hash _fromHash;
private static Map _cloves; // map of clove Id --> Expiration of cloves we've already seen
static {
StatManager.getInstance().createRateStat("crypto.garlic.decryptFail", "How often garlic messages are undecryptable", "Encryption", new long[] { 5*60*1000, 60*60*1000, 24*60*60*1000 });
}
private final static int FORWARD_PRIORITY = 50;
public HandleGarlicMessageJob(GarlicMessage msg, RouterIdentity from, Hash fromHash) {
@ -68,11 +73,13 @@ public class HandleGarlicMessageJob extends JobImpl {
set = GarlicMessageParser.getInstance().getGarlicCloves(_message, lskeys.getDecryptionKey());
if (set != null) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Decrypted garlic message with lease set key for destination " + lskeys.getDestination().calculateHash().toBase64() + " SUCCEEDED: " + set);
_log.debug("Decrypted garlic message with lease set key for destination "
+ lskeys.getDestination().calculateHash().toBase64() + " SUCCEEDED: " + set);
break;
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Decrypting garlic message with lease set key for destination " + lskeys.getDestination().calculateHash().toBase64() + " failed");
_log.debug("Decrypting garlic message with lease set key for destination "
+ lskeys.getDestination().calculateHash().toBase64() + " failed");
}
}
} else {
@ -86,8 +93,13 @@ public class HandleGarlicMessageJob extends JobImpl {
}
} else {
if (_log.shouldLog(Log.ERROR))
_log.error("CloveMessageParser failed to decrypt the message [" + _message.getUniqueId() + "] to us when received from [" + _fromHash + "] / [" + _from + "]", new Exception("Decrypt garlic failed"));
MessageHistory.getInstance().messageProcessingError(_message.getUniqueId(), _message.getClass().getName(), "Garlic could not be decrypted");
_log.error("CloveMessageParser failed to decrypt the message [" + _message.getUniqueId()
+ "] to us when received from [" + _fromHash + "] / [" + _from + "]",
new Exception("Decrypt garlic failed"));
StatManager.getInstance().addRateData("crypto.garlic.decryptFail", 1, 0);
MessageHistory.getInstance().messageProcessingError(_message.getUniqueId(),
_message.getClass().getName(),
"Garlic could not be decrypted");
}
}
@ -121,23 +133,25 @@ public class HandleGarlicMessageJob extends JobImpl {
private static boolean isValid(GarlicClove clove) {
if (isKnown(clove.getCloveId())) {
_log.error("Duplicate garlic clove received - replay attack in progress? [cloveId = " +
clove.getCloveId() + " expiration = " + clove.getExpiration());
_log.error("Duplicate garlic clove received - replay attack in progress? [cloveId = "
+ clove.getCloveId() + " expiration = " + clove.getExpiration());
return false;
} else {
_log.debug("Clove " + clove.getCloveId() + " expiring on " + clove.getExpiration() + " is not known");
_log.debug("Clove " + clove.getCloveId() + " expiring on " + clove.getExpiration()
+ " is not known");
}
long now = Clock.getInstance().now();
if (clove.getExpiration().getTime() < now) {
if (clove.getExpiration().getTime() < now + Router.CLOCK_FUDGE_FACTOR) {
_log.warn("Expired garlic received, but within our fudge factor [" + clove.getExpiration() + "]");
_log.warn("Expired garlic received, but within our fudge factor ["
+ clove.getExpiration() + "]");
} else {
if (_log.shouldLog(Log.DEBUG))
_log.error("Expired garlic clove received - replay attack in progress? [cloveId = " +
clove.getCloveId() + " expiration = " + clove.getExpiration() + " now = " + (new Date(Clock.getInstance().now())));
_log.error("Expired garlic clove received - replay attack in progress? [cloveId = "
+ clove.getCloveId() + " expiration = " + clove.getExpiration()
+ " now = " + (new Date(Clock.getInstance().now())));
return false;
}
}
synchronized (_cloves) {
_cloves.put(new Long(clove.getCloveId()), clove.getExpiration());
@ -154,11 +168,15 @@ public class HandleGarlicMessageJob extends JobImpl {
}
boolean requestAck = (clove.getSourceRouteBlockAction() == GarlicClove.ACTION_STATUS);
long sendExpiration = clove.getExpiration().getTime();
MessageHandler.getInstance().handleMessage(clove.getInstructions(), clove.getData(), requestAck, clove.getSourceRouteBlock(),
clove.getCloveId(), _from, _fromHash, sendExpiration, FORWARD_PRIORITY);
MessageHandler.getInstance().handleMessage(clove.getInstructions(), clove.getData(),
requestAck, clove.getSourceRouteBlock(),
clove.getCloveId(), _from, _fromHash,
sendExpiration, FORWARD_PRIORITY);
}
public void dropped() {
MessageHistory.getInstance().messageProcessingError(_message.getUniqueId(), _message.getClass().getName(), "Dropped due to overload");
MessageHistory.getInstance().messageProcessingError(_message.getUniqueId(),
_message.getClass().getName(),
"Dropped due to overload");
}
}