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

[or-cvs] cosmetic fix: only have one local to hold smartlist_len(dow...



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

Modified Files:
	routerlist.c 
Log Message:
cosmetic fix: only have one local to hold smartlist_len(downloadable), not too.

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.322
retrieving revision 1.323
diff -u -d -r1.322 -r1.323
--- routerlist.c	30 Sep 2005 21:38:45 -0000	1.322
+++ routerlist.c	4 Oct 2005 20:18:26 -0000	1.323
@@ -2521,10 +2521,12 @@
 #define MIN_DL_PER_REQUEST 4
 #define MIN_REQUESTS 3
 #define MAX_DL_TO_DELAY 16
-#define MAX_INTERVAL_WITHOUT_REQUEST 10*60
+#define MAX_CLIENT_INTERVAL_WITHOUT_REQUEST 10*60
+#define MAX_SERVER_INTERVAL_WITHOUT_REQUEST 1*60
   smartlist_t *downloadable = NULL;
   int get_all = 0;
-  int mirror = server_mode(get_options()) && get_options()->DirPort;
+  int dirserv = server_mode(get_options()) && get_options()->DirPort;
+  int should_delay, n_downloadable;
   static time_t last_download_attempted = 0;
   if (!networkstatus_list || smartlist_len(networkstatus_list)<2)
     get_all = 1;
@@ -2537,30 +2539,39 @@
   }
 
   downloadable = router_list_downloadable();
-  if (smartlist_len(downloadable) >= MAX_DL_TO_DELAY ||
-      (smartlist_len(downloadable) &&
-       (mirror ||
-        last_download_attempted + MAX_INTERVAL_WITHOUT_REQUEST < now))) {
-    int i, j, n, n_per_request=MAX_DL_PER_REQUEST;
+  n_downloadable = smartlist_len(downloadable);
+  if (n_downloadable >= MAX_DL_TO_DELAY)
+    should_delay = 0;
+  else if (n_downloadable == 0)
+    should_delay = 1;
+  else if (dirserv)
+    should_delay = (last_download_attempted +
+                    MAX_SERVER_INTERVAL_WITHOUT_REQUEST) < now;
+  else
+    should_delay = (last_download_attempted +
+                    MAX_CLIENT_INTERVAL_WITHOUT_REQUEST) < now;
+
+  if (! should_delay) {
+    int i, j, n_per_request=MAX_DL_PER_REQUEST;
     size_t r_len = MAX_DL_PER_REQUEST*(HEX_DIGEST_LEN+1)+16;
     char *resource = tor_malloc(r_len);
 
-    n = smartlist_len(downloadable);
-    if (! mirror) {
-      n_per_request = (n+MIN_REQUESTS-1) / MIN_REQUESTS;
+    if (! dirserv) {
+      n_per_request = (n_downloadable+MIN_REQUESTS-1) / MIN_REQUESTS;
       if (n_per_request > MAX_DL_PER_REQUEST)
         n_per_request = MAX_DL_PER_REQUEST;
       if (n_per_request < MIN_DL_PER_REQUEST)
         n_per_request = MIN_DL_PER_REQUEST;
     }
     log_fn(LOG_NOTICE, "Launching %d request%s for %d router%s, %d at a time",
-           (n+n_per_request-1)/n_per_request, n>n_per_request?"s":"",
-           n, n>1?"s":"", n_per_request);
-    for (i=0; i < n; i += n_per_request) {
+           (n_downloadable+n_per_request-1)/n_per_request,
+           n_downloadable>n_per_request?"s":"",
+           n_downloadable, n_downloadable>1?"s":"", n_per_request);
+    for (i=0; i < n_downloadable; i += n_per_request) {
       char *cp = resource;
       memcpy(resource, "fp/", 3);
       cp = resource + 3;
-      for (j=i; j < i+n_per_request && j < n; ++j) {
+      for (j=i; j < i+n_per_request && j < n_downloadable; ++j) {
         memcpy(cp, smartlist_get(downloadable, j), HEX_DIGEST_LEN);
         cp += HEX_DIGEST_LEN;
         *cp++ = '+';