diff options
Diffstat (limited to 'mirror-checker.lua')
-rwxr-xr-x | mirror-checker.lua | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/mirror-checker.lua b/mirror-checker.lua index 69dd9e8..e7de781 100755 --- a/mirror-checker.lua +++ b/mirror-checker.lua | |||
@@ -203,6 +203,7 @@ local nlst = function (u) | |||
203 | return r and table.concat(t), e | 203 | return r and table.concat(t), e |
204 | end | 204 | end |
205 | 205 | ||
206 | local timeouts = 0; | ||
206 | checkHEAD = function (host, URL, r, retry) | 207 | checkHEAD = function (host, URL, r, retry) |
207 | if nil == r then r = 0 end | 208 | if nil == r then r = 0 end |
208 | if nil == retry then retry = 0 end | 209 | if nil == retry then retry = 0 end |
@@ -213,14 +214,18 @@ checkHEAD = function (host, URL, r, retry) | |||
213 | check = "Redirecting to" | 214 | check = "Redirecting to" |
214 | end | 215 | end |
215 | if 0 < retry then | 216 | if 0 < retry then |
216 | -- TODO - should have a random sleep here before retrying. | 217 | os.execute("sleep " .. math.random(1, 4)) |
217 | check = "Retry " .. retry .. " " .. check | 218 | check = "Retry " .. retry .. " " .. check |
218 | end | 219 | end |
220 | if 3 < timeouts then | ||
221 | E("too many timeouts! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) | ||
222 | return | ||
223 | end | ||
219 | if 20 < r then | 224 | if 20 < r then |
220 | E("too many redirects! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) | 225 | E("too many redirects! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) |
221 | return | 226 | return |
222 | end | 227 | end |
223 | if 10 < retry then | 228 | if 4 < retry then |
224 | E("too many retries! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) | 229 | E("too many retries! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) |
225 | return | 230 | return |
226 | end | 231 | end |
@@ -241,12 +246,14 @@ checkHEAD = function (host, URL, r, retry) | |||
241 | E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) | 246 | E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) |
242 | -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth. | 247 | -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth. |
243 | -- Might be worthwhile retrying those, some number of times. | 248 | -- Might be worthwhile retrying those, some number of times. |
244 | if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkHEAD(host, URL, r, retry + 1) end | 249 | if "timeout" == c then timeouts = timeouts + 1 end |
250 | if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkHEAD(host, URL, r, retry + 1, timeouts) end | ||
245 | else | 251 | else |
246 | if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then | 252 | if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then |
247 | E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) | 253 | E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) |
248 | else | 254 | else |
249 | I(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL) | 255 | I(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL) |
256 | timeouts = timeouts - 1 -- Backoff the timeouts count if we managed to get through. | ||
250 | end | 257 | end |
251 | l = h.location | 258 | l = h.location |
252 | if nil ~= l then | 259 | if nil ~= l then |
@@ -295,14 +302,18 @@ local checkFiles = function (host, ip, path, file) | |||
295 | I(" Checking IP " .. host .. " -> " .. ip .. " " .. path) | 302 | I(" Checking IP " .. host .. " -> " .. ip .. " " .. path) |
296 | for i, s in pairs(referenceDevs) do | 303 | for i, s in pairs(referenceDevs) do |
297 | if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. s) end | 304 | if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. s) end |
305 | if 3 < timeouts then return end | ||
298 | if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. s) end | 306 | if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. s) end |
307 | if 3 < timeouts then return end | ||
299 | end | 308 | end |
300 | 309 | ||
301 | for i, s in pairs(releases) do | 310 | for i, s in pairs(releases) do |
302 | for j, k in pairs(releaseFiles) do | 311 | for j, k in pairs(releaseFiles) do |
303 | if repoExists(s .. k) then | 312 | if repoExists(s .. k) then |
304 | if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/merged/dists/" .. s .. k) end | 313 | if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/merged/dists/" .. s .. k) end |
314 | if 3 < timeouts then return end | ||
305 | if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/merged/dists/" .. s .. k) end | 315 | if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/merged/dists/" .. s .. k) end |
316 | if 3 < timeouts then return end | ||
306 | end | 317 | end |
307 | end | 318 | end |
308 | end | 319 | end |