From ae40e7f6339208530ddbbc2fe6690faceb02a1ee Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 30 Apr 2007 19:48:33 +0000 Subject: r12585@catbus: nickm | 2007-04-30 14:38:37 -0400 (Needs review.) Allow directory authorities to accept multiple router descriptors and extra info documents in a single POST. This will make implementing the client side of proposal 104 a lot simpler. svn:r10069 --- ChangeLog | 3 +++ src/or/directory.c | 2 +- src/or/dirserv.c | 41 ++++++++++++++++++++++++++++++++++++++--- src/or/or.h | 4 +++- src/or/router.c | 2 +- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c65f8e34..e6226232e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -62,6 +62,9 @@ Changes in version 0.2.0.1-alpha - 2007-??-?? should be about 60%. (Limitation: servers do not yet upload extra-info documents; authorities do not yet cache them.) [Partially implements proposal 104.] + - Directory authorities allow multiple router descriptors and/or extra + info documents to be uploaded in a single go. This will make + implementing proposal 104 simpler. o Minor features (controller): - Add a new config option __DisablePredictedCircuits designed for diff --git a/src/or/directory.c b/src/or/directory.c index 2bc6578eb..796c0f0a0 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -1875,7 +1875,7 @@ directory_handle_command_post(dir_connection_t *conn, const char *headers, if (!strcmp(url,"/tor/")) { /* server descriptor post */ const char *msg; - int r = dirserv_add_descriptor(body, &msg); + int r = dirserv_add_multiple_descriptors(body, &msg); tor_assert(msg); if (r > 0) dirserv_get_directory(); /* rebuild and write to disk */ diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 1effd10bf..abe8f9596 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -522,6 +522,41 @@ authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg, return 0; } +/** As for dirserv_add_descriptor, but accepts multiple documents, and + * returns the most severe error that occurred for any one of them. */ +int +dirserv_add_multiple_descriptors(const char *desc, const char **msg) +{ + int r=100; /* higher than any actual return value. */ + int r_tmp; + const char *msg_out; + + while (desc && *desc) { + const char *eos = strstr(desc, "\nrouter-signature"); + const char *next = NULL; + if (eos) { + char *next_extra = strstr(eos, "\nextra-info"); + char *next_routerinfo = strstr(eos, "\nrouter "); + if (next_extra) + next = next_extra; + if (!next || (next_routerinfo && next_routerinfo < next)) + next = next_routerinfo; + } + if (next) + ++next; + + r_tmp = dirserv_add_descriptor(desc, next, &msg_out); + desc = next; + + if (r_tmp < r) { + r = r_tmp; + *msg = msg_out; + } + } + + return r <= 2 ? r : -2; +} + /** Parse the server descriptor at desc and maybe insert it into * the list of server descriptors. Set *msg to a message that * should be passed back to the origin of this descriptor. @@ -533,7 +568,7 @@ authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg, * -2 if we can't find a router descriptor in desc. */ int -dirserv_add_descriptor(const char *desc, const char **msg) +dirserv_add_descriptor(const char *desc, const char *end, const char **msg) { int r; routerinfo_t *ri = NULL, *ri_old = NULL; @@ -545,7 +580,7 @@ dirserv_add_descriptor(const char *desc, const char **msg) if (!strcmpstart(desc, "extra-info")) { /* It's an extra-info thingie. */ routerlist_t *rl = router_get_routerlist(); - ei = extrainfo_parse_entry_from_string(desc, NULL, 1, rl->identity_map); + ei = extrainfo_parse_entry_from_string(desc, end, 1, rl->identity_map); if (!ei) { log_warn(LD_DIRSERV, "Couldn't parse uploaded extra-info descriptor"); *msg = "Rejected: couldn't parse extra-info descriptor"; @@ -567,7 +602,7 @@ dirserv_add_descriptor(const char *desc, const char **msg) } /* Check: is the descriptor syntactically valid? */ - ri = router_parse_entry_from_string(desc, NULL, 1); + ri = router_parse_entry_from_string(desc, end, 1); if (!ri) { log_warn(LD_DIRSERV, "Couldn't parse uploaded server descriptor"); *msg = "Rejected: Couldn't parse server descriptor."; diff --git a/src/or/or.h b/src/or/or.h index ed31c153b..1559ddcf3 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -2518,7 +2518,9 @@ int dirserv_add_own_fingerprint(const char *nickname, crypto_pk_env_t *pk); int dirserv_load_fingerprint_file(void); void dirserv_free_fingerprint_list(void); const char *dirserv_get_nickname_by_digest(const char *digest); -int dirserv_add_descriptor(const char *desc, const char **msg); +int dirserv_add_multiple_descriptors(const char *desc, const char **msg); +int dirserv_add_descriptor(const char *desc, const char *end, + const char **msg); int getinfo_helper_dirserv_unregistered(control_connection_t *conn, const char *question, char **answer); void dirserv_free_descriptors(void); diff --git a/src/or/router.c b/src/or/router.c index 0dfe62d62..1516bf374 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -327,7 +327,7 @@ init_keys(void) log_err(LD_GENERAL,"Error initializing descriptor."); return -1; } - if (dirserv_add_descriptor(mydesc, &m) < 0) { + if (dirserv_add_descriptor(mydesc, NULL, &m) < 0) { log_err(LD_GENERAL,"Unable to add own descriptor to directory: %s", m?m:""); return -1; -- cgit v1.2.3