I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Unverified Commit d60bb12d authored by zzz's avatar zzz
Browse files

Console: Netdb tab fixes and cleanup (Gitlab #465)

Reversions and fixes to changes since 2.3.0.
Subdbs may not contain RIs, so we don't need /netdb tabs for them.
Partially fixes Gitlab #465.

- Remove subdb RI tabs on /netdb
- HTML fixes on subdb LS tab
- Skip subdb LS tab if no clients
- We don't need both Hash and boolean args on renderLeaseSetHTML(), just use hash != null
- Rename/cleanup/restore tagged strings, don't tag strings only visible in advanced config
parent 5ea16d95
No related branches found
No related tags found
1 merge request!140Console: Netdb tab fixes and cleanup (Gitlab #465)
Pipeline #1206 passed
...@@ -6,14 +6,12 @@ import java.util.EnumSet; ...@@ -6,14 +6,12 @@ import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import net.i2p.crypto.EncType; import net.i2p.crypto.EncType;
import net.i2p.crypto.SigType; import net.i2p.crypto.SigType;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
import net.i2p.data.Hash; import net.i2p.data.Hash;
import net.i2p.data.router.RouterInfo;
import net.i2p.util.SystemVersion; import net.i2p.util.SystemVersion;
import net.i2p.router.sybil.Analysis; import net.i2p.router.sybil.Analysis;
import net.i2p.router.web.FormHandler; import net.i2p.router.web.FormHandler;
...@@ -49,16 +47,14 @@ public class NetDbHelper extends FormHandler { ...@@ -49,16 +47,14 @@ public class NetDbHelper extends FormHandler {
_x("Local Router"), // 1 _x("Local Router"), // 1
_x("Router Lookup"), // 2 _x("Router Lookup"), // 2
// advanced below here // advanced below here
_x("All Routers in Floodfill NetDB"), // 3 _x("All Routers"), // 3
_x("All Routers in Floodfill NetDB with Full Stats"), // 4 _x("All Routers with Full Stats"), // 4
_x("LeaseSets"), // 5 _x("LeaseSets"), // 5
"LeaseSet Debug", // 6 "LeaseSet Debug", // 6
"Sybil", // 7 "Sybil", // 7
"Advanced Lookup", // 8 "Advanced Lookup", // 8
"LeaseSet Lookup", // 9 "LeaseSet Lookup", // 9
_x("All Routers in Client NetDBs"), // 10 "LeaseSets (Client DBs)" // 10
_x("All Routers in Client NetDBs with Full Stats"), // 11
_x("LeaseSets in Client NetDBs"), // 12
}; };
private static final String links[] = private static final String links[] =
...@@ -72,9 +68,7 @@ public class NetDbHelper extends FormHandler { ...@@ -72,9 +68,7 @@ public class NetDbHelper extends FormHandler {
"?f=3", // 7 "?f=3", // 7
"?f=4", // 8 "?f=4", // 8
"", // 9 "", // 9
"?f=5", // 10 "?l=7", // 10
"?f=6", // 11
"?l=7", // 12
}; };
...@@ -251,14 +245,6 @@ public class NetDbHelper extends FormHandler { ...@@ -251,14 +245,6 @@ public class NetDbHelper extends FormHandler {
_icount = Integer.parseInt(f); _icount = Integer.parseInt(f);
} catch (NumberFormatException nfe) {} } catch (NumberFormatException nfe) {}
} }
public void setClientPage(String f) {
try {
} catch(Exception e){
//if (_log.shouldLog)
}
}
/** /**
* call for non-text-mode browsers * call for non-text-mode browsers
...@@ -326,27 +312,21 @@ public class NetDbHelper extends FormHandler { ...@@ -326,27 +312,21 @@ public class NetDbHelper extends FormHandler {
/** /**
* storeWriter() must be called previously * storeWriter() must be called previously
*/ */
public String getFloodfillNetDbSummary() { public String getNetDbSummary() {
return getNetDbSummary(null, false);
}
public String getNetDbSummary(Hash client, boolean clientOnly) {
NetDbRenderer renderer = new NetDbRenderer(_context); NetDbRenderer renderer = new NetDbRenderer(_context);
try { try {
if (client == null && !clientOnly) renderNavBar();
renderNavBar();
if (_routerPrefix != null || _version != null || _country != null || if (_routerPrefix != null || _version != null || _country != null ||
_family != null || _caps != null || _ip != null || _sybil != null || _family != null || _caps != null || _ip != null || _sybil != null ||
_port != 0 || _type != null || _mtu != null || _ipv6 != null || _port != 0 || _type != null || _mtu != null || _ipv6 != null ||
_ssucaps != null || _transport != null || _cost != 0 || _etype != null || _ssucaps != null || _transport != null || _cost != 0 || _etype != null ||
_icount > 0) { _icount > 0) {
if (client == null && !clientOnly) renderer.renderRouterInfoHTML(_out, _limit, _page,
renderer.renderRouterInfoHTML(_out, _limit, _page,
_routerPrefix, _version, _country, _routerPrefix, _version, _country,
_family, _caps, _ip, _sybil, _port, _highPort, _type, _etype, _family, _caps, _ip, _sybil, _port, _highPort, _type, _etype,
_mtu, _ipv6, _ssucaps, _transport, _cost, _icount, client, clientOnly); _mtu, _ipv6, _ssucaps, _transport, _cost, _icount);
} else if (_lease) { } else if (_lease) {
renderer.renderLeaseSetHTML(_out, _debug, client, _clientOnly); renderer.renderLeaseSetHTML(_out, _debug, null);
} else if (_hostname != null) { } else if (_hostname != null) {
renderer.renderLeaseSet(_out, _hostname, true); renderer.renderLeaseSet(_out, _hostname, true);
} else if (_full == 3) { } else if (_full == 3) {
...@@ -357,18 +337,14 @@ public class NetDbHelper extends FormHandler { ...@@ -357,18 +337,14 @@ public class NetDbHelper extends FormHandler {
(new SybilRenderer(_context)).getNetDbSummary(_out, _newNonce, _mode, _date); (new SybilRenderer(_context)).getNetDbSummary(_out, _newNonce, _mode, _date);
} else if (_full == 4) { } else if (_full == 4) {
renderLookupForm(); renderLookupForm();
} else if (_full == 5) { } else if (_clientOnly) {
renderer.renderStatusHTML(_out, _limit, _page, _full, null, true); for (Hash client : _context.clientManager().getPrimaryHashes()) {
} else if (_full == 6) { renderer.renderLeaseSetHTML(_out, false, client);
renderer.renderStatusHTML(_out, _limit, _page, _full, null, true);
} else if (_clientOnly && client == null) {
for (Hash _client : _context.clientManager().getPrimaryHashes()) {
renderer.renderLeaseSetHTML(_out, _debug, _client, clientOnly);
} }
} else { } else {
if (_full == 0 && _sort != null) if (_full == 0 && _sort != null)
_full = 3; _full = 3;
renderer.renderStatusHTML(_out, _limit, _page, _full, client, clientOnly); renderer.renderStatusHTML(_out, _limit, _page, _full);
} }
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace(); ioe.printStackTrace();
...@@ -376,10 +352,6 @@ public class NetDbHelper extends FormHandler { ...@@ -376,10 +352,6 @@ public class NetDbHelper extends FormHandler {
return ""; return "";
} }
public String getClientNetDbSummary(Hash client) {
return getNetDbSummary(client, true);
}
/** /**
* @since 0.9.1 * @since 0.9.1
*/ */
...@@ -405,12 +377,8 @@ public class NetDbHelper extends FormHandler { ...@@ -405,12 +377,8 @@ public class NetDbHelper extends FormHandler {
return 8; return 8;
if (_hostname != null) if (_hostname != null)
return 9; return 9;
if (_full == 5)
return 10;
if (_full == 6)
return 11;
if (_clientOnly) if (_clientOnly)
return 12; return 10;
return 0; return 0;
} }
...@@ -431,8 +399,9 @@ public class NetDbHelper extends FormHandler { ...@@ -431,8 +399,9 @@ public class NetDbHelper extends FormHandler {
continue; // can't nav to lookup continue; // can't nav to lookup
if (i > 2 && i != tab && !isAdvanced()) if (i > 2 && i != tab && !isAdvanced())
continue; continue;
if (i == 10 || i == 11) { if (i == 10) {
if (_context.netDbSegmentor().getRoutersKnownToClients().size() == 0) // skip if no clients
if (_context.clientManager().getPrimaryHashes().isEmpty() && i != tab)
continue; continue;
} }
if (i == tab) { if (i == tab) {
......
...@@ -41,13 +41,12 @@ import net.i2p.data.router.RouterAddress; ...@@ -41,13 +41,12 @@ import net.i2p.data.router.RouterAddress;
import net.i2p.data.router.RouterInfo; import net.i2p.data.router.RouterInfo;
import net.i2p.data.router.RouterKeyGenerator; import net.i2p.data.router.RouterKeyGenerator;
import net.i2p.router.JobImpl; import net.i2p.router.JobImpl;
import net.i2p.router.NetworkDatabaseFacade;
import net.i2p.router.RouterContext; import net.i2p.router.RouterContext;
import net.i2p.router.TunnelPoolSettings; import net.i2p.router.TunnelPoolSettings;
import net.i2p.router.crypto.FamilyKeyCrypto; import net.i2p.router.crypto.FamilyKeyCrypto;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseSegmentor;
import net.i2p.router.networkdb.kademlia.SegmentedNetworkDatabaseFacade;
import net.i2p.router.util.HashDistance; // debug
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade; import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.router.util.HashDistance; // debug
import static net.i2p.router.sybil.Util.biLog2; import static net.i2p.router.sybil.Util.biLog2;
import net.i2p.router.transport.GeoIP; import net.i2p.router.transport.GeoIP;
import net.i2p.router.web.HelperBase; import net.i2p.router.web.HelperBase;
...@@ -115,34 +114,9 @@ class NetDbRenderer { ...@@ -115,34 +114,9 @@ class NetDbRenderer {
String ip, String sybil, int port, int highPort, SigType type, EncType etype, String ip, String sybil, int port, int highPort, SigType type, EncType etype,
String mtu, String ipv6, String ssucaps, String mtu, String ipv6, String ssucaps,
String tr, int cost, int icount) throws IOException { String tr, int cost, int icount) throws IOException {
renderRouterInfoHTML(out, pageSize, page,
routerPrefix, version,
country, family, caps,
ip, sybil, port, highPort, type, etype,
mtu, ipv6, ssucaps,
tr, cost, icount, null, false);
}
public void renderRouterInfoHTML(Writer out, int pageSize, int page,
String routerPrefix, String version,
String country, String family, String caps,
String ip, String sybil, int port, int highPort, SigType type, EncType etype,
String mtu, String ipv6, String ssucaps,
String tr, int cost, int icount, Hash client, boolean allClients) throws IOException {
StringBuilder buf = new StringBuilder(4*1024); StringBuilder buf = new StringBuilder(4*1024);
List<Hash> sybils = sybil != null ? new ArrayList<Hash>(128) : null; List<Hash> sybils = sybil != null ? new ArrayList<Hash>(128) : null;
FloodfillNetworkDatabaseFacade netdb = _context.netDb(); NetworkDatabaseFacade netdb = _context.netDb();
if (allClients) {
netdb = _context.netDb();
}else{
if (client != null) {
Log _log = _context.logManager().getLog(NetDbRenderer.class);
if (_log.shouldLog(Log.DEBUG))
_log.debug("client subdb for: " + client);
netdb = _context.clientNetDb(client);
}
else
netdb = _context.netDb();
}
if (".".equals(routerPrefix)) { if (".".equals(routerPrefix)) {
buf.append("<table><tr><td class=\"infohelp\">") buf.append("<table><tr><td class=\"infohelp\">")
...@@ -234,15 +208,7 @@ class NetDbRenderer { ...@@ -234,15 +208,7 @@ class NetDbRenderer {
} }
boolean notFound = true; boolean notFound = true;
Set<RouterInfo> routers = new HashSet<RouterInfo>(); Set<RouterInfo> routers = new HashSet<RouterInfo>();
if (allClients){ routers.addAll(_context.netDb().getRouters());
routers.addAll(_context.netDbSegmentor().getRoutersKnownToClients());
} else {
if (client == null)
routers.addAll(_context.netDb().getRouters());
else
routers.addAll(_context.clientNetDb(client).getRouters());
}
int ipMode = 0; int ipMode = 0;
String ipArg = ip; // save for error message String ipArg = ip; // save for error message
String altIPv6 = null; String altIPv6 = null;
...@@ -611,27 +577,20 @@ class NetDbRenderer { ...@@ -611,27 +577,20 @@ class NetDbRenderer {
* *
* @param debug @since 0.7.14 sort by distance from us, display * @param debug @since 0.7.14 sort by distance from us, display
* median distance, and other stuff, useful when floodfill * median distance, and other stuff, useful when floodfill
* @param client null for main db; non-null for client db
*/ */
public void renderLeaseSetHTML(Writer out, boolean debug, Hash client, boolean clientsOnly) throws IOException { public void renderLeaseSetHTML(Writer out, boolean debug, Hash client) throws IOException {
StringBuilder buf = new StringBuilder(4*1024); StringBuilder buf = new StringBuilder(4*1024);
if (debug) if (debug)
buf.append("<p id=\"debugmode\">Debug mode - Sorted by hash distance, closest first</p>\n"); buf.append("<p id=\"debugmode\">Debug mode - Sorted by hash distance, closest first</p>\n");
Hash ourRKey; Hash ourRKey;
Set<LeaseSet> leases; Set<LeaseSet> leases;
DecimalFormat fmt; DecimalFormat fmt;
FloodfillNetworkDatabaseFacade netdb = null; NetworkDatabaseFacade netdb;
if (clientsOnly){ if (client == null)
netdb = _context.netDb(); netdb = _context.netDb();
}else{ else
if (client != null) { netdb = _context.clientNetDb(client);
Log _log = _context.logManager().getLog(NetDbRenderer.class);
if (_log.shouldLog(Log.DEBUG))
_log.debug("client subdb for: " + client);
netdb = _context.clientNetDb(client);
}
else
netdb = _context.netDb();
}
if (debug) { if (debug) {
ourRKey = _context.routerHash(); ourRKey = _context.routerHash();
leases = new TreeSet<LeaseSet>(new LeaseSetRoutingKeyComparator(ourRKey)); leases = new TreeSet<LeaseSet>(new LeaseSetRoutingKeyComparator(ourRKey));
...@@ -641,11 +600,7 @@ class NetDbRenderer { ...@@ -641,11 +600,7 @@ class NetDbRenderer {
leases = new TreeSet<LeaseSet>(new LeaseSetComparator()); leases = new TreeSet<LeaseSet>(new LeaseSetComparator());
fmt = null; fmt = null;
} }
if (clientsOnly) leases.addAll(netdb.getLeases());
leases.addAll(_context.netDbSegmentor().getLeasesKnownToClients());
else{
leases.addAll(netdb.getLeases());
}
int medianCount = 0; int medianCount = 0;
int rapCount = 0; int rapCount = 0;
BigInteger median = null; BigInteger median = null;
...@@ -658,16 +613,15 @@ class NetDbRenderer { ...@@ -658,16 +613,15 @@ class NetDbRenderer {
} else { } else {
buf.append("<table id=\"leasesetsummary\">\n"); buf.append("<table id=\"leasesetsummary\">\n");
} }
if (clientsOnly) if (client != null) {
buf.append("<tr><th colspan=\"3\">Leaseset Summary for All Clients: ").append(client).append("</th>"); buf.append("<tr><th colspan=\"3\">Leasesets for Client: ").append(client.toBase32()).append("</th><th></th></tr>\n");
else if (client != null) } else {
buf.append("<tr><th colspan=\"3\">Leaseset Summary for Client: ").append(client).append("</th>"); buf.append("<tr><th colspan=\"3\">Leaseset Summary for Floodfill</th>" +
else "<th><a href=\"/configadvanced\" title=\"").append(_t("Manually Configure Floodfill Participation")).append("\">[")
buf.append("<tr><th colspan=\"3\">Leaseset Summary for Floodfill</th>"); .append(_t("Configure Floodfill Participation"))
buf.append("<th><a href=\"/configadvanced\" title=\"").append(_t("Manually Configure Floodfill Participation")).append("\">[") .append("]</a></th></tr>\n");
.append(_t("Configure Floodfill Participation")) }
.append("]</a></th></tr>\n") buf.append("<tr><td><b>Total Leasesets:</b></td><td colspan=\"3\">").append(leases.size()).append("</td></tr>\n");
.append("<tr><td><b>Total Leasesets:</b></td><td colspan=\"3\">").append(leases.size()).append("</td></tr>\n");
if (debug) { if (debug) {
RouterKeyGenerator gen = _context.routerKeyGenerator(); RouterKeyGenerator gen = _context.routerKeyGenerator();
buf.append("<tr><td><b>Published (RAP) Leasesets:</b></td><td colspan=\"3\">").append(leases).append("</td></tr>\n") buf.append("<tr><td><b>Published (RAP) Leasesets:</b></td><td colspan=\"3\">").append(leases).append("</td></tr>\n")
...@@ -676,17 +630,17 @@ class NetDbRenderer { ...@@ -676,17 +630,17 @@ class NetDbRenderer {
.append("<tr><td><b>Next Mod Data:</b></td><td>").append(DataHelper.getUTF8(gen.getNextModData())).append("</td>") .append("<tr><td><b>Next Mod Data:</b></td><td>").append(DataHelper.getUTF8(gen.getNextModData())).append("</td>")
.append("<td><b>Change in:</b></td><td>").append(DataHelper.formatDuration(gen.getTimeTillMidnight())).append("</td></tr>\n"); .append("<td><b>Change in:</b></td><td>").append(DataHelper.formatDuration(gen.getTimeTillMidnight())).append("</td></tr>\n");
} }
int ff = 0;
if (client == null) { if (client == null) {
ff = _context.peerManager().getPeersByCapability(FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL).size(); 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"); buf.append("<tr><td><b>Known Floodfills:</b></td><td colspan=\"3\">").append(ff).append("</td></tr>\n");
buf.append("<tr><td><b>Currently Floodfill?</b></td><td>").append(netdb.floodfillEnabled() ? "yes" : "no"); buf.append("<tr><td><b>Currently Floodfill?</b></td><td>").append(netdb.floodfillEnabled() ? "yes" : "no");
if (debug)
buf.append("</td><td><b>Routing Key:</b></td><td>").append(ourRKey.toBase64());
else
buf.append("</td><td colspan=\"2\">");
buf.append("</td></tr>\n");
} }
if (debug) buf.append("</table>\n");
buf.append("</td><td><b>Routing Key:</b></td><td>").append(ourRKey.toBase64());
else
buf.append("</td><td colspan=\"2\">");
buf.append("</td></tr>\n</table>\n");
if (leases.isEmpty()) { if (leases.isEmpty()) {
//if (!debug) //if (!debug)
...@@ -960,7 +914,7 @@ class NetDbRenderer { ...@@ -960,7 +914,7 @@ class NetDbRenderer {
* @param mode 0: charts only; 1: full routerinfos; 2: abbreviated routerinfos * @param mode 0: charts only; 1: full routerinfos; 2: abbreviated routerinfos
* mode 3: Same as 0 but sort countries by count * mode 3: Same as 0 but sort countries by count
*/ */
public void renderStatusHTML(Writer out, int pageSize, int page, int mode, Hash client, boolean clientsOnly) throws IOException { public void renderStatusHTML(Writer out, int pageSize, int page, int mode) throws IOException {
if (!_context.netDb().isInitialized()) { if (!_context.netDb().isInitialized()) {
out.write("<div id=\"notinitialized\">"); out.write("<div id=\"notinitialized\">");
out.write(_t("Not initialized")); out.write(_t("Not initialized"));
...@@ -977,13 +931,7 @@ class NetDbRenderer { ...@@ -977,13 +931,7 @@ class NetDbRenderer {
Hash us = _context.routerHash(); Hash us = _context.routerHash();
Set<RouterInfo> routers = new TreeSet<RouterInfo>(new RouterInfoComparator()); Set<RouterInfo> routers = new TreeSet<RouterInfo>(new RouterInfoComparator());
if (client != null) { routers.addAll(_context.netDb().getRouters());
routers.addAll(_context.clientNetDb(client).getRouters());
} else if (clientsOnly) {
routers.addAll(_context.netDbSegmentor().getRoutersKnownToClients());
} else {
routers.addAll(_context.netDb().getRouters());
}
int toSkip = pageSize * page; int toSkip = pageSize * page;
boolean nextpg = routers.size() > toSkip + pageSize; boolean nextpg = routers.size() > toSkip + pageSize;
StringBuilder buf = new StringBuilder(8192); StringBuilder buf = new StringBuilder(8192);
...@@ -1071,19 +1019,9 @@ class NetDbRenderer { ...@@ -1071,19 +1019,9 @@ class NetDbRenderer {
if (!showStats) { if (!showStats) {
// the summary table // the summary table
if (client != null) { buf.append("<table id=\"netdboverview\" border=\"0\" cellspacing=\"30\"><tr><th colspan=\"3\">");
buf.append("<table id=\"netdboverview\" border=\"0\" cellspacing=\"30\"><tr><th colspan=\"3\">") buf.append(_t("Network Database Router Statistics"));
.append(_t("Network Database Router Statistics for Client " + client)) buf.append("</th></tr><tr><td style=\"vertical-align: top;\">");
.append("</th></tr><tr><td style=\"vertical-align: top;\">");
} else if (clientsOnly) {
buf.append("<table id=\"netdboverview\" border=\"0\" cellspacing=\"30\"><tr><th colspan=\"3\">")
.append(_t("Network Database Router Statistics for all Clients"))
.append("</th></tr><tr><td style=\"vertical-align: top;\">");
} else {
buf.append("<table id=\"netdboverview\" border=\"0\" cellspacing=\"30\"><tr><th colspan=\"3\">")
.append(_t("Network Database Router Statistics for Floodfill Router"))
.append("</th></tr><tr><td style=\"vertical-align: top;\">");
}
// versions table // versions table
List<String> versionList = new ArrayList<String>(versions.objects()); List<String> versionList = new ArrayList<String>(versions.objects());
if (!versionList.isEmpty()) { if (!versionList.isEmpty()) {
......
...@@ -41,5 +41,5 @@ ...@@ -41,5 +41,5 @@
<jsp:setProperty name="formhandler" property="sort" value="<%=request.getParameter(\"s\")%>" /> <jsp:setProperty name="formhandler" property="sort" value="<%=request.getParameter(\"s\")%>" />
<jsp:setProperty name="formhandler" property="intros" value="<%=request.getParameter(\"i\")%>" /> <jsp:setProperty name="formhandler" property="intros" value="<%=request.getParameter(\"i\")%>" />
<%@include file="formhandler.jsi" %> <%@include file="formhandler.jsi" %>
<jsp:getProperty name="formhandler" property="floodfillNetDbSummary" /> <jsp:getProperty name="formhandler" property="netDbSummary" />
</div></body></html> </div></body></html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment