summaryrefslogtreecommitdiff
path: root/src/or/circuituse.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2005-08-13 00:22:07 +0000
committerRoger Dingledine <arma@torproject.org>2005-08-13 00:22:07 +0000
commit87fcd60aa29afc07ed1cfe8d5999bca63591bf52 (patch)
tree93dc45c25247d745ae8287d59f591da66c0079d6 /src/or/circuituse.c
parentd1c094637dee46493f2be435e2b37588bfe5331b (diff)
downloadtor-87fcd60aa29afc07ed1cfe8d5999bca63591bf52.tar.gz
tor-87fcd60aa29afc07ed1cfe8d5999bca63591bf52.zip
predict required circuits better, with an eye toward making
hidden services faster on the service end. svn:r4772
Diffstat (limited to 'src/or/circuituse.c')
-rw-r--r--src/or/circuituse.c60
1 files changed, 36 insertions, 24 deletions
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 2fba046c38..a1aa3d716e 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -331,17 +331,9 @@ circuit_predict_and_launch_new(void)
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 @@ circuit_predict_and_launch_new(void)
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;
}
}