Skip to content

Commit

Permalink
Merge branch 'i2p.i2p.2.7.0-organize-leasesets-and-better-crossrefere…
Browse files Browse the repository at this point in the history
…ncing' into 'master'

Console/NetDB: Tweak design of client netDb page

See merge request i2p-hackers/i2p.i2p!218
  • Loading branch information
eyedeekay committed Sep 23, 2024
2 parents 4eb70e9 + 63e13c8 commit 610baa8
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;

import net.i2p.crypto.EncType;
import net.i2p.crypto.SigType;
import net.i2p.data.DataHelper;
import net.i2p.data.Hash;
import net.i2p.data.LeaseSet;
import net.i2p.util.SystemVersion;
import net.i2p.router.sybil.Analysis;
import net.i2p.router.web.FormHandler;
Expand Down Expand Up @@ -41,7 +43,7 @@ public class NetDbHelper extends FormHandler {

private static final int DEFAULT_LIMIT = SystemVersion.isARM() ? 250 : 500;
private static final int DEFAULT_PAGE = 0;

private static final String titles[] =
{_x("Summary"), // 0
_x("Local Router"), // 1
Expand Down Expand Up @@ -70,7 +72,7 @@ public class NetDbHelper extends FormHandler {
"", // 9
"?l=7", // 10
};


public void setRouter(String r) {
if (r != null && r.length() > 0)
Expand Down Expand Up @@ -238,22 +240,22 @@ public void setPage(String f) {
public void setSort(String f) {
_sort = f;
}

/** @since 0.9.58 */
public void setIntros(String f) {
try {
_icount = Integer.parseInt(f);
} catch (NumberFormatException nfe) {}
}

/**
* call for non-text-mode browsers
* @since 0.9.1
*/
public void allowGraphical() {
_graphical = true;
}

/**
* Override to save it
* @since 0.9.38
Expand Down Expand Up @@ -338,7 +340,9 @@ else if ((_mode == 13 || _mode == 16) && !_postOK)
} else if (_full == 4) {
renderLookupForm();
} else if (_clientOnly) {
for (Hash client : _context.clientManager().getPrimaryHashes()) {
TreeSet<Hash> hashes = new TreeSet<Hash>(new HashComparator());
hashes.addAll(_context.clientManager().getPrimaryHashes());
for (Hash client : hashes) {
renderer.renderLeaseSetHTML(_out, false, client);
}
} else {
Expand Down Expand Up @@ -430,7 +434,7 @@ private void renderNavBar() throws IOException {
* @since 0.9.28
*/
private void renderLookupForm() throws IOException {
_out.write("<form action=\"/netdb\" method=\"POST\">\n" +
_out.write("<form action=\"/netdb\" method=\"POST\">\n" +
"<input type=\"hidden\" name=\"nonce\" value=\"" + _newNonce + "\" >\n" +
"<table id=\"netdblookup\"><tr><th colspan=\"3\">Network Database Search</th></tr>\n" +
"<tr><td>Capabilities:</td><td><input type=\"text\" name=\"caps\"></td><td>e.g. f or XfR</td></tr>\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,9 @@ public void renderLeaseSetHTML(Writer out, boolean debug, Hash client) throws IO
fmt = null;
}
leases.addAll(netdb.getLeases());
LeaseSet myLeaseSet = new LeaseSet();
if (netdb.getLeases().size() > 0)
myLeaseSet = new ArrayList<LeaseSet>(netdb.getLeases()).get(0);
int medianCount = 0;
int rapCount = 0;
BigInteger median = null;
Expand All @@ -711,14 +714,77 @@ public void renderLeaseSetHTML(Writer out, boolean debug, Hash client) throws IO
buf.append("<table id=\"leasesetsummary\">\n");
}
if (client != null) {
buf.append("<tr><th colspan=\"3\">Leasesets for Client: ").append(client.toBase32()).append("</th><th></th></tr>\n");
buf.append("<tr><th colspan=\"3\">").append(_t("Leasesets for Client")).append(": ");
buf.append(client.toBase32());
if (netdb.getLeases().size() > 0) {
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(myLeaseSet.getHash());
if (in != null && in.getDestinationNickname() != null)
buf.append(" - ").append(DataHelper.escapeHTML(in.getDestinationNickname()));
buf.append("</th><th></th></tr>\n");
boolean unpublished = ! _context.clientManager().shouldPublishLeaseSet(myLeaseSet.getHash());
if (unpublished) {
buf.append("<tr><th colspan=\"3\">").append(_t("Local")).append(" ");
if (myLeaseSet.getType() == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2 || _context.keyRing().get(myLeaseSet.getHash()) != null)
buf.append(" <b>(").append(_t("Encrypted")).append(")</b>");
buf.append(_t("Unpublished")).append(" ");
} else {
buf.append("<tr><th colspan=\"3\">").append(_t("Local")).append(" ");
if (myLeaseSet.getType() == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2 || _context.keyRing().get(myLeaseSet.getHash()) != null)
buf.append(" <b>(").append(_t("Encrypted")).append(")</b>");
buf.append(_t("Published")).append(" ");
LeaseSet2 ls2 = (LeaseSet2) myLeaseSet;
long now = _context.clock().now();
long pub = now - ls2.getPublished();
buf.append(_t("{0} ago", DataHelper.formatDuration2(pub)));
long exp;
if (myLeaseSet.getType() == DatabaseEntry.KEY_TYPE_LEASESET) {
exp = ls2.getLatestLeaseDate() - now;
} else {
exp = ls2.getExpires()-now;
}
buf.append(" - ");
if (exp > 0)
buf.append(_t("Expires in {0}", DataHelper.formatDuration2(exp)));
else
buf.append(_t("Expired {0} ago", DataHelper.formatDuration2(0-exp)));
}
buf.append("</th><th></th></tr>\n");
buf.append("\n<tr><td colspan=\"2\"><ul class=\"netdb_leases\">");
boolean isMeta = myLeaseSet.getType() == DatabaseEntry.KEY_TYPE_META_LS2;
for (int i = 0; i < myLeaseSet.getLeaseCount(); i++) {
Lease lease = myLeaseSet.getLease(i);
buf.append("<li><b>").append(_t("Lease")).append(' ').append(i + 1).append(":</b> <span class=\"tunnel_peer\">");
buf.append(_context.commSystem().renderPeerHTML(lease.getGateway()));
buf.append("</span> ");
if (!isMeta) {
buf.append("<span class=\"netdb_tunnel\">").append(_t("Tunnel")).append(" <span class=\"tunnel_id\">")
.append(lease.getTunnelId().getTunnelId()).append("</span></span> ");
}
if (debug) {
long now = _context.clock().now();
long exl = lease.getEndTime() - now;
buf.append("<b class=\"netdb_expiry\">");
if (exl > 0)
buf.append(_t("Expires in {0}", DataHelper.formatDuration2(exl)));
else
buf.append(_t("Expired {0} ago", DataHelper.formatDuration2(0-exl)));
buf.append("</b>");
}
buf.append("</li>");
}
buf.append("</ul></td></tr>\n");
}
buf.append("<tr><td><b>Total Known Remote Leasesets:</b></td><td colspan=\"3\">").append(leases.size()-1).append("</td></tr>\n");
buf.append("</ul></td></tr>\n" +
"</table>\n");
} else {
buf.append("<tr><th colspan=\"3\">Leaseset Summary for Floodfill</th>" +
"<th><a href=\"/configadvanced\" title=\"").append(_t("Manually Configure Floodfill Participation")).append("\">[")
.append(_t("Configure Floodfill Participation"))
.append("]</a></th></tr>\n");
buf.append("<tr><td><b>Total Known Leasesets:</b></td><td colspan=\"3\">").append(leases.size()).append("</td></tr>\n");
}
buf.append("<tr><td><b>Total Leasesets:</b></td><td colspan=\"3\">").append(leases.size()).append("</td></tr>\n");

if (debug) {
RouterKeyGenerator gen = _context.routerKeyGenerator();
buf.append("<tr><td><b>Published (RAP) Leasesets:</b></td><td colspan=\"3\">").append(netdb.getKnownLeaseSets()).append("</td></tr>\n")
Expand Down Expand Up @@ -767,9 +833,11 @@ public void renderLeaseSetHTML(Writer out, boolean debug, Hash client) throws IO
} else {
distance = null;
}
renderLeaseSet(buf, ls, debug, now, linkSusi, distance);
out.write(buf.toString());
buf.setLength(0);
if (myLeaseSet == null || ls.getHash() != myLeaseSet.getHash()) {
renderLeaseSet(buf, ls, debug, now, linkSusi, distance);
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\">");
Expand Down Expand Up @@ -1221,7 +1289,7 @@ public void renderStatusHTML(Writer out, int pageSize, int page, int mode) throw
out.write(buf.toString());
out.flush();
}

/**
* Countries now in a separate bundle
* @param code two-letter country code
Expand Down Expand Up @@ -1478,7 +1546,7 @@ private static String getAltIPv6(String ip) {
} else if (ip.contains(":0:")) {
// convert to canonical
return Addresses.toCanonicalString(ip);
}
}
return null;
}

Expand Down
2 changes: 2 additions & 0 deletions apps/routerconsole/jsp/themes/console/dark/console.css
Original file line number Diff line number Diff line change
Expand Up @@ -7158,6 +7158,8 @@ img+tt {
-moz-column-gap: 10px;
-webkit-column-gap: 10px;
column-gap: 10px;
padding: 8px;
border: 1px groove rgb(82, 75, 94);
}

th code {
Expand Down
2 changes: 2 additions & 0 deletions apps/routerconsole/jsp/themes/console/light/console.css
Original file line number Diff line number Diff line change
Expand Up @@ -7230,6 +7230,8 @@ a[href^="configpeer?peer"]:hover {
-moz-column-gap: 10px;
-webkit-column-gap: 10px;
column-gap: 10px;
padding: 8px;
border: 1px groove rgb(82, 75, 94);
}

th code {
Expand Down

0 comments on commit 610baa8

Please sign in to comment.