[or-cvs] Backport directory cache fix

Nick Mathewson nickm at seul.org
Thu Jan 6 20:30:11 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv31741/src/or

Modified Files:
      Tag: tor-0_0_9-patches
	directory.c dirserv.c or.h routerlist.c routerparse.c test.c 
Log Message:
Backport directory cache fix

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.181.2.3
retrieving revision 1.181.2.4
diff -u -d -r1.181.2.3 -r1.181.2.4
--- directory.c	4 Jan 2005 01:11:08 -0000	1.181.2.3
+++ directory.c	6 Jan 2005 20:30:08 -0000	1.181.2.4
@@ -612,7 +612,7 @@
       tor_free(body); tor_free(headers);
       return -1;
     }
-    if (router_load_routerlist_from_directory(body, NULL, 1) < 0) {
+    if (router_load_routerlist_from_directory(body, NULL, 1, 0) < 0) {
       log_fn(LOG_WARN,"I failed to parse the directory I fetched from %s:%d. Ignoring.", conn->address, conn->port);
     } else {
       log_fn(LOG_INFO,"updated routers.");
@@ -631,7 +631,7 @@
       tor_free(body); tor_free(headers);
       return -1;
     }
-    if (!(rrs = router_parse_runningrouters(body))) {
+    if (!(rrs = router_parse_runningrouters(body, 1))) {
       log_fn(LOG_WARN, "Can't parse runningrouters list");
       tor_free(body); tor_free(headers);
       return -1;

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.129.2.2
retrieving revision 1.129.2.3
diff -u -d -r1.129.2.2 -r1.129.2.3
--- dirserv.c	24 Dec 2004 02:19:29 -0000	1.129.2.2
+++ dirserv.c	6 Jan 2005 20:30:09 -0000	1.129.2.3
@@ -820,7 +820,8 @@
    * necessary, but safe is better than sorry. */
   new_directory = tor_strdup(the_directory);
   /* use a new copy of the dir, since get_dir_from_string scribbles on it */
-  if (router_load_routerlist_from_directory(new_directory, get_identity_key(), 1)) {
+  if (router_load_routerlist_from_directory(new_directory,
+                                            get_identity_key(), 1, 0)) {
     log_fn(LOG_ERR, "We just generated a directory we can't parse. Dying.");
     tor_cleanup();
     exit(0);

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.508.2.5
retrieving revision 1.508.2.6
diff -u -d -r1.508.2.5 -r1.508.2.6
--- or.h	5 Jan 2005 06:09:10 -0000	1.508.2.5
+++ or.h	6 Jan 2005 20:30:09 -0000	1.508.2.6
@@ -1605,7 +1605,7 @@
 void router_mark_as_down(const char *digest);
 void routerlist_remove_old_routers(int age);
 int router_load_routerlist_from_directory(const char *s,crypto_pk_env_t *pkey,
-                                          int check_version);
+                                        int dir_is_recent, int dir_is_cached);
 int router_compare_addr_to_addr_policy(uint32_t addr, uint16_t port,
                                        addr_policy_t *policy);
 #define ADDR_POLICY_ACCEPTED 0
@@ -1690,8 +1690,10 @@
 int router_parse_routerlist_from_directory(const char *s,
                                            routerlist_t **dest,
                                            crypto_pk_env_t *pkey,
-                                           int check_version);
-running_routers_t *router_parse_runningrouters(const char *str);
+                                           int check_version,
+                                           int write_to_cache);
+running_routers_t *router_parse_runningrouters(const char *str,
+                                               int write_to_cache);
 routerinfo_t *router_parse_entry_from_string(const char *s, const char *end);
 int router_add_exit_policy_from_string(routerinfo_t *router, const char *s);
 addr_policy_t *router_parse_addr_policy_from_string(const char *s);

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.200.2.1
retrieving revision 1.200.2.2
diff -u -d -r1.200.2.1 -r1.200.2.2
--- routerlist.c	3 Jan 2005 21:24:07 -0000	1.200.2.1
+++ routerlist.c	6 Jan 2005 20:30:09 -0000	1.200.2.2
@@ -60,7 +60,7 @@
     stat(filename, &st); /* if s is true, stat probably worked */
     log_fn(LOG_INFO, "Loading cached directory from %s", filename);
     is_recent = st.st_mtime > time(NULL) - 60*15;
-    if (router_load_routerlist_from_directory(s, NULL, is_recent) < 0) {
+    if (router_load_routerlist_from_directory(s, NULL, is_recent, 1) < 0) {
       log_fn(LOG_WARN, "Cached directory at '%s' was unparseable; ignoring.", filename);
     }
     if (routerlist &&
@@ -852,14 +852,19 @@
 
 /** Add to the current routerlist each router stored in the
  * signed directory <b>s</b>.  If pkey is provided, check the signature against
- * pkey; else check against the pkey of the signing directory server. */
+ * pkey; else check against the pkey of the signing directory server.
+ *
+ * DOCDOC dir_is_recent/cached
+ */
 int router_load_routerlist_from_directory(const char *s,
                                           crypto_pk_env_t *pkey,
-                                          int dir_is_recent)
+                                          int dir_is_recent,
+                                          int dir_is_cached)
 {
   routerlist_t *new_list = NULL;
   if (router_parse_routerlist_from_directory(s, &new_list, pkey,
-                                             dir_is_recent)) {
+                                             dir_is_recent,
+                                             !dir_is_cached)) {
     log_fn(LOG_WARN, "Couldn't parse directory.");
     return -1;
   }

Index: routerparse.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerparse.c,v
retrieving revision 1.94.2.1
retrieving revision 1.94.2.2
diff -u -d -r1.94.2.1 -r1.94.2.2
--- routerparse.c	2 Jan 2005 06:18:36 -0000	1.94.2.1
+++ routerparse.c	6 Jan 2005 20:30:09 -0000	1.94.2.2
@@ -291,12 +291,15 @@
 /** Parse a directory from <b>str</b> and, when done, store the
  * resulting routerlist in *<b>dest</b>, freeing the old value if necessary.
  * If <b>pkey</b> is provided, we check the directory signature with pkey.
+ *
+ * DOCDOC check_version, write_to_cache.
  */
 int /* Should be static; exposed for unit tests */
 router_parse_routerlist_from_directory(const char *str,
                                        routerlist_t **dest,
                                        crypto_pk_env_t *pkey,
-                                       int check_version)
+                                       int check_version,
+                                       int write_to_cache)
 {
   directory_token_t *tok;
   char digest[DIGEST_LEN];
@@ -390,7 +393,7 @@
 
   /* Now that we know the signature is okay, and we have a
    * publication time, cache the directory. */
-  if (!get_options()->AuthoritativeDir)
+  if (!get_options()->AuthoritativeDir && write_to_cache)
     dirserv_set_cached_directory(str, published_on, 0);
 
   if (!(tok = find_first_by_keyword(tokens, K_RECOMMENDED_SOFTWARE))) {
@@ -476,7 +479,7 @@
 
 /* DOCDOC */
 running_routers_t *
-router_parse_runningrouters(const char *str)
+router_parse_runningrouters(const char *str, int write_to_cache)
 {
   char digest[DIGEST_LEN];
   running_routers_t *new_list = NULL;
@@ -516,7 +519,7 @@
 
   /* Now that we know the signature is okay, and we have a
    * publication time, cache the list. */
-  if (!get_options()->AuthoritativeDir)
+  if (!get_options()->AuthoritativeDir && write_to_cache)
     dirserv_set_cached_directory(str, published_on, 1);
 
   if (!(tok = find_first_by_keyword(tokens, K_ROUTER_STATUS))) {

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/test.c,v
retrieving revision 1.160.2.1
retrieving revision 1.160.2.2
diff -u -d -r1.160.2.1 -r1.160.2.2
--- test.c	24 Dec 2004 02:19:29 -0000	1.160.2.1
+++ test.c	6 Jan 2005 20:30:09 -0000	1.160.2.2
@@ -1165,7 +1165,7 @@
   test_eq(dirserv_add_descriptor((const char**)&cp), 1);
   get_options()->Nickname = tor_strdup("DirServer");
   test_assert(!dirserv_dump_directory_to_string(&cp,pk3));
-  test_assert(!router_parse_routerlist_from_directory(cp, &dir1, pk3, 1));
+  test_assert(!router_parse_routerlist_from_directory(cp, &dir1, pk3, 1, 0));
   test_eq(2, smartlist_len(dir1->routers));
   dirserv_free_fingerprint_list();
   tor_free(cp);



More information about the tor-commits mailing list