commit f5666b967510463fdd02b8f6de8746d86b5893cd Author: Damian Johnson atagar@torproject.org Date: Mon Jul 3 15:31:15 2017 -0700
Supporting 'SAVECONF FORCE' flag
When the torrc has an %include clause tor refuses SAVECONF requests unless the caller specifies 'FORCE'. Letting callers include this...
https://gitweb.torproject.org/torspec.git/commit/?id=5c82d5e --- docs/change_log.rst | 1 + stem/control.py | 13 +++++++++++-- stem/version.py | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst index 286d35f..c4a4af3 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 * :func:`~stem.process.launch_tor` raised a ValueError if invoked when outside the main thread * Failure to authenticate could raise an improper response or hang (:trac:`22679`) * Renamed :class:`~stem.response.events.ConnectionBandwidthEvent` type attribute to conn_type to avoid conflict with parent class (:trac:`21774`) + * Added 'force' argument to :func:`~stem.control.Controller.save_conf` (:spec:`5c82d5e`) * Added the QUERY_NO_HSDIR :data:`~stem.HSDescReason` and recognizing unknown HSDir results (:spec:`1412d79`) * Added the GUARD_WAIT :data:`~stem.CircStatus` (:spec:`6446210`) * Unable to use cookie auth when path includes wide characters (chinese, japanese, etc) diff --git a/stem/control.py b/stem/control.py index e7d7977..95b4d91 100644 --- a/stem/control.py +++ b/stem/control.py @@ -3154,17 +3154,26 @@ class Controller(BaseController): elif not response.is_ok(): raise stem.ProtocolError('+LOADCONF Received unexpected response\n%s' % str(response))
- def save_conf(self): + def save_conf(self, force = False): """ Saves the current configuration options into the active torrc file.
+ .. versionchanged:: 1.6.0 + Added the force argument. + + :param bool force: overwrite the configuration even if it includes a + '%include' clause, this is ignored if tor doesn't support it + :raises: * :class:`stem.ControllerError` if the call fails * :class:`stem.OperationFailed` if the client is unable to save the configuration file """
- response = self.msg('SAVECONF') + if self.get_version() < stem.version.Requirement.SAVECONF_FORCE: + force = False + + response = self.msg('SAVECONF FORCE' if force else 'SAVECONF') stem.response.convert('SINGLELINE', response)
if response.is_ok(): diff --git a/stem/version.py b/stem/version.py index b8960a5..7c347d5 100644 --- a/stem/version.py +++ b/stem/version.py @@ -67,6 +67,7 @@ easily parsed and compared, for instance... **ADD_ONION_NON_ANONYMOUS** ADD_ONION supports non-anonymous mode **LOADCONF** LOADCONF requests **MICRODESCRIPTOR_IS_DEFAULT** Tor gets microdescriptors by default rather than server descriptors + **SAVECONF_FORCE** Added the 'FORCE' flag to SAVECONF **TAKEOWNERSHIP** TAKEOWNERSHIP requests **TORRC_CONTROL_SOCKET** 'ControlSocket <path>' config option **TORRC_PORT_FORWARDING** 'PortForwarding' config option @@ -376,6 +377,7 @@ Requirement = stem.util.enum.Enum( ('ADD_ONION_NON_ANONYMOUS', Version('0.2.9.3-alpha')), ('LOADCONF', Version('0.2.1.1')), ('MICRODESCRIPTOR_IS_DEFAULT', Version('0.2.3.3')), + ('SAVECONF_FORCE', Version('0.3.1.1-alpha')), ('TAKEOWNERSHIP', Version('0.2.2.28-beta')), ('TORRC_CONTROL_SOCKET', Version('0.2.0.30')), ('TORRC_PORT_FORWARDING', Version('0.2.3.1-alpha')),
tor-commits@lists.torproject.org