mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-05-31 15:49:41 +03:00
Use EDDN gateway's idea of time-of-day rather than NTP's
Reverts ea0c3d3
This commit is contained in:
parent
ea0c3d3e9a
commit
fac7501855
@ -11,7 +11,7 @@ from os import chdir, mkdir, environ
|
|||||||
from os.path import dirname, expanduser, isdir, join
|
from os.path import dirname, expanduser, isdir, join
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
from time import time, localtime, strftime, strptime
|
from time import gmtime, time, localtime, strftime, strptime
|
||||||
from calendar import timegm
|
from calendar import timegm
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
|
||||||
@ -35,6 +35,7 @@ import Tkinter as tk
|
|||||||
import ttk
|
import ttk
|
||||||
import tkFileDialog
|
import tkFileDialog
|
||||||
import tkFont
|
import tkFont
|
||||||
|
import tkMessageBox
|
||||||
from ttkHyperlinkLabel import HyperlinkLabel
|
from ttkHyperlinkLabel import HyperlinkLabel
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
@ -57,7 +58,6 @@ import coriolis
|
|||||||
import eddb
|
import eddb
|
||||||
import edshipyard
|
import edshipyard
|
||||||
import loadout
|
import loadout
|
||||||
from ntp import NTPCheck
|
|
||||||
import stats
|
import stats
|
||||||
import prefs
|
import prefs
|
||||||
import plug
|
import plug
|
||||||
@ -71,6 +71,11 @@ EDDB = eddb.EDDB()
|
|||||||
SERVER_RETRY = 5 # retry pause for Companion servers [s]
|
SERVER_RETRY = 5 # retry pause for Companion servers [s]
|
||||||
EDSM_POLL = 0.1
|
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:
|
class AppWindow:
|
||||||
|
|
||||||
@ -310,7 +315,15 @@ class AppWindow:
|
|||||||
except:
|
except:
|
||||||
if __debug__: print_exc()
|
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()
|
self.w.destroy()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -52,10 +52,10 @@
|
|||||||
/* Menu item. [EDMarketConnector.py] */
|
/* Menu item. [EDMarketConnector.py] */
|
||||||
"Check for Updates..." = "Check for Updates...";
|
"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.";
|
"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.";
|
"Check your system's Time Zone setting." = "Check your system's Time Zone setting.";
|
||||||
|
|
||||||
/* Federation rank. [stats.py] */
|
/* Federation rank. [stats.py] */
|
||||||
@ -481,7 +481,7 @@
|
|||||||
/* Appearance setting. [prefs.py] */
|
/* Appearance setting. [prefs.py] */
|
||||||
"Theme" = "Theme";
|
"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.";
|
"This app requires accurate timestamps." = "This app requires accurate timestamps.";
|
||||||
|
|
||||||
/* Help text in settings. [prefs.py] */
|
/* Help text in settings. [prefs.py] */
|
||||||
|
@ -178,17 +178,17 @@ Download and extract the source code of the [latest release](https://github.com/
|
|||||||
|
|
||||||
Mac:
|
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` .
|
* Run with `./EDMarketConnector.py` .
|
||||||
|
|
||||||
Windows:
|
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` .
|
* Run with `EDMarketConnector.py` .
|
||||||
|
|
||||||
Linux:
|
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` .
|
* Run with `./EDMarketConnector.py` .
|
||||||
|
|
||||||
Command-line
|
Command-line
|
||||||
|
18
eddn.py
18
eddn.py
@ -10,6 +10,7 @@ import re
|
|||||||
import requests
|
import requests
|
||||||
from sys import platform
|
from sys import platform
|
||||||
import time
|
import time
|
||||||
|
from calendar import timegm
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
if platform != 'win32':
|
if platform != 'win32':
|
||||||
@ -29,8 +30,10 @@ replayfile = None # For delayed messages
|
|||||||
|
|
||||||
class EDDN:
|
class EDDN:
|
||||||
|
|
||||||
### UPLOAD = 'http://localhost:8081/upload/' # testing
|
### SERVER = 'http://localhost:8081/' # testing
|
||||||
UPLOAD = 'http://eddn-gateway.elite-markets.net:8080/upload/'
|
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]
|
REPLAYPERIOD = 400 # Roughly two messages per second, accounting for send delays [ms]
|
||||||
REPLAYFLUSH = 20 # Update log on disk roughly every 10 seconds
|
REPLAYFLUSH = 20 # Update log on disk roughly every 10 seconds
|
||||||
|
|
||||||
@ -76,6 +79,17 @@ class EDDN:
|
|||||||
replayfile.close()
|
replayfile.close()
|
||||||
replayfile = None
|
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):
|
def send(self, cmdr, msg):
|
||||||
if config.getint('anonymous'):
|
if config.getint('anonymous'):
|
||||||
uploaderID = config.get('uploaderID')
|
uploaderID = config.get('uploaderID')
|
||||||
|
28
ntp.py
28
ntp.py
@ -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
|
|
Loading…
x
Reference in New Issue
Block a user