aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2005-10-18 17:09:57 +0000
committerPeter Palfrader <peter@palfrader.org>2005-10-18 17:09:57 +0000
commitd8daa910a66ccfbd25afa57e22e1a77090a8bb5c (patch)
tree920cf1645447ec0fadf50aa0d24670838ab9f657
parent551e3402a3a82eaf92c495564e0a5f4b7ab80fe4 (diff)
downloadtor-d8daa910a66ccfbd25afa57e22e1a77090a8bb5c.tar
tor-d8daa910a66ccfbd25afa57e22e1a77090a8bb5c.tar.gz
Make dirserv_get_routerdescs() return better http 404 error messages instead of a generic "Servers unavailable."
svn:r5274
-rw-r--r--src/or/directory.c10
-rw-r--r--src/or/dirserv.c27
-rw-r--r--src/or/or.h3
3 files changed, 31 insertions, 9 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index b36fa2a58..175ddfbc0 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 3c413e3c2..dab99477a 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 9e2707e68..45519fc5e 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,