mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-01 08:03:31 +01:00
predict required circuits better, with an eye toward making
hidden services faster on the service end. svn:r4772
This commit is contained in:
parent
d1c094637d
commit
87fcd60aa2
@ -331,17 +331,9 @@ circuit_predict_and_launch_new(void)
|
|||||||
int num=0, num_internal=0, num_uptime_internal=0;
|
int num=0, num_internal=0, num_uptime_internal=0;
|
||||||
int hidserv_needs_uptime=0, hidserv_needs_capacity=1;
|
int hidserv_needs_uptime=0, hidserv_needs_capacity=1;
|
||||||
int port_needs_uptime=0, port_needs_capacity=1;
|
int port_needs_uptime=0, port_needs_capacity=1;
|
||||||
int need_ports, need_hidserv;
|
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
||||||
/* check if we know of a port that's been requested recently
|
/* First, count how many of each type of circuit we have already. */
|
||||||
* 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);
|
|
||||||
|
|
||||||
for (circ=global_circuitlist;circ;circ = circ->next) {
|
for (circ=global_circuitlist;circ;circ = circ->next) {
|
||||||
if (!CIRCUIT_IS_ORIGIN(circ))
|
if (!CIRCUIT_IS_ORIGIN(circ))
|
||||||
continue;
|
continue;
|
||||||
@ -358,21 +350,41 @@ circuit_predict_and_launch_new(void)
|
|||||||
num_uptime_internal++;
|
num_uptime_internal++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num < MAX_UNUSED_OPEN_CIRCUITS) {
|
/* If that's enough, then stop now. */
|
||||||
/* perhaps we want another */
|
if (num >= MAX_UNUSED_OPEN_CIRCUITS)
|
||||||
if (need_ports) {
|
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.",
|
log_fn(LOG_INFO,"Have %d clean circs (%d internal), need another exit circ.",
|
||||||
num, num_internal);
|
num, num_internal);
|
||||||
circuit_launch_by_router(CIRCUIT_PURPOSE_C_GENERAL, NULL,
|
circuit_launch_by_router(CIRCUIT_PURPOSE_C_GENERAL, NULL,
|
||||||
port_needs_uptime, port_needs_capacity, 0);
|
port_needs_uptime, port_needs_capacity, 0);
|
||||||
} else if (need_hidserv &&
|
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_uptime_internal<2 && hidserv_needs_uptime) ||
|
||||||
num_internal<2)) {
|
num_internal<2)) {
|
||||||
log_fn(LOG_INFO,"Have %d clean circs (%d uptime-internal, %d internal),"
|
log_fn(LOG_INFO,"Have %d clean circs (%d uptime-internal, %d internal),"
|
||||||
" need another hidserv circ.", num, num_uptime_internal, num_internal);
|
" need another hidserv circ.", num, num_uptime_internal, num_internal);
|
||||||
circuit_launch_by_router(CIRCUIT_PURPOSE_C_GENERAL, NULL,
|
circuit_launch_by_router(CIRCUIT_PURPOSE_C_GENERAL, NULL,
|
||||||
hidserv_needs_uptime, hidserv_needs_capacity, 1);
|
hidserv_needs_uptime, hidserv_needs_capacity, 1);
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -904,7 +904,7 @@ spawn_enough_dnsworkers(void)
|
|||||||
|
|
||||||
while (num_dnsworkers < num_dnsworkers_needed) {
|
while (num_dnsworkers < num_dnsworkers_needed) {
|
||||||
if (spawn_dnsworker() < 0) {
|
if (spawn_dnsworker() < 0) {
|
||||||
log(LOG_WARN,"spawn_enough_dnsworkers(): spawn failed!");
|
log_fn(LOG_WARN,"spawn failed!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
num_dnsworkers++;
|
num_dnsworkers++;
|
||||||
|
@ -1846,6 +1846,7 @@ int rend_cache_store(const char *desc, size_t desc_len);
|
|||||||
|
|
||||||
/********************************* rendservice.c ***************************/
|
/********************************* rendservice.c ***************************/
|
||||||
|
|
||||||
|
int num_rend_services(void);
|
||||||
int rend_config_services(or_options_t *options, int validate_only);
|
int rend_config_services(or_options_t *options, int validate_only);
|
||||||
int rend_service_load_keys(void);
|
int rend_service_load_keys(void);
|
||||||
void rend_services_init(void);
|
void rend_services_init(void);
|
||||||
|
@ -61,6 +61,13 @@ typedef struct rend_service_t {
|
|||||||
*/
|
*/
|
||||||
static smartlist_t *rend_service_list = NULL;
|
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>.
|
/** Release the storage held by <b>service</b>.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
|
@ -748,8 +748,11 @@ rep_hist_note_used_hidserv(time_t now, int need_uptime, int need_capacity)
|
|||||||
int
|
int
|
||||||
rep_hist_get_predicted_hidserv(time_t now, int *need_uptime, int *need_capacity)
|
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_time = now;
|
||||||
|
predicted_hidserv_uptime_time = now;
|
||||||
|
predicted_hidserv_capacity_time = now;
|
||||||
|
}
|
||||||
if (predicted_hidserv_time + PREDICTED_CIRCS_RELEVANCE_TIME < now)
|
if (predicted_hidserv_time + PREDICTED_CIRCS_RELEVANCE_TIME < now)
|
||||||
return 0; /* too long ago */
|
return 0; /* too long ago */
|
||||||
if (predicted_hidserv_uptime_time + PREDICTED_CIRCS_RELEVANCE_TIME < now)
|
if (predicted_hidserv_uptime_time + PREDICTED_CIRCS_RELEVANCE_TIME < now)
|
||||||
|
Loading…
Reference in New Issue
Block a user