consdiff.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright (c) 2014, Daniel Martí
  2. * Copyright (c) 2014, The Tor Project, Inc. */
  3. /* See LICENSE for licensing information */
  4. #ifndef TOR_CONSDIFF_H
  5. #define TOR_CONSDIFF_H
  6. #include "or.h"
  7. typedef struct consensus_digest_t {
  8. uint8_t sha3_256[DIGEST256_LEN];
  9. } consensus_digest_t;
  10. smartlist_t *consdiff_gen_diff(smartlist_t *cons1, smartlist_t *cons2,
  11. consensus_digest_t *digests1, consensus_digest_t *digests2);
  12. char *consdiff_apply_diff(smartlist_t *cons1, smartlist_t *diff,
  13. consensus_digest_t *digests1);
  14. int consdiff_get_digests(smartlist_t *diff,
  15. char *digest1_out,
  16. char *digest2_out);
  17. #ifdef CONSDIFF_PRIVATE
  18. /** Data structure to define a slice of a smarltist. */
  19. typedef struct smartlist_slice_t {
  20. /**
  21. * Smartlist that this slice is made from.
  22. * References the whole original smartlist that the slice was made out of.
  23. * */
  24. smartlist_t *list;
  25. /** Starting position of the slice in the smartlist. */
  26. int offset;
  27. /** Length of the slice, i.e. the number of elements it holds. */
  28. int len;
  29. } smartlist_slice_t;
  30. STATIC smartlist_t *gen_ed_diff(smartlist_t *cons1, smartlist_t *cons2);
  31. STATIC smartlist_t *apply_ed_diff(smartlist_t *cons1, smartlist_t *diff);
  32. STATIC void calc_changes(smartlist_slice_t *slice1, smartlist_slice_t *slice2,
  33. bitarray_t *changed1, bitarray_t *changed2);
  34. STATIC smartlist_slice_t *smartlist_slice(smartlist_t *list,
  35. int start, int end);
  36. STATIC int next_router(smartlist_t *cons, int cur);
  37. STATIC int *lcs_lengths(smartlist_slice_t *slice1, smartlist_slice_t *slice2,
  38. int direction);
  39. STATIC void trim_slices(smartlist_slice_t *slice1, smartlist_slice_t *slice2);
  40. STATIC int base64cmp(const char *hash1, const char *hash2);
  41. STATIC const char *get_id_hash(const char *r_line);
  42. STATIC int is_valid_router_entry(const char *line);
  43. STATIC int smartlist_slice_string_pos(smartlist_slice_t *slice,
  44. const char *string);
  45. STATIC void set_changed(bitarray_t *changed1, bitarray_t *changed2,
  46. smartlist_slice_t *slice1, smartlist_slice_t *slice2);
  47. STATIC int consensus_compute_digest(const char *cons,
  48. consensus_digest_t *digest_out);
  49. #endif
  50. #endif