Commit 05a8c264 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

overhaul the dns farm: cut its size in half

i've eliminated the master dns process, so now the workers just
act like regular connections and are handled by the normal pollarray.

everything seems to still work. ;)


svn:r327
parent cb8ebfcf
...@@ -545,7 +545,7 @@ int connection_process_inbuf(connection_t *conn) { ...@@ -545,7 +545,7 @@ int connection_process_inbuf(connection_t *conn) {
return connection_edge_process_inbuf(conn); return connection_edge_process_inbuf(conn);
case CONN_TYPE_DIR: case CONN_TYPE_DIR:
return connection_dir_process_inbuf(conn); return connection_dir_process_inbuf(conn);
case CONN_TYPE_DNSMASTER: case CONN_TYPE_DNSWORKER:
return connection_dns_process_inbuf(conn); return connection_dns_process_inbuf(conn);
default: default:
log(LOG_DEBUG,"connection_process_inbuf() got unexpected conn->type."); log(LOG_DEBUG,"connection_process_inbuf() got unexpected conn->type.");
...@@ -686,7 +686,7 @@ int connection_finished_flushing(connection_t *conn) { ...@@ -686,7 +686,7 @@ int connection_finished_flushing(connection_t *conn) {
return connection_edge_finished_flushing(conn); return connection_edge_finished_flushing(conn);
case CONN_TYPE_DIR: case CONN_TYPE_DIR:
return connection_dir_finished_flushing(conn); return connection_dir_finished_flushing(conn);
case CONN_TYPE_DNSMASTER: case CONN_TYPE_DNSWORKER:
return connection_dns_finished_flushing(conn); return connection_dns_finished_flushing(conn);
default: default:
log(LOG_DEBUG,"connection_finished_flushing() got unexpected conn->type."); log(LOG_DEBUG,"connection_finished_flushing() got unexpected conn->type.");
......
This diff is collapsed.
...@@ -168,6 +168,18 @@ connection_t *connection_get_by_type(int type) { ...@@ -168,6 +168,18 @@ connection_t *connection_get_by_type(int type) {
return NULL; return NULL;
} }
connection_t *connection_get_by_type_state(int type, int state) {
int i;
connection_t *conn;
for(i=0;i<nfds;i++) {
conn = connection_array[i];
if(conn->type == type && conn->state == state)
return conn;
}
return NULL;
}
void connection_watch_events(connection_t *conn, short events) { void connection_watch_events(connection_t *conn, short events) {
assert(conn && conn->poll_index < nfds); assert(conn && conn->poll_index < nfds);
...@@ -782,17 +794,13 @@ int tor_main(int argc, char *argv[]) { ...@@ -782,17 +794,13 @@ int tor_main(int argc, char *argv[]) {
exit(1); exit(1);
log(options.loglevel,NULL); /* assign logging severity level from options */ log(options.loglevel,NULL); /* assign logging severity level from options */
if (options.Daemon) if(options.Daemon)
daemonize(); daemonize();
if(options.OnionRouter) { /* only spawn dns handlers if we're a router */ if(options.OnionRouter) { /* only spawn dns handlers if we're a router */
if(dns_master_start() < 0) { dns_init(); /* initialize the dns resolve tree, and spawn workers */
log(LOG_ERR,"main(): We're running without a dns handler. Bad news.");
}
} }
init_cache_tree(); /* initialize the dns resolve tree */
signal (SIGINT, catch); /* catch kills so we can exit cleanly */ signal (SIGINT, catch); /* catch kills so we can exit cleanly */
signal (SIGTERM, catch); signal (SIGTERM, catch);
signal (SIGUSR1, catch); /* to dump stats to stdout */ signal (SIGUSR1, catch); /* to dump stats to stdout */
......
...@@ -62,11 +62,12 @@ ...@@ -62,11 +62,12 @@
#define CONN_TYPE_AP 7 #define CONN_TYPE_AP 7
#define CONN_TYPE_DIR_LISTENER 8 #define CONN_TYPE_DIR_LISTENER 8
#define CONN_TYPE_DIR 9 #define CONN_TYPE_DIR 9
#define CONN_TYPE_DNSMASTER 10 #define CONN_TYPE_DNSWORKER 10
#define LISTENER_STATE_READY 0 #define LISTENER_STATE_READY 0
#define DNSMASTER_STATE_OPEN 0 #define DNSWORKER_STATE_IDLE 0
#define DNSWORKER_STATE_BUSY 1
/* how to read these states: /* how to read these states:
* foo_CONN_STATE_bar_baz: * foo_CONN_STATE_bar_baz:
...@@ -83,7 +84,7 @@ ...@@ -83,7 +84,7 @@
#define OR_CONN_STATE_SERVER_NONCE_WAIT 8 /* waiting for confirmation of nonce */ #define OR_CONN_STATE_SERVER_NONCE_WAIT 8 /* waiting for confirmation of nonce */
#define OR_CONN_STATE_OPEN 9 /* ready to send/receive cells. */ #define OR_CONN_STATE_OPEN 9 /* ready to send/receive cells. */
#define EXIT_CONN_STATE_RESOLVING 0 /* waiting for response from dnsmaster */ #define EXIT_CONN_STATE_RESOLVING 0 /* waiting for response from dns farm */
#define EXIT_CONN_STATE_CONNECTING 1 /* waiting for connect() to finish */ #define EXIT_CONN_STATE_CONNECTING 1 /* waiting for connect() to finish */
#define EXIT_CONN_STATE_OPEN 2 #define EXIT_CONN_STATE_OPEN 2
#if 0 #if 0
...@@ -267,6 +268,9 @@ struct connection_t { ...@@ -267,6 +268,9 @@ struct connection_t {
/* Used while negotiating OR/OR connections */ /* Used while negotiating OR/OR connections */
char nonce[8]; char nonce[8];
/* Used by worker connections */
int num_processed;
}; };
...@@ -646,7 +650,7 @@ int connection_dir_handle_listener_read(connection_t *conn); ...@@ -646,7 +650,7 @@ int connection_dir_handle_listener_read(connection_t *conn);
int connection_dns_finished_flushing(connection_t *conn); int connection_dns_finished_flushing(connection_t *conn);
int connection_dns_process_inbuf(connection_t *conn); int connection_dns_process_inbuf(connection_t *conn);
void init_cache_tree(void); void dns_init(void);
int dns_resolve(connection_t *exitconn); int dns_resolve(connection_t *exitconn);
int dns_master_start(void); int dns_master_start(void);
...@@ -664,6 +668,7 @@ connection_t *connection_twin_get_by_addr_port(uint32_t addr, uint16_t port); ...@@ -664,6 +668,7 @@ connection_t *connection_twin_get_by_addr_port(uint32_t addr, uint16_t port);
connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port); connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port);
connection_t *connection_get_by_type(int type); connection_t *connection_get_by_type(int type);
connection_t *connection_get_by_type_state(int type, int state);
void connection_watch_events(connection_t *conn, short events); void connection_watch_events(connection_t *conn, short events);
void connection_stop_reading(connection_t *conn); void connection_stop_reading(connection_t *conn);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment