aboutsummaryrefslogtreecommitdiff
path: root/src/feature/dircache/consdiffmgr.h
blob: 39e8fa31cb518fab302a750db095192926651a76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Copyright (c) 2017-2019, The Tor Project, Inc. */
/* See LICENSE for licensing information */

#ifndef TOR_CONSDIFFMGR_H
#define TOR_CONSDIFFMGR_H

enum compress_method_t;

/**
 * Possible outcomes from trying to look up a given consensus diff.
 */
typedef enum consdiff_status_t {
  CONSDIFF_AVAILABLE,
  CONSDIFF_NOT_FOUND,
  CONSDIFF_IN_PROGRESS,
} consdiff_status_t;

typedef struct consdiff_cfg_t {
  int32_t cache_max_num;
} consdiff_cfg_t;

struct consensus_cache_entry_t; // from conscache.h

int consdiffmgr_add_consensus(const char *consensus,
                              const networkstatus_t *as_parsed);

consdiff_status_t consdiffmgr_find_consensus(
                           struct consensus_cache_entry_t **entry_out,
                           consensus_flavor_t flavor,
                           enum compress_method_t method);

consdiff_status_t consdiffmgr_find_diff_from(
                           struct consensus_cache_entry_t **entry_out,
                           consensus_flavor_t flavor,
                           int digest_type,
                           const uint8_t *digest,
                           size_t digestlen,
                           enum compress_method_t method);

int consensus_cache_entry_get_voter_id_digests(
                                  const struct consensus_cache_entry_t *ent,
                                  smartlist_t *out);
int consensus_cache_entry_get_fresh_until(
                                  const struct consensus_cache_entry_t *ent,
                                  time_t *out);
int consensus_cache_entry_get_valid_until(
                                  const struct consensus_cache_entry_t *ent,
                                  time_t *out);
int consensus_cache_entry_get_valid_after(
                                  const struct consensus_cache_entry_t *ent,
                                  time_t *out);

void consdiffmgr_rescan(void);
int consdiffmgr_cleanup(void);
void consdiffmgr_enable_background_compression(void);
void consdiffmgr_configure(const consdiff_cfg_t *cfg);
struct sandbox_cfg_elem;
int consdiffmgr_register_with_sandbox(struct sandbox_cfg_elem **cfg);
void consdiffmgr_free_all(void);
int consdiffmgr_validate(void);

#ifdef CONSDIFFMGR_PRIVATE
STATIC unsigned n_diff_compression_methods(void);
STATIC unsigned n_consensus_compression_methods(void);
STATIC consensus_cache_t *cdm_cache_get(void);
STATIC consensus_cache_entry_t *cdm_cache_lookup_consensus(
                          consensus_flavor_t flavor, time_t valid_after);
STATIC int cdm_entry_get_sha3_value(uint8_t *digest_out,
                                    consensus_cache_entry_t *ent,
                                    const char *label);
STATIC int uncompress_or_copy(char **out, size_t *outlen,
                              consensus_cache_entry_t *ent);
#endif /* defined(CONSDIFFMGR_PRIVATE) */

#endif /* !defined(TOR_CONSDIFFMGR_H) */