[or-cvs] Our connection_or_get_by_identity_digest() was slightly wro...

Peter Palfrader weasel at seul.org
Tue Feb 14 00:08:21 UTC 2006


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

Modified Files:
	connection_or.c 
Log Message:
Our connection_or_get_by_identity_digest() was slightly wrong.  If best
didn't have any circuits on it, but conn had circuits, we would not make
conn our new best unless it was also newer.  Also, restructure the code
a bit to maybe make it clearer.


Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_or.c,v
retrieving revision 1.211
retrieving revision 1.212
diff -u -p -d -r1.211 -r1.212
--- connection_or.c	13 Feb 2006 09:02:35 -0000	1.211
+++ connection_or.c	14 Feb 2006 00:08:19 -0000	1.212
@@ -394,12 +394,22 @@ connection_or_get_by_identity_digest(con
         conn->state != OR_CONN_STATE_OPEN)
       continue; /* avoid non-open conns if we can */
     newer = best->timestamp_created < conn->timestamp_created;
-    if (conn->is_obsolete && (!best->is_obsolete || !newer))
-      continue; /* we have something, and it's better than this. */
-    if (best->n_circuits && !conn->n_circuits)
-      continue; /* prefer conns with circuits on them */
-    if (newer)
-      best = conn; /* lastly, prefer newer conns */
+
+    if (!best->is_obsolete && conn->is_obsolete)
+      continue; /* We never prefer obsolete over non-obsolete connections. */
+
+      /* If both are obsolete we prefer the newer: */
+    if ((best->is_obsolete && conn->is_obsolete && newer) ||
+      /* We prefer non-obsolete connections */
+        (best->is_obsolete && !conn->is_obsolete) ||
+      /* If both have circuits we prefer the newer: */
+        (best->n_circuits && conn->n_circuits && newer) ||
+      /* If neither has circuits we prefer the newer: */
+        (!best->n_circuits && !conn->n_circuits && newer) ||
+      /* We prefer connections with circuits: */
+        (!best->n_circuits && conn->n_circuits)) {
+      best = conn;
+    };
   }
   return best;
 }



More information about the tor-commits mailing list