[tor-commits] [tor/master] bwauth: check and use compression serving bw file

teor at torproject.org teor at torproject.org
Tue Mar 26 09:16:26 UTC 2019


commit 4d3502e45bc9b0da91b32c362a7995f33cee0539
Author: juga0 <juga at riseup.net>
Date:   Wed Nov 7 12:15:31 2018 +0000

    bwauth: check and use compression serving bw file
---
 src/feature/dircache/dircache.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/feature/dircache/dircache.c b/src/feature/dircache/dircache.c
index d9625ee69..e5ea9f73b 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;
     }





More information about the tor-commits mailing list