@Override protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException { SessionConfig config = new SessionConfig(); try { config.readBytes(in); } catch (DataFormatException dfe) { throw new I2CPMessageException("Unable to load the session configuration", dfe); } setSessionConfig(config); }
@Override public boolean equals(Object object) { if ((object != null) && (object instanceof SessionConfig)) { SessionConfig cfg = (SessionConfig) object; return DataHelper.eq(getSignature(), cfg.getSignature()) && DataHelper.eq(getDestination(), cfg.getDestination()) && DataHelper.eq(getCreationDate(), cfg.getCreationDate()) && DataHelper.eq(getOptions(), cfg.getOptions()); } return false; }
@Override public String toString() { StringBuilder buf = new StringBuilder("[SessionConfig: "); buf.append("\n\tDestination: ").append(getDestination()); buf.append("\n\tSignature: ").append(getSignature()); buf.append("\n\tCreation Date: ").append(getCreationDate()); buf.append("\n\tOptions: #: ").append(_options.size()); Properties sorted = new OrderedProperties(); sorted.putAll(_options); for (Map.Entry<Object, Object> e : sorted.entrySet()) { String key = (String) e.getKey(); String val = (String) e.getValue(); buf.append("\n\t\t[").append(key).append("] = [").append(val).append("]"); } buf.append("]"); return buf.toString(); } }
Destination dest = in.getDestination(); if (in.verifySignature()) { if (_log.shouldLog(Log.DEBUG)) _log.debug("Signature verified correctly on create session message"); _log.error("Client requested unsupported signature type " + itype); _runner.disconnectClient("Unsupported signature type " + itype); } else if (in.tooOld()) { long skew = _context.clock().now() - in.getCreationDate().getTime(); String msg = "Create session message client clock skew? "; if (skew >= 0) Properties inProps = in.getOptions(); if (!checkAuth(inProps)) return; SessionConfig cfg = new SessionConfig(dest); cfg.setSignature(in.getSignature()); Properties props = new Properties(); boolean isPrimary = _runner.getSessionIds().isEmpty(); props.putAll(pcfg.getOptions()); } else { _log.error("no primary config?"); cfg.setOptions(props); boolean ok = _context.tunnelManager().addAlias(dest, settings, pcfg.getDestination()); if (!ok) {
if (getSignature() == null) { if (getDestination() == null) { if (getCreationDate() == null) { if (tooOld()) { byte data[] = getBytes(); if (data == null) { SigningPublicKey spk = getTransientSigningPublicKey(); if (spk != null) { long expires = getOfflineExpiration(); if (expires < _creationDate.getTime()) return false; Signature sig = getOfflineSignature(); if (sig == null) return false; return false; } else { spk = getDestination().getSigningPublicKey(); boolean ok = DSAEngine.getInstance().verifySignature(getSignature(), data, spk); if (!ok) { Log log = I2PAppContext.getGlobalContext().logManager().getLog(SessionConfig.class);
public DataStructure createDataStructure() throws DataFormatException { SessionConfig cfg = new SessionConfig((Destination)(new DestinationTest()).createDataStructure()); cfg.setSignature((Signature)(new SignatureTest()).createDataStructure()); Properties options = new Properties(); options.setProperty("routerHost", "localhost"); options.setProperty("routerPort", "54321"); options.setProperty("routerSecret", "blah"); cfg.setOptions(options); cfg.signSessionConfig((SigningPrivateKey)(new SigningPrivateKeyTest()).createDataStructure()); return cfg; } public DataStructure createStructureToRead() { return new SessionConfig(); }
/** * Send all the messages that a client needs to send to a router to establish * a new session. */ public void connect(I2PSessionImpl session) throws I2PSessionException { updateBandwidth(session); CreateSessionMessage msg = new CreateSessionMessage(); SessionConfig cfg = new SessionConfig(session.getMyDestination()); cfg.setOptions(getRouterOptions(session)); if (session.isOffline()) { cfg.setOfflineSignature(session.getOfflineExpiration(), session.getTransientSigningPublicKey(), session.getOfflineSignature()); } try { cfg.signSessionConfig(session.getPrivateKey()); } catch (DataFormatException dfe) { throw new I2PSessionException("Unable to sign the session config", dfe); } msg.setSessionConfig(cfg); session.sendMessage_unchecked(msg); }
SessionConfig cfg = new SessionConfig(session.getMyDestination()); Properties props = getRouterOptions(session); if (tunnels > 0) { props.setProperty("outbound.backupQuantity", "0"); cfg.setOptions(props); try { cfg.signSessionConfig(session.getPrivateKey()); } catch (DataFormatException dfe) { throw new I2PSessionException("Unable to sign the session config", dfe);
public void runJob() { Hash dest = _config.getDestination().calculateHash(); if (_log.shouldLog(Log.INFO)) _log.info("Requesting lease set for destination " + dest); ClientTunnelSettings settings = new ClientTunnelSettings(dest); Properties props = new Properties(); // We're NOT going to force all clients to use the router's defaults, since that may be // excessive. This means that unless the user says otherwise, we'll be satisfied with whatever // is available. Otherwise, when the router starts up, if there aren't sufficient tunnels with the // adequate number of hops, the user will have to wait. Once peer profiles are persistent, we can // reenable this, since on startup we'll have a sufficient number of high enough ranked peers to // tunnel through. (perhaps). // XXX take the router's defaults // XXX props.putAll(Router.getInstance().getConfigMap()); // override them by the client's settings props.putAll(_config.getOptions()); // and load 'em up (using anything not yet set as the software defaults) settings.readFromProperties(props); getContext().tunnelManager().buildTunnels(_config.getDestination(), settings); } }
/** * Equivalent to getConfig().getDestination().calculateHash(); * will be null before session is established * Not subsession aware. Returns primary session hash. * Don't use if you can help it. * * @return primary hash or null if not yet set */ public Hash getDestHash() { SessionConfig cfg = getPrimaryConfig(); if (cfg != null) return cfg.getDestination().calculateHash(); return null; }
public CreateSessionMessage() { _sessionConfig = new SessionConfig(); }
/** * @return true if we don't know about this destination at all */ public boolean shouldPublishLeaseSet(Hash destHash) { if (destHash == null) return true; ClientConnectionRunner runner = getRunner(destHash); if (runner == null) return true; SessionConfig config = runner.getConfig(destHash); if (config == null) return true; return !Boolean.parseBoolean(config.getOptions().getProperty(ClientManagerFacade.PROP_CLIENT_ONLY)); }
Destination dest = config.getDestination(); Hash destHash = dest.calculateHash(); if (_log.shouldLog(Log.DEBUG)) Properties opts = config.getOptions(); if (isPrimary && opts != null) { _dontSendMSM = "none".equals(opts.getProperty(I2PClient.PROP_RELIABILITY, "").toLowerCase(Locale.US));
public void timeReached() { if (!_isStarted) return; for (ClientConnectionRunner runner : _runners.values()) { if (runner instanceof QueuedClientConnectionRunner) continue; if (runner.isDead()) continue; SessionConfig cfg = runner.getPrimaryConfig(); if (cfg == null) continue; // simple session or no session yet if (runner.getLeaseSet(cfg.getDestination().calculateHash()) == null) continue; // don't confuse client while waiting for CreateLeaseSet msg try { // only send version if the client can handle it (0.8.7 or greater) runner.doSend(new SetDateMessage(runner.getClientVersion() != null ? CoreVersion.VERSION : null)); } catch (I2CPMessageException ime) {} } if (_isStarted) schedule(LOOP_TIME); } }
public DataStructure createStructureToRead() { return new SessionConfig(); } }
String param = msg.getSenderConfig().getOptions().getProperty(OVERALL_TIMEOUT_MS_PARAM); if (param == null) param = ctx.router().getConfigSetting(OVERALL_TIMEOUT_MS_PARAM);
if (!message.getSessionConfig().getDestination().equals(cfg.getDestination())) { _log.error("Dest mismatch"); sendStatusMessage(id, SessionStatusMessage.STATUS_INVALID); return; Hash dest = cfg.getDestination().calculateHash(); cfg.getOptions().putAll(message.getSessionConfig().getOptions()); ClientTunnelSettings settings = new ClientTunnelSettings(dest); Properties props = new Properties(); props.putAll(cfg.getOptions()); settings.readFromProperties(props); _context.tunnelManager().setInboundSettings(dest,
/** * Immediately send a fake leaseset */ @Override protected void startCreateSessionJob(SessionConfig config) { long exp = _context.clock().now() + 10*60*1000; LeaseSet ls = new LeaseSet(); Lease lease = new Lease(); lease.setGateway(Hash.FAKE_HASH); TunnelId id = new TunnelId(1); lease.setTunnelId(id); Date date = new Date(exp); lease.setEndDate(date); ls.addLease(lease); _runner.requestLeaseSet(config.getDestination().calculateHash(), ls, exp, null, null); }
@Override protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException { try { _sessionId = new SessionId(); _sessionId.readBytes(in); _sessionConfig = new SessionConfig(); _sessionConfig.readBytes(in); } catch (DataFormatException dfe) { throw new I2CPMessageException("Unable to load the message data", dfe); } }
String allow = _clientMessage.getSenderConfig().getOptions().getProperty(BUNDLE_REPLY_LEASESET); boolean allowLeaseBundle = SendMessageOptions.getSendLeaseSet(sendFlags) && (allow == null || Boolean.parseBoolean(allow));