summaryrefslogtreecommitdiff
path: root/src/or/routerlist.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-08-13 18:47:22 +0000
committerNick Mathewson <nickm@torproject.org>2007-08-13 18:47:22 +0000
commitce1f01c3e6b55700baf46365aaef5a83fbae858e (patch)
tree60e30ce9a8238ae01c3e5c42e401dcb72fbbd1f3 /src/or/routerlist.c
parentf3e9dceaa97ad361db708dcbb4f91771d0adf0dc (diff)
downloadtor-ce1f01c3e6b55700baf46365aaef5a83fbae858e.tar.gz
tor-ce1f01c3e6b55700baf46365aaef5a83fbae858e.zip
r14531@catbus: nickm | 2007-08-13 14:46:25 -0400
Cache v3 networkstatus consensuses on disk. svn:r11086
Diffstat (limited to 'src/or/routerlist.c')
-rw-r--r--src/or/routerlist.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 0cff1709fd..39518b6fac 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -175,6 +175,27 @@ router_reload_networkstatus(void)
return 0;
}
+/**DOCDOC */
+int
+router_reload_consensus_networkstatus(void)
+{
+ char filename[512];
+ char *s;
+
+ tor_snprintf(filename,sizeof(filename),"%s"PATH_SEPARATOR"cached-consensus",
+ get_options()->DataDirectory);
+ s = read_file_to_str(filename, 0, NULL);
+ if (!s)
+ return 0;
+
+ if (networkstatus_set_current_consensus(s, 1)) {
+ log_warn(LD_FS, "Couldn't load consensus networkstatus from \"%s\"",
+ filename);
+ }
+ tor_free(s);
+ return 0;
+}
+
/** Reload the cached v3 key certificates from the cached-certs file in
* the data directory. Return 0 on success, -1 on failure. */
int
@@ -3837,8 +3858,9 @@ networkstatus_get_live_consensus(time_t now)
return current_consensus;
}
+/** DOCDOC */
int
-networkstatus_set_current_consensus(const char *consensus)
+networkstatus_set_current_consensus(const char *consensus, int from_cache)
{
networkstatus_vote_t *c;
/* Make sure it's parseable. */
@@ -3857,6 +3879,15 @@ networkstatus_set_current_consensus(const char *consensus)
current_consensus = c;
+ if (!from_cache) {
+ or_options_t *options = get_options();
+ char filename[512];
+ tor_snprintf(filename, sizeof(filename),
+ "%s"PATH_SEPARATOR"cached-consensus",
+ options->DataDirectory);
+ write_str_to_file(filename, consensus, 0);
+ }
+
if (get_options()->DirPort)
dirserv_set_cached_networkstatus_v3(consensus, c->valid_after);