* list can not contain more than 10 digests of DIGEST_LEN bytes (20).
*
* At position i in the list, the digest corresponds to the
- * ((CIRCWINDOW_INCREMENT * i) - 1)-nth cell received since we expect the
- * (CIRCWINDOW_INCREMENT * i)-nth cell to be the SENDME and thus containing
- * the previous cell digest.
+ * (CIRCWINDOW_INCREMENT * i)-nth cell received since we expect a SENDME to
+ * be received containing that cell digest.
*
- * For example, position 2 (starting at 0) means that we've received 299
- * cells and the 299th cell digest is kept at index 2.
+ * For example, position 2 (starting at 0) means that we've received 300
+ * cells so the 300th cell digest is kept at index 2.
*
* At maximum, this list contains 200 bytes plus the smartlist overhead. */
smartlist_t *sendme_last_digests;
* 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_cell_is_next(int window)
+static bool
+circuit_sendme_cell_is_next(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. */
+ /* At the start of the window, no SENDME will be expected. */
+ if (window == CIRCWINDOW_START) {
+ return false;
+ }
+
+ /* 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.
+ *
+ * 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. */
if (((window - 1) % CIRCWINDOW_INCREMENT) != 0) {
return false;
}
+
/* Next cell is expected to be a SENDME. */
return true;
}
/* 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 (!sendme_circuit_cell_is_next(package_window)) {
+ if (!circuit_sendme_cell_is_next(package_window)) {
return;
}
tor_assert(circ);
/* Only record if the next cell is expected to be a SENDME. */
- if (!sendme_circuit_cell_is_next(cpath ? cpath->deliver_window :
+ if (!circuit_sendme_cell_is_next(cpath ? cpath->deliver_window :
circ->deliver_window)) {
return;
}
tor_assert(circ);
/* Only record if the next cell is expected to be a SENDME. */
- if (!sendme_circuit_cell_is_next(cpath ? cpath->package_window:
+ if (!circuit_sendme_cell_is_next(cpath ? cpath->package_window :
circ->package_window)) {
goto end;
}