]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge remote-tracking branch 'public/bug11553_024' into bug11553_025
authorNick Mathewson <nickm@torproject.org>
Wed, 23 Apr 2014 16:44:18 +0000 (12:44 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 23 Apr 2014 16:44:18 +0000 (12:44 -0400)
Conflicts:
src/or/circuitbuild.c

1  2 
src/or/channel.c
src/or/channel.h
src/or/circuitbuild.c

Simple merge
index de19fad9a58b3a8f1b3a62b3745521b485b5fb1b,63da0c1c248f787c84c7d2677c95a7857eab96ca..bd9a02f32317841ffc2f6669e0ce6be289976488
@@@ -146,16 -145,14 +146,14 @@@ struct channel_s 
     * When we send CREATE cells along this connection, which half of the
     * space should we use?
     */
 -  ENUM_BF(circ_id_type_t) circ_id_type:2;
 +  circ_id_type_bitfield_t circ_id_type:2;
    /** DOCDOC*/
    unsigned wide_circ_ids:1;
-   /** Have we logged a warning about circID exhaustion on this channel? */
-   unsigned warned_circ_ids_exhausted:1;
  
 -  /* For how many circuits are we n_chan?  What about p_chan? */
 +  /** For how many circuits are we n_chan?  What about p_chan? */
    unsigned int num_n_circuits, num_p_circuits;
  
 -  /*
 +  /**
     * True iff this channel shouldn't get any new circs attached to it,
     * because the connection is too old, or because there's a better one.
     * More generally, this flag is used to note an unhealthy connection;
index 550ed1cddcf028ed6e77c7d91e9b9143beee9f22,8d6aad605cc668331e855146b85fa2d01d99e18c..9e11a0bb1ab12f59f8623ebb33b7c0d4afdc013a
@@@ -87,9 -102,14 +87,15 @@@ channel_connect_for_circuit(const tor_a
  static circid_t
  get_unique_circ_id_by_chan(channel_t *chan)
  {
+ /* This number is chosen somewhat arbitrarily; see comment below for more
+  * info.  When the space is 80% full, it gives a one-in-a-million failure
+  * chance; when the space is 90% full, it gives a one-in-850 chance; and when
+  * the space is 95% full, it gives a one-in-26 failure chance.  That seems
+  * okay, though you could make a case IMO for anything between N=32 and
+  * N=256. */
  #define MAX_CIRCID_ATTEMPTS 64
 -
 +  int in_use;
 +  unsigned n_with_circ = 0, n_pending_destroy = 0;
    circid_t test_circ_id;
    circid_t attempts=0;
    circid_t high_bit, max_range, mask;
         * whole circuit ID space every time we extend a circuit, which is
         * not so great either.
         */
-       if (! chan->warned_circ_ids_exhausted) {
-         chan->warned_circ_ids_exhausted = 1;
-         log_warn(LD_CIRC,"No unused circIDs found on channel %s wide "
+       log_fn_ratelim(&chan->last_warned_circ_ids_exhausted, LOG_WARN,
+                  LD_CIRC,"No unused circIDs found on channel %s wide "
                   "circID support, with %u inbound and %u outbound circuits. "
 +                 "Found %u circuit IDs in use by circuits, and %u with "
 +                 "pending destroy cells."
                   "Failing a circuit.",
                   chan->wide_circ_ids ? "with" : "without",
 -                 chan->num_p_circuits, chan->num_n_circuits);
 +                 chan->num_p_circuits, chan->num_n_circuits,
 +                 n_with_circ, n_pending_destroy);
-       }
        return 0;
      }
  
-     crypto_rand((char*) &test_circ_id, sizeof(test_circ_id));
-     test_circ_id &= mask;
+     do {
+       crypto_rand((char*) &test_circ_id, sizeof(test_circ_id));
+       test_circ_id &= mask;
+     } while (test_circ_id == 0);
      test_circ_id |= high_bit;
 -  } while (circuit_id_in_use_on_channel(test_circ_id, chan));
 +
 +    in_use = circuit_id_in_use_on_channel(test_circ_id, chan);
 +    if (in_use == 1)
 +      ++n_with_circ;
 +    else if (in_use == 2)
 +      ++n_pending_destroy;
 +  } while (in_use);
    return test_circ_id;
  }