summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2019-04-03 17:59:02 +0300
committerGeorge Kadianakis <desnacked@riseup.net>2019-04-03 17:59:02 +0300
commit42aae0e693be6f96eef9d124867c7e0915b6ab78 (patch)
tree137015a9e52427915b11c255dc479673ed457fc3 /src
parent828f1829c8082abd7e3f9221b63d2367ff4b9639 (diff)
parent194b25f0c7043b2485bb90da6fb24c0e96957875 (diff)
downloadtor-42aae0e693be6f96eef9d124867c7e0915b6ab78.tar.gz
tor-42aae0e693be6f96eef9d124867c7e0915b6ab78.zip
Merge branch 'tor-github/pr/867' into maint-0.4.0
Diffstat (limited to 'src')
-rw-r--r--src/core/mainloop/connection.c17
-rw-r--r--src/core/mainloop/connection.h2
-rw-r--r--src/feature/dircache/dircache.c5
3 files changed, 20 insertions, 4 deletions
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index c8b19344bd..7f2e96b4d1 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -4341,6 +4341,23 @@ connection_write_to_buf_impl_,(const char *string, size_t len,
connection_write_to_buf_commit(conn, written);
}
+/**
+ * Write a <b>string</b> (of size <b>len</b> to directory connection
+ * <b>dir_conn</b>. Apply compression if connection is configured to use
+ * it and finalize it if <b>done</b> is true.
+ */
+void
+connection_dir_buf_add(const char *string, size_t len,
+ dir_connection_t *dir_conn, int done)
+{
+ if (dir_conn->compress_state != NULL) {
+ connection_buf_add_compress(string, len, dir_conn, done);
+ return;
+ }
+
+ connection_buf_add(string, len, TO_CONN(dir_conn));
+}
+
void
connection_buf_add_compress(const char *string, size_t len,
dir_connection_t *conn, int done)
diff --git a/src/core/mainloop/connection.h b/src/core/mainloop/connection.h
index 411f13a8b8..c93f1ef8e8 100644
--- a/src/core/mainloop/connection.h
+++ b/src/core/mainloop/connection.h
@@ -226,6 +226,8 @@ MOCK_DECL(void, connection_write_to_buf_impl_,
/* DOCDOC connection_write_to_buf */
static void connection_buf_add(const char *string, size_t len,
connection_t *conn);
+void connection_dir_buf_add(const char *string, size_t len,
+ dir_connection_t *dir_conn, int done);
static inline void
connection_buf_add(const char *string, size_t len, connection_t *conn)
{
diff --git a/src/feature/dircache/dircache.c b/src/feature/dircache/dircache.c
index caa085dd63..62eb4c86c2 100644
--- a/src/feature/dircache/dircache.c
+++ b/src/feature/dircache/dircache.c
@@ -1486,13 +1486,10 @@ handle_get_next_bandwidth(dir_connection_t *conn,
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));
}
+ connection_dir_buf_add((const char*)bandwidth, len, conn, 1);
tor_free(bandwidth);
return 0;
}