continuing 0.5 merges

This commit is contained in:
jrandom
2005-02-16 22:35:12 +00:00
committed by zzz
parent 566a713baa
commit 9646ac2911
5 changed files with 451 additions and 228 deletions

View File

@@ -1,84 +0,0 @@
package net.i2p.router.web;
import net.i2p.router.ClientTunnelSettings;
/**
* Handler to deal with form submissions from the client config form and act
* upon the values.
*
*/
public class ConfigClientsHandler extends FormHandler {
private String _numClients;
private String _numTunnels;
private String _numHops;
private String _numHopsOutbound;
private boolean _shouldSave;
public void ConfigNetHandler() {
_shouldSave = false;
}
protected void processForm() {
if (_shouldSave) {
saveChanges();
} else {
// noop
}
}
public void setShouldsave(String moo) { _shouldSave = true; }
public void setClientcount(String num) {
_numClients = (num != null ? num.trim(): null);
}
public void setTunnelcount(String num) {
_numTunnels = (num != null ? num.trim() : null);
}
public void setTunneldepth(String num) {
_numHops = (num != null ? num.trim() : null);
}
public void setTunneldepthoutbound(String num) {
_numHopsOutbound = (num != null ? num.trim() : null);
}
/**
* The user made changes to the network config and wants to save them, so
* lets go ahead and do so.
*
*/
private void saveChanges() {
boolean saveRequired = false;
if ( (_numClients != null) && (_numClients.length() > 0) ) {
_context.router().setConfigSetting("router.targetClients", _numClients);
addFormNotice("Updating estimated number of clients to " + _numClients);
saveRequired = true;
}
if ( (_numTunnels != null) && (_numTunnels.length() > 0) ) {
_context.router().setConfigSetting(ClientTunnelSettings.PROP_NUM_INBOUND, _numTunnels);
addFormNotice("Updating default number of tunnels per client to " + _numTunnels);
saveRequired = true;
}
if ( (_numHops != null) && (_numHops.length() > 0) ) {
_context.router().setConfigSetting(ClientTunnelSettings.PROP_DEPTH_INBOUND, _numHops);
addFormNotice("Updating default tunnel length to " + _numHops);
saveRequired = true;
}
if ( (_numHopsOutbound != null) && (_numHopsOutbound.length() > 0) ) {
_context.router().setConfigSetting(ClientTunnelSettings.PROP_DEPTH_OUTBOUND, _numHopsOutbound);
addFormNotice("Updating default outbound tunnel length to " + _numHopsOutbound);
saveRequired = true;
}
if (saveRequired) {
boolean saved = _context.router().saveConfig();
if (saved)
addFormNotice("Configuration saved successfully");
else
addFormNotice("Error saving the configuration (applied but not saved) - please see the error logs");
}
}
}

View File

