diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-12-04 12:21:14 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-12-13 08:25:54 -0500 |
commit | b5c04173c88369d0c4cdaf8a34c2474dc25c79fa (patch) | |
tree | 44cbe58c9b9282addf26fc4786f548a0bf1f48aa /src/core | |
parent | c037bf58173db56766381a7c1cd5973789f0fd0f (diff) | |
download | tor-b5c04173c88369d0c4cdaf8a34c2474dc25c79fa.tar.gz tor-b5c04173c88369d0c4cdaf8a34c2474dc25c79fa.zip |
Change interaction between dormant mode and clock jumps.
When the clock jumps, and we have a record of last user activity,
adjust that record. This way if I'm inactive for 10 minutes and
then the laptop is sleeping for an hour, I'll still count as having
been inactive for 10 minutes.
Previously, we treat every jump as if it were activity, which is
ridiculous, and would prevent a Tor instance with a jumpy clock from
ever going dormant.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/mainloop/mainloop.c | 21 | ||||
-rw-r--r-- | src/core/mainloop/netstatus.c | 12 | ||||
-rw-r--r-- | src/core/mainloop/netstatus.h | 1 |
3 files changed, 24 insertions, 10 deletions
diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c index cd955e0ca0..6b9c03798e 100644 --- a/src/core/mainloop/mainloop.c +++ b/src/core/mainloop/mainloop.c @@ -1627,7 +1627,6 @@ schedule_rescan_periodic_events,(void)) void rescan_periodic_events(const or_options_t *options) { - puts("RESCAN"); tor_assert(options); /* Avoid scanning the event list if we haven't initialized it yet. This is @@ -2687,6 +2686,17 @@ update_current_time(time_t now) memcpy(&last_updated, ¤t_second_last_changed, sizeof(last_updated)); monotime_coarse_get(¤t_second_last_changed); + /** How much clock jumping means that we should adjust our idea of when + * to go dormant? */ +#define NUM_JUMPED_SECONDS_BEFORE_NETSTATUS_UPDATE 20 + + /* Don't go dormant early or late just because we jumped in time. */ + if (ABS(seconds_elapsed) >= NUM_JUMPED_SECONDS_BEFORE_NETSTATUS_UPDATE) { + if (is_participating_on_network()) { + netstatus_note_clock_jumped(seconds_elapsed); + } + } + /** How much clock jumping do we tolerate? */ #define NUM_JUMPED_SECONDS_BEFORE_WARN 100 @@ -2697,10 +2707,6 @@ update_current_time(time_t now) // moving back in time is always a bad sign. circuit_note_clock_jumped(seconds_elapsed, false); - /* Don't go dormant just because we jumped in time. */ - if (is_participating_on_network()) { - reset_user_activity(now); - } } else if (seconds_elapsed >= NUM_JUMPED_SECONDS_BEFORE_WARN) { /* Compare the monotonic clock to the result of time(). */ const int32_t monotime_msec_passed = @@ -2722,11 +2728,6 @@ update_current_time(time_t now) if (clock_jumped || seconds_elapsed >= NUM_IDLE_SECONDS_BEFORE_WARN) { circuit_note_clock_jumped(seconds_elapsed, ! clock_jumped); } - - /* Don't go dormant just because we jumped in time. */ - if (is_participating_on_network()) { - reset_user_activity(now); - } } else if (seconds_elapsed > 0) { stats_n_seconds_working += seconds_elapsed; } diff --git a/src/core/mainloop/netstatus.c b/src/core/mainloop/netstatus.c index 2426baae34..d1989cb839 100644 --- a/src/core/mainloop/netstatus.c +++ b/src/core/mainloop/netstatus.c @@ -146,3 +146,15 @@ netstatus_load_from_state(const or_state_t *state, time_t now) } reset_user_activity(last_activity); } + +/** + * Adjust the time at which the user was last active by <b>seconds_diff</b> + * in response to a clock jump. + */ +void +netstatus_note_clock_jumped(time_t seconds_diff) +{ + time_t last_active = get_last_user_activity_time(); + if (last_active) + reset_user_activity(last_active + seconds_diff); +} diff --git a/src/core/mainloop/netstatus.h b/src/core/mainloop/netstatus.h index 4b008e4cfa..9a0fa410fd 100644 --- a/src/core/mainloop/netstatus.h +++ b/src/core/mainloop/netstatus.h @@ -19,5 +19,6 @@ bool is_participating_on_network(void); void netstatus_flush_to_state(or_state_t *state, time_t now); void netstatus_load_from_state(const or_state_t *state, time_t now); +void netstatus_note_clock_jumped(time_t seconds_diff); #endif |