Browse Source

Add a new controller event type that allows controllers to get all
server descriptors that were uploaded to a router in its role as authoritative
dirserver.


svn:r5436

Peter Palfrader 18 years ago
parent
commit
b9d37a2d58
4 changed files with 57 additions and 2 deletions
  1. 9 1
      doc/control-spec.txt
  2. 42 1
      src/or/control.c
  3. 5 0
      src/or/dirserv.c
  4. 1 0
      src/or/or.h

+ 9 - 1
doc/control-spec.txt

@@ -171,7 +171,8 @@ $Id$
      "SETEVENTS" [SP "EXTENDED"] *(SP EventCode) CRLF
 
      EventCode = "CIRC" / "STREAM" / "ORCONN" / "BW" / "DEBUG" /
-         "INFO" / "NOTICE" / "WARN" / "ERR" / "NEWDESC" / "ADDRMAP"
+         "INFO" / "NOTICE" / "WARN" / "ERR" / "NEWDESC" / "ADDRMAP" /
+         "AUTHDIR_NEWDESCS"
 
   Any events *not* listed in the SETEVENTS line are turned off; thus, sending
   SETEVENTS with an empty body turns off all event reporting.
@@ -676,6 +677,13 @@ $Id$
      "650" SP "ADDRMAP" SP Address SP Address SP Expiry
      Expiry = DQOUTE ISOTime DQUOTE / "NEVER"
 
+4.1.8. Descriptors uploaded to us in our role as authoritative dirserver
+
+  Syntax:
+     "650" "+" "AUTHDIR_NEWDESCS" CRLF Action CRLF Message CRLF Descriptor CRLF "." CRLF
+     Action = "ACCEPTED" / "DROPPED" / "REJECTED"
+     Message = Text
+
 5. Implementation notes
 
 5.1. Authentication

+ 42 - 1
src/or/control.c

@@ -73,7 +73,8 @@ const char control_c_id[] = "$Id$";
 #define EVENT_ERR_MSG         0x000B
 #define LAST_V0_EVENT         0x000B
 #define EVENT_ADDRMAP         0x000C
-#define _EVENT_MAX            0x000C
+#define EVENT_AUTHDIR_NEWDESCS 0x000D
+#define _EVENT_MAX            0x000D
 
 /** Array mapping from message type codes to human-readable message
  * type names. Used for compatibility with version 0 of the control
@@ -916,6 +917,8 @@ handle_control_setevents(connection_t *conn, uint32_t len, const char *body)
           event_code = EVENT_NEW_DESC;
         else if (!strcasecmp(ev, "ADDRMAP"))
           event_code = EVENT_ADDRMAP;
+        else if (!strcasecmp(ev, "AUTHDIR_NEWDESCS"))
+          event_code = EVENT_AUTHDIR_NEWDESCS;
         else {
           connection_printf_to_buf(conn, "552 Unrecognized event \"%s\"\r\n",
                                    ev);
@@ -2611,6 +2614,44 @@ control_event_address_mapped(const char *from, const char *to, time_t expires)
   return 0;
 }
 
+/** The authoritative dirserver has received a new descriptor that
+ * has passed basic syntax checks and is properly self-signed.
+ *
+ * Notify any interested party of the new descriptor and what has
+ * been done with it, and also optionally give an explanation/reason. */
+int
+control_event_or_authdir_new_descriptor(const char *action, const char *descriptor, const char *msg)
+
+{
+  char firstline[1024];
+  char *buf;
+  int totallen;
+  char *esc = NULL;
+  size_t esclen;
+
+  if (!EVENT_IS_INTERESTING(EVENT_AUTHDIR_NEWDESCS))
+    return 0;
+
+  tor_snprintf(firstline, sizeof(firstline),
+               "650+AUTHDIR_NEWDESC=\r\n%s\r\n%s\r\n",
+               action,
+               msg ? msg : "");
+
+  /* Escape the server descriptor properly */
+  esclen = write_escaped_data(descriptor, strlen(descriptor), 1, &esc);
+
+  totallen = strlen(firstline) + esclen + 1;
+  buf = tor_malloc(totallen);
+  strlcpy(buf, firstline, totallen);
+  strlcpy(buf+strlen(firstline), esc, totallen);
+  send_control1_event_string(EVENT_AUTHDIR_NEWDESCS, buf);
+
+  tor_free(esc);
+  tor_free(buf);
+
+  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. */

+ 5 - 0
src/or/dirserv.c

@@ -456,11 +456,16 @@ dirserv_add_descriptor(const char *desc, const char **msg)
          ri->nickname);
     *msg = "Not replacing router descriptor; no information has changed since the last one with this identity.";
     routerinfo_free(ri);
+    control_event_or_authdir_new_descriptor("DROPPED", desc, *msg);
     return 0;
   }
   if ((r = router_add_to_routerlist(ri, msg, 0))<0) {
+    if (r < -1) /* unless the routerinfo was fine, just out-of-date */
+      control_event_or_authdir_new_descriptor("REJECTED", desc, *msg);
     return r == -1 ? 0 : -1;
   } else {
+    control_event_or_authdir_new_descriptor("ACCEPTED", desc, *msg);
+
     smartlist_t *changed = smartlist_create();
     smartlist_add(changed, ri);
     control_event_descriptors_changed(changed);

+ 1 - 0
src/or/or.h

@@ -1739,6 +1739,7 @@ int control_event_bandwidth_used(uint32_t n_read, uint32_t n_written);
 void control_event_logmsg(int severity, unsigned int domain, const char *msg);
 int control_event_descriptors_changed(smartlist_t *routers);
 int control_event_address_mapped(const char *from, const char *to,time_t expires);
+int control_event_or_authdir_new_descriptor(const char *action, const char *descriptor, const char *msg);
 
 int init_cookie_authentication(int enabled);
 int decode_hashed_password(char *buf, const char *hashed);