[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Fix a fun bug: do not rewrite a cached directory back to th...



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

Modified Files:
	directory.c dirserv.c or.h routerlist.c routerparse.c test.c 
Log Message:
Fix a fun bug: do not rewrite a cached directory back to the cache; otherwise we will think it is recent and not fetch a newer one.

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.187
retrieving revision 1.188
diff -u -d -r1.187 -r1.188
--- directory.c	4 Jan 2005 01:16:20 -0000	1.187
+++ directory.c	6 Jan 2005 20:11:52 -0000	1.188
@@ -614,7 +614,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.");
@@ -633,7 +633,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 (server '%s')", conn->address);
       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.133
retrieving revision 1.134
diff -u -d -r1.133 -r1.134
--- dirserv.c	3 Jan 2005 17:47:32 -0000	1.133
+++ dirserv.c	6 Jan 2005 20:11:52 -0000	1.134
@@ -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.518
retrieving revision 1.519
diff -u -d -r1.518 -r1.519
--- or.h	5 Jan 2005 06:40:47 -0000	1.518
+++ or.h	6 Jan 2005 20:11:52 -0000	1.519
@@ -1611,7 +1611,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
@@ -1696,8 +1696,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.203
retrieving revision 1.204
diff -u -d -r1.203 -r1.204
--- routerlist.c	3 Jan 2005 20:51:24 -0000	1.203
+++ routerlist.c	6 Jan 2005 20:11:52 -0000	1.204
@@ -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 &&
@@ -846,14 +846,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.97
retrieving revision 1.98
diff -u -d -r1.97 -r1.98
--- routerparse.c	4 Jan 2005 05:46:54 -0000	1.97
+++ routerparse.c	6 Jan 2005 20:11:52 -0000	1.98
@@ -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];
@@ -394,7 +397,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))) {
@@ -480,7 +483,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;
@@ -520,7 +523,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.162
retrieving revision 1.163
diff -u -d -r1.162 -r1.163
--- test.c	4 Jan 2005 05:46:54 -0000	1.162
+++ test.c	6 Jan 2005 20:11:52 -0000	1.163
@@ -1161,7 +1161,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);