From 4b162fd1f41c53e52746628b8dec41450e72b38a Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 13 Jun 2007 19:50:18 +0000 Subject: [PATCH] r13401@catbus: nickm | 2007-06-13 15:50:16 -0400 Add dnsport connection to the global connection list. (Bug found by mwenge.) svn:r10592 --- ChangeLog | 3 +++ src/or/dnsserv.c | 2 ++ src/or/main.c | 19 ++++++++++++------- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5790e56efc..1e7b5d530d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,9 @@ Changes in version 0.2.0.3-alpha - 2007-??-?? o Minor bugfixes (dns): - Fix a crash when DNSPort is set more than once. (Patch from Robert Hogan.) [Bugfix on 0.2.0.2-alpha] + - Add DNSPort connections to the global connection list, so that we + can time them out correctly. (Bug found by mwenge) [Bugfix on + 0.2.0.2-alpha] o Minor bugfixes (hidden services): - Stop tearing down the whole circuit when the user asks for a diff --git a/src/or/dnsserv.c b/src/or/dnsserv.c index ee3cd473cf..659d264a7b 100644 --- a/src/or/dnsserv.c +++ b/src/or/dnsserv.c @@ -122,6 +122,8 @@ evdns_server_callback(struct evdns_server_request *req, void *_data) conn->dns_server_request = req; + connection_add(TO_CONN(conn)); + /* Now, throw the connection over to get rewritten (which will answer it * immediately if it's in the cache, or completely bogus, or automapped), * and then attached to a circuit. */ diff --git a/src/or/main.c b/src/or/main.c index 73a0401178..5c7fcb5476 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -162,18 +162,23 @@ int connection_add(connection_t *conn) { tor_assert(conn); - tor_assert(conn->s >= 0 || conn->linked); + tor_assert(conn->s >= 0 || + conn->linked || + (conn->type == CONN_TYPE_AP && + TO_EDGE_CONN(conn)->dns_server_request)); tor_assert(conn->conn_array_index == -1); /* can only connection_add once */ conn->conn_array_index = smartlist_len(connection_array); smartlist_add(connection_array, conn); - conn->read_event = tor_malloc_zero(sizeof(struct event)); - conn->write_event = tor_malloc_zero(sizeof(struct event)); - event_set(conn->read_event, conn->s, EV_READ|EV_PERSIST, - conn_read_callback, conn); - event_set(conn->write_event, conn->s, EV_WRITE|EV_PERSIST, - conn_write_callback, conn); + if (conn->s >= 0) { + conn->read_event = tor_malloc_zero(sizeof(struct event)); + conn->write_event = tor_malloc_zero(sizeof(struct event)); + event_set(conn->read_event, conn->s, EV_READ|EV_PERSIST, + conn_read_callback, conn); + event_set(conn->write_event, conn->s, EV_WRITE|EV_PERSIST, + conn_write_callback, conn); + } log_debug(LD_NET,"new conn type %s, socket %d, n_conns %d.", conn_type_to_string(conn->type), conn->s,