Remove expect and received flight hooks.
Instead, the DTLS driver can detect these states implicitly based on
when we write flights and when the handshake completes. When we flush a
new flight, the peer has enough information to send their reply, so we
start a timer. When we begin assembling a new flight, we must have
received the final message in the peer's flight. (If there are
asynchronous events between, we may stop the timer later, but we may
freely stop the timer anytime before we next try to read something.)
The only place this fails is if we were the last to write a flight,
we'll have a stray timer. Clear it in a handshake completion hook.
Change-Id: I973c592ee5721192949a45c259b93192fa309edb
Reviewed-on: https://boringssl-review.googlesource.com/18864
Reviewed-by: Steven Valdez <svaldez@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/ssl/dtls_method.cc b/ssl/dtls_method.cc
index 59c771b..947cfce 100644
--- a/ssl/dtls_method.cc
+++ b/ssl/dtls_method.cc
@@ -72,9 +72,12 @@
return cipher->algorithm_enc != SSL_eNULL;
}
-static void dtls1_expect_flight(SSL *ssl) { dtls1_start_timer(ssl); }
-
-static void dtls1_received_flight(SSL *ssl) { dtls1_stop_timer(ssl); }
+static void dtls1_on_handshake_complete(SSL *ssl) {
+ /* If we wrote the last flight, we'll have a timer left over without waiting
+ * for a read. Stop the timer but leave the flight around for post-handshake
+ * transmission logic. */
+ dtls1_stop_timer(ssl);
+}
static int dtls1_set_read_state(SSL *ssl, UniquePtr<SSLAEADContext> aead_ctx) {
/* Cipher changes are illegal when there are buffered incoming messages. */
@@ -124,8 +127,7 @@
dtls1_add_change_cipher_spec,
dtls1_add_alert,
dtls1_flush_flight,
- dtls1_expect_flight,
- dtls1_received_flight,
+ dtls1_on_handshake_complete,
dtls1_set_read_state,
dtls1_set_write_state,
};