rephist.h 5.9 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-2017, 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_note_connect_failed(const char* nickname, time_t when);
  14. void rep_hist_note_connect_succeeded(const char* nickname, time_t when);
  15. void rep_hist_note_disconnect(const char* nickname, time_t when);
  16. void rep_hist_note_connection_died(const char* nickname, time_t when);
  17. void rep_hist_note_extend_succeeded(const char *from_name,
  18. const char *to_name);
  19. void rep_hist_note_extend_failed(const char *from_name, const char *to_name);
  20. void rep_hist_dump_stats(time_t now, int severity);
  21. void rep_hist_note_bytes_read(size_t num_bytes, time_t when);
  22. void rep_hist_note_bytes_written(size_t num_bytes, time_t when);
  23. void rep_hist_make_router_pessimal(const char *id, time_t when);
  24. void rep_hist_note_dir_bytes_read(size_t num_bytes, time_t when);
  25. void rep_hist_note_dir_bytes_written(size_t num_bytes, time_t when);
  26. int rep_hist_bandwidth_assess(void);
  27. char *rep_hist_get_bandwidth_lines(void);
  28. void rep_hist_update_state(or_state_t *state);
  29. int rep_hist_load_state(or_state_t *state, char **err);
  30. void rep_history_clean(time_t before);
  31. void rep_hist_note_router_reachable(const char *id, const tor_addr_t *at_addr,
  32. const uint16_t at_port, time_t when);
  33. void rep_hist_note_router_unreachable(const char *id, time_t when);
  34. int rep_hist_record_mtbf_data(time_t now, int missing_means_down);
  35. int rep_hist_load_mtbf_data(time_t now);
  36. time_t rep_hist_downrate_old_runs(time_t now);
  37. long rep_hist_get_uptime(const char *id, time_t when);
  38. double rep_hist_get_stability(const char *id, time_t when);
  39. double rep_hist_get_weighted_fractional_uptime(const char *id, time_t when);
  40. long rep_hist_get_weighted_time_known(const char *id, time_t when);
  41. int rep_hist_have_measured_enough_stability(void);
  42. void predicted_ports_init(void);
  43. void rep_hist_note_used_port(time_t now, uint16_t port);
  44. smartlist_t *rep_hist_get_predicted_ports(time_t now);
  45. void rep_hist_remove_predicted_ports(const smartlist_t *rmv_ports);
  46. void rep_hist_note_used_resolve(time_t now);
  47. void rep_hist_note_used_internal(time_t now, int need_uptime,
  48. int need_capacity);
  49. int rep_hist_get_predicted_internal(time_t now, int *need_uptime,
  50. int *need_capacity);
  51. int any_predicted_circuits(time_t now);
  52. int rep_hist_circbuilding_dormant(time_t now);
  53. int predicted_ports_prediction_time_remaining(time_t now);
  54. void rep_hist_exit_stats_init(time_t now);
  55. void rep_hist_reset_exit_stats(time_t now);
  56. void rep_hist_exit_stats_term(void);
  57. char *rep_hist_format_exit_stats(time_t now);
  58. time_t rep_hist_exit_stats_write(time_t now);
  59. void rep_hist_note_exit_bytes(uint16_t port, size_t num_written,
  60. size_t num_read);
  61. void rep_hist_note_exit_stream_opened(uint16_t port);
  62. void rep_hist_buffer_stats_init(time_t now);
  63. void rep_hist_buffer_stats_add_circ(circuit_t *circ,
  64. time_t end_of_interval);
  65. time_t rep_hist_buffer_stats_write(time_t now);
  66. void rep_hist_buffer_stats_term(void);
  67. void rep_hist_add_buffer_stats(double mean_num_cells_in_queue,
  68. double mean_time_cells_in_queue, uint32_t processed_cells);
  69. char *rep_hist_format_buffer_stats(time_t now);
  70. void rep_hist_reset_buffer_stats(time_t now);
  71. void rep_hist_desc_stats_init(time_t now);
  72. void rep_hist_note_desc_served(const char * desc);
  73. void rep_hist_desc_stats_term(void);
  74. time_t rep_hist_desc_stats_write(time_t now);
  75. void rep_hist_conn_stats_init(time_t now);
  76. void rep_hist_note_or_conn_bytes(uint64_t conn_id, size_t num_read,
  77. size_t num_written, time_t when);
  78. void rep_hist_reset_conn_stats(time_t now);
  79. char *rep_hist_format_conn_stats(time_t now);
  80. time_t rep_hist_conn_stats_write(time_t now);
  81. void rep_hist_conn_stats_term(void);
  82. void rep_hist_note_circuit_handshake_requested(uint16_t type);
  83. void rep_hist_note_circuit_handshake_assigned(uint16_t type);
  84. void rep_hist_log_circuit_handshake_stats(time_t now);
  85. void rep_hist_hs_stats_init(time_t now);
  86. void rep_hist_hs_stats_term(void);
  87. time_t rep_hist_hs_stats_write(time_t now);
  88. char *rep_hist_get_hs_stats_string(void);
  89. void rep_hist_seen_new_rp_cell(void);
  90. void rep_hist_stored_maybe_new_hs(const crypto_pk_t *pubkey);
  91. void rep_hist_free_all(void);
  92. void rep_hist_note_negotiated_link_proto(unsigned link_proto,
  93. int started_here);
  94. void rep_hist_log_link_protocol_counts(void);
  95. extern uint64_t rephist_total_alloc;
  96. extern uint32_t rephist_total_num;
  97. #ifdef TOR_UNIT_TESTS
  98. extern int onion_handshakes_requested[MAX_ONION_HANDSHAKE_TYPE+1];
  99. extern int onion_handshakes_assigned[MAX_ONION_HANDSHAKE_TYPE+1];
  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