[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r9527: backport r9324 while we're at it (in tor/branches/tor-0_1_1-patches: . src/or)
- To: or-cvs@xxxxxxxxxxxxx
- Subject: [or-cvs] r9527: backport r9324 while we're at it (in tor/branches/tor-0_1_1-patches: . src/or)
- From: arma@xxxxxxxx
- Date: Thu, 8 Feb 2007 03:42:52 -0500 (EST)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Thu, 08 Feb 2007 03:43:39 -0500
- Reply-to: or-talk@xxxxxxxxxxxxx
- Sender: owner-or-cvs@xxxxxxxxxxxxx
Author: arma
Date: 2007-02-08 03:42:41 -0500 (Thu, 08 Feb 2007)
New Revision: 9527
Modified:
tor/branches/tor-0_1_1-patches/ChangeLog
tor/branches/tor-0_1_1-patches/src/or/dirserv.c
tor/branches/tor-0_1_1-patches/src/or/or.h
tor/branches/tor-0_1_1-patches/src/or/routerlist.c
Log:
backport r9324 while we're at it
Modified: tor/branches/tor-0_1_1-patches/ChangeLog
===================================================================
--- tor/branches/tor-0_1_1-patches/ChangeLog 2007-02-08 08:28:03 UTC (rev 9526)
+++ tor/branches/tor-0_1_1-patches/ChangeLog 2007-02-08 08:42:41 UTC (rev 9527)
@@ -1,5 +1,10 @@
Changes in version 0.1.1.27 - 2007-??-??
- o Minor bugfixes
+ o Major bugfixes:
+ - Previously, we would cache up to 16 old networkstatus documents
+ indefinitely, if they came from nontrusted authorities. Now we
+ discard them if they are more than 10 days old.
+
+ o Minor bugfixes:
- Don't launch requests for descriptors unless we have networkstatuses
from enough authorities. This delays the first download slightly under
pathological circumstances, but can prevent us from downloading a bunch
Modified: tor/branches/tor-0_1_1-patches/src/or/dirserv.c
===================================================================
--- tor/branches/tor-0_1_1-patches/src/or/dirserv.c 2007-02-08 08:28:03 UTC (rev 9526)
+++ tor/branches/tor-0_1_1-patches/src/or/dirserv.c 2007-02-08 08:42:41 UTC (rev 9527)
@@ -997,6 +997,39 @@
}
}
+/** Remove any networkstatus from the directory cache that was published
+ * before <b>cutoff</b>. */
+void
+dirserv_clear_old_networkstatuses(time_t cutoff)
+{
+ digestmap_iter_t *iter;
+
+ for (iter = digestmap_iter_init(cached_v2_networkstatus);
+ !digestmap_iter_done(iter); ) {
+ const char *ident;
+ void *val;
+ cached_dir_t *dir;
+ digestmap_iter_get(iter, &ident, &val);
+ dir = val;
+ if (dir->published < cutoff) {
+ char *fname;
+ iter = digestmap_iter_next_rmv(cached_v2_networkstatus, iter);
+ fname = networkstatus_get_cache_filename(ident);
+ if (file_status(fname) == FN_FILE) {
+ log_info(LD_DIR, "Removing too-old untrusted networkstatus in %s",
+ fname);
+ unlink(fname);
+ }
+ tor_free(fname);
+ cached_dir_decref(dir);
+ } else {
+ iter = digestmap_iter_next(cached_v2_networkstatus, iter);
+ }
+ }
+
+}
+
+
/** Helper: If we're an authority for the right directory version (the
* directory version is determined by <b>is_v1_object</b>), try to regenerate
* auth_src as appropriate and return it, falling back to cache_src on
Modified: tor/branches/tor-0_1_1-patches/src/or/or.h
===================================================================
--- tor/branches/tor-0_1_1-patches/src/or/or.h 2007-02-08 08:28:03 UTC (rev 9526)
+++ tor/branches/tor-0_1_1-patches/src/or/or.h 2007-02-08 08:42:41 UTC (rev 9527)
@@ -1936,6 +1936,7 @@
void dirserv_set_cached_networkstatus_v2(const char *directory,
const char *identity,
time_t published);
+void dirserv_clear_old_networkstatuses(time_t cutoff);
void dirserv_get_networkstatus_v2(smartlist_t *result, const char *key);
int dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
const char **msg);
@@ -2368,6 +2369,7 @@
int router_set_networkstatus(const char *s, time_t arrived_at,
networkstatus_source_t source,
smartlist_t *requested_fingerprints);
+char *networkstatus_get_cache_filename(const char *identity_digest);
int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port,
int need_uptime);
Modified: tor/branches/tor-0_1_1-patches/src/or/routerlist.c
===================================================================
--- tor/branches/tor-0_1_1-patches/src/or/routerlist.c 2007-02-08 08:28:03 UTC (rev 9526)
+++ tor/branches/tor-0_1_1-patches/src/or/routerlist.c 2007-02-08 08:42:41 UTC (rev 9527)
@@ -1970,15 +1970,15 @@
}
/** Helper: return a newly allocated string containing the name of the filename
- * where we plan to cache <b>ns</b>. */
-static char *
-networkstatus_get_cache_filename(const networkstatus_t *ns)
+ * where we plan to cache the network status with the given identity digest. */
+char *
+networkstatus_get_cache_filename(const char *identity_digest)
{
const char *datadir = get_options()->DataDirectory;
size_t len = strlen(datadir)+64;
char fp[HEX_DIGEST_LEN+1];
char *fn = tor_malloc(len+1);
- base16_encode(fp, HEX_DIGEST_LEN+1, ns->identity_digest, DIGEST_LEN);
+ base16_encode(fp, HEX_DIGEST_LEN+1, identity_digest, DIGEST_LEN);
tor_snprintf(fn, len, "%s/cached-status/%s",datadir,fp);
return fn;
}
@@ -2006,7 +2006,7 @@
networkstatus_t *ns)
{
if (source != NS_FROM_CACHE) {
- char *fn = networkstatus_get_cache_filename(ns);
+ char *fn = networkstatus_get_cache_filename(ns->identity_digest);
if (write_str_to_file(fn, s, 0)<0) {
log_notice(LD_FS, "Couldn't write cached network status to \"%s\"", fn);
}
@@ -2150,7 +2150,8 @@
trusted_dir->description, published);
if (old_ns->received_on < arrived_at) {
if (source != NS_FROM_CACHE) {
- char *fn = networkstatus_get_cache_filename(old_ns);
+ char *fn;
+ fn = networkstatus_get_cache_filename(old_ns->identity_digest);
/* We use mtime to tell when it arrived, so update that. */
touch_file(fn);
tor_free(fn);
@@ -2218,13 +2219,13 @@
for (i = 0; i < smartlist_len(networkstatus_list); ++i) {
networkstatus_t *ns = smartlist_get(networkstatus_list, i);
- char *fname = NULL;;
+ char *fname = NULL;
if (ns->published_on + MAX_NETWORKSTATUS_AGE > now)
continue;
/* Okay, this one is too old. Remove it from the list, and delete it
* from the cache. */
smartlist_del(networkstatus_list, i--);
- fname = networkstatus_get_cache_filename(ns);
+ fname = networkstatus_get_cache_filename(ns->identity_digest);
if (file_status(fname) == FN_FILE) {
log_info(LD_DIR, "Removing too-old networkstatus in %s", fname);
unlink(fname);
@@ -2236,6 +2237,10 @@
networkstatus_free(ns);
router_dir_info_changed();
}
+
+ /* And now go through the directory cache for any cached untrusted
+ * networkstatuses. */
+ dirserv_clear_old_networkstatuses(now - MAX_NETWORKSTATUS_AGE);
}
/** Helper for bsearching a list of routerstatus_t pointers.*/