Add a "best compression" flag.

This commit is contained in:
Nick Mathewson 2017-04-25 09:54:02 -04:00
parent 880fb3e3a9
commit 4b01b45ec1
5 changed files with 10 additions and 6 deletions

View File

@ -208,8 +208,8 @@ tor_compress(char **out, size_t *out_len,
compress_method_t method) compress_method_t method)
{ {
return tor_compress_impl(1, out, out_len, in, in_len, method, return tor_compress_impl(1, out, out_len, in, in_len, method,
HIGH_COMPRESSION, BEST_COMPRESSION,
1, LOG_WARN); // XXXX "best"? 1, LOG_WARN);
} }
/** Given zero or more zlib-compressed or gzip-compressed strings of /** Given zero or more zlib-compressed or gzip-compressed strings of
@ -231,7 +231,7 @@ tor_uncompress(char **out, size_t *out_len,
int protocol_warn_level) int protocol_warn_level)
{ {
return tor_compress_impl(0, out, out_len, in, in_len, method, return tor_compress_impl(0, out, out_len, in, in_len, method,
HIGH_COMPRESSION, BEST_COMPRESSION,
complete_only, protocol_warn_level); complete_only, protocol_warn_level);
} }

View File

@ -26,11 +26,11 @@ typedef enum {
/** /**
* Enumeration to define tradeoffs between memory usage and compression level. * Enumeration to define tradeoffs between memory usage and compression level.
* HIGH_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most * BEST_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most
* memory. * memory.
**/ **/
typedef enum { typedef enum {
HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION BEST_COMPRESSION, HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION
} compression_level_t; } compression_level_t;
int tor_compress(char **out, size_t *out_len, int tor_compress(char **out, size_t *out_len,

View File

@ -32,6 +32,7 @@ memory_level(compression_level_t level)
{ {
switch (level) { switch (level) {
default: default:
case BEST_COMPRESSION:
case HIGH_COMPRESSION: return 9; case HIGH_COMPRESSION: return 9;
case MEDIUM_COMPRESSION: return 6; case MEDIUM_COMPRESSION: return 6;
case LOW_COMPRESSION: return 3; case LOW_COMPRESSION: return 3;

View File

@ -56,6 +56,7 @@ memory_level(compression_level_t level)
{ {
switch (level) { switch (level) {
default: default:
case BEST_COMPRESSION: return 9;
case HIGH_COMPRESSION: return 8; case HIGH_COMPRESSION: return 8;
case MEDIUM_COMPRESSION: return 7; case MEDIUM_COMPRESSION: return 7;
case LOW_COMPRESSION: return 6; case LOW_COMPRESSION: return 6;
@ -70,6 +71,7 @@ method_bits(compress_method_t method, compression_level_t level)
const int flag = method == GZIP_METHOD ? 16 : 0; const int flag = method == GZIP_METHOD ? 16 : 0;
switch (level) { switch (level) {
default: default:
case BEST_COMPRESSION:
case HIGH_COMPRESSION: return flag + 15; case HIGH_COMPRESSION: return flag + 15;
case MEDIUM_COMPRESSION: return flag + 13; case MEDIUM_COMPRESSION: return flag + 13;
case LOW_COMPRESSION: return flag + 11; case LOW_COMPRESSION: return flag + 11;
@ -162,7 +164,7 @@ tor_zlib_compress_new(int compress_,
if (! compress_) { if (! compress_) {
/* use this setting for decompression, since we might have the /* use this setting for decompression, since we might have the
* max number of window bits */ * max number of window bits */
compression_level = HIGH_COMPRESSION; compression_level = BEST_COMPRESSION;
} }
out = tor_malloc_zero(sizeof(tor_zlib_compress_state_t)); out = tor_malloc_zero(sizeof(tor_zlib_compress_state_t));

View File

@ -33,6 +33,7 @@ memory_level(compression_level_t level)
{ {
switch (level) { switch (level) {
default: default:
case BEST_COMPRESSION:
case HIGH_COMPRESSION: return 9; case HIGH_COMPRESSION: return 9;
case MEDIUM_COMPRESSION: return 8; case MEDIUM_COMPRESSION: return 8;
case LOW_COMPRESSION: return 7; case LOW_COMPRESSION: return 7;