[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r13009: Patch from Tup: make NS events work again. (in tor/trunk: . src/or)
Author: nickm
Date: 2007-12-31 16:12:16 -0500 (Mon, 31 Dec 2007)
New Revision: 13009
Modified:
tor/trunk/
tor/trunk/ChangeLog
tor/trunk/src/or/control.c
tor/trunk/src/or/networkstatus.c
tor/trunk/src/or/or.h
Log:
r15768@tombo: nickm | 2007-12-31 16:12:09 -0500
Patch from Tup: make NS events work again.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r15768] on d9e39d38-0f13-419c-a857-e10a0ce2aa0c
Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog 2007-12-31 21:12:14 UTC (rev 13008)
+++ tor/trunk/ChangeLog 2007-12-31 21:12:16 UTC (rev 13009)
@@ -6,6 +6,9 @@
implementation also avoids realloc();realloc(); patterns that
can contribute to memory fragmentation.
+ o Minor features (controller):
+ - Get NS events working again. (Patch from tup)
+
Changes in version 0.2.0.15-alpha - 2007-12-25
o Major bugfixes:
- Fix several remotely triggerable asserts based on DirPort requests
Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c 2007-12-31 21:12:14 UTC (rev 13008)
+++ tor/trunk/src/or/control.c 2007-12-31 21:12:16 UTC (rev 13009)
@@ -38,7 +38,7 @@
#define EVENT_ADDRMAP 0x000C
// #define EVENT_AUTHDIR_NEWDESCS 0x000D
#define EVENT_DESCCHANGED 0x000E
-#define EVENT_NS 0x000F
+// #define EVENT_NS 0x000F
#define EVENT_STATUS_CLIENT 0x0010
#define EVENT_STATUS_SERVER 0x0011
#define EVENT_STATUS_GENERAL 0x0012
Modified: tor/trunk/src/or/networkstatus.c
===================================================================
--- tor/trunk/src/or/networkstatus.c 2007-12-31 21:12:14 UTC (rev 13008)
+++ tor/trunk/src/or/networkstatus.c 2007-12-31 21:12:16 UTC (rev 13009)
@@ -1199,6 +1199,77 @@
return NULL;
}
+/** Given two router status entries for the same router identity, return 1 if
+ * if the contents have changed between them. Otherwise, return 0. */
+static int
+routerstatus_has_changed(const routerstatus_t *a, const routerstatus_t *b)
+{
+ tor_assert(!memcmp(a->identity_digest, b->identity_digest, DIGEST_LEN));
+
+ return strcmp(a->nickname, b->nickname) ||
+ memcmp(a->descriptor_digest, b->descriptor_digest, DIGEST_LEN) ||
+ a->addr != b->addr ||
+ a->or_port != b->or_port ||
+ a->dir_port != b->dir_port ||
+ a->is_authority != b->is_authority ||
+ a->is_exit != b->is_exit ||
+ a->is_stable != b->is_stable ||
+ a->is_fast != b->is_fast ||
+ a->is_running != b->is_running ||
+ a->is_named != b->is_named ||
+ a->is_unnamed != b->is_unnamed ||
+ a->is_valid != b->is_valid ||
+ a->is_v2_dir != b->is_v2_dir ||
+ a->is_possible_guard != b->is_possible_guard ||
+ a->is_bad_exit != b->is_bad_exit ||
+ a->is_bad_directory != b->is_bad_directory ||
+ a->is_hs_dir != b->is_hs_dir ||
+ a->version_known != b->version_known ||
+ a->version_supports_begindir != b->version_supports_begindir ||
+ a->version_supports_extrainfo_upload !=
+ b->version_supports_extrainfo_upload ||
+ a->version_supports_v3_dir != b->version_supports_v3_dir;
+}
+
+/** Notify controllers of any router status entries that changed between
+ * <b>old_c</b> and <b>new_c</b>. */
+static void
+notify_control_networkstatus_changed(const networkstatus_vote_t *old_c,
+ const networkstatus_vote_t *new_c)
+{
+ int idx = 0;
+ int old_remain = old_c && smartlist_len(old_c->routerstatus_list);
+ const routerstatus_t *rs_old = NULL;
+ smartlist_t *changed;
+ if (old_c == new_c)
+ return;
+ changed = smartlist_create();
+ if (old_remain)
+ rs_old = smartlist_get(old_c->routerstatus_list, idx);
+
+ SMARTLIST_FOREACH(new_c->routerstatus_list, routerstatus_t *, rs_new,
+ {
+ if (!old_remain) {
+ smartlist_add(changed, rs_new);
+ } else {
+ int r;
+ while ((r = memcmp(rs_old->identity_digest, rs_new->identity_digest,
+ DIGEST_LEN)) < 0) {
+ if (++idx == smartlist_len(old_c->routerstatus_list)) {
+ old_remain = 0;
+ break;
+ }
+ rs_old = smartlist_get(old_c->routerstatus_list, idx);
+ }
+ if (r || (!r && routerstatus_has_changed(rs_old, rs_new)))
+ smartlist_add(changed, rs_new);
+ }
+ });
+
+ control_event_networkstatus_changed(changed);
+ smartlist_free(changed);
+}
+
/** Copy all the ancillary information (like router download status and so on)
* from <b>old_c</b> to <b>new_c</b>. */
static void
@@ -1337,6 +1408,9 @@
if (r != 1)
authority_certs_fetch_missing(c, now);
+ if (control_event_is_interesting(EVENT_NS))
+ notify_control_networkstatus_changed(current_consensus, c);
+
if (current_consensus) {
networkstatus_copy_old_consensus_info(c, current_consensus);
networkstatus_vote_free(current_consensus);
Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h 2007-12-31 21:12:14 UTC (rev 13008)
+++ tor/trunk/src/or/or.h 2007-12-31 21:12:16 UTC (rev 13009)
@@ -2930,6 +2930,7 @@
int connection_control_process_inbuf(control_connection_t *conn);
#define EVENT_AUTHDIR_NEWDESCS 0x000D
+#define EVENT_NS 0x000F
int control_event_is_interesting(int event);
int control_event_circuit_status(origin_circuit_t *circ,