consdiff.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. int start_line);
  37. STATIC void calc_changes(smartlist_slice_t *slice1, smartlist_slice_t *slice2,
  38. bitarray_t *changed1, bitarray_t *changed2);
  39. STATIC smartlist_slice_t *smartlist_slice(const smartlist_t *list,
  40. int start, int end);
  41. STATIC int next_router(const smartlist_t *cons, int cur);
  42. STATIC int *lcs_lengths(const smartlist_slice_t *slice1,
  43. const smartlist_slice_t *slice2,
  44. int direction);
  45. STATIC void trim_slices(smartlist_slice_t *slice1, smartlist_slice_t *slice2);
  46. STATIC int base64cmp(const char *hash1, const char *hash2);
  47. STATIC const char *get_id_hash(const char *r_line);
  48. STATIC int is_valid_router_entry(const char *line);
  49. STATIC int smartlist_slice_string_pos(const smartlist_slice_t *slice,
  50. const char *string);
  51. STATIC void set_changed(bitarray_t *changed1, bitarray_t *changed2,
  52. const smartlist_slice_t *slice1,
  53. const smartlist_slice_t *slice2);
  54. STATIC int consensus_compute_digest(const char *cons,
  55. consensus_digest_t *digest_out);
  56. #endif
  57. #endif