bwhist.h (1673B)
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-2021, The Tor Project, Inc. */ 5 /* See LICENSE for licensing information */ 6 7 /** 8 * @file bwhist.h 9 * @brief Header for feature/stats/bwhist.c 10 **/ 11 12 #ifndef TOR_FEATURE_STATS_BWHIST_H 13 #define TOR_FEATURE_STATS_BWHIST_H 14 15 void bwhist_init(void); 16 void bwhist_free_all(void); 17 18 void bwhist_note_bytes_read(uint64_t num_bytes, time_t when, bool ipv6); 19 void bwhist_note_bytes_written(uint64_t num_bytes, time_t when, bool ipv6); 20 void bwhist_note_dir_bytes_read(uint64_t num_bytes, time_t when); 21 void bwhist_note_dir_bytes_written(uint64_t num_bytes, time_t when); 22 23 MOCK_DECL(int, bwhist_bandwidth_assess, (void)); 24 char *bwhist_get_bandwidth_lines(void); 25 struct or_state_t; 26 void bwhist_update_state(struct or_state_t *state); 27 int bwhist_load_state(struct or_state_t *state, char **err); 28 29 #ifdef BWHIST_PRIVATE 30 typedef struct bw_array_t bw_array_t; 31 STATIC uint64_t find_largest_max(bw_array_t *b, int min_observation_time); 32 STATIC void commit_max(bw_array_t *b); 33 STATIC void advance_obs(bw_array_t *b); 34 STATIC bw_array_t *bw_array_new(void); 35 STATIC void add_obs(bw_array_t *b, time_t when, uint64_t n); 36 #define bw_array_free(val) \ 37 FREE_AND_NULL(bw_array_t, bw_array_free_, (val)) 38 STATIC void bw_array_free_(bw_array_t *b); 39 STATIC size_t bwhist_fill_bandwidth_history(char *buf, size_t len, 40 const bw_array_t *b); 41 #endif /* defined(BWHIST_PRIVATE) */ 42 43 #ifdef TOR_UNIT_TESTS 44 extern struct bw_array_t *write_array; 45 #endif 46 47 #endif /* !defined(TOR_FEATURE_STATS_BWHIST_H) */