[or-cvs] [tor/master] Use connection_mark_and_flush consistently.

nickm at torproject.org nickm at torproject.org
Wed Oct 13 17:05:11 UTC 2010


Author: Nick Mathewson <nickm at torproject.org>
Date: Wed, 13 Oct 2010 13:08:38 -0400
Subject: Use connection_mark_and_flush consistently.
Commit: a0c1c2ac012fded493c0d8c49fe57e56373b061f

---
 src/or/connection.h      |   10 ++++++++--
 src/or/connection_edge.c |    5 ++---
 src/or/control.c         |   10 ++++------
 src/or/main.c            |    3 +--
 src/or/routerlist.c      |   10 +++++-----
 5 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/src/or/connection.h b/src/or/connection.h
index 004ede5..dc8c5df 100644
--- a/src/or/connection.h
+++ b/src/or/connection.h
@@ -34,15 +34,21 @@ void _connection_mark_for_close(connection_t *conn,int line, const char *file);
 #define connection_mark_for_close(c) \
   _connection_mark_for_close((c), __LINE__, _SHORT_FILE_)
 
-#define connection_mark_and_flush(c)                                    \
+/**
+ * Mark 'c' for close, but try to hold it open until all the data is written.
+ */
+#define _connection_mark_and_flush(c,line,file)                         \
   do {                                                                  \
     connection_t *tmp_conn_ = (c);                                      \
-    _connection_mark_for_close(tmp_conn_, __LINE__, _SHORT_FILE_);      \
+    _connection_mark_for_close(tmp_conn_, (line), (file));              \
     tmp_conn_->hold_open_until_flushed = 1;                             \
     IF_HAS_BUFFEREVENT(tmp_conn_,                                       \
                        connection_start_writing(tmp_conn_));            \
   } while (0)
 
+#define connection_mark_and_flush(c)            \
+  _connection_mark_and_flush((c), __LINE__, _SHORT_FILE_)
+
 void connection_expire_held_open(void);
 
 int connection_connect(connection_t *conn, const char *address,
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 9627631..be6428d 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -90,9 +90,8 @@ _connection_mark_unattached_ap(edge_connection_t *conn, int endreason,
       conn->socks_request->has_finished = 1;
   }
 
-  _connection_mark_for_close(TO_CONN(conn), line, file);
-  conn->_base.hold_open_until_flushed = 1;
-  IF_HAS_BUFFEREVENT(TO_CONN(conn), connection_start_writing(TO_CONN(conn)));
+  _connection_mark_and_flush(TO_CONN(conn), line, file);
+
   conn->end_reason = endreason;
 }
 
diff --git a/src/or/control.c b/src/or/control.c
index 37ebfd8..4c32b5b 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -2798,8 +2798,8 @@ connection_control_process_inbuf(control_connection_t *conn)
     body_len = 2+strlen(buf+6)+2; /* code, msg, nul. */
     set_uint16(buf+0, htons(body_len));
     connection_write_to_buf(buf, 4+body_len, TO_CONN(conn));
-    connection_mark_for_close(TO_CONN(conn));
-    conn->_base.hold_open_until_flushed = 1;
+
+    connection_mark_and_flush(TO_CONN(conn));
     return 0;
   }
 
@@ -2820,8 +2820,7 @@ connection_control_process_inbuf(control_connection_t *conn)
         if (data_len + conn->incoming_cmd_cur_len > MAX_COMMAND_LINE_LENGTH) {
           connection_write_str_to_buf("500 Line too long.\r\n", conn);
           connection_stop_reading(TO_CONN(conn));
-          connection_mark_for_close(TO_CONN(conn));
-          conn->_base.hold_open_until_flushed = 1;
+          connection_mark_and_flush(TO_CONN(conn));
         }
         while (conn->incoming_cmd_len < data_len+conn->incoming_cmd_cur_len)
           conn->incoming_cmd_len *= 2;
@@ -2880,8 +2879,7 @@ connection_control_process_inbuf(control_connection_t *conn)
   /* Otherwise, Quit is always valid. */
   if (!strcasecmp(conn->incoming_cmd, "QUIT")) {
     connection_write_str_to_buf("250 closing connection\r\n", conn);
-    connection_mark_for_close(TO_CONN(conn));
-    conn->_base.hold_open_until_flushed = 1;
+    connection_mark_and_flush(TO_CONN(conn));
     return 0;
   }
 
diff --git a/src/or/main.c b/src/or/main.c
index ddd5da3..2562c21 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -949,8 +949,7 @@ run_connection_housekeeping(int i, time_t now)
       connection_or_connect_failed(TO_OR_CONN(conn),
                                    END_OR_CONN_REASON_TIMEOUT,
                                    "Tor gave up on the connection");
-    connection_mark_for_close(conn);
-    conn->hold_open_until_flushed = 1;
+    connection_mark_and_flush(conn);
   } else if (!connection_state_is_open(conn)) {
     if (past_keepalive) {
       /* We never managed to actually get this connection open and happy. */
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 43be834..bf2a5a5 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -3216,13 +3216,13 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
   /* Make sure that we haven't already got this exact descriptor. */
   if (sdmap_get(routerlist->desc_digest_map,
                 router->cache_info.signed_descriptor_digest)) {
-    /* If we have this descriptor already and the new descriptor is a bridge
+    /* If we have this descriptor already but the new descriptor is a bridge
      * descriptor, replace it. If we had a bridge descriptor before and the
      * new one is not a bridge descriptor, don't replace it. */
-    tor_assert(old_router);
-    if (! (routerinfo_is_a_configured_bridge(router) &&
-            (router->purpose == ROUTER_PURPOSE_BRIDGE ||
-             old_router->purpose != ROUTER_PURPOSE_BRIDGE))) {
+    const int had_as_bridge = old_router &&
+      old_router->purpose == ROUTER_PURPOSE_BRIDGE;
+    if (! routerinfo_is_a_configured_bridge(router) ||
+        (router->purpose != ROUTER_PURPOSE_BRIDGE && had_as_bridge)) {
       log_info(LD_DIR,
                "Dropping descriptor that we already have for router '%s'",
                router->nickname);
-- 
1.7.1



More information about the tor-commits mailing list