forked from I2P_Developers/i2p.i2p
* Console: Tab the netdb and profile pages
This commit is contained in:
@ -11,9 +11,28 @@ public class NetDbHelper extends HelperBase {
|
||||
private int _full;
|
||||
private boolean _lease;
|
||||
private boolean _debug;
|
||||
private boolean _graphical;
|
||||
|
||||
public NetDbHelper() {}
|
||||
|
||||
private static final String PROP_DEBUG = "routerconsole.debug";
|
||||
|
||||
private static final String titles[] =
|
||||
{_x("Summary"), // 0
|
||||
_x("Local Router"), // 1
|
||||
_x("Router Lookup"), // 2
|
||||
_x("All Routers"), // 3
|
||||
_x("All Routers with Full Stats"), // 4
|
||||
"LeaseSet Debug", // 5
|
||||
_x("LeaseSets") }; // 6
|
||||
|
||||
private static final String links[] =
|
||||
{"", // 0
|
||||
"?r=.", // 1
|
||||
"", // 2
|
||||
"?f=2", // 3
|
||||
"?f=1", // 4
|
||||
"?l=2", // 5
|
||||
"?l=1" }; // 6
|
||||
|
||||
public void setRouter(String r) {
|
||||
if (r != null)
|
||||
_routerPrefix = DataHelper.stripHTML(r); // XSS
|
||||
@ -30,30 +49,88 @@ public class NetDbHelper extends HelperBase {
|
||||
_lease = _debug || "1".equals(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* call for non-text-mode browsers
|
||||
* @since 0.9.1
|
||||
*/
|
||||
public void allowGraphical() {
|
||||
_graphical = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* storeWriter() must be called previously
|
||||
*/
|
||||
public String getNetDbSummary() {
|
||||
NetDbRenderer renderer = new NetDbRenderer(_context);
|
||||
try {
|
||||
if (_out != null) {
|
||||
if (_routerPrefix != null)
|
||||
renderer.renderRouterInfoHTML(_out, _routerPrefix);
|
||||
else if (_lease)
|
||||
renderer.renderLeaseSetHTML(_out, _debug);
|
||||
else
|
||||
renderer.renderStatusHTML(_out, _full);
|
||||
return "";
|
||||
} else {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(32*1024);
|
||||
if (_routerPrefix != null)
|
||||
renderer.renderRouterInfoHTML(new OutputStreamWriter(baos), _routerPrefix);
|
||||
else if (_lease)
|
||||
renderer.renderLeaseSetHTML(new OutputStreamWriter(baos), _debug);
|
||||
else
|
||||
renderer.renderStatusHTML(new OutputStreamWriter(baos), _full);
|
||||
return new String(baos.toByteArray());
|
||||
}
|
||||
renderNavBar();
|
||||
if (_routerPrefix != null)
|
||||
renderer.renderRouterInfoHTML(_out, _routerPrefix);
|
||||
else if (_lease)
|
||||
renderer.renderLeaseSetHTML(_out, _debug);
|
||||
else
|
||||
renderer.renderStatusHTML(_out, _full);
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.1
|
||||
*/
|
||||
private int getTab() {
|
||||
if (_debug)
|
||||
return 5;
|
||||
if (_lease)
|
||||
return 6;
|
||||
if (".".equals(_routerPrefix))
|
||||
return 1;
|
||||
if (_routerPrefix != null)
|
||||
return 2;
|
||||
if (_full == 2)
|
||||
return 3;
|
||||
if (_full == 1)
|
||||
return 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.1
|
||||
*/
|
||||
private void renderNavBar() throws IOException {
|
||||
StringBuilder buf = new StringBuilder(1024);
|
||||
buf.append("<div class=\"confignav\" id=\"confignav\">");
|
||||
// TODO fix up the non-light themes
|
||||
String theme = _context.getProperty(CSSHelper.PROP_THEME_NAME);
|
||||
boolean span = _graphical && (theme == null || theme.equals(CSSHelper.DEFAULT_THEME));
|
||||
if (!span)
|
||||
buf.append("<center>");
|
||||
int tab = getTab();
|
||||
for (int i = 0; i < titles.length; i++) {
|
||||
if (i == 2 && tab != 2)
|
||||
continue; // can't nav to lookup
|
||||
if (i == 5 && !_context.getBooleanProperty(PROP_DEBUG))
|
||||
continue;
|
||||
if (i == tab) {
|
||||
// we are there
|
||||
if (span)
|
||||
buf.append("<span class=\"tab2\">");
|
||||
buf.append(_(titles[i]));
|
||||
} else {
|
||||
// we are not there, make a link
|
||||
if (span)
|
||||
buf.append("<span class=\"tab\">");
|
||||
buf.append("<a href=\"netdb").append(links[i]).append("\">").append(_(titles[i])).append("</a>");
|
||||
}
|
||||
if (span)
|
||||
buf.append(" </span>\n");
|
||||
else if (i != titles.length - 1)
|
||||
buf.append(" |\n");
|
||||
}
|
||||
if (!span)
|
||||
buf.append("</center>");
|
||||
buf.append("</div>");
|
||||
_out.write(buf.toString());
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,6 @@ public class NetDbRenderer {
|
||||
|
||||
public void renderRouterInfoHTML(Writer out, String routerPrefix) throws IOException {
|
||||
StringBuilder buf = new StringBuilder(4*1024);
|
||||
buf.append("<h2>" + _("Network Database RouterInfo Lookup") + "</h2>\n");
|
||||
if (".".equals(routerPrefix)) {
|
||||
renderRouterInfo(buf, _context.router().getRouterInfo(), true, true);
|
||||
} else {
|
||||
@ -102,12 +101,8 @@ public class NetDbRenderer {
|
||||
*/
|
||||
public void renderLeaseSetHTML(Writer out, boolean debug) throws IOException {
|
||||
StringBuilder buf = new StringBuilder(4*1024);
|
||||
buf.append("<h2>" + _("Network Database Contents") + "</h2>\n");
|
||||
buf.append("<a href=\"netdb\">" + _("View RouterInfo") + "</a>");
|
||||
buf.append("<h3>").append(_("LeaseSets"));
|
||||
if (debug)
|
||||
buf.append(" - Debug mode - Sorted by hash distance, closest first");
|
||||
buf.append("</h3>\n");
|
||||
buf.append("<p>Debug mode - Sorted by hash distance, closest first</p>\n");
|
||||
Hash ourRKey;
|
||||
Set<LeaseSet> leases;
|
||||
DecimalFormat fmt;
|
||||
@ -233,7 +228,6 @@ public class NetDbRenderer {
|
||||
* @param mode 0: our info and charts only; 1: full routerinfos and charts; 2: abbreviated routerinfos and charts
|
||||
*/
|
||||
public void renderStatusHTML(Writer out, int mode) throws IOException {
|
||||
out.write("<h2>" + _("Network Database Contents") + " (<a href=\"netdb?l=1\">" + _("View LeaseSets") + "</a>)</h2>\n");
|
||||
if (!_context.netDb().isInitialized()) {
|
||||
out.write(_("Not initialized"));
|
||||
out.flush();
|
||||
@ -244,12 +238,6 @@ public class NetDbRenderer {
|
||||
boolean shortStats = mode == 2;
|
||||
boolean showStats = full || shortStats;
|
||||
Hash us = _context.routerHash();
|
||||
out.write("<a name=\"routers\" ></a><h3>" + _("Routers") + " (<a href=\"netdb");
|
||||
if (full || !showStats)
|
||||
out.write("?f=2#routers\" >" + _("Show all routers"));
|
||||
else
|
||||
out.write("?f=1#routers\" >" + _("Show all routers with full stats"));
|
||||
out.write("</a>)</h3>\n");
|
||||
|
||||
StringBuilder buf = new StringBuilder(8192);
|
||||
RouterInfo ourInfo = _context.router().getRouterInfo();
|
||||
@ -365,11 +353,10 @@ public class NetDbRenderer {
|
||||
buf.append("<a name=\"our-info\" ></a><b>" + _("Our info") + ": ").append(hash).append("</b></th></tr><tr><td>\n");
|
||||
} else {
|
||||
buf.append("<b>" + _("Peer info for") + ":</b> ").append(hash).append("\n");
|
||||
if (full) {
|
||||
buf.append("[<a href=\"netdb\" >Back</a>]</th></tr><tr><td>\n");
|
||||
} else {
|
||||
buf.append("[<a href=\"netdb?r=").append(hash.substring(0, 6)).append("\" >").append(_("Full entry")).append("</a>]</th></tr><tr><td>\n");
|
||||
if (!full) {
|
||||
buf.append("[<a href=\"netdb?r=").append(hash.substring(0, 6)).append("\" >").append(_("Full entry")).append("</a>]");
|
||||
}
|
||||
buf.append("</th></tr><tr><td>\n");
|
||||
}
|
||||
|
||||
long age = _context.clock().now() - info.getPublished();
|
||||
|
@ -23,16 +23,21 @@ import net.i2p.stat.RateStat;
|
||||
*
|
||||
*/
|
||||
class ProfileOrganizerRenderer {
|
||||
private RouterContext _context;
|
||||
private ProfileOrganizer _organizer;
|
||||
private ProfileComparator _comparator;
|
||||
private final RouterContext _context;
|
||||
private final ProfileOrganizer _organizer;
|
||||
private final ProfileComparator _comparator;
|
||||
|
||||
public ProfileOrganizerRenderer(ProfileOrganizer organizer, RouterContext context) {
|
||||
_context = context;
|
||||
_organizer = organizer;
|
||||
_comparator = new ProfileComparator();
|
||||
}
|
||||
public void renderStatusHTML(Writer out, boolean full) throws IOException {
|
||||
|
||||
/**
|
||||
* @param mode 0 = high cap; 1 = all; 2 = floodfill
|
||||
*/
|
||||
public void renderStatusHTML(Writer out, int mode) throws IOException {
|
||||
boolean full = mode == 1;
|
||||
Set<Hash> peers = _organizer.selectAllPeers();
|
||||
|
||||
long now = _context.clock().now();
|
||||
@ -68,7 +73,13 @@ class ProfileOrganizerRenderer {
|
||||
int reliable = 0;
|
||||
int integrated = 0;
|
||||
StringBuilder buf = new StringBuilder(16*1024);
|
||||
buf.append("<h2>").append(_("Peer Profiles")).append("</h2>\n<p>");
|
||||
|
||||
////
|
||||
//// don't bother reindenting
|
||||
////
|
||||
if (mode < 2) {
|
||||
|
||||
//buf.append("<h2>").append(_("Peer Profiles")).append("</h2>\n<p>");
|
||||
buf.append(ngettext("Showing 1 recent profile.", "Showing {0} recent profiles.", order.size())).append('\n');
|
||||
if (older > 0)
|
||||
buf.append(ngettext("Hiding 1 older profile.", "Hiding {0} older profiles.", older)).append('\n');
|
||||
@ -181,8 +192,13 @@ class ProfileOrganizerRenderer {
|
||||
}
|
||||
buf.append("</table>");
|
||||
|
||||
buf.append("<h2><a name=\"flood\"></a>").append(_("Floodfill and Integrated Peers"))
|
||||
.append(" (").append(integratedPeers.size()).append(")</h2>\n");
|
||||
////
|
||||
//// don't bother reindenting
|
||||
////
|
||||
} else {
|
||||
|
||||
//buf.append("<h2><a name=\"flood\"></a>").append(_("Floodfill and Integrated Peers"))
|
||||
// .append(" (").append(integratedPeers.size()).append(")</h2>\n");
|
||||
buf.append("<table>");
|
||||
buf.append("<tr>");
|
||||
buf.append("<th class=\"smallhead\">").append(_("Peer")).append("</th>");
|
||||
@ -247,6 +263,12 @@ class ProfileOrganizerRenderer {
|
||||
}
|
||||
buf.append("</table>");
|
||||
|
||||
////
|
||||
//// don't bother reindenting
|
||||
////
|
||||
}
|
||||
if (mode < 2) {
|
||||
|
||||
buf.append("<h3>").append(_("Thresholds")).append("</h3>");
|
||||
buf.append("<p><b>").append(_("Speed")).append(":</b> ").append(num(_organizer.getSpeedThreshold()))
|
||||
.append(" (").append(fast).append(' ').append(_("fast peers")).append(")<br>");
|
||||
@ -262,6 +284,12 @@ class ProfileOrganizerRenderer {
|
||||
buf.append("<li><b>").append(_("integration")).append("</b>: ").append(_("how many new peers have they told us about lately?")).append("</li>");
|
||||
buf.append("<li><b>").append(_("status")).append("</b>: ").append(_("is the peer banned, or unreachable, or failing tunnel tests?")).append("</li>");
|
||||
buf.append("</ul>");
|
||||
|
||||
////
|
||||
//// don't bother reindenting
|
||||
////
|
||||
} // mode < 2
|
||||
|
||||
out.write(buf.toString());
|
||||
out.flush();
|
||||
}
|
||||
|
@ -4,12 +4,52 @@ import java.io.IOException;
|
||||
|
||||
|
||||
public class ProfilesHelper extends HelperBase {
|
||||
private boolean _full;
|
||||
private int _full;
|
||||
private boolean _graphical;
|
||||
|
||||
private static final String titles[] =
|
||||
{_x("High Capacity"), // 0
|
||||
_x("Floodfill "), // 1
|
||||
_x("Banned"), // 2
|
||||
_x("All"), }; // 3
|
||||
|
||||
private static final String links[] =
|
||||
{"", // 0
|
||||
"?f=2", // 1
|
||||
"?f=3", // 2
|
||||
"?f=1" }; // 3
|
||||
|
||||
public ProfilesHelper() {}
|
||||
|
||||
public void setFull(String f) {
|
||||
_full = f != null;
|
||||
if (f != null) {
|
||||
try {
|
||||
_full = Integer.parseInt(f);
|
||||
if (_full < 0 || _full > 3)
|
||||
_full = 0;
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* call for non-text-mode browsers
|
||||
* @since 0.9.1
|
||||
*/
|
||||
public void allowGraphical() {
|
||||
_graphical = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return empty string, writes directly to _out
|
||||
* @since 0.9.1
|
||||
*/
|
||||
public String getSummary() {
|
||||
try {
|
||||
renderNavBar();
|
||||
} catch (IOException ioe) {}
|
||||
if (_full == 3)
|
||||
getShitlistSummary();
|
||||
else
|
||||
getProfileSummary();
|
||||
return "";
|
||||
}
|
||||
|
||||
/** @return empty string, writes directly to _out */
|
||||
@ -33,4 +73,52 @@ public class ProfilesHelper extends HelperBase {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.1
|
||||
*/
|
||||
private int getTab() {
|
||||
if (_full == 2)
|
||||
return 1;
|
||||
if (_full == 3)
|
||||
return 2;
|
||||
if (_full == 1)
|
||||
return 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.1
|
||||
*/
|
||||
private void renderNavBar() throws IOException {
|
||||
StringBuilder buf = new StringBuilder(1024);
|
||||
buf.append("<div class=\"confignav\" id=\"confignav\">");
|
||||
// TODO fix up the non-light themes
|
||||
String theme = _context.getProperty(CSSHelper.PROP_THEME_NAME);
|
||||
boolean span = _graphical && (theme == null || theme.equals(CSSHelper.DEFAULT_THEME));
|
||||
if (!span)
|
||||
buf.append("<center>");
|
||||
int tab = getTab();
|
||||
for (int i = 0; i < titles.length; i++) {
|
||||
if (i == tab) {
|
||||
// we are there
|
||||
if (span)
|
||||
buf.append("<span class=\"tab2\">");
|
||||
buf.append(_(titles[i]));
|
||||
} else {
|
||||
// we are not there, make a link
|
||||
if (span)
|
||||
buf.append("<span class=\"tab\">");
|
||||
buf.append("<a href=\"profiles").append(links[i]).append("\">").append(_(titles[i])).append("</a>");
|
||||
}
|
||||
if (span)
|
||||
buf.append(" </span>\n");
|
||||
else if (i != titles.length - 1)
|
||||
buf.append(" |\n");
|
||||
}
|
||||
if (!span)
|
||||
buf.append("</center>");
|
||||
buf.append("</div>");
|
||||
_out.write(buf.toString());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user