[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r6976: Add functions to eventdns to allow detecting whether we have (in tor/trunk: . src/or)



Author: nickm
Date: 2006-08-04 14:26:13 -0400 (Fri, 04 Aug 2006)
New Revision: 6976

Modified:
   tor/trunk/
   tor/trunk/src/or/dns.c
   tor/trunk/src/or/eventdns.c
   tor/trunk/src/or/eventdns.h
Log:
 r7009@Kushana:  nickm | 2006-08-03 10:44:58 -0700
 Add functions to eventdns to allow detecting whether we have any nameservers configured, and to change the list of nameservers after initial configuration.



Property changes on: tor/trunk
___________________________________________________________________
Name: svk:merge
   - 1f724f9b-111a-0410-b636-93f1a77c1813:/local/or/tor/trunk:8207
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/eventdns:7008
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6950
   + 1f724f9b-111a-0410-b636-93f1a77c1813:/local/or/tor/trunk:8207
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/eventdns:7009
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6950

Modified: tor/trunk/src/or/dns.c
===================================================================
--- tor/trunk/src/or/dns.c	2006-08-04 18:24:41 UTC (rev 6975)
+++ tor/trunk/src/or/dns.c	2006-08-04 18:26:13 UTC (rev 6976)
@@ -563,7 +563,7 @@
  * <b>address</b> from the cache.
  */
 void
-dns_cancel_pending_resolve(char *address) //XXXX NM CHECKME.
+dns_cancel_pending_resolve(char *address)
 {
   pending_connection_t *pend;
   cached_resolve_t search;

Modified: tor/trunk/src/or/eventdns.c
===================================================================
--- tor/trunk/src/or/eventdns.c	2006-08-04 18:24:41 UTC (rev 6975)
+++ tor/trunk/src/or/eventdns.c	2006-08-04 18:26:13 UTC (rev 6976)
@@ -393,9 +393,11 @@
 {
 	return err == EAGAIN || err == WSAEWOULDBLOCK;
 }
+#define CLOSE_SOCKET(x) closesocket(x)
 #else
 #define last_error(sock) (errno)
 #define error_is_eagain(err) ((err) == EAGAIN)
+#define CLOSE_SOCKET(x) close(x)
 #endif
 
 #define ISSPACE(c) isspace((int)(unsigned char)(c))
@@ -1167,6 +1169,72 @@
 
 // exported function
 int
+eventdns_count_nameservers(void)
+{
+	const struct nameserver *server = server_head;
+	int n = 0;
+	if (!server)
+		return 0;
+	do {
+		++n;
+		server = server->next;
+	} while (server != server_head);
+	return n;
+}
+
+// exported function
+int
+eventdns_clear_nameservers_and_suspend(void)
+{
+	struct nameserver *server = server_head, *started_at = server_head;
+	struct request *req = req_head, *req_started_at = req_head;
+
+	if (!server)
+		return 0;
+	while (1) {
+		struct nameserver *next = server->next;
+		event_del(&server->event);
+		evtimer_del(&server->timeout_event);
+		if (server->socket >= 0)
+			CLOSE_SOCKET(server->socket);
+		free(server);
+		if (next == started_at)
+			break;
+		server = next;
+	}
+	server_head = NULL;
+
+	while (req) {
+		struct request *next = req->next;
+		req->next = req->prev = NULL;
+		req->tx_count = req->reissue_count = 0;
+		req->ns = NULL;
+		// ???? What to do about searches?
+		evtimer_del(&req->timeout_event);
+		req->trans_id = 0;
+		req->transmit_me = 0;
+
+		eventdns_request_insert(req, &req_waiting_head);
+		if (next == req_started_at)
+			break;
+		req = next;
+	}
+	req_head = NULL;
+
+	return 0;
+}
+
+
+// exported function
+int
+eventdns_resume(void)
+{
+	eventdns_requests_pump_waiting_queue();
+	return 0;
+}
+
+// exported function
+int
 eventdns_nameserver_add(unsigned long int address) {
 	// first check to see if we already have this nameserver
 
@@ -1209,6 +1277,8 @@
 	event_set(&ns->event, ns->socket, EV_READ | EV_PERSIST, nameserver_ready_callback, ns);
 	event_add(&ns->event, NULL);
 
+	log("Added nameserver %s", debug_ntoa(address));
+
 	// insert this nameserver into the list of them
 	if (!server_head) {
 		ns->next = ns->prev = ns;
@@ -1227,13 +1297,11 @@
 	return 0;
 
 out2:
-#ifdef MS_WINDOWS
-	closesocket(ns->socket);
-#else
-	close(ns->socket);
+	CLOSE_SOCKET(ns->socket);
 #endif
 out1:
 	free(ns);
+	log("Unable to add nameserver %s: error %d", debug_ntoa(address), err);
 	return err;
 }
 

Modified: tor/trunk/src/or/eventdns.h
===================================================================
--- tor/trunk/src/or/eventdns.h	2006-08-04 18:24:41 UTC (rev 6975)
+++ tor/trunk/src/or/eventdns.h	2006-08-04 18:26:13 UTC (rev 6976)
@@ -49,6 +49,9 @@
 typedef void (*eventdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg);
 
 int eventdns_nameserver_add(unsigned long int address);
+int eventdns_count_nameservers(void);
+int eventdns_clear_nameservers_and_suspend(void);
+int eventdns_resume(void);
 int eventdns_nameserver_ip_add(const char *ip_as_string);
 int eventdns_resolve(const char *name, int flags, eventdns_callback_type callback, void *ptr);
 int eventdns_resolv_conf_parse(int flags, const char *);