[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/main] Add test for circuit_sendme_cell_is_next() when sendme_inc is 100.



commit 5c88bea84c3535ed908d51d2ed2e9beaa58ee607
Author: Mike Perry <mikeperry-git@xxxxxxxxxxxxxx>
Date:   Thu Feb 17 00:04:41 2022 +0000

    Add test for circuit_sendme_cell_is_next() when sendme_inc is 100.
    
    This ensures compatibility with old tor.
---
 src/core/or/sendme.c   |  2 +-
 src/core/or/sendme.h   |  2 ++
 src/test/test_sendme.c | 25 +++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/core/or/sendme.c b/src/core/or/sendme.c
index 9acef1cc20..494910049e 100644
--- a/src/core/or/sendme.c
+++ b/src/core/or/sendme.c
@@ -338,7 +338,7 @@ record_cell_digest_on_circ(circuit_t *circ, const uint8_t *sendme_digest)
  * low in the stack when decrypting or encrypting a cell. The window is only
  * updated once the cell is actually put in the outbuf.
  */
-static bool
+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
diff --git a/src/core/or/sendme.h b/src/core/or/sendme.h
index 2abec91a91..bc1daef23d 100644
--- a/src/core/or/sendme.h
+++ b/src/core/or/sendme.h
@@ -73,6 +73,8 @@ STATIC ssize_t build_cell_payload_v1(const uint8_t *cell_digest,
 STATIC bool sendme_is_valid(const circuit_t *circ,
                             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) */
 
diff --git a/src/test/test_sendme.c b/src/test/test_sendme.c
index eef65a394e..1a046b5c50 100644
--- a/src/test/test_sendme.c
+++ b/src/test/test_sendme.c
@@ -348,6 +348,30 @@ test_package_payload_len(void *arg)
   tor_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:
+ ;
+}
+
 struct testcase_t sendme_tests[] = {
   { "v1_record_digest", test_v1_record_digest, TT_FORK,
     NULL, NULL },
@@ -360,6 +384,7 @@ 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 },
 
   END_OF_TESTCASES
 };



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits