Data Structures | Macros | Functions | Variables
compress_zstd.c File Reference

Compression backend for Zstandard. More...

#include "orconfig.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/compress/compress.h"
#include "lib/compress/compress_zstd.h"
#include "lib/string/printf.h"
#include "lib/thread/threads.h"

Go to the source code of this file.

Data Structures

struct  tor_zstd_compress_state_t


#define VERSION_STR_MAX_LEN   16 /* more than enough space for 99.99.99 */


int tor_zstd_method_supported (void)
const char * tor_zstd_get_version_str (void)
const char * tor_zstd_get_header_version_str (void)
int tor_zstd_can_use_static_apis (void)
tor_zstd_compress_state_ttor_zstd_compress_new (int compress, compress_method_t method, compression_level_t level)
tor_compress_output_t tor_zstd_compress_process (tor_zstd_compress_state_t *state, char **out, size_t *out_len, const char **in, size_t *in_len, int finish)
void tor_zstd_compress_free_ (tor_zstd_compress_state_t *state)
size_t tor_zstd_compress_state_size (const tor_zstd_compress_state_t *state)
size_t tor_zstd_get_total_allocation (void)
void tor_zstd_init (void)
void tor_zstd_warn_if_version_mismatched (void)


static atomic_counter_t total_zstd_allocation

Detailed Description

Compression backend for Zstandard.

This module should never be invoked directly. Use the compress module instead.

Definition in file compress_zstd.c.

Function Documentation

◆ tor_zstd_can_use_static_apis()

int tor_zstd_can_use_static_apis ( void  )

Return true iff we can use the "static-only" APIs.

Definition at line 119 of file compress_zstd.c.

Referenced by tor_zstd_warn_if_version_mismatched().

◆ tor_zstd_compress_free_()

void tor_zstd_compress_free_ ( tor_zstd_compress_state_t state)

Deallocate state.

Definition at line 471 of file compress_zstd.c.

◆ tor_zstd_compress_new()

tor_zstd_compress_state_t* tor_zstd_compress_new ( int  compress,
compress_method_t  method,
compression_level_t  level 

Construct and return a tor_zstd_compress_state_t object using method. If compress, it's for compression; otherwise it's for decompression.

Definition at line 249 of file compress_zstd.c.

◆ tor_zstd_compress_process()

tor_compress_output_t tor_zstd_compress_process ( tor_zstd_compress_state_t state,
char **  out,
size_t *  out_len,
const char **  in,
size_t *  in_len,
int  finish 

Compress/decompress some bytes using state. Read up to *in_len bytes from *in, and write up to *out_len bytes to *out, adjusting the values as we go. If finish is true, we've reached the end of the input.

Return TOR_COMPRESS_DONE if we've finished the entire compression/decompression. Return TOR_COMPRESS_OK if we're processed everything from the input. Return TOR_COMPRESS_BUFFER_FULL if we're out of space on out. Return TOR_COMPRESS_ERROR if the stream is corrupt.

Definition at line 341 of file compress_zstd.c.

◆ tor_zstd_compress_state_size()

size_t tor_zstd_compress_state_size ( const tor_zstd_compress_state_t state)

Return the approximate number of bytes allocated for state.

Definition at line 491 of file compress_zstd.c.

◆ tor_zstd_get_header_version_str()

const char* tor_zstd_get_header_version_str ( void  )

Return a string representation of the version of the version of libzstd used at compilation time. Returns NULL if Zstandard is unsupported.

Definition at line 104 of file compress_zstd.c.

◆ tor_zstd_get_total_allocation()

size_t tor_zstd_get_total_allocation ( void  )

Return the approximate number of bytes allocated for all Zstandard states.

Definition at line 500 of file compress_zstd.c.

Referenced by tor_compress_get_total_allocation().

◆ tor_zstd_get_version_str()

const char* tor_zstd_get_version_str ( void  )

Return a string representation of the version of the currently running version of libzstd. Returns NULL if Zstandard is unsupported.

Definition at line 87 of file compress_zstd.c.

◆ tor_zstd_init()

void tor_zstd_init ( void  )

Initialize the zstd module

Definition at line 507 of file compress_zstd.c.

Referenced by tor_compress_init().

◆ tor_zstd_method_supported()

int tor_zstd_method_supported ( void  )

Return 1 if Zstandard compression is supported; otherwise 0.

Definition at line 60 of file compress_zstd.c.

◆ tor_zstd_warn_if_version_mismatched()

void tor_zstd_warn_if_version_mismatched ( void  )

Warn if the header and library versions don't match.

Definition at line 514 of file compress_zstd.c.

Referenced by tor_compress_log_init_warnings().

Variable Documentation

◆ total_zstd_allocation

atomic_counter_t total_zstd_allocation

Total number of bytes allocated for Zstandard state.

Definition at line 41 of file compress_zstd.c.

Referenced by tor_zstd_compress_free_(), tor_zstd_get_total_allocation(), and tor_zstd_init().