diff options
author | juga0 <juga@riseup.net> | 2018-11-07 12:15:31 +0000 |
---|---|---|
committer | teor <teor@torproject.org> | 2019-03-26 17:40:58 +1000 |
commit | 4d3502e45bc9b0da91b32c362a7995f33cee0539 (patch) | |
tree | db6957312775d82c8b073e722c5db823fa1ebe0c /src/feature/dircache | |
parent | b75e2539f9994dc04ee7662445878e8486eb77b0 (diff) | |
download | tor-4d3502e45bc9b0da91b32c362a7995f33cee0539.tar.gz tor-4d3502e45bc9b0da91b32c362a7995f33cee0539.zip |
bwauth: check and use compression serving bw file
Diffstat (limited to 'src/feature/dircache')
-rw-r--r-- | src/feature/dircache/dircache.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/feature/dircache/dircache.c b/src/feature/dircache/dircache.c index d9625ee698..e5ea9f73b3 100644 --- a/src/feature/dircache/dircache.c +++ b/src/feature/dircache/dircache.c @@ -1449,14 +1449,28 @@ handle_get_next_bandwidth(dir_connection_t *conn, (void)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) { int lifetime = 60; char *bandwidth = read_file_to_str(options->V3BandwidthsFile, RFTS_IGNORE_MISSING, NULL); if (bandwidth != NULL) { - site_t len = strlen(bandwidth); - write_http_response_header(conn, len, NO_METHOD, lifetime); - connection_buf_add(bandwidth, len, TO_CONN(conn)); + 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; } |