I2CP: Add new discardMessage() to session API

to avoid decompression overhead on messages with no match
in the demuxer.

Log hexdump of discarded message if enabled
This commit is contained in:
zzz committed 2026-08-26 12:08:29 -04:00
1 parent 73cc98d28b
commit 8752b8d0ae
3 files changed
+29 -8

No files matched your search

@@ -229,6 +229,14 @@ public interface I2PSession {
*/
public byte[] receiveMessage(int msgId) throws I2PSessionException;
/**
* Throw away the received message, we don't want it.
* Use instead of receiveMessage() to avoid gunzip overhead.
*
* @since 0.9.71
*/
public void discardMessage(int msgId);
/** Instruct the router that the message received was abusive (including how
* abusive on a 1-100 scale) in the hopes the router can do something to
* minimize receiving abusive messages like that in the future.
@@ -46,17 +46,20 @@ public class I2PSessionDemultiplexer implements I2PSessionMuxedListener {
l.messageAvailable(session, msgId, size, proto, fromport, toport);
} else {
// no listener, throw it out
if (_listeners.isEmpty()) {
if (_log.shouldLog(Log.WARN))
if (_log.shouldWarn()) {
if (_listeners.isEmpty()) {
_log.warn("No listeners for incoming message");
} else {
if (_log.shouldLog(Log.WARN))
_log.warn("No listener found for proto: " + proto + " port: " + toport + " msg id: " + msgId +
} else {
_log.warn("No listener found for proto: " + proto + " fromport: " + fromport + " toport: " + toport + " msg id: " + msgId +
" from pool of " + _listeners.size() + " listeners");
}
try {
byte[] msg = session.receiveMessage(msgId);
_log.warn("Message:\n" + net.i2p.util.HexDump.dump(msg));
} catch (I2PSessionException ise) {}
} else {
session.discardMessage(msgId);
}
try {
session.receiveMessage(msgId);
} catch (I2PSessionException ise) {}
}
}
@@ -912,6 +912,16 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
return msg.getPayload().getUnencryptedData();
}
/**
* Throw away the received message, we don't want it.
* Use instead of receiveMessage() to avoid gunzip overhead.
*
* @since 0.9.71
*/
public void discardMessage(int msgId) {
_availableMessages.remove(Long.valueOf(msgId));
}
/**
* Report abuse with regards to the given messageId
*/