diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-08-20 15:32:48 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-08-20 15:32:48 -0400 |
commit | 916fba2243f36dcf53b078a95ce2389a63b94f72 (patch) | |
tree | 8c91ae1fd1b6fe925092a334afc5e5332b6a808d /src/or | |
parent | 01a0ab02a3d8ef9e7664945224ce5e22f18ac4b9 (diff) | |
parent | 2994f00199096860c4cbdfcb6b7d82918d637b27 (diff) | |
download | tor-916fba2243f36dcf53b078a95ce2389a63b94f72.tar.gz tor-916fba2243f36dcf53b078a95ce2389a63b94f72.zip |
Merge branch 'bug12205_take2_squashed'
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/entrynodes.c | 41 | ||||
-rw-r--r-- | src/or/entrynodes.h | 3 |
2 files changed, 33 insertions, 11 deletions
diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c index 365b9274ec..edf766bb87 100644 --- a/src/or/entrynodes.c +++ b/src/or/entrynodes.c @@ -156,21 +156,40 @@ entry_guard_set_status(entry_guard_t *e, const node_t *node, /** Return true iff enough time has passed since we last tried to connect * to the unreachable guard <b>e</b> that we're willing to try again. */ -static int +STATIC int entry_is_time_to_retry(const entry_guard_t *e, time_t now) { - long diff; + struct guard_retry_period_s { + time_t period_duration; + time_t interval_during_period; + }; + + struct guard_retry_period_s periods[] = { + { 6*60*60, 60*60 }, /* For first 6 hrs., retry hourly; */ + { 3*24*60*60, 4*60*60 }, /* Then retry every 4 hrs. until the + 3-day mark; */ + { 7*24*60*60, 18*60*60 }, /* After 3 days, retry every 18 hours until + 1 week mark. */ + { TIME_MAX, 36*60*60 } /* After 1 week, retry every 36 hours. */ + }; + + time_t ith_deadline_for_retry; + time_t unreachable_for; + int i; + if (e->last_attempted < e->unreachable_since) return 1; - diff = now - e->unreachable_since; - if (diff < 6*60*60) - return now > (e->last_attempted + 60*60); - else if (diff < 3*24*60*60) - return now > (e->last_attempted + 4*60*60); - else if (diff < 7*24*60*60) - return now > (e->last_attempted + 18*60*60); - else - return now > (e->last_attempted + 36*60*60); + + unreachable_for = now - e->unreachable_since; + + for (i = 0; ; i++) { + if (unreachable_for <= periods[i].period_duration) { + ith_deadline_for_retry = e->last_attempted + + periods[i].interval_during_period; + + return (now > ith_deadline_for_retry); + } + } } /** Return the node corresponding to <b>e</b>, if <b>e</b> is diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h index 5d91756aa4..52b31a225d 100644 --- a/src/or/entrynodes.h +++ b/src/or/entrynodes.h @@ -104,6 +104,9 @@ typedef enum { STATIC const node_t *entry_is_live(const entry_guard_t *e, entry_is_live_flags_t flags, const char **msg); + +STATIC int entry_is_time_to_retry(const entry_guard_t *e, time_t now); + #endif void remove_all_entry_guards(void); |