package net.i2p.router.web; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.List; import java.util.Iterator; import java.util.Set; import java.util.Properties; import java.util.TreeMap; import net.i2p.util.Log; import net.i2p.data.Destination; import net.i2p.router.RouterContext; import net.i2p.router.TunnelPoolSettings; public class ConfigTunnelsHelper { private RouterContext _context; /** * Configure this bean to query a particular router context * * @param contextId begging few characters of the routerHash, or null to pick * the first one we come across. */ public void setContextId(String contextId) { try { _context = ContextHelper.getContext(contextId); } catch (Throwable t) { t.printStackTrace(); } } public ConfigTunnelsHelper() {} public String getForm() { StringBuffer buf = new StringBuffer(1024); buf.append("\n"); TunnelPoolSettings exploratoryIn = _context.tunnelManager().getInboundSettings(); TunnelPoolSettings exploratoryOut = _context.tunnelManager().getOutboundSettings(); buf.append(""); renderForm(buf, 0, "exploratory", "Exploratory tunnels", exploratoryIn, exploratoryOut); 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()); String name = (in != null ? in.getDestinationNickname() : null); if (name == null) name = (out != null ? out.getDestinationNickname() : null); if (name == null) name = dest.calculateHash().toBase64().substring(0,6); String prefix = dest.calculateHash().toBase64().substring(0,4); buf.append(""); renderForm(buf, cur, prefix, "Client tunnels for " + name, in, out); cur++; } buf.append("
\n"); return buf.toString(); } private void renderForm(StringBuffer buf, int index, String prefix, String name, TunnelPoolSettings in, TunnelPoolSettings out) { buf.append(""); buf.append(name).append("\n"); buf.append("InboundOutbound\n"); // tunnel depth buf.append("Depth\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); if (out.getLength() > 3) buf.append("\n"); buf.append("\n"); buf.append("\n"); // tunnel depth variance buf.append("Variance\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); if (out.getLengthVariance() < -2) buf.append("\n"); if (out.getLengthVariance() > 2) buf.append("\n"); buf.append("\n"); // tunnel quantity buf.append("Quantity\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); if (out.getQuantity() > 3) 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"); buf.append("\n"); buf.append("\n"); if (out.getBackupQuantity() > 3) buf.append("\n"); buf.append("\n"); buf.append("\n"); // custom options buf.append("Inbound options:\n"); buf.append("\n"); buf.append("Outbound options:\n"); buf.append("\n"); buf.append("
\n"); } }