rephist.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 rephist.h
  8. * \brief Header file for rephist.c.
  9. **/
  10. #ifndef TOR_REPHIST_H
  11. #define TOR_REPHIST_H
  12. void rep_hist_init(void);
  13. void rep_hist_dump_stats(time_t now, int severity);
  14. void rep_hist_note_bytes_read(uint64_t num_bytes, time_t when);
  15. void rep_hist_note_bytes_written(uint64_t num_bytes, time_t when);
  16. void rep_hist_make_router_pessimal(const char *id, time_t when);
  17. void rep_hist_note_dir_bytes_read(uint64_t num_bytes, time_t when);
  18. void rep_hist_note_dir_bytes_written(uint64_t num_bytes, time_t when);
  19. MOCK_DECL(int, rep_hist_bandwidth_assess, (void));
  20. char *rep_hist_get_bandwidth_lines(void);
  21. void rep_hist_update_state(or_state_t *state);
  22. int rep_hist_load_state(or_state_t *state, char **err);
  23. void rep_history_clean(time_t before);
  24. void rep_hist_note_router_reachable(const char *id, const tor_addr_t *at_addr,
  25. const uint16_t at_port, time_t when);
  26. void rep_hist_note_router_unreachable(const char *id, time_t when);
  27. int rep_hist_record_mtbf_data(time_t now, int missing_means_down);
  28. int rep_hist_load_mtbf_data(time_t now);
  29. time_t rep_hist_downrate_old_runs(time_t now);
  30. long rep_hist_get_uptime(const char *id, time_t when);
  31. double rep_hist_get_stability(const char *id, time_t when);
  32. double rep_hist_get_weighted_fractional_uptime(const char *id, time_t when);
  33. long rep_hist_get_weighted_time_known(const char *id, time_t when);
  34. int rep_hist_have_measured_enough_stability(void);
  35. void predicted_ports_init(void);
  36. void rep_hist_note_used_port(time_t now, uint16_t port);
  37. smartlist_t *rep_hist_get_predicted_ports(time_t now);
  38. void rep_hist_remove_predicted_ports(const smartlist_t *rmv_ports);
  39. void rep_hist_note_used_resolve(time_t now);
  40. void rep_hist_note_used_internal(time_t now, int need_uptime,
  41. int need_capacity);
  42. int rep_hist_get_predicted_internal(time_t now, int *need_uptime,
  43. int *need_capacity);
  44. int any_predicted_circuits(time_t now);
  45. int rep_hist_circbuilding_dormant(time_t now);
  46. int predicted_ports_prediction_time_remaining(time_t now);
  47. void rep_hist_exit_stats_init(time_t now);
  48. void rep_hist_reset_exit_stats(time_t now);
  49. void rep_hist_exit_stats_term(void);
  50. char *rep_hist_format_exit_stats(time_t now);
  51. time_t rep_hist_exit_stats_write(time_t now);
  52. void rep_hist_note_exit_bytes(uint16_t port, size_t num_written,
  53. size_t num_read);
  54. void rep_hist_note_exit_stream_opened(uint16_t port);
  55. void rep_hist_buffer_stats_init(time_t now);
  56. void rep_hist_buffer_stats_add_circ(circuit_t *circ,
  57. time_t end_of_interval);
  58. time_t rep_hist_buffer_stats_write(time_t now);
  59. void rep_hist_buffer_stats_term(void);
  60. void rep_hist_add_buffer_stats(double mean_num_cells_in_queue,
  61. double mean_time_cells_in_queue, uint32_t processed_cells);
  62. char *rep_hist_format_buffer_stats(time_t now);
  63. void rep_hist_reset_buffer_stats(time_t now);
  64. void rep_hist_desc_stats_init(time_t now);
  65. void rep_hist_note_desc_served(const char * desc);
  66. void rep_hist_desc_stats_term(void);
  67. time_t rep_hist_desc_stats_write(time_t now);
  68. void rep_hist_conn_stats_init(time_t now);
  69. void rep_hist_note_or_conn_bytes(uint64_t conn_id, size_t num_read,
  70. size_t num_written, time_t when);
  71. void rep_hist_reset_conn_stats(time_t now);
  72. char *rep_hist_format_conn_stats(time_t now);
  73. time_t rep_hist_conn_stats_write(time_t now);
  74. void rep_hist_conn_stats_term(void);
  75. void rep_hist_note_circuit_handshake_requested(uint16_t type);
  76. void rep_hist_note_circuit_handshake_assigned(uint16_t type);
  77. void rep_hist_log_circuit_handshake_stats(time_t now);
  78. void rep_hist_hs_stats_init(time_t now);
  79. void rep_hist_hs_stats_term(void);
  80. time_t rep_hist_hs_stats_write(time_t now);
  81. char *rep_hist_get_hs_stats_string(void);
  82. void rep_hist_seen_new_rp_cell(void);
  83. void rep_hist_stored_maybe_new_hs(const crypto_pk_t *pubkey);
  84. void rep_hist_free_all(void);
  85. void rep_hist_note_negotiated_link_proto(unsigned link_proto,
  86. int started_here);
  87. void rep_hist_log_link_protocol_counts(void);
  88. extern uint64_t rephist_total_alloc;
  89. extern uint32_t rephist_total_num;
  90. #ifdef TOR_UNIT_TESTS
  91. extern int onion_handshakes_requested[MAX_ONION_HANDSHAKE_TYPE+1];
  92. extern int onion_handshakes_assigned[MAX_ONION_HANDSHAKE_TYPE+1];
  93. extern struct bw_array_t *write_array;
  94. #endif
  95. #ifdef REPHIST_PRIVATE
  96. typedef struct bw_array_t bw_array_t;
  97. STATIC uint64_t find_largest_max(bw_array_t *b);
  98. STATIC void commit_max(bw_array_t *b);
  99. STATIC void advance_obs(bw_array_t *b);
  100. #endif
  101. /**
  102. * Represents the type of a cell for padding accounting
  103. */
  104. typedef enum padding_type_t {
  105. /** A RELAY_DROP cell */
  106. PADDING_TYPE_DROP,
  107. /** A CELL_PADDING cell */
  108. PADDING_TYPE_CELL,
  109. /** Total counts of padding and non-padding together */
  110. PADDING_TYPE_TOTAL,
  111. /** Total cell counts for all padding-enabled channels */
  112. PADDING_TYPE_ENABLED_TOTAL,
  113. /** CELL_PADDING counts for all padding-enabled channels */
  114. PADDING_TYPE_ENABLED_CELL
  115. } padding_type_t;
  116. /** The amount of time over which the padding cell counts were counted */
  117. #define REPHIST_CELL_PADDING_COUNTS_INTERVAL (24*60*60)
  118. void rep_hist_padding_count_read(padding_type_t type);
  119. void rep_hist_padding_count_write(padding_type_t type);
  120. char *rep_hist_get_padding_count_lines(void);
  121. void rep_hist_reset_padding_counts(void);
  122. void rep_hist_prep_published_padding_counts(time_t now);
  123. void rep_hist_padding_count_timers(uint64_t num_timers);
  124. #endif /* !defined(TOR_REPHIST_H) */