diff options
author | onefang | 2019-11-25 02:31:15 +1000 |
---|---|---|
committer | onefang | 2019-11-25 02:31:15 +1000 |
commit | 8290a02946e3e4f202b3377b132fabc57df80f63 (patch) | |
tree | 73298c98d60e425f1b324b0dd362a9e625bf0e97 | |
parent | git ignore all the results directories. (diff) | |
download | apt-panopticon-8290a02946e3e4f202b3377b132fabc57df80f63.zip apt-panopticon-8290a02946e3e4f202b3377b132fabc57df80f63.tar.gz apt-panopticon-8290a02946e3e4f202b3377b132fabc57df80f63.tar.bz2 apt-panopticon-8290a02946e3e4f202b3377b132fabc57df80f63.tar.xz |
Clean up the timeout code.
Make it a command line parameter.
Re-factor the code somewhat.
Comment out the timeout backoff, for now.
Reduce the retry sleep time.
-rwxr-xr-x | apt-panopticon.lua | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/apt-panopticon.lua b/apt-panopticon.lua index cd1bca0..ed08c66 100755 --- a/apt-panopticon.lua +++ b/apt-panopticon.lua | |||
@@ -48,6 +48,12 @@ options = | |||
48 | -- "Updated", | 48 | -- "Updated", |
49 | }, | 49 | }, |
50 | }, | 50 | }, |
51 | timeout = | ||
52 | { | ||
53 | typ = "number", | ||
54 | help = "", | ||
55 | value = 15, | ||
56 | }, | ||
51 | reports = | 57 | reports = |
52 | { | 58 | { |
53 | typ = "table", | 59 | typ = "table", |
@@ -389,6 +395,7 @@ local nlst = function (u) | |||
389 | end | 395 | end |
390 | 396 | ||
391 | local timeouts = 0; | 397 | local timeouts = 0; |
398 | local totalTimeouts = 0 | ||
392 | checkHEAD = function (host, URL, r, retry) | 399 | checkHEAD = function (host, URL, r, retry) |
393 | if nil == r then r = 0 end | 400 | if nil == r then r = 0 end |
394 | if nil == retry then retry = 0 end | 401 | if nil == retry then retry = 0 end |
@@ -399,13 +406,17 @@ checkHEAD = function (host, URL, r, retry) | |||
399 | check = "Redirecting to" | 406 | check = "Redirecting to" |
400 | end | 407 | end |
401 | if 0 < retry then | 408 | if 0 < retry then |
402 | os.execute("sleep " .. math.random(1, 4)) | 409 | os.execute("sleep " .. math.random(1, 3)) |
403 | check = "Retry " .. retry .. " " .. check | 410 | check = "Retry " .. retry .. " " .. check |
404 | end | 411 | end |
405 | if 2 <= timeouts then | 412 | if 2 <= timeouts then |
406 | E("too many timeouts! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, "", host) | 413 | E("too many timeouts! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, "", host) |
407 | return | 414 | return |
408 | end | 415 | end |
416 | if 4 <= (totalTimeouts) then | ||
417 | E("Way too many timeouts!", PU.scheme, "", host) | ||
418 | return | ||
419 | end | ||
409 | if 20 <= r then | 420 | if 20 <= r then |
410 | E("too many redirects! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, "", host) | 421 | E("too many redirects! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, "", host) |
411 | return | 422 | return |
@@ -442,7 +453,7 @@ checkHEAD = function (host, URL, r, retry) | |||
442 | end | 453 | end |
443 | IP = '--connect-to "' .. pu.host .. '::' .. PU.host .. ':"' | 454 | IP = '--connect-to "' .. pu.host .. '::' .. PU.host .. ':"' |
444 | end | 455 | end |
445 | local cmd = 'curl -I --retry 0 -s --path-as-is --connect-timeout 15 --max-redirs 0 ' .. IP .. ' ' .. '-o /dev/null -D results/"HEADERS_' .. fname .. '" ' .. | 456 | local cmd = 'ionice -c3 nice -n 19 curl -I --retry 0 -s --path-as-is --connect-timeout ' .. options.timeout.value .. ' --max-redirs 0 ' .. IP .. ' ' .. '-o /dev/null -D results/"HEADERS_' .. fname .. '" ' .. |
446 | hdr .. ' -w "#%{http_code} %{ssl_verify_result} %{url_effective}\\n" ' .. PU.scheme .. '://' .. host .. PU.path .. ' >>results/"STATUS_' .. fname .. '"' | 457 | hdr .. ' -w "#%{http_code} %{ssl_verify_result} %{url_effective}\\n" ' .. PU.scheme .. '://' .. host .. PU.path .. ' >>results/"STATUS_' .. fname .. '"' |
447 | local status, result = execute(cmd) | 458 | local status, result = execute(cmd) |
448 | os.execute('cat results/"HEADERS_' .. fname .. '" >>results/"STATUS_' .. fname .. '" 2>/dev/null; rm results/"HEADERS_' .. fname .. '" 2>/dev/null') | 459 | os.execute('cat results/"HEADERS_' .. fname .. '" >>results/"STATUS_' .. fname .. '" 2>/dev/null; rm results/"HEADERS_' .. fname .. '" 2>/dev/null') |
@@ -479,7 +490,7 @@ checkHEAD = function (host, URL, r, retry) | |||
479 | E(" " .. code .. " " .. cstr .. ". " .. check .. " " .. host .. " -> " .. URL, PU.scheme, "", host) | 490 | E(" " .. code .. " " .. cstr .. ". " .. check .. " " .. host .. " -> " .. URL, PU.scheme, "", host) |
480 | else | 491 | else |
481 | I(" " .. code .. " " .. cstr .. ". " .. check .. " " .. host .. " -> " .. URL) | 492 | I(" " .. code .. " " .. cstr .. ". " .. check .. " " .. host .. " -> " .. URL) |
482 | timeouts = timeouts - 1 -- Backoff the timeouts count if we managed to get through. | 493 | -- timeouts = timeouts - 1 -- Backoff the timeouts count if we managed to get through. |
483 | if nil ~= location then | 494 | if nil ~= location then |
484 | pu = url.parse(location, defaultURL) | 495 | pu = url.parse(location, defaultURL) |
485 | if (pu.scheme ~= PU.scheme) then | 496 | if (pu.scheme ~= PU.scheme) then |
@@ -515,31 +526,44 @@ checkHEAD = function (host, URL, r, retry) | |||
515 | end | 526 | end |
516 | end | 527 | end |
517 | 528 | ||
529 | local checkTimeouts = function(host, scheme, URL) | ||
530 | if testing(scheme) then | ||
531 | totalTimeouts = totalTimeouts + timeouts; timeouts = 0 | ||
532 | checkHEAD(host, scheme .. "://" .. URL) | ||
533 | if 4 <= (totalTimeouts) then | ||
534 | E("Way too many timeouts!", scheme, "", host) | ||
535 | return true | ||
536 | end | ||
537 | end | ||
538 | return false | ||
539 | end | ||
540 | |||
518 | local checkFiles = function (host, ip, path, file) | 541 | local checkFiles = function (host, ip, path, file) |
542 | timeouts = 0 | ||
519 | if nil == path then path = "" end | 543 | if nil == path then path = "" end |
520 | if nil ~= file then | 544 | if nil ~= file then |
521 | if "redir" == ip then ip = host end | 545 | if "redir" == ip then ip = host end |
522 | I(" Checking IP for file " .. host .. " -> " .. ip .. " " .. path .. " " .. file) | 546 | I(" Checking IP for file " .. host .. " -> " .. ip .. " " .. path .. " " .. file) |
523 | if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. file) end | 547 | if checkTimeouts(host, "http", ip .. path .. "/" .. file) then return end |
524 | if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. file) end | 548 | if checkTimeouts(host, "https", ip .. path .. "/" .. file) then return end |
549 | -- if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. file); if checkTimeouts(host, "http" ) then return end; end | ||
550 | -- if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. file); if checkTimeouts(host, "https") then return end; end | ||
525 | else | 551 | else |
526 | I(" Checking IP " .. host .. " -> " .. ip .. " " .. path) | 552 | I(" Checking IP " .. host .. " -> " .. ip .. " " .. path) |
527 | for i, s in pairs(referenceDevs) do | 553 | for i, s in pairs(referenceDevs) do |
528 | local t = timeouts; timeouts = 0 | 554 | if checkTimeouts(host, "http", ip .. path .. "/" .. s) then return end |
529 | if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. s) end | 555 | if checkTimeouts(host, "https", ip .. path .. "/" .. s) then return end |
530 | t = t + timeouts; timeouts = 0 | 556 | -- if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. s); if checkTimeouts(host, "http" ) then return end; end |
531 | if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. s) end | 557 | -- if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. s); if checkTimeouts(host, "https") then return end; end |
532 | if 4 <= (t + timeouts) then return end | ||
533 | end | 558 | end |
534 | 559 | ||
535 | for i, s in pairs(releases) do | 560 | for i, s in pairs(releases) do |
536 | for j, k in pairs(releaseFiles) do | 561 | for j, k in pairs(releaseFiles) do |
537 | if repoExists(s .. k) then | 562 | if repoExists(s .. k) then |
538 | local t = timeouts; timeouts = 0 | 563 | if checkTimeouts(host, "http", ip .. path .. "/merged/dists/" .. s .. k) then return end |
539 | if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/merged/dists/" .. s .. k) end | 564 | if checkTimeouts(host, "https", ip .. path .. "/merged/dists/" .. s .. k) then return end |
540 | t = t + timeouts; timeouts = 0 | 565 | -- if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/merged/dists/" .. s .. k); if checkTimeouts(host, "http" ) then return end; end |
541 | if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/merged/dists/" .. s .. k) end | 566 | -- if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/merged/dists/" .. s .. k); if checkTimeouts(host, "https") then return end; end |
542 | if 4 <= (t + timeouts) then return end | ||
543 | end | 567 | end |
544 | end | 568 | end |
545 | end | 569 | end |
@@ -726,7 +750,7 @@ if 0 ~= #args then | |||
726 | end | 750 | end |
727 | end | 751 | end |
728 | else | 752 | else |
729 | options[option].value = a | 753 | options[option].value = a:sub(e + 1, -1) |
730 | end | 754 | end |
731 | option = "" | 755 | option = "" |
732 | end | 756 | end |