[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Emits CONF_CHANGED events whenever Tor's configuration values change.



commit 5a801a8c8b71c9551a80913398135809cb10cecd
Author: Kamran Riaz Khan <krkhan@xxxxxxxxxxxxxx>
Date:   Mon Aug 8 04:38:53 2011 +0500

    Emits CONF_CHANGED events whenever Tor's configuration values change.
---
 src/or/config.c  |   35 ++++++++++++++++++++++++++++++++++-
 src/or/control.c |   17 ++++++++++++++++-
 src/or/control.h |    1 +
 3 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/src/or/config.c b/src/or/config.c
index 088617b..653e23d 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -10,6 +10,7 @@
  **/
 
 #define CONFIG_PRIVATE
+#define CONTROL_PRIVATE
 
 #include "or.h"
 #include "circuitbuild.h"
@@ -693,6 +694,10 @@ get_options(void)
 int
 set_options(or_options_t *new_val, char **msg)
 {
+  int i;
+  char *result;
+  smartlist_t *elements;
+  config_line_t *line;
   or_options_t *old_options = global_options;
   global_options = new_val;
   /* Note that we pass the *old* options below, for comparison. It
@@ -707,7 +712,35 @@ set_options(or_options_t *new_val, char **msg)
             "Acting on config options left us in a broken state. Dying.");
     exit(1);
   }
-
+  /* Issues a CONF_CHANGED event to notify controller of the change. If Tor is
+   * just starting up then the old_options will be undefined. */
+  if (old_options) {
+    elements = smartlist_create();
+    for (i=0; options_format.vars[i].name; ++i) {
+      if (!option_is_same(&options_format, new_val, old_options,
+        options_format.vars[i].name)) {
+        line = get_assigned_option(&options_format, new_val,
+        options_format.vars[i].name, 0);
+
+        if (line) {
+          for (; line; line = line->next) {
+            char *tmp;
+            tor_asprintf(&tmp, "650-%s=%s", line->key, line->value);
+            smartlist_add(elements, tmp);
+          }
+        } else {
+          char *tmp;
+          tor_asprintf(&tmp, "650-%s", options_format.vars[i].name);
+          smartlist_add(elements, tmp);
+        }
+      }
+    }
+    result = smartlist_join_strings(elements, "\r\n", 0, NULL);
+    control_event_conf_changed(result);
+    tor_free(result);
+    SMARTLIST_FOREACH(elements, char *, cp, tor_free(cp));
+    smartlist_free(elements);
+  }
   config_free(&options_format, old_options);
 
   return 0;
diff --git a/src/or/control.c b/src/or/control.c
index ad11350..0b19a25 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -74,7 +74,8 @@
 #define EVENT_NEWCONSENSUS     0x0016
 #define EVENT_BUILDTIMEOUT_SET     0x0017
 #define EVENT_SIGNAL           0x0018
-#define _EVENT_MAX             0x0018
+#define EVENT_CONF_CHANGED     0x0019
+#define _EVENT_MAX             0x0019
 /* If _EVENT_MAX ever hits 0x0020, we need to make the mask wider. */
 
 /** Bitfield: The bit 1&lt;&lt;e is set if <b>any</b> open control
@@ -946,6 +947,7 @@ static const struct control_event_t control_event_table[] = {
   { EVENT_NEWCONSENSUS, "NEWCONSENSUS" },
   { EVENT_BUILDTIMEOUT_SET, "BUILDTIMEOUT_SET" },
   { EVENT_SIGNAL, "SIGNAL" },
+  { EVENT_CONF_CHANGED, "CONF_CHANGED"},
   { 0, NULL },
 };
 
@@ -3996,6 +3998,19 @@ control_event_guard(const char *nickname, const char *digest,
   return 0;
 }
 
+/** Called when a configuration option changes. This is generally triggered
+ * by SETCONF requests and RELOAD/SIGHUP signals. The <b>values</b> are the
+ * keyword/value pairs for the configuration changes tor is using. */
+int
+control_event_conf_changed(const char *values)
+{
+  if(strlen(values) > 0) {
+    send_control_event(EVENT_CONF_CHANGED, 0,
+      "650-CONF_CHANGED\r\n%s\r\n650 OK\r\n", values);
+  }
+  return 0;
+}
+
 /** Helper: Return a newly allocated string containing a path to the
  * file where we store our authentication cookie. */
 static char *
diff --git a/src/or/control.h b/src/or/control.h
index 147a5af..ed83f53 100644
--- a/src/or/control.h
+++ b/src/or/control.h
@@ -66,6 +66,7 @@ int control_event_server_status(int severity, const char *format, ...)
   CHECK_PRINTF(2,3);
 int control_event_guard(const char *nickname, const char *digest,
                         const char *status);
+int control_event_conf_changed(const char *values);
 int control_event_buildtimeout_set(const circuit_build_times_t *cbt,
                                    buildtimeout_set_event_t type);
 int control_event_signal(uintptr_t signal);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits