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

[or-cvs] r9081: Implement dns server reply retry logic. (in tor/trunk: . doc src/or)



Author: nickm
Date: 2006-12-11 21:56:23 -0500 (Mon, 11 Dec 2006)
New Revision: 9081

Modified:
   tor/trunk/
   tor/trunk/doc/TODO
   tor/trunk/src/or/eventdns.c
Log:
 r11492@Kushana:  nickm | 2006-12-11 12:30:23 -0500
 Implement dns server reply retry logic.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/branches/eventdns [r11492] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/doc/TODO
===================================================================
--- tor/trunk/doc/TODO	2006-12-12 02:56:20 UTC (rev 9080)
+++ tor/trunk/doc/TODO	2006-12-12 02:56:23 UTC (rev 9081)
@@ -95,16 +95,18 @@
       - Teach evdns to be able to listen for requests to be processed.
         . Design interface.
           - Rename stuff; current names suck.
-        . Design backend.
-        - Implement
-          . Listen for questions
+        o Design backend.
+        . Implement
+          o Listen for questions
           o Parse questions, tell user code
           o Let user code tell us the answer
           o Generate responses
           o Send responses to client
           o Queue responses when we see EAGAIN
-          - Retry responses after a while
+          o Retry responses after a while
           o Be efficient about labels.
+          - Comment everything.
+          - Clean up XXXX items
           - Test
 d         - Be more memory-efficient
       - Add some kind of general question/response API so libevent can be

Modified: tor/trunk/src/or/eventdns.c
===================================================================
--- tor/trunk/src/or/eventdns.c	2006-12-12 02:56:20 UTC (rev 9080)
+++ tor/trunk/src/or/eventdns.c	2006-12-12 02:56:23 UTC (rev 9081)
@@ -1243,8 +1243,19 @@
 static void
 server_port_flush(struct evdns_server_port *port)
 {
-	// XXXX Writeme.
-	(void)port;
+	while (port->pending_replies) {
+		struct server_request *req = port->pending_replies;
+		int r = sendto(port->socket, req->response, req->response_len, 0,
+			   (struct sockaddr*) &req->addr, req->addrlen);
+		if (r < 0) // handle errror XXXX
+			return;
+		evdns_server_request_free(req);
+	}
+
+	(void) event_del(&port->event);
+	event_set(&port->event, port->socket, EV_READ | EV_PERSIST,
+			  server_port_ready_callback, port);
+	event_add(&port->event, NULL); // handle error. XXXX
 }
 
 // set if we are waiting for the ability to write to this server.
@@ -1671,34 +1682,43 @@
 evdns_request_respond(struct evdns_server_request *_req, int flags)
 {
 	struct server_request *req = TO_SERVER_REQUEST(_req);
+	struct evdns_server_port *port = req->port;
 	int r;
 	if (!req->response) {
 		if ((r = evdns_request_response_format(req, flags))<0)
 			return r;
 	}
 
-	r = sendto(req->port->socket, req->response, req->response_len, 0,
+	r = sendto(port->socket, req->response, req->response_len, 0,
 			   (struct sockaddr*) &req->addr, req->addrlen);
 	if (r<0) {
-		int err = last_error(req->port->socket);
+		int err = last_error(port->socket);
 		if (! error_is_eagain(err))
 			return -1;
 
-		if (req->port->pending_replies) {
-			req->prev_pending = req->port->pending_replies->prev_pending;
-			req->next_pending = req->port->pending_replies;
+		if (port->pending_replies) {
+			req->prev_pending = port->pending_replies->prev_pending;
+			req->next_pending = port->pending_replies;
 			req->prev_pending->next_pending =
 				req->next_pending->prev_pending = req;
 		} else {
 			req->prev_pending = req->next_pending = req;
-			req->port->pending_replies = req;
-			req->port->choaked = 1;
+			port->pending_replies = req;
+			port->choaked = 1;
+
+			(void) event_del(&port->event);
+			event_set(&port->event, port->socket, EV_READ | EV_WRITE | EV_PERSIST, server_port_ready_callback, port);
+
+			event_add(&port->event, NULL); // handle error. XXXX
 		}
-		return 0;
+
+		return 1;
 	}
-	// XXXX process pending replies.
+	evdns_server_request_free(req);
 
-	evdns_server_request_free(req);
+	if (req->port->pending_replies)
+		server_port_flush(port);
+
 	return 0;
 }