* i2psnark:
- Add tunnel config dropdowns - Comment out old proxy stuff
This commit is contained in:
@ -45,7 +45,7 @@ public class I2PSnarkUtil {
|
|||||||
private int _proxyPort;
|
private int _proxyPort;
|
||||||
private String _i2cpHost;
|
private String _i2cpHost;
|
||||||
private int _i2cpPort;
|
private int _i2cpPort;
|
||||||
private Map _opts;
|
private Map<String, String> _opts;
|
||||||
private I2PSocketManager _manager;
|
private I2PSocketManager _manager;
|
||||||
private boolean _configured;
|
private boolean _configured;
|
||||||
private final Set<Hash> _shitlist;
|
private final Set<Hash> _shitlist;
|
||||||
@ -65,7 +65,7 @@ public class I2PSnarkUtil {
|
|||||||
_context = ctx;
|
_context = ctx;
|
||||||
_log = _context.logManager().getLog(Snark.class);
|
_log = _context.logManager().getLog(Snark.class);
|
||||||
_opts = new HashMap();
|
_opts = new HashMap();
|
||||||
setProxy("127.0.0.1", 4444);
|
//setProxy("127.0.0.1", 4444);
|
||||||
setI2CPConfig("127.0.0.1", 7654, null);
|
setI2CPConfig("127.0.0.1", 7654, null);
|
||||||
_shitlist = new ConcurrentHashSet();
|
_shitlist = new ConcurrentHashSet();
|
||||||
_configured = false;
|
_configured = false;
|
||||||
@ -85,6 +85,7 @@ public class I2PSnarkUtil {
|
|||||||
* host for no proxying)
|
* host for no proxying)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
/*****
|
||||||
public void setProxy(String host, int port) {
|
public void setProxy(String host, int port) {
|
||||||
if ( (host != null) && (port > 0) ) {
|
if ( (host != null) && (port > 0) ) {
|
||||||
_shouldProxy = true;
|
_shouldProxy = true;
|
||||||
@ -97,6 +98,7 @@ public class I2PSnarkUtil {
|
|||||||
}
|
}
|
||||||
_configured = true;
|
_configured = true;
|
||||||
}
|
}
|
||||||
|
******/
|
||||||
|
|
||||||
public boolean configured() { return _configured; }
|
public boolean configured() { return _configured; }
|
||||||
|
|
||||||
@ -128,7 +130,7 @@ public class I2PSnarkUtil {
|
|||||||
|
|
||||||
public String getI2CPHost() { return _i2cpHost; }
|
public String getI2CPHost() { return _i2cpHost; }
|
||||||
public int getI2CPPort() { return _i2cpPort; }
|
public int getI2CPPort() { return _i2cpPort; }
|
||||||
public Map getI2CPOptions() { return _opts; }
|
public Map<String, String> getI2CPOptions() { return _opts; }
|
||||||
public String getEepProxyHost() { return _proxyHost; }
|
public String getEepProxyHost() { return _proxyHost; }
|
||||||
public int getEepProxyPort() { return _proxyPort; }
|
public int getEepProxyPort() { return _proxyPort; }
|
||||||
public boolean getEepProxySet() { return _shouldProxy; }
|
public boolean getEepProxySet() { return _shouldProxy; }
|
||||||
|
@ -618,14 +618,14 @@ public class Snark
|
|||||||
command_interpreter = false;
|
command_interpreter = false;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
else if (args[i].equals("--eepproxy"))
|
//else if (args[i].equals("--eepproxy"))
|
||||||
{
|
// {
|
||||||
String proxyHost = args[i+1];
|
// String proxyHost = args[i+1];
|
||||||
String proxyPort = args[i+2];
|
// String proxyPort = args[i+2];
|
||||||
if (!configured)
|
// if (!configured)
|
||||||
util.setProxy(proxyHost, Integer.parseInt(proxyPort));
|
// util.setProxy(proxyHost, Integer.parseInt(proxyPort));
|
||||||
i += 3;
|
// i += 3;
|
||||||
}
|
// }
|
||||||
else if (args[i].equals("--i2cp"))
|
else if (args[i].equals("--i2cp"))
|
||||||
{
|
{
|
||||||
String i2cpHost = args[i+1];
|
String i2cpHost = args[i+1];
|
||||||
|
@ -46,8 +46,8 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
public static final String PROP_I2CP_HOST = "i2psnark.i2cpHost";
|
public static final String PROP_I2CP_HOST = "i2psnark.i2cpHost";
|
||||||
public static final String PROP_I2CP_PORT = "i2psnark.i2cpPort";
|
public static final String PROP_I2CP_PORT = "i2psnark.i2cpPort";
|
||||||
public static final String PROP_I2CP_OPTS = "i2psnark.i2cpOptions";
|
public static final String PROP_I2CP_OPTS = "i2psnark.i2cpOptions";
|
||||||
public static final String PROP_EEP_HOST = "i2psnark.eepHost";
|
//public static final String PROP_EEP_HOST = "i2psnark.eepHost";
|
||||||
public static final String PROP_EEP_PORT = "i2psnark.eepPort";
|
//public static final String PROP_EEP_PORT = "i2psnark.eepPort";
|
||||||
public static final String PROP_UPLOADERS_TOTAL = "i2psnark.uploaders.total";
|
public static final String PROP_UPLOADERS_TOTAL = "i2psnark.uploaders.total";
|
||||||
public static final String PROP_UPBW_MAX = "i2psnark.upbw.max";
|
public static final String PROP_UPBW_MAX = "i2psnark.upbw.max";
|
||||||
public static final String PROP_DIR = "i2psnark.dir";
|
public static final String PROP_DIR = "i2psnark.dir";
|
||||||
@ -157,10 +157,10 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
_config.setProperty(PROP_I2CP_PORT, "7654");
|
_config.setProperty(PROP_I2CP_PORT, "7654");
|
||||||
if (!_config.containsKey(PROP_I2CP_OPTS))
|
if (!_config.containsKey(PROP_I2CP_OPTS))
|
||||||
_config.setProperty(PROP_I2CP_OPTS, "inbound.length=2 inbound.lengthVariance=0 outbound.length=2 outbound.lengthVariance=0 inbound.quantity=3 outbound.quantity=3");
|
_config.setProperty(PROP_I2CP_OPTS, "inbound.length=2 inbound.lengthVariance=0 outbound.length=2 outbound.lengthVariance=0 inbound.quantity=3 outbound.quantity=3");
|
||||||
if (!_config.containsKey(PROP_EEP_HOST))
|
//if (!_config.containsKey(PROP_EEP_HOST))
|
||||||
_config.setProperty(PROP_EEP_HOST, "127.0.0.1");
|
// _config.setProperty(PROP_EEP_HOST, "127.0.0.1");
|
||||||
if (!_config.containsKey(PROP_EEP_PORT))
|
//if (!_config.containsKey(PROP_EEP_PORT))
|
||||||
_config.setProperty(PROP_EEP_PORT, "4444");
|
// _config.setProperty(PROP_EEP_PORT, "4444");
|
||||||
if (!_config.containsKey(PROP_UPLOADERS_TOTAL))
|
if (!_config.containsKey(PROP_UPLOADERS_TOTAL))
|
||||||
_config.setProperty(PROP_UPLOADERS_TOTAL, "" + Snark.MAX_TOTAL_UPLOADERS);
|
_config.setProperty(PROP_UPLOADERS_TOTAL, "" + Snark.MAX_TOTAL_UPLOADERS);
|
||||||
if (!_config.containsKey(PROP_DIR))
|
if (!_config.containsKey(PROP_DIR))
|
||||||
@ -198,10 +198,10 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
_log.debug("Configuring with I2CP options " + i2cpOpts);
|
_log.debug("Configuring with I2CP options " + i2cpOpts);
|
||||||
}
|
}
|
||||||
//I2PSnarkUtil.instance().setI2CPConfig("66.111.51.110", 7654, new Properties());
|
//I2PSnarkUtil.instance().setI2CPConfig("66.111.51.110", 7654, new Properties());
|
||||||
String eepHost = _config.getProperty(PROP_EEP_HOST);
|
//String eepHost = _config.getProperty(PROP_EEP_HOST);
|
||||||
int eepPort = getInt(PROP_EEP_PORT, 4444);
|
//int eepPort = getInt(PROP_EEP_PORT, 4444);
|
||||||
if (eepHost != null)
|
//if (eepHost != null)
|
||||||
_util.setProxy(eepHost, eepPort);
|
// _util.setProxy(eepHost, eepPort);
|
||||||
_util.setMaxUploaders(getInt(PROP_UPLOADERS_TOTAL, Snark.MAX_TOTAL_UPLOADERS));
|
_util.setMaxUploaders(getInt(PROP_UPLOADERS_TOTAL, Snark.MAX_TOTAL_UPLOADERS));
|
||||||
_util.setMaxUpBW(getInt(PROP_UPBW_MAX, DEFAULT_MAX_UP_BW));
|
_util.setMaxUpBW(getInt(PROP_UPBW_MAX, DEFAULT_MAX_UP_BW));
|
||||||
String ot = _config.getProperty(I2PSnarkUtil.PROP_OPENTRACKERS);
|
String ot = _config.getProperty(I2PSnarkUtil.PROP_OPENTRACKERS);
|
||||||
@ -226,20 +226,20 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
String eepPort, String i2cpHost, String i2cpPort, String i2cpOpts,
|
String eepPort, String i2cpHost, String i2cpPort, String i2cpOpts,
|
||||||
String upLimit, String upBW, boolean useOpenTrackers, String openTrackers) {
|
String upLimit, String upBW, boolean useOpenTrackers, String openTrackers) {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
if (eepHost != null) {
|
//if (eepHost != null) {
|
||||||
// unused, we use socket eepget
|
// // unused, we use socket eepget
|
||||||
int port = _util.getEepProxyPort();
|
// int port = _util.getEepProxyPort();
|
||||||
try { port = Integer.parseInt(eepPort); } catch (NumberFormatException nfe) {}
|
// try { port = Integer.parseInt(eepPort); } catch (NumberFormatException nfe) {}
|
||||||
String host = _util.getEepProxyHost();
|
// String host = _util.getEepProxyHost();
|
||||||
if ( (eepHost.trim().length() > 0) && (port > 0) &&
|
// if ( (eepHost.trim().length() > 0) && (port > 0) &&
|
||||||
((!host.equals(eepHost) || (port != _util.getEepProxyPort()) )) ) {
|
// ((!host.equals(eepHost) || (port != _util.getEepProxyPort()) )) ) {
|
||||||
_util.setProxy(eepHost, port);
|
// _util.setProxy(eepHost, port);
|
||||||
changed = true;
|
// changed = true;
|
||||||
_config.setProperty(PROP_EEP_HOST, eepHost);
|
// _config.setProperty(PROP_EEP_HOST, eepHost);
|
||||||
_config.setProperty(PROP_EEP_PORT, eepPort+"");
|
// _config.setProperty(PROP_EEP_PORT, eepPort+"");
|
||||||
addMessage("EepProxy location changed to " + eepHost + ":" + port);
|
// addMessage("EepProxy location changed to " + eepHost + ":" + port);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
if (upLimit != null) {
|
if (upLimit != null) {
|
||||||
int limit = _util.getMaxUploaders();
|
int limit = _util.getMaxUploaders();
|
||||||
try { limit = Integer.parseInt(upLimit); } catch (NumberFormatException nfe) {}
|
try { limit = Integer.parseInt(upLimit); } catch (NumberFormatException nfe) {}
|
||||||
@ -308,7 +308,10 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (snarksActive) {
|
if (snarksActive) {
|
||||||
addMessage(_("Cannot change the I2CP settings while torrents are active"));
|
Properties p = new Properties();
|
||||||
|
p.putAll(opts);
|
||||||
|
_util.setI2CPConfig(i2cpHost, port, p);
|
||||||
|
addMessage(_("I2CP and tunnel changes will take effect after stopping all torrents"));
|
||||||
_log.debug("i2cp host [" + i2cpHost + "] i2cp port " + port + " opts [" + opts
|
_log.debug("i2cp host [" + i2cpHost + "] i2cp port " + port + " opts [" + opts
|
||||||
+ "] oldOpts [" + oldOpts + "]");
|
+ "] oldOpts [" + oldOpts + "]");
|
||||||
} else {
|
} else {
|
||||||
|
@ -419,7 +419,7 @@ public class I2PSnarkServlet extends Default {
|
|||||||
String eepPort = req.getParameter("eepPort");
|
String eepPort = req.getParameter("eepPort");
|
||||||
String i2cpHost = req.getParameter("i2cpHost");
|
String i2cpHost = req.getParameter("i2cpHost");
|
||||||
String i2cpPort = req.getParameter("i2cpPort");
|
String i2cpPort = req.getParameter("i2cpPort");
|
||||||
String i2cpOpts = req.getParameter("i2cpOpts");
|
String i2cpOpts = buildI2CPOpts(req);
|
||||||
String upLimit = req.getParameter("upLimit");
|
String upLimit = req.getParameter("upLimit");
|
||||||
String upBW = req.getParameter("upBW");
|
String upBW = req.getParameter("upBW");
|
||||||
boolean useOpenTrackers = req.getParameter("useOpenTrackers") != null;
|
boolean useOpenTrackers = req.getParameter("useOpenTrackers") != null;
|
||||||
@ -486,6 +486,23 @@ public class I2PSnarkServlet extends Default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final String iopts[] = {"inbound.length", "inbound.quantity",
|
||||||
|
"outbound.length", "outbound.quantity" };
|
||||||
|
|
||||||
|
/** put the individual i2cp selections into the option string */
|
||||||
|
private static String buildI2CPOpts(HttpServletRequest req) {
|
||||||
|
StringBuilder buf = new StringBuilder(128);
|
||||||
|
String p = req.getParameter("i2cpOpts");
|
||||||
|
if (p != null)
|
||||||
|
buf.append(p);
|
||||||
|
for (int i = 0; i < iopts.length; i++) {
|
||||||
|
p = req.getParameter(iopts[i]);
|
||||||
|
if (p != null)
|
||||||
|
buf.append(' ').append(iopts[i]).append('=').append(p);
|
||||||
|
}
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort alphabetically in current locale, ignore case, ignore leading "the "
|
* Sort alphabetically in current locale, ignore case, ignore leading "the "
|
||||||
* (I guess this is worth it, a lot of torrents start with "The "
|
* (I guess this is worth it, a lot of torrents start with "The "
|
||||||
@ -982,6 +999,20 @@ public class I2PSnarkServlet extends Default {
|
|||||||
//out.write("port: <input type=\"text\" name=\"eepPort\" value=\""
|
//out.write("port: <input type=\"text\" name=\"eepPort\" value=\""
|
||||||
// + _manager.util().getEepProxyPort() + "\" size=\"5\" maxlength=\"5\" /><br>\n");
|
// + _manager.util().getEepProxyPort() + "\" size=\"5\" maxlength=\"5\" /><br>\n");
|
||||||
|
|
||||||
|
Map<String, String> options = new TreeMap(_manager.util().getI2CPOptions());
|
||||||
|
out.write("<tr><td>");
|
||||||
|
out.write(_("Inbound Settings"));
|
||||||
|
out.write(":<td>");
|
||||||
|
out.write(renderOptions(1, 6, options.remove("inbound.quantity"), "inbound.quantity", TUNNEL));
|
||||||
|
out.write(" ");
|
||||||
|
out.write(renderOptions(0, 4, options.remove("inbound.length"), "inbound.length", HOP));
|
||||||
|
out.write("<tr><td>");
|
||||||
|
out.write(_("Outbound Settings"));
|
||||||
|
out.write(":<td>");
|
||||||
|
out.write(renderOptions(1, 6, options.remove("outbound.quantity"), "outbound.quantity", TUNNEL));
|
||||||
|
out.write(" ");
|
||||||
|
out.write(renderOptions(0, 4, options.remove("outbound.length"), "outbound.length", HOP));
|
||||||
|
|
||||||
out.write("<tr><td>");
|
out.write("<tr><td>");
|
||||||
out.write(_("I2CP host"));
|
out.write(_("I2CP host"));
|
||||||
out.write(": <td><input type=\"text\" name=\"i2cpHost\" value=\""
|
out.write(": <td><input type=\"text\" name=\"i2cpHost\" value=\""
|
||||||
@ -993,7 +1024,6 @@ public class I2PSnarkServlet extends Default {
|
|||||||
+ _manager.util().getI2CPPort() + "\" size=\"5\" maxlength=\"5\" > <br>\n");
|
+ _manager.util().getI2CPPort() + "\" size=\"5\" maxlength=\"5\" > <br>\n");
|
||||||
|
|
||||||
StringBuilder opts = new StringBuilder(64);
|
StringBuilder opts = new StringBuilder(64);
|
||||||
Map options = new TreeMap(_manager.util().getI2CPOptions());
|
|
||||||
for (Iterator iter = options.entrySet().iterator(); iter.hasNext(); ) {
|
for (Iterator iter = options.entrySet().iterator(); iter.hasNext(); ) {
|
||||||
Map.Entry entry = (Map.Entry)iter.next();
|
Map.Entry entry = (Map.Entry)iter.next();
|
||||||
String key = (String)entry.getKey();
|
String key = (String)entry.getKey();
|
||||||
@ -1012,6 +1042,38 @@ public class I2PSnarkServlet extends Default {
|
|||||||
out.write("</form></div>");
|
out.write("</form></div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** copied from ConfigTunnelsHelper */
|
||||||
|
private static final String HOP = _x("hop");
|
||||||
|
private static final String TUNNEL = _x("tunnel");
|
||||||
|
/** dummies for translation */
|
||||||
|
private static final String HOPS = _x("hops");
|
||||||
|
private static final String TUNNELS = _x("tunnels");
|
||||||
|
|
||||||
|
/** modded from ConfigTunnelsHelper */
|
||||||
|
private String renderOptions(int min, int max, String strNow, String selName, String name) {
|
||||||
|
int now = 2;
|
||||||
|
try {
|
||||||
|
now = Integer.parseInt(strNow);
|
||||||
|
} catch (Throwable t) {}
|
||||||
|
StringBuilder buf = new StringBuilder(128);
|
||||||
|
buf.append("<select name=\"").append(selName).append("\">\n");
|
||||||
|
for (int i = min; i <= max; i++) {
|
||||||
|
buf.append("<option value=\"").append(i).append("\" ");
|
||||||
|
if (i == now)
|
||||||
|
buf.append("selected=\"true\" ");
|
||||||
|
String pname;
|
||||||
|
// pluralize and then translate
|
||||||
|
if (i != 1 && i != -1)
|
||||||
|
pname = name + 's';
|
||||||
|
else
|
||||||
|
pname = name;
|
||||||
|
buf.append(">").append(i).append(' ').append(_(pname));
|
||||||
|
buf.append("</option>\n");
|
||||||
|
}
|
||||||
|
buf.append("</select>\n");
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/** translate */
|
/** translate */
|
||||||
private String _(String s) {
|
private String _(String s) {
|
||||||
return _manager.util().getString(s);
|
return _manager.util().getString(s);
|
||||||
@ -1022,6 +1084,11 @@ public class I2PSnarkServlet extends Default {
|
|||||||
return _manager.util().getString(s, o);
|
return _manager.util().getString(s, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** dummy for tagging */
|
||||||
|
private static String _x(String s) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
// rounding makes us look faster :)
|
// rounding makes us look faster :)
|
||||||
private String formatSize(long bytes) {
|
private String formatSize(long bytes) {
|
||||||
if (bytes < 5*1024)
|
if (bytes < 5*1024)
|
||||||
|
Reference in New Issue
Block a user