Improve startup of LQM so we get some information early (#1632)

* Improve startup of LQM so we get some information early

* Display device information earlier
This commit is contained in:
Tim Wilkinson 2024-10-16 18:04:24 -07:00 committed by GitHub
parent ef7c6bed68
commit 64a91caa2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 75 additions and 36 deletions

View File

@ -40,6 +40,9 @@
} }
function calcColor(tracker) function calcColor(tracker)
{ {
if (!tracker) {
return "unknown";
}
if (tracker.blocked) { if (tracker.blocked) {
if (tracker.blocks.user) { if (tracker.blocks.user) {
return "blocked by user"; return "blocked by user";
@ -62,7 +65,10 @@
return "idle"; return "idle";
} }
const quality = tracker.quality; const quality = tracker.quality;
if (quality < 40) { if (!type(quality)) {
return "unknown";
}
else if (quality < 40) {
return "bad"; return "bad";
} }
else if (quality < 50) { else if (quality < 50) {
@ -78,9 +84,11 @@
return "excellent"; return "excellent";
} }
}; };
function calcBitrate(txbitrate, rxbitrate) function calcBitrate(tracker)
{ {
const txbitrate = tracker.tx_bitrate;
if (txbitrate) { if (txbitrate) {
const rxbitrate = tracker.rx_bitrate;
if (rxbitrate) { if (rxbitrate) {
return sprintf("%.1f", ((txbitrate + rxbitrate) * 5 + 0.5) / 10); return sprintf("%.1f", ((txbitrate + rxbitrate) * 5 + 0.5) / 10);
} }
@ -105,42 +113,61 @@
</div> </div>
</div> </div>
{% {%
const trackers = lqm.getTrackers();
const llist = []; const llist = [];
const nlist = []; const nlist = [];
const hlist = lqm.getHidden(); const hlist = lqm.getHidden();
for (mac in trackers) { const t = lqm.getTrackers();
const tracker = trackers[mac]; const trackers = {};
if (tracker.hostname || (tracker.ip && tracker.routable)) { for (mac in t) {
if (tracker.type === "DtD" && tracker.distance < 100) { const tmac = t[mac];
push(llist, { name: tracker.hostname || `|${tracker.ip}`, mac: mac }); if (tmac.ip) {
trackers[tmac.ip] = tmac;
}
}
const links = olsr.getLinks();
for (let i = 0; i < length(links); i++) {
const link = links[i];
const tracker = trackers[link.remoteIP];
if (link.ifName === "br-dtdlink") {
if (tracker && tracker.distance >= 100) {
push(nlist, { name: tracker.hostname || `|${link.remoteIP}`, tracker: tracker, link: link });
} }
else { else {
push(nlist, { name: tracker.hostname || `|${tracker.ip}`, mac: mac }); push(llist, { name: (tracker && tracker.hostname) || `|${link.remoteIP}`, tracker: tracker, link: link });
} }
} }
else {
push(nlist, { name: (tracker && tracker.hostname) || `|${link.remoteIP}`, tracker: tracker, link: link });
}
} }
if (length(llist) > 0) { if (length(llist) > 0) {
sort(llist, (a, b) => a.name == b.name ? 0 : a.name < b.name ? -1 : 1); sort(llist, (a, b) => a.name == b.name ? 0 : a.name < b.name ? -1 : 1);
for (let i = 0; i < length(llist); i++) { for (let i = 0; i < length(llist); i++) {
const tracker = trackers[llist[i].mac]; const entry = llist[i];
const tracker = entry.tracker;
const link = entry.link;
const status = calcColor(tracker); const status = calcColor(tracker);
print(`<div class="ctrl cols status ${status}" hx-get="status/e/neighbor-device?m=${tracker.mac}" title="Link status: ${status}">`); if (tracker) {
const link = links[tracker.ip] || {}; print(`<div class="ctrl cols status ${status}" hx-get="status/e/neighbor-device?m=${tracker.mac}" title="Link status: ${status}">`);
const lq = link.lossMultiplier ? (min(100, int(100 * link.linkQuality * 65536 / link.lossMultiplier)) + "%") : "-";
const nlq = link.lossMultiplier ? (min(100, int(100 * link.neighborLinkQuality * 65536 / link.lossMultiplier)) + "%") : "-";
if (tracker.hostname) {
print(`<div class='h'><a onclick="event.stopPropagation()" href='http://${tracker.hostname}.local.mesh'>${tracker.hostname}</a></div>`);
} }
else { else {
print(`<div class='h'><a onclick="event.stopPropagation()" href='http://${tracker.ip}'>${tracker.ip}</a></div>`); print(`<div class="ctrl cols status unknown" title="Link status: unknown">`);
}
const lq = link.lossMultiplier ? (min(100, int(100 * link.linkQuality * 65536 / link.lossMultiplier)) + "%") : "-";
const nlq = link.lossMultiplier ? (min(100, int(100 * link.neighborLinkQuality * 65536 / link.lossMultiplier)) + "%") : "-";
if (substr(entry.name, 0, 1) !== "|") {
print(`<div class='h'><a onclick="event.stopPropagation()" href='http://${entry.name}.local.mesh'>${entry.name}</a></div>`);
}
else {
const ip = substr(entry.name, 1);
print(`<div class='h'><a onclick="event.stopPropagation()" href='http://${ip}'>${ip}</a></div>`);
} }
print("<div class='ts cols stats'>"); print("<div class='ts cols stats'>");
if (!request.mobile) { if (!request.mobile) {
print(`<div>${lq}</div><div>${nlq}</div><div></div><div></div><div>${100 - tracker.quality}%</div><div></div><div></div>`); print(`<div>${lq}</div><div>${nlq}</div><div></div><div></div><div>${type(tracker && tracker.quality) ? (100 - tracker.quality) + "%" : "-"}</div><div></div><div></div>`);
} }
else { else {
print(`<div>${lq}</div><div>${nlq}</div><div></div><div></div><div>${100 - tracker.quality}%</div>`); print(`<div>${lq}</div><div>${nlq}</div><div></div><div></div><div>${type(tracker && tracker.quality) ? (100 - tracker.quality) + "%" : "-"}</div>`);
} }
print("</div></div>"); print("</div></div>");
} }
@ -158,15 +185,21 @@
if (length(nlist) > 0) { if (length(nlist) > 0) {
sort(nlist, (a, b) => a.name == b.name ? 0 : a.name < b.name ? -1 : 1); sort(nlist, (a, b) => a.name == b.name ? 0 : a.name < b.name ? -1 : 1);
for (let i = 0; i < length(nlist); i++) { for (let i = 0; i < length(nlist); i++) {
const tracker = trackers[nlist[i].mac]; const entry = nlist[i];
const tracker = entry.tracker;
const link = entry.link;
const status = calcColor(tracker); const status = calcColor(tracker);
print(`<div class="ctrl cols status ${status}" hx-get="status/e/neighbor-device?m=${tracker.mac}" title="Link status: ${status}">`); if (tracker) {
const link = links[tracker.ip] || {}; print(`<div class="ctrl cols status ${status}" hx-get="status/e/neighbor-device?m=${tracker.mac}" title="Link status: ${status}">`);
}
else {
print(`<div class="ctrl cols status unknown" title="Link status: unknown">`);
}
const lq = link.lossMultiplier ? (min(100, int(100 * link.linkQuality * 65536 / link.lossMultiplier)) + "%") : "-"; const lq = link.lossMultiplier ? (min(100, int(100 * link.linkQuality * 65536 / link.lossMultiplier)) + "%") : "-";
const nlq = link.lossMultiplier ? (min(100, int(100 * link.neighborLinkQuality * 65536 / link.lossMultiplier)) + "%") : "-"; const nlq = link.lossMultiplier ? (min(100, int(100 * link.neighborLinkQuality * 65536 / link.lossMultiplier)) + "%") : "-";
let icon = ""; let icon = "";
let title = ""; let title = "";
switch (tracker.type) { switch (tracker && tracker.type || "Unknown") {
case "RF": case "RF":
title = "RF "; title = "RF ";
icon = "wifi"; icon = "wifi";
@ -190,24 +223,30 @@
default: default:
break; break;
} }
if (tracker.hostname) { if (substr(entry.name, 0, 1) !== "|") {
print(`<div class='h'><a onclick="event.stopPropagation()" href='http://${tracker.hostname}.local.mesh'>${tracker.hostname}<div class="icon ${icon}"></div></a></div>`); print(`<div class='h'><a onclick="event.stopPropagation()" href='http://${entry.name}.local.mesh'>${entry.name}<div class="icon ${icon}"></div></a></div>`);
} }
else { else {
print(`<div class='h'><a onclick="event.stopPropagation()" href='http://${tracker.ip}'>${tracker.ip}<div class="icon ${icon}"></div></a></div>`); const ip = substr(entry.name, 1);
print(`<div class='h'><a onclick="event.stopPropagation()" href='http://${ip}'>${ip}<div class="icon ${icon}"></div></a></div>`);
} }
print("<div class='ts cols stats'>"); print("<div class='ts cols stats'>");
let d = "-"; if (tracker) {
if ("distance" in tracker) { let d = "-";
d = units.meters2distance(tracker.distance); if ("distance" in tracker) {
if (d < 1) { d = units.meters2distance(tracker.distance);
d = "< 1"; if (d < 1) {
} d = "< 1";
else { }
d = sprintf("%.1f", d); else {
d = sprintf("%.1f", d);
}
} }
print(`<div>${lq}</div><div>${nlq}</div><div>${tracker.snr || "-"}</div><div>${tracker.rev_snr || "-"}</div><div>${type(tracker.quality) ? (100 - tracker.quality) + "%" : "-"}</div><div>${calcBitrate(tracker)}</div><div>${d}</div>`);
}
else {
print(`<div>${lq}</div><div>${nlq}</div><div></div><div></div><div></div><div></div><div></div>`);
} }
print(`<div>${lq}</div><div>${nlq}</div><div>${tracker.snr || "-"}</div><div>${tracker.rev_snr || "-"}</div><div>${100 - tracker.quality}%</div><div>${calcBitrate(tracker.tx_bitrate, tracker.rx_bitrate)}</div><div>${d}</div>`);
print("</div></div>"); print("</div></div>");
} }
} }

View File

@ -126,7 +126,7 @@ function should_nonpair_block(track)
end end
function should_ping(track) function should_ping(track)
if not track.ip or is_user_blocked(track) or track.lastseen < now then if not track.ip or is_user_blocked(track) or track.lastseen < now or track.firstseen == track.lastseen then
return false return false
end end
if track.type == "Tunnel" or track.type == "Wireguard" then if track.type == "Tunnel" or track.type == "Wireguard" then