Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Oct 13, 2024
1 parent 69c5ad7 commit 502ab55
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ def getErrorPK(server):
# only happen depending on it.
return "%s/%s/%d" % (server["ip"], server["address"], server["port"])

def isDomain(s):
# expressed as a regex: \.[A-Za-z][^.]*$
return "." in s and s.rpartition(".")[2][0].isalpha()

# Returns ping time in seconds (up), False (down), or None (error).
def serverUp(info):
sock = None
Expand Down Expand Up @@ -428,16 +432,17 @@ def asyncFinishThread(server):
type=socket.SOCK_DGRAM,
proto=socket.SOL_UDP)
except socket.gaierror:
err = "Unable to get address info for %s." % (server["address"],)
err = "Unable to get address info for %s" % server["address"]
app.logger.warning(err)
errorTracker.put(getErrorPK(server), err)
return

if checkAddress:
addresses = set(data[4][0] for data in info)
if not server["ip"] in addresses:
err = "Requester IP %s does not match host %s (valid: %s)." % \
(server["ip"], server["address"], " ".join(addresses))
err = "Requester IP %s does not match host %s" % (server["ip"], server["address"])
if isDomain(server["address"]):
err += " (valid: %s)" % " ".join(addresses)
app.logger.warning(err)
errorTracker.put(getErrorPK(server), err)
return
Expand All @@ -448,8 +453,9 @@ def asyncFinishThread(server):

server["ping"] = serverUp(info[0])
if not server["ping"]:
err = "Server %s port %d did not respond to ping (tried %s)" % \
(server["address"], server["port"], info[0][4][0])
err = "Server %s port %d did not respond to ping" % (server["address"], server["port"])
if isDomain(server["address"]):
err += " (tried %s)" % info[0][4][0]
app.logger.warning(err)
errorTracker.put(getErrorPK(server), err)
return
Expand Down Expand Up @@ -599,7 +605,7 @@ def get(self, k):
def cleanup(self):
with self.lock:
now = time.monotonic()
table = {k: e for e in self.table if e[0] >= now}
table = {k: e for k, e in self.table.items() if e[0] >= now}
self.table = table


Expand Down

0 comments on commit 502ab55

Please sign in to comment.