* I2CP: Implement optional reduce tunnels on idle - not hooked

in to i2ptunnel GUI yet - still needs tweaks
This commit is contained in:
zzz
2009-02-02 14:03:17 +00:00
parent 1ee2b5e899
commit 8d7340500f
9 changed files with 228 additions and 23 deletions

View File

@ -8,6 +8,8 @@ package net.i2p.router.client;
*
*/
import java.util.Properties;
import net.i2p.data.Payload;
import net.i2p.data.i2cp.CreateLeaseSetMessage;
import net.i2p.data.i2cp.CreateSessionMessage;
@ -27,6 +29,7 @@ import net.i2p.data.i2cp.SendMessageExpiresMessage;
import net.i2p.data.i2cp.SessionId;
import net.i2p.data.i2cp.SessionStatusMessage;
import net.i2p.data.i2cp.SetDateMessage;
import net.i2p.router.ClientTunnelSettings;
import net.i2p.router.RouterContext;
import net.i2p.util.Log;
import net.i2p.util.RandomSource;
@ -87,6 +90,9 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
case DestLookupMessage.MESSAGE_TYPE:
handleDestLookup(reader, (DestLookupMessage)message);
break;
case ReconfigureSessionMessage.MESSAGE_TYPE:
handleReconfigureSession(reader, (ReconfigureSessionMessage)message);
break;
default:
if (_log.shouldLog(Log.ERROR))
_log.error("Unhandled I2CP type received: " + message.getType());
@ -138,24 +144,13 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
return;
}
SessionStatusMessage msg = new SessionStatusMessage();
SessionId sessionId = new SessionId();
sessionId.setSessionId(getNextSessionId());
_runner.setSessionId(sessionId);
msg.setSessionId(sessionId);
msg.setStatus(SessionStatusMessage.STATUS_CREATED);
try {
if (_log.shouldLog(Log.DEBUG))
_log.debug("before sending sessionStatusMessage for " + message.getSessionConfig().getDestination().calculateHash().toBase64());
_runner.doSend(msg);
if (_log.shouldLog(Log.DEBUG))
_log.debug("after sending sessionStatusMessage for " + message.getSessionConfig().getDestination().calculateHash().toBase64());
_runner.sessionEstablished(message.getSessionConfig());
if (_log.shouldLog(Log.DEBUG))
_log.debug("after sessionEstablished for " + message.getSessionConfig().getDestination().calculateHash().toBase64());
} catch (I2CPMessageException ime) {
_log.error("Error writing out the session status message", ime);
}
sendStatusMessage(SessionStatusMessage.STATUS_CREATED);
_runner.sessionEstablished(message.getSessionConfig());
if (_log.shouldLog(Log.DEBUG))
_log.debug("after sessionEstablished for " + message.getSessionConfig().getDestination().calculateHash().toBase64());
_context.jobQueue().addJob(new CreateSessionJob(_context, _runner));
}
@ -249,10 +244,36 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
*/
private void handleReconfigureSession(I2CPMessageReader reader, ReconfigureSessionMessage message) {
if (_log.shouldLog(Log.INFO))
_log.info("Updating options - session " + _runner.getSessionId());
_log.info("Updating options - old: " + _runner.getConfig() + " new: " + message.getSessionConfig());
if (!message.getSessionConfig().getDestination().equals(_runner.getConfig().getDestination())) {
_log.error("Dest mismatch");
sendStatusMessage(SessionStatusMessage.STATUS_INVALID);
_runner.stopRunning();
return;
}
_runner.getConfig().getOptions().putAll(message.getSessionConfig().getOptions());
ClientTunnelSettings settings = new ClientTunnelSettings();
Properties props = new Properties();
props.putAll(_runner.getConfig().getOptions());
settings.readFromProperties(props);
_context.tunnelManager().setInboundSettings(_runner.getConfig().getDestination().calculateHash(),
settings.getInboundSettings());
_context.tunnelManager().setOutboundSettings(_runner.getConfig().getDestination().calculateHash(),
settings.getOutboundSettings());
sendStatusMessage(SessionStatusMessage.STATUS_UPDATED);
}
private void sendStatusMessage(int status) {
SessionStatusMessage msg = new SessionStatusMessage();
msg.setSessionId(_runner.getSessionId());
msg.setStatus(status);
try {
_runner.doSend(msg);
} catch (I2CPMessageException ime) {
_log.error("Error writing out the session status message", ime);
}
}
// this *should* be mod 65536, but UnsignedInteger is still b0rked. FIXME
private final static int MAX_SESSION_ID = 32767;