Make generating new salts independent of the system clock

Closes #553
This commit is contained in:
Dan 2020-12-12 16:46:40 +01:00
parent 7efd0d1d4e
commit 8b3e1ce9cc

View File

@ -19,6 +19,7 @@
import asyncio import asyncio
import logging import logging
import os import os
import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from hashlib import sha1 from hashlib import sha1
from io import BytesIO from io import BytesIO
@ -303,17 +304,15 @@ class Session:
log.info("NextSaltTask started") log.info("NextSaltTask started")
while True: while True:
now = datetime.now() now = datetime.fromtimestamp(time.perf_counter() - MsgId.reference_clock + MsgId.server_time)
# Seconds to wait until middle-overlap, which is # Seconds to wait until middle-overlap, which is
# 15 minutes before/after the current/next salt end/start time # 15 minutes before/after the current/next salt end/start time
valid_until = datetime.fromtimestamp(self.current_salt.valid_until) valid_until = datetime.fromtimestamp(self.current_salt.valid_until)
dt = (valid_until - now).total_seconds() - 900 dt = (valid_until - now).total_seconds() - 900
log.info("Next salt in {:.0f}m {:.0f}s ({})".format( minutes, seconds = divmod(int(dt), 60)
dt // 60, dt % 60, log.info(f"Next salt in {minutes:.0f}m {seconds:.0f}s (at {now + timedelta(seconds=dt)})")
now + timedelta(seconds=dt)
))
try: try:
await asyncio.wait_for(self.next_salt_task_event.wait(), dt) await asyncio.wait_for(self.next_salt_task_event.wait(), dt)