From 63e13c8f2795f2e6171b21bd94dcef01ba38b8dd Mon Sep 17 00:00:00 2001 From: idk Date: Mon, 23 Sep 2024 00:00:57 +0000 Subject: [PATCH] Console/NetDB: Tweak design of client netDb page --- .../i2p/router/web/helpers/NetDbHelper.java | 18 ++-- .../i2p/router/web/helpers/NetDbRenderer.java | 82 +++++++++++++++++-- .../jsp/themes/console/dark/console.css | 2 + .../jsp/themes/console/light/console.css | 2 + 4 files changed, 90 insertions(+), 14 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbHelper.java index efc7c31a21..d7c48af8fc 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbHelper.java @@ -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; @@ -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 @@ -70,7 +72,7 @@ public class NetDbHelper extends FormHandler { "", // 9 "?l=7", // 10 }; - + public void setRouter(String r) { if (r != null && r.length() > 0) @@ -238,14 +240,14 @@ 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 @@ -253,7 +255,7 @@ public void setIntros(String f) { public void allowGraphical() { _graphical = true; } - + /** * Override to save it * @since 0.9.38 @@ -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 hashes = new TreeSet(new HashComparator()); + hashes.addAll(_context.clientManager().getPrimaryHashes()); + for (Hash client : hashes) { renderer.renderLeaseSetHTML(_out, false, client); } } else { @@ -430,7 +434,7 @@ private void renderNavBar() throws IOException { * @since 0.9.28 */ private void renderLookupForm() throws IOException { - _out.write("
\n" + + _out.write("\n" + "\n" + "\n" + "\n" + diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbRenderer.java index 608c664d7b..f2acb80b10 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbRenderer.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbRenderer.java @@ -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(netdb.getLeases()).get(0); int medianCount = 0; int rapCount = 0; BigInteger median = null; @@ -711,14 +714,77 @@ public void renderLeaseSetHTML(Writer out, boolean debug, Hash client) throws IO buf.append("
Network Database Search
Capabilities:e.g. f or XfR
\n"); } if (client != null) { - buf.append("\n"); + buf.append("\n"); + boolean unpublished = ! _context.clientManager().shouldPublishLeaseSet(myLeaseSet.getHash()); + if (unpublished) { + buf.append("\n"); + buf.append("\n\n"); + } + buf.append("\n"); + buf.append("\n" + + "
Leasesets for Client: ").append(client.toBase32()).append("
").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("
").append(_t("Local")).append(" "); + if (myLeaseSet.getType() == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2 || _context.keyRing().get(myLeaseSet.getHash()) != null) + buf.append(" (").append(_t("Encrypted")).append(")"); + buf.append(_t("Unpublished")).append(" "); + } else { + buf.append("
").append(_t("Local")).append(" "); + if (myLeaseSet.getType() == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2 || _context.keyRing().get(myLeaseSet.getHash()) != null) + buf.append(" (").append(_t("Encrypted")).append(")"); + 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("
    "); + boolean isMeta = myLeaseSet.getType() == DatabaseEntry.KEY_TYPE_META_LS2; + for (int i = 0; i < myLeaseSet.getLeaseCount(); i++) { + Lease lease = myLeaseSet.getLease(i); + buf.append("
  • ").append(_t("Lease")).append(' ').append(i + 1).append(": "); + buf.append(_context.commSystem().renderPeerHTML(lease.getGateway())); + buf.append(" "); + if (!isMeta) { + buf.append("").append(_t("Tunnel")).append(" ") + .append(lease.getTunnelId().getTunnelId()).append(" "); + } + if (debug) { + long now = _context.clock().now(); + long exl = lease.getEndTime() - now; + buf.append(""); + 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(""); + } + buf.append("
  • "); + } + buf.append("
Total Known Remote Leasesets:").append(leases.size()-1).append("
\n"); } else { buf.append("Leaseset Summary for Floodfill" + "[") .append(_t("Configure Floodfill Participation")) .append("]\n"); + buf.append("Total Known Leasesets:").append(leases.size()).append("\n"); } - buf.append("Total Leasesets:").append(leases.size()).append("\n"); + if (debug) { RouterKeyGenerator gen = _context.routerKeyGenerator(); buf.append("Published (RAP) Leasesets:").append(netdb.getKnownLeaseSets()).append("\n") @@ -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("
Network data (only valid if floodfill):"); @@ -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 @@ -1478,7 +1546,7 @@ private static String getAltIPv6(String ip) { } else if (ip.contains(":0:")) { // convert to canonical return Addresses.toCanonicalString(ip); - } + } return null; } diff --git a/apps/routerconsole/jsp/themes/console/dark/console.css b/apps/routerconsole/jsp/themes/console/dark/console.css index e395096c3c..0d43740091 100644 --- a/apps/routerconsole/jsp/themes/console/dark/console.css +++ b/apps/routerconsole/jsp/themes/console/dark/console.css @@ -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 { diff --git a/apps/routerconsole/jsp/themes/console/light/console.css b/apps/routerconsole/jsp/themes/console/light/console.css index 54dd8ad6e6..523280ecbb 100644 --- a/apps/routerconsole/jsp/themes/console/light/console.css +++ b/apps/routerconsole/jsp/themes/console/light/console.css @@ -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 {