]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add fast paths to channel_rsa_id_group_set_badness, #24119
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>
Sun, 5 Nov 2017 14:40:22 +0000 (09:40 -0500)
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>
Fri, 24 Nov 2017 17:42:51 +0000 (12:42 -0500)
src/or/channel.c
src/or/connection_or.c
src/or/connection_or.h

index 0b5a7fde9063d92821a46e3e34f70b53ee66fb6a..acd890c72b8f72187eebe22efea8999938adc93f 100644 (file)
@@ -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();
index 7af1f2b6453e5a44da83339d997f2019faa534d4..fdf1b2ebb181973319349237fbed89ec320f4b55 100644 (file)
@@ -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;
index ee66b7c528d2205a9ebd795394b5d8bef7fa3a8c..644df5c2c92342b90b1dc2da5974610350c92f71 100644 (file)
@@ -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