mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 12:23:32 +01:00
Make dirserv_get_routerdescs() return better http 404 error messages instead of a generic "Servers unavailable."
svn:r5274
This commit is contained in:
parent
551e3402a3
commit
d8daa910a6
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user