]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Implement circuitmux_get_first_active_circuit() in circuitmux.c; add pick_active_circ...
authorAndrea Shepard <andrea@torproject.org>
Fri, 28 Sep 2012 23:56:46 +0000 (16:56 -0700)
committerAndrea Shepard <andrea@torproject.org>
Wed, 10 Oct 2012 07:44:46 +0000 (00:44 -0700)
src/or/circuitmux.c
src/or/circuitmux.h

index 824bf0b0ca40daed8cb36dd9024140f3c7b81db8..4500c6ab2148e5dd49a5b8554758ec74a66d4b39 100644 (file)
@@ -359,7 +359,6 @@ circuitmux_detach_all_circuits(circuitmux_t *cmux)
                      U64_PRINTF_ARG(to_remove->chan_id));
           }
 
-
           /* Free policy-specific data if we have it */
           if (to_remove->muxinfo.policy_data) {
             /*
@@ -1254,6 +1253,35 @@ circuitmux_set_num_cells(circuitmux_t *cmux, circuit_t *circ,
  * notify that cells have been transmitted.
  */
 
+/**
+ * Pick a circuit to send from, using the active circuits list or a
+ * circuitmux policy if one is available.  This is called from channel.c.
+ */
+
+circuit_t *
+circuitmux_get_first_active_circuit(circuitmux_t *cmux)
+{
+  circuit_t *circ = NULL;
+
+  tor_assert(cmux);
+
+  if (cmux->n_active_circuits > 0) {
+    /* We also must have a cell available for this to be the case */
+    tor_assert(cmux->n_cells > 0);
+    /* Do we have a policy-provided circuit selector? */
+    if (cmux->policy && cmux->policy->pick_active_circuit) {
+      circ = cmux->policy->pick_active_circuit(cmux, cmux->policy_data);
+    }
+    /* Fall back on the head of the active circuits list */
+    if (!circ) {
+      tor_assert(cmux->active_circuits_head);
+      circ = cmux->active_circuits_head;
+    }
+  } else tor_assert(cmux->n_cells == 0);
+
+  return circ;
+}
+
 /**
  * Notify the circuitmux that cells have been sent on a circuit; this
  * is called from channel.c.
@@ -1310,7 +1338,7 @@ circuitmux_notify_xmit_cells(circuitmux_t *cmux, circuit_t *circ,
 
   /*
    * Now make the circuit inactive if needed; this will call the policy's
-   * notify_circ_inactive() if present. 
+   * notify_circ_inactive() if present.
    */
   if (becomes_inactive) {
     --(cmux->n_active_circuits);
index dcacb8e15d5d275f97a525b080e51382f3357e25..f4eb73e3914ff7cad9b2b8e90c20e754d2a6df3d 100644 (file)
@@ -53,6 +53,9 @@ struct circuitmux_policy_s {
                             circuit_t *circ,
                             circuitmux_policy_circ_data_t *pol_circ_data,
                             unsigned int n_cells);
+  /* Choose a circuit */
+  circuit_t * (*pick_active_circuit)(circuitmux_t *cmux,
+                                     circuitmux_policy_data_t *pol_data);
 };
 
 /*