[tor-commits] [tor/master] Implement circuitmux_clear_num_cells() and circuitmux_set_num_cells() in circuitmux.c, remove unneeded circuitmux_add_to_num_cells() from circuitmux.h

andrea at torproject.org andrea at torproject.org
Thu Oct 11 02:05:23 UTC 2012


commit a9deec3550ed51b3cd2a6a51104745def56b5e7a
Author: Andrea Shepard <andrea at torproject.org>
Date:   Wed Sep 26 12:23:58 2012 -0700

    Implement circuitmux_clear_num_cells() and circuitmux_set_num_cells() in circuitmux.c, remove unneeded circuitmux_add_to_num_cells() from circuitmux.h
---
 src/or/circuitmux.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/or/circuitmux.h |    2 --
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/src/or/circuitmux.c b/src/or/circuitmux.c
index ede2486..f6cdbf1 100644
--- a/src/or/circuitmux.c
+++ b/src/or/circuitmux.c
@@ -512,3 +512,53 @@ circuitmux_detach_circuit(circuitmux_t *cmux, circuit_t *circ)
   }
 }
 
+/**
+ * Clear the cell counter for a circuit on a circuitmux
+ */
+
+void
+circuitmux_clear_num_cells(circuitmux_t *cmux, circuit_t *circ)
+{
+  /* This is the same as setting the cell count to zero */
+  circuitmux_set_num_cells(cmux, circ, 0);
+}
+
+/**
+ * Set the cell counter for a circuit on a circuitmux
+ */
+
+void
+circuitmux_set_num_cells(circuitmux_t *cmux, circuit_t *circ,
+                         unsigned int n_cells)
+{
+  chanid_circid_muxinfo_t *hashent = NULL;
+
+  tor_assert(cmux);
+  tor_assert(circ);
+
+  /* Search for this circuit's entry */
+  hashent = circuitmux_find_map_entry(cmux, circ);
+  /* Assert that we found one */
+  tor_assert(hashent);
+
+  /* Update cmux cell counter */
+  cmux->n_cells -= hashent->muxinfo.cell_count;
+  cmux->n_cells += n_cells;
+
+  /*
+   * Update cmux active circuit counter: is the old cell count > 0 and the
+   * new cell count == 0 ?
+   */
+  if (hashent->muxinfo.cell_count > 0 && n_cells == 0) {
+    --(cmux->n_active_circuits);
+    /* TODO update active_circuits / active_circuit_pqueue */
+  /* Is the old cell count == 0 and the new cell count > 0 ? */
+  } else if (hashent->muxinfo.cell_count == 0 && n_cells > 0) {
+    ++(cmux->n_active_circuits);
+    /* TODO update active_circuits / active_circuit_pqueue */
+  }
+
+  /* Update hash entry cell counter */
+  hashent->muxinfo.cell_count = n_cells;
+}
+
diff --git a/src/or/circuitmux.h b/src/or/circuitmux.h
index c5f9526..ade544f 100644
--- a/src/or/circuitmux.h
+++ b/src/or/circuitmux.h
@@ -41,8 +41,6 @@ void circuitmux_attach_circuit(circuitmux_t *cmux, circuit_t *circ,
                                cell_direction_t direction);
 void circuitmux_detach_circuit(circuitmux_t *cmux, circuit_t *circ);
 void circuitmux_clear_num_cells(circuitmux_t *cmux, circuit_t *circ);
-void circuitmux_add_to_num_cells(circuitmux_t *cmux, circuit_t *circ,
-                                 unsigned int n_cells);
 void circuitmux_set_num_cells(circuitmux_t *cmux, circuit_t *circ,
                               unsigned int n_cells);
 





More information about the tor-commits mailing list