aboutsummaryrefslogtreecommitdiff
path: root/src/or/router.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/router.c')
-rw-r--r--src/or/router.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/or/router.c b/src/or/router.c
index 31f2ff00d2..c416474226 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -1859,10 +1859,11 @@ router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port)
MOCK_IMPL(int,
router_my_exit_policy_is_reject_star,(void))
{
- if (!router_get_my_routerinfo()) /* make sure routerinfo exists */
+ const routerinfo_t *me = router_get_my_routerinfo();
+ if (!me) /* make sure routerinfo exists */
return -1;
- return router_get_my_routerinfo()->policy_is_reject_star;
+ return me->policy_is_reject_star;
}
/** Return true iff I'm a server and <b>digest</b> is equal to
@@ -2425,21 +2426,38 @@ 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;
- if (!router_get_my_routerinfo())
+ const routerinfo_t *my_ri = router_get_my_routerinfo();
+
+ 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;
- prev = router_get_my_routerinfo()->bandwidthcapacity;
- cur = we_are_hibernating() ? 0 : rep_hist_bandwidth_assess();
+ if (!my_ri) /* make sure routerinfo exists */
+ return;
+
+ prev = my_ri->bandwidthcapacity;
+ 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.");
@@ -2486,14 +2504,15 @@ check_descriptor_ipaddress_changed(time_t now)
const or_options_t *options = get_options();
const char *method = NULL;
char *hostname = NULL;
+ const routerinfo_t *my_ri = router_get_my_routerinfo();
(void) now;
- if (router_get_my_routerinfo() == NULL)
+ if (my_ri == NULL) /* make sure routerinfo exists */
return;
/* XXXX ipv6 */
- prev = router_get_my_routerinfo()->addr;
+ prev = my_ri->addr;
if (resolve_my_address(LOG_INFO, options, &cur, &method, &hostname) < 0) {
log_info(LD_CONFIG,"options->Address didn't resolve into an IP.");
return;
@@ -3637,4 +3656,3 @@ router_get_all_orports(const routerinfo_t *ri)
fake_node.ri = (routerinfo_t *)ri;
return node_get_all_orports(&fake_node);
}
-