From ae4a183ed8ca8e6f0a4d53c259517583e5c0947b Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 26 Aug 2005 21:46:24 +0000 Subject: Change the return values on dirserv_add_descriptor svn:r4863 --- src/or/directory.c | 5 ++--- src/or/dirserv.c | 14 ++++++++++---- src/or/routerlist.c | 12 ++++++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/or/directory.c b/src/or/directory.c index 9e92b485b..b02ec7f6b 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -1196,12 +1196,11 @@ directory_handle_command_post(connection_t *conn, char *headers, log_fn(LOG_NOTICE,"Rejected descriptor published by %s.", origin); break; case 0: - /* descriptor was well-formed but server has not been approved */ - write_http_status_line(conn, 200, msg?msg:"Unverified server descriptor accepted"); + write_http_status_line(conn, 200, msg?msg:"Server okay, but not accepted."); break; case 1: dirserv_get_directory(&cp, 0); /* rebuild and write to disk */ - write_http_status_line(conn, 200, msg?msg:"Verified server descriptor accepted"); + write_http_status_line(conn, 200, msg?msg:"Server descriptor accepted"); break; } goto done; diff --git a/src/or/dirserv.c b/src/or/dirserv.c index a9910a3ed..a5521314b 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -266,6 +266,7 @@ dirserv_router_has_valid_address(routerinfo_t *ri) return 0; } +/** DOCDOC */ int dirserv_wants_to_reject_router(routerinfo_t *ri, int *verified, const char **msg) @@ -329,13 +330,14 @@ dirserv_wants_to_reject_router(routerinfo_t *ri, int *verified, * origin of this descriptor, or to NULL. * * Return 1 if descriptor is well-formed and accepted; - * 0 if well-formed and server is unapproved but accepted; + * 0 if well-formed and server is well-formed but rejected for timeliness. * -1 if it looks vaguely like a router descriptor but rejected; * -2 if we can't find a router descriptor in *desc. */ int dirserv_add_descriptor(const char *desc, const char **msg) { + int r; routerinfo_t *ri = NULL; tor_assert(msg); *msg = NULL; @@ -347,14 +349,18 @@ dirserv_add_descriptor(const char *desc, const char **msg) *msg = "Rejected: Couldn't parse server descriptor."; return -1; } - if (router_add_to_routerlist(ri, msg)) { - return -1; + if ((r = router_add_to_routerlist(ri, msg))<0) { + return r == -1 ? 0 : -1; } else { smartlist_t *changed = smartlist_create(); smartlist_add(changed, ri); control_event_descriptors_changed(changed); smartlist_free(changed); - return ri->is_verified ? 1 : 0; + if (!*msg) { + *msg = ri->is_verified ? "Verified server descriptor accepted" : + "Unverified server descriptor accepted"; + } + return 1; } } diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 207d51455..36eca55b5 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -855,11 +855,15 @@ router_mark_as_down(const char *digest) * older entries (if any) with the same name. Note: Callers should not hold * their pointers to router if this function fails; router * will either be inserted into the routerlist or freed. Returns 0 if the - * router was added; -1 if it was not. + * router was added; less than 0 if it was not. * - * If we're returning -1 and msg is not NULL, then assign to + * If we're returning an error and msg is not NULL, then assign to * *msg a static string describing the reason for refusing the * routerinfo. + * + * If the return value is less than -1, there was a problem with the + * routerinfo. If the return value is equal to -1, then the routerinfo was + * fine, but out-of-date. */ int router_add_to_routerlist(routerinfo_t *router, const char **msg) @@ -878,7 +882,7 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg) if (authdir) { if (dirserv_wants_to_reject_router(router, &authdir_verified, msg)) - return -1; + return -2; router->is_verified = authdir_verified; if (tor_version_as_new_as(router->platform,"0.1.0.2-rc")) router->is_verified = 1; @@ -943,7 +947,7 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg) router->nickname); routerinfo_free(router); if (msg) *msg = "Already have verified router with same nickname and different key."; - return -1; + return -2; } } } -- cgit v1.2.3