2005-02-16 22:35:12 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
|
|
|
import java.util.Properties;
|
2008-07-16 13:42:54 +00:00
|
|
|
import java.util.Set;
|
|
|
|
|
2014-08-23 13:44:56 +00:00
|
|
|
import net.i2p.data.DataHelper;
|
2005-02-16 22:35:12 +00:00
|
|
|
import net.i2p.data.Destination;
|
|
|
|
import net.i2p.router.TunnelPoolSettings;
|
|
|
|
|
2009-01-29 02:16:18 +00:00
|
|
|
public class ConfigTunnelsHelper extends HelperBase {
|
2010-05-27 00:38:32 +00:00
|
|
|
private static final String HOP = "hop";
|
|
|
|
private static final String TUNNEL = "tunnel";
|
2009-10-26 21:48:46 +00:00
|
|
|
/** dummies for translation */
|
2010-05-27 00:38:32 +00:00
|
|
|
private static final String HOPS = ngettext("1 hop", "{0} hops");
|
|
|
|
private static final String TUNNELS = ngettext("1 tunnel", "{0} tunnels");
|
2009-10-26 21:48:46 +00:00
|
|
|
|
2005-02-16 22:35:12 +00:00
|
|
|
public String getForm() {
|
2009-07-01 16:00:43 +00:00
|
|
|
StringBuilder buf = new StringBuilder(1024);
|
2011-03-12 17:32:15 +00:00
|
|
|
// HTML: <input> cannot be inside a <table>
|
|
|
|
buf.append("<input type=\"hidden\" name=\"pool.0\" value=\"exploratory\" >\n");
|
|
|
|
int cur = 1;
|
|
|
|
Set<Destination> clients = _context.clientManager().listClients();
|
|
|
|
for (Destination dest : clients) {
|
|
|
|
buf.append("<input type=\"hidden\" name=\"pool.").append(cur).append("\" value=\"");
|
|
|
|
buf.append(dest.calculateHash().toBase64()).append("\" >\n");
|
|
|
|
cur++;
|
|
|
|
}
|
|
|
|
|
2009-07-28 13:06:19 +00:00
|
|
|
buf.append("<table>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
TunnelPoolSettings exploratoryIn = _context.tunnelManager().getInboundSettings();
|
|
|
|
TunnelPoolSettings exploratoryOut = _context.tunnelManager().getOutboundSettings();
|
|
|
|
|
2009-10-26 10:53:53 +00:00
|
|
|
renderForm(buf, 0, "exploratory", _("Exploratory tunnels"), exploratoryIn, exploratoryOut);
|
2005-02-16 22:35:12 +00:00
|
|
|
|
2011-03-12 17:32:15 +00:00
|
|
|
cur = 1;
|
|
|
|
for (Destination dest : clients) {
|
2005-02-16 22:35:12 +00:00
|
|
|
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(dest.calculateHash());
|
|
|
|
TunnelPoolSettings out = _context.tunnelManager().getOutboundSettings(dest.calculateHash());
|
|
|
|
|
2005-02-21 18:02:14 +00:00
|
|
|
if ( (in == null) || (out == null) ) continue;
|
|
|
|
|
|
|
|
String name = in.getDestinationNickname();
|
2005-02-16 22:35:12 +00:00
|
|
|
if (name == null)
|
2005-02-21 18:02:14 +00:00
|
|
|
name = out.getDestinationNickname();
|
2005-02-16 22:35:12 +00:00
|
|
|
if (name == null)
|
|
|
|
name = dest.calculateHash().toBase64().substring(0,6);
|
|
|
|
|
|
|
|
String prefix = dest.calculateHash().toBase64().substring(0,4);
|
2014-08-23 13:44:56 +00:00
|
|
|
renderForm(buf, cur, prefix, _("Client tunnels for {0}", DataHelper.escapeHTML(_(name))), in, out);
|
2005-02-16 22:35:12 +00:00
|
|
|
cur++;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf.append("</table>\n");
|
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
|
2008-11-09 15:59:35 +00:00
|
|
|
private static final int WARN_LENGTH = 4;
|
|
|
|
private static final int MAX_LENGTH = 4;
|
2013-05-31 23:28:41 +00:00
|
|
|
private static final int MAX_ADVANCED_LENGTH = 7;
|
2009-02-02 14:03:17 +00:00
|
|
|
private static final int WARN_QUANTITY = 5;
|
|
|
|
private static final int MAX_QUANTITY = 6;
|
2013-05-31 23:28:41 +00:00
|
|
|
private static final int MAX_ADVANCED_QUANTITY = 16;
|
2009-02-02 14:03:17 +00:00
|
|
|
private static final int MAX_BACKUP_QUANTITY = 3;
|
2013-05-31 23:28:41 +00:00
|
|
|
private static final int MAX_ADVANCED_BACKUP_QUANTITY = 16;
|
2008-11-09 15:59:35 +00:00
|
|
|
private static final int MAX_VARIANCE = 2;
|
|
|
|
private static final int MIN_NEG_VARIANCE = -1;
|
2011-10-25 21:39:32 +00:00
|
|
|
|
2009-07-01 16:00:43 +00:00
|
|
|
private void renderForm(StringBuilder buf, int index, String prefix, String name, TunnelPoolSettings in, TunnelPoolSettings out) {
|
2005-02-16 22:35:12 +00:00
|
|
|
|
2013-10-04 19:06:39 +00:00
|
|
|
boolean advanced = isAdvanced();
|
2013-05-31 23:28:41 +00:00
|
|
|
|
2009-06-24 18:47:17 +00:00
|
|
|
buf.append("<tr><th colspan=\"3\"><a name=\"").append(prefix).append("\">");
|
|
|
|
buf.append(name).append("</a></th></tr>\n");
|
2008-06-04 16:03:34 +00:00
|
|
|
if (in.getLength() <= 0 ||
|
|
|
|
in.getLength() + in.getLengthVariance() <= 0 ||
|
|
|
|
out.getLength() <= 0 ||
|
|
|
|
out.getLength() + out.getLengthVariance() <= 0)
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<tr><th colspan=\"3\"><font color=\"red\">" + _("ANONYMITY WARNING - Settings include 0-hop tunnels.") + "</font></th></tr>");
|
2009-05-13 19:20:49 +00:00
|
|
|
else if (in.getLength() <= 1 ||
|
|
|
|
in.getLength() + in.getLengthVariance() <= 1 ||
|
|
|
|
out.getLength() <= 1 ||
|
|
|
|
out.getLength() + out.getLengthVariance() <= 1)
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<tr><th colspan=\"3\"><font color=\"red\">" + _("ANONYMITY WARNING - Settings include 1-hop tunnels.") + "</font></th></tr>");
|
2008-06-04 16:03:34 +00:00
|
|
|
if (in.getLength() + Math.abs(in.getLengthVariance()) >= WARN_LENGTH ||
|
|
|
|
out.getLength() + Math.abs(out.getLengthVariance()) >= WARN_LENGTH)
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<tr><th colspan=\"3\"><font color=\"red\">" + _("PERFORMANCE WARNING - Settings include very long tunnels.") + "</font></th></tr>");
|
2011-10-25 21:39:32 +00:00
|
|
|
if (in.getTotalQuantity() >= WARN_QUANTITY ||
|
|
|
|
out.getTotalQuantity() >= WARN_QUANTITY)
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<tr><th colspan=\"3\"><font color=\"red\">" + _("PERFORMANCE WARNING - Settings include high tunnel quantities.") + "</font></th></tr>");
|
2008-06-04 16:03:34 +00:00
|
|
|
|
2009-10-26 21:48:46 +00:00
|
|
|
buf.append("<tr><th></th><th><img src=\"/themes/console/images/inbound.png\" alt=\"Inbound\" title=\"Inbound Tunnels\"> " + _("Inbound") + "</th><th><img src=\"/themes/console/images/outbound.png\" alt=\"Outbound Tunnels\" title=\"Outbound\"> " + _("Outbound") + "</th></tr>\n");
|
2008-06-04 16:03:34 +00:00
|
|
|
|
2009-07-22 21:07:46 +00:00
|
|
|
// buf.append("<tr><th></th><th>Inbound</th><th>Outbound</th></tr>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
|
|
|
|
// tunnel depth
|
2013-05-31 23:28:41 +00:00
|
|
|
int maxLength = advanced ? MAX_ADVANCED_LENGTH : MAX_LENGTH;
|
2009-12-07 21:25:27 +00:00
|
|
|
buf.append("<tr><td align=\"right\" class=\"mediumtags\">" + _("Length") + ":</td>\n");
|
2009-07-22 21:07:46 +00:00
|
|
|
buf.append("<td align=\"center\"><select name=\"").append(index).append(".depthInbound\">\n");
|
2008-11-09 15:59:35 +00:00
|
|
|
int now = in.getLength();
|
2013-05-31 23:28:41 +00:00
|
|
|
renderOptions(buf, 0, maxLength, now, "", HOP);
|
|
|
|
if (now > maxLength)
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, now, now, now, "", HOP);
|
2008-11-21 16:29:16 +00:00
|
|
|
buf.append("</select></td>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
|
2009-07-22 21:07:46 +00:00
|
|
|
buf.append("<td align=\"center\"><select name=\"").append(index).append(".depthOutbound\">\n");
|
2008-11-09 15:59:35 +00:00
|
|
|
now = out.getLength();
|
2013-05-31 23:28:41 +00:00
|
|
|
renderOptions(buf, 0, maxLength, now, "", HOP);
|
|
|
|
if (now > maxLength)
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, now, now, now, "", HOP);
|
2008-11-21 16:29:16 +00:00
|
|
|
buf.append("</select></td>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
buf.append("</tr>\n");
|
|
|
|
|
|
|
|
// tunnel depth variance
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<tr><td align=\"right\" class=\"mediumtags\">" + _("Randomization") + ":</td>\n");
|
2009-07-22 21:07:46 +00:00
|
|
|
buf.append("<td align=\"center\"><select name=\"").append(index).append(".varianceInbound\">\n");
|
2008-11-09 15:59:35 +00:00
|
|
|
now = in.getLengthVariance();
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, 0, 0, now, "", HOP);
|
|
|
|
renderOptions(buf, 1, MAX_VARIANCE, now, "+ 0-", HOP);
|
|
|
|
renderOptions(buf, MIN_NEG_VARIANCE, -1, now, "+/- 0", HOP);
|
2008-11-09 15:59:35 +00:00
|
|
|
if (now > MAX_VARIANCE)
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, now, now, now, "+ 0-", HOP);
|
2008-11-09 15:59:35 +00:00
|
|
|
else if (now < MIN_NEG_VARIANCE)
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, now, now, now, "+/- 0", HOP);
|
2008-11-21 16:29:16 +00:00
|
|
|
buf.append("</select></td>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
|
2009-07-22 21:07:46 +00:00
|
|
|
buf.append("<td align=\"center\"><select name=\"").append(index).append(".varianceOutbound\">\n");
|
2008-11-09 15:59:35 +00:00
|
|
|
now = out.getLengthVariance();
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, 0, 0, now, "", HOP);
|
|
|
|
renderOptions(buf, 1, MAX_VARIANCE, now, "+ 0-", HOP);
|
|
|
|
renderOptions(buf, MIN_NEG_VARIANCE, -1, now, "+/- 0", HOP);
|
2008-11-09 15:59:35 +00:00
|
|
|
if (now > MAX_VARIANCE)
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, now, now, now, "+ 0-", HOP);
|
2008-11-09 15:59:35 +00:00
|
|
|
else if (now < MIN_NEG_VARIANCE)
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, now, now, now, "+/- 0", HOP);
|
2008-11-21 16:29:16 +00:00
|
|
|
buf.append("</select></td>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
|
|
|
|
// tunnel quantity
|
2013-05-31 23:28:41 +00:00
|
|
|
int maxQuantity = advanced ? MAX_ADVANCED_QUANTITY : MAX_QUANTITY;
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<tr><td align=\"right\" class=\"mediumtags\">" + _("Quantity") + ":</td>\n");
|
2009-07-22 21:07:46 +00:00
|
|
|
buf.append("<td align=\"center\"><select name=\"").append(index).append(".quantityInbound\">\n");
|
2008-11-09 15:59:35 +00:00
|
|
|
now = in.getQuantity();
|
2013-05-31 23:28:41 +00:00
|
|
|
renderOptions(buf, 1, maxQuantity, now, "", TUNNEL);
|
|
|
|
if (now > maxQuantity)
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, now, now, now, "", TUNNEL);
|
2008-11-21 16:29:16 +00:00
|
|
|
buf.append("</select></td>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
|
2009-07-22 21:07:46 +00:00
|
|
|
buf.append("<td align=\"center\"><select name=\"").append(index).append(".quantityOutbound\">\n");
|
2008-11-09 15:59:35 +00:00
|
|
|
now = out.getQuantity();
|
2013-05-31 23:28:41 +00:00
|
|
|
renderOptions(buf, 1, maxQuantity, now, "", TUNNEL);
|
|
|
|
if (now > maxQuantity)
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, now, now, now, "", TUNNEL);
|
2008-11-21 16:29:16 +00:00
|
|
|
buf.append("</select></td>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
buf.append("</tr>\n");
|
|
|
|
|
|
|
|
// tunnel backup quantity
|
2013-05-31 23:28:41 +00:00
|
|
|
int maxBQuantity = advanced ? MAX_ADVANCED_BACKUP_QUANTITY : MAX_BACKUP_QUANTITY;
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<tr><td align=\"right\" class=\"mediumtags\">" + _("Backup quantity") + ":</td>\n");
|
2009-07-22 21:07:46 +00:00
|
|
|
buf.append("<td align=\"center\"><select name=\"").append(index).append(".backupInbound\">\n");
|
2008-11-09 15:59:35 +00:00
|
|
|
now = in.getBackupQuantity();
|
2013-05-31 23:28:41 +00:00
|
|
|
renderOptions(buf, 0, maxBQuantity, now, "", TUNNEL);
|
|
|
|
if (now > maxBQuantity)
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, now, now, now, "", TUNNEL);
|
2008-11-21 16:29:16 +00:00
|
|
|
buf.append("</select></td>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
|
2009-07-22 21:07:46 +00:00
|
|
|
buf.append("<td align=\"center\"><select name=\"").append(index).append(".backupOutbound\">\n");
|
2009-01-05 15:11:00 +00:00
|
|
|
now = out.getBackupQuantity();
|
2013-05-31 23:28:41 +00:00
|
|
|
renderOptions(buf, 0, maxBQuantity, now, "", TUNNEL);
|
|
|
|
if (now > maxBQuantity)
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, now, now, now, "", TUNNEL);
|
2008-11-21 16:29:16 +00:00
|
|
|
buf.append("</select></td>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
buf.append("</tr>\n");
|
|
|
|
|
|
|
|
// custom options
|
2009-08-20 15:43:27 +00:00
|
|
|
// There is no facility to set these, either in ConfigTunnelsHandler or
|
|
|
|
// TunnelPoolOptions, so make the boxes readonly.
|
|
|
|
// And let's not display them at all unless they have contents, which should be rare.
|
2005-02-16 22:35:12 +00:00
|
|
|
Properties props = in.getUnknownOptions();
|
2010-05-05 16:51:54 +00:00
|
|
|
if (!props.isEmpty()) {
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<tr><td align=\"right\" class=\"mediumtags\">" + _("Inbound options") + ":</td>\n" +
|
2009-08-20 15:43:27 +00:00
|
|
|
"<td colspan=\"2\" align=\"center\"><input name=\"").append(index);
|
2012-03-02 22:32:45 +00:00
|
|
|
buf.append(".inboundOptions\" type=\"text\" size=\"32\" disabled=\"disabled\" " +
|
2009-08-20 15:43:27 +00:00
|
|
|
"value=\"");
|
2015-04-24 16:27:03 +00:00
|
|
|
for (String prop : props.stringPropertyNames()) {
|
2012-03-25 20:42:41 +00:00
|
|
|
String val = props.getProperty(prop);
|
2009-08-20 15:43:27 +00:00
|
|
|
buf.append(prop).append('=').append(val).append(' ');
|
|
|
|
}
|
|
|
|
buf.append("\"></td></tr>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
}
|
2009-08-20 15:43:27 +00:00
|
|
|
props = out.getUnknownOptions();
|
2010-05-05 16:51:54 +00:00
|
|
|
if (!props.isEmpty()) {
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<tr><td align=\"right\" class=\"mediumtags\">" + _("Outbound options") + ":</td>\n" +
|
2009-08-20 15:43:27 +00:00
|
|
|
"<td colspan=\"2\" align=\"center\"><input name=\"").append(index);
|
2012-03-02 22:32:45 +00:00
|
|
|
buf.append(".outboundOptions\" type=\"text\" size=\"32\" disabled=\"disabled\" " +
|
2009-08-20 15:43:27 +00:00
|
|
|
"value=\"");
|
2015-04-24 16:27:03 +00:00
|
|
|
for (String prop : props.stringPropertyNames()) {
|
2012-03-25 20:42:41 +00:00
|
|
|
String val = props.getProperty(prop);
|
2009-08-20 15:43:27 +00:00
|
|
|
buf.append(prop).append('=').append(val).append(' ');
|
|
|
|
}
|
|
|
|
buf.append("\"></td></tr>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
}
|
2009-08-15 16:08:33 +00:00
|
|
|
// buf.append("<tr><td colspan=\"3\"><br></td></tr>\n");
|
2005-02-16 22:35:12 +00:00
|
|
|
}
|
2008-11-09 15:59:35 +00:00
|
|
|
|
2011-03-12 21:32:29 +00:00
|
|
|
/** to fool xgettext so the following isn't tagged */
|
|
|
|
private static final String DUMMY1 = "1 ";
|
|
|
|
private static final String DUMMY2 = "{0} ";
|
|
|
|
|
2009-07-01 16:00:43 +00:00
|
|
|
private void renderOptions(StringBuilder buf, int min, int max, int now, String prefix, String name) {
|
2008-11-09 15:59:35 +00:00
|
|
|
for (int i = min; i <= max; i++) {
|
|
|
|
buf.append("<option value=\"").append(i).append("\" ");
|
|
|
|
if (i == now)
|
2012-03-02 22:32:45 +00:00
|
|
|
buf.append("selected=\"selected\" ");
|
2011-03-12 21:32:29 +00:00
|
|
|
buf.append(">").append(ngettext(DUMMY1 + name, DUMMY2 + name + 's', i));
|
2008-11-09 15:59:35 +00:00
|
|
|
buf.append("</option>\n");
|
|
|
|
}
|
|
|
|
}
|
2010-05-27 00:38:32 +00:00
|
|
|
|
|
|
|
/** dummy for tagging */
|
|
|
|
private static String ngettext(String s, String p) {
|
|
|
|
return null;
|
|
|
|
}
|
2005-02-16 22:35:12 +00:00
|
|
|
}
|