Comment structs, reload a field, start making network status caches work

svn:r4908
This commit is contained in:
Nick Mathewson 2005-09-04 23:12:27 +00:00
parent d2a5b614eb
commit 1e37ec4782
3 changed files with 71 additions and 30 deletions

View file

@ -766,40 +766,48 @@ typedef struct running_routers_t {
smartlist_t *running_routers;
} running_routers_t;
/** Contents of a network status object */
/** Contents of a single per-router entry in a network status object.
*/
typedef struct routerstatus_t {
time_t published_on;
char nickname[MAX_NICKNAME_LEN+1];
char identity_digest[DIGEST_LEN];
char descriptor_digest[DIGEST_LEN];
uint32_t addr;
uint16_t or_port;
uint16_t dir_port;
unsigned int is_exit:1;
unsigned int is_stable:1;
unsigned int is_fast:1;
unsigned int is_running:1;
unsigned int is_named:1;
unsigned int is_valid:1;
time_t published_on; /**< When was this router published? */
char nickname[MAX_NICKNAME_LEN+1]; /**<The nickname this router says it has*/
char identity_digest[DIGEST_LEN]; /**< Digest of the router's identity key*/
char descriptor_digest[DIGEST_LEN]; /**< Digest of the router's most recent
* descriptor */
uint32_t addr; /**< IPv4 address for this router */
uint16_t or_port; /**< OR port for this router */
uint16_t dir_port; /**< Directory port for this router */
unsigned int is_exit:1; /**< True iff this router is a good exit */
unsigned int is_stable:1; /**< True iff this router stays up a long time */
unsigned int is_fast:1; /**< True iff this router has good bandwidth */
unsigned int is_running:1; /**< True iff this router is up */
unsigned int is_named:1; /**< True iff "nickname" belongs to this router */
unsigned int is_valid:1; /**< True iff this router is validated */
} routerstatus_t;
/** Contents of a network status object */
/** Contents of a (v2 or later) network status object */
typedef struct networkstatus_t {
time_t published_on;
/** When did we receive the network-status document? */
time_t received_on;
char *source_address;
uint32_t source_addr;
uint16_t source_dirport;
/* These fields come from the actual network-status document.*/
time_t published_on; /**< Declared publication date. */
char fingerprint[DIGEST_LEN];
char *contact;
crypto_pk_env_t *signing_key;
char *client_versions;
char *server_versions;
char *source_address; /**< Canonical directory server hostname */
uint32_t source_addr; /**< Canonical directory server IP */
uint16_t source_dirport; /**< Canonical directory server dirport */
int binds_names:1;
char identity_digest[DIGEST_LEN]; /**< Digest of signing key */
char *contact; /**< How to contact directory admin? (may be NULL) */
crypto_pk_env_t *signing_key; /**< Key used to sign this directory */
char *client_versions; /**< comma-separated list of recommended client
* versions */
char *server_versions; /**< comma-separated list of recommended server
* versions */
smartlist_t *entries;
int binds_names:1; /**< True iff this directory server binds names. */
smartlist_t *entries; /**< List of router_status_t* */
} networkstatus_t;
/** Contents of a directory of onion routers. */

View file

@ -37,11 +37,15 @@ static void router_normalize_routerlist(routerlist_t *rl);
* descriptors.)
****/
/** Global list of all of the routers that we, as an OR or OP, know about. */
/** Global list of all of the routers that we know about. */
static routerlist_t *routerlist = NULL;
extern int has_fetched_directory; /**< from main.c */
/** Global list of all of the current network_status documents that we know
* about. */
static smartlist_t *networkstatus_list = NULL;
/**
* Reload the most recent cached directory (if present).
*/
@ -74,6 +78,36 @@ router_reload_router_list(void)
return 0;
}
int
router_reload_networkstatus(void)
{
char filename[512];
struct stat st;
smartlist_t *entries;
char *s;
tor_assert(get_options()->DataDirectory);
if (!networkstatus_list)
networkstatus_list = smartlist_create();
tor_snprintf(filename,sizeof(filename),"%s/cached-status",
get_options()->DataDirectory);
entries = tor_listdir(filename);
SMARTLIST_FOREACH(entries, const char *, fn, {
tor_snprintf(filename,sizeof(filename),"%s/cached-status/%s",
get_options()->DataDirectory, fn);
s = read_file_to_str(filename, 0);
if (s) {
networkstatus_t *ns;
stat(filename, &st);
log_fn(LOG_INFO, "Loading cached network status from %s", filename);
ns = networkstatus_parse_from_string(s);
ns->received_on = st.st_mtime;
smartlist_add(networkstatus_list, ns);
}
});
return 0;
}
/* Set *<b>outp</b> to a smartlist containing a list of
* trusted_dir_server_t * for all known trusted dirservers. Callers
* must not modify the list or its contents.

View file

@ -1318,7 +1318,7 @@ networkstatus_parse_from_string(const char *s)
log_fn(LOG_WARN, "Too few arguments to fingerprint");
goto err;
}
if (base16_decode(ns->fingerprint, DIGEST_LEN, tok->args[0],
if (base16_decode(ns->identity_digest, DIGEST_LEN, tok->args[0],
strlen(tok->args[0]))) {
log_fn(LOG_WARN, "Couldn't decode fingerprint '%s'", tok->args[0]);
goto err;
@ -1340,7 +1340,7 @@ networkstatus_parse_from_string(const char *s)
log_fn(LOG_WARN, "Couldn't compute signing key digest");
goto err;
}
if (memcmp(tmp_digest, ns->fingerprint, DIGEST_LEN)) {
if (memcmp(tmp_digest, ns->identity_digest, DIGEST_LEN)) {
log_fn(LOG_WARN, "network-status fingerprint did not match dir-signing-key");
goto err;
}
@ -1351,7 +1351,6 @@ networkstatus_parse_from_string(const char *s)
}
ns->client_versions = tok->args[0];
/* XXXX NM When to check these ?? */
if (!(tok = find_first_by_keyword(tokens, K_CLIENT_VERSIONS)) || tok->n_args<1){
log_fn(LOG_WARN, "Missing client-versions");
goto err;