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;
}
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;
}
}
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();
}
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>";
}
Aggregations