Use dir_compressed(_len) instead of dir_z(_len).

This patch renames `dir_z` to `dir_compressed` and `dir_z_len` to
`dir_compressed_len`.

See: https://bugs.torproject.org/21667
This commit is contained in:
Alexander Færøy 2017-05-04 16:21:05 +02:00
parent 4410271446
commit ca632144e5
No known key found for this signature in database
GPG Key ID: E15081D5D3C3DB53
3 changed files with 15 additions and 11 deletions

View File

@ -3885,7 +3885,9 @@ handle_get_status_vote(dir_connection_t *conn, const get_handler_args_t *args)
goto vote_done;
}
SMARTLIST_FOREACH(dir_items, cached_dir_t *, d,
body_len += compressed ? d->dir_z_len : d->dir_len);
body_len += compressed
? d->dir_compressed_len
: d->dir_len);
estimated_len += body_len;
SMARTLIST_FOREACH(items, const char *, item, {
size_t ln = strlen(item);
@ -3917,8 +3919,10 @@ handle_get_status_vote(dir_connection_t *conn, const get_handler_args_t *args)
}
} else {
SMARTLIST_FOREACH(dir_items, cached_dir_t *, d,
connection_write_to_buf(compressed ? d->dir_z : d->dir,
compressed ? d->dir_z_len : d->dir_len,
connection_write_to_buf(compressed
? d->dir_compressed : d->dir,
compressed
? d->dir_compressed_len : d->dir_len,
TO_CONN(conn)));
}
vote_done:

View File

@ -1179,8 +1179,8 @@ new_cached_dir(char *s, time_t published)
d->dir = s;
d->dir_len = strlen(s);
d->published = published;
if (tor_compress(&(d->dir_z), &(d->dir_z_len), d->dir, d->dir_len,
ZLIB_METHOD)) {
if (tor_compress(&(d->dir_compressed), &(d->dir_compressed_len),
d->dir, d->dir_len, ZLIB_METHOD)) {
log_warn(LD_BUG, "Error compressing directory");
}
return d;
@ -1191,7 +1191,7 @@ static void
clear_cached_dir(cached_dir_t *d)
{
tor_free(d->dir);
tor_free(d->dir_z);
tor_free(d->dir_compressed);
memset(d, 0, sizeof(cached_dir_t));
}
@ -3508,7 +3508,7 @@ spooled_resource_estimate_size(const spooled_resource_t *spooled,
if (cached == NULL) {
return 0;
}
size_t result = compressed ? cached->dir_z_len : cached->dir_len;
size_t result = compressed ? cached->dir_compressed_len : cached->dir_len;
return result;
}
}
@ -3567,8 +3567,8 @@ spooled_resource_flush_some(spooled_resource_t *spooled,
int64_t total_len;
const char *ptr;
if (cached) {
total_len = cached->dir_z_len;
ptr = cached->dir_z;
total_len = cached->dir_compressed_len;
ptr = cached->dir_compressed;
} else {
total_len = spooled->cce_len;
ptr = (const char *)spooled->cce_body;

View File

@ -1934,9 +1934,9 @@ typedef struct addr_policy_t {
* compressed form. */
typedef struct cached_dir_t {
char *dir; /**< Contents of this object, NUL-terminated. */
char *dir_z; /**< Compressed contents of this object. */
char *dir_compressed; /**< Compressed contents of this object. */
size_t dir_len; /**< Length of <b>dir</b> (not counting its NUL). */
size_t dir_z_len; /**< Length of <b>dir_z</b>. */
size_t dir_compressed_len; /**< Length of <b>dir_compressed</b>. */
time_t published; /**< When was this object published. */
common_digests_t digests; /**< Digests of this object (networkstatus only) */
/** Sha3 digest (also ns only) */