[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Support for CONF_CHANGED events
commit bb458df4ac47c1405ce7e7f7e3e15ececf485b4b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Mon Dec 3 08:21:50 2012 -0800
Support for CONF_CHANGED events
Implementation and testing for CONF_CHANGED events. Got the test data by
issuing a SETCONF request...
SETEVENTS CONF_CHANGED
250 OK
SETCONF ExitNodes=caerSidi MaxCircuitDirtiness=20 ExitPolicy
650-CONF_CHANGED
650-ExitNodes=caerSidi
650-ExitPolicy
650-MaxCircuitDirtiness=20
650 OK
250 OK
---
stem/control.py | 1 +
stem/response/events.py | 32 ++++++++++++++++++++++++++++++++
test/unit/response/events.py | 21 +++++++++++++++++++++
3 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index ec3273a..43229b5 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -84,6 +84,7 @@ providing its own for interacting at a higher level.
**BW** :class:`stem.response.events.BandwidthEvent`
**CIRC** :class:`stem.response.events.CircuitEvent`
**CLIENTS_SEEN** :class:`stem.response.events.ClientsSeenEvent`
+ **CONF_CHANGED** :class:`stem.response.events.ConfChangedEvent`
**DEBUG** :class:`stem.response.events.LogEvent`
**DESCCHANGED** :class:`stem.response.events.DescChangedEvent`
**ERR** :class:`stem.response.events.LogEvent`
diff --git a/stem/response/events.py b/stem/response/events.py
index 98e1bf3..bf74fce 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -424,6 +424,37 @@ class ClientsSeenEvent(Event):
self.ip_versions = protocol_to_count
+class ConfChangedEvent(Event):
+ """
+ Event that indicates that our configuration changed, either in response to a
+ SETCONF or RELOAD signal.
+
+ :var dict config: mapping of configuration options to their new values
+ (**None** of the option is being unset)
+ """
+
+ _SKIP_PARSING = True
+
+ def _parse(self):
+ self.config = {}
+
+ # Skip first and last line since they're the header and footer. For
+ # instance...
+ #
+ # 650-CONF_CHANGED
+ # 650-ExitNodes=caerSidi
+ # 650-ExitPolicy
+ # 650-MaxCircuitDirtiness=20
+ # 650 OK
+
+ for line in str(self).splitlines()[1:-1]:
+ if '=' in line:
+ key, value = line.split('=', 1)
+ else:
+ key, value = line, None
+
+ self.config[key] = value
+
class DescChangedEvent(Event):
"""
Event that indicates that our descriptor has changed. This was first added in
@@ -754,6 +785,7 @@ EVENT_TYPE_TO_CLASS = {
"BW": BandwidthEvent,
"CIRC": CircuitEvent,
"CLIENTS_SEEN": ClientsSeenEvent,
+ "CONF_CHANGED": ConfChangedEvent,
"DEBUG": LogEvent,
"DESCCHANGED": DescChangedEvent,
"ERR": LogEvent,
diff --git a/test/unit/response/events.py b/test/unit/response/events.py
index 6d5f0d3..f6a4b85 100644
--- a/test/unit/response/events.py
+++ b/test/unit/response/events.py
@@ -60,6 +60,15 @@ TimeStarted="2008-12-25 23:50:43" \
CountrySummary=us=16,de=8,uk=8 \
IPVersions=v4=16,v6=40'
+# CONF_CHANGED event from tor 0.2.3.16.
+
+CONF_CHANGED_EVENT = """650-CONF_CHANGED
+650-ExitNodes=caerSidi
+650-ExitPolicy
+650-MaxCircuitDirtiness=20
+650 OK
+"""
+
# GUARD events from tor v0.2.1.30.
GUARD_NEW = "650 GUARD ENTRY $36B5DBA788246E8369DBAF58577C6BC044A9A374 NEW"
@@ -397,6 +406,18 @@ class TestEvents(unittest.TestCase):
self.assertEqual({'us': 16, 'de': 8, 'uk': 8}, event.locales)
self.assertEqual({'v4': 16, 'v6': 40}, event.ip_versions)
+ def test_conf_changed(self):
+ event = _get_event(CONF_CHANGED_EVENT)
+
+ expected_config = {
+ 'ExitNodes': 'caerSidi',
+ 'MaxCircuitDirtiness': '20',
+ 'ExitPolicy': None,
+ }
+
+ self.assertTrue(isinstance(event, stem.response.events.ConfChangedEvent))
+ self.assertEqual(expected_config, event.config)
+
def test_descchanged_event(self):
# all we can check for is that the event is properly parsed as a
# DescChangedEvent instance
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits