minor updates on upcoming changelog
[tor.git] / src / or / consdiff.h
blobeb772c0b2b6966fd7563659b5a53f1b89cf24668
1 /* Copyright (c) 2014, Daniel Martí
2 * Copyright (c) 2014, The Tor Project, Inc. */
3 /* See LICENSE for licensing information */
5 #ifndef TOR_CONSDIFF_H
6 #define TOR_CONSDIFF_H
8 #include "or.h"
10 char *consensus_diff_generate(const char *cons1,
11 const char *cons2);
12 char *consensus_diff_apply(const char *consensus,
13 const char *diff);
15 int looks_like_a_consensus_diff(const char *document, size_t len);
17 #ifdef CONSDIFF_PRIVATE
18 struct memarea_t;
20 /** Line type used for constructing consensus diffs. Each of these lines
21 * refers to a chunk of memory allocated elsewhere, and is not necessarily
22 * NUL-terminated: this helps us avoid copies and save memory. */
23 typedef struct cdline_t {
24 const char *s;
25 uint32_t len;
26 } cdline_t;
28 typedef struct consensus_digest_t {
29 uint8_t sha3_256[DIGEST256_LEN];
30 } consensus_digest_t;
32 STATIC smartlist_t *consdiff_gen_diff(const smartlist_t *cons1,
33 const smartlist_t *cons2,
34 const consensus_digest_t *digests1,
35 const consensus_digest_t *digests2,
36 struct memarea_t *area);
37 STATIC char *consdiff_apply_diff(const smartlist_t *cons1,
38 const smartlist_t *diff,
39 const consensus_digest_t *digests1);
40 STATIC int consdiff_get_digests(const smartlist_t *diff,
41 char *digest1_out,
42 char *digest2_out);
44 /** Data structure to define a slice of a smarltist. */
45 typedef struct smartlist_slice_t {
46 /**
47 * Smartlist that this slice is made from.
48 * References the whole original smartlist that the slice was made out of.
49 * */
50 const smartlist_t *list;
51 /** Starting position of the slice in the smartlist. */
52 int offset;
53 /** Length of the slice, i.e. the number of elements it holds. */
54 int len;
55 } smartlist_slice_t;
56 STATIC smartlist_t *gen_ed_diff(const smartlist_t *cons1,
57 const smartlist_t *cons2,
58 struct memarea_t *area);
59 STATIC smartlist_t *apply_ed_diff(const smartlist_t *cons1,
60 const smartlist_t *diff,
61 int start_line);
62 STATIC void calc_changes(smartlist_slice_t *slice1, smartlist_slice_t *slice2,
63 bitarray_t *changed1, bitarray_t *changed2);
64 STATIC smartlist_slice_t *smartlist_slice(const smartlist_t *list,
65 int start, int end);
66 STATIC int next_router(const smartlist_t *cons, int cur);
67 STATIC int *lcs_lengths(const smartlist_slice_t *slice1,
68 const smartlist_slice_t *slice2,
69 int direction);
70 STATIC void trim_slices(smartlist_slice_t *slice1, smartlist_slice_t *slice2);
71 STATIC int base64cmp(const cdline_t *hash1, const cdline_t *hash2);
72 STATIC int get_id_hash(const cdline_t *line, cdline_t *hash_out);
73 STATIC int is_valid_router_entry(const cdline_t *line);
74 STATIC int smartlist_slice_string_pos(const smartlist_slice_t *slice,
75 const cdline_t *string);
76 STATIC void set_changed(bitarray_t *changed1, bitarray_t *changed2,
77 const smartlist_slice_t *slice1,
78 const smartlist_slice_t *slice2);
79 STATIC int consensus_split_lines(smartlist_t *out, const char *s,
80 struct memarea_t *area);
81 STATIC void smartlist_add_linecpy(smartlist_t *lst, struct memarea_t *area,
82 const char *s);
83 STATIC int lines_eq(const cdline_t *a, const cdline_t *b);
84 STATIC int line_str_eq(const cdline_t *a, const char *b);
86 MOCK_DECL(STATIC int,
87 consensus_compute_digest,(const char *cons,
88 consensus_digest_t *digest_out));
89 MOCK_DECL(STATIC int,
90 consensus_compute_digest_as_signed,(const char *cons,
91 consensus_digest_t *digest_out));
92 MOCK_DECL(STATIC int,
93 consensus_digest_eq,(const uint8_t *d1,
94 const uint8_t *d2));
95 #endif /* defined(CONSDIFF_PRIVATE) */
97 #endif /* !defined(TOR_CONSDIFF_H) */