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
This commit is contained in:
Nick Mathewson 2007-04-30 19:48:33 +00:00
parent b27b09ae1e
commit ae40e7f633
5 changed files with 46 additions and 6 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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 <b>desc</b> and maybe insert it into
* the list of server descriptors. Set *<b>msg</b> 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 <b>desc</b>.
*/
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.";

View File

@ -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);

View File

@ -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:"<unknown error>");
return -1;