[or-cvs] Implement new controller events for changed descriptors and...

Nick Mathewson nickm at seul.org
Wed Mar 2 22:30:02 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv2137/src/or

Modified Files:
	connection_edge.c control.c or.h routerlist.c 
Log Message:
Implement new controller events for changed descriptors and new (not-yet-attached) streams.

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.291
retrieving revision 1.292
diff -u -d -r1.291 -r1.292
--- connection_edge.c	2 Mar 2005 22:01:10 -0000	1.291
+++ connection_edge.c	2 Mar 2005 22:29:58 -0000	1.292
@@ -812,6 +812,7 @@
       }
       rep_hist_note_used_port(socks->port, time(NULL)); /* help predict this next time */
     }
+    control_event_stream_status(conn, STREAM_EVENT_NEW);
     conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
     return connection_ap_handshake_attach_circuit(conn);
   } else {

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- control.c	2 Mar 2005 21:59:36 -0000	1.50
+++ control.c	2 Mar 2005 22:29:58 -0000	1.51
@@ -871,6 +871,31 @@
   send_control_event(EVENT_WARNING, (uint32_t)(len+1), msg);
 }
 
+/** DOCDOC */
+int control_event_descriptors_changed(smartlist_t *routers)
+{
+  size_t len;
+  char *msg;
+  smartlist_t *identities;
+  char buf[HEX_DIGEST_LEN+1];
+
+  if (!EVENT_IS_INTERESTING(EVENT_NEW_DESC))
+    return 0;
+  identities = smartlist_create();
+  SMARTLIST_FOREACH(routers, routerinfo_t *, r,
+  {
+    base16_encode(buf,sizeof(buf),r->identity_digest,DIGEST_LEN);
+    smartlist_add(identities, tor_strdup(buf));
+  });
+  msg = smartlist_join_strings(identities, ",", 1, &len);
+  send_control_event(EVENT_NEW_DESC, len+1, msg);
+
+  SMARTLIST_FOREACH(identities, char *, cp, tor_free(cp));
+  smartlist_free(identities);
+  tor_free(msg);
+  return 0;
+}
+
 /** Choose a random authentication cookie and write it to disk.
  * Anybody who can read the cookie from disk will be considered
  * authorized to use the control connection. */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.550
retrieving revision 1.551
diff -u -d -r1.550 -r1.551
--- or.h	2 Mar 2005 21:02:11 -0000	1.550
+++ or.h	2 Mar 2005 22:29:58 -0000	1.551
@@ -1362,7 +1362,8 @@
   STREAM_EVENT_SENT_RESOLVE = 1,
   STREAM_EVENT_SUCCEEDED    = 2,
   STREAM_EVENT_FAILED       = 3,
-  STREAM_EVENT_CLOSED       = 4
+  STREAM_EVENT_CLOSED       = 4,
+  STREAM_EVENT_NEW          = 5
 } stream_status_event_t;
 
 typedef enum or_conn_status_event_t {
@@ -1381,6 +1382,7 @@
 int control_event_or_conn_status(connection_t *conn, or_conn_status_event_t e);
 int control_event_bandwidth_used(uint32_t n_read, uint32_t n_written);
 void control_event_logmsg(int severity, const char *msg);
+int control_event_descriptors_changed(smartlist_t *routers);
 
 int init_cookie_authentication(int enabled);
 int decode_hashed_password(char *buf, const char *hashed);

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.217
retrieving revision 1.218
diff -u -d -r1.217 -r1.218
--- routerlist.c	28 Feb 2005 03:37:27 -0000	1.217
+++ routerlist.c	2 Mar 2005 22:29:58 -0000	1.218
@@ -886,6 +886,11 @@
   if (router_add_to_routerlist(ri)<0) {
     log_fn(LOG_WARN, "Couldn't add router to list; dropping.");
     return -1;
+  } else {
+    smartlist_t *changed = smartlist_create();
+    smartlist_add(changed, ri);
+    control_event_descriptors_changed(changed);
+    smartlist_free(changed);
   }
   log_fn(LOG_DEBUG, "Added router to list");
   return 0;
@@ -914,16 +919,23 @@
     return -1;
   }
   if (routerlist) {
+    smartlist_t *changed = smartlist_create();
     SMARTLIST_FOREACH(new_list->routers, routerinfo_t *, r,
-                      router_add_to_routerlist(r));
+    {
+      if (router_add_to_routerlist(r)==0)
+        smartlist_add(changed, r);
+    });
     smartlist_clear(new_list->routers);
     routerlist->published_on = new_list->published_on;
     tor_free(routerlist->software_versions);
     routerlist->software_versions = new_list->software_versions;
     new_list->software_versions = NULL;
     routerlist_free(new_list);
+    control_event_descriptors_changed(changed);
+    smartlist_free(changed);
   } else {
     routerlist = new_list;
+    control_event_descriptors_changed(routerlist->routers);
   }
   if (router_resolve_routerlist(routerlist)) {
     log_fn(LOG_WARN, "Error resolving routerlist");



More information about the tor-commits mailing list