I2CP: Send DestroySessionMessage with dummy SessionID if unset

rather than throwing I2CPMessageException
ref: https://www.reddit.com/r/i2p/comments/1dp7j98/automatically_restarting_i2psnark/
This commit is contained in:
zzz
2024-07-05 08:00:11 -04:00
parent dc049899bd
commit 2093131f46
2 changed files with 6 additions and 2 deletions
@@ -175,7 +175,10 @@ class I2CPMessageProducer {
public void disconnect(I2PSessionImpl session) throws I2PSessionException {
if (session.isClosed()) return;
DestroySessionMessage dmsg = new DestroySessionMessage();
dmsg.setSessionId(session.getSessionId());
SessionId id = session.getSessionId();
if (id == null)
id = I2PSessionImpl.DUMMY_SESSION;
dmsg.setSessionId(id);
session.sendMessage_unchecked(dmsg);
// use DisconnectMessage only if we fail and drop connection...
// todo: update the code to fire off DisconnectMessage on socket error
@@ -256,7 +256,7 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
public static final int LISTEN_PORT = I2PClient.DEFAULT_LISTEN_PORT;
private static final int BUF_SIZE = 32*1024;
private static final SessionId DUMMY_SESSION = new SessionId(65535);
static final SessionId DUMMY_SESSION = new SessionId(65535);
/**
* for extension by SimpleSession (no dest)
@@ -1180,6 +1180,7 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
/**
* Retrieve the session's ID
* @return null if unset
*/
SessionId getSessionId() { return _sessionId; }
void setSessionId(SessionId id) { _sessionId = id; }