aboutsummaryrefslogtreecommitdiff
path: root/src/feature/stats
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2021-03-17 08:45:37 -0400
committerNick Mathewson <nickm@torproject.org>2021-03-17 08:45:37 -0400
commit2ae24d003d1d12e8e202748c4398d7438e4a65d9 (patch)
treeed28225754a655c069a9a6d5fd6b66af2fdfc205 /src/feature/stats
parent59bbf8cde9144ee5c8d060959e723a4bedfd6bb8 (diff)
downloadtor-2ae24d003d1d12e8e202748c4398d7438e4a65d9.tar.gz
tor-2ae24d003d1d12e8e202748c4398d7438e4a65d9.zip
Add a MinTimeToReportBandwidth option; make it 0 for testing networks.
This option changes the time for which a bandwidth measurement period must have been in progress before we include it when reporting our observed bandwidth in our descriptors. Without this option, we only consider a time period towards our maximum if it has been running for a full day. Obviously, that's unacceptable for testing networks, where we'd like to get results as soon as possible. For non-testing networks, I've put a (somewhat arbitrary) 2-hour minimum on the option, since there are traffic analysis concerns with immediate reporting here. Closes #40337.
Diffstat (limited to 'src/feature/stats')
-rw-r--r--src/feature/stats/bwhist.c19
-rw-r--r--src/feature/stats/bwhist.h2
2 files changed, 15 insertions, 6 deletions
diff --git a/src/feature/stats/bwhist.c b/src/feature/stats/bwhist.c
index 7cbc5f60a6..55a8f7c747 100644
--- a/src/feature/stats/bwhist.c
+++ b/src/feature/stats/bwhist.c
@@ -206,16 +206,24 @@ bwhist_note_dir_bytes_read(uint64_t num_bytes, time_t when)
add_obs(dir_read_array, when, num_bytes);
}
-/** Helper: Return the largest value in b->maxima. (This is equal to the
+/**
+ * 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.)
+ *
+ * Also include the current period if we have been observing it for
+ * at least min_observation_time seconds.
*/
STATIC uint64_t
-find_largest_max(bw_array_t *b)
+find_largest_max(bw_array_t *b, int min_observation_time)
{
int i;
uint64_t max;
- max=0;
+ time_t period_start = b->next_period - NUM_SECS_BW_SUM_INTERVAL;
+ if (b->cur_obs_time > period_start + min_observation_time)
+ max = b->max_total;
+ else
+ max = 0;
for (i=0; i<NUM_TOTALS; ++i) {
if (b->maxima[i]>max)
max = b->maxima[i];
@@ -233,8 +241,9 @@ MOCK_IMPL(int,
bwhist_bandwidth_assess,(void))
{
uint64_t w,r;
- r = find_largest_max(read_array);
- w = find_largest_max(write_array);
+ int min_obs_time = get_options()->MinTimeToReportBandwidth;
+ r = find_largest_max(read_array, min_obs_time);
+ w = find_largest_max(write_array, min_obs_time);
if (r>w)
return (int)(((double)w)/NUM_SECS_ROLLING_MEASURE);
else
diff --git a/src/feature/stats/bwhist.h b/src/feature/stats/bwhist.h
index f88b951447..01055df720 100644
--- a/src/feature/stats/bwhist.h
+++ b/src/feature/stats/bwhist.h
@@ -28,7 +28,7 @@ int bwhist_load_state(struct or_state_t *state, char **err);
#ifdef BWHIST_PRIVATE
typedef struct bw_array_t bw_array_t;
-STATIC uint64_t find_largest_max(bw_array_t *b);
+STATIC uint64_t find_largest_max(bw_array_t *b, int min_observation_time);
STATIC void commit_max(bw_array_t *b);
STATIC void advance_obs(bw_array_t *b);
STATIC bw_array_t *bw_array_new(void);