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
function getRemoteNodes()
local info={}
local allhosts = aredn_info.all_hosts()
local cn = aredn_olsr.getCurrentNeighbors()
local routes = aredn_olsr.getOLSRRoutes()
for k, v in pairs(allhosts) do
for rk, rv in pairs(routes) do -- add etx from routes table
if rv['destination'] == allhosts[k].ip then
allhosts[k]['etx']=tostring(round2(routes[rk].etx, 2))
end
end
if setContains(allhosts[k],"etx") then -- only include nodes with etx
table.insert(info, allhosts[k])
end
end
for k, v in pairs(info) do
for cnk, cnv in pairs(cn) do -- remove currentneighbors
if cnk == info[k].ip then
table.remove(info, k)
end
end
local info = {}
local neighbors = {}
for _, v in ipairs(aredn_olsr.getOLSRLinks())
do
local remoteIP = v.remoteIP
neighbors[remoteIP] = true
local name = nixio.getnameinfo(remoteIP)
if name then
local cname = name:match("^dtdlink%.(.*)$") or name:match("^mid%d+%.(.*)$")
if cname then
local addrs = nixio.getaddrinfo(cname)
if addrs then
neighbors[addrs[1].address] = true
end
end
end
end
table.sort( info, function(a,b) return tonumber(a.etx) < tonumber(b.etx) end)
return info
local routeetx = {}
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
-- gets signal and noise data from either iwinfo (realtime = true) or the files archived in /tmp/snrlog (realtime = false)