better logging of corrupted I2NP msgs

This commit is contained in:
zzz
2011-12-11 13:36:50 +00:00
parent ec460794eb
commit caada2bfa0
2 changed files with 9 additions and 11 deletions

View File

@@ -202,16 +202,13 @@ class MessageReceiver {
// zero copy for single fragment
m = I2NPMessageImpl.fromRawByteArray(_context, state.getFragments()[0].getData(), 0, state.getCompleteSize(), handler);
}
if (state.getCompleteSize() == 534 && _log.shouldLog(Log.INFO)) {
_log.info(HexDump.dump(buf.getData(), 0, state.getCompleteSize()));
}
m.setUniqueId(state.getMessageId());
return m;
} catch (I2NPMessageException ime) {
if (_log.shouldLog(Log.WARN)) {
_log.warn("Message invalid: " + state, ime);
_log.warn(HexDump.dump(buf.getData(), 0, state.getCompleteSize()));
_log.warn("RAW: " + Base64.encode(buf.getData(), 0, state.getCompleteSize()));
_log.warn("DUMP:\n" + HexDump.dump(buf.getData(), 0, state.getCompleteSize()));
_log.warn("RAW:\n" + Base64.encode(buf.getData(), 0, state.getCompleteSize()));
}
_context.messageHistory().droppedInboundMessage(state.getMessageId(), state.getFrom(), "error: " + ime.toString() + ": " + state.toString());
return null;

View File

@@ -14,6 +14,7 @@ import net.i2p.data.i2np.I2NPMessageException;
import net.i2p.data.i2np.I2NPMessageHandler;
import net.i2p.router.RouterContext;
import net.i2p.util.ByteCache;
import net.i2p.util.HexDump;
import net.i2p.util.Log;
import net.i2p.util.SimpleByteCache;
import net.i2p.util.SimpleTimer;
@@ -468,10 +469,11 @@ class FragmentHandler {
String stringified = null;
if (_log.shouldLog(Log.DEBUG))
stringified = msg.toString();
byte data[] = null;
try {
int fragmentCount = msg.getFragmentCount();
// toByteArray destroys the contents of the message completely
byte data[] = msg.toByteArray();
data = msg.toByteArray();
if (data == null)
throw new I2NPMessageException("null data"); // fragments already released???
if (_log.shouldLog(Log.DEBUG))
@@ -488,14 +490,13 @@ class FragmentHandler {
noteReception(m.getUniqueId(), fragmentCount-1, "complete: ");// + msg.toString());
noteCompletion(m.getUniqueId());
_receiver.receiveComplete(m, msg.getTargetRouter(), msg.getTargetTunnel());
} catch (IOException ioe) {
if (stringified == null) stringified = msg.toString();
if (_log.shouldLog(Log.ERROR))
_log.error("Error receiving fragmented message (corrupt?): " + stringified, ioe);
} catch (I2NPMessageException ime) {
if (stringified == null) stringified = msg.toString();
if (_log.shouldLog(Log.WARN))
if (_log.shouldLog(Log.WARN)) {
_log.warn("Error receiving fragmented message (corrupt?): " + stringified, ime);
_log.warn("DUMP:\n" + HexDump.dump(data));
_log.warn("RAW:\n" + Base64.encode(data));
}
}
}