Browse Source

detect stale persisted cm list and update

pull/168/head
Rossen Georgiev 6 years ago
parent
commit
ffed0571f6
  1. 33
      steam/client/__init__.py

33
steam/client/__init__.py

@ -128,18 +128,31 @@ class SteamClient(CMClient, BuiltinBase):
if self.credential_location: if self.credential_location:
filepath = os.path.join(self.credential_location, 'cm_servers.json') filepath = os.path.join(self.credential_location, 'cm_servers.json')
if not os.path.exists(filepath): if os.path.exists(filepath):
data = {
'cell_id': self.cm_servers.cell_id,
'last_updated': self.cm_servers.last_updated,
'servers': list(zip(map(ip_from_int, msg.body.cm_addresses), msg.body.cm_ports)),
}
try: try:
with open(filepath, 'wb') as f: with open(filepath, 'r') as f:
f.write(json.dumps(data, indent=True).encode('ascii')) data = json.load(f)
self._LOG.debug("Saved CM servers to %s" % repr(filepath)) except ValueError:
self._LOG.error("Failed parsing %s", repr(filepath))
except IOError as e: except IOError as e:
self._LOG.error("saving %s: %s" % (filepath, str(e))) self._LOG.error("Failed reading %s (%s)", repr(filepath), str(e))
else:
if data.get('last_updated', 0) + 3600*24 > time():
return
self._LOG.debug("Persisted CM server list is stale")
data = {
'cell_id': self.cm_servers.cell_id,
'last_updated': self.cm_servers.last_updated,
'servers': list(zip(map(ip_from_int, msg.body.cm_addresses), msg.body.cm_ports)),
}
try:
with open(filepath, 'wb') as f:
f.write(json.dumps(data, indent=True).encode('ascii'))
self._LOG.debug("Saved CM servers to %s" % repr(filepath))
except IOError as e:
self._LOG.error("saving %s: %s" % (filepath, str(e)))
def _handle_jobs(self, event, *args): def _handle_jobs(self, event, *args):
if isinstance(event, EMsg): if isinstance(event, EMsg):

Loading…
Cancel
Save