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

[tor-commits] [tor/master] Add fast paths to channel_rsa_id_group_set_badness, #24119



commit 2cda005ac49dcf02d2cfe358f8c75129a0f2f3bf
Author: Alex Xu (Hello71) <alex_y_xu@xxxxxxxx>
Date:   Sun Nov 5 09:40:22 2017 -0500

    Add fast paths to channel_rsa_id_group_set_badness, #24119
---
 src/or/channel.c       | 12 +++++++++++-
 src/or/connection_or.c | 43 +++++++++++++++++++++++++++++++------------
 src/or/connection_or.h |  3 +++
 3 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index 0b5a7fde9..acd890c72 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -4734,7 +4734,17 @@ static void
 channel_rsa_id_group_set_badness(struct channel_list_s *lst, int force)
 {
   /*XXXX This function should really be about channels. 15056 */
-  channel_t *chan;
+  channel_t *chan = TOR_LIST_FIRST(lst);
+
+  if (!chan)
+    return;
+
+  /* if there is only one channel, don't bother looping */
+  if (PREDICT_LIKELY(!TOR_LIST_NEXT(chan, next_with_same_id))) {
+    connection_or_single_set_badness_(
+            time(NULL), BASE_CHAN_TO_TLS(chan)->conn, force);
+    return;
+  }
 
   /* First, get a minimal list of the ed25519 identites */
   smartlist_t *ed_identities = smartlist_new();
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 7af1f2b64..fdf1b2ebb 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -965,6 +965,36 @@ connection_or_mark_bad_for_new_circs(or_connection_t *or_conn)
  * too old for new circuits? */
 #define TIME_BEFORE_OR_CONN_IS_TOO_OLD (60*60*24*7)
 
+/** Expire an or_connection if it is too old. Helper for
+ * connection_or_group_set_badness_ and fast path for
+ * channel_rsa_id_group_set_badness.
+ *
+ * Returns 1 if the connection was already expired, else 0.
+ */
+int
+connection_or_single_set_badness_(time_t now,
+                                  or_connection_t *or_conn,
+                                  int force)
+{
+  /* XXXX this function should also be about channels? */
+  if (or_conn->base_.marked_for_close ||
+      connection_or_is_bad_for_new_circs(or_conn))
+    return 1;
+
+  if (force ||
+      or_conn->base_.timestamp_created + TIME_BEFORE_OR_CONN_IS_TOO_OLD
+        < now) {
+    log_info(LD_OR,
+             "Marking OR conn to %s:%d as too old for new circuits "
+             "(fd "TOR_SOCKET_T_FORMAT", %d secs old).",
+             or_conn->base_.address, or_conn->base_.port, or_conn->base_.s,
+             (int)(now - or_conn->base_.timestamp_created));
+    connection_or_mark_bad_for_new_circs(or_conn);
+  }
+
+  return 0;
+}
+
 /** Given a list of all the or_connections with a given
  * identity, set elements of that list as is_bad_for_new_circs as
  * appropriate. Helper for connection_or_set_bad_connections().
@@ -995,19 +1025,8 @@ connection_or_group_set_badness_(smartlist_t *group, int force)
   /* Pass 1: expire everything that's old, and see what the status of
    * everything else is. */
   SMARTLIST_FOREACH_BEGIN(group, or_connection_t *, or_conn) {
-    if (or_conn->base_.marked_for_close ||
-        connection_or_is_bad_for_new_circs(or_conn))
+    if (connection_or_single_set_badness_(now, or_conn, force))
       continue;
-    if (force ||
-        or_conn->base_.timestamp_created + TIME_BEFORE_OR_CONN_IS_TOO_OLD
-          < now) {
-      log_info(LD_OR,
-               "Marking OR conn to %s:%d as too old for new circuits "
-               "(fd "TOR_SOCKET_T_FORMAT", %d secs old).",
-               or_conn->base_.address, or_conn->base_.port, or_conn->base_.s,
-               (int)(now - or_conn->base_.timestamp_created));
-      connection_or_mark_bad_for_new_circs(or_conn);
-    }
 
     if (connection_or_is_bad_for_new_circs(or_conn)) {
       ++n_old;
diff --git a/src/or/connection_or.h b/src/or/connection_or.h
index ee66b7c52..644df5c2c 100644
--- a/src/or/connection_or.h
+++ b/src/or/connection_or.h
@@ -112,6 +112,9 @@ void var_cell_free(var_cell_t *cell);
 #define MIN_LINK_PROTO_FOR_CHANNEL_PADDING 5
 #define MAX_LINK_PROTO MIN_LINK_PROTO_FOR_CHANNEL_PADDING
 
+int connection_or_single_set_badness_(time_t now,
+                                      or_connection_t *or_conn,
+                                      int force);
 void connection_or_group_set_badness_(smartlist_t *group, int force);
 
 #ifdef TOR_UNIT_TESTS



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits