From 8752b8d0ae3606d3f75809f94b9711790fa997df Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 26 Aug 2026 12:08:29 -0400 Subject: [PATCH] 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 --- core/java/src/net/i2p/client/I2PSession.java | 8 ++++++++ .../client/impl/I2PSessionDemultiplexer.java | 19 +++++++++++-------- .../net/i2p/client/impl/I2PSessionImpl.java | 10 ++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/core/java/src/net/i2p/client/I2PSession.java b/core/java/src/net/i2p/client/I2PSession.java index b9fa72807..850752bf1 100644 --- a/core/java/src/net/i2p/client/I2PSession.java +++ b/core/java/src/net/i2p/client/I2PSession.java @@ -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. diff --git a/core/java/src/net/i2p/client/impl/I2PSessionDemultiplexer.java b/core/java/src/net/i2p/client/impl/I2PSessionDemultiplexer.java index 6480733e1..72b8d9c65 100644 --- a/core/java/src/net/i2p/client/impl/I2PSessionDemultiplexer.java +++ b/core/java/src/net/i2p/client/impl/I2PSessionDemultiplexer.java @@ -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) {} } } diff --git a/core/java/src/net/i2p/client/impl/I2PSessionImpl.java b/core/java/src/net/i2p/client/impl/I2PSessionImpl.java index 44123f7c2..6dfd60e3f 100644 --- a/core/java/src/net/i2p/client/impl/I2PSessionImpl.java +++ b/core/java/src/net/i2p/client/impl/I2PSessionImpl.java @@ -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 */