aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2005-11-19 18:35:43 +0000
committerPeter Palfrader <peter@palfrader.org>2005-11-19 18:35:43 +0000
commitb9d37a2d58e76ee233e2501e2e21503540c894ab (patch)
treeac99f1ab9a0df2e683056e74b1fa0a34522e1d88 /src/or
parent7446c7e6d726eb58954917d58f02529d1ce8e41d (diff)
downloadtor-b9d37a2d58e76ee233e2501e2e21503540c894ab.tar
tor-b9d37a2d58e76ee233e2501e2e21503540c894ab.tar.gz
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
Diffstat (limited to 'src/or')
-rw-r--r--src/or/control.c43
-rw-r--r--src/or/dirserv.c5
-rw-r--r--src/or/or.h1
3 files changed, 48 insertions, 1 deletions
diff --git a/src/or/control.c b/src/or/control.c
index 103ba003a..88451cda3 100644
--- a/src/or/control.c
+++ b/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. */
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 510cf6c97..3905f86a1 100644
--- a/src/or/dirserv.c
+++ b/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);
diff --git a/src/or/or.h b/src/or/or.h
index 393aae19c..1141f4022 100644
--- a/src/or/or.h
+++ b/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);