summaryrefslogtreecommitdiff
path: root/src/or/routerlist.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-04-02 22:02:13 +0000
committerNick Mathewson <nickm@torproject.org>2005-04-02 22:02:13 +0000
commit4a90d3722969f6b0c8b7a4507af0889594fbed13 (patch)
tree947f458dfa1782f2e20271e7f730a79533da07db /src/or/routerlist.c
parenta1397b2d045b9efc05a8e2fa869a32b23074075c (diff)
downloadtor-4a90d3722969f6b0c8b7a4507af0889594fbed13.tar.gz
tor-4a90d3722969f6b0c8b7a4507af0889594fbed13.zip
Better messages when POSTDESCRIPTOR fails
svn:r3989
Diffstat (limited to 'src/or/routerlist.c')
-rw-r--r--src/or/routerlist.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index d8dc2873ed..0de1eb9aad 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -769,9 +769,11 @@ void router_mark_as_down(const char *digest) {
* their pointers to <b>router</b> after invoking this function; <b>router</b>
* will either be inserted into the routerlist or freed. Returns 0 if the
* router was added; -1 if it was not.
+ *
+ * DOCDOC msg
*/
static int
-router_add_to_routerlist(routerinfo_t *router) {
+router_add_to_routerlist(routerinfo_t *router, const char **msg) {
int i;
routerinfo_t *r;
char id_digest[DIGEST_LEN];
@@ -797,11 +799,12 @@ router_add_to_routerlist(routerinfo_t *router) {
smartlist_set(routerlist->routers, i, router);
return 0;
} else {
- log_fn(LOG_DEBUG, "Skipping old entry for router '%s'",
+ log_fn(LOG_DEBUG, "Skipping not-new descriptor for router '%s'",
router->nickname);
/* Update the is_running status to whatever we were told. */
r->is_running = router->is_running;
routerinfo_free(router);
+ if (msg) *msg = "Router descriptor was not new.";
return -1;
}
} else if (!strcasecmp(router->nickname, r->nickname)) {
@@ -827,6 +830,7 @@ router_add_to_routerlist(routerinfo_t *router) {
log_fn(LOG_DEBUG, "Skipping unverified entry for verified router '%s'",
router->nickname);
routerinfo_free(router);
+ if (msg) *msg = "Already have verified router with different key and same nickname";
return -1;
}
}
@@ -865,15 +869,19 @@ routerlist_remove_old_routers(int age)
}
/*
- * Code to parse router descriptors and directories.
+ * Code to parse a single router descriptors and insert it into the
+ * directory. Return -1 if the descriptor was ill-formed; 0 if the
+ * descriptor was well-formed but could not be added; and 1 if the
+ * descriptor was added.
*/
int
-router_load_single_router(const char *s)
+router_load_single_router(const char *s, const char **msg)
{
routerinfo_t *ri;
if (!(ri = router_parse_entry_from_string(s, NULL))) {
log_fn(LOG_WARN, "Error parsing router descriptor; dropping.");
+ if (msg) *msg = "Couldn't parse router descriptor";
return -1;
}
if (routerlist && routerlist->running_routers) {
@@ -883,9 +891,10 @@ router_load_single_router(const char *s)
rr->running_routers,
rr->is_running_routers_format);
}
- if (router_add_to_routerlist(ri)<0) {
+ if (router_add_to_routerlist(ri, msg)<0) {
log_fn(LOG_WARN, "Couldn't add router to list; dropping.");
- return -1;
+ if (msg && !*msg) *msg = "Couldn't add router to list.";
+ return 0;
} else {
smartlist_t *changed = smartlist_create();
smartlist_add(changed, ri);
@@ -893,7 +902,7 @@ router_load_single_router(const char *s)
smartlist_free(changed);
}
log_fn(LOG_DEBUG, "Added router to list");
- return 0;
+ return 1;
}
/** Add to the current routerlist each router stored in the
@@ -922,7 +931,7 @@ int router_load_routerlist_from_directory(const char *s,
smartlist_t *changed = smartlist_create();
SMARTLIST_FOREACH(new_list->routers, routerinfo_t *, r,
{
- if (router_add_to_routerlist(r)==0)
+ if (router_add_to_routerlist(r,NULL)==0)
smartlist_add(changed, r);
});
smartlist_clear(new_list->routers);