17 #define BWHIST_PRIVATE
80 if (when < b->cur_obs_time)
282 total = b->
totals[i] & ~0x3ff;
303 #define MAX_HIST_VALUE_LEN (21*NUM_TOTALS)
305 char tmp[MAX_HIST_VALUE_LEN];
306 char end[ISO_TIME_LEN+1];
354 smartlist_free(*s_values);
358 smartlist_free(*s_maxima);
365 if (*s_begins != 0 || *s_interval != 900) {
366 time_t now = time(NULL);
404 #define UPDATE(arrname,st) \
405 bwhist_update_bwhist_state_section(state,\
407 &state->BWHistory ## st ## Values, \
408 &state->BWHistory ## st ## Maxima, \
409 &state->BWHistory ## st ## Ends, \
410 &state->BWHistory ## st ## Interval)
431 const time_t s_begins,
432 const int s_interval)
434 time_t now = time(NULL);
440 int have_maxima = s_maxima && s_values &&
441 (smartlist_len(s_values) == smartlist_len(s_maxima));
444 start = s_begins - s_interval*(smartlist_len(s_values));
450 const char *maxstr = NULL;
453 maxstr = smartlist_get(s_maxima, cp_sl_idx);
462 log_notice(
LD_HIST,
"Could not parse value '%s' into a number.'",cp);
464 if (maxstr && !ok_m) {
466 log_notice(
LD_HIST,
"Could not parse maximum '%s' into a number.'",
471 time_t cur_start = start;
472 time_t actual_interval_len = s_interval;
473 uint64_t cur_val = 0;
476 if (start + s_interval > now)
477 actual_interval_len = now - start;
478 cur_val = v / actual_interval_len;
481 while (cur_start < start + actual_interval_len) {
482 add_obs(b, cur_start, cur_val);
488 start += actual_interval_len;
490 } SMARTLIST_FOREACH_END(cp);
513 #define LOAD(arrname,st) \
514 if (bwhist_load_bwhist_state_section( \
516 state->BWHistory ## st ## Values, \
517 state->BWHistory ## st ## Maxima, \
518 state->BWHistory ## st ## Ends, \
519 state->BWHistory ## st ## Interval)<0) \
531 *err = tor_strdup(
"Parsing of bandwidth history values failed");
540 bwhist_free_all(
void)
void buf_add_printf(buf_t *buf, const char *format,...)
char * buf_extract(buf_t *buf, size_t *sz_out)
Declaration for bw_array_t structure and related constants.
#define NUM_SECS_BW_SUM_INTERVAL
#define NUM_SECS_ROLLING_MEASURE
void bwhist_note_dir_bytes_written(uint64_t num_bytes, time_t when)
STATIC void commit_max(bw_array_t *b)
static bw_array_t * write_array_ipv6
static int bwhist_load_bwhist_state_section(bw_array_t *b, const smartlist_t *s_values, const smartlist_t *s_maxima, const time_t s_begins, const int s_interval)
char * bwhist_get_bandwidth_lines(void)
STATIC void bw_array_free_(bw_array_t *b)
static bw_array_t * dir_read_array
void bwhist_update_state(or_state_t *state)
STATIC bw_array_t * write_array
void bwhist_note_bytes_read(uint64_t num_bytes, time_t when, bool ipv6)
int bwhist_load_state(or_state_t *state, char **err)
static bw_array_t * dir_write_array
static bw_array_t * read_array
void bwhist_note_dir_bytes_read(uint64_t num_bytes, time_t when)
void bwhist_note_bytes_written(uint64_t num_bytes, time_t when, bool ipv6)
static void bwhist_update_bwhist_state_section(or_state_t *state, const bw_array_t *b, smartlist_t **s_values, smartlist_t **s_maxima, time_t *s_begins, int *s_interval)
STATIC size_t bwhist_fill_bandwidth_history(char *buf, size_t len, const bw_array_t *b)
static void bwhist_get_one_bandwidth_line(buf_t *buf, const char *desc, const bw_array_t *b)
static bw_array_t * read_array_ipv6
int bwhist_bandwidth_assess(void)
STATIC void advance_obs(bw_array_t *b)
STATIC uint64_t find_largest_max(bw_array_t *b)
STATIC void add_obs(bw_array_t *b, time_t when, uint64_t n)
STATIC bw_array_t * bw_array_new(void)
Header for feature/stats/bwhist.c.
const or_options_t * get_options(void)
Header file for config.c.
Master header file for Tor-specific functionality.
The or_options_t structure, which represents Tor's configuration.
The or_state_t structure, which represents Tor's state file.
uint64_t tor_parse_uint64(const char *s, int base, uint64_t min, uint64_t max, int *ok, char **next)
int tor_snprintf(char *str, size_t size, const char *format,...)
int server_mode(const or_options_t *options)
Header file for routermode.c.
void smartlist_add_asprintf(struct smartlist_t *sl, const char *pattern,...)
smartlist_t * smartlist_new(void)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
void or_state_mark_dirty(or_state_t *state, time_t when)
uint64_t totals[NUM_TOTALS]
uint64_t obs[NUM_SECS_ROLLING_MEASURE]
uint64_t maxima[NUM_TOTALS]
uint64_t RelayBandwidthRate
#define MOCK_IMPL(rv, funcname, arglist)
void format_iso_time(char *buf, time_t t)