use of net.i2p.data.Hash in project i2p.i2p by i2p.
the class NetDbRenderer method renderLeaseSetHTML.
/**
* @param debug @since 0.7.14 sort by distance from us, display
* median distance, and other stuff, useful when floodfill
*/
public void renderLeaseSetHTML(Writer out, boolean debug) throws IOException {
StringBuilder buf = new StringBuilder(4 * 1024);
if (debug)
buf.append("<p id=\"debugmode\">Debug mode - Sorted by hash distance, closest first</p>\n");
Hash ourRKey;
Set<LeaseSet> leases;
DecimalFormat fmt;
if (debug) {
ourRKey = _context.routerHash();
leases = new TreeSet<LeaseSet>(new LeaseSetRoutingKeyComparator(ourRKey));
fmt = new DecimalFormat("#0.00");
} else {
ourRKey = null;
leases = new TreeSet<LeaseSet>(new LeaseSetComparator());
fmt = null;
}
leases.addAll(_context.netDb().getLeases());
int medianCount = 0;
int rapCount = 0;
BigInteger median = null;
int c = 0;
// Summary
FloodfillNetworkDatabaseFacade netdb = (FloodfillNetworkDatabaseFacade) _context.netDb();
if (debug) {
buf.append("<table id=\"leasesetdebug\">\n");
} else {
buf.append("<table id=\"leasesetsummary\">\n");
}
buf.append("<tr><th colspan=\"3\">Leaseset Summary</th>").append("<th><a href=\"/configadvanced\" title=\"").append(_t("Manually Configure Floodfill Participation")).append("\">[").append(_t("Configure Floodfill Participation")).append("]</a></th></tr>\n").append("<tr><td><b>Total Leasesets:</b></td><td colspan=\"3\">").append(leases.size()).append("</td></tr>\n");
if (debug) {
buf.append("<tr><td><b>Published (RAP) Leasesets:</b></td><td colspan=\"3\">").append(netdb.getKnownLeaseSets()).append("</td></tr>\n").append("<tr><td><b>Mod Data:</b></td><td>").append(DataHelper.getUTF8(_context.routerKeyGenerator().getModData())).append("</td>").append("<td><b>Last Changed:</b></td><td>").append(new Date(_context.routerKeyGenerator().getLastChanged())).append("</td></tr>\n").append("<tr><td><b>Next Mod Data:</b></td><td>").append(DataHelper.getUTF8(_context.routerKeyGenerator().getNextModData())).append("</td>").append("<td><b>Change in:</b></td><td>").append(DataHelper.formatDuration(_context.routerKeyGenerator().getTimeTillMidnight())).append("</td></tr>\n");
}
int ff = _context.peerManager().getPeersByCapability(FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL).size();
buf.append("<tr><td><b>Known Floodfills:</b></td><td colspan=\"3\">").append(ff).append("</td></tr>\n").append("<tr><td><b>Currently Floodfill?</b></td><td colspan=\"3\">").append(netdb.floodfillEnabled() ? "yes" : "no").append("</td></tr>\n");
buf.append("</table>\n");
if (leases.isEmpty()) {
if (!debug)
buf.append("<div id=\"noleasesets\"><i>").append(_t("No Leasesets currently active.")).append("</i></div>");
} else {
if (debug) {
// Find the center of the RAP leasesets
for (LeaseSet ls : leases) {
if (ls.getReceivedAsPublished())
rapCount++;
}
medianCount = rapCount / 2;
}
boolean linkSusi = WebAppStarter.isWebAppRunning("susidns");
long now = _context.clock().now();
buf.append("<div class=\"leasesets_container\">");
for (LeaseSet ls : leases) {
Destination dest = ls.getDestination();
Hash key = dest.calculateHash();
buf.append("<table class=\"leaseset\">\n").append("<tr><th><b>").append(_t("LeaseSet")).append(":</b> <code>").append(key.toBase64()).append("</code>");
if (_context.keyRing().get(key) != null)
buf.append(" (").append(_t("Encrypted")).append(')');
buf.append("</th>");
if (_context.clientManager().isLocal(dest)) {
buf.append("<th><a href=\"tunnels#" + key.toBase64().substring(0, 4) + "\">" + _t("Local") + "</a> ");
boolean unpublished = !_context.clientManager().shouldPublishLeaseSet(key);
if (unpublished)
buf.append("<b>").append(_t("Unpublished")).append("</b> ");
buf.append("<b>").append(_t("Destination")).append(":</b> ");
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(key);
if (in != null && in.getDestinationNickname() != null)
buf.append(in.getDestinationNickname());
else
buf.append(dest.toBase64().substring(0, 6));
buf.append("</th></tr>\n<tr><td");
// If the dest is published but not in the addressbook, an extra
// <td> is appended with an "Add to addressbook" link, so this
// <td> should not span 2 columns.
String host = null;
if (!unpublished) {
host = _context.namingService().reverseLookup(dest);
}
if (unpublished || host != null || !linkSusi) {
buf.append(" colspan=\"2\"");
}
buf.append(">");
String b32 = dest.toBase32();
buf.append("<a href=\"http://").append(b32).append("\">").append(b32).append("</a></td>");
if (linkSusi && !unpublished) {
if (host == null) {
buf.append("<td class=\"addtobook\" colspan=\"2\">").append("<a title=\"").append(_t("Add to addressbook")).append("\" href=\"/susidns/addressbook.jsp?book=private&destination=").append(dest.toBase64()).append("#add\">").append(_t("Add to local addressbook")).append("</a></td>");
}
}
// else probably a client
} else {
buf.append("<th><b>").append(_t("Destination")).append(":</b> ");
String host = _context.namingService().reverseLookup(dest);
if (host != null) {
buf.append("<a href=\"http://").append(host).append("/\">").append(host).append("</a></th>");
} else {
String b32 = dest.toBase32();
buf.append("<code>").append(dest.toBase64().substring(0, 6)).append("</code></th>").append("</tr>\n<tr><td");
if (!linkSusi)
buf.append(" colspan=\"2\"");
buf.append("><a href=\"http://").append(b32).append("\">").append(b32).append("</a></td>\n");
if (linkSusi) {
buf.append("<td class=\"addtobook\"><a title=\"").append(_t("Add to addressbook")).append("\" href=\"/susidns/addressbook.jsp?book=private&destination=").append(dest.toBase64()).append("#add\">").append(_t("Add to local addressbook")).append("</a></td>");
}
}
}
buf.append("</tr>\n<tr><td colspan=\"2\">\n");
long exp = ls.getLatestLeaseDate() - now;
if (exp > 0)
buf.append("<b>").append(_t("Expires in {0}", DataHelper.formatDuration2(exp))).append("</b>");
else
buf.append("<b>").append(_t("Expired {0} ago", DataHelper.formatDuration2(0 - exp))).append("</b>");
buf.append("</td></tr>\n");
if (debug) {
buf.append("<tr><td colspan=\"2\">");
buf.append("<b>RAP?</b> ").append(ls.getReceivedAsPublished());
buf.append(" <b>RAR?</b> ").append(ls.getReceivedAsReply());
BigInteger dist = HashDistance.getDistance(ourRKey, ls.getRoutingKey());
if (ls.getReceivedAsPublished()) {
if (c++ == medianCount)
median = dist;
}
buf.append(" <b>Distance: </b>").append(fmt.format(biLog2(dist)));
buf.append("</td></tr>\n<tr><td colspan=\"2\">");
// buf.append(dest.toBase32()).append("<br>");
buf.append("<b>Signature type:</b> ").append(dest.getSigningPublicKey().getType());
buf.append(" <b>Encryption Key:</b> ").append(ls.getEncryptionKey().toBase64().substring(0, 20)).append("…");
buf.append("</td></tr>\n<tr><td colspan=\"2\">");
buf.append("<b>Routing Key:</b> ").append(ls.getRoutingKey().toBase64());
buf.append("</td></tr>");
}
buf.append("<tr><td colspan=\"2\"><ul class=\"netdb_leases\">");
for (int i = 0; i < ls.getLeaseCount(); i++) {
Lease lease = ls.getLease(i);
buf.append("<li><b>").append(_t("Lease")).append(' ').append(i + 1).append(":</b> <span class=\"netdb_gateway\" title=\"").append(_t("Gateway")).append("\"><img src=\"themes/console/images/info/gateway.png\" alt=\"").append(_t("Gateway")).append("\"></span> <span class=\"tunnel_peer\">");
buf.append(_context.commSystem().renderPeerHTML(lease.getGateway()));
buf.append("</span> <span class=\"netdb_tunnel\">").append(_t("Tunnel")).append(" <span class=\"tunnel_id\">").append(lease.getTunnelId().getTunnelId()).append("</span></span> ");
if (debug) {
long exl = lease.getEndDate().getTime() - now;
if (exl > 0)
buf.append("<b class=\"netdb_expiry\">").append(_t("Expires in {0}", DataHelper.formatDuration2(exl))).append("</b>");
else
buf.append("<b class=\"netdb_expiry\">").append(_t("Expired {0} ago", DataHelper.formatDuration2(0 - exl))).append("</b>");
}
buf.append("</li>");
}
buf.append("</ul></td></tr>\n");
buf.append("</table>\n");
out.write(buf.toString());
buf.setLength(0);
}
// for each
if (debug) {
buf.append("<table id=\"leasesetdebug\"><tr><td><b>Network data (only valid if floodfill):</b></td><td colspan=\"3\">");
// buf.append("</b></p><p><b>Center of Key Space (router hash): " + ourRKey.toBase64());
if (median != null) {
double log2 = biLog2(median);
buf.append("</td></tr>").append("<tr><td><b>Median distance (bits):</b></td><td colspan=\"3\">").append(fmt.format(log2)).append("</td></tr>\n");
// 2 for 4 floodfills... -1 for median
// this can be way off for unknown reasons
int total = (int) Math.round(Math.pow(2, 2 + 256 - 1 - log2));
buf.append("<tr><td><b>Estimated total floodfills:</b></td><td colspan=\"3\">").append(total).append("</td></tr>\n");
buf.append("<tr><td><b>Estimated total leasesets:</b></td><td colspan=\"3\">").append(total * rapCount / 4);
} else {
buf.append("<i>Not floodfill or no data.</i>");
}
buf.append("</td></tr></table>\n");
}
// median table
buf.append("</div>");
}
// !empty
out.write(buf.toString());
out.flush();
}
use of net.i2p.data.Hash in project i2p.i2p by i2p.
the class OldConsoleHelper method renderStatusHTML.
/**
* this is for oldconsole.jsp, pretty much unused except as a way to get memory info,
* so let's comment out the rest, it is available elsewhere, and we don't really
* want to spend a minute rendering a multi-megabyte page in memory.
*
* @since 0.9 moved from Router.java
*/
private void renderStatusHTML(Writer out) throws IOException {
StringBuilder buf = new StringBuilder(4 * 1024);
// Please don't change the text or formatting, tino matches it in his scripts
Hash h = _context.routerHash();
if (h != null)
buf.append("<b>Router: </b> ").append(h.toBase64()).append("<br>\n");
buf.append("<b>As of: </b> ").append(new Date(_context.clock().now())).append("<br>\n");
buf.append("<b>RouterUptime: </b> ").append(DataHelper.formatDuration(_context.router().getUptime())).append(" <br>\n");
buf.append("<b>Started on: </b> ").append(new Date(_context.router().getWhenStarted())).append("<br>\n");
buf.append("<b>Clock offset: </b> ").append(_context.clock().getOffset()).append("ms (OS time: ").append(new Date(_context.clock().now() - _context.clock().getOffset())).append(")<br>\n");
buf.append("<b>RouterVersion:</b> ").append(RouterVersion.FULL_VERSION).append(" / SDK: ").append(CoreVersion.VERSION).append("<br>\n");
long tot = Runtime.getRuntime().totalMemory() / 1024;
long free = Runtime.getRuntime().freeMemory() / 1024;
buf.append("<b>Memory:</b> In use: ").append((tot - free)).append("KB Free: ").append(free).append("KB <br>\n");
out.write(buf.toString());
out.flush();
}
use of net.i2p.data.Hash in project i2p.i2p by i2p.
the class ProfileOrganizerRenderer method renderStatusHTML.
/**
* @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();
long hideBefore = now - 90 * 60 * 1000;
Set<PeerProfile> order = new TreeSet<PeerProfile>(mode == 2 ? new HashComparator() : new ProfileComparator());
int older = 0;
int standard = 0;
for (Hash peer : peers) {
if (_organizer.getUs().equals(peer))
continue;
PeerProfile prof = _organizer.getProfileNonblocking(peer);
if (prof == null)
continue;
if (mode == 2) {
RouterInfo info = _context.netDb().lookupRouterInfoLocally(peer);
if (info != null && info.getCapabilities().indexOf('f') >= 0)
order.add(prof);
continue;
}
if (prof.getLastSendSuccessful() <= hideBefore) {
older++;
continue;
}
if ((!full) && !_organizer.isHighCapacity(peer)) {
standard++;
continue;
}
order.add(prof);
}
int fast = 0;
int reliable = 0;
int integrated = 0;
StringBuilder buf = new StringBuilder(16 * 1024);
// //
if (mode < 2) {
// buf.append("<h2>").append(_t("Peer Profiles")).append("</h2>\n<p>");
buf.append("<p id=\"profiles_overview\" class=\"infohelp\">");
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');
if (standard > 0)
buf.append("<a href=\"/profiles?f=1\">").append(ngettext("Hiding 1 standard profile.", "Hiding {0} standard profiles.", standard)).append("</a>\n");
buf.append("</p>");
buf.append("<div class=\"widescroll\"><table id=\"profilelist\">");
buf.append("<tr>");
buf.append("<th>").append(_t("Peer")).append("</th>");
buf.append("<th>").append(_t("Groups")).append("</th>");
buf.append("<th>").append(_t("Caps")).append("</th>");
buf.append("<th>").append(_t("Version")).append("</th>");
buf.append("<th>").append(_t("Speed")).append("</th>");
buf.append("<th>").append(_t("Capacity")).append("</th>");
buf.append("<th>").append(_t("Integration")).append("</th>");
buf.append("<th>").append(_t("Status")).append("</th>");
buf.append("<th>").append(_t("View/Edit")).append("</th>");
buf.append("</tr>");
int prevTier = 1;
for (PeerProfile prof : order) {
Hash peer = prof.getPeer();
int tier = 0;
boolean isIntegrated = false;
if (_organizer.isFast(peer)) {
tier = 1;
fast++;
reliable++;
} else if (_organizer.isHighCapacity(peer)) {
tier = 2;
reliable++;
} else if (_organizer.isFailing(peer)) {
} else {
tier = 3;
}
if (_organizer.isWellIntegrated(peer)) {
isIntegrated = true;
integrated++;
}
if (tier != prevTier)
buf.append("<tr><td colspan=\"9\"><hr></td></tr>\n");
prevTier = tier;
buf.append("<tr><td align=\"center\" nowrap>");
buf.append(_context.commSystem().renderPeerHTML(peer));
// debug
// if(prof.getIsExpandedDB())
// buf.append(" ** ");
buf.append("</td><td align=\"center\">");
switch(tier) {
case 1:
buf.append(_t("Fast, High Capacity"));
break;
case 2:
buf.append(_t("High Capacity"));
break;
case 3:
buf.append(_t("Standard"));
break;
default:
buf.append(_t("Failing"));
break;
}
if (isIntegrated)
buf.append(", ").append(_t("Integrated"));
RouterInfo info = _context.netDb().lookupRouterInfoLocally(peer);
if (info != null) {
// prevent HTML injection in the caps and version
buf.append("<td align=\"right\">").append(DataHelper.stripHTML(info.getCapabilities()));
} else {
buf.append("<td align=\"right\"><i>").append(_t("unknown")).append("</i></td>");
}
buf.append("<td align=\"right\">");
String v = info != null ? info.getOption("router.version") : null;
if (v != null)
buf.append(DataHelper.stripHTML(v));
buf.append("</td><td align=\"right\">").append(num(prof.getSpeedValue()));
long bonus = prof.getSpeedBonus();
if (bonus != 0) {
if (bonus > 0)
buf.append(" (+");
else
buf.append(" (");
buf.append(bonus).append(')');
}
buf.append("</td><td align=\"right\">").append(num(prof.getCapacityValue()));
bonus = prof.getCapacityBonus();
if (bonus != 0) {
if (bonus > 0)
buf.append(" (+");
else
buf.append(" (");
buf.append(bonus).append(')');
}
buf.append("</td><td align=\"right\">").append(num(prof.getIntegrationValue()));
buf.append("</td><td align=\"center\">");
boolean ok = true;
if (_context.banlist().isBanlisted(peer)) {
buf.append(_t("Banned"));
ok = false;
}
if (prof.getIsFailing()) {
buf.append(' ').append(_t("Failing"));
ok = false;
}
if (_context.commSystem().wasUnreachable(peer)) {
buf.append(' ').append(_t("Unreachable"));
ok = false;
}
RateAverages ra = RateAverages.getTemp();
Rate failed = prof.getTunnelHistory().getFailedRate().getRate(30 * 60 * 1000);
long fails = failed.computeAverages(ra, false).getTotalEventCount();
if (ok && fails == 0) {
buf.append(_t("OK"));
} else if (fails > 0) {
Rate accepted = prof.getTunnelCreateResponseTime().getRate(30 * 60 * 1000);
long total = fails + accepted.computeAverages(ra, false).getTotalEventCount();
if (// hide if < 10%
total / fails <= 10)
buf.append(' ').append(fails).append('/').append(total).append(' ').append(_t("Test Fails"));
}
buf.append(" </td>");
// buf.append("<td nowrap align=\"center\"><a target=\"_blank\" href=\"dumpprofile.jsp?peer=")
// .append(peer.toBase64().substring(0,6)).append("\">").append(_t("profile")).append("</a>");
buf.append("<td nowrap align=\"center\"><a href=\"viewprofile?peer=").append(peer.toBase64()).append("\">").append(_t("profile")).append("</a>");
buf.append(" <a title=\"").append(_t("Configure peer")).append("\" href=\"configpeer?peer=").append(peer.toBase64()).append("\">+-</a></td>\n");
buf.append("</tr>");
// let's not build the whole page in memory (~500 bytes per peer)
out.write(buf.toString());
buf.setLength(0);
}
buf.append("</table></div>");
// //
// // don't bother reindenting
// //
} else {
// buf.append("<h2><a name=\"flood\"></a>").append(_t("Floodfill and Integrated Peers"))
// .append(" (").append(integratedPeers.size()).append(")</h2>\n");
buf.append("<div class=\"widescroll\"><table id=\"floodfills\">");
buf.append("<tr class=\"smallhead\">");
buf.append("<th>").append(_t("Peer")).append("</th>");
buf.append("<th>").append(_t("Caps")).append("</th>");
buf.append("<th>").append(_t("Integ. Value")).append("</th>");
buf.append("<th>").append(_t("Last Heard About")).append("</th>");
buf.append("<th>").append(_t("Last Heard From")).append("</th>");
buf.append("<th>").append(_t("Last Good Send")).append("</th>");
buf.append("<th>").append(_t("Last Bad Send")).append("</th>");
buf.append("<th>").append(_t("10m Resp. Time")).append("</th>");
buf.append("<th>").append(_t("1h Resp. Time")).append("</th>");
buf.append("<th>").append(_t("1d Resp. Time")).append("</th>");
buf.append("<th>").append(_t("Last Good Lookup")).append("</th>");
buf.append("<th>").append(_t("Last Bad Lookup")).append("</th>");
buf.append("<th>").append(_t("Last Good Store")).append("</th>");
buf.append("<th>").append(_t("Last Bad Store")).append("</th>");
buf.append("<th>").append(_t("1h Fail Rate")).append("</th>");
buf.append("<th>").append(_t("1d Fail Rate")).append("</th>");
buf.append("</tr>");
RateAverages ra = RateAverages.getTemp();
for (PeerProfile prof : order) {
Hash peer = prof.getPeer();
buf.append("<tr><td align=\"center\" nowrap>");
buf.append(_context.commSystem().renderPeerHTML(peer));
buf.append("</td>");
RouterInfo info = _context.netDb().lookupRouterInfoLocally(peer);
if (info != null)
buf.append("<td align=\"center\">").append(DataHelper.stripHTML(info.getCapabilities())).append("</td>");
else
buf.append("<td> </td>");
buf.append("<td align=\"right\">").append(num(prof.getIntegrationValue())).append("</td>");
buf.append("<td align=\"right\">").append(formatInterval(now, prof.getLastHeardAbout())).append("</td>");
buf.append("<td align=\"right\">").append(formatInterval(now, prof.getLastHeardFrom())).append("</td>");
buf.append("<td align=\"right\">").append(formatInterval(now, prof.getLastSendSuccessful())).append("</td>");
buf.append("<td align=\"right\">").append(formatInterval(now, prof.getLastSendFailed())).append("</td>");
buf.append("<td align=\"right\">").append(avg(prof, 10 * 60 * 1000l, ra)).append("</td>");
buf.append("<td align=\"right\">").append(avg(prof, 60 * 60 * 1000l, ra)).append("</td>");
buf.append("<td align=\"right\">").append(avg(prof, 24 * 60 * 60 * 1000l, ra)).append("</td>");
DBHistory dbh = prof.getDBHistory();
if (dbh != null) {
buf.append("<td align=\"right\">").append(formatInterval(now, dbh.getLastLookupSuccessful())).append("</td>");
buf.append("<td align=\"right\">").append(formatInterval(now, dbh.getLastLookupFailed())).append("</td>");
buf.append("<td align=\"right\">").append(formatInterval(now, dbh.getLastStoreSuccessful())).append("</td>");
buf.append("<td align=\"right\">").append(formatInterval(now, dbh.getLastStoreFailed())).append("</td>");
buf.append("<td align=\"right\">").append(davg(dbh, 60 * 60 * 1000l, ra)).append("</td>");
buf.append("<td align=\"right\">").append(davg(dbh, 24 * 60 * 60 * 1000l, ra)).append("</td>");
} else {
for (int i = 0; i < 6; i++) buf.append("<td align=\"right\">").append(_t(NA));
}
buf.append("</tr>\n");
}
buf.append("</table></div>");
// //
// // don't bother reindenting
// //
}
if (mode < 2) {
buf.append("<h3 class=\"tabletitle\">").append(_t("Thresholds")).append("</h3>\n").append("<table id=\"thresholds\"><tbody>").append("<tr><th><b>").append(_t("Speed")).append(": </b>").append(num(_organizer.getSpeedThreshold())).append("</th><th><b>").append(_t("Capacity")).append(": </b>").append(num(_organizer.getCapacityThreshold())).append("</th><th><b>").append(_t("Integration")).append(": </b>").append(num(_organizer.getIntegrationThreshold())).append("</th></tr><tr><td>").append(fast).append(' ').append(_t("fast peers")).append("</td><td>").append(reliable).append(' ').append(_t("high capacity peers")).append("</td><td>").append(integrated).append(' ').append(_t(" well integrated peers")).append("</td></tr></tbody></table>\n");
buf.append("<h3 class=\"tabletitle\">").append(_t("Definitions")).append("</h3>\n").append("<table id=\"profile_defs\"><tbody>");
buf.append("<tr><td><b>").append(_t("groups")).append(":</b></td><td>").append(_t("as determined by the profile organizer")).append("</td></tr>");
buf.append("<tr><td><b>").append(_t("caps")).append(":</b></td><td>").append(_t("capabilities in the netDb, not used to determine profiles")).append("</td></tr>");
buf.append("<tr id=\"capabilities_key\"><td colspan=\"2\"><table><tbody>");
buf.append("<tr><td> </td>").append("<td><b>B</b></td><td>").append(_t("SSU Testing")).append("</td>").append("<td><b>C</b></td><td>").append(_t("SSU Introducer")).append("</td>").append("<td> </td></tr>");
buf.append("<tr><td> </td>").append("<td><b>f</b></td><td>").append(_t("Floodfill")).append("</td>").append("<td><b>H</b></td><td>").append(_t("Hidden")).append("</td>").append("<td> </td></tr>");
buf.append("<tr><td> </td>").append("<td><b>K</b></td><td>").append(_t("Under {0} shared bandwidth", Router.MIN_BW_L + " KBps")).append("</td>").append("<td><b>L</b></td><td>").append(_t("{0} shared bandwidth", range(Router.MIN_BW_L, Router.MIN_BW_M))).append("</td>").append("<td> </td></tr>");
buf.append("<tr><td> </td>").append("<td><b>M</b></td><td>").append(_t("{0} shared bandwidth", range(Router.MIN_BW_M, Router.MIN_BW_N))).append("</td>").append("<td><b>N</b></td><td>").append(_t("{0} shared bandwidth", range(Router.MIN_BW_N, Router.MIN_BW_O))).append("</td>").append("<td> </td></tr>");
buf.append("<tr><td> </td>").append("<td><b>O</b></td><td>").append(_t("{0} shared bandwidth", range(Router.MIN_BW_O, Router.MIN_BW_P))).append("</td>").append("<td><b>P</b></td><td>").append(_t("{0} shared bandwidth", range(Router.MIN_BW_P, Router.MIN_BW_X))).append("</td>").append("<td> </td></tr>");
buf.append("<tr><td> </td>").append("<td><b>R</b></td><td>").append(_t("Reachable")).append("</td>").append("<td><b>U</b></td><td>").append(_t("Unreachable")).append("</td>").append("<td> </td></tr>");
buf.append("<tr><td> </td>").append("<td><b>X</b></td><td>").append(_t("Over {0} shared bandwidth", Math.round(Router.MIN_BW_X * 1.024f) + " KBps")).append("</td>").append("<td> </td><td> </td><td> </td></tr>");
buf.append("<tr><td> </td><td colspan=\"5\">").append(_t("Note: For P and X bandwidth tiers, O is included for the purpose of backward compatibility in the NetDB.")).append("</tr>");
// profile_defs
buf.append("</tbody></table></td></tr>");
buf.append("<tr><td><b>").append(_t("speed")).append(":</b></td><td>").append(_t("peak throughput (bytes per second) over a 1 minute period that the peer has sustained in a single tunnel")).append("</td></tr>");
buf.append("<tr><td><b>").append(_t("capacity")).append(":</b></td><td>").append(_t("how many tunnels can we ask them to join in an hour?")).append("</td></tr>");
buf.append("<tr><td><b>").append(_t("integration")).append(":</b></td><td>").append(_t("how many new peers have they told us about lately?")).append("</td></tr>");
buf.append("<tr><td><b>").append(_t("status")).append(":</b></td><td>").append(_t("is the peer banned, or unreachable, or failing tunnel tests?")).append("</td></tr>");
// thresholds
buf.append("</tbody></table>\n");
// //
// // don't bother reindenting
// //
}
// mode < 2
out.write(buf.toString());
out.flush();
}
use of net.i2p.data.Hash in project i2p.i2p by i2p.
the class I2PSocketManagerFull method connect.
/**
* Create a new connected socket. Blocks until the socket is created,
* unless the connectDelay option (i2p.streaming.connectDelay) is
* set and greater than zero. If so this will return immediately,
* and the client may quickly write initial data to the socket and
* this data will be bundled in the SYN packet.
*
* @param peer Destination to connect to
* @param options I2P socket options to be used for connecting, may be null
*
* @return I2PSocket if successful
* @throws NoRouteToHostException if the peer is not found or not reachable
* @throws I2PException if there is some other I2P-related problem
*/
public I2PSocket connect(Destination peer, I2PSocketOptions options) throws I2PException, NoRouteToHostException {
if (peer == null)
throw new NullPointerException();
if (options == null)
options = _defaultOptions;
ConnectionOptions opts = null;
if (options instanceof ConnectionOptions)
opts = new ConnectionOptions((ConnectionOptions) options);
else
opts = new ConnectionOptions(options);
if (_log.shouldLog(Log.INFO))
_log.info("Connecting to " + peer.calculateHash().toBase64().substring(0, 6) + " with options: " + opts);
// pick the subsession here
I2PSession session = _session;
if (!_subsessions.isEmpty()) {
updateUserDsaList();
Hash h = peer.calculateHash();
SigAlgo myAlgo = session.getMyDestination().getSigType().getBaseAlgorithm();
if ((myAlgo == SigAlgo.EC && _ecUnsupported.contains(h)) || (myAlgo == SigAlgo.EdDSA && _edUnsupported.contains(h)) || (!_userDsaOnly.isEmpty() && _userDsaOnly.contains(h))) {
// FIXME just taking the first one for now
for (I2PSession sess : _subsessions) {
if (sess.getMyDestination().getSigType() == SigType.DSA_SHA1) {
session = sess;
break;
}
}
}
}
verifySession(session);
// the following blocks unless connect delay > 0
Connection con = _connectionManager.connect(peer, opts, session);
if (con == null)
throw new TooManyStreamsException("Too many streams, max " + _defaultOptions.getMaxConns());
I2PSocketFull socket = new I2PSocketFull(con, _context);
con.setSocket(socket);
if (con.getConnectionError() != null) {
con.disconnect(false);
throw new NoRouteToHostException(con.getConnectionError());
}
return socket;
}
use of net.i2p.data.Hash in project i2p.i2p by i2p.
the class SummaryHelper method getDestinations.
/**
* Client destinations connected locally.
*
* @return html section summary
*/
public String getDestinations() {
// convert the set to a list so we can sort by name and not lose duplicates
List<Destination> clients = new ArrayList<Destination>(_context.clientManager().listClients());
StringBuilder buf = new StringBuilder(512);
boolean link = WebAppStarter.isWebAppRunning("i2ptunnel");
buf.append("<h3>");
if (link) {
buf.append("<a href=\"/i2ptunnelmgr\" target=\"_top\" title=\"").append(_t("Add/remove/edit & control your client and server tunnels")).append("\">");
}
buf.append(_t("Local Tunnels"));
if (link) {
buf.append("</a>");
}
buf.append("</h3><hr class=\"b\">");
if (!clients.isEmpty()) {
Collections.sort(clients, new AlphaComparator());
buf.append("<table id=\"sb_localtunnels\">");
for (Destination client : clients) {
String name = getName(client);
Hash h = client.calculateHash();
buf.append("<tr><td align=\"right\"><img src=\"/themes/console/images/");
if (_context.clientManager().shouldPublishLeaseSet(h))
buf.append("server.png\" alt=\"Server\" title=\"").append(_t("Hidden Service")).append("\">");
else
buf.append("client.png\" alt=\"Client\" title=\"").append(_t("Client")).append("\">");
buf.append("</td><td align=\"left\"><b><a href=\"tunnels#").append(h.toBase64().substring(0, 4));
buf.append("\" target=\"_top\" title=\"").append(_t("Show tunnels")).append("\">");
// Increase permitted max length of tunnel name & handle overflow with css
if (name.length() <= 32)
buf.append(DataHelper.escapeHTML(name));
else
buf.append(DataHelper.escapeHTML(ServletUtil.truncate(name, 29))).append("…");
buf.append("</a></b></td>\n");
LeaseSet ls = _context.netDb().lookupLeaseSetLocally(h);
if (ls != null && _context.tunnelManager().getOutboundClientTunnelCount(h) > 0) {
long timeToExpire = ls.getEarliestLeaseDate() - _context.clock().now();
if (timeToExpire < 0) {
// red or yellow light
buf.append("<td><img src=\"/themes/console/images/local_inprogress.png\" alt=\"").append(_t("Rebuilding")).append("…\" title=\"").append(_t("Leases expired")).append(" ").append(DataHelper.formatDuration2(0 - timeToExpire));
buf.append(" ").append(_t("ago")).append(". ").append(_t("Rebuilding")).append("…\"></td></tr>\n");
} else {
// green light
buf.append("<td><img src=\"/themes/console/images/local_up.png\" alt=\"Ready\" title=\"").append(_t("Ready")).append("\"></td></tr>\n");
}
} else {
// yellow light
buf.append("<td><img src=\"/themes/console/images/local_inprogress.png\" alt=\"").append(_t("Building")).append("…\" title=\"").append(_t("Building tunnels")).append("…\"></td></tr>\n");
}
}
buf.append("</table>");
} else {
buf.append("<center><i>").append(_t("none")).append("</i></center>");
}
return buf.toString();
}
Aggregations