[or-cvs] r11183: Some work on implementing bufferevents for directory connect (in tor/branches/urz-bufferevents: . src/or)

Urz at seul.org Urz at seul.org
Sun Aug 19 05:51:10 UTC 2007


Author: Urz
Date: 2007-08-19 01:51:10 -0400 (Sun, 19 Aug 2007)
New Revision: 11183

Modified:
   tor/branches/urz-bufferevents/autogen.sh
   tor/branches/urz-bufferevents/src/or/connection.c
   tor/branches/urz-bufferevents/src/or/or.h
Log:
Some work on implementing bufferevents for directory connections. Spent a lot of time trying to make it build with altered libevent but still no luck. It also looks like we will need to keep inbuf and outbuf at least until we decide what to do with rate limiting.

Modified: tor/branches/urz-bufferevents/autogen.sh
===================================================================
--- tor/branches/urz-bufferevents/autogen.sh	2007-08-19 05:04:56 UTC (rev 11182)
+++ tor/branches/urz-bufferevents/autogen.sh	2007-08-19 05:51:10 UTC (rev 11183)
@@ -3,5 +3,6 @@
 aclocal && \
 	autoheader && \
 	autoconf && \
-	automake --add-missing --copy && \
-	if test x$NOCONF = x ; then ./configure "$@"; fi
+	automake --add-missing --copy 
+#&& \
+#if test x$NOCONF = x ; then ./configure "$@"; fi

Modified: tor/branches/urz-bufferevents/src/or/connection.c
===================================================================
--- tor/branches/urz-bufferevents/src/or/connection.c	2007-08-19 05:04:56 UTC (rev 11182)
+++ tor/branches/urz-bufferevents/src/or/connection.c	2007-08-19 05:51:10 UTC (rev 11183)
@@ -194,6 +194,8 @@
   conn->magic = magic;
   conn->s = -1; /* give it a default of 'not used' */
   conn->conn_array_index = -1; /* also default to 'not used' */
+  
+  conn->bufev = NULL  
 
   conn->type = type;
   conn->socket_family = socket_family;
@@ -292,6 +294,10 @@
            (int)buf_datalen(conn->inbuf), (int)buf_datalen(conn->outbuf));
     // tor_assert(!buf_datalen(conn->outbuf)); /*XXXX020 remove me.*/
   }
+  
+  if(conn->bufev != NULL) {
+    bufferevent_close_and_free(conn->bufev);
+  }
 
   if (!connection_is_listener(conn)) {
     buf_free(conn->inbuf);
@@ -1843,6 +1849,7 @@
   int result, at_most = *max_to_read;
   size_t bytes_in_buf, more_to_read;
   size_t n_read = 0, n_written = 0;
+  char *copybuf;
 
   if (at_most == -1) { /* we need to initialize it */
     /* how many bytes are we allowed to read? */
@@ -1938,17 +1945,29 @@
     n_read = (size_t) result;
   } else {
     /* !connection_speaks_cells, !conn->linked_conn. */
-    int reached_eof = 0;
-    CONN_LOG_PROTECT(conn,
-        result = read_to_buf(conn->s, at_most, conn->inbuf, &reached_eof));
-    if (reached_eof)
-      conn->inbuf_reached_eof = 1;
+    if(conn->type == CONN_TYPE_DIR) { 
+      copybuf = tor_malloc(max_to_write);
+      result = bufferevent_read(conn->bufev, copybuf, at_most);
+      //fetch_from_buf(copybuf, max_to_write, conn->outbuf);
+      
+      if(write_to_buf(copybuf, result, conn->inbuf) == -1) {
+        printf("Write to buffer failed.\n");
+      }
+      tor_free(copybuf);
+      copybuf = NULL;
+    } else {
+        int reached_eof = 0;
+        CONN_LOG_PROTECT(conn,
+            result = read_to_buf(conn->s, at_most, conn->inbuf, &reached_eof));
+        if (reached_eof)
+          conn->inbuf_reached_eof = 1;
 
 //  log_fn(LOG_DEBUG,"read_to_buf returned %d.",read_result);
 
-    if (result < 0)
-      return -1;
-    n_read = (size_t) result;
+        if (result < 0)
+          return -1;
+        n_read = (size_t) result;
+    }
   }
 
   if (n_read > 0) { /* change *max_to_read */
@@ -2029,6 +2048,7 @@
   socklen_t len=sizeof(e);
   int result;
   int max_to_write;
+  char *copybuf;
   time_t now = time(NULL);
   size_t n_read = 0, n_written = 0;
 
@@ -2128,9 +2148,23 @@
     log_debug(LD_GENERAL, "After TLS write of %d: %ld read, %ld written",
               result, (long)n_read, (long)n_written);
   } else {
-    CONN_LOG_PROTECT(conn,
+    if(conn->type == CONN_TYPE_DIR) { 
+      copybuf = tor_malloc(max_to_write);
+      max_to_write = fetch_from_buf(copybuf, max_to_write, conn->outbuf);
+      
+      while(max_to_write > 0) {
+        result = bufferevent_write(conn->bufev, copybuf, max_to_write);
+        if(result > 0) {
+          max_to_write -= result;
+        }
+      }
+      tor_free(copybuf);
+      copybuf = NULL;
+    } else {
+      CONN_LOG_PROTECT(conn,
              result = flush_buf(conn->s, conn->outbuf,
                                 max_to_write, &conn->outbuf_flushlen));
+    }
     if (result < 0) {
       if (CONN_IS_EDGE(conn))
         connection_edge_end_errno(TO_EDGE_CONN(conn));

Modified: tor/branches/urz-bufferevents/src/or/or.h
===================================================================
--- tor/branches/urz-bufferevents/src/or/or.h	2007-08-19 05:04:56 UTC (rev 11182)
+++ tor/branches/urz-bufferevents/src/or/or.h	2007-08-19 05:51:10 UTC (rev 11183)
@@ -783,6 +783,7 @@
    * stop requiring it. */
   unsigned int chosen_exit_optional:1;
 
+  bufferevent *bufev; /**< Bufferevent for connection types which have been converted */
   int s; /**< Our socket; -1 if this connection is closed, or has no
           * socket. */
   int conn_array_index; /**< Index into the global connection array. */



More information about the tor-commits mailing list