i2ptunnel: Define standard tunnel properties and types in one place

This commit is contained in:
zzz
2014-05-26 13:36:41 +00:00
parent e0914c358e
commit ff837cf66e
3 changed files with 166 additions and 121 deletions

View File

@@ -45,6 +45,45 @@ public class TunnelController implements Logging {
public static final String KEY_BACKUP_DIR = "i2ptunnel-keyBackup"; public static final String KEY_BACKUP_DIR = "i2ptunnel-keyBackup";
/** all of these @since 0.9.14 */
public static final String PROP_DESCR = "description";
public static final String PROP_DEST = "targetDestination";
public static final String PROP_I2CP_HOST = "i2cpHost";
public static final String PROP_I2CP_PORT = "i2cpPort";
public static final String PROP_INTFC = "interface";
public static final String PROP_FILE = "privKeyFile";
public static final String PROP_LISTEN_PORT = "listenPort";
public static final String PROP_NAME = "name";
public static final String PROP_PROXIES = "proxyList";
public static final String PROP_SHARED = "sharedClient";
public static final String PROP_SPOOFED_HOST = "spoofedHost";
public static final String PROP_START = "startOnLoad";
public static final String PROP_TARGET_HOST = "targetHost";
public static final String PROP_TARGET_PORT = "targetPort";
public static final String PROP_TYPE = "type";
/** @since 0.9.14 */
public static final String PFX_OPTION = "option.";
private static final String OPT_PERSISTENT = PFX_OPTION + "persistentClientKey";
private static final String OPT_BUNDLE_REPLY = PFX_OPTION + "shouldBundleReplyInfo";
private static final String OPT_TAGS_SEND = PFX_OPTION + "crypto.tagsToSend";
private static final String OPT_LOW_TAGS = PFX_OPTION + "crypto.lowTagThreshold";
/** all of these @since 0.9.14 */
public static final String TYPE_CONNECT = "connectclient";
public static final String TYPE_HTTP_BIDIR_SERVER = "httpbidirserver";
public static final String TYPE_HTTP_CLIENT = "httpclient";
public static final String TYPE_HTTP_SERVER = "httpserver";
public static final String TYPE_IRC_CLIENT = "ircclient";
public static final String TYPE_IRC_SERVER = "ircserver";
public static final String TYPE_SOCKS = "sockstunnel";
public static final String TYPE_SOCKS_IRC = "socksirctunnel";
public static final String TYPE_STD_CLIENT = "client";
public static final String TYPE_STD_SERVER = "server";
public static final String TYPE_STREAMR_CLIENT = "streamrclient";
public static final String TYPE_STREAMR_SERVER = "streamrserver";
/** /**
* Create a new controller for a tunnel out of the specific config options. * Create a new controller for a tunnel out of the specific config options.
* The config may contain a large number of options - only ones that begin in * The config may contain a large number of options - only ones that begin in
@@ -104,7 +143,7 @@ public class TunnelController implements Logging {
try { try {
fos = new SecureFileOutputStream(keyFile); fos = new SecureFileOutputStream(keyFile);
SigType stype = I2PClient.DEFAULT_SIGTYPE; SigType stype = I2PClient.DEFAULT_SIGTYPE;
String st = _config.getProperty("option." + I2PClient.PROP_SIGTYPE); String st = _config.getProperty(PFX_OPTION + I2PClient.PROP_SIGTYPE);
if (st != null) { if (st != null) {
SigType type = SigType.parseSigType(st); SigType type = SigType.parseSigType(st);
if (type != null) if (type != null)
@@ -193,29 +232,29 @@ public class TunnelController implements Logging {
} }
setI2CPOptions(); setI2CPOptions();
setSessionOptions(); setSessionOptions();
if ("httpclient".equals(type)) { if (TYPE_HTTP_CLIENT.equals(type)) {
startHttpClient(); startHttpClient();
} else if("ircclient".equals(type)) { } else if(TYPE_IRC_CLIENT.equals(type)) {
startIrcClient(); startIrcClient();
} else if("sockstunnel".equals(type)) { } else if(TYPE_SOCKS.equals(type)) {
startSocksClient(); startSocksClient();
} else if("socksirctunnel".equals(type)) { } else if(TYPE_SOCKS_IRC.equals(type)) {
startSocksIRCClient(); startSocksIRCClient();
} else if("connectclient".equals(type)) { } else if(TYPE_CONNECT.equals(type)) {
startConnectClient(); startConnectClient();
} else if ("client".equals(type)) { } else if (TYPE_STD_CLIENT.equals(type)) {
startClient(); startClient();
} else if ("streamrclient".equals(type)) { } else if (TYPE_STREAMR_CLIENT.equals(type)) {
startStreamrClient(); startStreamrClient();
} else if ("server".equals(type)) { } else if (TYPE_STD_SERVER.equals(type)) {
startServer(); startServer();
} else if ("httpserver".equals(type)) { } else if (TYPE_HTTP_SERVER.equals(type)) {
startHttpServer(); startHttpServer();
} else if ("httpbidirserver".equals(type)) { } else if (TYPE_HTTP_BIDIR_SERVER.equals(type)) {
startHttpBidirServer(); startHttpBidirServer();
} else if ("ircserver".equals(type)) { } else if (TYPE_IRC_SERVER.equals(type)) {
startIrcServer(); startIrcServer();
} else if ("streamrserver".equals(type)) { } else if (TYPE_STREAMR_SERVER.equals(type)) {
startStreamrServer(); startStreamrServer();
} else { } else {
if (_log.shouldLog(Log.ERROR)) if (_log.shouldLog(Log.ERROR))
@@ -428,8 +467,8 @@ public class TunnelController implements Logging {
Properties opts = new Properties(); Properties opts = new Properties();
for (Map.Entry<Object, Object> e : _config.entrySet()) { for (Map.Entry<Object, Object> e : _config.entrySet()) {
String key = (String) e.getKey(); String key = (String) e.getKey();
if (key.startsWith("option.")) { if (key.startsWith(PFX_OPTION)) {
key = key.substring("option.".length()); key = key.substring(PFX_OPTION.length());
String val = (String) e.getValue(); String val = (String) e.getValue();
opts.setProperty(key, val); opts.setProperty(key, val);
} }
@@ -444,11 +483,11 @@ public class TunnelController implements Logging {
// as a "spoofed" option. Since 0.9.9. // as a "spoofed" option. Since 0.9.9.
String target = getTargetDestination(); String target = getTargetDestination();
if (target != null) if (target != null)
opts.setProperty("targetDestination", target); opts.setProperty(PROP_DEST, target);
// Ditto outproxy list. Since 0.9.12. // Ditto outproxy list. Since 0.9.12.
String proxies = getProxyList(); String proxies = getProxyList();
if (proxies != null) if (proxies != null)
opts.setProperty("proxyList", proxies); opts.setProperty(PROP_PROXIES, proxies);
_tunnel.setClientOptions(opts); _tunnel.setClientOptions(opts);
} }
@@ -504,15 +543,15 @@ public class TunnelController implements Logging {
// is done in the I2PTunnelServer constructor. // is done in the I2PTunnelServer constructor.
String type = getType(); String type = getType();
if (type != null) { if (type != null) {
if (type.equals("httpserver") || type.equals("streamrserver")) { if (type.equals(TYPE_HTTP_SERVER) || type.equals(TYPE_STREAMR_SERVER)) {
if (!_config.containsKey("option.shouldBundleReplyInfo")) if (!_config.containsKey(OPT_BUNDLE_REPLY))
_config.setProperty("option.shouldBundleReplyInfo", "false"); _config.setProperty(OPT_BUNDLE_REPLY, "false");
} else if (type.contains("irc") || type.equals("streamrclient")) { } else if (type.contains("irc") || type.equals(TYPE_STREAMR_CLIENT)) {
// maybe a bad idea for ircclient if DCC is enabled // maybe a bad idea for ircclient if DCC is enabled
if (!_config.containsKey("option.crypto.tagsToSend")) if (!_config.containsKey(OPT_TAGS_SEND))
_config.setProperty("option.crypto.tagsToSend", "20"); _config.setProperty(OPT_TAGS_SEND, "20");
if (!_config.containsKey("option.crypto.lowTagThreshold")) if (!_config.containsKey(OPT_LOW_TAGS))
_config.setProperty("option.crypto.lowTagThreshold", "14"); _config.setProperty(OPT_LOW_TAGS, "14");
} }
} }
@@ -541,11 +580,11 @@ public class TunnelController implements Logging {
return rv; return rv;
} }
public String getType() { return _config.getProperty("type"); } public String getType() { return _config.getProperty(PROP_TYPE); }
public String getName() { return _config.getProperty("name"); } public String getName() { return _config.getProperty(PROP_NAME); }
public String getDescription() { return _config.getProperty("description"); } public String getDescription() { return _config.getProperty(PROP_DESCR); }
public String getI2CPHost() { return _config.getProperty("i2cpHost"); } public String getI2CPHost() { return _config.getProperty(PROP_I2CP_HOST); }
public String getI2CPPort() { return _config.getProperty("i2cpPort"); } public String getI2CPPort() { return _config.getProperty(PROP_I2CP_PORT); }
/** /**
* These are the ones with a prefix of "option." * These are the ones with a prefix of "option."
@@ -557,8 +596,8 @@ public class TunnelController implements Logging {
StringBuilder opts = new StringBuilder(64); StringBuilder opts = new StringBuilder(64);
for (Map.Entry<Object, Object> e : _config.entrySet()) { for (Map.Entry<Object, Object> e : _config.entrySet()) {
String key = (String) e.getKey(); String key = (String) e.getKey();
if (key.startsWith("option.")) { if (key.startsWith(PFX_OPTION)) {
key = key.substring("option.".length()); key = key.substring(PFX_OPTION.length());
String val = (String) e.getValue(); String val = (String) e.getValue();
if (opts.length() > 0) opts.append(' '); if (opts.length() > 0) opts.append(' ');
opts.append(key).append('=').append(val); opts.append(key).append('=').append(val);
@@ -567,19 +606,19 @@ public class TunnelController implements Logging {
return opts.toString(); return opts.toString();
} }
public String getListenOnInterface() { return _config.getProperty("interface"); } public String getListenOnInterface() { return _config.getProperty(PROP_INTFC); }
public String getTargetHost() { return _config.getProperty("targetHost"); } public String getTargetHost() { return _config.getProperty(PROP_TARGET_HOST); }
public String getTargetPort() { return _config.getProperty("targetPort"); } public String getTargetPort() { return _config.getProperty(PROP_TARGET_PORT); }
public String getSpoofedHost() { return _config.getProperty("spoofedHost"); } public String getSpoofedHost() { return _config.getProperty(PROP_SPOOFED_HOST); }
public String getPrivKeyFile() { return _config.getProperty("privKeyFile"); } public String getPrivKeyFile() { return _config.getProperty(PROP_FILE); }
public String getListenPort() { return _config.getProperty("listenPort"); } public String getListenPort() { return _config.getProperty(PROP_LISTEN_PORT); }
public String getTargetDestination() { return _config.getProperty("targetDestination"); } public String getTargetDestination() { return _config.getProperty(PROP_DEST); }
public String getProxyList() { return _config.getProperty("proxyList"); } public String getProxyList() { return _config.getProperty(PROP_PROXIES); }
/** default true */ /** default true */
public String getSharedClient() { return _config.getProperty("sharedClient", "true"); } public String getSharedClient() { return _config.getProperty(PROP_SHARED, "true"); }
/** default true */ /** default true */
public boolean getStartOnLoad() { return Boolean.parseBoolean(_config.getProperty("startOnLoad", "true")); } public boolean getStartOnLoad() { return Boolean.parseBoolean(_config.getProperty(PROP_START, "true")); }
public boolean getPersistentClientKey() { return Boolean.parseBoolean(_config.getProperty("option.persistentClientKey")); } public boolean getPersistentClientKey() { return Boolean.parseBoolean(_config.getProperty(OPT_PERSISTENT)); }
public String getMyDestination() { public String getMyDestination() {
if (_tunnel != null) { if (_tunnel != null) {

View File

@@ -399,7 +399,7 @@ public class EditBean extends IndexBean {
/** @since 0.9.12 */ /** @since 0.9.12 */
public boolean isAdvanced() { public boolean isAdvanced() {
return _context.getBooleanProperty("routerconsole.advanced"); return _context.getBooleanProperty(PROP_ADVANCED);
} }
public String getI2CPHost(int tunnel) { public String getI2CPHost(int tunnel) {
@@ -427,8 +427,8 @@ public class EditBean extends IndexBean {
if (tun != null) { if (tun != null) {
Properties opts = getOptions(tun); Properties opts = getOptions(tun);
if (opts == null) return ""; if (opts == null) return "";
boolean isMD5Proxy = "httpclient".equals(tun.getType()) || boolean isMD5Proxy = TunnelController.TYPE_HTTP_CLIENT.equals(tun.getType()) ||
"connectclient".equals(tun.getType()); TunnelController.TYPE_CONNECT.equals(tun.getType());
Map<String, String> sorted = new TreeMap<String, String>(); Map<String, String> sorted = new TreeMap<String, String>();
for (Map.Entry<Object, Object> e : opts.entrySet()) { for (Map.Entry<Object, Object> e : opts.entrySet()) {
String key = (String)e.getKey(); String key = (String)e.getKey();

View File

@@ -113,6 +113,7 @@ public class IndexBean {
public static final String PROP_CSS_DISABLED = "routerconsole.css.disabled"; public static final String PROP_CSS_DISABLED = "routerconsole.css.disabled";
public static final String PROP_JS_DISABLED = "routerconsole.javascript.disabled"; public static final String PROP_JS_DISABLED = "routerconsole.javascript.disabled";
private static final String PROP_PW_ENABLE = "routerconsole.auth.enable"; private static final String PROP_PW_ENABLE = "routerconsole.auth.enable";
private static final String OPT = TunnelController.PFX_OPTION;
public IndexBean() { public IndexBean() {
_context = I2PAppContext.getGlobalContext(); _context = I2PAppContext.getGlobalContext();
@@ -445,13 +446,13 @@ public class IndexBean {
} }
public static boolean isClient(String type) { public static boolean isClient(String type) {
return ( ("client".equals(type)) || return ( (TunnelController.TYPE_STD_CLIENT.equals(type)) ||
("httpclient".equals(type)) || (TunnelController.TYPE_HTTP_CLIENT.equals(type)) ||
("sockstunnel".equals(type)) || (TunnelController.TYPE_SOCKS.equals(type)) ||
("socksirctunnel".equals(type)) || (TunnelController.TYPE_SOCKS_IRC.equals(type)) ||
("connectclient".equals(type)) || (TunnelController.TYPE_CONNECT.equals(type)) ||
("streamrclient".equals(type)) || (TunnelController.TYPE_STREAMR_CLIENT.equals(type)) ||
("ircclient".equals(type))); (TunnelController.TYPE_IRC_CLIENT.equals(type)));
} }
public String getTunnelName(int tunnel) { public String getTunnelName(int tunnel) {
@@ -514,18 +515,18 @@ public class IndexBean {
} }
public String getTypeName(String internalType) { public String getTypeName(String internalType) {
if ("client".equals(internalType)) return _("Standard client"); if (TunnelController.TYPE_STD_CLIENT.equals(internalType)) return _("Standard client");
else if ("httpclient".equals(internalType)) return _("HTTP/HTTPS client"); else if (TunnelController.TYPE_HTTP_CLIENT.equals(internalType)) return _("HTTP/HTTPS client");
else if ("ircclient".equals(internalType)) return _("IRC client"); else if (TunnelController.TYPE_IRC_CLIENT.equals(internalType)) return _("IRC client");
else if ("server".equals(internalType)) return _("Standard server"); else if (TunnelController.TYPE_STD_SERVER.equals(internalType)) return _("Standard server");
else if ("httpserver".equals(internalType)) return _("HTTP server"); else if (TunnelController.TYPE_HTTP_SERVER.equals(internalType)) return _("HTTP server");
else if ("sockstunnel".equals(internalType)) return _("SOCKS 4/4a/5 proxy"); else if (TunnelController.TYPE_SOCKS.equals(internalType)) return _("SOCKS 4/4a/5 proxy");
else if ("socksirctunnel".equals(internalType)) return _("SOCKS IRC proxy"); else if (TunnelController.TYPE_SOCKS_IRC.equals(internalType)) return _("SOCKS IRC proxy");
else if ("connectclient".equals(internalType)) return _("CONNECT/SSL/HTTPS proxy"); else if (TunnelController.TYPE_CONNECT.equals(internalType)) return _("CONNECT/SSL/HTTPS proxy");
else if ("ircserver".equals(internalType)) return _("IRC server"); else if (TunnelController.TYPE_IRC_SERVER.equals(internalType)) return _("IRC server");
else if ("streamrclient".equals(internalType)) return _("Streamr client"); else if (TunnelController.TYPE_STREAMR_CLIENT.equals(internalType)) return _("Streamr client");
else if ("streamrserver".equals(internalType)) return _("Streamr server"); else if (TunnelController.TYPE_STREAMR_SERVER.equals(internalType)) return _("Streamr server");
else if ("httpbidirserver".equals(internalType)) return _("HTTP bidir"); else if (TunnelController.TYPE_HTTP_BIDIR_SERVER.equals(internalType)) return _("HTTP bidir");
else return internalType; else return internalType;
} }
@@ -580,8 +581,9 @@ public class IndexBean {
TunnelController tun = getController(tunnel); TunnelController tun = getController(tunnel);
if (tun == null) return ""; if (tun == null) return "";
String rv; String rv;
if ("client".equals(tun.getType()) || "ircclient".equals(tun.getType()) || if (TunnelController.TYPE_STD_CLIENT.equals(tun.getType()) ||
"streamrclient".equals(tun.getType())) TunnelController.TYPE_IRC_CLIENT.equals(tun.getType()) ||
TunnelController.TYPE_STREAMR_CLIENT.equals(tun.getType()))
rv = tun.getTargetDestination(); rv = tun.getTargetDestination();
else else
rv = tun.getProxyList(); rv = tun.getProxyList();
@@ -595,7 +597,7 @@ public class IndexBean {
public boolean isServerTargetLinkValid(int tunnel) { public boolean isServerTargetLinkValid(int tunnel) {
TunnelController tun = getController(tunnel); TunnelController tun = getController(tunnel);
return tun != null && return tun != null &&
"httpserver".equals(tun.getType()) && TunnelController.TYPE_HTTP_SERVER.equals(tun.getType()) &&
tun.getTargetHost() != null && tun.getTargetHost() != null &&
tun.getTargetPort() != null; tun.getTargetPort() != null;
} }
@@ -665,7 +667,7 @@ public class IndexBean {
public boolean getIsUsingOutproxyPlugin(int tunnel) { public boolean getIsUsingOutproxyPlugin(int tunnel) {
TunnelController tun = getController(tunnel); TunnelController tun = getController(tunnel);
if (tun != null) { if (tun != null) {
if ("httpclient".equals(tun.getType())) { if (TunnelController.TYPE_HTTP_CLIENT.equals(tun.getType())) {
Properties opts = tun.getClientOptionProps(); Properties opts = tun.getClientOptionProps();
if (Boolean.parseBoolean(opts.getProperty(I2PTunnelHTTPClient.PROP_USE_OUTPROXY_PLUGIN, "true"))) { if (Boolean.parseBoolean(opts.getProperty(I2PTunnelHTTPClient.PROP_USE_OUTPROXY_PLUGIN, "true"))) {
ClientAppManager mgr = _context.clientAppManager(); ClientAppManager mgr = _context.clientAppManager();
@@ -1100,9 +1102,9 @@ public class IndexBean {
String signerPKF = null; String signerPKF = null;
for (int i = 0; i < getTunnelCount(); i++) { for (int i = 0; i < getTunnelCount(); i++) {
TunnelController c = getController(i); TunnelController c = getController(i);
if (_certSigner.equals(c.getConfig("").getProperty("name")) || if (_certSigner.equals(c.getConfig("").getProperty(TunnelController.PROP_NAME)) ||
_certSigner.equals(c.getConfig("").getProperty("spoofedHost"))) { _certSigner.equals(c.getConfig("").getProperty(TunnelController.PROP_SPOOFED_HOST))) {
signerPKF = c.getConfig("").getProperty("privKeyFile"); signerPKF = c.getConfig("").getProperty(TunnelController.PROP_FILE);
break; break;
} }
} }
@@ -1160,62 +1162,63 @@ public class IndexBean {
Properties config = new Properties(); Properties config = new Properties();
updateConfigGeneric(config); updateConfigGeneric(config);
if ((isClient(_type) && !"streamrclient".equals(_type)) || "streamrserver".equals(_type)) { if ((isClient(_type) && !TunnelController.TYPE_STREAMR_CLIENT.equals(_type)) ||
TunnelController.TYPE_STREAMR_SERVER.equals(_type)) {
// streamrserver uses interface // streamrserver uses interface
if (_reachableBy != null) if (_reachableBy != null)
config.setProperty("interface", _reachableBy); config.setProperty(TunnelController.PROP_INTFC, _reachableBy);
else else
config.setProperty("interface", ""); config.setProperty(TunnelController.PROP_INTFC, "");
} else { } else {
// streamrclient uses targetHost // streamrclient uses targetHost
if (_targetHost != null) if (_targetHost != null)
config.setProperty("targetHost", _targetHost); config.setProperty(TunnelController.PROP_TARGET_HOST, _targetHost);
} }
if (isClient(_type)) { if (isClient(_type)) {
// generic client stuff // generic client stuff
if (_port != null) if (_port != null)
config.setProperty("listenPort", _port); config.setProperty(TunnelController.PROP_LISTEN_PORT, _port);
config.setProperty("sharedClient", _sharedClient + ""); config.setProperty(TunnelController.PROP_SHARED, _sharedClient + "");
for (String p : _booleanClientOpts) for (String p : _booleanClientOpts)
config.setProperty("option." + p, "" + _booleanOptions.contains(p)); config.setProperty(OPT + p, "" + _booleanOptions.contains(p));
for (String p : _otherClientOpts) for (String p : _otherClientOpts)
if (_otherOptions.containsKey(p)) if (_otherOptions.containsKey(p))
config.setProperty("option." + p, _otherOptions.get(p)); config.setProperty(OPT + p, _otherOptions.get(p));
} else { } else {
// generic server stuff // generic server stuff
if (_targetPort != null) if (_targetPort != null)
config.setProperty("targetPort", _targetPort); config.setProperty(TunnelController.PROP_TARGET_PORT, _targetPort);
for (String p : _booleanServerOpts) for (String p : _booleanServerOpts)
config.setProperty("option." + p, "" + _booleanOptions.contains(p)); config.setProperty(OPT + p, "" + _booleanOptions.contains(p));
for (String p : _otherServerOpts) for (String p : _otherServerOpts)
if (_otherOptions.containsKey(p)) if (_otherOptions.containsKey(p))
config.setProperty("option." + p, _otherOptions.get(p)); config.setProperty(OPT + p, _otherOptions.get(p));
} }
// generic proxy stuff // generic proxy stuff
if ("httpclient".equals(_type) || "connectclient".equals(_type) || if (TunnelController.TYPE_HTTP_CLIENT.equals(_type) || TunnelController.TYPE_CONNECT.equals(_type) ||
"sockstunnel".equals(_type) ||"socksirctunnel".equals(_type)) { TunnelController.TYPE_SOCKS.equals(_type) ||TunnelController.TYPE_SOCKS_IRC.equals(_type)) {
for (String p : _booleanProxyOpts) for (String p : _booleanProxyOpts)
config.setProperty("option." + p, "" + _booleanOptions.contains(p)); config.setProperty(OPT + p, "" + _booleanOptions.contains(p));
if (_proxyList != null) if (_proxyList != null)
config.setProperty("proxyList", _proxyList); config.setProperty(TunnelController.PROP_PROXIES, _proxyList);
} }
// Proxy auth including migration to MD5 // Proxy auth including migration to MD5
if ("httpclient".equals(_type) || "connectclient".equals(_type)) { if (TunnelController.TYPE_HTTP_CLIENT.equals(_type) || TunnelController.TYPE_CONNECT.equals(_type)) {
// Migrate even if auth is disabled // Migrate even if auth is disabled
// go get the old from custom options that updateConfigGeneric() put in there // go get the old from custom options that updateConfigGeneric() put in there
String puser = "option." + I2PTunnelHTTPClientBase.PROP_USER; String puser = OPT + I2PTunnelHTTPClientBase.PROP_USER;
String user = config.getProperty(puser); String user = config.getProperty(puser);
String ppw = "option." + I2PTunnelHTTPClientBase.PROP_PW; String ppw = OPT + I2PTunnelHTTPClientBase.PROP_PW;
String pw = config.getProperty(ppw); String pw = config.getProperty(ppw);
if (user != null && pw != null && user.length() > 0 && pw.length() > 0) { if (user != null && pw != null && user.length() > 0 && pw.length() > 0) {
String pmd5 = "option." + I2PTunnelHTTPClientBase.PROP_PROXY_DIGEST_PREFIX + String pmd5 = OPT + I2PTunnelHTTPClientBase.PROP_PROXY_DIGEST_PREFIX +
user + I2PTunnelHTTPClientBase.PROP_PROXY_DIGEST_SUFFIX; user + I2PTunnelHTTPClientBase.PROP_PROXY_DIGEST_SUFFIX;
if (config.getProperty(pmd5) == null) { if (config.getProperty(pmd5) == null) {
// not in there, migrate // not in there, migrate
String realm = _type.equals("httpclient") ? I2PTunnelHTTPClient.AUTH_REALM String realm = _type.equals(TunnelController.TYPE_HTTP_CLIENT) ? I2PTunnelHTTPClient.AUTH_REALM
: I2PTunnelConnectClient.AUTH_REALM; : I2PTunnelConnectClient.AUTH_REALM;
String hex = PasswordManager.md5Hex(realm, user, pw); String hex = PasswordManager.md5Hex(realm, user, pw);
if (hex != null) { if (hex != null) {
@@ -1230,9 +1233,9 @@ public class IndexBean {
if (auth != null && !auth.equals("false")) { if (auth != null && !auth.equals("false")) {
if (_newProxyUser != null && _newProxyPW != null && if (_newProxyUser != null && _newProxyPW != null &&
_newProxyUser.length() > 0 && _newProxyPW.length() > 0) { _newProxyUser.length() > 0 && _newProxyPW.length() > 0) {
String pmd5 = "option." + I2PTunnelHTTPClientBase.PROP_PROXY_DIGEST_PREFIX + String pmd5 = OPT + I2PTunnelHTTPClientBase.PROP_PROXY_DIGEST_PREFIX +
_newProxyUser + I2PTunnelHTTPClientBase.PROP_PROXY_DIGEST_SUFFIX; _newProxyUser + I2PTunnelHTTPClientBase.PROP_PROXY_DIGEST_SUFFIX;
String realm = _type.equals("httpclient") ? I2PTunnelHTTPClient.AUTH_REALM String realm = _type.equals(TunnelController.TYPE_HTTP_CLIENT) ? I2PTunnelHTTPClient.AUTH_REALM
: I2PTunnelConnectClient.AUTH_REALM; : I2PTunnelConnectClient.AUTH_REALM;
String hex = PasswordManager.md5Hex(realm, _newProxyUser, _newProxyPW); String hex = PasswordManager.md5Hex(realm, _newProxyUser, _newProxyPW);
if (hex != null) if (hex != null)
@@ -1241,37 +1244,40 @@ public class IndexBean {
} }
} }
if ("ircclient".equals(_type) || "client".equals(_type) || "streamrclient".equals(_type)) { if (TunnelController.TYPE_IRC_CLIENT.equals(_type) ||
TunnelController.TYPE_STD_CLIENT.equals(_type) ||
TunnelController.TYPE_STREAMR_CLIENT.equals(_type)) {
if (_targetDestination != null) if (_targetDestination != null)
config.setProperty("targetDestination", _targetDestination); config.setProperty(TunnelController.PROP_DEST, _targetDestination);
} else if ("httpserver".equals(_type) || "httpbidirserver".equals(_type)) { } else if (TunnelController.TYPE_HTTP_SERVER.equals(_type) ||
TunnelController.TYPE_HTTP_BIDIR_SERVER.equals(_type)) {
if (_spoofedHost != null) if (_spoofedHost != null)
config.setProperty("spoofedHost", _spoofedHost); config.setProperty(TunnelController.PROP_SPOOFED_HOST, _spoofedHost);
for (String p : _httpServerOpts) for (String p : _httpServerOpts)
if (_otherOptions.containsKey(p)) if (_otherOptions.containsKey(p))
config.setProperty("option." + p, _otherOptions.get(p)); config.setProperty(OPT + p, _otherOptions.get(p));
} }
if ("httpbidirserver".equals(_type)) { if (TunnelController.TYPE_HTTP_BIDIR_SERVER.equals(_type)) {
if (_port != null) if (_port != null)
config.setProperty("listenPort", _port); config.setProperty(TunnelController.PROP_LISTEN_PORT, _port);
if (_reachableBy != null) if (_reachableBy != null)
config.setProperty("interface", _reachableBy); config.setProperty(TunnelController.PROP_INTFC, _reachableBy);
else if (_targetHost != null) else if (_targetHost != null)
config.setProperty("interface", _targetHost); config.setProperty(TunnelController.PROP_INTFC, _targetHost);
else else
config.setProperty("interface", ""); config.setProperty(TunnelController.PROP_INTFC, "");
} }
if ("ircclient".equals(_type)) { if (TunnelController.TYPE_IRC_CLIENT.equals(_type)) {
boolean dcc = _booleanOptions.contains(I2PTunnelIRCClient.PROP_DCC); boolean dcc = _booleanOptions.contains(I2PTunnelIRCClient.PROP_DCC);
config.setProperty("option." + I2PTunnelIRCClient.PROP_DCC, config.setProperty(OPT + I2PTunnelIRCClient.PROP_DCC,
"" + dcc); "" + dcc);
// add some sane server options since they aren't in the GUI (yet) // add some sane server options since they aren't in the GUI (yet)
if (dcc) { if (dcc) {
config.setProperty("option." + PROP_MAX_CONNS_MIN, "3"); config.setProperty(OPT + PROP_MAX_CONNS_MIN, "3");
config.setProperty("option." + PROP_MAX_CONNS_HOUR, "10"); config.setProperty(OPT + PROP_MAX_CONNS_HOUR, "10");
config.setProperty("option." + PROP_MAX_TOTAL_CONNS_MIN, "5"); config.setProperty(OPT + PROP_MAX_TOTAL_CONNS_MIN, "5");
config.setProperty("option." + PROP_MAX_TOTAL_CONNS_HOUR, "25"); config.setProperty(OPT + PROP_MAX_TOTAL_CONNS_HOUR, "25");
} }
} }
@@ -1346,22 +1352,22 @@ public class IndexBean {
} }
private void updateConfigGeneric(Properties config) { private void updateConfigGeneric(Properties config) {
config.setProperty("type", _type); config.setProperty(TunnelController.PROP_TYPE, _type);
if (_name != null) if (_name != null)
config.setProperty("name", _name); config.setProperty(TunnelController.PROP_NAME, _name);
if (_description != null) if (_description != null)
config.setProperty("description", _description); config.setProperty(TunnelController.PROP_DESCR, _description);
if (!_context.isRouterContext()) { if (!_context.isRouterContext()) {
if (_i2cpHost != null) if (_i2cpHost != null)
config.setProperty("i2cpHost", _i2cpHost); config.setProperty(TunnelController.PROP_I2CP_HOST, _i2cpHost);
if ( (_i2cpPort != null) && (_i2cpPort.trim().length() > 0) ) { if ( (_i2cpPort != null) && (_i2cpPort.trim().length() > 0) ) {
config.setProperty("i2cpPort", _i2cpPort); config.setProperty(TunnelController.PROP_I2CP_PORT, _i2cpPort);
} else { } else {
config.setProperty("i2cpPort", "7654"); config.setProperty(TunnelController.PROP_I2CP_PORT, "7654");
} }
} }
if (_privKeyFile != null) if (_privKeyFile != null)
config.setProperty("privKeyFile", _privKeyFile); config.setProperty(TunnelController.PROP_FILE, _privKeyFile);
if (_customOptions != null) { if (_customOptions != null) {
StringTokenizer tok = new StringTokenizer(_customOptions); StringTokenizer tok = new StringTokenizer(_customOptions);
@@ -1375,16 +1381,16 @@ public class IndexBean {
continue; continue;
// leave in for HTTP and Connect so it can get migrated to MD5 // leave in for HTTP and Connect so it can get migrated to MD5
// hide for SOCKS until migrated to MD5 // hide for SOCKS until migrated to MD5
if ((!"httpclient".equals(_type)) && if ((!TunnelController.TYPE_HTTP_CLIENT.equals(_type)) &&
(! "connectclient".equals(_type)) && (!TunnelController.TYPE_CONNECT.equals(_type)) &&
_nonProxyNoShowSet.contains(key)) _nonProxyNoShowSet.contains(key))
continue; continue;
String val = pair.substring(eq+1); String val = pair.substring(eq+1);
config.setProperty("option." + key, val); config.setProperty(OPT + key, val);
} }
} }
config.setProperty("startOnLoad", _startOnLoad + ""); config.setProperty(TunnelController.PROP_START, _startOnLoad + "");
if (_tunnelQuantity != null) { if (_tunnelQuantity != null) {
config.setProperty("option.inbound.quantity", _tunnelQuantity); config.setProperty("option.inbound.quantity", _tunnelQuantity);