consdiffmgr.h (3371B)
1 /* Copyright (c) 2017-2021, The Tor Project, Inc. */ 2 /* See LICENSE for licensing information */ 3 4 /** 5 * @file consdiffmgr.h 6 * @brief Header for consdiffmgr.c 7 **/ 8 9 #ifndef TOR_CONSDIFFMGR_H 10 #define TOR_CONSDIFFMGR_H 11 12 enum compress_method_t; 13 14 /** 15 * Possible outcomes from trying to look up a given consensus diff. 16 */ 17 typedef enum consdiff_status_t { 18 CONSDIFF_AVAILABLE, 19 CONSDIFF_NOT_FOUND, 20 CONSDIFF_IN_PROGRESS, 21 } consdiff_status_t; 22 23 typedef struct consdiff_cfg_t { 24 int32_t cache_max_num; 25 } consdiff_cfg_t; 26 27 struct consensus_cache_entry_t; // from conscache.h 28 29 int consdiffmgr_add_consensus(const char *consensus, 30 size_t consensus_len, 31 const networkstatus_t *as_parsed); 32 33 consdiff_status_t consdiffmgr_find_consensus( 34 struct consensus_cache_entry_t **entry_out, 35 consensus_flavor_t flavor, 36 enum compress_method_t method); 37 38 consdiff_status_t consdiffmgr_find_diff_from( 39 struct consensus_cache_entry_t **entry_out, 40 consensus_flavor_t flavor, 41 int digest_type, 42 const uint8_t *digest, 43 size_t digestlen, 44 enum compress_method_t method); 45 46 int consensus_cache_entry_get_voter_id_digests( 47 const struct consensus_cache_entry_t *ent, 48 smartlist_t *out); 49 int consensus_cache_entry_get_fresh_until( 50 const struct consensus_cache_entry_t *ent, 51 time_t *out); 52 int consensus_cache_entry_get_valid_until( 53 const struct consensus_cache_entry_t *ent, 54 time_t *out); 55 int consensus_cache_entry_get_valid_after( 56 const struct consensus_cache_entry_t *ent, 57 time_t *out); 58 59 void consdiffmgr_rescan(void); 60 int consdiffmgr_cleanup(void); 61 void consdiffmgr_enable_background_compression(void); 62 void consdiffmgr_configure(const consdiff_cfg_t *cfg); 63 struct sandbox_cfg_elem_t; 64 int consdiffmgr_register_with_sandbox(struct sandbox_cfg_elem_t **cfg); 65 void consdiffmgr_free_all(void); 66 int consdiffmgr_validate(void); 67 68 #ifdef CONSDIFFMGR_PRIVATE 69 struct consensus_cache_t; 70 struct consensus_cache_entry_t; 71 STATIC unsigned n_diff_compression_methods(void); 72 STATIC unsigned n_consensus_compression_methods(void); 73 STATIC struct consensus_cache_t *cdm_cache_get(void); 74 STATIC struct consensus_cache_entry_t *cdm_cache_lookup_consensus( 75 consensus_flavor_t flavor, time_t valid_after); 76 STATIC int cdm_entry_get_sha3_value(uint8_t *digest_out, 77 struct consensus_cache_entry_t *ent, 78 const char *label); 79 STATIC int uncompress_or_set_ptr(const char **out, size_t *outlen, 80 char **owned_out, 81 struct consensus_cache_entry_t *ent); 82 #endif /* defined(CONSDIFFMGR_PRIVATE) */ 83 84 #ifdef TOR_UNIT_TESTS 85 int consdiffmgr_add_consensus_nulterm(const char *consensus, 86 const networkstatus_t *as_parsed); 87 #endif 88 89 #endif /* !defined(TOR_CONSDIFFMGR_H) */