Search in sources :

Example 1 with ReconfigureSessionMessage

use of net.i2p.data.i2cp.ReconfigureSessionMessage in project i2p.i2p by i2p.

the class I2CPMessageProducer method updateTunnels.

/**
 * Update number of tunnels
 *
 * @param tunnels 0 for original configured number
 */
public void updateTunnels(I2PSessionImpl session, int tunnels) throws I2PSessionException {
    ReconfigureSessionMessage msg = new ReconfigureSessionMessage();
    SessionConfig cfg = new SessionConfig(session.getMyDestination());
    Properties props = session.getOptions();
    if (tunnels > 0) {
        Properties newprops = new Properties();
        newprops.putAll(props);
        props = newprops;
        props.setProperty("inbound.quantity", "" + tunnels);
        props.setProperty("outbound.quantity", "" + tunnels);
        props.setProperty("inbound.backupQuantity", "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);
    }
    msg.setSessionConfig(cfg);
    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);
}
Also used : ReconfigureSessionMessage(net.i2p.data.i2cp.ReconfigureSessionMessage) DataFormatException(net.i2p.data.DataFormatException) SessionConfig(net.i2p.data.i2cp.SessionConfig) I2PSessionException(net.i2p.client.I2PSessionException) Properties(java.util.Properties) SessionId(net.i2p.data.i2cp.SessionId) DataFormatException(net.i2p.data.DataFormatException) I2PSessionException(net.i2p.client.I2PSessionException)

Aggregations

Properties (java.util.Properties)1 I2PSessionException (net.i2p.client.I2PSessionException)1 DataFormatException (net.i2p.data.DataFormatException)1 ReconfigureSessionMessage (net.i2p.data.i2cp.ReconfigureSessionMessage)1 SessionConfig (net.i2p.data.i2cp.SessionConfig)1 SessionId (net.i2p.data.i2cp.SessionId)1