[or-cvs] predict required circuits better, with an eye toward making

arma at seul.org arma at seul.org
Sat Aug 13 00:22:09 UTC 2005


Update of /home2/or/cvsroot/tor/src/or
In directory moria:/home/arma/work/onion/cvs/tor/src/or

Modified Files:
	circuituse.c dns.c or.h rendservice.c rephist.c 
Log Message:
predict required circuits better, with an eye toward making
hidden services faster on the service end.


Index: circuituse.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/circuituse.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -d -r1.78 -r1.79
--- circuituse.c	12 Aug 2005 01:26:21 -0000	1.78
+++ circuituse.c	13 Aug 2005 00:22:06 -0000	1.79
@@ -331,17 +331,9 @@
   int num=0, num_internal=0, num_uptime_internal=0;
   int hidserv_needs_uptime=0, hidserv_needs_capacity=1;
   int port_needs_uptime=0, port_needs_capacity=1;
-  int need_ports, need_hidserv;
   time_t now = time(NULL);
 
-  /* check if we know of a port that's been requested recently
-   * and no circuit is currently available that can handle it. */
-  need_ports = !circuit_all_predicted_ports_handled(now, &port_needs_uptime,
-                                                    &port_needs_capacity);
-
-  need_hidserv = rep_hist_get_predicted_hidserv(now, &hidserv_needs_uptime,
-                                                &hidserv_needs_capacity);
-
+  /* First, count how many of each type of circuit we have already. */
   for (circ=global_circuitlist;circ;circ = circ->next) {
     if (!CIRCUIT_IS_ORIGIN(circ))
       continue;
@@ -358,21 +350,41 @@
       num_uptime_internal++;
   }
 
-  if (num < MAX_UNUSED_OPEN_CIRCUITS) {
-    /* perhaps we want another */
-    if (need_ports) {
-      log_fn(LOG_INFO,"Have %d clean circs (%d internal), need another exit circ.",
-        num, num_internal);
-      circuit_launch_by_router(CIRCUIT_PURPOSE_C_GENERAL, NULL,
-                               port_needs_uptime, port_needs_capacity, 0);
-    } else if (need_hidserv &&
-               ((num_uptime_internal<2 && hidserv_needs_uptime) ||
-                num_internal<2)) {
-      log_fn(LOG_INFO,"Have %d clean circs (%d uptime-internal, %d internal),"
-        " need another hidserv circ.", num, num_uptime_internal, num_internal);
-      circuit_launch_by_router(CIRCUIT_PURPOSE_C_GENERAL, NULL,
-                               hidserv_needs_uptime, hidserv_needs_capacity, 1);
-    }
+  /* If that's enough, then stop now. */
+  if (num >= MAX_UNUSED_OPEN_CIRCUITS)
+    return; /* we already have many, making more probably will hurt */
+
+  /* Second, see if we need any more exit circuits. */
+  /* check if we know of a port that's been requested recently
+   * and no circuit is currently available that can handle it. */
+  if (!circuit_all_predicted_ports_handled(now, &port_needs_uptime,
+                                           &port_needs_capacity)) {
+    log_fn(LOG_INFO,"Have %d clean circs (%d internal), need another exit circ.",
+      num, num_internal);
+    circuit_launch_by_router(CIRCUIT_PURPOSE_C_GENERAL, NULL,
+                             port_needs_uptime, port_needs_capacity, 0);
+    return;
+  }
+
+  /* Third, see if we need any more hidden service (server) circuits. */
+  if (num_rend_services() && num_uptime_internal < 3) {
+    log_fn(LOG_INFO,"Have %d clean circs (%d internal), need another internal circ for my hidden service.",
+           num, num_internal);
+    circuit_launch_by_router(CIRCUIT_PURPOSE_C_GENERAL, NULL,
+                             1, 1, 1);
+    return;
+  }
+
+  /* Fourth, see if we need any more hidden service (client) circuits. */
+  if (rep_hist_get_predicted_hidserv(now, &hidserv_needs_uptime,
+                                     &hidserv_needs_capacity) &&
+      ((num_uptime_internal<2 && hidserv_needs_uptime) ||
+        num_internal<2)) {
+    log_fn(LOG_INFO,"Have %d clean circs (%d uptime-internal, %d internal),"
+      " need another hidserv circ.", num, num_uptime_internal, num_internal);
+    circuit_launch_by_router(CIRCUIT_PURPOSE_C_GENERAL, NULL,
+                             hidserv_needs_uptime, hidserv_needs_capacity, 1);
+    return;
   }
 }
 

Index: dns.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/dns.c,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -d -r1.162 -r1.163
--- dns.c	22 Jul 2005 21:12:10 -0000	1.162
+++ dns.c	13 Aug 2005 00:22:06 -0000	1.163
@@ -904,7 +904,7 @@
 
   while (num_dnsworkers < num_dnsworkers_needed) {
     if (spawn_dnsworker() < 0) {
-      log(LOG_WARN,"spawn_enough_dnsworkers(): spawn failed!");
+      log_fn(LOG_WARN,"spawn failed!");
       return;
     }
     num_dnsworkers++;

Index: or.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.640
retrieving revision 1.641
diff -u -d -r1.640 -r1.641
--- or.h	10 Aug 2005 18:05:20 -0000	1.640
+++ or.h	13 Aug 2005 00:22:06 -0000	1.641
@@ -1846,6 +1846,7 @@
 
 /********************************* rendservice.c ***************************/
 
+int num_rend_services(void);
 int rend_config_services(or_options_t *options, int validate_only);
 int rend_service_load_keys(void);
 void rend_services_init(void);

Index: rendservice.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/rendservice.c,v
retrieving revision 1.133
retrieving revision 1.134
diff -u -d -r1.133 -r1.134
--- rendservice.c	12 Aug 2005 15:05:05 -0000	1.133
+++ rendservice.c	13 Aug 2005 00:22:07 -0000	1.134
@@ -61,6 +61,13 @@
  */
 static smartlist_t *rend_service_list = NULL;
 
+/** Return the number of rendezvous services we have configured. */
+int num_rend_services(void) {
+  if (!rend_service_list)
+    return 0;
+  return smartlist_len(rend_service_list);
+}
+
 /** Release the storage held by <b>service</b>.
  */
 static void

Index: rephist.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/rephist.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- rephist.c	25 Jul 2005 10:29:21 -0000	1.62
+++ rephist.c	13 Aug 2005 00:22:07 -0000	1.63
@@ -748,8 +748,11 @@
 int
 rep_hist_get_predicted_hidserv(time_t now, int *need_uptime, int *need_capacity)
 {
-  if (!predicted_hidserv_time) /* initialize it */
+  if (!predicted_hidserv_time) { /* initialize it */
     predicted_hidserv_time = now;
+    predicted_hidserv_uptime_time = now;
+    predicted_hidserv_capacity_time = now;
+  }
   if (predicted_hidserv_time + PREDICTED_CIRCS_RELEVANCE_TIME < now)
     return 0; /* too long ago */
   if (predicted_hidserv_uptime_time + PREDICTED_CIRCS_RELEVANCE_TIME < now)



More information about the tor-commits mailing list