summaryrefslogtreecommitdiff
path: root/src/or/consdiff.h
blob: 7797067f321516f25088535b8c88a82e41b6758a (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) 2014, Daniel Martí
 * Copyright (c) 2014, The Tor Project, Inc. */
/* See LICENSE for licensing information */

#ifndef TOR_CONSDIFF_H
#define TOR_CONSDIFF_H

#include "or.h"

char *consensus_diff_generate(const char *cons1,
                              const char *cons2);
char *consensus_diff_apply(const char *consensus,
                           const char *diff);

#ifdef CONSDIFF_PRIVATE
typedef struct consensus_digest_t {
  uint8_t sha3_256[DIGEST256_LEN];
} consensus_digest_t;

STATIC smartlist_t *consdiff_gen_diff(const smartlist_t *cons1,
                                      const smartlist_t *cons2,
                                      const consensus_digest_t *digests1,
                                      const consensus_digest_t *digests2);
STATIC char *consdiff_apply_diff(const smartlist_t *cons1,
                                 const smartlist_t *diff,
                                 const consensus_digest_t *digests1);
STATIC int consdiff_get_digests(const smartlist_t *diff,
                                char *digest1_out,
                                char *digest2_out);

/** Data structure to define a slice of a smarltist. */
typedef struct smartlist_slice_t {
  /**
   * Smartlist that this slice is made from.
   * References the whole original smartlist that the slice was made out of.
   * */
  const smartlist_t *list;
  /** Starting position of the slice in the smartlist. */
  int offset;
  /** Length of the slice, i.e. the number of elements it holds. */
  int len;
} smartlist_slice_t;
STATIC smartlist_t *gen_ed_diff(const smartlist_t *cons1,
                                const smartlist_t *cons2);
STATIC smartlist_t *apply_ed_diff(const smartlist_t *cons1,
                                  const smartlist_t *diff,
                                  int start_line);
STATIC void calc_changes(smartlist_slice_t *slice1, smartlist_slice_t *slice2,
                         bitarray_t *changed1, bitarray_t *changed2);
STATIC smartlist_slice_t *smartlist_slice(const smartlist_t *list,
                                          int start, int end);
STATIC int next_router(const smartlist_t *cons, int cur);
STATIC int *lcs_lengths(const smartlist_slice_t *slice1,
                        const smartlist_slice_t *slice2,
                        int direction);
STATIC void trim_slices(smartlist_slice_t *slice1, smartlist_slice_t *slice2);
STATIC int base64cmp(const char *hash1, const char *hash2);
STATIC const char *get_id_hash(const char *r_line);
STATIC int is_valid_router_entry(const char *line);
STATIC int smartlist_slice_string_pos(const smartlist_slice_t *slice,
                                      const char *string);
STATIC void set_changed(bitarray_t *changed1, bitarray_t *changed2,
                        const smartlist_slice_t *slice1,
                        const smartlist_slice_t *slice2);

MOCK_DECL(STATIC int,
          consensus_compute_digest,(const char *cons,
                                    consensus_digest_t *digest_out));
MOCK_DECL(STATIC int,
          consensus_digest_eq,(const uint8_t *d1,
                               const uint8_t *d2));
#endif

#endif