circuitstats.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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-2017, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file circuitstats.h
  8. * \brief Header file for circuitstats.c
  9. **/
  10. #ifndef TOR_CIRCUITSTATS_H
  11. #define TOR_CIRCUITSTATS_H
  12. const circuit_build_times_t *get_circuit_build_times(void);
  13. circuit_build_times_t *get_circuit_build_times_mutable(void);
  14. double get_circuit_build_close_time_ms(void);
  15. double get_circuit_build_timeout_ms(void);
  16. int circuit_build_times_disabled(const or_options_t *options);
  17. int circuit_build_times_disabled_(const or_options_t *options,
  18. int ignore_consensus);
  19. int circuit_build_times_enough_to_compute(const circuit_build_times_t *cbt);
  20. void circuit_build_times_update_state(const circuit_build_times_t *cbt,
  21. or_state_t *state);
  22. int circuit_build_times_parse_state(circuit_build_times_t *cbt,
  23. or_state_t *state);
  24. void circuit_build_times_count_timeout(circuit_build_times_t *cbt,
  25. int did_onehop);
  26. int circuit_build_times_count_close(circuit_build_times_t *cbt,
  27. int did_onehop, time_t start_time);
  28. void circuit_build_times_set_timeout(circuit_build_times_t *cbt);
  29. int circuit_build_times_add_time(circuit_build_times_t *cbt,
  30. build_time_t time);
  31. int circuit_build_times_needs_circuits(const circuit_build_times_t *cbt);
  32. int circuit_build_times_needs_circuits_now(const circuit_build_times_t *cbt);
  33. void circuit_build_times_init(circuit_build_times_t *cbt);
  34. void circuit_build_times_free_timeouts(circuit_build_times_t *cbt);
  35. void circuit_build_times_new_consensus_params(circuit_build_times_t *cbt,
  36. networkstatus_t *ns);
  37. double circuit_build_times_timeout_rate(const circuit_build_times_t *cbt);
  38. double circuit_build_times_close_rate(const circuit_build_times_t *cbt);
  39. void circuit_build_times_update_last_circ(circuit_build_times_t *cbt);
  40. #ifdef CIRCUITSTATS_PRIVATE
  41. STATIC double circuit_build_times_calculate_timeout(circuit_build_times_t *cbt,
  42. double quantile);
  43. STATIC int circuit_build_times_update_alpha(circuit_build_times_t *cbt);
  44. STATIC void circuit_build_times_reset(circuit_build_times_t *cbt);
  45. /* Network liveness functions */
  46. STATIC int circuit_build_times_network_check_changed(
  47. circuit_build_times_t *cbt);
  48. #endif /* defined(CIRCUITSTATS_PRIVATE) */
  49. #ifdef TOR_UNIT_TESTS
  50. build_time_t circuit_build_times_generate_sample(circuit_build_times_t *cbt,
  51. double q_lo, double q_hi);
  52. double circuit_build_times_cdf(circuit_build_times_t *cbt, double x);
  53. void circuit_build_times_initial_alpha(circuit_build_times_t *cbt,
  54. double quantile, double time_ms);
  55. void circuitbuild_running_unit_tests(void);
  56. #endif /* defined(TOR_UNIT_TESTS) */
  57. /* Network liveness functions */
  58. void circuit_build_times_network_is_live(circuit_build_times_t *cbt);
  59. int circuit_build_times_network_check_live(const circuit_build_times_t *cbt);
  60. void circuit_build_times_network_circ_success(circuit_build_times_t *cbt);
  61. #ifdef CIRCUITSTATS_PRIVATE
  62. /** Structure for circuit build times history */
  63. struct circuit_build_times_s {
  64. /** The circular array of recorded build times in milliseconds */
  65. build_time_t circuit_build_times[CBT_NCIRCUITS_TO_OBSERVE];
  66. /** Current index in the circuit_build_times circular array */
  67. int build_times_idx;
  68. /** Total number of build times accumulated. Max CBT_NCIRCUITS_TO_OBSERVE */
  69. int total_build_times;
  70. /** Information about the state of our local network connection */
  71. network_liveness_t liveness;
  72. /** Last time we built a circuit. Used to decide to build new test circs */
  73. time_t last_circ_at;
  74. /** "Minimum" value of our pareto distribution (actually mode) */
  75. build_time_t Xm;
  76. /** alpha exponent for pareto dist. */
  77. double alpha;
  78. /** Have we computed a timeout? */
  79. int have_computed_timeout;
  80. /** The exact value for that timeout in milliseconds. Stored as a double
  81. * to maintain precision from calculations to and from quantile value. */
  82. double timeout_ms;
  83. /** How long we wait before actually closing the circuit. */
  84. double close_ms;
  85. };
  86. #endif /* defined(CIRCUITSTATS_PRIVATE) */
  87. #endif /* !defined(TOR_CIRCUITSTATS_H) */