[or-cvs] Unify our "figure out which fingerprints we were downloadin...

Nick Mathewson nickm at seul.org
Fri Sep 16 04:42:47 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv19942/src/or

Modified Files:
	dirserv.c directory.c or.h 
Log Message:
Unify our "figure out which fingerprints we were downloading" code.

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.234
retrieving revision 1.235
diff -u -d -r1.234 -r1.235
--- dirserv.c	15 Sep 2005 21:10:58 -0000	1.234
+++ dirserv.c	16 Sep 2005 04:42:45 -0000	1.235
@@ -1338,7 +1338,7 @@
       log_fn(LOG_WARN, "Client requested 'all' network status objects; we have none.");
   } else if (!strcmpstart(key, "fp/")) {
     smartlist_t *hexdigests = smartlist_create();
-    smartlist_split_string(hexdigests, key+3, "+", 0, 0);
+    dir_split_resource_into_fingerprints(key+3, hexdigests, NULL);
     SMARTLIST_FOREACH(hexdigests, char *, cp,
         {
           cached_dir_t *cached;
@@ -1384,7 +1384,7 @@
     smartlist_t *hexdigests = smartlist_create();
     smartlist_t *digests = smartlist_create();
     key += strlen("/tor/server/fp/");
-    smartlist_split_string(hexdigests, key, "+", 0, 0);
+    dir_split_resource_into_fingerprints(key, hexdigests, NULL);
     SMARTLIST_FOREACH(hexdigests, char *, cp,
                       {
                         char *d;

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.279
retrieving revision 1.280
diff -u -d -r1.279 -r1.280
--- directory.c	15 Sep 2005 21:11:48 -0000	1.279
+++ directory.c	16 Sep 2005 04:42:45 -0000	1.280
@@ -29,7 +29,6 @@
  * - connection_dir_finished_connecting(), called from
  *   connection_finished_connecting() in connection.c
  */
-
 static void
 directory_initiate_command_trusted_dir(trusted_dir_server_t *dirserv,
                                       uint8_t purpose, int private_connection,
@@ -305,14 +304,9 @@
     /* We were trying to download by fingerprint; mark them all has having
      * failed, and possibly retry them later.*/
     smartlist_t *failed = smartlist_create();
-    /* XXXX NM this splitting logic is duplicated someplace. Fix that. */
-    smartlist_split_string(failed, conn->requested_resource+3, "+", 0, 0);
+    dir_split_resource_into_fingerprints(conn->requested_resource+3,
+                                         failed, NULL);
     if (smartlist_len(failed)) {
-      char *last = smartlist_get(failed,smartlist_len(failed)-1);
-      size_t last_len = strlen(last);
-      if (!strcmp(last+last_len-2, ".z"))
-        last[last_len-2] = '\0';
-
       dir_networkstatus_download_failed(failed);
       SMARTLIST_FOREACH(failed, char *, cp, tor_free(cp));
     }
@@ -968,12 +962,9 @@
     }
     if (conn->requested_resource &&
         !strcmpstart(conn->requested_resource,"fp/")) {
-      int n;
       which = smartlist_create();
-      smartlist_split_string(which, conn->requested_resource+3, "+", 0, -1);
-      n = smartlist_len(which);
-      if (n && strlen(smartlist_get(which,n-1))==HEX_DIGEST_LEN+2)
-        ((char*)smartlist_get(which,n-1))[HEX_DIGEST_LEN] = '\0';
+      dir_split_resource_into_fingerprints(conn->requested_resource+3,
+                                           which, NULL);
     }
     cp = body;
     while (*cp) {
@@ -1016,12 +1007,9 @@
     }
     if (conn->requested_resource &&
         !strcmpstart(conn->requested_resource,"fp/")) {
-      int n;
       which = smartlist_create();
-      smartlist_split_string(which, conn->requested_resource+3, "+", 0, -1);
-      n = smartlist_len(which);
-      if (n && strlen(smartlist_get(which,n-1))==HEX_DIGEST_LEN+2)
-        ((char*)smartlist_get(which,n-1))[HEX_DIGEST_LEN] = '\0';
+      dir_split_resource_into_fingerprints(conn->requested_resource+3,
+                                           which, NULL);
     }
     if (which)
       n_asked_for = smartlist_len(which);
@@ -1586,3 +1574,22 @@
   /* XXXX writeme!  Give up after a while! */
 }
 
+/* DOCDOC */
+int
+dir_split_resource_into_fingerprints(const char *resource,
+                                     smartlist_t *fp_out, int *compressed_out)
+{
+  smartlist_split_string(fp_out, resource, "+", 0, 0);
+  if (compressed_out)
+    *compressed_out = 0;
+  if (smartlist_len(fp_out)) {
+    char *last = smartlist_get(fp_out,smartlist_len(fp_out)-1);
+    size_t last_len = strlen(last);
+    if (last_len > 2 && !strcmp(last+last_len-2, ".z")) {
+      last[last_len-2] = '\0';
+      if (compressed_out)
+        *compressed_out = 1;
+    }
+  }
+}
+

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.687
retrieving revision 1.688
diff -u -d -r1.687 -r1.688
--- or.h	15 Sep 2005 14:39:05 -0000	1.687
+++ or.h	16 Sep 2005 04:42:45 -0000	1.688
@@ -1715,6 +1715,8 @@
 void connection_dir_request_failed(connection_t *conn);
 void parse_dir_policy(void);
 void free_dir_policy(void);
+int dir_split_resource_into_fingerprints(const char *resource,
+                               smartlist_t *fp_out, int *compresseed_out);
 
 /********************************* dirserv.c ***************************/
 



More information about the tor-commits mailing list