circuitstats.h 4.2 KB

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