1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 08:17:13 +03:00

Use EDDN gateway's idea of time-of-day rather than NTP's

Reverts ea0c3d3
This commit is contained in:
Jonathan Harris 2017-06-28 13:36:41 +01:00
parent ea0c3d3e9a
commit fac7501855
5 changed files with 38 additions and 39 deletions

View File

@ -11,7 +11,7 @@ from os import chdir, mkdir, environ
from os.path import dirname, expanduser, isdir, join
import re
import requests
from time import time, localtime, strftime, strptime
from time import gmtime, time, localtime, strftime, strptime
from calendar import timegm
import webbrowser
@ -35,6 +35,7 @@ import Tkinter as tk
import ttk
import tkFileDialog
import tkFont
import tkMessageBox
from ttkHyperlinkLabel import HyperlinkLabel
if __debug__:
@ -57,7 +58,6 @@ import coriolis
import eddb
import edshipyard
import loadout
from ntp import NTPCheck
import stats
import prefs
import plug
@ -71,6 +71,11 @@ EDDB = eddb.EDDB()
SERVER_RETRY = 5 # retry pause for Companion servers [s]
EDSM_POLL = 0.1
# Limits on local clock drift from EDDN gateway
DRIFT_THRESHOLD = 3 * 60
TZ_THRESHOLD = 30 * 60
CLOCK_THRESHOLD = 11 * 60 * 60 + TZ_THRESHOLD
class AppWindow:
@ -310,7 +315,15 @@ class AppWindow:
except:
if __debug__: print_exc()
if not NTPCheck(self.w): # Check system time
# Check system time
drift = abs(time() - self.eddn.time())
if drift > DRIFT_THRESHOLD:
tkMessageBox.showerror(applongname,
_('This app requires accurate timestamps.') + '\n' + # Error message shown if system time is wrong
(TZ_THRESHOLD < drift < CLOCK_THRESHOLD and
_("Check your system's Time Zone setting.") or # Error message shown if system time is wrong
_("Check your system's Date and Time settings.")), # Error message shown if system time is wrong
parent = self.w)
self.w.destroy()
return

View File

@ -52,10 +52,10 @@
/* Menu item. [EDMarketConnector.py] */
"Check for Updates..." = "Check for Updates...";
/* Error message shown if system time is wrong. [ntp.py] */
/* Error message shown if system time is wrong. [EDMarketConnector.py] */
"Check your system's Date and Time settings." = "Check your system's Date and Time settings.";
/* Error message shown if system time is wrong. [ntp.py] */
/* Error message shown if system time is wrong. [EDMarketConnector.py] */
"Check your system's Time Zone setting." = "Check your system's Time Zone setting.";
/* Federation rank. [stats.py] */
@ -481,7 +481,7 @@
/* Appearance setting. [prefs.py] */
"Theme" = "Theme";
/* Error message shown if system time is wrong. [ntp.py] */
/* Error message shown if system time is wrong. [EDMarketConnector.py] */
"This app requires accurate timestamps." = "This app requires accurate timestamps.";
/* Help text in settings. [prefs.py] */

View File

@ -178,17 +178,17 @@ Download and extract the source code of the [latest release](https://github.com/
Mac:
* Requires the Python “keyring”, “ntplib”, “requests” and “watchdog” modules, plus an up-to-date “py2app” module if you also want to package the app - install these with `easy_install -U keyring ntplib requests watchdog py2app` .
* Requires the Python “keyring”, “requests” and “watchdog” modules, plus an up-to-date “py2app” module if you also want to package the app - install these with `easy_install -U keyring requests watchdog py2app` .
* Run with `./EDMarketConnector.py` .
Windows:
* Requires Python2.7 and the Python “keyring”, “ntplib”, “requests” and “watchdog” modules, plus “py2exe” 0.6 if you also want to package the app.
* Requires Python2.7 and the Python “keyring”, “requests” and “watchdog” modules, plus “py2exe” 0.6 if you also want to package the app.
* Run with `EDMarketConnector.py` .
Linux:
* Requires the Python “imaging-tk”, “iniparse”, “keyring”, “ntplib” and “requests” modules. On Debian-based systems install these with `sudo apt-get install python-imaging-tk python-iniparse python-ntplib python-keyring python-requests` .
* Requires the Python “imaging-tk”, “iniparse”, “keyring” and “requests” modules. On Debian-based systems install these with `sudo apt-get install python-imaging-tk python-iniparse python-keyring python-requests` .
* Run with `./EDMarketConnector.py` .
Command-line

18
eddn.py
View File

@ -10,6 +10,7 @@ import re
import requests
from sys import platform
import time
from calendar import timegm
import uuid
if platform != 'win32':
@ -29,8 +30,10 @@ replayfile = None # For delayed messages
class EDDN:
### UPLOAD = 'http://localhost:8081/upload/' # testing
UPLOAD = 'http://eddn-gateway.elite-markets.net:8080/upload/'
### SERVER = 'http://localhost:8081/' # testing
SERVER = 'http://eddn-gateway.elite-markets.net:8080/'
UPLOAD = '%s/upload/' % SERVER
HEALTH = '%s/health_check/' % SERVER
REPLAYPERIOD = 400 # Roughly two messages per second, accounting for send delays [ms]
REPLAYFLUSH = 20 # Update log on disk roughly every 10 seconds
@ -76,6 +79,17 @@ class EDDN:
replayfile.close()
replayfile = None
def time(self):
# Returns the EDDN gateway's idea of time-of-day.
# Assumes that the gateway returns a strictly compliant Date - https://tools.ietf.org/html/rfc7231#section-7.1.1.1
try:
r = self.session.get(self.HEALTH, timeout=timeout)
return timegm(time.strptime(r.headers['Date'], "%a, %d %b %Y %H:%M:%S GMT"))
except:
# On any error assume that we're good
if __debug__: print_exc()
return time.time()
def send(self, cmdr, msg):
if config.getint('anonymous'):
uploaderID = config.get('uploaderID')

28
ntp.py
View File

@ -1,28 +0,0 @@
from ntplib import NTPClient
from tkMessageBox import showerror
from config import applongname
if __debug__:
from traceback import print_exc
def NTPCheck(parent):
DRIFT_THRESHOLD = 3 * 60
TZ_THRESHOLD = 30 * 60
CLOCK_THRESHOLD = 12 * 60 * 60 + DRIFT_THRESHOLD
try:
response = NTPClient().request('pool.ntp.org')
if abs(response.offset) > DRIFT_THRESHOLD:
showerror(applongname,
_('This app requires accurate timestamps.') + '\n' + # Error message shown if system time is wrong
(TZ_THRESHOLD < abs(response.offset) < CLOCK_THRESHOLD and
_("Check your system's Time Zone setting.") or # Error message shown if system time is wrong
_("Check your system's Date and Time settings.")), # Error message shown if system time is wrong
parent = parent)
return False
except:
if __debug__: print_exc()
return True