2005-02-16 22:35:12 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Properties;
|
2008-07-16 13:42:54 +00:00
|
|
|
import java.util.Set;
|
|
|
|
|
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 {
|
2009-10-26 21:48:46 +00:00
|
|
|
static final String HOP = _x("hop");
|
|
|
|
static final String TUNNEL = _x("tunnel");
|
|
|
|
/** dummies for translation */
|
|
|
|
static final String HOPS = _x("hops");
|
|
|
|
static final String TUNNELS = _x("tunnels");
|
|
|
|
|
2005-02-16 22:35:12 +00:00
|
|
|
public ConfigTunnelsHelper() {}
|
|
|
|
|
|
|
|
public String getForm() {
|
2009-07-01 16:00:43 +00:00
|
|
|
StringBuilder buf = new StringBuilder(1024);
|
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();
|
|
|
|
|
|
|
|
buf.append("<input type=\"hidden\" name=\"pool.0\" value=\"exploratory\" >");
|
2009-10-26 10:53:53 +00:00
|
|
|
renderForm(buf, 0, "exploratory", _("Exploratory tunnels"), exploratoryIn, exploratoryOut);
|
2005-02-16 22:35:12 +00:00
|
|
|
|
|
|
|
int cur = 1;
|
|
|
|
Set clients = _context.clientManager().listClients();
|
|
|
|
for (Iterator iter = clients.iterator(); iter.hasNext(); ) {
|
|
|
|
Destination dest = (Destination)iter.next();
|
|
|
|
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);
|
|
|
|
buf.append("<input type=\"hidden\" name=\"pool.").append(cur).append("\" value=\"");
|
|
|
|
buf.append(dest.calculateHash().toBase64()).append("\" >");
|
2009-11-12 03:17:33 +00:00
|
|
|
renderForm(buf, cur, prefix, _("Client tunnels for") + " " + _(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;
|
2009-02-02 14:03:17 +00:00
|
|
|
private static final int WARN_QUANTITY = 5;
|
|
|
|
private static final int MAX_QUANTITY = 6;
|
|
|
|
private static final int MAX_BACKUP_QUANTITY = 3;
|
2008-11-09 15:59:35 +00:00
|
|
|
private static final int MAX_VARIANCE = 2;
|
|
|
|
private static final int MIN_NEG_VARIANCE = -1;
|
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
|
|
|
|
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>");
|
2009-02-02 14:03:17 +00:00
|
|
|
if (in.getQuantity() + in.getBackupQuantity() >= WARN_QUANTITY ||
|
|
|
|
out.getQuantity() + out.getBackupQuantity() >= 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
|
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();
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, 0, MAX_LENGTH, now, "", HOP);
|
2008-11-09 15:59:35 +00:00
|
|
|
if (now > MAX_LENGTH)
|
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();
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, 0, MAX_LENGTH, now, "", HOP);
|
2008-11-09 15:59:35 +00:00
|
|
|
if (now > MAX_LENGTH)
|
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
|
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();
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, 1, MAX_QUANTITY, now, "", TUNNEL);
|
2008-11-09 15:59:35 +00:00
|
|
|
if (now > MAX_QUANTITY)
|
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();
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, 1, MAX_QUANTITY, now, "", TUNNEL);
|
2008-11-09 15:59:35 +00:00
|
|
|
if (now > MAX_QUANTITY)
|
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
|
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();
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, 0, MAX_BACKUP_QUANTITY, now, "", TUNNEL);
|
2009-02-02 14:03:17 +00:00
|
|
|
if (now > MAX_BACKUP_QUANTITY)
|
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();
|
2009-10-26 21:48:46 +00:00
|
|
|
renderOptions(buf, 0, MAX_BACKUP_QUANTITY, now, "", TUNNEL);
|
2009-02-02 14:03:17 +00:00
|
|
|
if (now > MAX_BACKUP_QUANTITY)
|
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();
|
2009-08-20 15:43:27 +00:00
|
|
|
if (props.size() > 0) {
|
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);
|
|
|
|
buf.append(".inboundOptions\" type=\"text\" size=\"32\" disabled=\"true\" " +
|
|
|
|
"value=\"");
|
|
|
|
for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) {
|
|
|
|
String prop = (String)iter.next();
|
|
|
|
String val = (String)props.getProperty(prop);
|
|
|
|
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();
|
|
|
|
if (props.size() > 0) {
|
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);
|
|
|
|
buf.append(".outboundOptions\" type=\"text\" size=\"32\" disabled=\"true\" " +
|
|
|
|
"value=\"");
|
|
|
|
for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) {
|
|
|
|
String prop = (String)iter.next();
|
|
|
|
String val = (String)props.getProperty(prop);
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
buf.append("selected=\"true\" ");
|
2009-10-26 21:48:46 +00:00
|
|
|
String pname;
|
|
|
|
// pluralize and then translate
|
2008-11-09 15:59:35 +00:00
|
|
|
if (i != 1 && i != -1)
|
2009-10-26 21:48:46 +00:00
|
|
|
pname = name + 's';
|
|
|
|
else
|
|
|
|
pname = name;
|
|
|
|
buf.append(">").append(prefix).append(i).append(' ').append(_(pname));
|
2008-11-09 15:59:35 +00:00
|
|
|
buf.append("</option>\n");
|
|
|
|
}
|
|
|
|
}
|
2005-02-16 22:35:12 +00:00
|
|
|
}
|