[tor-commits] [arm/master] Narrowing scope of _getRelayAttr()
atagar at torproject.org
atagar at torproject.org
Sat Jun 1 01:06:18 UTC 2013
commit bf057c32f0ae5bc3c0e7884a95e00e1a055b0f4d
Author: Damian Johnson <atagar at torproject.org>
Date: Fri May 31 18:03:59 2013 -0700
Narrowing scope of _getRelayAttr()
Moving several attributes from _getRelayAttr() up to their relevant methods.
This has two disadvantages: we lose caching and it's no longer under our
connection lock. However, this gets us closer to purging this controller
wrapper (stem should handle any caching and locking on our behalf).
---
src/util/torTools.py | 80 +++++++++++++++++++++++---------------------------
1 file changed, 37 insertions(+), 43 deletions(-)
diff --git a/src/util/torTools.py b/src/util/torTools.py
index e4c6b5c..49506c5 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -449,7 +449,15 @@ class Controller:
default - result if the query fails or this relay isn't a part of the consensus yet
"""
- return self._getRelayAttr("flags", default)
+ myFingerprint = self.getInfo("fingerprint", None)
+
+ if myFingerprint:
+ myStatusEntry = self.controller.get_network_status(myFingerprint)
+
+ if myStatusEntry:
+ return myStatusEntry.flags
+
+ return default
def getVersion(self):
"""
@@ -486,7 +494,7 @@ class Controller:
provides None.
"""
- return self._getRelayAttr("user", None)
+ return self.controller.get_user(None)
def getMyFileDescriptorUsage(self):
"""
@@ -534,7 +542,29 @@ class Controller:
use (unfortunately, this might be out of date).
"""
- return self._getRelayAttr("authorities", [])
+ # There's two configuration options that can overwrite the default
+ # authorities: DirServer and AlternateDirAuthority.
+
+ # TODO: Both options accept a set of flags to more precisely set what they
+ # overwrite. Ideally this would account for these flags to more accurately
+ # identify authority connections from relays.
+
+ dirServerCfg = self.getOption("DirServer", [], True)
+ altDirAuthCfg = self.getOption("AlternateDirAuthority", [], True)
+ altAuthoritiesCfg = dirServerCfg + altDirAuthCfg
+
+ if altAuthoritiesCfg:
+ result = []
+
+ # entries are of the form:
+ # [nickname] [flags] address:port fingerprint
+ for entry in altAuthoritiesCfg:
+ locationComp = entry.split()[-2] # address:port component
+ result.append(tuple(locationComp.split(":", 1)))
+
+ return result
+ else:
+ return list(DIR_SERVERS)
def getPathPrefix(self):
"""
@@ -551,7 +581,10 @@ class Controller:
can't be determined then this provides None.
"""
- return self._getRelayAttr("startTime", None)
+ try:
+ return system.get_start_time(self.controller.get_pid())
+ except:
+ return None
def isExitingAllowed(self, ipAddress, port):
"""
@@ -1002,17 +1035,14 @@ class Controller:
if myFingerprint:
for desc in event.desc:
if desc.fingerprint == myFingerprint:
- self._cachedParam["flags"] = None
self._cachedParam["bwMeasured"] = None
return
else:
- self._cachedParam["flags"] = None
self._cachedParam["bwMeasured"] = None
def new_consensus_event(self, event):
self.connLock.acquire()
- self._cachedParam["flags"] = None
self._cachedParam["bwMeasured"] = None
# reconstructs consensus based mappings
@@ -1256,16 +1286,6 @@ class Controller:
if myStatusEntry and hasattr(myStatusEntry, 'bandwidth'):
result = myStatusEntry.bandwidth
- elif key == "flags":
- myFingerprint = self.getInfo("fingerprint", None)
-
- if myFingerprint:
- myStatusEntry = self.controller.get_network_status(myFingerprint)
-
- if myStatusEntry:
- result = myStatusEntry.flags
- elif key == "user":
- result = self.controller.get_user(None)
elif key == "fdLimit":
# provides -1 if the query fails
queriedLimit = self.getInfo("process/descriptor-limit", None)
@@ -1310,32 +1330,6 @@ class Controller:
self._pathPrefixLogging = False # prevents logging if fetched again
result = prefixPath
- elif key == "startTime":
- try:
- result = system.get_start_time(self.controller.get_pid())
- except:
- pass
- elif key == "authorities":
- # There's two configuration options that can overwrite the default
- # authorities: DirServer and AlternateDirAuthority.
-
- # TODO: Both options accept a set of flags to more precisely set what they
- # overwrite. Ideally this would account for these flags to more accurately
- # identify authority connections from relays.
-
- dirServerCfg = self.getOption("DirServer", [], True)
- altDirAuthCfg = self.getOption("AlternateDirAuthority", [], True)
- altAuthoritiesCfg = dirServerCfg + altDirAuthCfg
-
- if altAuthoritiesCfg:
- result = []
-
- # entries are of the form:
- # [nickname] [flags] address:port fingerprint
- for entry in altAuthoritiesCfg:
- locationComp = entry.split()[-2] # address:port component
- result.append(tuple(locationComp.split(":", 1)))
- else: result = list(DIR_SERVERS)
# cache value
if result != None: self._cachedParam[key] = result
More information about the tor-commits
mailing list