2017-03-07 15:58:30 +01:00
|
|
|
/* Copyright (c) 2014, Daniel Martí
|
2018-06-20 14:13:28 +02:00
|
|
|
* Copyright (c) 2014-2018, The Tor Project, Inc. */
|
2017-03-07 15:58:30 +01:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
#ifndef TOR_CONSDIFF_H
|
|
|
|
#define TOR_CONSDIFF_H
|
|
|
|
|
2018-07-05 22:34:59 +02:00
|
|
|
#include "core/or/or.h"
|
2017-03-07 15:58:30 +01:00
|
|
|
|
2017-03-07 19:45:32 +01:00
|
|
|
char *consensus_diff_generate(const char *cons1,
|
|
|
|
const char *cons2);
|
|
|
|
char *consensus_diff_apply(const char *consensus,
|
|
|
|
const char *diff);
|
|
|
|
|
2017-05-03 21:08:59 +02:00
|
|
|
int looks_like_a_consensus_diff(const char *document, size_t len);
|
|
|
|
|
2017-03-07 19:45:32 +01:00
|
|
|
#ifdef CONSDIFF_PRIVATE
|
2018-06-21 22:48:54 +02:00
|
|
|
#include "lib/container/bitarray.h"
|
|
|
|
|
2017-03-14 20:00:39 +01:00
|
|
|
struct memarea_t;
|
|
|
|
|
|
|
|
/** Line type used for constructing consensus diffs. Each of these lines
|
|
|
|
* refers to a chunk of memory allocated elsewhere, and is not necessarily
|
|
|
|
* NUL-terminated: this helps us avoid copies and save memory. */
|
|
|
|
typedef struct cdline_t {
|
|
|
|
const char *s;
|
|
|
|
uint32_t len;
|
|
|
|
} cdline_t;
|
|
|
|
|
2017-03-07 19:02:00 +01:00
|
|
|
typedef struct consensus_digest_t {
|
|
|
|
uint8_t sha3_256[DIGEST256_LEN];
|
|
|
|
} consensus_digest_t;
|
|
|
|
|
2017-03-07 19:45:32 +01:00
|
|
|
STATIC smartlist_t *consdiff_gen_diff(const smartlist_t *cons1,
|
|
|
|
const smartlist_t *cons2,
|
|
|
|
const consensus_digest_t *digests1,
|
2017-03-14 20:00:39 +01:00
|
|
|
const consensus_digest_t *digests2,
|
|
|
|
struct memarea_t *area);
|
2017-03-07 19:45:32 +01:00
|
|
|
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);
|
2017-03-07 15:58:30 +01:00
|
|
|
|
2017-03-07 16:22:00 +01:00
|
|
|
/** 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.
|
|
|
|
* */
|
2017-03-07 19:11:38 +01:00
|
|
|
const smartlist_t *list;
|
2017-03-07 16:22:00 +01:00
|
|
|
/** 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;
|
2017-03-07 19:11:38 +01:00
|
|
|
STATIC smartlist_t *gen_ed_diff(const smartlist_t *cons1,
|
2017-03-14 20:00:39 +01:00
|
|
|
const smartlist_t *cons2,
|
|
|
|
struct memarea_t *area);
|
2017-03-07 19:11:38 +01:00
|
|
|
STATIC smartlist_t *apply_ed_diff(const smartlist_t *cons1,
|
2017-03-07 19:15:43 +01:00
|
|
|
const smartlist_t *diff,
|
|
|
|
int start_line);
|
2017-03-07 16:22:00 +01:00
|
|
|
STATIC void calc_changes(smartlist_slice_t *slice1, smartlist_slice_t *slice2,
|
|
|
|
bitarray_t *changed1, bitarray_t *changed2);
|
2017-03-07 19:11:38 +01:00
|
|
|
STATIC smartlist_slice_t *smartlist_slice(const smartlist_t *list,
|
2017-03-07 16:22:00 +01:00
|
|
|
int start, int end);
|
2017-03-07 19:11:38 +01:00
|
|
|
STATIC int next_router(const smartlist_t *cons, int cur);
|
|
|
|
STATIC int *lcs_lengths(const smartlist_slice_t *slice1,
|
|
|
|
const smartlist_slice_t *slice2,
|
2017-03-07 16:22:00 +01:00
|
|
|
int direction);
|
|
|
|
STATIC void trim_slices(smartlist_slice_t *slice1, smartlist_slice_t *slice2);
|
2017-03-14 20:00:39 +01:00
|
|
|
STATIC int base64cmp(const cdline_t *hash1, const cdline_t *hash2);
|
|
|
|
STATIC int get_id_hash(const cdline_t *line, cdline_t *hash_out);
|
|
|
|
STATIC int is_valid_router_entry(const cdline_t *line);
|
2017-03-07 19:11:38 +01:00
|
|
|
STATIC int smartlist_slice_string_pos(const smartlist_slice_t *slice,
|
2017-03-14 20:00:39 +01:00
|
|
|
const cdline_t *string);
|
2017-03-07 16:22:00 +01:00
|
|
|
STATIC void set_changed(bitarray_t *changed1, bitarray_t *changed2,
|
2017-03-07 19:11:38 +01:00
|
|
|
const smartlist_slice_t *slice1,
|
|
|
|
const smartlist_slice_t *slice2);
|
2017-03-14 20:00:39 +01:00
|
|
|
STATIC int consensus_split_lines(smartlist_t *out, const char *s,
|
|
|
|
struct memarea_t *area);
|
|
|
|
STATIC void smartlist_add_linecpy(smartlist_t *lst, struct memarea_t *area,
|
|
|
|
const char *s);
|
|
|
|
STATIC int lines_eq(const cdline_t *a, const cdline_t *b);
|
|
|
|
STATIC int line_str_eq(const cdline_t *a, const char *b);
|
2017-03-07 20:12:53 +01:00
|
|
|
|
|
|
|
MOCK_DECL(STATIC int,
|
|
|
|
consensus_compute_digest,(const char *cons,
|
|
|
|
consensus_digest_t *digest_out));
|
2017-05-03 17:48:08 +02:00
|
|
|
MOCK_DECL(STATIC int,
|
|
|
|
consensus_compute_digest_as_signed,(const char *cons,
|
|
|
|
consensus_digest_t *digest_out));
|
2017-03-07 20:12:53 +01:00
|
|
|
MOCK_DECL(STATIC int,
|
|
|
|
consensus_digest_eq,(const uint8_t *d1,
|
|
|
|
const uint8_t *d2));
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* defined(CONSDIFF_PRIVATE) */
|
2017-03-07 16:22:00 +01:00
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* !defined(TOR_CONSDIFF_H) */
|