diff options
author | teor <teor@torproject.org> | 2019-03-26 19:16:06 +1000 |
---|---|---|
committer | teor <teor@torproject.org> | 2019-03-26 19:16:06 +1000 |
commit | 06426508655590fee73696a6d398d8ed7f9af1ed (patch) | |
tree | 2a8a8cd4855ef94e1c53957663c16ebac2d52ee0 /src/feature | |
parent | 3d38d0ca24915fc05e770f2d5be3fd38203b5210 (diff) | |
parent | 4258728d56cb02d36baa785200a0d04f5b4c8fa6 (diff) | |
download | tor-06426508655590fee73696a6d398d8ed7f9af1ed.tar.gz tor-06426508655590fee73696a6d398d8ed7f9af1ed.zip |
Merge branch 'maint-0.4.0'
Diffstat (limited to 'src/feature')
-rw-r--r-- | src/feature/dircache/dircache.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/feature/dircache/dircache.c b/src/feature/dircache/dircache.c index ee6e4f7a81..a8649054a9 100644 --- a/src/feature/dircache/dircache.c +++ b/src/feature/dircache/dircache.c @@ -49,7 +49,8 @@ #define ROUTERDESC_BY_DIGEST_CACHE_LIFETIME (48*60*60) #define ROBOTS_CACHE_LIFETIME (24*60*60) #define MICRODESC_CACHE_LIFETIME (48*60*60) - +/* Bandwidth files change every hour. */ +#define BANDWIDTH_CACHE_LIFETIME (30*60) /** Parse an HTTP request string <b>headers</b> of the form * \verbatim * "\%s [http[s]://]\%s HTTP/1..." @@ -351,12 +352,15 @@ static int handle_get_robots(dir_connection_t *conn, const get_handler_args_t *args); static int handle_get_networkstatus_bridges(dir_connection_t *conn, const get_handler_args_t *args); +static int handle_get_next_bandwidth(dir_connection_t *conn, + const get_handler_args_t *args); /** Table for handling GET requests. */ static const url_table_ent_t url_table[] = { { "/tor/", 0, handle_get_frontpage }, { "/tor/status-vote/current/consensus", 1, handle_get_current_consensus }, { "/tor/status-vote/current/", 1, handle_get_status_vote }, + { "/tor/status-vote/next/bandwidth", 0, handle_get_next_bandwidth }, { "/tor/status-vote/next/", 1, handle_get_status_vote }, { "/tor/micro/d/", 1, handle_get_microdesc }, { "/tor/server/", 1, handle_get_descriptor }, @@ -1453,6 +1457,42 @@ handle_get_networkstatus_bridges(dir_connection_t *conn, return 0; } +/** Helper function for GET the bandwidth file used for the next vote */ +static int +handle_get_next_bandwidth(dir_connection_t *conn, + const get_handler_args_t *args) +{ + log_debug(LD_DIR, "Getting next bandwidth."); + const or_options_t *options = get_options(); + const compress_method_t compress_method = + find_best_compression_method(args->compression_supported, 1); + + if (options->V3BandwidthsFile) { + char *bandwidth = read_file_to_str(options->V3BandwidthsFile, + RFTS_IGNORE_MISSING, NULL); + if (bandwidth != NULL) { + ssize_t len = strlen(bandwidth); + write_http_response_header(conn, compress_method != NO_METHOD ? -1 : len, + compress_method, BANDWIDTH_CACHE_LIFETIME); + if (compress_method != NO_METHOD) { + conn->compress_state = tor_compress_new(1, compress_method, + choose_compression_level(len/2)); + log_debug(LD_DIR, "Compressing bandwidth file."); + connection_buf_add_compress(bandwidth, len, conn, 0); + /* Flush the compression state. */ + connection_buf_add_compress("", 0, conn, 1); + } else { + log_debug(LD_DIR, "Not compressing bandwidth file."); + connection_buf_add(bandwidth, len, TO_CONN(conn)); + } + tor_free(bandwidth); + return 0; + } + } + write_short_http_response(conn, 404, "Not found"); + return 0; +} + /** Helper function for GET robots.txt or /tor/robots.txt */ static int handle_get_robots(dir_connection_t *conn, const get_handler_args_t *args) |