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

[tor-commits] [tor/master] Teach channel_rsa_id_group_set_badness_() about Ed25519



commit 3b1e04fe4505ccbd7d93061dccb5673523519c64
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Nov 10 16:38:04 2016 -0500

    Teach channel_rsa_id_group_set_badness_() about Ed25519
    
    (Only run the connection_or_group_set_badness_() function on groups
    of channels that have the same RSA and Ed25519 identities.)
    
    There's a possible opportunity here where we might want to set a
    channel to "bad" if it has no ed25519 identity and some other
    channel has some.  Also there's an opportunity to add a warning if
    we ever have an Ed mismatch on open connections with the same RSA
    ID.
---
 src/or/channel.c       | 41 ++++++++++++++++++++++++++++++++++-------
 src/or/connection_or.c |  6 +++---
 2 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index 0a96f23..7984558 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -4551,18 +4551,45 @@ channel_set_circid_type,(channel_t *chan,
 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;
 
-  smartlist_t *or_conns = smartlist_new();
+  /* First, get a minimal list of the ed25519 identites */
+  smartlist_t *ed_identities = smartlist_new();
   TOR_LIST_FOREACH(chan, lst, next_with_same_id) {
-    channel_tls_t *chantls = BASE_CHAN_TO_TLS(chan);
-    or_connection_t *orconn = chantls->conn;
-    if (orconn)
-      smartlist_add(or_conns, orconn);
+    uint8_t *id_copy =
+      tor_memdup(&chan->ed25519_identity.pubkey, DIGEST256_LEN);
+    smartlist_add(ed_identities, id_copy);
   }
-  /*XXXX This function should really be about channels. 15056 */
-  connection_or_group_set_badness_(or_conns, force);
+  smartlist_sort_digests256(ed_identities);
+  smartlist_uniq_digests256(ed_identities);
+
+  /* Now, for each Ed identity, build a smartlist and find the best entry on
+   * it.  */
+  smartlist_t *or_conns = smartlist_new();
+  SMARTLIST_FOREACH_BEGIN(ed_identities, const uint8_t *, ed_id) {
+    TOR_LIST_FOREACH(chan, lst, next_with_same_id) {
+      channel_tls_t *chantls = BASE_CHAN_TO_TLS(chan);
+      if (tor_memneq(ed_id, &chan->ed25519_identity.pubkey, DIGEST256_LEN))
+        continue;
+      or_connection_t *orconn = chantls->conn;
+      if (orconn) {
+        tor_assert(orconn->chan == chantls);
+        smartlist_add(or_conns, orconn);
+      }
+    }
+
+    connection_or_group_set_badness_(or_conns, force);
+    smartlist_clear(or_conns);
+  } SMARTLIST_FOREACH_END(ed_id);
+
+  /* XXXX 15056 we may want to do something special with connections that have
+   * no set Ed25519 identity! */
+
   smartlist_free(or_conns);
+
+  SMARTLIST_FOREACH(ed_identities, uint8_t *, ed_id, tor_free(ed_id));
+  smartlist_free(ed_identities);
 }
 
 /** Go through all the channels (or if <b>digest</b> is non-NULL, just
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 2889bb7..953e9df 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -966,9 +966,9 @@ connection_or_mark_bad_for_new_circs(or_connection_t *or_conn)
 void
 connection_or_group_set_badness_(smartlist_t *group, int force)
 {
-  /* XXXX this should be entirely about channels, not OR connections.  15056*/
-  /* XXXX Look at Ed25519 ids too! 15056 */
-  
+  /* XXXX this function should be entirely about channels, not OR
+   * XXXX connections. */
+
   or_connection_t *best = NULL;
   int n_old = 0, n_inprogress = 0, n_canonical = 0, n_other = 0;
   time_t now = time(NULL);



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