I2CP: More fixes after prop, w.r.t. restore after close-on-idle

- When socket is closed, set sessionID and LS to null,
    close subsession and set its sessionID and LS to null
  - Checks on client side for null session ID
  - Check for null session in Destroy Session message
  - Don't kill I2CP connection due to a bad session ID
    in a SendMessage, just drop the message and send
    a MessageStatusMessage
  - Log tweaks
This commit is contained in:
zzz
2015-06-17 23:44:12 +00:00
parent 8d9cced128
commit 7c5dfaee20
4 changed files with 85 additions and 17 deletions

View File

@@ -34,6 +34,7 @@ import net.i2p.data.i2cp.ReportAbuseMessage;
import net.i2p.data.i2cp.SendMessageMessage;
import net.i2p.data.i2cp.SendMessageExpiresMessage;
import net.i2p.data.i2cp.SessionConfig;
import net.i2p.data.i2cp.SessionId;
import net.i2p.util.Log;
/**
@@ -154,7 +155,12 @@ class I2CPMessageProducer {
} else
msg = new SendMessageMessage();
msg.setDestination(dest);
msg.setSessionId(session.getSessionId());
SessionId sid = session.getSessionId();
if (sid == null) {
_log.error(session.toString() + " send message w/o session", new Exception());
return;
}
msg.setSessionId(sid);
msg.setNonce(nonce);
Payload data = createPayload(dest, payload, null, null, null, null);
msg.setPayload(data);
@@ -176,7 +182,12 @@ class I2CPMessageProducer {
return;
SendMessageMessage msg = new SendMessageExpiresMessage(options);
msg.setDestination(dest);
msg.setSessionId(session.getSessionId());
SessionId sid = session.getSessionId();
if (sid == null) {
_log.error(session.toString() + " send message w/o session", new Exception());
return;
}
msg.setSessionId(sid);
msg.setNonce(nonce);
Payload data = createPayload(dest, payload, null, null, null, null);
msg.setPayload(data);
@@ -352,7 +363,12 @@ class I2CPMessageProducer {
msg.setLeaseSet(leaseSet);
msg.setPrivateKey(priv);
msg.setSigningPrivateKey(signingPriv);
msg.setSessionId(session.getSessionId());
SessionId sid = session.getSessionId();
if (sid == null) {
_log.error(session.toString() + " create LS w/o session", new Exception());
return;
}
msg.setSessionId(sid);
session.sendMessage(msg);
}
@@ -381,7 +397,12 @@ class I2CPMessageProducer {
throw new I2PSessionException("Unable to sign the session config", dfe);
}
msg.setSessionConfig(cfg);
msg.setSessionId(session.getSessionId());
SessionId sid = session.getSessionId();
if (sid == null) {
_log.error(session.toString() + " update config w/o session", new Exception());
return;
}
msg.setSessionId(sid);
session.sendMessage(msg);
}
}

View File

@@ -502,6 +502,8 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
}
protected void changeState(State state) {
if (_log.shouldInfo())
_log.info(getPrefix() + "Change state to " + state);
synchronized (_stateLock) {
_state = state;
_stateLock.notifyAll();
@@ -891,8 +893,9 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
public void messageReceived(I2CPMessageReader reader, I2CPMessage message) {
int type = message.getType();
SessionId id = message.sessionId();
if (id == null || id.equals(_sessionId) ||
(_sessionId == null && id != null && type == SessionStatusMessage.MESSAGE_TYPE)) {
SessionId currId = _sessionId;
if (id == null || id.equals(currId) ||
(currId == null && id != null && type == SessionStatusMessage.MESSAGE_TYPE)) {
// it's for us
I2CPMessageHandler handler = _handlerMap.getHandler(type);
if (handler != null) {
@@ -1123,6 +1126,13 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
locked_closeSocket();
changeState(State.CLOSED);
}
synchronized (_subsessionLock) {
for (SubSession sess : _subsessions) {
sess.changeState(State.CLOSED);
sess.setSessionId(null);
sess.setLeaseSet(null);
}
}
}
/**
@@ -1152,6 +1162,8 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
_socket = null; // so when propogateError calls closeSocket, it doesnt loop
}
}
setSessionId(null);
setLeaseSet(null);
}
/**
@@ -1238,8 +1250,10 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
buf.append(s);
else
buf.append(getClass().getSimpleName());
if (_sessionId != null)
buf.append(" #").append(_sessionId.getSessionId());
SessionId id = _sessionId;
if (id != null)
buf.append(" #").append(id.getSessionId());
buf.append(' ').append(_state.toString());
buf.append("]: ");
return buf.toString();
}