commit cbc5d8c69e9386b15a3d366a1b3e9a4b379c96ba Author: Sebastian Hahn sebastian@torproject.org Date: Sun Sep 4 08:32:34 2011 +0200
Use UTC consistently --- bulklist.fcgi | 4 +++- checkweb.py | 3 ++- controller.py | 2 +- dnsel/dnsel.py | 5 +++-- doc/data-spec.txt | 6 +++--- query.py | 6 +++--- 6 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/bulklist.fcgi b/bulklist.fcgi index c447903..92dfcff 100755 --- a/bulklist.fcgi +++ b/bulklist.fcgi @@ -7,6 +7,8 @@ sys.path.append('/home/torbel/torbel')
import socket
+from calendar import timegm + import torbel.query as query from cgi import escape from urlparse import parse_qs @@ -28,7 +30,7 @@ def update_elist(): global elist elist = query.ExitList(filename = "/home/torbel/export/torbel_export.csv", status_filename = "/home/torbel/export/torbel_export.status") - nextUpdate = math.ceil(time.mktime(elist.next_update.timetuple()) - time.time()) + nextUpdate = math.ceil(timegm(elist.next_update.timetuple()) - time.time()) if nextUpdate > 0: log.debug("Scheduling update in %d seconds.", nextUpdate) Timer(nextUpdate, update_elist, ()).start() diff --git a/checkweb.py b/checkweb.py index 85a99a5..32c6388 100755 --- a/checkweb.py +++ b/checkweb.py @@ -11,6 +11,7 @@ from logger import * from flup.server.fcgi import WSGIServer
import time +from calendar import timegm from threading import Timer
import math @@ -25,7 +26,7 @@ def update_elist(): global elist elist = query.ExitList(filename = "/home/torbel/export/torbel_export.csv", status_filename = "/home/torbel/export/torbel_export.status") - nextUpdate = math.ceil(time.mktime(elist.next_update.timetuple()) - time.time()) + nextUpdate = math.ceil(timegm(elist.next_update.timetuple()) - time.time()) if nextUpdate > 0: log.debug("Scheduling update in %d seconds.", nextUpdate) Timer(nextUpdate, update_elist, ()).start() diff --git a/controller.py b/controller.py index 807ce18..fe6dbf7 100644 --- a/controller.py +++ b/controller.py @@ -524,7 +524,7 @@ class Controller(TorCtl.EventHandler):
# Add 30 seconds to the config.export_interval time so clients don't # try to fetch it as we're writing it. - next = datetime.now() + timedelta(0, config.export_interval * 60 + 30) + next = datetime.utcnow() + timedelta(0, config.export_interval * 60 + 30) nextstr = next.strftime("%b %d %Y %H:%M:%S") export_file_prefix = config.export_file_prefix fn = export_file_prefix + ".status" diff --git a/dnsel/dnsel.py b/dnsel/dnsel.py index 2060562..b39230a 100755 --- a/dnsel/dnsel.py +++ b/dnsel/dnsel.py @@ -6,6 +6,7 @@ # and the TorBEL query interface. import os, sys, time from datetime import datetime +from calendar import timegm
from zope.interface import implements from twisted.names import server, dns, common, error @@ -32,7 +33,7 @@ class TorDNSServerFactory(server.DNSServerFactory): log.info("Export %s likely stale.", filename)
# Set up updates. - nextUpdate = time.mktime(self.el.next_update.timetuple()) - time.time() + nextUpdate = timegm(self.el.next_update.timetuple()) - time.time() if nextUpdate > 0: log.debug("Scheduling first update in %.1f seconds.", nextUpdate) reactor.callLater(nextUpdate, self.update) @@ -45,7 +46,7 @@ class TorDNSServerFactory(server.DNSServerFactory):
def update(self): next = self.el.update() - nextUpdate = time.mktime(next.timetuple()) - time.time() + nextUpdate = timegm(next.timetuple()) - time.time() if nextUpdate > 0: log.info("ExitList updated. Next update in %.1f seconds.", nextUpdate) reactor.callLater(nextUpdate, self.update) diff --git a/doc/data-spec.txt b/doc/data-spec.txt index 9c39d87..5d6db11 100644 --- a/doc/data-spec.txt +++ b/doc/data-spec.txt @@ -108,9 +108,9 @@ Status: Draft
* NextUpdate "Datetime": The value of this key is a date-time string with strftime(3) format - "%b %d %Y %H:%M:%S". This date represents the absolute earliest time at - which a TorBEL export consumer should attempt to fetch an updated export - file. + "%b %d %Y %H:%M:%S" in UTC. This date represents the absolute earliest + time at which a TorBEL export consumer should attempt to fetch an + updated export file. An example of this key is: NextUpdate "Aug 12 16:51:04" This key must appear exactly once in the status file. diff --git a/query.py b/query.py index 16a6e7a..a5dda85 100644 --- a/query.py +++ b/query.py @@ -212,7 +212,7 @@ class ExitList:
def should_update(self): """ Returns True if our updates are out of date. """ - return self.next_update and (datetime.datetime.now() > self.next_update) + return self.next_update and (datetime.datetime.utcnow() > self.next_update)
def update(self, force = False): """ Read and update to the latest export and status files. @@ -232,13 +232,13 @@ class ExitList: # Import the status file, if available. if self.status_filename: self.next_update, self.export_files = self.read_status(self.status_filename) - self.stale = (datetime.datetime.now() > self.next_update) + self.stale = (datetime.datetime.utcnow() > self.next_update) else: self.next_update = None self.export_files = None
# Record our last update time. - self.last_update = datetime.datetime.now() + self.last_update = datetime.datetime.utcnow()
return self.next_update
tor-commits@lists.torproject.org