Search in sources :

Example 11 with TunnelController

use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.

the class GeneralHelper method getDestination.

/**
 *  Works even if tunnel is not running.
 *  @return Destination or null
 */
public Destination getDestination(int tunnel) {
    TunnelController tun = getController(tunnel);
    if (tun != null) {
        Destination rv = tun.getDestination();
        if (rv != null)
            return rv;
        // if not running, do this the hard way
        File keyFile = tun.getPrivateKeyFile();
        if (keyFile != null) {
            PrivateKeyFile pkf = new PrivateKeyFile(keyFile);
            try {
                rv = pkf.getDestination();
                if (rv != null)
                    return rv;
            } catch (I2PException e) {
            } catch (IOException e) {
            }
        }
    }
    return null;
}
Also used : I2PException(net.i2p.I2PException) Destination(net.i2p.data.Destination) TunnelController(net.i2p.i2ptunnel.TunnelController) PrivateKeyFile(net.i2p.data.PrivateKeyFile) IOException(java.io.IOException) SecureFile(net.i2p.util.SecureFile) PrivateKeyFile(net.i2p.data.PrivateKeyFile) File(java.io.File)

Example 12 with TunnelController

use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.

the class EditBean method staticIsClient.

/**
 *  Is it a client or server in the UI and I2P side?
 *  Note that a streamr client is a UI and I2P client but a server on the localhost side.
 *  Note that a streamr server is a UI and I2P server but a client on the localhost side.
 */
public static boolean staticIsClient(int tunnel) {
    TunnelControllerGroup group = TunnelControllerGroup.getInstance();
    if (group == null)
        return false;
    List<TunnelController> controllers = group.getControllers();
    if (controllers.size() > tunnel) {
        TunnelController cur = controllers.get(tunnel);
        if (cur == null)
            return false;
        return isClient(cur.getType());
    } else {
        return false;
    }
}
Also used : TunnelController(net.i2p.i2ptunnel.TunnelController) TunnelControllerGroup(net.i2p.i2ptunnel.TunnelControllerGroup)

Example 13 with TunnelController

use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.

the class IndexBean method generateNewEncryptionKey.

/**
 * New key
 */
private String generateNewEncryptionKey() {
    TunnelController tun = getController(_tunnel);
    Properties config = getConfig();
    if (tun == null) {
        // creating new
        tun = new TunnelController(config, "", true);
        _group.addController(tun);
        saveChanges();
    } else if (tun.getIsRunning() || tun.getIsStarting()) {
        return "Tunnel must be stopped before modifying leaseset encryption key";
    }
    byte[] data = new byte[SessionKey.KEYSIZE_BYTES];
    _context.random().nextBytes(data);
    SessionKey sk = new SessionKey(data);
    setEncryptKey(sk.toBase64());
    setEncrypt("");
    saveChanges();
    return "New Leaseset Encryption Key: " + sk.toBase64();
}
Also used : SessionKey(net.i2p.data.SessionKey) TunnelController(net.i2p.i2ptunnel.TunnelController) Properties(java.util.Properties)

Example 14 with TunnelController

use of net.i2p.i2ptunnel.TunnelController in project i2p.i2p by i2p.

the class IndexBean method getClientPort2.

/**
 *  Returns error message if blank or invalid
 *  @since 0.9.3
 */
public String getClientPort2(int tunnel) {
    TunnelController tun = getController(tunnel);
    if (tun != null && tun.getListenPort() != null) {
        String port = tun.getListenPort();
        if (port.length() == 0)
            return "<font color=\"red\">" + _t("Port not set") + "</font>";
        int iport = Addresses.getPort(port);
        if (iport == 0)
            return "<font color=\"red\">" + _t("Invalid port") + ' ' + port + "</font>";
        if (iport < 1024)
            return "<font color=\"red\">" + _t("Warning - ports less than 1024 are not recommended") + ": " + port + "</font>";
        // dup check, O(n**2)
        List<TunnelController> controllers = _group.getControllers();
        for (int i = 0; i < controllers.size(); i++) {
            if (i == tunnel)
                continue;
            if (port.equals(controllers.get(i).getListenPort()))
                return "<font color=\"red\">" + _t("Warning - duplicate port") + ": " + port + "</font>";
        }
        return port;
    }
    return "<font color=\"red\">" + _t("Port not set") + "</font>";
}
Also used : TunnelController(net.i2p.i2ptunnel.TunnelController)

Aggregations

TunnelController (net.i2p.i2ptunnel.TunnelController)14 File (java.io.File)5 PrivateKeyFile (net.i2p.data.PrivateKeyFile)5 Properties (java.util.Properties)4 IOException (java.io.IOException)3 SecureFile (net.i2p.util.SecureFile)3 I2PException (net.i2p.I2PException)2 Destination (net.i2p.data.Destination)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Certificate (net.i2p.data.Certificate)1 Hash (net.i2p.data.Hash)1 SessionKey (net.i2p.data.SessionKey)1 TunnelControllerGroup (net.i2p.i2ptunnel.TunnelControllerGroup)1 ConvertToHash (net.i2p.util.ConvertToHash)1