#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);
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) ||
FILE *cf;
char fname[256];
int i;
- const char *cmd;
int result = 0;
/* give reasonable values for each option. Defaults to zero. */
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) {
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;
}
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);
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.
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);
return 0;
case CACHE_STATE_VALID:
exitconn->addr = resolve->answer;
- return connection_exit_connect(exitconn);
+ return 1;
case CACHE_STATE_FAILED:
return -1;
}
}
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;
}
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)) ||
int MaxOnionsPending;
int NewCircuitPeriod;
int TotalBandwidth;
+ int NumCpus;
int Role;
int loglevel;
} or_options_t;
/********************************* config.c ***************************/
-const char *basename(const char *filename);
-
/* open configuration file for reading */
FILE *config_open(const unsigned char *filename);
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 */