[tor-commits] [stem/master] Disable caching of HiddenServiceOptions

atagar at torproject.org atagar at torproject.org
Sat Sep 21 19:07:12 UTC 2013


commit 1d2fe8a218768eb5a1713cd2daa6d54df0d6c7ca
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Sep 21 12:05:25 2013 -0700

    Disable caching of HiddenServiceOptions
    
    Stem's controller has pretty straight forward caching for tor's configuration
    options. If you call 'GETCONF foo' then the value of foo is cached until you
    call either 'SETCONF foo' or 'RESETCONF foo'.
    
    In general this is all well and good, but HiddenServiceOptions behave in a
    different fashion. With those the caller might call 'SETCONF HiddenServiceDir'
    and expect 'GETCONF HiddenServiceOptions' to change. As such, opting out of
    caching hidden service options.
    
    This was a bug uncovered by wayzard on...
    
    http://stackoverflow.com/questions/18777837/tors-stem-module-python-loading-but-not-unloading-config
    https://trac.torproject.org/projects/tor/ticket/9792
    
    Prior to this fix...
    
    >>> from stem.control import Controller
    >>> controller = Controller.from_port()
    >>> controller.authenticate()
    >>> controller.get_conf_map('HiddenServiceOptions')
    {'HiddenServiceOptions': []}
    >>> controller.set_options([('HiddenServiceDir','/tmp/my_hidden_service'), ('HiddenServicePort', '1236 127.0.0.1:1236')])
    >>> controller.get_conf_map('HiddenServiceOptions')
    {'HiddenServiceOptions': []}
    
    Now it behaves as expected...
    
    >>> from stem.control import Controller
    >>> controller = Controller.from_port()
    >>> controller.authenticate()
    >>> controller.get_conf_map('HiddenServiceOptions')
    {'HiddenServiceOptions': []}
    >>> controller.set_options([('HiddenServiceDir','/tmp/my_hidden_service'), ('HiddenServicePort', '1236 127.0.0.1:1236')])
    >>> controller.get_conf_map('HiddenServiceOptions')
    {'HiddenServicePort': ['1236 127.0.0.1:1236'], 'HiddenServiceDir': ['/tmp/my_hidden_service']}
---
 docs/change_log.rst |    1 +
 stem/control.py     |   19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/docs/change_log.rst b/docs/change_log.rst
index 75a5e81..b7840b4 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -48,6 +48,7 @@ The following are only available within stem's `git repository
   * Added :func:`~stem.control.Controller.get_user` method to the :class:`~stem.control.Controller`
   * Added :func:`~stem.control.Controller.get_pid` method to the :class:`~stem.control.Controller`
   * :class:`~stem.response.events.StreamEvent` didn't recognize IPv6 addresses (:trac:`9181`)
+  * :func:`~stem.control.Controller.get_conf` mistakenly cached hidden service related options (:trac:`9792`)
 
  * **Descriptors**
 
diff --git a/stem/control.py b/stem/control.py
index 8233b2a..64eecc4 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -204,6 +204,7 @@ MAPPED_CONFIG_KEYS = {
 }
 
 # unchangeable GETINFO parameters
+
 CACHEABLE_GETINFO_PARAMS = (
   'version',
   'config-file',
@@ -217,6 +218,19 @@ CACHEABLE_GETINFO_PARAMS = (
   'process/descriptor-limit',
 )
 
+# GETCONF parameters we shouldn't cache. This includes hidden service
+# perameters due to the funky way they're set and retrieved (for instance,
+# 'SETCONF HiddenServiceDir' effects 'GETCONF HiddenServiceOptions').
+
+UNCACHEABLE_GETCONF_PARAMS = (
+  'hiddenserviceoptions',
+  'hiddenservicedir',
+  'hiddenserviceport',
+  'hiddenserviceversion',
+  'hiddenserviceauthorizeclient',
+  'hiddenserviceoptions',
+)
+
 # number of sequential attempts before we decide that the Tor geoip database
 # is unavailable
 GEOIP_FAILURE_THRESHOLD = 5
@@ -1465,6 +1479,11 @@ class Controller(BaseController):
 
       if self.is_caching_enabled():
         to_cache = dict((k.lower(), v) for k, v in response.entries.items())
+
+        for key in UNCACHEABLE_GETCONF_PARAMS:
+          if key in to_cache:
+            del to_cache[key]
+
         self._set_cache(to_cache, "getconf")
 
       # Maps the entries back to the parameters that the user requested so the



More information about the tor-commits mailing list