summaryrefslogtreecommitdiff
path: root/src/feature/relay
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-09-04 10:44:36 -0400
committerNick Mathewson <nickm@torproject.org>2018-09-04 10:44:36 -0400
commit94b04d6c64ec998a9117d65a156888fa3af188e5 (patch)
tree08ed94f695e8c1b9abef413a8bfee98c8be07be8 /src/feature/relay
parent1c62adb65baa99c92f937318c452955306301643 (diff)
parent81f4223329a709e5138532b037a58c118b30dd7f (diff)
downloadtor-94b04d6c64ec998a9117d65a156888fa3af188e5.tar.gz
tor-94b04d6c64ec998a9117d65a156888fa3af188e5.zip
Merge branch 'bug24104_029_squashed'
Diffstat (limited to 'src/feature/relay')
-rw-r--r--src/feature/relay/router.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index ad97d534c2..b9a930dbe9 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -2644,25 +2644,42 @@ 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)
+
+/** 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. 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;
+ const 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 && !hibernating)
+ return;
+
const routerinfo_t *my_ri = router_get_my_routerinfo();
- if (!my_ri) /* make sure routerinfo exists */
+
+ if (!my_ri)
return;
prev = my_ri->bandwidthcapacity;
/* Consider ourselves to have zero bandwidth if we're hibernating or
* shutting down. */
- cur = we_are_hibernating() ? 0 : rep_hist_bandwidth_assess();
+ cur = 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.");