Console: Improve efficiency of transport+cost search

This commit is contained in:
zzz
2026-02-15 08:19:37 -05:00
parent bb1f487fbd
commit 2bc285a8a0
@@ -252,8 +252,9 @@ class NetDbRenderer {
filterSigType(routers, type);
if (etype != null && !routers.isEmpty())
filterEncType(routers, etype);
// if cost is set also, we filter for that here
if (tr != null && !routers.isEmpty())
filterTransport(routers, tr);
filterTransport(routers, tr, cost);
if (family != null && !routers.isEmpty())
filterFamily(routers, family);
if (ip != null && !routers.isEmpty()) {
@@ -270,7 +271,8 @@ class NetDbRenderer {
filterIP(routers, ipv6, altIPv6);
if (ssucaps != null && !routers.isEmpty())
filterSSUCaps(routers, ssucaps);
if (cost != 0 && !routers.isEmpty())
// if transport was set also, we filtered for that above
if (cost != 0 && tr == null && !routers.isEmpty())
filterCost(routers, cost);
if (itag != null && !routers.isEmpty())
filterITag(routers, itag);
@@ -490,9 +492,10 @@ class NetDbRenderer {
/**
* Remove all non-matching from routers
* @param cost if nonzero, filter for that also
* @since 0.9.64 split out from above
*/
private static void filterTransport(Set<RouterInfo> routers, String tr) {
private static void filterTransport(Set<RouterInfo> routers, String tr, int cost) {
String transport;
int mode;
if (tr.equals("NTCP_1")) {
@@ -511,26 +514,56 @@ class NetDbRenderer {
transport = tr;
mode = 4;
}
loop:
for (Iterator<RouterInfo> iter = routers.iterator(); iter.hasNext(); ) {
RouterInfo ri = iter.next();
RouterAddress ra = ri.getTargetAddress(transport);
if (ra != null) {
switch (mode) {
case 0:
case 2:
if (ra.getOption("v") == null)
if (cost == 0) {
// just look for any matching
RouterAddress ra = ri.getTargetAddress(transport);
if (ra != null) {
switch (mode) {
case 0:
case 2:
if (ra.getOption("v") == null)
continue;
break;
case 1:
case 3:
if (ra.getOption("v") != null)
continue;
break;
case 4:
continue;
break;
case 1:
case 3:
if (ra.getOption("v") != null)
continue;
break;
}
}
} else {
// go through all matching and compare cost
List<RouterAddress> ras = ri.getTargetAddresses(transport);
if (!ras.isEmpty()) {
for (RouterAddress ra : ras) {
switch (mode) {
case 0:
case 2:
if (ra.getOption("v") == null && cost == ra.getCost())
continue loop;
break;
case 4:
continue;
case 1:
case 3:
if (ra.getOption("v") != null && cost == ra.getCost())
continue loop;
break;
case 4:
if (cost == ra.getCost())
continue loop;
break;
}
}
}
}
iter.remove();