mirror of
https://github.com/chocolate-doom/master-server.git
synced 2024-11-10 07:11:38 +00:00
Periodically force queries of servers that are refreshing themselves, to
keep metadata up to date. Subversion-branch: /master Subversion-revision: 2205
This commit is contained in:
parent
073864be95
commit
5432fd9b0f
1 changed files with 15 additions and 0 deletions
|
@ -36,6 +36,10 @@ LOG_FILE = "chocolate-master.log"
|
|||
|
||||
SERVER_TIMEOUT = 2 * 60 * 60 # 2 hours
|
||||
|
||||
# How long is metadata valid before we force another query to refresh it?
|
||||
|
||||
METADATA_REFRESH_TIME = 6 * 60 * 60 # 6 hours
|
||||
|
||||
# Maximum length of a query response.
|
||||
|
||||
MAX_RESPONSE_LEN = 1000
|
||||
|
@ -87,8 +91,12 @@ class Server:
|
|||
self.add_time = time()
|
||||
|
||||
def set_metadata(self, metadata):
|
||||
self.metadata_time = time()
|
||||
self.metadata = metadata
|
||||
|
||||
def metadata_age(self):
|
||||
return time() - self.metadata_time
|
||||
|
||||
def timed_out(self):
|
||||
return time() - self.add_time > SERVER_TIMEOUT
|
||||
|
||||
|
@ -221,6 +229,13 @@ class MasterServer:
|
|||
server = Server(addr)
|
||||
self.servers[addr] = server
|
||||
|
||||
# If the metadata for this server is old, un-verify it
|
||||
# to force a query to refresh it.
|
||||
|
||||
if server.verified and server.metadata_age() > METADATA_REFRESH_TIME:
|
||||
self.log_output(addr, "Metadata is old, forcing query")
|
||||
server.verified = False
|
||||
|
||||
# If the server has already been verified, we can send a
|
||||
# reply immediately. Otherwise, query the server via a
|
||||
# different socket first to verify it.
|
||||
|
|
Loading…
Reference in a new issue