use of net.i2p.router.crypto.TransientSessionKeyManager in project i2p.i2p by i2p.
the class ClientConnectionRunner method sessionEstablished.
/**
* Caller must send a SessionStatusMessage to the client with the returned code.
* Caller must call disconnectClient() on failure.
* Side effect: Sets the session ID.
*
* @return SessionStatusMessage return code, 1 for success, != 1 for failure
*/
public int sessionEstablished(SessionConfig config) {
Destination dest = config.getDestination();
Hash destHash = dest.calculateHash();
if (_log.shouldLog(Log.DEBUG))
_log.debug("SessionEstablished called for destination " + destHash);
if (_sessions.size() > MAX_SESSIONS)
return SessionStatusMessage.STATUS_REFUSED;
boolean isPrimary = _sessions.isEmpty();
if (!isPrimary) {
// all encryption keys must be the same
for (SessionParams sp : _sessions.values()) {
if (!dest.getPublicKey().equals(sp.dest.getPublicKey()))
return SessionStatusMessage.STATUS_INVALID;
}
}
SessionParams sp = new SessionParams(dest, isPrimary);
sp.config = config;
SessionParams old = _sessions.putIfAbsent(destHash, sp);
if (old != null)
return SessionStatusMessage.STATUS_INVALID;
// We process a few options here, but most are handled by the tunnel manager.
// The ones here can't be changed later.
Properties opts = config.getOptions();
if (isPrimary && opts != null) {
_dontSendMSM = "none".equals(opts.getProperty(I2PClient.PROP_RELIABILITY, "").toLowerCase(Locale.US));
_dontSendMSMOnReceive = Boolean.parseBoolean(opts.getProperty(I2PClient.PROP_FAST_RECEIVE));
}
// per-destination session key manager to prevent rather easy correlation
if (isPrimary && _sessionKeyManager == null) {
int tags = TransientSessionKeyManager.DEFAULT_TAGS;
int thresh = TransientSessionKeyManager.LOW_THRESHOLD;
if (opts != null) {
String ptags = opts.getProperty(PROP_TAGS);
if (ptags != null) {
try {
tags = Integer.parseInt(ptags);
} catch (NumberFormatException nfe) {
}
}
String pthresh = opts.getProperty(PROP_THRESH);
if (pthresh != null) {
try {
thresh = Integer.parseInt(pthresh);
} catch (NumberFormatException nfe) {
}
}
}
_sessionKeyManager = new TransientSessionKeyManager(_context, tags, thresh);
}
return _manager.destinationEstablished(this, dest);
}
Aggregations