mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 23:53:32 +01:00
r9770@danube: weasel | 2006-09-15 07:20:05 +0200
router_set_networkstatus() gets a list of status documents we asked for from connection_dir_client_reached_eof(). However, as a cache we (sometimes?) just ask for "all". router_set_networkstatus() would freak out over that, meaning it would log a warning and drop the status document instead of caching it as it is supposed to. Now we let router_set_networkstatus() know if the data comes from an all-request so it can do the right thing. svn:r8398
This commit is contained in:
parent
5beb114744
commit
ba091ae5d7
@ -990,6 +990,7 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
|
||||
|
||||
if (conn->_base.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->_base.address, conn->_base.port);
|
||||
@ -1006,11 +1007,13 @@ connection_dir_client_reached_eof(dir_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, 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,
|
||||
@ -1019,6 +1022,11 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
|
||||
base16_encode(cp, HEX_DIGEST_LEN+1, ds->digest, DIGEST_LEN);
|
||||
smartlist_add(which, cp);
|
||||
});
|
||||
} else {
|
||||
/* Can we even end up here? -- weasel*/
|
||||
source = NS_FROM_DIR_BY_FP;
|
||||
log_warn(LD_BUG, "we received a networkstatus but we did neither ask"
|
||||
"for it by fp/ nor did we ask for all.");
|
||||
}
|
||||
cp = body;
|
||||
while (*cp) {
|
||||
@ -1026,7 +1034,7 @@ connection_dir_client_reached_eof(dir_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';
|
||||
|
@ -2559,7 +2559,7 @@ void router_load_routers_from_string(const char *s,
|
||||
saved_location_t saved_location,
|
||||
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,
|
||||
|
@ -2199,7 +2199,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;
|
||||
@ -2211,12 +2212,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2225,6 +2228,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);
|
||||
}
|
||||
@ -2287,7 +2293,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();
|
||||
|
Loading…
Reference in New Issue
Block a user