@@ -1,144 +0,0 @@
package net.i2p.router.web;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Iterator;
import java.util.TreeMap;
import net.i2p.util.Log;
import net.i2p.router.RouterContext;
import net.i2p.router.ClientTunnelSettings;
public class ConfigClientsHelper {
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();
}
}
/** copied from the package private {@link net.i2p.router.tunnelmanager.TunnelPool} */
public final static String TARGET_CLIENTS_PARAM = "router.targetClients";
/** copied from the package private {@link net.i2p.router.tunnelmanager.TunnelPool} */
public final static int TARGET_CLIENTS_DEFAULT = 3;
public ConfigClientsHelper() {}
public String getClientCountSelectBox() {
int count = TARGET_CLIENTS_DEFAULT;
String val = _context.router().getConfigSetting(TARGET_CLIENTS_PARAM);
if (val != null) {
try {
count = Integer.parseInt(val);
} catch (NumberFormatException nfe) {
// ignore, use default from above
}
}
StringBuffer buf = new StringBuffer(1024);
buf.append("<select name=\"clientcount\">\n");
for (int i = 0; i < 5; i++) {
buf.append("<option value=\"").append(i).append("\" ");
if (count == i)
buf.append("selected=\"true\" ");
buf.append(">").append(i).append("</option>\n");
}
if (count >= 5) {
buf.append("<option value=\"").append(count);
buf.append("\" selected>").append(count);
buf.append("</option>\n");
}
buf.append("</select>\n");
return buf.toString();
}
public String getTunnelCountSelectBox() {
int count = ClientTunnelSettings.DEFAULT_NUM_INBOUND;
String val = _context.router().getConfigSetting(ClientTunnelSettings.PROP_NUM_INBOUND);
if (val != null) {
try {
count = Integer.parseInt(val);
} catch (NumberFormatException nfe) {
// ignore, use default from above
}
}
StringBuffer buf = new StringBuffer(1024);
buf.append("<select name=\"tunnelcount\">\n");
for (int i = 0; i < 4; i++) {
buf.append("<option value=\"").append(i).append("\" ");
if (count == i)
buf.append("selected=\"true\" ");
buf.append(">").append(i).append("</option>\n");
}
if (count >= 4) {
buf.append("<option value=\"").append(count);
buf.append("\" selected>").append(count);
buf.append("</option>\n");
}
buf.append("</select>\n");
return buf.toString();
}
public String getTunnelDepthSelectBox() {
int count = ClientTunnelSettings.DEFAULT_DEPTH_INBOUND;
String val = _context.router().getConfigSetting(ClientTunnelSettings.PROP_DEPTH_INBOUND);
if (val != null) {
try {
count = Integer.parseInt(val);
} catch (NumberFormatException nfe) {
// ignore, use default from above
}
}
StringBuffer buf = new StringBuffer(1024);
buf.append("<select name=\"tunneldepth\">\n");
for (int i = 0; i < 4; i++) {
buf.append("<option value=\"").append(i).append("\" ");
if (count == i)
buf.append("selected=\"true\" ");
buf.append(">").append(i).append("</option>\n");
}
if (count >= 4) {
buf.append("<option value=\"").append(count);
buf.append("\" selected>").append(count);
buf.append("</option>\n");
}
buf.append("</select>\n");
return buf.toString();
}
public String getTunnelDepthOutboundSelectBox() {
int count = ClientTunnelSettings.DEFAULT_DEPTH_OUTBOUND;
String val = _context.router().getConfigSetting(ClientTunnelSettings.PROP_DEPTH_OUTBOUND);
if (val != null) {
try {
count = Integer.parseInt(val);
} catch (NumberFormatException nfe) {
// ignore, use default from above
}
}
StringBuffer buf = new StringBuffer(1024);
buf.append("<select name=\"tunneldepthoutbound\">\n");
for (int i = 0; i < 4; i++) {
buf.append("<option value=\"").append(i).append("\" ");
if (count == i)
buf.append("selected=\"true\" ");
buf.append(">").append(i).append("</option>\n");
}
if (count >= 4) {
buf.append("<option value=\"").append(count);
buf.append("\" selected>").append(count);
buf.append("</option>\n");
}
buf.append("</select>\n");
return buf.toString();
}
}

View File

