Fix displaying "Previous neighbors" with empty hostnames (#325)

* Dont display previous neighbors with empty hostnames
* Use IP address when name missing
* Fix bug where missing names became ever growing string of whitespace
This commit is contained in:
Tim Wilkinson 2022-04-04 19:16:35 -07:00 committed by GitHub
parent e0ac3e9349
commit b26476f5e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 12 deletions

View File

@ -93,15 +93,9 @@ function do_namechange()
if nixio.fs.stat("/tmp/node.history") then
for line in io.lines("/tmp/node.history")
do
local v = line:splitWhiteSpace()
local ip = v[1]
local age = 0
if v[2] then
age = math.floor(v[2])
end
local name = v[3]
if age and not history[ip] and uptime - age < 86400 then
history[ip] = { age = age, name = name or "" }
local ip, age, name = line:match("^(%S*) (%d+) +(.*)$")
if ip and age and not history[ip] and uptime - tonumber(age) < 86400 then
history[ip] = { age = age, name = name }
end
end
end
@ -111,7 +105,7 @@ function do_namechange()
if f then
for k,v in pairs(history)
do
f:write(string.format("%s %d %s\n", k, v.age, v.name))
f:write(k .. " " .. v.age .. " " .. v.name .. "\n")
end
f:close()
end

View File

@ -399,7 +399,7 @@ end
if nixio.fs.stat("/tmp/node.history") then
for line in io.lines("/tmp/node.history")
do
local ip, age, host = line:match("^(.+) (%d+) (.*)")
local ip, age, host = line:match("^(%S+) (%d+) (%S+)")
if ip and age and host then
history[ip] = { age = age, host = host:gsub("/", " / ") }
end
@ -729,7 +729,7 @@ do
if not (links[ip] or links[ipalias[ip]]) then
local age = uptime - tonumber(node.age)
local host = node.host
if not host then
if host == "" then
host = ip
else
host = host:gsub("^mid%d+%.", ""):gsub("^dtdlink%.", "")