[or-cvs] r22851: {arm} Making heartbeats take all events into account (rather than (in arm/trunk: interface util)

Damian Johnson atagar1 at gmail.com
Tue Aug 10 15:19:30 UTC 2010


Author: atagar
Date: 2010-08-10 15:19:30 +0000 (Tue, 10 Aug 2010)
New Revision: 22851

Modified:
   arm/trunk/interface/controller.py
   arm/trunk/util/torTools.py
Log:
Making heartbeats take all events into account (rather than just BW).



Modified: arm/trunk/interface/controller.py
===================================================================
--- arm/trunk/interface/controller.py	2010-08-10 03:24:23 UTC (rev 22850)
+++ arm/trunk/interface/controller.py	2010-08-10 15:19:30 UTC (rev 22851)
@@ -491,7 +491,7 @@
       
       # provides a notice if there's been ten seconds since the last BW event
       lastHeartbeat = torTools.getConn().getHeartbeat()
-      if torTools.getConn().isAlive() and lastHeartbeat != 0:
+      if torTools.getConn().isAlive() and "BW" in torTools.getConn().getControllerEvents() and lastHeartbeat != 0:
         if not isUnresponsive and (time.time() - lastHeartbeat) >= 10:
           isUnresponsive = True
           log.log(log.NOTICE, "Relay unresponsive (last heartbeat: %s)" % time.ctime(lastHeartbeat))

Modified: arm/trunk/util/torTools.py
===================================================================
--- arm/trunk/util/torTools.py	2010-08-10 03:24:23 UTC (rev 22850)
+++ arm/trunk/util/torTools.py	2010-08-10 15:19:30 UTC (rev 22851)
@@ -49,11 +49,9 @@
 CONFIG = {"log.torGetInfo": log.DEBUG, "log.torGetConf": log.DEBUG}
 
 # events used for controller functionality:
-# BW - used to check for a periodic heartbeat
 # NOTICE - used to detect when tor is shut down
 # NEWDESC, NS, and NEWCONSENSUS - used for cache invalidation
-REQ_EVENTS = {"BW": "unable to check for a periodic heartbeat",
-              "NOTICE": "this will be unable to detect when tor is shut down",
+REQ_EVENTS = {"NOTICE": "this will be unable to detect when tor is shut down",
               "NEWDESC": "information related to descriptors will grow stale",
               "NS": "information related to the consensus will grow stale",
               "NEWCONSENSUS": "information related to the consensus will grow stale"}
@@ -293,7 +291,7 @@
     self._isReset = False               # internal flag for tracking resets
     self._status = TOR_CLOSED           # current status of the attached control port
     self._statusTime = 0                # unix time-stamp for the duration of the status
-    self.lastHeartbeat = 0              # time of the last bw event
+    self.lastHeartbeat = 0              # time of the last tor event
     
     # cached getInfo parameters (None if unset or possibly changed)
     self._cachedParam = dict([(arg, "") for arg in CACHE_ARGS])
@@ -373,9 +371,9 @@
   
   def getHeartbeat(self):
     """
-    Provides the time of the last registered BW event (this should occure every
-    second if relay's still responsive). This returns zero if there has never
-    been an attached tor instance.
+    Provides the time of the last registered tor event (if listening for BW
+    events then this should occure every second if relay's still responsive).
+    This returns zero if this has never received an event.
     """
     
     return self.lastHeartbeat
@@ -635,6 +633,13 @@
       return True
     else: return False
   
+  def getControllerEvents(self):
+    """
+    Provides the events the controller's currently configured to listen for.
+    """
+    
+    return list(self.controllerEvents)
+  
   def setControllerEvents(self, events):
     """
     Sets the events being requested from any attached tor instance, logging
@@ -808,10 +813,9 @@
       
       thread.start_new_thread(self._notifyStatusListeners, (TOR_INIT,))
   
-  def bandwidth_event(self, event):
-    self.lastHeartbeat = time.time()
-  
   def ns_event(self, event):
+    self._updateHeartbeat()
+    
     myFingerprint = self.getMyFingerprint()
     if myFingerprint:
       for ns in event.nslist:
@@ -826,16 +830,44 @@
       self._cachedParam["bwMeasured"] = None
   
   def new_consensus_event(self, event):
+    self._updateHeartbeat()
+    
     self._cachedParam["nsEntry"] = None
     self._cachedParam["flags"] = None
     self._cachedParam["bwMeasured"] = None
   
   def new_desc_event(self, event):
+    self._updateHeartbeat()
+    
     myFingerprint = self.getMyFingerprint()
     if not myFingerprint or myFingerprint in event.idlist:
       self._cachedParam["descEntry"] = None
       self._cachedParam["bwObserved"] = None
   
+  def circ_status_event(self, event):
+    self._updateHeartbeat()
+  
+  def buildtimeout_set_event(self, event):
+    self._updateHeartbeat()
+  
+  def stream_status_event(self, event):
+    self._updateHeartbeat()
+  
+  def or_conn_status_event(self, event):
+    self._updateHeartbeat()
+  
+  def stream_bw_event(self, event):
+    self._updateHeartbeat()
+  
+  def bandwidth_event(self, event):
+    self._updateHeartbeat()
+  
+  def address_mapped_event(self, event):
+    self._updateHeartbeat()
+  
+  def unknown_event(self, event):
+    self._updateHeartbeat()
+  
   def write(self, msg):
     """
     Tracks TorCtl events. Ugly hack since TorCtl/TorUtil.py expects a file.
@@ -853,6 +885,13 @@
   
   def flush(self): pass
   
+  def _updateHeartbeat(self):
+    """
+    Called on any event occurance to note the time it occured.
+    """
+    
+    self.lastHeartbeat = time.time()
+  
   def _getRelayAttr(self, key, default, cacheUndefined = True):
     """
     Provides information associated with this relay, using the cached value if



More information about the tor-commits mailing list