@@ -0,0 +1,154 @@
package net.i2p.router.web;
import java.util.HashMap;
import java.util.Map;
import net.i2p.data.Hash;
import net.i2p.data.DataFormatException;
import net.i2p.util.Log;
import net.i2p.router.TunnelPoolSettings;
/**
* Handler to deal with form submissions from the tunnel config form and act
* upon the values. Holy crap, this is UUUUGLY
*
*/
public class ConfigTunnelsHandler extends FormHandler {
private Log _log;
private Map _settings;
private boolean _shouldSave;
public ConfigTunnelsHandler() {
_shouldSave = false;
}
protected void processForm() {
if (_shouldSave) {
saveChanges();
} else {
// noop
}
}
public void setShouldsave(String moo) {
if ( (moo != null) && (moo.equals("Save changes")) )
_shouldSave = true;
}
public void setSettings(Map settings) { _settings = new HashMap(settings); }
/**
* The user made changes to the network config and wants to save them, so
* lets go ahead and do so.
*
*/
private void saveChanges() {
_log = _context.logManager().getLog(ConfigTunnelsHandler.class);
boolean saveRequired = false;
if (_log.shouldLog(Log.DEBUG))
_log.debug("Saving changes, with props = " + _settings);
int updated = 0;
int index = 0;
while (true) {
Object val = _settings.get("pool." + index);
if (val == null) break;
Hash client = new Hash();
String poolName = (val instanceof String ? (String)val : ((String[])val)[0]);
TunnelPoolSettings in = null;
TunnelPoolSettings out = null;
if ("exploratory".equals(poolName)) {
in = _context.tunnelManager().getInboundSettings();
out = _context.tunnelManager().getOutboundSettings();
} else {
try {
client.fromBase64(poolName);
} catch (DataFormatException dfe) {
addFormError("Internal error (pool name could not resolve - " + poolName + ")");
index++;
continue;
}
in = _context.tunnelManager().getInboundSettings(client);
out = _context.tunnelManager().getOutboundSettings(client);
}
if ( (in == null) || (out == null) ) {
addFormError("Internal error (pool settings cound not be fuond for " + poolName + ")");
index++;
continue;
}
in.setLength(getInt(_settings.get(index + ".depthInbound")));
out.setLength(getInt(_settings.get(index + ".depthOutbound")));
in.setLengthVariance(getInt(_settings.get(index + ".varianceInbound")));
out.setLengthVariance(getInt(_settings.get(index + ".varianceOutbound")));
in.setQuantity(getInt(_settings.get(index + ".quantityInbound")));
out.setQuantity(getInt(_settings.get(index + ".quantityOutbound")));
in.setBackupQuantity(getInt(_settings.get(index + ".backupInbound")));
out.setBackupQuantity(getInt(_settings.get(index + ".backupOutbound")));
if ("exploratory".equals(poolName)) {
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
TunnelPoolSettings.PROP_LENGTH, in.getLength()+"");
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
TunnelPoolSettings.PROP_LENGTH, out.getLength()+"");
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
TunnelPoolSettings.PROP_LENGTH_VARIANCE, in.getLengthVariance()+"");
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
TunnelPoolSettings.PROP_LENGTH_VARIANCE, out.getLengthVariance()+"");
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
TunnelPoolSettings.PROP_QUANTITY, in.getQuantity()+"");
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
TunnelPoolSettings.PROP_QUANTITY, out.getQuantity()+"");
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
TunnelPoolSettings.PROP_BACKUP_QUANTITY, in.getBackupQuantity()+"");
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
TunnelPoolSettings.PROP_BACKUP_QUANTITY, out.getBackupQuantity()+"");
}
if ("exploratory".equals(poolName)) {
if (_log.shouldLog(Log.DEBUG)) {
_log.debug("Inbound exploratory settings: " + in);
_log.debug("Outbound exploratory settings: " + out);
}
_context.tunnelManager().setInboundSettings(in);
_context.tunnelManager().setOutboundSettings(out);
} else {
if (_log.shouldLog(Log.DEBUG)) {
_log.debug("Inbound settings for " + client.toBase64() + ": " + in);
_log.debug("Outbound settings for " + client.toBase64() + ": " + out);
}
_context.tunnelManager().setInboundSettings(client, in);
_context.tunnelManager().setOutboundSettings(client, out);
}
updated++;
saveRequired = true;
index++;
}
if (updated > 0)
addFormNotice("Updated settings for " + updated + " pools");
if (saveRequired) {
boolean saved = _context.router().saveConfig();
if (saved)
addFormNotice("Configuration saved successfully");
else
addFormNotice("Error saving the configuration (applied but not saved) - please see the error logs");
}
}
private static final int getInt(Object val) {
if (val == null) return 0;
String str = null;
if (val instanceof String)
str = (String)val;
else
str = ((String[])val)[0];
if (str.trim().length() <= 0) return 0;
try { return Integer.parseInt(str); } catch (NumberFormatException nfe) { return 0; }
}
}

View File

