Optimize getRemoteNodes (#326)

This commit is contained in:
Tim Wilkinson 2022-04-05 17:30:36 -07:00 committed by GitHub
parent b26476f5e2
commit c3f2fcd400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 22 deletions

View File

@ -123,29 +123,44 @@ function get_key_for_value( t, value )
end end
function getRemoteNodes() function getRemoteNodes()
local info={} local info = {}
local allhosts = aredn_info.all_hosts() local neighbors = {}
local cn = aredn_olsr.getCurrentNeighbors() for _, v in ipairs(aredn_olsr.getOLSRLinks())
local routes = aredn_olsr.getOLSRRoutes() do
for k, v in pairs(allhosts) do local remoteIP = v.remoteIP
for rk, rv in pairs(routes) do -- add etx from routes table neighbors[remoteIP] = true
if rv['destination'] == allhosts[k].ip then local name = nixio.getnameinfo(remoteIP)
allhosts[k]['etx']=tostring(round2(routes[rk].etx, 2)) if name then
end local cname = name:match("^dtdlink%.(.*)$") or name:match("^mid%d+%.(.*)$")
end if cname then
if setContains(allhosts[k],"etx") then -- only include nodes with etx local addrs = nixio.getaddrinfo(cname)
table.insert(info, allhosts[k]) if addrs then
end neighbors[addrs[1].address] = true
end end
for k, v in pairs(info) do end
for cnk, cnv in pairs(cn) do -- remove currentneighbors end
if cnk == info[k].ip then
table.remove(info, k)
end
end
end end
table.sort( info, function(a,b) return tonumber(a.etx) < tonumber(b.etx) end) local routeetx = {}
return info for _, v in ipairs(aredn_olsr.getOLSRRoutes())
do
routeetx[v.destination] = string.format("%.2f", v.etx)
end
for line in io.lines("/var/run/hosts_olsr")
do
local ip, hostname = line:match("^(%d+%.%d+%.%d+%.%d+)%s+(%S+)%s+#.*$")
if ip and not neighbors[ip] and not (hostname:match("^dtdlink%.") or hostname:match("^mid%d+%.")) then
local etx = routeetx[ip]
if etx then
info[#info + 1] = {
name = hostname,
ip = ip,
etx = etx
}
end
end
end
table.sort(info, function(a,b) return tonumber(a.etx) < tonumber(b.etx) end)
return info
end end
-- gets signal and noise data from either iwinfo (realtime = true) or the files archived in /tmp/snrlog (realtime = false) -- gets signal and noise data from either iwinfo (realtime = true) or the files archived in /tmp/snrlog (realtime = false)