]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Remove circuit_sendme_cell_is_next
authorNick Mathewson <nickm@torproject.org>
Tue, 10 Jun 2025 16:29:40 +0000 (12:29 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 10 Jun 2025 23:06:47 +0000 (19:06 -0400)
We needed this function previously, when we only computed a SENDME
tag conditionally, depending on whether we were about to need it.
But as part of the CGO refactoring, we now compute and store SENDME
tags unconditionally, whenever a cell is originated or recognized.
Therefore this function is no longer needed anywhere.

src/core/or/sendme.c
src/core/or/sendme.h
src/test/test_sendme.c

index be9c15ed39965687b70be220ba1deec90024fddc..4774a706106831992fb81223bde5c6e178eac47d 100644 (file)
@@ -382,43 +382,6 @@ record_cell_digest_on_circ(circuit_t *circ,
  * Public API
  */
 
-/** Return true iff the next cell for the given cell window is expected to be
- * a SENDME.
- *
- * We are able to know that because the package or inflight window value minus
- * one cell (the possible SENDME cell) should be a multiple of the
- * cells-per-sendme increment value (set via consensus parameter, negotiated
- * for the circuit, and passed in as sendme_inc).
- *
- * This function is used when recording a cell digest and this is done quite
- * low in the stack when decrypting or encrypting a cell. The window is only
- * updated once the cell is actually put in the outbuf.
- */
-// XXXX Todo remove if truly not needed.
-ATTR_UNUSED STATIC bool
-circuit_sendme_cell_is_next(int deliver_window, int sendme_inc)
-{
-  /* Are we at the limit of the increment and if not, we don't expect next
-   * cell is a SENDME.
-   *
-   * We test against the window minus 1 because when we are looking if the
-   * next cell is a SENDME, the window (either package or deliver) hasn't been
-   * decremented just yet so when this is called, we are currently processing
-   * the "window - 1" cell.
-   *
-   * Because deliver_window starts at CIRCWINDOW_START and counts down,
-   * to get the actual number of received cells for this check, we must
-   * first convert to received cells, or the modulus operator will fail.
-   */
-  tor_assert(deliver_window <= CIRCWINDOW_START);
-  if (((CIRCWINDOW_START - (deliver_window - 1)) % sendme_inc) != 0) {
-    return false;
-  }
-
-  /* Next cell is expected to be a SENDME. */
-  return true;
-}
-
 /** Called when we've just received a relay data cell, when we've just
  * finished flushing all bytes to stream <b>conn</b>, or when we've flushed
  * *some* bytes to the stream <b>conn</b>.
index c76b6d3947052019de8847fb050f7d5f6eafb798..53c6776d7614c1d53c6f010a6db14fcfc54af164 100644 (file)
@@ -72,8 +72,6 @@ STATIC bool sendme_is_valid(const circuit_t *circ,
                             const crypt_path_t *layer_hint,
                             const uint8_t *cell_payload,
                             size_t cell_payload_len);
-STATIC bool circuit_sendme_cell_is_next(int deliver_window,
-                                        int sendme_inc);
 
 #endif /* defined(TOR_UNIT_TESTS) */
 
index cde6dd5d2915c5a5f655136ca9fcdd2478d065d5..1eb3de568436730ac60deb79a0fbc2d6af3e28c2 100644 (file)
@@ -317,50 +317,6 @@ test_package_payload_len(void *arg)
   circuit_free(c);
 }
 
-/* Check that circuit_sendme_is_next works with a window of 1000,
- * and a sendme_inc of 100 (old school tor compat) */
-static void
-test_sendme_is_next1000(void *arg)
-{
- (void)arg;
- tt_int_op(circuit_sendme_cell_is_next(1000, 100), OP_EQ, 0);
- tt_int_op(circuit_sendme_cell_is_next(999, 100), OP_EQ, 0);
- tt_int_op(circuit_sendme_cell_is_next(901, 100), OP_EQ, 1);
-
- tt_int_op(circuit_sendme_cell_is_next(900, 100), OP_EQ, 0);
- tt_int_op(circuit_sendme_cell_is_next(899, 100), OP_EQ, 0);
- tt_int_op(circuit_sendme_cell_is_next(801, 100), OP_EQ, 1);
-
- tt_int_op(circuit_sendme_cell_is_next(101, 100), OP_EQ, 1);
- tt_int_op(circuit_sendme_cell_is_next(100, 100), OP_EQ, 0);
- tt_int_op(circuit_sendme_cell_is_next(99, 100), OP_EQ, 0);
- tt_int_op(circuit_sendme_cell_is_next(1, 100), OP_EQ, 1);
- tt_int_op(circuit_sendme_cell_is_next(0, 100), OP_EQ, 0);
-
-done:
- ;
-}
-
-/* Check that circuit_sendme_is_next works with a window of 31 */
-static void
-test_sendme_is_next(void *arg)
-{
- (void)arg;
- tt_int_op(circuit_sendme_cell_is_next(1000, 31), OP_EQ, 0);
- tt_int_op(circuit_sendme_cell_is_next(970, 31), OP_EQ, 1);
- tt_int_op(circuit_sendme_cell_is_next(969, 31), OP_EQ, 0);
-
- /* deliver_window should never get this low, but test anyway */
- tt_int_op(circuit_sendme_cell_is_next(9, 31), OP_EQ, 1);
- tt_int_op(circuit_sendme_cell_is_next(8, 31), OP_EQ, 0);
- tt_int_op(circuit_sendme_cell_is_next(7, 31), OP_EQ, 0);
- tt_int_op(circuit_sendme_cell_is_next(1, 31), OP_EQ, 0);
- tt_int_op(circuit_sendme_cell_is_next(0, 31), OP_EQ, 0);
-
- done:
-  ;
-}
-
 struct testcase_t sendme_tests[] = {
   { "v1_record_digest", test_v1_record_digest, TT_FORK,
     NULL, NULL },
@@ -371,8 +327,6 @@ struct testcase_t sendme_tests[] = {
   { "cell_version_validation", test_cell_version_validation, TT_FORK,
     NULL, NULL },
   { "package_payload_len", test_package_payload_len, 0, NULL, NULL },
-  { "sendme_is_next1000", test_sendme_is_next1000, 0, NULL, NULL },
-  { "sendme_is_next", test_sendme_is_next, 0, NULL, NULL },
 
   END_OF_TESTCASES
 };