mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 12:23:32 +01:00
bwauth: check and use compression serving bw file
This commit is contained in:
parent
b75e2539f9
commit
4d3502e45b
@ -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);
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user