@@ -0,0 +1,251 @@
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("<table border=\"1\">\n");
TunnelPoolSettings exploratoryIn = _context.tunnelManager().getInboundSettings();
TunnelPoolSettings exploratoryOut = _context.tunnelManager().getOutboundSettings();
buf.append("<input type=\"hidden\" name=\"pool.0\" value=\"exploratory\" >");
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("<input type=\"hidden\" name=\"pool.").append(cur).append("\" value=\"");
buf.append(dest.calculateHash().toBase64()).append("\" >");
renderForm(buf, cur, prefix, "Client tunnels for " + name, in, out);
cur++;
}
buf.append("</table>\n");
return buf.toString();
}
private void renderForm(StringBuffer buf, int index, String prefix, String name, TunnelPoolSettings in, TunnelPoolSettings out) {
buf.append("<tr><td colspan=\"3\"><b><a name=\"").append(prefix).append("\">");
buf.append(name).append("</a></b></td></tr>\n");
buf.append("<tr><td></td><td><b>Inbound</b></td><td><b>Outbound</b></td></tr>\n");
// tunnel depth
buf.append("<tr><td>Depth</td>\n");
buf.append("<td><select name=\"").append(index).append(".depthInbound\">\n");
buf.append("<option value=\"0\" ");
if (in.getLength() <= 0) buf.append(" selected=\"true\" ");
buf.append(">0 hops</option>\n");
buf.append("<option value=\"1\" ");
if (in.getLength() == 1) buf.append(" selected=\"true\" ");
buf.append(">1 hop</option>\n");
buf.append("<option value=\"2\" ");
if (in.getLength() == 2) buf.append(" selected=\"true\" ");
buf.append(">2 hops</option>\n");
buf.append("<option value=\"3\" ");
if (in.getLength() == 3) buf.append(" selected=\"true\" ");
buf.append(">3 hops</option>\n");
if (in.getLength() > 3)
buf.append("<option value=\"").append(in.getLength()).append("\">").append(in.getLength()).append(" hops</option>\n");
buf.append("</td>\n");
buf.append("<td><select name=\"").append(index).append(".depthOutbound\">\n");
buf.append("<option value=\"0\" ");
if (out.getLength() <= 0) buf.append(" selected=\"true\" ");
buf.append(">0 hops</option>\n");
buf.append("<option value=\"1\" ");
if (out.getLength() == 1) buf.append(" selected=\"true\" ");
buf.append(">1 hop</option>\n");
buf.append("<option value=\"2\" ");
if (out.getLength() == 2) buf.append(" selected=\"true\" ");
buf.append(">2 hops</option>\n");
buf.append("<option value=\"3\" ");
if (out.getLength() == 3) buf.append(" selected=\"true\" ");
buf.append(">3 hops</option>\n");
if (out.getLength() > 3)
buf.append("<option value=\"").append(out.getLength()).append("\">").append(out.getLength()).append(" hops</option>\n");
buf.append("</td>\n");
buf.append("</tr>\n");
// tunnel depth variance
buf.append("<tr><td>Variance</td>\n");
buf.append("<td><select name=\"").append(index).append(".varianceInbound\">\n");
buf.append("<option value=\"0\" ");
if (in.getLengthVariance() == 0) buf.append(" selected=\"true\" ");
buf.append(">0 hops</option>\n");
buf.append("<option value=\"-1\" ");
if (in.getLengthVariance() == -1) buf.append(" selected=\"true\" ");
buf.append(">+/- 0-1 hops</option>\n");
buf.append("<option value=\"-2\" ");
if (in.getLengthVariance() == -2) buf.append(" selected=\"true\" ");
buf.append(">+/- 0-2 hops</option>\n");
buf.append("<option value=\"1\" ");
if (in.getLengthVariance() == 1) buf.append(" selected=\"true\" ");
buf.append(">+ 0-1 hops</option>\n");
buf.append("<option value=\"2\" ");
if (in.getLengthVariance() == 2) buf.append(" selected=\"true\" ");
buf.append(">+ 0-2 hops</option>\n");
if (in.getLengthVariance() < -2)
buf.append("<option value=\"").append(in.getLengthVariance()).append("\">+/- 0-").append(in.getLengthVariance()).append(" hops</option>\n");
if (in.getLengthVariance() > 2)
buf.append("<option value=\"").append(in.getLengthVariance()).append("\">+ 0-").append(in.getLengthVariance()).append(" hops</option>\n");
buf.append("</td>\n");
buf.append("<td><select name=\"").append(index).append(".varianceOutbound\">\n");
buf.append("<option value=\"0\" ");
if (out.getLengthVariance() == 0) buf.append(" selected=\"true\" ");
buf.append(">0 hops</option>\n");
buf.append("<option value=\"-1\" ");
if (out.getLengthVariance() == -1) buf.append(" selected=\"true\" ");
buf.append(">+/- 0-1 hops</option>\n");
buf.append("<option value=\"-2\" ");
if (out.getLengthVariance() == -2) buf.append(" selected=\"true\" ");
buf.append(">+/- 0-2 hops</option>\n");
buf.append("<option value=\"1\" ");
if (out.getLengthVariance() == 1) buf.append(" selected=\"true\" ");
buf.append(">+ 0-1 hops</option>\n");
buf.append("<option value=\"2\" ");
if (out.getLengthVariance() == 2) buf.append(" selected=\"true\" ");
buf.append(">+ 0-2 hops</option>\n");
if (out.getLengthVariance() < -2)
buf.append("<option value=\"").append(out.getLengthVariance()).append("\">+/- 0-").append(out.getLengthVariance()).append(" hops</option>\n");
if (out.getLengthVariance() > 2)
buf.append("<option value=\"").append(out.getLengthVariance()).append("\">+ 0-").append(out.getLengthVariance()).append(" hops</option>\n");
buf.append("</td>\n");
// tunnel quantity
buf.append("<tr><td>Quantity</td>\n");
buf.append("<td><select name=\"").append(index).append(".quantityInbound\">\n");
buf.append("<option value=\"1\" ");
if (in.getQuantity() <= 1) buf.append(" selected=\"true\" ");
buf.append(">1 tunnel</option>\n");
buf.append("<option value=\"2\" ");
if (in.getQuantity() == 2) buf.append(" selected=\"true\" ");
buf.append(">2 tunnels</option>\n");
buf.append("<option value=\"3\" ");
if (in.getQuantity() == 3) buf.append(" selected=\"true\" ");
buf.append(">3 tunnels</option>\n");
if (in.getQuantity() > 3)
buf.append("<option value=\"").append(in.getQuantity()).append("\">").append(in.getQuantity()).append(" tunnels</option>\n");
buf.append("</td>\n");
buf.append("<td><select name=\"").append(index).append(".quantityOutbound\">\n");
buf.append("<option value=\"1\" ");
if (out.getQuantity() <= 1) buf.append(" selected=\"true\" ");
buf.append(">1 tunnel</option>\n");
buf.append("<option value=\"2\" ");
if (out.getQuantity() == 2) buf.append(" selected=\"true\" ");
buf.append(">2 tunnels</option>\n");
buf.append("<option value=\"3\" ");
if (out.getQuantity() == 3) buf.append(" selected=\"true\" ");
buf.append(">3 tunnels</option>\n");
if (out.getQuantity() > 3)
buf.append("<option value=\"").append(out.getQuantity()).append("\">").append(out.getQuantity()).append(" tunnels</option>\n");
buf.append("</td>\n");
buf.append("</tr>\n");
// tunnel backup quantity
buf.append("<tr><td>Backup quantity</td>\n");
buf.append("<td><select name=\"").append(index).append(".backupInbound\">\n");
buf.append("<option value=\"0\" ");
if (in.getBackupQuantity() <= 0) buf.append(" selected=\"true\" ");
buf.append(">0 tunnels</option>\n");
buf.append("<option value=\"1\" ");
if (in.getBackupQuantity() == 1) buf.append(" selected=\"true\" ");
buf.append(">1 tunnel</option>\n");
buf.append("<option value=\"2\" ");
if (in.getBackupQuantity() == 2) buf.append(" selected=\"true\" ");
buf.append(">2 tunnels</option>\n");
buf.append("<option value=\"3\" ");
if (in.getBackupQuantity() == 3) buf.append(" selected=\"true\" ");
buf.append(">3 tunnels</option>\n");
if (in.getBackupQuantity() > 3)
buf.append("<option value=\"").append(in.getBackupQuantity()).append("\">").append(in.getBackupQuantity()).append(" tunnels</option>\n");
buf.append("</td>\n");
buf.append("<td><select name=\"").append(index).append(".backupOutbound\">\n");
buf.append("<option value=\"0\" ");
if (out.getBackupQuantity() <= 0) buf.append(" selected=\"true\" ");
buf.append(">0 tunnel</option>\n");
buf.append("<option value=\"1\" ");
if (out.getBackupQuantity() == 1) buf.append(" selected=\"true\" ");
buf.append(">1 tunnel</option>\n");
buf.append("<option value=\"2\" ");
if (out.getBackupQuantity() == 2) buf.append(" selected=\"true\" ");
buf.append(">2 tunnels</option>\n");
buf.append("<option value=\"3\" ");
if (out.getBackupQuantity() == 3) buf.append(" selected=\"true\" ");
buf.append(">3 tunnels</option>\n");
if (out.getBackupQuantity() > 3)
buf.append("<option value=\"").append(out.getBackupQuantity()).append("\">").append(out.getBackupQuantity()).append(" tunnels</option>\n");
buf.append("</td>\n");
buf.append("</tr>\n");
// custom options
buf.append("<tr><td>Inbound options:</td>\n");
buf.append("<td colspan=\"2\"><input name=\"").append(index);
buf.append(".inboundOptions\" type=\"text\" size=\"40\" ");
buf.append("value=\"");
Properties props = in.getUnknownOptions();
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");
buf.append("<tr><td>Outbound options:</td>\n");
buf.append("<td colspan=\"2\"><input name=\"").append(index);
buf.append(".outboundOptions\" type=\"text\" size=\"40\" ");
buf.append("value=\"");
props = in.getUnknownOptions();
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");
buf.append("<tr><td colspan=\"3\"><hr /></td></tr>\n");
}
}

View File

@@ -0,0 +1,46 @@
package net.i2p.router.web;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import net.i2p.router.RouterContext;
public class TunnelHelper {
private RouterContext _context;
private Writer _out;
/**
* 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 TunnelHelper() {}
public void setWriter(Writer writer) { _out = writer; }
public String getTunnelSummary() {
try {
if (_out != null) {
_context.tunnelManager().renderStatusHTML(_out);
return "";
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream(32*1024);
_context.tunnelManager().renderStatusHTML(new OutputStreamWriter(baos));
return new String(baos.toByteArray());
}
} catch (IOException ioe) {
ioe.printStackTrace();
return "";
}
}
}