summaryrefslogtreecommitdiff
path: root/src/or/control.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-10-20 21:04:39 +0000
committerNick Mathewson <nickm@torproject.org>2006-10-20 21:04:39 +0000
commit01bc03eff43775d5f293c63d1dec05650a84a420 (patch)
treee87f5d8c8c5d29eced92c407e8f96d215ea9d56a /src/or/control.c
parent0459db2c0d0e2af23b4db26ce4de555ee29eb7ec (diff)
downloadtor-01bc03eff43775d5f293c63d1dec05650a84a420.tar.gz
tor-01bc03eff43775d5f293c63d1dec05650a84a420.zip
r9312@Kushana: nickm | 2006-10-20 14:45:22 -0400
Add an event type to tell the controller when our opinion of a router status has changed. I might have missed some cases here. svn:r8781
Diffstat (limited to 'src/or/control.c')
-rw-r--r--src/or/control.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/or/control.c b/src/or/control.c
index 05b2da2ee6..eb68497c3b 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -82,7 +82,9 @@ const char control_c_id[] =
#define EVENT_ADDRMAP 0x000C
#define EVENT_AUTHDIR_NEWDESCS 0x000D
#define EVENT_DESCCHANGED 0x000E
-#define _EVENT_MAX 0x000E
+#define EVENT_NS 0x000F
+#define _EVENT_MAX 0x000F
+/* If _EVENT_MAX ever hits 0x0020, we need to make the mask wider. */
/** Array mapping from message type codes to human-readable message
* type names. Used for compatibility with version 0 of the control
@@ -1050,6 +1052,8 @@ handle_control_setevents(control_connection_t *conn, uint32_t len,
event_code = EVENT_AUTHDIR_NEWDESCS;
else if (!strcasecmp(ev, "DESCCHANGED"))
event_code = EVENT_DESCCHANGED;
+ else if (!strcasecmp(ev, "NS"))
+ event_code = EVENT_NS;
else {
connection_printf_to_buf(conn, "552 Unrecognized event \"%s\"\r\n",
ev);
@@ -3347,6 +3351,49 @@ control_event_or_authdir_new_descriptor(const char *action,
return 0;
}
+/* DOCDOC takes a list of local_routerstatus_t */
+int
+control_event_networkstatus_changed(smartlist_t *statuses)
+{
+ smartlist_t *strs;
+ char *s;
+ if (!EVENT_IS_INTERESTING(EVENT_NS) || !smartlist_len(statuses))
+ return 0;
+
+ strs = smartlist_create();
+ smartlist_add(strs, tor_strdup("650+NS\r\n"));
+ SMARTLIST_FOREACH(statuses, local_routerstatus_t *, rs,
+ {
+ s = networkstatus_getinfo_helper_single(&rs->status);
+ if (!s) continue;
+ smartlist_add(strs, s);
+ });
+ smartlist_add(strs, tor_strdup("\r\n.\r\n"));
+
+ s = smartlist_join_strings(strs, "", 0, NULL);
+ SMARTLIST_FOREACH(strs, char *, cp, tor_free(cp));
+ smartlist_free(strs);
+ send_control1_event_string(EVENT_NS, ALL_NAMES|ALL_FORMATS, s);
+ tor_free(s);
+ return 0;
+}
+
+int
+control_event_networkstatus_changed_single(local_routerstatus_t *rs)
+{
+ smartlist_t *statuses;
+ int r;
+
+ if (!EVENT_IS_INTERESTING(EVENT_NS))
+ return 0;
+
+ statuses = smartlist_create();
+ smartlist_add(statuses, rs);
+ r = control_event_networkstatus_changed(statuses);
+ smartlist_free(statuses);
+ return r;
+}
+
/** Our own router descriptor has changed; tell any controllers that care.
*/
int