mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Rename write_to_buf_zlib()
to write_to_buf_compress()
.
See https://bugs.torproject.org/21663
This commit is contained in:
parent
40ed68290e
commit
b8c9f229d7
@ -2092,9 +2092,9 @@ fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len)
|
|||||||
* <b>done</b> is true, flush the data in the state and finish the
|
* <b>done</b> is true, flush the data in the state and finish the
|
||||||
* compression/uncompression. Return -1 on failure, 0 on success. */
|
* compression/uncompression. Return -1 on failure, 0 on success. */
|
||||||
int
|
int
|
||||||
write_to_buf_zlib(buf_t *buf, tor_compress_state_t *state,
|
write_to_buf_compress(buf_t *buf, tor_compress_state_t *state,
|
||||||
const char *data, size_t data_len,
|
const char *data, size_t data_len,
|
||||||
int done)
|
int done)
|
||||||
{
|
{
|
||||||
char *next;
|
char *next;
|
||||||
size_t old_avail, avail;
|
size_t old_avail, avail;
|
||||||
|
@ -36,8 +36,8 @@ int flush_buf(tor_socket_t s, buf_t *buf, size_t sz, size_t *buf_flushlen);
|
|||||||
int flush_buf_tls(tor_tls_t *tls, buf_t *buf, size_t sz, size_t *buf_flushlen);
|
int flush_buf_tls(tor_tls_t *tls, buf_t *buf, size_t sz, size_t *buf_flushlen);
|
||||||
|
|
||||||
int write_to_buf(const char *string, size_t string_len, buf_t *buf);
|
int write_to_buf(const char *string, size_t string_len, buf_t *buf);
|
||||||
int write_to_buf_zlib(buf_t *buf, tor_compress_state_t *state,
|
int write_to_buf_compress(buf_t *buf, tor_compress_state_t *state,
|
||||||
const char *data, size_t data_len, int done);
|
const char *data, size_t data_len, int done);
|
||||||
int move_buf_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen);
|
int move_buf_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen);
|
||||||
int fetch_from_buf(char *string, size_t string_len, buf_t *buf);
|
int fetch_from_buf(char *string, size_t string_len, buf_t *buf);
|
||||||
int fetch_var_cell_from_buf(buf_t *buf, var_cell_t **out, int linkproto);
|
int fetch_var_cell_from_buf(buf_t *buf, var_cell_t **out, int linkproto);
|
||||||
|
@ -4060,9 +4060,9 @@ connection_write_to_buf_impl_,(const char *string, size_t len,
|
|||||||
if (zlib) {
|
if (zlib) {
|
||||||
dir_connection_t *dir_conn = TO_DIR_CONN(conn);
|
dir_connection_t *dir_conn = TO_DIR_CONN(conn);
|
||||||
int done = zlib < 0;
|
int done = zlib < 0;
|
||||||
CONN_LOG_PROTECT(conn, r = write_to_buf_zlib(conn->outbuf,
|
CONN_LOG_PROTECT(conn, r = write_to_buf_compress(conn->outbuf,
|
||||||
dir_conn->compress_state,
|
dir_conn->compress_state,
|
||||||
string, len, done));
|
string, len, done));
|
||||||
} else {
|
} else {
|
||||||
CONN_LOG_PROTECT(conn, r = write_to_buf(string, len, conn->outbuf));
|
CONN_LOG_PROTECT(conn, r = write_to_buf(string, len, conn->outbuf));
|
||||||
}
|
}
|
||||||
|
@ -141,17 +141,17 @@ MOCK_DECL(void, connection_write_to_buf_impl_,
|
|||||||
/* DOCDOC connection_write_to_buf */
|
/* DOCDOC connection_write_to_buf */
|
||||||
static void connection_write_to_buf(const char *string, size_t len,
|
static void connection_write_to_buf(const char *string, size_t len,
|
||||||
connection_t *conn);
|
connection_t *conn);
|
||||||
/* DOCDOC connection_write_to_buf_zlib */
|
/* DOCDOC connection_write_to_buf_compress */
|
||||||
static void connection_write_to_buf_zlib(const char *string, size_t len,
|
static void connection_write_to_buf_compress(const char *string, size_t len,
|
||||||
dir_connection_t *conn, int done);
|
dir_connection_t *conn, int done);
|
||||||
static inline void
|
static inline void
|
||||||
connection_write_to_buf(const char *string, size_t len, connection_t *conn)
|
connection_write_to_buf(const char *string, size_t len, connection_t *conn)
|
||||||
{
|
{
|
||||||
connection_write_to_buf_impl_(string, len, conn, 0);
|
connection_write_to_buf_impl_(string, len, conn, 0);
|
||||||
}
|
}
|
||||||
static inline void
|
static inline void
|
||||||
connection_write_to_buf_zlib(const char *string, size_t len,
|
connection_write_to_buf_compress(const char *string, size_t len,
|
||||||
dir_connection_t *conn, int done)
|
dir_connection_t *conn, int done)
|
||||||
{
|
{
|
||||||
connection_write_to_buf_impl_(string, len, TO_CONN(conn), done ? -1 : 1);
|
connection_write_to_buf_impl_(string, len, TO_CONN(conn), done ? -1 : 1);
|
||||||
}
|
}
|
||||||
|
@ -3280,8 +3280,8 @@ handle_get_status_vote(dir_connection_t *conn, const get_handler_args_t *args)
|
|||||||
conn->compress_state = tor_compress_new(1, ZLIB_METHOD,
|
conn->compress_state = tor_compress_new(1, ZLIB_METHOD,
|
||||||
choose_compression_level(estimated_len));
|
choose_compression_level(estimated_len));
|
||||||
SMARTLIST_FOREACH(items, const char *, c,
|
SMARTLIST_FOREACH(items, const char *, c,
|
||||||
connection_write_to_buf_zlib(c, strlen(c), conn, 0));
|
connection_write_to_buf_compress(c, strlen(c), conn, 0));
|
||||||
connection_write_to_buf_zlib("", 0, conn, 1);
|
connection_write_to_buf_compress("", 0, conn, 1);
|
||||||
} else {
|
} else {
|
||||||
SMARTLIST_FOREACH(items, const char *, c,
|
SMARTLIST_FOREACH(items, const char *, c,
|
||||||
connection_write_to_buf(c, strlen(c), TO_CONN(conn)));
|
connection_write_to_buf(c, strlen(c), TO_CONN(conn)));
|
||||||
@ -3523,10 +3523,11 @@ handle_get_keys(dir_connection_t *conn, const get_handler_args_t *args)
|
|||||||
conn->compress_state = tor_compress_new(1, ZLIB_METHOD,
|
conn->compress_state = tor_compress_new(1, ZLIB_METHOD,
|
||||||
choose_compression_level(len));
|
choose_compression_level(len));
|
||||||
SMARTLIST_FOREACH(certs, authority_cert_t *, c,
|
SMARTLIST_FOREACH(certs, authority_cert_t *, c,
|
||||||
connection_write_to_buf_zlib(c->cache_info.signed_descriptor_body,
|
connection_write_to_buf_compress(
|
||||||
c->cache_info.signed_descriptor_len,
|
c->cache_info.signed_descriptor_body,
|
||||||
conn, 0));
|
c->cache_info.signed_descriptor_len,
|
||||||
connection_write_to_buf_zlib("", 0, conn, 1);
|
conn, 0));
|
||||||
|
connection_write_to_buf_compress("", 0, conn, 1);
|
||||||
} else {
|
} else {
|
||||||
SMARTLIST_FOREACH(certs, authority_cert_t *, c,
|
SMARTLIST_FOREACH(certs, authority_cert_t *, c,
|
||||||
connection_write_to_buf(c->cache_info.signed_descriptor_body,
|
connection_write_to_buf(c->cache_info.signed_descriptor_body,
|
||||||
|
@ -3498,7 +3498,7 @@ spooled_resource_flush_some(spooled_resource_t *spooled,
|
|||||||
return SRFS_DONE;
|
return SRFS_DONE;
|
||||||
}
|
}
|
||||||
if (conn->compress_state) {
|
if (conn->compress_state) {
|
||||||
connection_write_to_buf_zlib((const char*)body, bodylen, conn, 0);
|
connection_write_to_buf_compress((const char*)body, bodylen, conn, 0);
|
||||||
} else {
|
} else {
|
||||||
connection_write_to_buf((const char*)body, bodylen, TO_CONN(conn));
|
connection_write_to_buf((const char*)body, bodylen, TO_CONN(conn));
|
||||||
}
|
}
|
||||||
@ -3524,8 +3524,9 @@ spooled_resource_flush_some(spooled_resource_t *spooled,
|
|||||||
return SRFS_ERR;
|
return SRFS_ERR;
|
||||||
ssize_t bytes = (ssize_t) MIN(DIRSERV_CACHED_DIR_CHUNK_SIZE, remaining);
|
ssize_t bytes = (ssize_t) MIN(DIRSERV_CACHED_DIR_CHUNK_SIZE, remaining);
|
||||||
if (conn->compress_state) {
|
if (conn->compress_state) {
|
||||||
connection_write_to_buf_zlib(cached->dir_z + spooled->cached_dir_offset,
|
connection_write_to_buf_compress(
|
||||||
bytes, conn, 0);
|
cached->dir_z + spooled->cached_dir_offset,
|
||||||
|
bytes, conn, 0);
|
||||||
} else {
|
} else {
|
||||||
connection_write_to_buf(cached->dir_z + spooled->cached_dir_offset,
|
connection_write_to_buf(cached->dir_z + spooled->cached_dir_offset,
|
||||||
bytes, TO_CONN(conn));
|
bytes, TO_CONN(conn));
|
||||||
@ -3789,9 +3790,9 @@ connection_dirserv_flushed_some(dir_connection_t *conn)
|
|||||||
smartlist_free(conn->spool);
|
smartlist_free(conn->spool);
|
||||||
conn->spool = NULL;
|
conn->spool = NULL;
|
||||||
if (conn->compress_state) {
|
if (conn->compress_state) {
|
||||||
/* Flush the zlib state: there could be more bytes pending in there, and
|
/* Flush the compression state: there could be more bytes pending in there,
|
||||||
* we don't want to omit bytes. */
|
* and we don't want to omit bytes. */
|
||||||
connection_write_to_buf_zlib("", 0, conn, 1);
|
connection_write_to_buf_compress("", 0, conn, 1);
|
||||||
tor_compress_free(conn->compress_state);
|
tor_compress_free(conn->compress_state);
|
||||||
conn->compress_state = NULL;
|
conn->compress_state = NULL;
|
||||||
}
|
}
|
||||||
|
@ -593,14 +593,17 @@ test_buffers_zlib_impl(int finalize_with_nil)
|
|||||||
|
|
||||||
msg = tor_malloc(512);
|
msg = tor_malloc(512);
|
||||||
crypto_rand(msg, 512);
|
crypto_rand(msg, 512);
|
||||||
tt_int_op(write_to_buf_zlib(buf, compress_state, msg, 128, 0), OP_EQ, 0);
|
tt_int_op(write_to_buf_compress(buf, compress_state,
|
||||||
tt_int_op(write_to_buf_zlib(buf, compress_state, msg+128, 128, 0), OP_EQ, 0);
|
msg, 128, 0), OP_EQ, 0);
|
||||||
tt_int_op(write_to_buf_zlib(buf, compress_state, msg+256, 256, 0), OP_EQ, 0);
|
tt_int_op(write_to_buf_compress(buf, compress_state,
|
||||||
|
msg+128, 128, 0), OP_EQ, 0);
|
||||||
|
tt_int_op(write_to_buf_compress(buf, compress_state,
|
||||||
|
msg+256, 256, 0), OP_EQ, 0);
|
||||||
done = !finalize_with_nil;
|
done = !finalize_with_nil;
|
||||||
tt_int_op(write_to_buf_zlib(buf, compress_state,
|
tt_int_op(write_to_buf_compress(buf, compress_state,
|
||||||
"all done", 9, done), OP_EQ, 0);
|
"all done", 9, done), OP_EQ, 0);
|
||||||
if (finalize_with_nil) {
|
if (finalize_with_nil) {
|
||||||
tt_int_op(write_to_buf_zlib(buf, compress_state, "", 0, 1), OP_EQ, 0);
|
tt_int_op(write_to_buf_compress(buf, compress_state, "", 0, 1), OP_EQ, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
in_len = buf_datalen(buf);
|
in_len = buf_datalen(buf);
|
||||||
@ -668,7 +671,7 @@ test_buffers_zlib_fin_at_chunk_end(void *arg)
|
|||||||
tt_uint_op(buf_datalen(buf), OP_EQ, headerjunk);
|
tt_uint_op(buf_datalen(buf), OP_EQ, headerjunk);
|
||||||
/* Write an empty string, with finalization on. */
|
/* Write an empty string, with finalization on. */
|
||||||
compress_state = tor_compress_new(1, ZLIB_METHOD, HIGH_COMPRESSION);
|
compress_state = tor_compress_new(1, ZLIB_METHOD, HIGH_COMPRESSION);
|
||||||
tt_int_op(write_to_buf_zlib(buf, compress_state, "", 0, 1), OP_EQ, 0);
|
tt_int_op(write_to_buf_compress(buf, compress_state, "", 0, 1), OP_EQ, 0);
|
||||||
|
|
||||||
in_len = buf_datalen(buf);
|
in_len = buf_datalen(buf);
|
||||||
contents = tor_malloc(in_len);
|
contents = tor_malloc(in_len);
|
||||||
|
Loading…
Reference in New Issue
Block a user