package net.i2p.router.web; import java.util.Iterator; import java.util.Properties; import java.util.Set; import net.i2p.data.Destination; import net.i2p.router.TunnelPoolSettings; public class ConfigTunnelsHelper extends HelperBase { private static final String HOP = "hop"; private static final String TUNNEL = "tunnel"; /** dummies for translation */ private static final String HOPS = ngettext("1 hop", "{0} hops"); private static final String TUNNELS = ngettext("1 tunnel", "{0} tunnels"); public ConfigTunnelsHelper() {} public String getForm() { StringBuilder buf = new StringBuilder(1024); // HTML: cannot be inside a buf.append("\n"); int cur = 1; Set clients = _context.clientManager().listClients(); for (Destination dest : clients) { buf.append("\n"); cur++; } buf.append("
\n"); TunnelPoolSettings exploratoryIn = _context.tunnelManager().getInboundSettings(); TunnelPoolSettings exploratoryOut = _context.tunnelManager().getOutboundSettings(); renderForm(buf, 0, "exploratory", _("Exploratory tunnels"), exploratoryIn, exploratoryOut); cur = 1; for (Destination dest : clients) { TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(dest.calculateHash()); TunnelPoolSettings out = _context.tunnelManager().getOutboundSettings(dest.calculateHash()); if ( (in == null) || (out == null) ) continue; String name = in.getDestinationNickname(); if (name == null) name = out.getDestinationNickname(); if (name == null) name = dest.calculateHash().toBase64().substring(0,6); String prefix = dest.calculateHash().toBase64().substring(0,4); renderForm(buf, cur, prefix, _("Client tunnels for {0}", _(name)), in, out); cur++; } buf.append("
\n"); return buf.toString(); } private static final int WARN_LENGTH = 4; private static final int MAX_LENGTH = 4; private static final int WARN_QUANTITY = 5; private static final int MAX_QUANTITY = 6; private static final int MAX_BACKUP_QUANTITY = 3; private static final int MAX_VARIANCE = 2; private static final int MIN_NEG_VARIANCE = -1; private void renderForm(StringBuilder buf, int index, String prefix, String name, TunnelPoolSettings in, TunnelPoolSettings out) { buf.append(""); buf.append(name).append("\n"); if (in.getLength() <= 0 || in.getLength() + in.getLengthVariance() <= 0 || out.getLength() <= 0 || out.getLength() + out.getLengthVariance() <= 0) buf.append("" + _("ANONYMITY WARNING - Settings include 0-hop tunnels.") + ""); else if (in.getLength() <= 1 || in.getLength() + in.getLengthVariance() <= 1 || out.getLength() <= 1 || out.getLength() + out.getLengthVariance() <= 1) buf.append("" + _("ANONYMITY WARNING - Settings include 1-hop tunnels.") + ""); if (in.getLength() + Math.abs(in.getLengthVariance()) >= WARN_LENGTH || out.getLength() + Math.abs(out.getLengthVariance()) >= WARN_LENGTH) buf.append("" + _("PERFORMANCE WARNING - Settings include very long tunnels.") + ""); if (in.getQuantity() + in.getBackupQuantity() >= WARN_QUANTITY || out.getQuantity() + out.getBackupQuantity() >= WARN_QUANTITY) buf.append("" + _("PERFORMANCE WARNING - Settings include high tunnel quantities.") + ""); buf.append("\"Inbound\"  " + _("Inbound") + "\"Outbound  " + _("Outbound") + "\n"); // buf.append("InboundOutbound\n"); // tunnel depth buf.append("" + _("Length") + ":\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); // tunnel depth variance buf.append("" + _("Randomization") + ":\n"); buf.append("\n"); buf.append("\n"); // tunnel quantity buf.append("" + _("Quantity") + ":\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); // tunnel backup quantity buf.append("" + _("Backup quantity") + ":\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); // custom options // 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. Properties props = in.getUnknownOptions(); if (!props.isEmpty()) { buf.append("" + _("Inbound options") + ":\n" + "\n"); } props = out.getUnknownOptions(); if (!props.isEmpty()) { buf.append("" + _("Outbound options") + ":\n" + "\n"); } // buf.append("
\n"); } /** to fool xgettext so the following isn't tagged */ private static final String DUMMY1 = "1 "; private static final String DUMMY2 = "{0} "; private void renderOptions(StringBuilder buf, int min, int max, int now, String prefix, String name) { for (int i = min; i <= max; i++) { buf.append("\n"); } } /** dummy for tagging */ private static String ngettext(String s, String p) { return null; } }