Search in sources :

Example 1 with ClientTunnelSettings

use of net.i2p.router.ClientTunnelSettings in project i2p.i2p by i2p.

the class ClientMessageEventListener method handleCreateSession.

/**
 * Handle a CreateSessionMessage.
 * On errors, we could perhaps send a SessionStatusMessage with STATUS_INVALID before
 * sending the DisconnectMessage... but right now the client will send _us_ a
 * DisconnectMessage in return, and not wait around for our DisconnectMessage.
 * So keep it simple.
 *
 * Defaults in SessionConfig options are, in general, NOT honored.
 * In-JVM client side must promote defaults to the primary map.
 */
private void handleCreateSession(CreateSessionMessage message) {
    SessionConfig in = message.getSessionConfig();
    Destination dest = in.getDestination();
    if (in.verifySignature()) {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("Signature verified correctly on create session message");
    } else {
        // For now, we do NOT send a SessionStatusMessage - see javadoc above
        int itype = dest.getCertificate().getCertificateType();
        SigType stype = SigType.getByCode(itype);
        if (stype == null || !stype.isAvailable()) {
            _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)
                msg += DataHelper.formatDuration(skew) + " in the past";
            else
                msg += DataHelper.formatDuration(0 - skew) + " in the future";
            _log.error(msg);
            _runner.disconnectClient(msg);
        } else {
            _log.error("Signature verification failed on a create session message");
            _runner.disconnectClient("Invalid signature on CreateSessionMessage");
        }
        return;
    }
    // Auth, since 0.8.2
    Properties inProps = in.getOptions();
    if (!checkAuth(inProps))
        return;
    SessionId id = _runner.getSessionId(dest.calculateHash());
    if (id != null) {
        _runner.disconnectClient("Already have session " + id);
        return;
    }
    // Copy over the whole config structure so we don't later corrupt it on
    // the client side if we change settings or later get a
    // ReconfigureSessionMessage
    SessionConfig cfg = new SessionConfig(dest);
    cfg.setSignature(in.getSignature());
    Properties props = new Properties();
    boolean isPrimary = _runner.getSessionIds().isEmpty();
    if (!isPrimary) {
        // all the primary options, then the overrides from the alias
        SessionConfig pcfg = _runner.getPrimaryConfig();
        if (pcfg != null) {
            props.putAll(pcfg.getOptions());
        } else {
            _log.error("no primary config?");
        }
    }
    props.putAll(inProps);
    cfg.setOptions(props);
    // this sets the session id
    int status = _runner.sessionEstablished(cfg);
    if (status != SessionStatusMessage.STATUS_CREATED) {
        // For now, we do NOT send a SessionStatusMessage - see javadoc above
        if (_log.shouldLog(Log.ERROR))
            _log.error("Session establish failed: code = " + status);
        String msg;
        if (status == SessionStatusMessage.STATUS_INVALID)
            msg = "duplicate destination";
        else if (status == SessionStatusMessage.STATUS_REFUSED)
            msg = "session limit exceeded";
        else
            msg = "unknown error";
        _runner.disconnectClient(msg);
        return;
    }
    // get the new session ID
    id = _runner.getSessionId(dest.calculateHash());
    if (_log.shouldLog(Log.INFO))
        _log.info("Session " + id + " established for " + dest.calculateHash());
    if (isPrimary) {
        sendStatusMessage(id, status);
        startCreateSessionJob(cfg);
    } else {
        SessionConfig pcfg = _runner.getPrimaryConfig();
        if (pcfg != null) {
            ClientTunnelSettings settings = new ClientTunnelSettings(dest.calculateHash());
            settings.readFromProperties(props);
            // addAlias() sends the create lease set msg, so we have to send the SMS first
            sendStatusMessage(id, status);
            boolean ok = _context.tunnelManager().addAlias(dest, settings, pcfg.getDestination());
            if (!ok) {
                _log.error("Add alias failed");
            // FIXME cleanup
            }
        } else {
            _log.error("no primary config?");
            status = SessionStatusMessage.STATUS_INVALID;
            sendStatusMessage(id, status);
        // FIXME cleanup
        }
    }
}
Also used : Destination(net.i2p.data.Destination) ClientTunnelSettings(net.i2p.router.ClientTunnelSettings) SessionConfig(net.i2p.data.i2cp.SessionConfig) Properties(java.util.Properties) SessionId(net.i2p.data.i2cp.SessionId) SigType(net.i2p.crypto.SigType)

Example 2 with ClientTunnelSettings

use of net.i2p.router.ClientTunnelSettings in project i2p.i2p by i2p.

the class CreateSessionJob method runJob.

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);
}
Also used : ClientTunnelSettings(net.i2p.router.ClientTunnelSettings) Hash(net.i2p.data.Hash) Properties(java.util.Properties)

Example 3 with ClientTunnelSettings

use of net.i2p.router.ClientTunnelSettings in project i2p.i2p by i2p.

the class ClientMessageEventListener method handleReconfigureSession.

/**
 * Message's Session ID ignored. This doesn't support removing previously set options.
 * Nor do we bother with message.getSessionConfig().verifySignature() ... should we?
 * Nor is the Date checked.
 *
 * Note that this does NOT update the few options handled in
 * ClientConnectionRunner.sessionEstablished(). Those can't be changed later.
 *
 * Defaults in SessionConfig options are, in general, NOT honored.
 * In-JVM client side must promote defaults to the primary map.
 */
private void handleReconfigureSession(ReconfigureSessionMessage message) {
    SessionId id = message.getSessionId();
    SessionConfig cfg = _runner.getConfig(id);
    if (cfg == null) {
        List<SessionId> current = _runner.getSessionIds();
        String msg = "ReconfigureSession invalid session: " + id + " current: " + current;
        if (_log.shouldLog(Log.ERROR))
            _log.error(msg);
        // sendStatusMessage(id, SessionStatusMessage.STATUS_INVALID);
        _runner.disconnectClient(msg);
        return;
    }
    if (_log.shouldLog(Log.INFO))
        _log.info("Updating options - old: " + cfg + " new: " + message.getSessionConfig());
    if (!message.getSessionConfig().getDestination().equals(cfg.getDestination())) {
        _log.error("Dest mismatch");
        sendStatusMessage(id, SessionStatusMessage.STATUS_INVALID);
        _runner.stopRunning();
        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, settings.getInboundSettings());
    _context.tunnelManager().setOutboundSettings(dest, settings.getOutboundSettings());
    sendStatusMessage(id, SessionStatusMessage.STATUS_UPDATED);
}
Also used : ClientTunnelSettings(net.i2p.router.ClientTunnelSettings) SessionConfig(net.i2p.data.i2cp.SessionConfig) Hash(net.i2p.data.Hash) Properties(java.util.Properties) SessionId(net.i2p.data.i2cp.SessionId)

Aggregations

Properties (java.util.Properties)3 ClientTunnelSettings (net.i2p.router.ClientTunnelSettings)3 Hash (net.i2p.data.Hash)2 SessionConfig (net.i2p.data.i2cp.SessionConfig)2 SessionId (net.i2p.data.i2cp.SessionId)2 SigType (net.i2p.crypto.SigType)1 Destination (net.i2p.data.Destination)1