Change the return values on dirserv_add_descriptor

svn:r4863
This commit is contained in:
Nick Mathewson
2005-08-26 21:46:24 +00:00
parent 53431a4950
commit ae4a183ed8
3 changed files with 20 additions and 11 deletions
+2 -3
View File
@@ -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;
+10 -4
View File
@@ -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;
}
}
+8 -4
View File
@@ -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 <b>router</b> if this function fails; <b>router</b>
* 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 <b>msg</b> is not NULL, then assign to
* If we're returning an error and <b>msg</b> is not NULL, then assign to
* *<b>msg</b> 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;
}
}
}