consdiff.h 3.0 KB

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