next-share: print time-based peer information
authorP2P-Next <p2p-next@cs.pub.ro>
Tue, 21 Sep 2010 06:32:52 +0000 (09:32 +0300)
committerP2P-Next <p2p-next@cs.pub.ro>
Tue, 21 Sep 2010 06:32:52 +0000 (09:32 +0300)
When peer logging is enabled print information each
PEERLIST_OUTPUT_INTERVAL seconds starting from the epoch in order to
ensure common time around test systems.

instrumentation/next-share/BaseLib/Tools/cmdlinedl.py

index 5dff96b..0f7594c 100644 (file)
@@ -60,12 +60,9 @@ def print_version():
 # use -l/--peer-logging option to enable peer logging
 peer_logging = False
 
-# number of state_callback calls to print peer list information
+# print peer list information each PEERLIST_OUTPUT_INTERVAL seconds
 PEERLIST_OUTPUT_INTERVAL = 5
 
-# number of callback counts
-callback_count = 0
-
 # Print torrent statistics
 def state_callback(ds):
     d = ds.get_download()
@@ -81,14 +78,11 @@ def state_callback(ds):
     if not peer_logging:
         return (1.0, peer_logging)
 
-    # peer listing each PEERLIST_OUTPUT_INTERVAL state_callback calls
-    global callback_count
-    callback_count = callback_count + 1
-
-    if callback_count == PEERLIST_OUTPUT_INTERVAL:
-        callback_count = 0
-        peerlist = ds.get_peerlist()
+    # peer listing each PEERLIST_OUTPUT_INTERVAL seconds
+    seconds_since_epoch = int(time.time())
+    if seconds_since_epoch % PEERLIST_OUTPUT_INTERVAL == 0:
         print >>sys.stderr, '--Peers: (%s) ' % (time.strftime("%b %d %H:%M:%S", time.localtime())),
+        peerlist = ds.get_peerlist()
         if peerlist is None or not peerlist:
             pass
         else: