80 if (when < b->cur_obs_time)
223 if (b->
cur_obs_time > period_start + min_observation_time)
291 total = b->
totals[i] & ~0x3ff;
312#define MAX_HIST_VALUE_LEN (21*NUM_TOTALS)
314 char tmp[MAX_HIST_VALUE_LEN];
315 char end[ISO_TIME_LEN+1];
363 smartlist_free(*s_values);
367 smartlist_free(*s_maxima);
374 if (*s_begins != 0 || *s_interval != 900) {
375 time_t now = time(NULL);
413#define UPDATE(arrname,st) \
414 bwhist_update_bwhist_state_section(state,\
416 &state->BWHistory ## st ## Values, \
417 &state->BWHistory ## st ## Maxima, \
418 &state->BWHistory ## st ## Ends, \
419 &state->BWHistory ## st ## Interval)
440 const time_t s_begins,
441 const int s_interval)
443 time_t now = time(NULL);
449 int have_maxima = s_maxima && s_values &&
450 (smartlist_len(s_values) == smartlist_len(s_maxima));
453 start = s_begins - s_interval*(smartlist_len(s_values));
459 const char *maxstr = NULL;
462 maxstr = smartlist_get(s_maxima, cp_sl_idx);
471 log_notice(
LD_HIST,
"Could not parse value '%s' into a number.'",cp);
473 if (maxstr && !ok_m) {
475 log_notice(
LD_HIST,
"Could not parse maximum '%s' into a number.'",
480 time_t cur_start = start;
481 time_t actual_interval_len = s_interval;
482 uint64_t cur_val = 0;
485 if (start + s_interval > now)
486 actual_interval_len = now - start;
487 cur_val = v / actual_interval_len;
490 while (cur_start < start + actual_interval_len) {
491 add_obs(b, cur_start, cur_val);
497 start += actual_interval_len;
499 } SMARTLIST_FOREACH_END(cp);
522#define LOAD(arrname,st) \
523 if (bwhist_load_bwhist_state_section( \
525 state->BWHistory ## st ## Values, \
526 state->BWHistory ## st ## Maxima, \
527 state->BWHistory ## st ## Ends, \
528 state->BWHistory ## st ## Interval)<0) \
540 *err = tor_strdup(
"Parsing of bandwidth history values failed");
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)
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 bw_array_t * bw_array_new(void)
char * bwhist_get_bandwidth_lines(void)
STATIC void add_obs(bw_array_t *b, time_t when, uint64_t n)
STATIC uint64_t find_largest_max(bw_array_t *b, int min_observation_time)
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]
int TestingMinTimeToReportBandwidth
uint64_t RelayBandwidthRate
#define MOCK_IMPL(rv, funcname, arglist)
void format_iso_time(char *buf, time_t t)