tor  0.4.1.0-alpha-dev
consdiff.h
1 /* Copyright (c) 2014, Daniel Martí
2  * Copyright (c) 2014-2019, The Tor Project, Inc. */
3 /* See LICENSE for licensing information */
4 
5 #ifndef TOR_CONSDIFF_H
6 #define TOR_CONSDIFF_H
7 
8 #include "core/or/or.h"
9 
10 char *consensus_diff_generate(const char *cons1, size_t cons1len,
11  const char *cons2, size_t cons2len);
12 char *consensus_diff_apply(const char *consensus, size_t consensus_len,
13  const char *diff, size_t diff_len);
14 
15 int looks_like_a_consensus_diff(const char *document, size_t len);
16 
17 #ifdef CONSDIFF_PRIVATE
18 #include "lib/container/bitarray.h"
19 
20 struct memarea_t;
21 
25 typedef struct cdline_t {
26  const char *s;
27  uint32_t len;
28 } cdline_t;
29 
30 typedef struct consensus_digest_t {
31  uint8_t sha3_256[DIGEST256_LEN];
32 } consensus_digest_t;
33 
34 STATIC smartlist_t *consdiff_gen_diff(const smartlist_t *cons1,
35  const smartlist_t *cons2,
36  const consensus_digest_t *digests1,
37  const consensus_digest_t *digests2,
38  struct memarea_t *area);
39 STATIC char *consdiff_apply_diff(const smartlist_t *cons1,
40  const smartlist_t *diff,
41  const consensus_digest_t *digests1);
42 STATIC int consdiff_get_digests(const smartlist_t *diff,
43  char *digest1_out,
44  char *digest2_out);
45 
47 typedef struct smartlist_slice_t {
52  const smartlist_t *list;
54  int offset;
56  int len;
57 } smartlist_slice_t;
58 STATIC smartlist_t *gen_ed_diff(const smartlist_t *cons1,
59  const smartlist_t *cons2,
60  struct memarea_t *area);
61 STATIC smartlist_t *apply_ed_diff(const smartlist_t *cons1,
62  const smartlist_t *diff,
63  int start_line);
64 STATIC void calc_changes(smartlist_slice_t *slice1, smartlist_slice_t *slice2,
65  bitarray_t *changed1, bitarray_t *changed2);
66 STATIC smartlist_slice_t *smartlist_slice(const smartlist_t *list,
67  int start, int end);
68 STATIC int next_router(const smartlist_t *cons, int cur);
69 STATIC int *lcs_lengths(const smartlist_slice_t *slice1,
70  const smartlist_slice_t *slice2,
71  int direction);
72 STATIC void trim_slices(smartlist_slice_t *slice1, smartlist_slice_t *slice2);
73 STATIC int base64cmp(const cdline_t *hash1, const cdline_t *hash2);
74 STATIC int get_id_hash(const cdline_t *line, cdline_t *hash_out);
75 STATIC int is_valid_router_entry(const cdline_t *line);
76 STATIC int smartlist_slice_string_pos(const smartlist_slice_t *slice,
77  const cdline_t *string);
78 STATIC void set_changed(bitarray_t *changed1, bitarray_t *changed2,
79  const smartlist_slice_t *slice1,
80  const smartlist_slice_t *slice2);
81 STATIC int consensus_split_lines(smartlist_t *out,
82  const char *s, size_t len,
83  struct memarea_t *area);
84 STATIC void smartlist_add_linecpy(smartlist_t *lst, struct memarea_t *area,
85  const char *s);
86 STATIC int lines_eq(const cdline_t *a, const cdline_t *b);
87 STATIC int line_str_eq(const cdline_t *a, const char *b);
88 
89 MOCK_DECL(STATIC int,
90  consensus_compute_digest,(const char *cons, size_t len,
91  consensus_digest_t *digest_out));
92 MOCK_DECL(STATIC int,
93  consensus_compute_digest_as_signed,(const char *cons, size_t len,
94  consensus_digest_t *digest_out));
95 MOCK_DECL(STATIC int,
96  consensus_digest_eq,(const uint8_t *d1,
97  const uint8_t *d2));
98 #endif /* defined(CONSDIFF_PRIVATE) */
99 
100 #endif /* !defined(TOR_CONSDIFF_H) */
STATIC int is_valid_router_entry(const cdline_t *line)
Definition: consdiff.c:435
STATIC int smartlist_slice_string_pos(const smartlist_slice_t *slice, const cdline_t *string)
Definition: consdiff.c:245
unsigned int bitarray_t
Definition: bitarray.h:30
STATIC void set_changed(bitarray_t *changed1, bitarray_t *changed2, const smartlist_slice_t *slice1, const smartlist_slice_t *slice2)
Definition: consdiff.c:264
STATIC void calc_changes(smartlist_slice_t *slice1, smartlist_slice_t *slice2, bitarray_t *changed1, bitarray_t *changed2)
Definition: consdiff.c:327
char * consdiff_apply_diff(const smartlist_t *cons1, const smartlist_t *diff, const consensus_digest_t *digests1)
Definition: consdiff.c:1190
Implements a variable-sized (but non-resizeable) bit-array.
STATIC smartlist_t * apply_ed_diff(const smartlist_t *cons1, const smartlist_t *diff, int diff_starting_line)
Definition: consdiff.c:857
char * consensus_diff_generate(const char *cons1, size_t cons1len, const char *cons2, size_t cons2len)
Definition: consdiff.c:1339
STATIC int next_router(const smartlist_t *cons, int cur)
Definition: consdiff.c:449
STATIC void trim_slices(smartlist_slice_t *slice1, smartlist_slice_t *slice2)
Definition: consdiff.c:213
#define DIGEST256_LEN
Definition: digest_sizes.h:23
STATIC int get_id_hash(const cdline_t *line, cdline_t *hash_out)
Definition: consdiff.c:395
Master header file for Tor-specific functionality.
STATIC smartlist_t * gen_ed_diff(const smartlist_t *cons1_orig, const smartlist_t *cons2, memarea_t *area)
Definition: consdiff.c:623
int consdiff_get_digests(const smartlist_t *diff, char *digest1_out, char *digest2_out)
Definition: consdiff.c:1104
STATIC int consensus_split_lines(smartlist_t *out, const char *s, size_t len, memarea_t *area)
Definition: consdiff.c:1287
STATIC smartlist_slice_t * smartlist_slice(const smartlist_t *list, int start, int end)
Definition: consdiff.c:140
STATIC int line_str_eq(const cdline_t *a, const char *b)
Definition: consdiff.c:60
STATIC int base64cmp(const cdline_t *hash1, const cdline_t *hash2)
Definition: consdiff.c:472
STATIC int * lcs_lengths(const smartlist_slice_t *slice1, const smartlist_slice_t *slice2, int direction)
Definition: consdiff.c:165
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
char * consensus_diff_apply(const char *consensus, size_t consensus_len, const char *diff, size_t diff_len)
Definition: consdiff.c:1379
STATIC int lines_eq(const cdline_t *a, const cdline_t *b)
Definition: consdiff.c:53
int looks_like_a_consensus_diff(const char *document, size_t len)
Definition: consdiff.c:1414
STATIC void smartlist_add_linecpy(smartlist_t *lst, memarea_t *area, const char *s)
Definition: consdiff.c:94
smartlist_t * consdiff_gen_diff(const smartlist_t *cons1, const smartlist_t *cons2, const consensus_digest_t *digests1, const consensus_digest_t *digests2, memarea_t *area)
Definition: consdiff.c:1024