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

[or-cvs] r10421: Make "authdir_newdesc rejected" work again. (in tor/trunk: . src/or)



Author: nickm
Date: 2007-05-31 14:48:28 -0400 (Thu, 31 May 2007)
New Revision: 10421

Modified:
   tor/trunk/
   tor/trunk/src/or/control.c
   tor/trunk/src/or/dirserv.c
   tor/trunk/src/or/or.h
Log:
 r13102@catbus:  nickm | 2007-05-31 13:56:25 -0400
 Make "authdir_newdesc rejected" work again.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r13102] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2007-05-31 18:48:25 UTC (rev 10420)
+++ tor/trunk/src/or/control.c	2007-05-31 18:48:28 UTC (rev 10421)
@@ -35,7 +35,7 @@
 #define EVENT_WARN_MSG         0x000A
 #define EVENT_ERR_MSG          0x000B
 #define EVENT_ADDRMAP          0x000C
-#define EVENT_AUTHDIR_NEWDESCS 0x000D
+// #define EVENT_AUTHDIR_NEWDESCS 0x000D
 #define EVENT_DESCCHANGED      0x000E
 #define EVENT_NS               0x000F
 #define EVENT_STATUS_CLIENT    0x0010
@@ -248,6 +248,16 @@
                                control_event_logmsg);
 }
 
+/** Return true iff the event with code <b>c</b> is being sent to any current
+ * control connection.  This is useful if the amount of work needed to prepare
+ * to call the appropriate control_event_...() function is high.
+ */
+int
+control_event_is_interesting(int event)
+{
+  return EVENT_IS_INTERESTING(event);
+}
+
 /** Append a NUL-terminated string <b>s</b> to the end of
  * <b>conn</b>-\>outbuf
  */
@@ -3032,7 +3042,7 @@
  * been done with it, and also optionally give an explanation/reason. */
 int
 control_event_or_authdir_new_descriptor(const char *action,
-                                        signed_descriptor_t *desc,
+                                        const char *desc, size_t desclen,
                                         const char *msg)
 {
   char firstline[1024];
@@ -3050,8 +3060,7 @@
                msg ? msg : "");
 
   /* Escape the server descriptor properly */
-  esclen = write_escaped_data(desc->signed_descriptor_body,
-                              desc->signed_descriptor_len, 1, &esc);
+  esclen = write_escaped_data(desc, desclen, 1, &esc);
 
   totallen = strlen(firstline) + esclen + 1;
   buf = tor_malloc(totallen);

Modified: tor/trunk/src/or/dirserv.c
===================================================================
--- tor/trunk/src/or/dirserv.c	2007-05-31 18:48:25 UTC (rev 10420)
+++ tor/trunk/src/or/dirserv.c	2007-05-31 18:48:28 UTC (rev 10421)
@@ -581,7 +581,8 @@
 {
   int r;
   routerinfo_t *ri_old;
-  signed_descriptor_t *desc = &ri->cache_info;
+  char *desc = NULL;
+  size_t desclen = 0;
 
   /* Check whether this descriptor is semantically identical to the last one
    * from this server.  (We do this here and not in router_add_to_routerlist
@@ -596,23 +597,27 @@
              ri->nickname);
     *msg = "Not replacing router descriptor; no information has changed since "
       "the last one with this identity.";
-    control_event_or_authdir_new_descriptor("DROPPED", desc, *msg);
+    control_event_or_authdir_new_descriptor("DROPPED",
+                         ri->cache_info.signed_descriptor_body,
+                         ri->cache_info.signed_descriptor_len, *msg);
     routerinfo_free(ri);
     return 0;
   }
+  if (control_event_is_interesting(EVENT_AUTHDIR_NEWDESCS)) {
+    /* Make a copy of desc, since router_add_to_routerlist might free
+     * ri and its associated signed_descriptor_t. */
+    desclen = ri->cache_info.signed_descriptor_len;
+    desc = tor_strndup(ri->cache_info.signed_descriptor_body, desclen);
+  }
+
   if ((r = router_add_to_routerlist(ri, msg, 0, 0))<0) {
-#if 0
-    /* XXXX020 reinstate this code, but remember that it can't actually
-       work, since it is NOT kosher to look at ri or desc after
-       add_to_routerlist, _unless_ the descriptor is accepted.
-    */
-    if (r < -1) /* unless the routerinfo was fine, just out-of-date */
-      control_event_or_authdir_new_descriptor("REJECTED", desc, *msg);
-#endif
+    if (r < -1 && desc) /* unless the routerinfo was fine, just out-of-date */
+      control_event_or_authdir_new_descriptor("REJECTED", desc, desclen, *msg);
+    tor_free(desc);
     return r == -1 ? 0 : -1;
   } else {
     smartlist_t *changed;
-    control_event_or_authdir_new_descriptor("ACCEPTED", desc, *msg);
+    control_event_or_authdir_new_descriptor("ACCEPTED", desc, desclen, *msg);
 
     changed = smartlist_create();
     smartlist_add(changed, ri);
@@ -622,6 +627,7 @@
       *msg =  ri->is_valid ? "Descriptor for valid server accepted" :
         "Descriptor for invalid server accepted";
     }
+    tor_free(desc);
     return r == 0 ? 2 : 1;
   }
 }

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-05-31 18:48:25 UTC (rev 10420)
+++ tor/trunk/src/or/or.h	2007-05-31 18:48:28 UTC (rev 10421)
@@ -2525,6 +2525,9 @@
 int connection_control_reached_eof(control_connection_t *conn);
 int connection_control_process_inbuf(control_connection_t *conn);
 
+#define EVENT_AUTHDIR_NEWDESCS 0x000D
+int control_event_is_interesting(int event);
+
 int control_event_circuit_status(origin_circuit_t *circ,
                                  circuit_status_event_t e, int reason);
 int control_event_stream_status(edge_connection_t *conn,
@@ -2540,7 +2543,8 @@
 int control_event_address_mapped(const char *from, const char *to,
                                  time_t expires);
 int control_event_or_authdir_new_descriptor(const char *action,
-                                            signed_descriptor_t *desc,
+                                            const char *desc,
+                                            size_t desclen,
                                             const char *msg);
 int control_event_my_descriptor_changed(void);
 int control_event_networkstatus_changed(smartlist_t *statuses);