aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mirror-checker.lua
diff options
context:
space:
mode:
authoronefang2019-11-05 00:07:43 +1000
committeronefang2019-11-05 00:07:43 +1000
commit4a1763099ece00cf0d462a3caca4421cf0a14bc4 (patch)
tree6bff6cbf3b0a71bbe4ccfd25d968774211880b84 /mirror-checker.lua
parentOops, missed a line in the --roundRobin commit. (diff)
downloadapt-panopticon-4a1763099ece00cf0d462a3caca4421cf0a14bc4.zip
apt-panopticon-4a1763099ece00cf0d462a3caca4421cf0a14bc4.tar.gz
apt-panopticon-4a1763099ece00cf0d462a3caca4421cf0a14bc4.tar.bz2
apt-panopticon-4a1763099ece00cf0d462a3caca4421cf0a14bc4.tar.xz
Gather the IPs and stuff them into mirrors.lua before forking.
Diffstat (limited to '')
-rwxr-xr-xmirror-checker.lua39
1 files changed, 27 insertions, 12 deletions
diff --git a/mirror-checker.lua b/mirror-checker.lua
index f4b5142..6580190 100755
--- a/mirror-checker.lua
+++ b/mirror-checker.lua
@@ -182,7 +182,7 @@ local repoExists = function (r)
182end 182end
183 183
184local IP = {} 184local IP = {}
185local gatherIPs = function (host) 185gatherIPs = function (host)
186 if nil == IP[host] then 186 if nil == IP[host] then
187 local IPs 187 local IPs
188 local dig = io.popen('dig +keepopen +noall +nottlid +answer ' .. host .. ' A ' .. host .. ' AAAA ' .. host .. ' CNAME ' .. host .. ' SRV | sort -r | uniq') 188 local dig = io.popen('dig +keepopen +noall +nottlid +answer ' .. host .. ' A ' .. host .. ' AAAA ' .. host .. ' CNAME ' .. host .. ' SRV | sort -r | uniq')
@@ -193,6 +193,13 @@ local gatherIPs = function (host)
193 if "." == v:sub(-1, -1) then v = v:sub(1, -2) end 193 if "." == v:sub(-1, -1) then v = v:sub(1, -2) end
194 if nil == IP[k] then IP[k] = {} end 194 if nil == IP[k] then IP[k] = {} end
195 IP[k][v] = t 195 IP[k][v] = t
196 D(" DNS record " .. host .. " == " .. k .. " type " .. t .. " -> " .. v)
197 if t == "CNAME" then
198 gatherIPs(v)
199 IP[k][v] = IP[v]
200 elseif v == "SRV" then
201 print("SVR record found, now what do we do?")
202 end
196 end 203 end
197 end 204 end
198 until nil == IPs 205 until nil == IPs
@@ -349,17 +356,23 @@ checkHost = function (orig, host, path, ip, file)
349 D("checkHost " .. orig .. "" .. file) 356 D("checkHost " .. orig .. "" .. file)
350 if testing("IPv4") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " -o " .. orig .. path .. " " .. file .." &") end 357 if testing("IPv4") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " -o " .. orig .. path .. " " .. file .." &") end
351 else D("checkHost " .. orig .. " -> " .. host) end 358 else D("checkHost " .. orig .. " -> " .. host) end
352 gatherIPs(ph.host) 359 local h = mirrors[ph.host]
353 for k, v in pairs(IP[ph.host]) do 360 if nil == h then return end
354 D(" DNS record " .. v .. " " .. ph.host .. " -> " .. k) 361 for k, v in pairs(h.IPs) do
355 if v == "A" then 362 if "table" == type(v) then
356 if testing("IPv4") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " " .. k .. " " .. file .." &") end 363 for k1, v1 in pairs(v) do
357 elseif v == "AAAA" then 364 if v1 == "A" then
358 if testing("IPv6") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " [" .. k .. "] " .. file .. " &") end 365 if testing("IPv4") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " " .. k1 .. " " .. file .." &") end
359 elseif v == "CNAME" then 366 elseif v1 == "AAAA" then
360 checkHost(orig, k, path, ip, file) -- Check the original, with the DNS records from the CNAME. Do not check the CNAME, it's just a source of IPs. 367 if testing("IPv6") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " [" .. k1 .. "] " .. file .. " &") end
361 elseif v == "SRV" then 368 end
362 print("SVR record found, now what do we do?") 369 end
370 else
371 if v == "A" then
372 if testing("IPv4") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " " .. k .. " " .. file .." &") end
373 elseif v == "AAAA" then
374 if testing("IPv6") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " [" .. k .. "] " .. file .. " &") end
375 end
363 end 376 end
364 end 377 end
365 end 378 end
@@ -410,6 +423,8 @@ local getMirrors = function ()
410 end 423 end
411 host = d 424 host = d
412 m[t] = d 425 m[t] = d
426 gatherIPs(host)
427 m["IPs"] = IP[host]
413 elseif "Protocols" == t then 428 elseif "Protocols" == t then
414 local prot = {} 429 local prot = {}
415 for w in d:gmatch("(%w+)") do 430 for w in d:gmatch("(%w+)") do