From 7d70f67deaeea1a3dc80a763f13bcec5d7a2425d Mon Sep 17 00:00:00 2001 From: juga0 Date: Sun, 3 Jun 2018 09:31:19 +0000 Subject: Check bandwidth changes only if small uptime to upload a new descriptor. --- src/or/router.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/or/router.c') diff --git a/src/or/router.c b/src/or/router.c index 31f2ff00d2..ab916fb6e6 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -2425,13 +2425,24 @@ mark_my_descriptor_dirty(const char *reason) * if our previous bandwidth estimate was exactly 0. */ #define MAX_BANDWIDTH_CHANGE_FREQ (3*60*60) +/** Maximum uptime to republish our descriptor because of large shifts in + * estimated bandwidth. */ +#define MAX_UPTIME_BANDWIDTH_CHANGE (24*60*60) + /** Check whether bandwidth has changed a lot since the last time we announced - * bandwidth. If so, mark our descriptor dirty. */ + * bandwidth while the uptime is smaller than MAX_UPTIME_BANDWIDTH_CHANGE. + * If so, mark our descriptor dirty. */ void check_descriptor_bandwidth_changed(time_t now) { static time_t last_changed = 0; uint64_t prev, cur; + + /* If the relay uptime is bigger than MAX_UPTIME_BANDWIDTH_CHANGE, + * the next regularly scheduled descriptor update (18h) will be enough */ + if (get_uptime() > MAX_UPTIME_BANDWIDTH_CHANGE) + return; + if (!router_get_my_routerinfo()) return; -- cgit v1.2.3-54-g00ecf From 6210d568ecc5c2fd1833126d68505f42e4399820 Mon Sep 17 00:00:00 2001 From: juga0 Date: Sun, 3 Jun 2018 09:40:57 +0000 Subject: Make bandwidth change factor a constant used to determine large changes in bandwidth. --- src/or/router.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/or/router.c') diff --git a/src/or/router.c b/src/or/router.c index ab916fb6e6..4afba65491 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -2429,6 +2429,9 @@ mark_my_descriptor_dirty(const char *reason) * estimated bandwidth. */ #define MAX_UPTIME_BANDWIDTH_CHANGE (24*60*60) +/** By which factor bandwidth shifts have to change to be considered large. */ +#define BANDWIDTH_CHANGE_FACTOR 2 + /** Check whether bandwidth has changed a lot since the last time we announced * bandwidth while the uptime is smaller than MAX_UPTIME_BANDWIDTH_CHANGE. * If so, mark our descriptor dirty. */ @@ -2449,8 +2452,8 @@ check_descriptor_bandwidth_changed(time_t now) prev = router_get_my_routerinfo()->bandwidthcapacity; cur = we_are_hibernating() ? 0 : rep_hist_bandwidth_assess(); if ((prev != cur && (!prev || !cur)) || - cur > prev*2 || - cur < prev/2) { + cur > (prev * BANDWIDTH_CHANGE_FACTOR) || + cur < (prev / BANDWIDTH_CHANGE_FACTOR) ) { if (last_changed+MAX_BANDWIDTH_CHANGE_FREQ < now || !prev) { log_info(LD_GENERAL, "Measured bandwidth has changed; rebuilding descriptor."); -- cgit v1.2.3-54-g00ecf From e033d98f79a950a342a7db6909709b5dc987b2cb Mon Sep 17 00:00:00 2001 From: juga0 Date: Mon, 2 Jul 2018 08:21:43 +0000 Subject: Check descriptor bandwidth changed if not hibernating There should be a separate check to update descriptor when start or end hibernating. --- src/or/router.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/or/router.c') diff --git a/src/or/router.c b/src/or/router.c index 4afba65491..f1a99364e6 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -2440,17 +2440,18 @@ check_descriptor_bandwidth_changed(time_t now) { static time_t last_changed = 0; uint64_t prev, cur; + int hibernating = we_are_hibernating(); /* If the relay uptime is bigger than MAX_UPTIME_BANDWIDTH_CHANGE, * the next regularly scheduled descriptor update (18h) will be enough */ - if (get_uptime() > MAX_UPTIME_BANDWIDTH_CHANGE) + if (get_uptime() > MAX_UPTIME_BANDWIDTH_CHANGE && !hibernating) return; if (!router_get_my_routerinfo()) return; prev = router_get_my_routerinfo()->bandwidthcapacity; - cur = we_are_hibernating() ? 0 : rep_hist_bandwidth_assess(); + cur = hibernating ? 0 : rep_hist_bandwidth_assess(); if ((prev != cur && (!prev || !cur)) || cur > (prev * BANDWIDTH_CHANGE_FACTOR) || cur < (prev / BANDWIDTH_CHANGE_FACTOR) ) { -- cgit v1.2.3-54-g00ecf