[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/release-0.3.1] Send the correct content-encoding when serving cached_dir_t objects



commit 782eb02b79363bf8ed609495d516bc59972f4352
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Tue Jun 20 11:26:51 2017 -0400

    Send the correct content-encoding when serving cached_dir_t objects
    
    A cached_dir_t object (for now) is always compressed with
    DEFLATE_METHOD, but in handle_get_status_vote() to we were using the
    general compression-negotiation code decide what compression to
    claim we were using.
    
    This was one of the reasons behind 22502.
    
    Fixes bug 22669; bugfix on 0.3.1.1-alpha
---
 changes/bug22669   |  4 ++++
 src/or/directory.c | 25 +++++++++++++++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/changes/bug22669 b/changes/bug22669
new file mode 100644
index 0000000..804a39e
--- /dev/null
+++ b/changes/bug22669
@@ -0,0 +1,4 @@
+  o Minor bugfixes (compression):
+    - When serving directory votes compressed with zlib,
+      do not claim to have compressed them with zstd. Fixes bug 22669;
+      bugfix on 0.3.1.1-alpha.
diff --git a/src/or/directory.c b/src/or/directory.c
index ecd9811..b680b13 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -4190,13 +4190,14 @@ static int
 handle_get_status_vote(dir_connection_t *conn, const get_handler_args_t *args)
 {
   const char *url = args->url;
-  const compress_method_t compress_method =
-    find_best_compression_method(args->compression_supported, 1);
   {
     int current;
     ssize_t body_len = 0;
     ssize_t estimated_len = 0;
+    /* This smartlist holds strings that we can compress on the fly. */
     smartlist_t *items = smartlist_new();
+    /* This smartlist holds cached_dir_t objects that have a precompressed
+     * deflated version. */
     smartlist_t *dir_items = smartlist_new();
     int lifetime = 60; /* XXXX?? should actually use vote intervals. */
     url += strlen("/tor/status-vote/");
@@ -4247,6 +4248,26 @@ handle_get_status_vote(dir_connection_t *conn, const get_handler_args_t *args)
       write_http_status_line(conn, 404, "Not found");
       goto vote_done;
     }
+
+    /* We're sending items from at most one kind of source */
+    tor_assert_nonfatal(smartlist_len(items) == 0 ||
+                        smartlist_len(dir_items) == 0);
+
+    int streaming;
+    unsigned mask;
+    if (smartlist_len(items)) {
+      /* We're taking strings and compressing them on the fly. */
+      streaming = 1;
+      mask = ~0u;
+    } else {
+      /* We're taking cached_dir_t objects. We only have them uncompressed
+       * or deflated. */
+      streaming = 0;
+      mask = (1u<<NO_METHOD) | (1u<<ZLIB_METHOD);
+    }
+    const compress_method_t compress_method = find_best_compression_method(
+                              args->compression_supported&mask, streaming);
+
     SMARTLIST_FOREACH(dir_items, cached_dir_t *, d,
                       body_len += compress_method != NO_METHOD ?
                         d->dir_compressed_len : d->dir_len);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits