2009-10-17 23:16:53 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
/*
|
|
|
|
* free (adj.): unencumbered; not under the control of others
|
|
|
|
* Written by jrandom in 2003 and released into the public domain
|
|
|
|
* with no warranty of any kind, either expressed or implied.
|
|
|
|
* It probably won't make your computer catch on fire, or eat
|
|
|
|
* your children, but it might. Use at your own risk.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.Writer;
|
2010-05-10 15:22:10 +00:00
|
|
|
import java.math.BigInteger; // debug
|
2010-06-16 13:23:21 +00:00
|
|
|
import java.text.Collator;
|
2010-05-10 15:22:10 +00:00
|
|
|
import java.text.DecimalFormat; // debug
|
2009-10-17 23:16:53 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
2012-05-20 18:20:48 +00:00
|
|
|
import java.util.Date;
|
2009-10-17 23:16:53 +00:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2010-06-16 13:23:21 +00:00
|
|
|
import java.util.Locale;
|
2010-10-02 15:51:48 +00:00
|
|
|
import java.util.Map;
|
2009-10-17 23:16:53 +00:00
|
|
|
import java.util.Set;
|
|
|
|
import java.util.TreeSet;
|
|
|
|
|
|
|
|
import net.i2p.data.DataHelper;
|
|
|
|
import net.i2p.data.Destination;
|
|
|
|
import net.i2p.data.Hash;
|
|
|
|
import net.i2p.data.LeaseSet;
|
|
|
|
import net.i2p.data.RouterAddress;
|
|
|
|
import net.i2p.data.RouterInfo;
|
|
|
|
import net.i2p.router.RouterContext;
|
|
|
|
import net.i2p.router.TunnelPoolSettings;
|
2012-11-19 16:22:09 +00:00
|
|
|
import net.i2p.router.util.HashDistance; // debug
|
2012-02-25 18:40:27 +00:00
|
|
|
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
|
2009-10-17 23:16:53 +00:00
|
|
|
import net.i2p.util.ObjectCounter;
|
2010-01-10 16:42:21 +00:00
|
|
|
import net.i2p.util.VersionComparator;
|
2009-10-17 23:16:53 +00:00
|
|
|
|
|
|
|
public class NetDbRenderer {
|
2012-02-17 23:08:03 +00:00
|
|
|
private final RouterContext _context;
|
2009-10-17 23:16:53 +00:00
|
|
|
|
|
|
|
public NetDbRenderer (RouterContext ctx) {
|
|
|
|
_context = ctx;
|
|
|
|
}
|
|
|
|
|
2010-05-10 15:22:10 +00:00
|
|
|
private class LeaseSetComparator implements Comparator<LeaseSet> {
|
|
|
|
public int compare(LeaseSet l, LeaseSet r) {
|
|
|
|
Destination dl = l.getDestination();
|
|
|
|
Destination dr = r.getDestination();
|
2009-10-17 23:16:53 +00:00
|
|
|
boolean locall = _context.clientManager().isLocal(dl);
|
|
|
|
boolean localr = _context.clientManager().isLocal(dr);
|
|
|
|
if (locall && !localr) return -1;
|
|
|
|
if (localr && !locall) return 1;
|
|
|
|
return dl.calculateHash().toBase64().compareTo(dr.calculateHash().toBase64());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-10 15:22:10 +00:00
|
|
|
/** for debugging @since 0.7.14 */
|
|
|
|
private static class LeaseSetRoutingKeyComparator implements Comparator<LeaseSet> {
|
|
|
|
private final Hash _us;
|
|
|
|
public LeaseSetRoutingKeyComparator(Hash us) {
|
|
|
|
_us = us;
|
|
|
|
}
|
|
|
|
public int compare(LeaseSet l, LeaseSet r) {
|
|
|
|
return HashDistance.getDistance(_us, l.getRoutingKey()).subtract(HashDistance.getDistance(_us, r.getRoutingKey())).signum();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class RouterInfoComparator implements Comparator<RouterInfo> {
|
|
|
|
public int compare(RouterInfo l, RouterInfo r) {
|
|
|
|
return l.getIdentity().getHash().toBase64().compareTo(r.getIdentity().getHash().toBase64());
|
2009-10-17 23:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void renderRouterInfoHTML(Writer out, String routerPrefix) throws IOException {
|
|
|
|
StringBuilder buf = new StringBuilder(4*1024);
|
|
|
|
if (".".equals(routerPrefix)) {
|
|
|
|
renderRouterInfo(buf, _context.router().getRouterInfo(), true, true);
|
|
|
|
} else {
|
|
|
|
boolean notFound = true;
|
|
|
|
Set routers = _context.netDb().getRouters();
|
|
|
|
for (Iterator iter = routers.iterator(); iter.hasNext(); ) {
|
|
|
|
RouterInfo ri = (RouterInfo)iter.next();
|
|
|
|
Hash key = ri.getIdentity().getHash();
|
|
|
|
if (key.toBase64().startsWith(routerPrefix)) {
|
|
|
|
renderRouterInfo(buf, ri, false, true);
|
|
|
|
notFound = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (notFound)
|
2009-10-29 23:22:51 +00:00
|
|
|
buf.append(_("Router") + ' ').append(routerPrefix).append(' ' + _("not found in network database") );
|
2009-10-17 23:16:53 +00:00
|
|
|
}
|
|
|
|
out.write(buf.toString());
|
|
|
|
out.flush();
|
|
|
|
}
|
|
|
|
|
2010-05-10 15:22:10 +00:00
|
|
|
/**
|
2010-05-13 17:02:32 +00:00
|
|
|
* @param debug @since 0.7.14 sort by distance from us, display
|
2010-05-10 15:22:10 +00:00
|
|
|
* median distance, and other stuff, useful when floodfill
|
|
|
|
*/
|
|
|
|
public void renderLeaseSetHTML(Writer out, boolean debug) throws IOException {
|
2009-10-17 23:16:53 +00:00
|
|
|
StringBuilder buf = new StringBuilder(4*1024);
|
2012-02-26 21:15:31 +00:00
|
|
|
if (debug)
|
2012-06-01 13:30:38 +00:00
|
|
|
buf.append("<p>Debug mode - Sorted by hash distance, closest first</p>\n");
|
2010-05-10 15:22:10 +00:00
|
|
|
Hash ourRKey;
|
|
|
|
Set<LeaseSet> leases;
|
|
|
|
DecimalFormat fmt;
|
|
|
|
if (debug) {
|
2010-05-13 17:02:32 +00:00
|
|
|
ourRKey = _context.routerHash();
|
2010-05-10 15:22:10 +00:00
|
|
|
leases = new TreeSet(new LeaseSetRoutingKeyComparator(ourRKey));
|
|
|
|
fmt = new DecimalFormat("#0.00");
|
|
|
|
} else {
|
|
|
|
ourRKey = null;
|
|
|
|
leases = new TreeSet(new LeaseSetComparator());
|
|
|
|
fmt = null;
|
|
|
|
}
|
2009-10-17 23:16:53 +00:00
|
|
|
leases.addAll(_context.netDb().getLeases());
|
2012-02-17 23:08:03 +00:00
|
|
|
int medianCount = 0;
|
2012-02-25 18:40:27 +00:00
|
|
|
int rapCount = 0;
|
2010-05-10 15:22:10 +00:00
|
|
|
BigInteger median = null;
|
|
|
|
int c = 0;
|
2012-02-17 23:08:03 +00:00
|
|
|
if (debug) {
|
|
|
|
// Find the center of the RAP leasesets
|
|
|
|
for (LeaseSet ls : leases) {
|
|
|
|
if (ls.getReceivedAsPublished())
|
2012-02-25 18:40:27 +00:00
|
|
|
rapCount++;
|
2012-02-17 23:08:03 +00:00
|
|
|
}
|
2012-02-25 18:40:27 +00:00
|
|
|
medianCount = rapCount / 2;
|
2012-02-17 23:08:03 +00:00
|
|
|
}
|
2009-10-17 23:16:53 +00:00
|
|
|
long now = _context.clock().now();
|
2012-02-17 23:08:03 +00:00
|
|
|
for (LeaseSet ls : leases) {
|
2009-10-17 23:16:53 +00:00
|
|
|
Destination dest = ls.getDestination();
|
|
|
|
Hash key = dest.calculateHash();
|
2009-10-29 23:22:51 +00:00
|
|
|
buf.append("<b>").append(_("LeaseSet")).append(": ").append(key.toBase64());
|
2009-10-17 23:16:53 +00:00
|
|
|
if (_context.clientManager().isLocal(dest)) {
|
2010-11-17 22:26:31 +00:00
|
|
|
buf.append(" (<a href=\"tunnels#" + key.toBase64().substring(0,4) + "\">" + _("Local") + "</a> ");
|
2009-10-17 23:16:53 +00:00
|
|
|
if (! _context.clientManager().shouldPublishLeaseSet(key))
|
2009-10-29 23:22:51 +00:00
|
|
|
buf.append(_("Unpublished") + ' ');
|
|
|
|
buf.append(_("Destination") + ' ');
|
2009-10-17 23:16:53 +00:00
|
|
|
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(key);
|
|
|
|
if (in != null && in.getDestinationNickname() != null)
|
|
|
|
buf.append(in.getDestinationNickname());
|
|
|
|
else
|
|
|
|
buf.append(dest.toBase64().substring(0, 6));
|
|
|
|
} else {
|
2009-10-29 23:22:51 +00:00
|
|
|
buf.append(" (" + _("Destination") + ' ');
|
2009-10-17 23:16:53 +00:00
|
|
|
String host = _context.namingService().reverseLookup(dest);
|
|
|
|
if (host != null)
|
|
|
|
buf.append(host);
|
|
|
|
else
|
|
|
|
buf.append(dest.toBase64().substring(0, 6));
|
|
|
|
}
|
|
|
|
buf.append(")</b><br>\n");
|
|
|
|
long exp = ls.getEarliestLeaseDate()-now;
|
|
|
|
if (exp > 0)
|
2010-11-06 12:28:38 +00:00
|
|
|
buf.append(_("Expires in {0}", DataHelper.formatDuration2(exp))).append("<br>\n");
|
2009-10-17 23:16:53 +00:00
|
|
|
else
|
2010-11-06 12:28:38 +00:00
|
|
|
buf.append(_("Expired {0} ago", DataHelper.formatDuration2(0-exp))).append("<br>\n");
|
2010-05-10 15:22:10 +00:00
|
|
|
if (debug) {
|
2012-02-17 23:08:03 +00:00
|
|
|
buf.append("RAP? " + ls.getReceivedAsPublished());
|
|
|
|
buf.append(" RAR? " + ls.getReceivedAsReply());
|
2010-05-10 15:22:10 +00:00
|
|
|
BigInteger dist = HashDistance.getDistance(ourRKey, ls.getRoutingKey());
|
2012-02-17 23:08:03 +00:00
|
|
|
if (ls.getReceivedAsPublished()) {
|
|
|
|
if (c++ == medianCount)
|
|
|
|
median = dist;
|
|
|
|
}
|
2012-02-26 21:15:31 +00:00
|
|
|
buf.append(" Dist: <b>").append(fmt.format(biLog2(dist))).append("</b><br>");
|
|
|
|
buf.append("Routing Key: ").append(ls.getRoutingKey().toBase64());
|
2010-05-10 15:22:10 +00:00
|
|
|
buf.append("<br>");
|
2012-02-26 21:15:31 +00:00
|
|
|
buf.append("Encryption Key: ").append(ls.getEncryptionKey().toBase64().substring(0, 20)).append("...<br>");
|
2010-05-10 15:22:10 +00:00
|
|
|
}
|
2009-10-17 23:16:53 +00:00
|
|
|
for (int i = 0; i < ls.getLeaseCount(); i++) {
|
2009-10-29 23:22:51 +00:00
|
|
|
buf.append(_("Lease")).append(' ').append(i + 1).append(": " + _("Gateway") + ' ');
|
2009-10-17 23:16:53 +00:00
|
|
|
buf.append(_context.commSystem().renderPeerHTML(ls.getLease(i).getGateway()));
|
2009-10-29 23:22:51 +00:00
|
|
|
buf.append(' ' + _("Tunnel") + ' ').append(ls.getLease(i).getTunnelId().getTunnelId()).append("<br>\n");
|
2009-10-17 23:16:53 +00:00
|
|
|
}
|
|
|
|
buf.append("<hr>\n");
|
|
|
|
out.write(buf.toString());
|
|
|
|
buf.setLength(0);
|
|
|
|
}
|
2010-05-10 15:22:10 +00:00
|
|
|
if (debug) {
|
2012-02-25 18:40:27 +00:00
|
|
|
FloodfillNetworkDatabaseFacade netdb = (FloodfillNetworkDatabaseFacade)_context.netDb();
|
|
|
|
buf.append("<p><b>Total Leasesets: ").append(leases.size());
|
|
|
|
buf.append("</b></p><p><b>Published (RAP) Leasesets: ").append(netdb.getKnownLeaseSets());
|
2012-05-20 18:20:48 +00:00
|
|
|
buf.append("</b></p><p><b>Mod Data: \"").append(DataHelper.getUTF8(_context.routingKeyGenerator().getModData()))
|
|
|
|
.append("\" Last Changed: ").append(new Date(_context.routingKeyGenerator().getLastChanged()));
|
2012-02-25 18:40:27 +00:00
|
|
|
int ff = _context.peerManager().getPeersByCapability(FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL).size();
|
|
|
|
buf.append("</b></p><p><b>Known Floodfills: ").append(ff);
|
|
|
|
buf.append("</b></p><p><b>Currently Floodfill? ");
|
|
|
|
buf.append(netdb.floodfillEnabled() ? "yes" : "no");
|
2011-04-10 18:22:43 +00:00
|
|
|
buf.append("</b></p><p><b>Network data (only valid if floodfill):");
|
2012-02-17 23:08:03 +00:00
|
|
|
//buf.append("</b></p><p><b>Center of Key Space (router hash): " + ourRKey.toBase64());
|
2010-05-10 15:22:10 +00:00
|
|
|
if (median != null) {
|
|
|
|
double log2 = biLog2(median);
|
2012-02-25 18:40:27 +00:00
|
|
|
buf.append("</b></p><p><b>Median distance (bits): ").append(fmt.format(log2));
|
2010-05-13 17:02:32 +00:00
|
|
|
// 3 for 8 floodfills... -1 for median
|
|
|
|
int total = (int) Math.round(Math.pow(2, 3 + 256 - 1 - log2));
|
2012-02-25 18:40:27 +00:00
|
|
|
buf.append("</b></p><p><b>Estimated total floodfills: ").append(total);
|
|
|
|
buf.append("</b></p><p><b>Estimated total leasesets: ").append(total * rapCount / 8);
|
2012-05-20 18:20:48 +00:00
|
|
|
} else {
|
|
|
|
buf.append("</b></p><p><b>Not floodfill or no data");
|
2010-05-10 15:22:10 +00:00
|
|
|
}
|
2011-04-10 18:22:43 +00:00
|
|
|
buf.append("</b></p>");
|
2010-05-10 15:22:10 +00:00
|
|
|
}
|
2009-10-17 23:16:53 +00:00
|
|
|
out.write(buf.toString());
|
|
|
|
out.flush();
|
|
|
|
}
|
|
|
|
|
2010-05-10 15:22:10 +00:00
|
|
|
/**
|
|
|
|
* For debugging
|
|
|
|
* http://forums.sun.com/thread.jspa?threadID=597652
|
|
|
|
* @since 0.7.14
|
|
|
|
*/
|
|
|
|
private static double biLog2(BigInteger a) {
|
|
|
|
int b = a.bitLength() - 1;
|
|
|
|
double c = 0;
|
|
|
|
double d = 0.5;
|
|
|
|
for (int i = b; i >= 0; --i) {
|
|
|
|
if (a.testBit(i))
|
|
|
|
c += d;
|
|
|
|
d /= 2;
|
|
|
|
}
|
|
|
|
return b + c;
|
|
|
|
}
|
|
|
|
|
2009-11-07 19:32:00 +00:00
|
|
|
/**
|
2012-06-08 16:10:26 +00:00
|
|
|
* @param mode 0: charts only; 1: full routerinfos; 2: abbreviated routerinfos
|
2009-11-07 19:32:00 +00:00
|
|
|
*/
|
|
|
|
public void renderStatusHTML(Writer out, int mode) throws IOException {
|
2009-10-17 23:16:53 +00:00
|
|
|
if (!_context.netDb().isInitialized()) {
|
2009-10-28 18:26:50 +00:00
|
|
|
out.write(_("Not initialized"));
|
2009-10-17 23:16:53 +00:00
|
|
|
out.flush();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-07 19:32:00 +00:00
|
|
|
boolean full = mode == 1;
|
|
|
|
boolean shortStats = mode == 2;
|
2012-06-08 16:10:26 +00:00
|
|
|
boolean showStats = full || shortStats; // this means show the router infos
|
2009-10-17 23:16:53 +00:00
|
|
|
Hash us = _context.routerHash();
|
|
|
|
|
2009-10-28 18:26:50 +00:00
|
|
|
StringBuilder buf = new StringBuilder(8192);
|
2012-06-08 16:10:26 +00:00
|
|
|
if (showStats) {
|
|
|
|
RouterInfo ourInfo = _context.router().getRouterInfo();
|
|
|
|
renderRouterInfo(buf, ourInfo, true, true);
|
|
|
|
out.write(buf.toString());
|
|
|
|
buf.setLength(0);
|
|
|
|
}
|
2009-10-17 23:16:53 +00:00
|
|
|
|
|
|
|
ObjectCounter<String> versions = new ObjectCounter();
|
|
|
|
ObjectCounter<String> countries = new ObjectCounter();
|
2009-11-09 17:11:20 +00:00
|
|
|
int[] transportCount = new int[8];
|
2009-10-17 23:16:53 +00:00
|
|
|
|
2010-05-10 15:22:10 +00:00
|
|
|
Set<RouterInfo> routers = new TreeSet(new RouterInfoComparator());
|
2009-10-17 23:16:53 +00:00
|
|
|
routers.addAll(_context.netDb().getRouters());
|
|
|
|
for (Iterator iter = routers.iterator(); iter.hasNext(); ) {
|
|
|
|
RouterInfo ri = (RouterInfo)iter.next();
|
|
|
|
Hash key = ri.getIdentity().getHash();
|
|
|
|
boolean isUs = key.equals(us);
|
|
|
|
if (!isUs) {
|
2009-11-07 19:32:00 +00:00
|
|
|
if (showStats) {
|
|
|
|
renderRouterInfo(buf, ri, false, full);
|
|
|
|
out.write(buf.toString());
|
|
|
|
buf.setLength(0);
|
|
|
|
}
|
2009-10-17 23:16:53 +00:00
|
|
|
String routerVersion = ri.getOption("router.version");
|
|
|
|
if (routerVersion != null)
|
|
|
|
versions.increment(routerVersion);
|
|
|
|
String country = _context.commSystem().getCountry(key);
|
|
|
|
if(country != null)
|
|
|
|
countries.increment(country);
|
2009-11-09 17:11:20 +00:00
|
|
|
transportCount[classifyTransports(ri)]++;
|
2009-10-17 23:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 16:10:26 +00:00
|
|
|
//
|
|
|
|
// don't bother to reindent
|
|
|
|
//
|
|
|
|
if (!showStats) {
|
|
|
|
|
|
|
|
// the summary table
|
2011-03-09 15:55:52 +00:00
|
|
|
buf.append("<table border=\"0\" cellspacing=\"30\"><tr><th colspan=\"3\">")
|
|
|
|
.append(_("Network Database Router Statistics"))
|
2011-03-12 16:11:10 +00:00
|
|
|
.append("</th></tr><tr><td style=\"vertical-align: top;\">");
|
2009-11-09 17:11:20 +00:00
|
|
|
// versions table
|
2009-10-17 23:16:53 +00:00
|
|
|
List<String> versionList = new ArrayList(versions.objects());
|
2010-05-05 16:51:54 +00:00
|
|
|
if (!versionList.isEmpty()) {
|
2010-01-10 16:42:21 +00:00
|
|
|
Collections.sort(versionList, Collections.reverseOrder(new VersionComparator()));
|
2009-10-17 23:16:53 +00:00
|
|
|
buf.append("<table>\n");
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<tr><th>" + _("Version") + "</th><th>" + _("Count") + "</th></tr>\n");
|
2009-10-17 23:16:53 +00:00
|
|
|
for (String routerVersion : versionList) {
|
|
|
|
int num = versions.count(routerVersion);
|
|
|
|
buf.append("<tr><td align=\"center\">").append(DataHelper.stripHTML(routerVersion));
|
|
|
|
buf.append("</td><td align=\"center\">").append(num).append("</td></tr>\n");
|
|
|
|
}
|
|
|
|
buf.append("</table>\n");
|
|
|
|
}
|
2011-03-09 15:55:52 +00:00
|
|
|
buf.append("</td><td style=\"vertical-align: top;\">");
|
2009-10-17 23:16:53 +00:00
|
|
|
out.write(buf.toString());
|
|
|
|
buf.setLength(0);
|
|
|
|
|
2009-11-09 17:11:20 +00:00
|
|
|
// transports table
|
|
|
|
buf.append("<table>\n");
|
2009-11-15 11:00:14 +00:00
|
|
|
buf.append("<tr><th align=\"left\">" + _("Transports") + "</th><th>" + _("Count") + "</th></tr>\n");
|
2009-11-09 17:11:20 +00:00
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
int num = transportCount[i];
|
|
|
|
if (num > 0) {
|
|
|
|
buf.append("<tr><td>").append(_(TNAMES[i]));
|
|
|
|
buf.append("</td><td align=\"center\">").append(num).append("</td></tr>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buf.append("</table>\n");
|
2011-03-09 15:55:52 +00:00
|
|
|
buf.append("</td><td style=\"vertical-align: top;\">");
|
2009-11-09 17:11:20 +00:00
|
|
|
out.write(buf.toString());
|
|
|
|
buf.setLength(0);
|
|
|
|
|
|
|
|
// country table
|
2009-10-17 23:16:53 +00:00
|
|
|
List<String> countryList = new ArrayList(countries.objects());
|
2010-05-05 16:51:54 +00:00
|
|
|
if (!countryList.isEmpty()) {
|
2009-11-07 19:32:00 +00:00
|
|
|
Collections.sort(countryList, new CountryComparator());
|
2009-10-17 23:16:53 +00:00
|
|
|
buf.append("<table>\n");
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<tr><th align=\"left\">" + _("Country") + "</th><th>" + _("Count") + "</th></tr>\n");
|
2009-10-17 23:16:53 +00:00
|
|
|
for (String country : countryList) {
|
|
|
|
int num = countries.count(country);
|
2011-11-28 20:32:23 +00:00
|
|
|
buf.append("<tr><td><img height=\"11\" width=\"16\" alt=\"").append(country.toUpperCase(Locale.US)).append("\"");
|
2009-10-17 23:16:53 +00:00
|
|
|
buf.append(" src=\"/flags.jsp?c=").append(country).append("\"> ");
|
2009-11-07 19:32:00 +00:00
|
|
|
buf.append(_(_context.commSystem().getCountryName(country)));
|
2009-10-17 23:16:53 +00:00
|
|
|
buf.append("</td><td align=\"center\">").append(num).append("</td></tr>\n");
|
|
|
|
}
|
|
|
|
buf.append("</table>\n");
|
|
|
|
}
|
2009-11-09 17:11:20 +00:00
|
|
|
|
2009-10-17 23:16:53 +00:00
|
|
|
buf.append("</td></tr></table>");
|
2012-06-08 16:10:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// don't bother to reindent
|
|
|
|
//
|
|
|
|
} // if !showStats
|
|
|
|
|
2009-10-17 23:16:53 +00:00
|
|
|
out.write(buf.toString());
|
|
|
|
out.flush();
|
|
|
|
}
|
|
|
|
|
2010-06-16 13:23:21 +00:00
|
|
|
/** sort by translated country name using rules for the current language setting */
|
|
|
|
private class CountryComparator implements Comparator<String> {
|
|
|
|
Collator coll;
|
|
|
|
|
|
|
|
public CountryComparator() {
|
|
|
|
super();
|
|
|
|
coll = Collator.getInstance(new Locale(Messages.getLanguage(_context)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public int compare(String l, String r) {
|
|
|
|
return coll.compare(_(_context.commSystem().getCountryName(l)),
|
|
|
|
_(_context.commSystem().getCountryName(r)));
|
2009-11-07 19:32:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-17 23:16:53 +00:00
|
|
|
/**
|
|
|
|
* Be careful to use stripHTML for any displayed routerInfo data
|
|
|
|
* to prevent vulnerabilities
|
|
|
|
*/
|
|
|
|
private void renderRouterInfo(StringBuilder buf, RouterInfo info, boolean isUs, boolean full) {
|
|
|
|
String hash = info.getIdentity().getHash().toBase64();
|
|
|
|
buf.append("<table><tr><th><a name=\"").append(hash.substring(0, 6)).append("\" ></a>");
|
|
|
|
if (isUs) {
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<a name=\"our-info\" ></a><b>" + _("Our info") + ": ").append(hash).append("</b></th></tr><tr><td>\n");
|
2009-10-17 23:16:53 +00:00
|
|
|
} else {
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<b>" + _("Peer info for") + ":</b> ").append(hash).append("\n");
|
2012-06-01 13:30:38 +00:00
|
|
|
if (!full) {
|
|
|
|
buf.append("[<a href=\"netdb?r=").append(hash.substring(0, 6)).append("\" >").append(_("Full entry")).append("</a>]");
|
2009-10-17 23:16:53 +00:00
|
|
|
}
|
2012-06-01 13:30:38 +00:00
|
|
|
buf.append("</th></tr><tr><td>\n");
|
2009-10-17 23:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long age = _context.clock().now() - info.getPublished();
|
2009-11-21 13:32:32 +00:00
|
|
|
if (isUs && _context.router().isHidden()) {
|
|
|
|
buf.append("<b>").append(_("Hidden")).append(", ").append(_("Updated")).append(":</b> ")
|
2010-11-06 12:28:38 +00:00
|
|
|
.append(_("{0} ago", DataHelper.formatDuration2(age))).append("<br>\n");
|
2009-11-21 13:32:32 +00:00
|
|
|
} else if (age > 0) {
|
|
|
|
buf.append("<b>").append(_("Published")).append(":</b> ")
|
2010-11-06 12:28:38 +00:00
|
|
|
.append(_("{0} ago", DataHelper.formatDuration2(age))).append("<br>\n");
|
2009-11-21 13:32:32 +00:00
|
|
|
} else {
|
|
|
|
// shouldnt happen
|
2010-11-06 12:28:38 +00:00
|
|
|
buf.append("<b>" + _("Published") + ":</b> in ").append(DataHelper.formatDuration2(0-age)).append("???<br>\n");
|
2009-11-21 13:32:32 +00:00
|
|
|
}
|
2009-10-26 10:53:53 +00:00
|
|
|
buf.append("<b>" + _("Address(es)") + ":</b> ");
|
2009-10-17 23:16:53 +00:00
|
|
|
String country = _context.commSystem().getCountry(info.getIdentity().getHash());
|
|
|
|
if(country != null) {
|
2011-11-28 20:32:23 +00:00
|
|
|
buf.append("<img height=\"11\" width=\"16\" alt=\"").append(country.toUpperCase(Locale.US)).append('\"');
|
2009-11-21 13:32:32 +00:00
|
|
|
buf.append(" title=\"").append(_(_context.commSystem().getCountryName(country))).append('\"');
|
2009-10-17 23:16:53 +00:00
|
|
|
buf.append(" src=\"/flags.jsp?c=").append(country).append("\"> ");
|
|
|
|
}
|
|
|
|
for (Iterator iter = info.getAddresses().iterator(); iter.hasNext(); ) {
|
|
|
|
RouterAddress addr = (RouterAddress)iter.next();
|
2010-03-17 16:15:52 +00:00
|
|
|
String style = addr.getTransportStyle();
|
|
|
|
buf.append("<b>").append(DataHelper.stripHTML(style)).append(":</b> ");
|
|
|
|
int cost = addr.getCost();
|
|
|
|
if (!((style.equals("SSU") && cost == 5) || (style.equals("NTCP") && cost == 10)))
|
2010-03-25 20:25:03 +00:00
|
|
|
buf.append('[').append(_("cost")).append('=').append("" + cost).append("] ");
|
2011-12-23 21:41:58 +00:00
|
|
|
Map p = addr.getOptionsMap();
|
|
|
|
for (Map.Entry e : (Set<Map.Entry>) p.entrySet()) {
|
2010-10-02 15:51:48 +00:00
|
|
|
String name = (String) e.getKey();
|
|
|
|
String val = (String) e.getValue();
|
2010-03-25 20:25:03 +00:00
|
|
|
buf.append('[').append(_(DataHelper.stripHTML(name))).append('=').append(DataHelper.stripHTML(val)).append("] ");
|
2009-10-17 23:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
buf.append("</td></tr>\n");
|
|
|
|
if (full) {
|
2010-12-05 04:05:20 +00:00
|
|
|
buf.append("<tr><td>" + _("Stats") + ": <br><code>");
|
2011-12-23 21:41:58 +00:00
|
|
|
Map p = info.getOptionsMap();
|
|
|
|
for (Map.Entry e : (Set<Map.Entry>) p.entrySet()) {
|
|
|
|
String key = (String) e.getKey();
|
|
|
|
String val = (String) e.getValue();
|
2009-10-17 23:16:53 +00:00
|
|
|
buf.append(DataHelper.stripHTML(key)).append(" = ").append(DataHelper.stripHTML(val)).append("<br>\n");
|
|
|
|
}
|
|
|
|
buf.append("</code></td></tr>\n");
|
|
|
|
}
|
2011-03-12 16:11:10 +00:00
|
|
|
buf.append("</table>\n");
|
2009-10-17 23:16:53 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 17:11:20 +00:00
|
|
|
private static final int SSU = 1;
|
|
|
|
private static final int SSUI = 2;
|
|
|
|
private static final int NTCP = 4;
|
|
|
|
private static final String[] TNAMES = { _x("Hidden or starting up"), _x("SSU"), _x("SSU with introducers"), "",
|
|
|
|
_x("NTCP"), _x("NTCP and SSU"), _x("NTCP and SSU with introducers"), "" };
|
|
|
|
/**
|
|
|
|
* what transport types
|
|
|
|
*/
|
2011-04-10 18:22:43 +00:00
|
|
|
private static int classifyTransports(RouterInfo info) {
|
2009-11-09 17:11:20 +00:00
|
|
|
int rv = 0;
|
2011-04-10 18:22:43 +00:00
|
|
|
for (RouterAddress addr : info.getAddresses()) {
|
2009-11-09 17:11:20 +00:00
|
|
|
String style = addr.getTransportStyle();
|
|
|
|
if (style.equals("NTCP")) {
|
|
|
|
rv |= NTCP;
|
|
|
|
} else if (style.equals("SSU")) {
|
2011-12-23 21:41:58 +00:00
|
|
|
if (addr.getOption("iport0") != null)
|
2009-11-09 17:11:20 +00:00
|
|
|
rv |= SSUI;
|
|
|
|
else
|
|
|
|
rv |= SSU;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-10-18 14:06:07 +00:00
|
|
|
/** translate a string */
|
|
|
|
private String _(String s) {
|
|
|
|
return Messages.getString(s, _context);
|
|
|
|
}
|
2009-10-29 23:22:51 +00:00
|
|
|
|
2009-11-09 17:11:20 +00:00
|
|
|
/** tag only */
|
|
|
|
private static final String _x(String s) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2009-10-29 23:22:51 +00:00
|
|
|
/**
|
|
|
|
* translate a string with a parameter
|
|
|
|
* This is a lot more expensive than _(s), so use sparingly.
|
|
|
|
*
|
|
|
|
* @param s string to be translated containing {0}
|
|
|
|
* The {0} will be replaced by the parameter.
|
|
|
|
* Single quotes must be doubled, i.e. ' -> '' in the string.
|
|
|
|
* @param o parameter, not translated.
|
|
|
|
* To tranlslate parameter also, use _("foo {0} bar", _("baz"))
|
|
|
|
* Do not double the single quotes in the parameter.
|
|
|
|
* Use autoboxing to call with ints, longs, floats, etc.
|
|
|
|
*/
|
|
|
|
private String _(String s, Object o) {
|
|
|
|
return Messages.getString(s, o, _context);
|
|
|
|
}
|
2009-10-17 23:16:53 +00:00
|
|
|
}
|