]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Implement circuitmux_clear_num_cells() and circuitmux_set_num_cells() in circuitmux...
authorAndrea Shepard <andrea@torproject.org>
Wed, 26 Sep 2012 19:23:58 +0000 (12:23 -0700)
committerAndrea Shepard <andrea@torproject.org>
Wed, 10 Oct 2012 07:43:18 +0000 (00:43 -0700)
src/or/circuitmux.c
src/or/circuitmux.h

index ede2486bfbbf445b3f6ff2b750ff3e82374374bc..f6cdbf1e5694531531070800791fc716bfaf5fc1 100644 (file)
@@ -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;
+}
+
index c5f95268e7658d62dc1acd1e39bae523dc6f1c85..ade544f3b23bd93e68ef5c4cfe3f4e330ebc183b 100644 (file)
@@ -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);