summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2010-01-19 17:52:52 -0500
committerRoger Dingledine <arma@torproject.org>2010-01-19 17:52:52 -0500
commit1fc94bfd0e0b2ab70ec51c35acde6330c8a7fd1d (patch)
treef11ae1a1175a81239bf018b249c1902f677c8c69
parent0642ab242865c00816510934ea1c3f6ce6982db9 (diff)
downloadtor-1fc94bfd0e0b2ab70ec51c35acde6330c8a7fd1d.tar.gz
tor-1fc94bfd0e0b2ab70ec51c35acde6330c8a7fd1d.zip
spread guard rotation out throughout the month
-rw-r--r--ChangeLog7
-rw-r--r--src/or/circuitbuild.c30
2 files changed, 17 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 998d14c2d1..71ab2d7220 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,13 @@ Changes in version 0.2.1.23 - 2010-0?-??
automatically discard guards picked using the old algorithm. Fixes
bug 1217; bugfix on 0.2.1.3-alpha. Found by Mike Perry.
+ o Minor features:
+ - Avoid a mad rush at the beginning of each month when each client
+ rotates half of its guards. Instead we spread the rotation out
+ throughout the month, but we still avoid leaving a precise timestamp
+ in the state file about when we first picked the guard. Improves
+ over the behavior introduced in 0.1.2.17.
+
Changes in version 0.2.1.22 - 2010-01-19
Tor 0.2.1.22 fixes a critical privacy problem in bridge directory
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 1f4a493fa5..3441c30f90 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -58,7 +58,6 @@ static int count_acceptable_routers(smartlist_t *routers);
static int onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice);
static void entry_guards_changed(void);
-static time_t start_of_month(time_t when);
/** Iterate over values of circ_id, starting from conn-\>next_circ_id,
* and with the high bit specified by conn-\>circ_id_type, until we get
@@ -2137,7 +2136,12 @@ add_an_entry_guard(routerinfo_t *chosen, int reset_status)
log_info(LD_CIRC, "Chose '%s' as new entry guard.", router->nickname);
strlcpy(entry->nickname, router->nickname, sizeof(entry->nickname));
memcpy(entry->identity, router->cache_info.identity_digest, DIGEST_LEN);
- entry->chosen_on_date = start_of_month(time(NULL));
+ /* Choose expiry time smudged over the past month. The goal here
+ * is to a) spread out when Tor clients rotate their guards, so they
+ * don't all select them on the same day, and b) avoid leaving a
+ * precise timestamp in the state file about when we first picked
+ * this guard. For details, see the Jan 2010 or-dev thread. */
+ entry->chosen_on_date = time(NULL) - crypto_rand_int(3600*24*30);
entry->chosen_by_version = tor_strdup(VERSION);
if (chosen) /* prepend */
smartlist_insert(entry_guards, 0, entry);
@@ -2188,7 +2192,7 @@ static int
remove_obsolete_entry_guards(void)
{
int changed = 0, i;
- time_t this_month = start_of_month(time(NULL));
+ time_t now = time(NULL);
for (i = 0; i < smartlist_len(entry_guards); ++i) {
entry_guard_t *entry = smartlist_get(entry_guards, i);
@@ -2220,9 +2224,8 @@ remove_obsolete_entry_guards(void)
}
tor_free(tor_ver);
}
- if (!version_is_bad && entry->chosen_on_date + 3600*24*35 < this_month) {
- /* It's been more than a month, and probably more like two since
- * chosen_on_date is clipped to the beginning of its month. */
+ if (!version_is_bad && entry->chosen_on_date + 3600*24*60 < now) {
+ /* It's been 2 months since the date listed in our state file. */
msg = "was selected several months ago";
date_is_bad = 1;
}
@@ -2673,19 +2676,6 @@ choose_random_entry(cpath_build_state_t *state)
return r;
}
-/** Helper: Return the start of the month containing <b>time</b>. */
-static time_t
-start_of_month(time_t now)
-{
- struct tm tm;
- tor_gmtime_r(&now, &tm);
- tm.tm_sec = 0;
- tm.tm_min = 0;
- tm.tm_hour = 0;
- tm.tm_mday = 1;
- return tor_timegm(&tm);
-}
-
/** Parse <b>state</b> and learn about the entry guards it describes.
* If <b>set</b> is true, and there are no errors, replace the global
* entry_list with what we find.
@@ -2794,7 +2784,7 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg)
} else {
if (state_version) {
e->chosen_by_version = tor_strdup(state_version);
- e->chosen_on_date = start_of_month(time(NULL));
+ e->chosen_on_date = time(NULL) - crypto_rand_int(3600*24*30);
}
}
});