1 /* Copyright (c) 2017-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
6 * @brief Header for consdiffmgr.c
9 #ifndef TOR_CONSDIFFMGR_H
10 #define TOR_CONSDIFFMGR_H
12 enum compress_method_t
;
15 * Possible outcomes from trying to look up a given consensus diff.
17 typedef enum consdiff_status_t
{
23 typedef struct consdiff_cfg_t
{
24 int32_t cache_max_num
;
27 struct consensus_cache_entry_t
; // from conscache.h
29 int consdiffmgr_add_consensus(const char *consensus
,
31 const networkstatus_t
*as_parsed
);
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
);
38 consdiff_status_t
consdiffmgr_find_diff_from(
39 struct consensus_cache_entry_t
**entry_out
,
40 consensus_flavor_t flavor
,
42 const uint8_t *digest
,
44 enum compress_method_t method
);
46 int consensus_cache_entry_get_voter_id_digests(
47 const struct consensus_cache_entry_t
*ent
,
49 int consensus_cache_entry_get_fresh_until(
50 const struct consensus_cache_entry_t
*ent
,
52 int consensus_cache_entry_get_valid_until(
53 const struct consensus_cache_entry_t
*ent
,
55 int consensus_cache_entry_get_valid_after(
56 const struct consensus_cache_entry_t
*ent
,
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);
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
,
79 STATIC
int uncompress_or_set_ptr(const char **out
, size_t *outlen
,
81 struct consensus_cache_entry_t
*ent
);
82 #endif /* defined(CONSDIFFMGR_PRIVATE) */
85 int consdiffmgr_add_consensus_nulterm(const char *consensus
,
86 const networkstatus_t
*as_parsed
);
89 #endif /* !defined(TOR_CONSDIFFMGR_H) */