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

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

    From 500d856a4e674c42aec8e8abc0ef70b42639e502 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 2/2] Simplify channel_rsa_id_group_set_badness, #24119
    
    ---
     src/or/channel.c | 56 +++++++++++++++++++++++++++++++-------------------------
     1 file changed, 31 insertions(+), 25 deletions(-)
    
    diff --git a/src/or/channel.c b/src/or/channel.c
    index d9455efbc..61a8bbeba 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
    channel_rsa_id_group_set_badness(struct channel_list_s *lst, int force) 
    47454754    return;
    47464755  }
    47474756
    4748   /* First, get a minimal list of the ed25519 identites */
    4749   smartlist_t *ed_identities = smartlist_new();
     4757  smartlist_t *channels = smartlist_new();
     4758
    47504759  TOR_LIST_FOREACH(chan, lst, next_with_same_id) {
    4751     uint8_t *id_copy =
    4752       tor_memdup(&chan->ed25519_identity.pubkey, DIGEST256_LEN);
    4753     smartlist_add(ed_identities, id_copy);
     4760    if (BASE_CHAN_TO_TLS(chan)->conn) {
     4761      smartlist_add(channels, chan);
     4762    }
    47544763  }
    4755   smartlist_sort_digests256(ed_identities);
    4756   smartlist_uniq_digests256(ed_identities);
    47574764
    4758   /* Now, for each Ed identity, build a smartlist and find the best entry on
    4759    * it.  */
     4765  smartlist_sort(channels, channel_sort_by_ed25519_identity);
     4766
     4767  const ed25519_public_key_t *common_ed25519_identity = NULL;
     4768  /* it would be more efficient to do a slice, but this case is rare */
    47604769  smartlist_t *or_conns = smartlist_new();
    4761   SMARTLIST_FOREACH_BEGIN(ed_identities, const uint8_t *, ed_id) {
    4762     TOR_LIST_FOREACH(chan, lst, next_with_same_id) {
    4763       channel_tls_t *chantls = BASE_CHAN_TO_TLS(chan);
    4764       if (tor_memneq(ed_id, &chan->ed25519_identity.pubkey, DIGEST256_LEN))
    4765         continue;
    4766       or_connection_t *orconn = chantls->conn;
    4767       if (orconn) {
    4768         tor_assert(orconn->chan == chantls);
    4769         smartlist_add(or_conns, orconn);
    4770       }
     4770  SMARTLIST_FOREACH_BEGIN(channels, channel_t *, channel) {
     4771    if (!common_ed25519_identity)
     4772      common_ed25519_identity = &channel->ed25519_identity;
     4773
     4774    if (memcmp(&channel->ed25519_identity, common_ed25519_identity,
     4775               sizeof(*common_ed25519_identity))) {
     4776        connection_or_group_set_badness_(or_conns, force);
     4777        smartlist_clear(or_conns);
     4778        common_ed25519_identity = &channel->ed25519_identity;
    47714779    }
    47724780
    4773     connection_or_group_set_badness_(or_conns, force);
    4774     smartlist_clear(or_conns);
    4775   } SMARTLIST_FOREACH_END(ed_id);
     4781    smartlist_add(or_conns, BASE_CHAN_TO_TLS(channel)->conn);
     4782  } SMARTLIST_FOREACH_END(channel);
    47764783
    47774784  /* XXXX 15056 we may want to do something special with connections that have
    47784785   * no set Ed25519 identity! */
    47794786
    47804787  smartlist_free(or_conns);
    4781 
    4782   SMARTLIST_FOREACH(ed_identities, uint8_t *, ed_id, tor_free(ed_id));
    4783   smartlist_free(ed_identities);
     4788  smartlist_free(channels);
    47844789}
    47854790
    47864791/** Go through all the channels (or if <b>digest</b> is non-NULL, just
    channel_update_bad_for_new_circs(const char *digest, int force) 
    48204825void
    48214826channel_update_xmit_queue_size(channel_t *chan)
    48224827{
     4828
    48234829  uint64_t queued, adj;
    48244830  double overhead;
    48254831