[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] start refactoring dnsworker so testing won"t be so darn hard
- To: or-cvs@freehaven.net
- Subject: [or-cvs] start refactoring dnsworker so testing won"t be so darn hard
- From: arma@seul.org (Roger Dingledine)
- Date: Wed, 13 Aug 2003 23:52:53 -0400 (EDT)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Wed, 13 Aug 2003 23:53:06 -0400
- Reply-to: or-dev@freehaven.net
- Sender: owner-or-cvs@freehaven.net
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or
Modified Files:
config.c connection_exit.c dns.c onion.c or.h routers.c
Log Message:
start refactoring dnsworker so testing won't be so darn hard
add NumCpus config variable in preparation for cpuworkers
hardcode /etc/torrc path for config (simplifies win32 port)
improve exit policy debugging during router entry parsing
Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- config.c 12 Aug 2003 03:08:40 -0000 1.37
+++ config.c 14 Aug 2003 03:52:50 -0000 1.38
@@ -4,16 +4,6 @@
#include "or.h"
-const char *basename(const char *filename) {
- char *result;
- /* XXX This won't work on windows. */
- result = strrchr(filename, '/');
- if (result)
- return result;
- else
- return filename;
-}
-
/* open configuration file for reading */
FILE *config_open(const unsigned char *filename) {
assert(filename);
@@ -189,6 +179,7 @@
config_compare(list, "MaxOnionsPending",CONFIG_TYPE_INT, &options->MaxOnionsPending) ||
config_compare(list, "NewCircuitPeriod",CONFIG_TYPE_INT, &options->NewCircuitPeriod) ||
config_compare(list, "TotalBandwidth", CONFIG_TYPE_INT, &options->TotalBandwidth) ||
+ config_compare(list, "NumCpus", CONFIG_TYPE_INT, &options->NumCpus) ||
config_compare(list, "OnionRouter", CONFIG_TYPE_BOOL, &options->OnionRouter) ||
config_compare(list, "Daemon", CONFIG_TYPE_BOOL, &options->Daemon) ||
@@ -214,7 +205,6 @@
FILE *cf;
char fname[256];
int i;
- const char *cmd;
int result = 0;
/* give reasonable values for each option. Defaults to zero. */
@@ -228,11 +218,12 @@
options->MaxOnionsPending = 10;
options->NewCircuitPeriod = 60; /* once a minute */
options->TotalBandwidth = 800000; /* at most 800kB/s total sustained incoming */
+ options->NumCpus = 1;
// options->ReconnectPeriod = 6001;
/* get config lines from /etc/torrc and assign them */
- cmd = basename(argv[0]);
- snprintf(fname,256,"/etc/%src",cmd);
+#define rcfile "torrc"
+ snprintf(fname,256,"/etc/%s",rcfile);
cf = config_open(fname);
if(cf) {
Index: connection_exit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_exit.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- connection_exit.c 12 Aug 2003 03:08:41 -0000 1.37
+++ connection_exit.c 14 Aug 2003 03:52:51 -0000 1.38
@@ -51,13 +51,17 @@
circ->n_streams = n_stream;
/* send it off to the gethostbyname farm */
- if(dns_resolve(n_stream) < 0) {
- log_fn(LOG_DEBUG,"Couldn't queue resolve request.");
- connection_remove(n_stream);
- connection_free(n_stream);
- return 0;
+ switch(dns_resolve(n_stream)) {
+ case 1: /* resolve worked */
+ if(connection_exit_connect(n_stream) >= 0)
+ return 0;
+ /* else fall through */
+ case -1: /* resolve failed */
+ log_fn(LOG_DEBUG,"Couldn't queue resolve request.");
+ connection_remove(n_stream);
+ connection_free(n_stream);
+ case 0: /* resolve added to pending list */
}
-
return 0;
}
Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dns.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- dns.c 13 Aug 2003 22:38:46 -0000 1.20
+++ dns.c 14 Aug 2003 03:52:51 -0000 1.21
@@ -19,6 +19,7 @@
int num_workers=0;
int num_workers_busy=0;
+static void purge_expired_resolves(uint32_t now);
static int dns_assign_to_worker(connection_t *exitconn);
static void dns_found_answer(char *question, uint32_t answer);
int dnsworker_main(void *data);
@@ -65,9 +66,26 @@
static struct cached_resolve *oldest_cached_resolve = NULL; /* linked list, */
static struct cached_resolve *newest_cached_resolve = NULL; /* oldest to newest */
+static void purge_expired_resolves(uint32_t now) {
+ struct cached_resolve *resolve;
+
+ /* this is fast because the linked list
+ * oldest_cached_resolve is ordered by when they came in.
+ */
+ while(oldest_cached_resolve && (oldest_cached_resolve->expire < now)) {
+ resolve = oldest_cached_resolve;
+ log(LOG_DEBUG,"Forgetting old cached resolve (expires %d)", resolve->expire);
+ oldest_cached_resolve = resolve->next;
+ if(!oldest_cached_resolve) /* if there are no more, */
+ newest_cached_resolve = NULL; /* then make sure the list's tail knows that too */
+ SPLAY_REMOVE(cache_tree, &cache_root, resolve);
+ free(resolve);
+ }
+}
+
/* See if the question 'exitconn->address' has been answered. if so,
- * if resolve valid, put it into exitconn->addr and exec to
- * connection_exit_connect. If resolve failed, return -1.
+ * if resolve valid, put it into exitconn->addr and return 1.
+ * If resolve failed, return -1.
*
* Else, if seen before and pending, add conn to the pending list,
* and return 0.
@@ -82,18 +100,8 @@
uint32_t now = time(NULL);
/* first take this opportunity to see if there are any expired
- * resolves in the tree. this is fast because the linked list
- * oldest_cached_resolve is ordered by when they came in.
- */
- while(oldest_cached_resolve && (oldest_cached_resolve->expire < now)) {
- resolve = oldest_cached_resolve;
- log(LOG_DEBUG,"Forgetting old cached resolve (expires %d)", resolve->expire);
- oldest_cached_resolve = resolve->next;
- if(!oldest_cached_resolve) /* if there are no more, */
- newest_cached_resolve = NULL; /* then make sure the list's tail knows that too */
- SPLAY_REMOVE(cache_tree, &cache_root, resolve);
- free(resolve);
- }
+ resolves in the tree.*/
+ purge_expired_resolves(now);
/* now check the tree to see if 'question' is already there. */
strncpy(search.question, exitconn->address, MAX_ADDRESSLEN);
@@ -109,7 +117,7 @@
return 0;
case CACHE_STATE_VALID:
exitconn->addr = resolve->answer;
- return connection_exit_connect(exitconn);
+ return 1;
case CACHE_STATE_FAILED:
return -1;
}
Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- onion.c 30 Jul 2003 19:12:02 -0000 1.59
+++ onion.c 14 Aug 2003 03:52:51 -0000 1.60
@@ -226,7 +226,7 @@
}
if(num_acceptable_routers < *routelen) {
- log(LOG_DEBUG,"new_route(): Cutting routelen from %d to %d.",*routelen, num_acceptable_routers);
+ log(LOG_NOTICE,"new_route(): Cutting routelen from %d to %d.",*routelen, num_acceptable_routers);
*routelen = num_acceptable_routers;
}
@@ -246,7 +246,7 @@
return NULL;
}
- choice = choice % (rarray_len);
+ choice = choice % rarray_len;
log(LOG_DEBUG,"new_route(): Contemplating router %u.",choice);
if(choice == oldchoice ||
(oldchoice < rarray_len && !crypto_pk_cmp_keys(rarray[choice]->pkey, rarray[oldchoice]->pkey)) ||
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -d -r1.105 -r1.106
--- or.h 12 Aug 2003 15:08:51 -0000 1.105
+++ or.h 14 Aug 2003 03:52:51 -0000 1.106
@@ -456,6 +456,7 @@
int MaxOnionsPending;
int NewCircuitPeriod;
int TotalBandwidth;
+ int NumCpus;
int Role;
int loglevel;
} or_options_t;
@@ -557,8 +558,6 @@
void command_process_connected_cell(cell_t *cell, connection_t *conn);
/********************************* config.c ***************************/
-
-const char *basename(const char *filename);
/* open configuration file for reading */
FILE *config_open(const unsigned char *filename);
Index: routers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routers.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- routers.c 12 Aug 2003 08:18:13 -0000 1.39
+++ routers.c 14 Aug 2003 03:52:51 -0000 1.40
@@ -842,8 +842,9 @@
newe->address = strdup(arg);
newe->port = strdup(colon+1);
- log(LOG_DEBUG,"router_add_exit_policy(): type %d, address '%s', port '%s'.",
- newe->policy_type, newe->address, newe->port);
+ log(LOG_DEBUG,"router_add_exit_policy(): %s %s:%s",
+ newe->policy_type == EXIT_POLICY_REJECT ? "reject" : "accept",
+ newe->address, newe->port);
/* now link newe onto the end of exit_policy */