aboutsummaryrefslogtreecommitdiff
path: root/src/feature
diff options
context:
space:
mode:
authorAlexander Færøy <ahf@torproject.org>2021-10-21 12:35:36 +0000
committerAlexander Færøy <ahf@torproject.org>2021-10-21 12:35:36 +0000
commitbd1c14f0156c4d166ed1706544242e31d7ddceff (patch)
treebc0eba46fb171915cdfa876eb928cce943077dfb /src/feature
parent1e08efdb5891008f8180603bccf461c467275f57 (diff)
parent0135fb028c8ca0ce310009f20efef89e53a36f2c (diff)
downloadtor-bd1c14f0156c4d166ed1706544242e31d7ddceff.tar.gz
tor-bd1c14f0156c4d166ed1706544242e31d7ddceff.zip
Merge branch 'maint-0.4.5' into maint-0.4.6
Diffstat (limited to 'src/feature')
-rw-r--r--src/feature/relay/router.c5
-rw-r--r--src/feature/stats/bwhist.c19
-rw-r--r--src/feature/stats/bwhist.h2
3 files changed, 19 insertions, 7 deletions
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index 67d3e3ee75..a2ca472307 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -2622,7 +2622,10 @@ check_descriptor_bandwidth_changed(time_t now)
if ((prev != cur && (!prev || !cur)) ||
cur > (prev * BANDWIDTH_CHANGE_FACTOR) ||
cur < (prev / BANDWIDTH_CHANGE_FACTOR) ) {
- if (last_changed+MAX_BANDWIDTH_CHANGE_FREQ < now || !prev) {
+ const bool change_recent_enough =
+ last_changed+MAX_BANDWIDTH_CHANGE_FREQ < now;
+ const bool testing_network = get_options()->TestingTorNetwork;
+ if (change_recent_enough || testing_network || !prev) {
log_info(LD_GENERAL,
"Measured bandwidth has changed; rebuilding descriptor.");
mark_my_descriptor_dirty("bandwidth has changed");
diff --git a/src/feature/stats/bwhist.c b/src/feature/stats/bwhist.c
index d5a9b73605..552dc7ad74 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()->TestingMinTimeToReportBandwidth;
+ 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 e7fc60fdee..d61c442e5d 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);