bwauth.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file bwauth.h
  8. * \brief Header file for bwauth.c
  9. **/
  10. #ifndef TOR_BWAUTH_H
  11. #define TOR_BWAUTH_H
  12. /** Maximum allowable length of bandwidth headers in a bandwidth file */
  13. #define MAX_BW_FILE_HEADER_COUNT_IN_VOTE 50
  14. /** Terminatore that separates bandwidth file headers from bandwidth file
  15. * relay lines */
  16. #define BW_FILE_HEADERS_TERMINATOR "=====\n"
  17. int dirserv_read_measured_bandwidths(const char *from_file,
  18. smartlist_t *routerstatuses,
  19. smartlist_t *bw_file_headers);
  20. int dirserv_query_measured_bw_cache_kb(const char *node_id,
  21. long *bw_out,
  22. time_t *as_of_out);
  23. void dirserv_clear_measured_bw_cache(void);
  24. int dirserv_has_measured_bw(const char *node_id);
  25. int dirserv_get_measured_bw_cache_size(void);
  26. void dirserv_count_measured_bws(const smartlist_t *routers);
  27. int dirserv_get_last_n_measured_bws(void);
  28. uint32_t dirserv_get_credible_bandwidth_kb(const routerinfo_t *ri);
  29. #ifdef BWAUTH_PRIVATE
  30. typedef struct measured_bw_line_t {
  31. char node_id[DIGEST_LEN];
  32. char node_hex[MAX_HEX_NICKNAME_LEN+1];
  33. long int bw_kb;
  34. } measured_bw_line_t;
  35. /* Put the MAX_MEASUREMENT_AGE #define here so unit tests can see it */
  36. #define MAX_MEASUREMENT_AGE (3*24*60*60) /* 3 days */
  37. STATIC int measured_bw_line_parse(measured_bw_line_t *out, const char *line,
  38. int line_is_after_headers);
  39. STATIC int measured_bw_line_apply(measured_bw_line_t *parsed_line,
  40. smartlist_t *routerstatuses);
  41. STATIC void dirserv_cache_measured_bw(const measured_bw_line_t *parsed_line,
  42. time_t as_of);
  43. STATIC void dirserv_expire_measured_bw_cache(time_t now);
  44. #endif /* defined(BWAUTH_PRIVATE) */
  45. #endif