Tor
0.4.7.0-alpha-dev
|
Tracking for relay bandwidth history. More...
#include "orconfig.h"
#include "core/or/or.h"
#include "feature/stats/bwhist.h"
#include "app/config/config.h"
#include "app/config/statefile.h"
#include "feature/relay/routermode.h"
#include "feature/stats/bw_array_st.h"
#include "app/config/or_state_st.h"
#include "app/config/or_options_st.h"
Go to the source code of this file.
Macros | |
#define | BWHIST_PRIVATE |
#define | MAX_HIST_VALUE_LEN (21*NUM_TOTALS) |
#define | UPDATE(arrname, st) |
#define | LOAD(arrname, st) |
Functions | |
STATIC void | commit_max (bw_array_t *b) |
STATIC void | advance_obs (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) |
STATIC void | bw_array_free_ (bw_array_t *b) |
void | bwhist_init (void) |
void | bwhist_note_bytes_written (uint64_t num_bytes, time_t when, bool ipv6) |
void | bwhist_note_bytes_read (uint64_t num_bytes, time_t when, bool ipv6) |
void | bwhist_note_dir_bytes_written (uint64_t num_bytes, time_t when) |
void | bwhist_note_dir_bytes_read (uint64_t num_bytes, time_t when) |
STATIC uint64_t | find_largest_max (bw_array_t *b) |
int | bwhist_bandwidth_assess (void) |
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) |
char * | bwhist_get_bandwidth_lines (void) |
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) |
void | bwhist_update_state (or_state_t *state) |
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) |
int | bwhist_load_state (or_state_t *state, char **err) |
void | bwhist_free_all (void) |
Variables | |
static bw_array_t * | read_array = NULL |
static bw_array_t * | read_array_ipv6 = NULL |
STATIC bw_array_t * | write_array = NULL |
static bw_array_t * | write_array_ipv6 = NULL |
static bw_array_t * | dir_read_array = NULL |
static bw_array_t * | dir_write_array = NULL |
Tracking for relay bandwidth history.
This module handles bandwidth usage history, used by relays to self-report how much bandwidth they've used for different purposes over last day or so, in order to generate the {dirreq-,}{read,write}-history lines in that they publish.
Definition in file bwhist.c.
#define LOAD | ( | arrname, | |
st | |||
) |
#define UPDATE | ( | arrname, | |
st | |||
) |
STATIC void add_obs | ( | bw_array_t * | b, |
time_t | when, | ||
uint64_t | n | ||
) |
Add n bytes to the number of bytes in b for second when.
Definition at line 78 of file bwhist.c.
Referenced by bwhist_note_bytes_read(), bwhist_note_bytes_written(), bwhist_note_dir_bytes_read(), and bwhist_note_dir_bytes_written().
STATIC void advance_obs | ( | bw_array_t * | b | ) |
STATIC void bw_array_free_ | ( | bw_array_t * | b | ) |
STATIC bw_array_t* bw_array_new | ( | void | ) |
Allocate, initialize, and return a new bw_array.
Definition at line 99 of file bwhist.c.
Referenced by bwhist_init().
int bwhist_bandwidth_assess | ( | void | ) |
Find the largest sums in the past NUM_SECS_BW_SUM_IS_VALID (roughly) seconds. Find one sum for reading and one for writing. They don't have to be at the same time.
Return the smaller of these sums, divided by NUM_SECS_ROLLING_MEASURE.
Definition at line 233 of file bwhist.c.
Referenced by check_descriptor_bandwidth_changed().
STATIC size_t bwhist_fill_bandwidth_history | ( | char * | buf, |
size_t | len, | ||
const bw_array_t * | b | ||
) |
char* bwhist_get_bandwidth_lines | ( | void | ) |
|
static |
Encode a single bandwidth history line into buf.
Definition at line 297 of file bwhist.c.
Referenced by bwhist_get_bandwidth_lines().
void bwhist_init | ( | void | ) |
Set up structures for bandwidth history, clearing them if they already exist.
Definition at line 139 of file bwhist.c.
Referenced by tor_init().
|
static |
Load a single bw_array_t from its Values, Ends, Maxima, and Interval entries in an or_state_t. Done while reading the state file.
int bwhist_load_state | ( | or_state_t * | state, |
char ** | err | ||
) |
void bwhist_note_bytes_read | ( | uint64_t | num_bytes, |
time_t | when, | ||
bool | ipv6 | ||
) |
Remember that we wrote num_bytes bytes in second when. (like bwhist_note_bytes_written() above)
Definition at line 183 of file bwhist.c.
Referenced by record_num_bytes_transferred_impl().
void bwhist_note_bytes_written | ( | uint64_t | num_bytes, |
time_t | when, | ||
bool | ipv6 | ||
) |
Remember that we read num_bytes bytes in second when.
Add num_bytes to the current running total for when.
when can go back to time, but it's safe to ignore calls earlier than the latest when you've heard of.
Definition at line 164 of file bwhist.c.
Referenced by record_num_bytes_transferred_impl().
void bwhist_note_dir_bytes_read | ( | uint64_t | num_bytes, |
time_t | when | ||
) |
Remember that we read num_bytes directory bytes in second when. (like bwhist_note_bytes_written() above)
Definition at line 204 of file bwhist.c.
Referenced by record_num_bytes_transferred_impl().
void bwhist_note_dir_bytes_written | ( | uint64_t | num_bytes, |
time_t | when | ||
) |
Remember that we wrote num_bytes directory bytes in second when. (like bwhist_note_bytes_written() above)
Definition at line 195 of file bwhist.c.
Referenced by record_num_bytes_transferred_impl().
|
static |
Write a single bw_array_t into the Values, Ends, Interval, and Maximum entries of an or_state_t. Done before writing out a new state file.
void bwhist_update_state | ( | or_state_t * | state | ) |
STATIC void commit_max | ( | bw_array_t * | b | ) |
Shift the current period of b forward by one.
Definition at line 32 of file bwhist.c.
Referenced by advance_obs().
STATIC uint64_t find_largest_max | ( | bw_array_t * | b | ) |
Helper: Return the largest value in b->maxima. (This is equal to the most bandwidth used in any NUM_SECS_ROLLING_MEASURE period for the last NUM_SECS_BW_SUM_IS_VALID seconds.)
Definition at line 214 of file bwhist.c.
Referenced by bwhist_bandwidth_assess().
|
static |
Recent history of bandwidth observations for read operations for the directory protocol.
Definition at line 131 of file bwhist.c.
Referenced by bwhist_get_bandwidth_lines(), bwhist_init(), bwhist_load_state(), and bwhist_note_dir_bytes_read().
|
static |
Recent history of bandwidth observations for write operations for the directory protocol.
Definition at line 134 of file bwhist.c.
Referenced by bwhist_get_bandwidth_lines(), bwhist_init(), bwhist_load_state(), and bwhist_note_dir_bytes_written().
|
static |
Recent history of bandwidth observations for (all) read operations.
Definition at line 122 of file bwhist.c.
Referenced by bwhist_bandwidth_assess(), bwhist_get_bandwidth_lines(), bwhist_init(), bwhist_load_state(), and bwhist_note_bytes_read().
|
static |
Recent history of bandwidth observations for IPv6 read operations.
Definition at line 124 of file bwhist.c.
Referenced by bwhist_get_bandwidth_lines(), bwhist_init(), bwhist_load_state(), and bwhist_note_bytes_read().
STATIC bw_array_t* write_array = NULL |
Recent history of bandwidth observations for (all) write operations.
Definition at line 126 of file bwhist.c.
Referenced by bwhist_bandwidth_assess(), bwhist_get_bandwidth_lines(), bwhist_init(), bwhist_load_state(), and bwhist_note_bytes_written().
|
static |
Recent history of bandwidth observations for IPv6 write operations.
Definition at line 128 of file bwhist.c.
Referenced by bwhist_get_bandwidth_lines(), bwhist_init(), bwhist_load_state(), and bwhist_note_bytes_written().