diff options
-rw-r--r-- | src/or/directory.c | 10 | ||||
-rw-r--r-- | src/or/dirserv.c | 27 | ||||
-rw-r--r-- | src/or/or.h | 3 |
3 files changed, 31 insertions, 9 deletions
diff --git a/src/or/directory.c b/src/or/directory.c index b36fa2a580..175ddfbc02 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -1326,14 +1326,16 @@ directory_handle_command_get(connection_t *conn, char *headers, if (!strcmpstart(url,"/tor/server/")) { size_t url_len = strlen(url); int deflated = !strcmp(url+url_len-2, ".z"); + int res; + const char *msg; smartlist_t *descs = smartlist_create(); if (deflated) url[url_len-2] = '\0'; - dirserv_get_routerdescs(descs, url); + res = dirserv_get_routerdescs(descs, url, &msg); tor_free(url); - if (!smartlist_len(descs)) { - write_http_status_line(conn, 404, "Servers unavailable"); - } else { + if (res < 0) + write_http_status_line(conn, 404, msg); + else { size_t len = 0; format_rfc1123_time(date, time(NULL)); SMARTLIST_FOREACH(descs, routerinfo_t *, ri, diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 3c413e3c20..dab99477ae 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -1393,13 +1393,23 @@ dirserv_get_networkstatus_v2(smartlist_t *result, * hex identity digests; or * - "/tor/server/d/D" where D is a plus-separated sequence * of server descriptor digests, in hex. + * + * Return -1 if we do not have any descriptors, no matching descriptors, + * or if we did not recognize the key (URL), 0 otherwise (i.e. we found some + * matching descriptors). If -1 is returned <b>msg</b> will be set to + * an appropriate error message. */ -void -dirserv_get_routerdescs(smartlist_t *descs_out, const char *key) +int +dirserv_get_routerdescs(smartlist_t *descs_out, const char *key, + const char **msg) { smartlist_t *complete_list = get_descriptor_list(); - if (!complete_list) - return; + *msg = NULL; + + if (!complete_list) { + *msg = "No server descriptors available"; + return -1; + } if (!strcmp(key, "/tor/server/all")) { smartlist_add_all(descs_out, complete_list); @@ -1435,7 +1445,16 @@ dirserv_get_routerdescs(smartlist_t *descs_out, const char *key) }); SMARTLIST_FOREACH(digests, char *, d, tor_free(d)); smartlist_free(digests); + } else { + *msg = "Key not recognized"; + return -1; } + + if (!smartlist_len(descs_out)) { + *msg = "Servers unavailable"; + return -1; + } + return 0; } /** Called when a TLS handshake has completed successfully with a diff --git a/src/or/or.h b/src/or/or.h index 9e2707e688..45519fc5e5 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1781,7 +1781,8 @@ void dirserv_set_cached_directory(const char *directory, time_t when, void dirserv_set_cached_networkstatus_v2(const char *directory, const char *fp, time_t published); int dirserv_get_networkstatus_v2(smartlist_t *result, const char *key); -void dirserv_get_routerdescs(smartlist_t *descs_out, const char *key); +int dirserv_get_routerdescs(smartlist_t *descs_out, const char *key, + const char **msg); void dirserv_orconn_tls_done(const char *address, uint16_t or_port, const char *digest_rcvd, |