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
-- load the olsr hosts file
for line in io.lines("/var/run/hosts_olsr.stable")
do
local ip, name, originator = line:match("^([%d%.]+)%s+(%S+)%s+%S+%s+(%S+)")
if ip and originator and originator ~= "myself" and (routes[ip] or routes[originator]) then
local etx = routes[ip]
if not etx then
etx = routes[originator]
end
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 = {} }
if nixio.fs.stat("/var/run/hosts_olsr.stable") then
for line in io.lines("/var/run/hosts_olsr.stable")
do
local ip, name, originator = line:match("^([%d%.]+)%s+(%S+)%s+%S+%s+(%S+)")
if ip and originator and originator ~= "myself" and (routes[ip] or routes[originator]) then
local etx = routes[ip]
if not etx then
etx = routes[originator]
end
local host = hosts[originator]
if host.name then
host.tactical = name
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
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
host.name = name
host.etx = etx
if not hosts[originator] then
hosts[originator] = { hosts = {} }
end
local host = hosts[originator]
host.hosts[#host.hosts + 1] = name
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

View File

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