aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2006-09-24 23:11:24 +0000
committerRoger Dingledine <arma@torproject.org>2006-09-24 23:11:24 +0000
commitb81ddec8672c0e1574b3b8d44cfb5ce1badfdc6e (patch)
treeb7531a69d3b78532e8ef71b497dc3ad83ad74228
parent028654b79edf64089c3c15eea5e5095e2d59a825 (diff)
downloadtor-b81ddec8672c0e1574b3b8d44cfb5ce1badfdc6e.tar.gz
tor-b81ddec8672c0e1574b3b8d44cfb5ce1badfdc6e.zip
backport weasel's r8398:
- If we're a directory mirror and we ask for "all" network status documents, we would forget that's what we wanted and discard most of them when they arrived. svn:r8491
-rw-r--r--ChangeLog3
-rw-r--r--src/or/directory.c7
-rw-r--r--src/or/or.h2
-rw-r--r--src/or/routerlist.c17
4 files changed, 22 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 22087e4c28..2a3c90fb26 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,9 @@ Changes in version 0.1.1.24 - 2006-09-xx [ongoing]
whether we have enough directory information every time we want to
do something, only check when the directory information has changed.
This should improve client CPU usage by 25-50%.
+ - If we're a directory mirror and we ask for "all" network status
+ documents, we would forget that's what we wanted and discard most
+ of them when they arrived.
o Minor bugfixes:
- Allow Tor to start when RunAsDaemon is set but no logs are set.
diff --git a/src/or/directory.c b/src/or/directory.c
index 3a3f3a0012..5858cea24f 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -977,6 +977,7 @@ connection_dir_client_reached_eof(connection_t *conn)
if (conn->purpose == DIR_PURPOSE_FETCH_NETWORKSTATUS) {
smartlist_t *which = NULL;
+ int source;
char *cp;
log_info(LD_DIR,"Received networkstatus objects (size %d) from server "
"'%s:%d'",(int) body_len, conn->address, conn->port);
@@ -993,11 +994,13 @@ connection_dir_client_reached_eof(connection_t *conn)
note_request(was_compressed?"dl/status.z":"dl/status", orig_len);
if (conn->requested_resource &&
!strcmpstart(conn->requested_resource,"fp/")) {
+ source = NS_FROM_DIR_BY_FP;
which = smartlist_create();
dir_split_resource_into_fingerprints(conn->requested_resource+3,
which, NULL, 0);
} else if (conn->requested_resource &&
!strcmpstart(conn->requested_resource, "all")) {
+ source = NS_FROM_DIR_ALL;
which = smartlist_create();
SMARTLIST_FOREACH(router_get_trusted_dir_servers(),
trusted_dir_server_t *, ds,
@@ -1006,6 +1009,8 @@ connection_dir_client_reached_eof(connection_t *conn)
base16_encode(cp, HEX_DIGEST_LEN+1, ds->digest, DIGEST_LEN);
smartlist_add(which, cp);
});
+ } else {
+ source = NS_FROM_DIR_BY_FP; /* probably not reached */
}
cp = body;
while (*cp) {
@@ -1013,7 +1018,7 @@ connection_dir_client_reached_eof(connection_t *conn)
if (next)
next[1] = '\0';
/* learn from it, and then remove it from 'which' */
- if (router_set_networkstatus(cp, time(NULL), NS_FROM_DIR, which)<0)
+ if (router_set_networkstatus(cp, time(NULL), source, which)<0)
break;
if (next) {
next[1] = 'n';
diff --git a/src/or/or.h b/src/or/or.h
index b529fcb617..9b6849eb6b 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2363,7 +2363,7 @@ int router_load_single_router(const char *s, uint8_t purpose,
void router_load_routers_from_string(const char *s, int from_cache,
smartlist_t *requested_fingerprints);
typedef enum {
- NS_FROM_CACHE, NS_FROM_DIR, NS_GENERATED
+ NS_FROM_CACHE, NS_FROM_DIR_BY_FP, NS_FROM_DIR_ALL, NS_GENERATED
} networkstatus_source_t;
int router_set_networkstatus(const char *s, time_t arrived_at,
networkstatus_source_t source,
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index a68ed86e6c..3ce8c445e6 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -2093,7 +2093,8 @@ router_set_networkstatus(const char *s, time_t arrived_at,
if (!networkstatus_list)
networkstatus_list = smartlist_create();
- if (source == NS_FROM_DIR && router_digest_is_me(ns->identity_digest)) {
+ if ( (source == NS_FROM_DIR_BY_FP || source == NS_FROM_DIR_ALL) &&
+ router_digest_is_me(ns->identity_digest)) {
/* Don't replace our own networkstatus when we get it from somebody else.*/
networkstatus_free(ns);
return 0;
@@ -2105,12 +2106,14 @@ router_set_networkstatus(const char *s, time_t arrived_at,
} else {
char *requested =
smartlist_join_strings(requested_fingerprints," ",0,NULL);
- log_warn(LD_DIR,
+ if (source != NS_FROM_DIR_ALL) {
+ log_warn(LD_DIR,
"We received a network status with a fingerprint (%s) that we "
"never requested. (We asked for: %s.) Dropping.",
fp, requested);
- tor_free(requested);
- return 0;
+ tor_free(requested);
+ return 0;
+ }
}
}
@@ -2119,6 +2122,9 @@ router_set_networkstatus(const char *s, time_t arrived_at,
/* We got a non-trusted networkstatus, and we're a directory cache.
* This means that we asked an authority, and it told us about another
* authority we didn't recognize. */
+ log_info(LD_DIR,
+ "We do not recognize authority (%s) but we are willing "
+ "to cache it", fp);
add_networkstatus_to_cache(s, source, ns);
networkstatus_free(ns);
}
@@ -2181,7 +2187,8 @@ router_set_networkstatus(const char *s, time_t arrived_at,
log_info(LD_DIR, "Setting networkstatus %s %s (published %s)",
source == NS_FROM_CACHE?"cached from":
- (source==NS_FROM_DIR?"downloaded from":"generated for"),
+ ((source == NS_FROM_DIR_BY_FP || source == NS_FROM_DIR_ALL) ?
+ "downloaded from":"generated for"),
trusted_dir->description, published);
networkstatus_list_has_changed = 1;
router_dir_info_changed();