[tor-commits] [tor/master] sendme: Helper to know if next cell is a SENDME

asn at torproject.org asn at torproject.org
Thu May 2 15:16:20 UTC 2019


commit 7c8e519b3452ce3eb3d3c854d80be5b7e49164b4
Author: David Goulet <dgoulet at torproject.org>
Date:   Wed Apr 24 10:25:29 2019 -0400

    sendme: Helper to know if next cell is a SENDME
    
    We'll use it this in order to know when to hash the cell for the SENDME
    instead of doing it at every cell.
    
    Part of #26288
    
    Signed-off-by: David Goulet <dgoulet at torproject.org>
---
 src/core/or/sendme.c | 25 ++++++++++++++++++++++++-
 src/core/or/sendme.h |  3 +++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/core/or/sendme.c b/src/core/or/sendme.c
index 3dcd9df08..c66e947bc 100644
--- a/src/core/or/sendme.c
+++ b/src/core/or/sendme.c
@@ -286,6 +286,29 @@ send_circuit_level_sendme(circuit_t *circ, crypt_path_t *layer_hint,
   return 0;
 }
 
+/*
+ * 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 deliver window value minus
+ * one cell (the possible SENDME cell) should be a multiple of the increment
+ * window value. */
+bool
+sendme_circuit_is_next_cell(int window)
+{
+  /* Is this the last cell before a SENDME? The idea is that if the package or
+   * deliver window reaches a multiple of the increment, after this cell, we
+   * should expect a SENDME. */
+  if (((window - 1) % CIRCWINDOW_INCREMENT) != 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>.
@@ -550,7 +573,7 @@ sendme_note_cell_digest(circuit_t *circ)
   /* Is this the last cell before a SENDME? The idea is that if the
    * package_window reaches a multiple of the increment, after this cell, we
    * should expect a SENDME. */
-  if (((circ->package_window - 1) % CIRCWINDOW_INCREMENT) != 0) {
+  if (!sendme_circuit_is_next_cell(circ->package_window)) {
     return;
   }
 
diff --git a/src/core/or/sendme.h b/src/core/or/sendme.h
index 71df9b6f0..0965b5b22 100644
--- a/src/core/or/sendme.h
+++ b/src/core/or/sendme.h
@@ -37,6 +37,9 @@ int sendme_note_stream_data_packaged(edge_connection_t *conn);
 /* Track cell digest. */
 void sendme_note_cell_digest(circuit_t *circ);
 
+/* Circuit level information. */
+bool sendme_circuit_is_next_cell(int window);
+
 /* Private section starts. */
 #ifdef SENDME_PRIVATE
 





More information about the tor-commits mailing list