consdiff.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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(const smartlist_t *cons1,
  11. const smartlist_t *cons2,
  12. const consensus_digest_t *digests1,
  13. const consensus_digest_t *digests2);
  14. char *consdiff_apply_diff(const smartlist_t *cons1, const smartlist_t *diff,
  15. const consensus_digest_t *digests1);
  16. int consdiff_get_digests(const smartlist_t *diff,
  17. char *digest1_out,
  18. char *digest2_out);
  19. #ifdef CONSDIFF_PRIVATE
  20. /** Data structure to define a slice of a smarltist. */
  21. typedef struct smartlist_slice_t {
  22. /**
  23. * Smartlist that this slice is made from.
  24. * References the whole original smartlist that the slice was made out of.
  25. * */
  26. const smartlist_t *list;
  27. /** Starting position of the slice in the smartlist. */
  28. int offset;
  29. /** Length of the slice, i.e. the number of elements it holds. */
  30. int len;
  31. } smartlist_slice_t;
  32. STATIC smartlist_t *gen_ed_diff(const smartlist_t *cons1,
  33. const smartlist_t *cons2);
  34. STATIC smartlist_t *apply_ed_diff(const smartlist_t *cons1,
  35. const smartlist_t *diff);
  36. STATIC void calc_changes(smartlist_slice_t *slice1, smartlist_slice_t *slice2,
  37. bitarray_t *changed1, bitarray_t *changed2);
  38. STATIC smartlist_slice_t *smartlist_slice(const smartlist_t *list,
  39. int start, int end);
  40. STATIC int next_router(const smartlist_t *cons, int cur);
  41. STATIC int *lcs_lengths(const smartlist_slice_t *slice1,
  42. const smartlist_slice_t *slice2,
  43. int direction);
  44. STATIC void trim_slices(smartlist_slice_t *slice1, smartlist_slice_t *slice2);
  45. STATIC int base64cmp(const char *hash1, const char *hash2);
  46. STATIC const char *get_id_hash(const char *r_line);
  47. STATIC int is_valid_router_entry(const char *line);
  48. STATIC int smartlist_slice_string_pos(const smartlist_slice_t *slice,
  49. const char *string);
  50. STATIC void set_changed(bitarray_t *changed1, bitarray_t *changed2,
  51. const smartlist_slice_t *slice1,
  52. const smartlist_slice_t *slice2);
  53. STATIC int consensus_compute_digest(const char *cons,
  54. consensus_digest_t *digest_out);
  55. #endif
  56. #endif