[or-cvs] Add a new controller event type that allows controllers to ...
Peter Palfrader
weasel at seul.org
Sat Nov 19 18:35:45 UTC 2005
Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv1007/src/or
Modified Files:
control.c dirserv.c or.h
Log Message:
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.
Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.152
retrieving revision 1.153
diff -u -d -r1.152 -r1.153
--- control.c 18 Nov 2005 11:35:23 -0000 1.152
+++ control.c 19 Nov 2005 18:35:43 -0000 1.153
@@ -73,7 +73,8 @@
#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 @@
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 @@
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. */
Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.267
retrieving revision 1.268
diff -u -d -r1.267 -r1.268
--- dirserv.c 19 Nov 2005 06:57:44 -0000 1.267
+++ dirserv.c 19 Nov 2005 18:35:43 -0000 1.268
@@ -456,11 +456,16 @@
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);
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.737
retrieving revision 1.738
diff -u -d -r1.737 -r1.738
--- or.h 19 Nov 2005 10:12:10 -0000 1.737
+++ or.h 19 Nov 2005 18:35:43 -0000 1.738
@@ -1739,6 +1739,7 @@
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);
More information about the tor-commits
mailing list