aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-09-04 23:12:27 +0000
committerNick Mathewson <nickm@torproject.org>2005-09-04 23:12:27 +0000
commit1e37ec4782bf8342337632dd03a1242fad6da705 (patch)
treef8a61aaa85a92a8b8c8a7a934fe263371202cb21 /src
parentd2a5b614ebc0fc93264a1c774e27cb9820742738 (diff)
downloadtor-1e37ec4782bf8342337632dd03a1242fad6da705.tar.gz
tor-1e37ec4782bf8342337632dd03a1242fad6da705.zip
Comment structs, reload a field, start making network status caches work
svn:r4908
Diffstat (limited to 'src')
-rw-r--r--src/or/or.h60
-rw-r--r--src/or/routerlist.c36
-rw-r--r--src/or/routerparse.c5
3 files changed, 71 insertions, 30 deletions
diff --git a/src/or/or.h b/src/or/or.h
index 3c812109d7..51247a2037 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -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;
+
+ /* These fields come from the actual network-status document.*/
+ time_t published_on; /**< Declared publication date. */
- char *source_address;
- uint32_t source_addr;
- uint16_t source_dirport;
+ char *source_address; /**< Canonical directory server hostname */
+ uint32_t source_addr; /**< Canonical directory server IP */
+ uint16_t source_dirport; /**< Canonical directory server dirport */
- char fingerprint[DIGEST_LEN];
- char *contact;
- crypto_pk_env_t *signing_key;
- char *client_versions;
- char *server_versions;
+ 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 */
- int binds_names:1;
+ int binds_names:1; /**< True iff this directory server binds names. */
- smartlist_t *entries;
+ smartlist_t *entries; /**< List of router_status_t* */
} networkstatus_t;
/** Contents of a directory of onion routers. */
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 91aaff3166..9a78b98ce0 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -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.
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 08a47b66e1..4697dc2144 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -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;