Ticket #24119: 0001-Simplify-channel_rsa_id_group_set_badness-24119.patch

File 0001-Simplify-channel_rsa_id_group_set_badness-24119.patch, 3.6 KB (added by Hello71, 2 years ago)
  • src/or/channel.c

    From 0646034b194b5be8e8164fd1e6a095ba400fe212 Mon Sep 17 00:00:00 2001
    From: "Alex Xu (Hello71)" <alex_y_xu@yahoo.ca>
    Date: Sat, 4 Nov 2017 22:23:40 -0400
    Subject: [PATCH] Simplify channel_rsa_id_group_set_badness, #24119
    
    ---
     src/or/channel.c | 62 ++++++++++++++++++++++++++++++++------------------------
     1 file changed, 35 insertions(+), 27 deletions(-)
    
    diff --git a/src/or/channel.c b/src/or/channel.c
    index 0b5a7fde9..ac811c31b 100644
    a b channel_set_circid_type,(channel_t *chan, 
    47264726  }
    47274727}
    47284728
     4729static int
     4730channel_sort_by_ed25519_identity(const void **a_, const void **b_)
     4731{
     4732  const channel_t *a = *a_;
     4733  const channel_t *b = *b_;
     4734  return memcmp(&a->ed25519_identity, &b->ed25519_identity,
     4735                sizeof(a->ed25519_identity));
     4736}
     4737
    47294738/** Helper for channel_update_bad_for_new_circs(): Perform the
    47304739 * channel_update_bad_for_new_circs operation on all channels in <b>lst</b>,
    47314740 * all of which MUST have the same RSA ID.  (They MAY have different
    static void 
    47344743channel_rsa_id_group_set_badness(struct channel_list_s *lst, int force)
    47354744{
    47364745  /*XXXX This function should really be about channels. 15056 */
    4737   channel_t *chan;
     4746  smartlist_t *channels = smartlist_new();
    47384747
    4739   /* First, get a minimal list of the ed25519 identites */
    4740   smartlist_t *ed_identities = smartlist_new();
    4741   TOR_LIST_FOREACH(chan, lst, next_with_same_id) {
    4742     uint8_t *id_copy =
    4743       tor_memdup(&chan->ed25519_identity.pubkey, DIGEST256_LEN);
    4744     smartlist_add(ed_identities, id_copy);
    4745   }
    4746   smartlist_sort_digests256(ed_identities);
    4747   smartlist_uniq_digests256(ed_identities);
     4748  {
     4749    channel_t *chan;
    47484750
    4749   /* Now, for each Ed identity, build a smartlist and find the best entry on
    4750    * it.  */
    4751   smartlist_t *or_conns = smartlist_new();
    4752   SMARTLIST_FOREACH_BEGIN(ed_identities, const uint8_t *, ed_id) {
    47534751    TOR_LIST_FOREACH(chan, lst, next_with_same_id) {
    4754       channel_tls_t *chantls = BASE_CHAN_TO_TLS(chan);
    4755       if (tor_memneq(ed_id, &chan->ed25519_identity.pubkey, DIGEST256_LEN))
    4756         continue;
    4757       or_connection_t *orconn = chantls->conn;
    4758       if (orconn) {
    4759         tor_assert(orconn->chan == chantls);
    4760         smartlist_add(or_conns, orconn);
     4752      if (BASE_CHAN_TO_TLS(chan)->conn) {
     4753        smartlist_add(channels, chan);
    47614754      }
    47624755    }
     4756  }
     4757
     4758  smartlist_sort(channels, channel_sort_by_ed25519_identity);
     4759
     4760  const ed25519_public_key_t *common_ed25519_identity = NULL;
     4761  /* it would be more efficient to do a slice, but since only one allocation is
     4762   * needed, the overhead is negligible here. */
     4763  smartlist_t *or_conns = smartlist_new();
     4764  SMARTLIST_FOREACH_BEGIN(channels, channel_t *, chan) {
     4765    if (!common_ed25519_identity)
     4766      common_ed25519_identity = &chan->ed25519_identity;
     4767
     4768    if (memcmp(&chan->ed25519_identity, common_ed25519_identity,
     4769               sizeof(*common_ed25519_identity))) {
     4770        connection_or_group_set_badness_(or_conns, force);
     4771        smartlist_clear(or_conns);
     4772        common_ed25519_identity = &chan->ed25519_identity;
     4773    }
    47634774
    4764     connection_or_group_set_badness_(or_conns, force);
    4765     smartlist_clear(or_conns);
    4766   } SMARTLIST_FOREACH_END(ed_id);
     4775    smartlist_add(or_conns, BASE_CHAN_TO_TLS(chan)->conn);
     4776  } SMARTLIST_FOREACH_END(chan);
    47674777
    47684778  /* XXXX 15056 we may want to do something special with connections that have
    47694779   * no set Ed25519 identity! */
    47704780
    47714781  smartlist_free(or_conns);
    4772 
    4773   SMARTLIST_FOREACH(ed_identities, uint8_t *, ed_id, tor_free(ed_id));
    4774   smartlist_free(ed_identities);
     4782  smartlist_free(channels);
    47754783}
    47764784
    47774785/** Go through all the channels (or if <b>digest</b> is non-NULL, just