Protect against missing hosts_olsr.stable (#523)

This commit is contained in:
Tim Wilkinson 2022-10-14 13:31:09 -07:00 committed by GitHub
parent 277610bf27
commit caaafc3831
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 52 deletions

View File

@ -316,49 +316,51 @@ do
end end
-- load the olsr hosts file -- load the olsr hosts file
for line in io.lines("/var/run/hosts_olsr.stable") if nixio.fs.stat("/var/run/hosts_olsr.stable") then
do for line in io.lines("/var/run/hosts_olsr.stable")
local ip, name, originator = line:match("^([%d%.]+)%s+(%S+)%s+%S+%s+(%S+)") do
if ip and originator and originator ~= "myself" and (routes[ip] or routes[originator]) then local ip, name, originator = line:match("^([%d%.]+)%s+(%S+)%s+%S+%s+(%S+)")
local etx = routes[ip] if ip and originator and originator ~= "myself" and (routes[ip] or routes[originator]) then
if not etx then local etx = routes[ip]
etx = routes[originator] if not etx then
end etx = routes[originator]
etx = etx.etx
if not name:match("%.") or name:match("^mid%.[^%.]*$") then
name = name .. ".local.mesh"
end
if ip == originator then
if not hosts[originator] then
hosts[originator] = { hosts = {} }
end end
local host = hosts[originator] etx = etx.etx
if host.name then if not name:match("%.") or name:match("^mid%.[^%.]*$") then
host.tactical = name name = name .. ".local.mesh"
end
if ip == originator then
if not hosts[originator] then
hosts[originator] = { hosts = {} }
end
local host = hosts[originator]
if host.name then
host.tactical = name
else
host.name = name
host.etx = etx
end
elseif name:match("^dtdlink%.") then
dtd[originator] = true
if links[ip] then
links[ip].dtd = true
end
elseif name:match("^mid%d+%.") then
if not midcount[originator] then
midcount[originator] = 1
else
midcount[originator] = midcount[originator] + 1
end
if links[ip] then
links[ip].tun = true
end
else else
host.name = name if not hosts[originator] then
host.etx = etx hosts[originator] = { hosts = {} }
end
local host = hosts[originator]
host.hosts[#host.hosts + 1] = name
end end
elseif name:match("^dtdlink%.") then
dtd[originator] = true
if links[ip] then
links[ip].dtd = true
end
elseif name:match("^mid%d+%.") then
if not midcount[originator] then
midcount[originator] = 1
else
midcount[originator] = midcount[originator] + 1
end
if links[ip] then
links[ip].tun = true
end
else
if not hosts[originator] then
hosts[originator] = { hosts = {} }
end
local host = hosts[originator]
host.hosts[#host.hosts + 1] = name
end end
end end
end end

View File

@ -58,11 +58,13 @@ function mesh_ip_to_hostnames(ip)
end end
end end
local hosts = "" local hosts = ""
for line in io.lines("/var/run/hosts_olsr.stable") if nixio.fs.stat("/var/run/hosts_olsr.stable") then
do for line in io.lines("/var/run/hosts_olsr.stable")
local host = line:match(pattern) do
if host then local host = line:match(pattern)
hosts = hosts .. " / " .. host if host then
hosts = hosts .. " / " .. host
end
end end
end end
return hosts:sub(4, #hosts) return hosts:sub(4, #hosts)
@ -180,13 +182,15 @@ end
local host_total = 0 local host_total = 0
local host_nodes = 0 local host_nodes = 0
for line in io.lines("/var/run/hosts_olsr.stable") if nixio.fs.stat("/var/run/hosts_olsr.stable") then
do for line in io.lines("/var/run/hosts_olsr.stable")
if line:match("^10%.") and not line:match("%smid%d+%.") then do
host_total = host_total + 1 if line:match("^10%.") and not line:match("%smid%d+%.") then
local host = line:match("^10%..+%sdtdlink%.") host_total = host_total + 1
if host then local host = line:match("^10%..+%sdtdlink%.")
host_nodes = host_nodes + 1 if host then
host_nodes = host_nodes + 1
end
end end
end end
end end