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

[or-cvs] write_to_buf != connection_write_to_buf. Also, add a conne...



Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv11380/src/or

Modified Files:
	connection.c directory.c dirserv.c or.h 
Log Message:
write_to_buf != connection_write_to_buf.  Also, add a connection_write_to_buf_zlib wrapper that sucks.

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection.c,v
retrieving revision 1.455
retrieving revision 1.456
diff -u -p -d -r1.455 -r1.456
--- connection.c	18 Jun 2006 07:38:55 -0000	1.455
+++ connection.c	18 Jun 2006 08:46:55 -0000	1.456
@@ -1595,6 +1595,43 @@ connection_write_to_buf(const char *stri
   conn->outbuf_flushlen += len;
 }
 
+void
+connection_write_to_buf_zlib(connection_t *conn,
+                             tor_zlib_state_t *state,
+                             const char *data, size_t data_len,
+                             int done)
+{
+  int r;
+  if (!data_len)
+    return;
+  /* if it's marked for close, only allow write if we mean to flush it */
+  if (conn->marked_for_close && !conn->hold_open_until_flushed)
+    return;
+
+  /* XXXX TOO much duplicate code! XXXX012NM */
+  CONN_LOG_PROTECT(conn, r = write_to_buf_zlib(
+                                conn->outbuf, state, data, data_len,
+                                done));
+  if (r < 0) {
+    if (CONN_IS_EDGE(conn)) {
+      /* if it failed, it means we have our package/delivery windows set
+         wrong compared to our max outbuf size. close the whole circuit. */
+      log_warn(LD_NET,
+               "write_to_buf failed. Closing circuit (fd %d).", conn->s);
+      circuit_mark_for_close(circuit_get_by_edge_conn(conn),
+                             END_CIRC_REASON_INTERNAL);
+    } else {
+      log_warn(LD_NET,
+               "write_to_buf failed. Closing connection (fd %d).", conn->s);
+      connection_mark_for_close(conn);
+    }
+    return;
+  }
+
+  connection_start_writing(conn);
+  conn->outbuf_flushlen += data_len;
+}
+
 /** Return the conn to addr/port that has the most recent
  * timestamp_created, or NULL if no such conn exists. */
 connection_t *

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.379
retrieving revision 1.380
diff -u -p -d -r1.379 -r1.380
--- directory.c	18 Jun 2006 08:16:05 -0000	1.379
+++ directory.c	18 Jun 2006 08:46:55 -0000	1.380
@@ -1413,7 +1413,7 @@ directory_handle_command_get(connection_
     connection_write_to_buf(tmp, strlen(tmp), conn);
     conn->cached_dir = d;
     conn->cached_dir_offset = 0;
-    if (deflated)
+    if (! deflated)
       conn->zlib_state = tor_zlib_new(0, ZLIB_METHOD);
     ++d->refcnt;
 

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.337
retrieving revision 1.338
diff -u -p -d -r1.337 -r1.338
--- dirserv.c	18 Jun 2006 08:19:35 -0000	1.337
+++ dirserv.c	18 Jun 2006 08:46:55 -0000	1.338
@@ -1771,19 +1771,21 @@ connection_dirserv_add_servers_to_outbuf
     if (!sd)
       continue;
     if (conn->zlib_state) {
-      write_to_buf_zlib(conn->outbuf, conn->zlib_state,
+      connection_write_to_buf_zlib(
+                        conn, conn->zlib_state,
                         sd->signed_descriptor_body, sd->signed_descriptor_len,
                         0);
     } else {
-      write_to_buf(sd->signed_descriptor_body, sd->signed_descriptor_len,
-                   conn->outbuf);
+      connection_write_to_buf(sd->signed_descriptor_body,
+                              sd->signed_descriptor_len,
+                              conn);
     }
   }
 
   if (!smartlist_len(conn->fingerprint_stack)) {
     /* We just wrote the last one; finish up. */
     if (conn->zlib_state) {
-      write_to_buf_zlib(conn->outbuf, conn->zlib_state, "", 0, 1);
+      connection_write_to_buf_zlib(conn, conn->zlib_state, "", 0, 1);
       tor_zlib_free(conn->zlib_state);
       conn->zlib_state = NULL;
     }
@@ -1809,18 +1811,18 @@ connection_dirserv_add_dir_bytes_to_outb
     bytes = remaining;
 
   if (conn->zlib_state) {
-    write_to_buf_zlib(conn->outbuf, conn->zlib_state,
-                      conn->cached_dir->dir_z + conn->cached_dir_offset,
-                      bytes, bytes == remaining);
+    connection_write_to_buf_zlib(conn, conn->zlib_state,
+                             conn->cached_dir->dir_z + conn->cached_dir_offset,
+                             bytes, bytes == remaining);
   } else {
-    write_to_buf(conn->cached_dir->dir_z + conn->cached_dir_offset,
-                 bytes, conn->outbuf);
+    connection_write_to_buf(conn->cached_dir->dir_z + conn->cached_dir_offset,
+                            bytes, conn);
   }
   conn->cached_dir_offset += bytes;
   if (bytes == (int)conn->cached_dir->dir_z_len) {
     /* We just wrote the last one; finish up. */
     if (conn->zlib_state) {
-      write_to_buf_zlib(conn->outbuf, conn->zlib_state, "", 0, 1);
+      connection_write_to_buf_zlib(conn, conn->zlib_state, "", 0, 1);
       tor_zlib_free(conn->zlib_state);
       conn->zlib_state = NULL;
     }

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.842
retrieving revision 1.843
diff -u -p -d -r1.842 -r1.843
--- or.h	18 Jun 2006 07:55:04 -0000	1.842
+++ or.h	18 Jun 2006 08:46:55 -0000	1.843
@@ -1679,6 +1679,10 @@ int connection_handle_write(connection_t
 void _connection_controller_force_write(connection_t *conn);
 void connection_write_to_buf(const char *string, size_t len,
                              connection_t *conn);
+void connection_write_to_buf_zlib(connection_t *conn,
+                                  tor_zlib_state_t *state,
+                                  const char *data, size_t data_len,
+                                  int done);
 
 connection_t *connection_or_exact_get_by_addr_port(uint32_t addr,
                                                    uint16_t port);