Add methods to QuicCryptoClientStreamBase to replace num_sent_client_hellos

The use of num_sent_client_hellos is to determine whether a 0-RTT handshake
was done (in which case it is 1) and whether an inchoate REJ was received
in the handshake (in which case it is 3). However, those only work for QUIC
crypto. To make the intention of its use clear and to make it easier to
replace QUIC crypto with TLS, the num_sent_client_hellos method is replaced
with EarlyDataAccepted and ReceivedInchoateReject.

gfe-relnote: no behavior change: adding unused methods
PiperOrigin-RevId: 294307567
Change-Id: I270cab9f702c66dbec6519a68965703a7872b87f
diff --git a/quic/core/http/quic_spdy_client_session.cc b/quic/core/http/quic_spdy_client_session.cc
index f82670f..70f79e9 100644
--- a/quic/core/http/quic_spdy_client_session.cc
+++ b/quic/core/http/quic_spdy_client_session.cc
@@ -110,6 +110,14 @@
   return crypto_stream_->num_sent_client_hellos();
 }
 
+bool QuicSpdyClientSession::EarlyDataAccepted() const {
+  return crypto_stream_->EarlyDataAccepted();
+}
+
+bool QuicSpdyClientSession::ReceivedInchoateReject() const {
+  return crypto_stream_->ReceivedInchoateReject();
+}
+
 int QuicSpdyClientSession::GetNumReceivedServerConfigUpdates() const {
   return crypto_stream_->num_scup_messages_received();
 }
diff --git a/quic/core/http/quic_spdy_client_session.h b/quic/core/http/quic_spdy_client_session.h
index b3def0a..32424ea 100644
--- a/quic/core/http/quic_spdy_client_session.h
+++ b/quic/core/http/quic_spdy_client_session.h
@@ -57,6 +57,18 @@
   // than the number of round-trips needed for the handshake.
   int GetNumSentClientHellos() const;
 
+  // Returns true if early data (0-RTT data) was sent and the server accepted
+  // it.
+  bool EarlyDataAccepted() const;
+
+  // Returns true if the handshake was delayed one round trip by the server
+  // because the server wanted proof the client controls its source address
+  // before progressing further. In Google QUIC, this would be due to an
+  // inchoate REJ in the QUIC Crypto handshake; in IETF QUIC this would be due
+  // to a Retry packet.
+  // TODO(nharper): Consider a better name for this method.
+  bool ReceivedInchoateReject() const;
+
   int GetNumReceivedServerConfigUpdates() const;
 
   void set_respect_goaway(bool respect_goaway) {
diff --git a/quic/core/quic_crypto_client_handshaker.cc b/quic/core/quic_crypto_client_handshaker.cc
index c306323..3614433 100644
--- a/quic/core/quic_crypto_client_handshaker.cc
+++ b/quic/core/quic_crypto_client_handshaker.cc
@@ -124,6 +124,16 @@
   return false;
 }
 
+bool QuicCryptoClientHandshaker::EarlyDataAccepted() const {
+  QUIC_BUG_IF(!one_rtt_keys_available_);
+  return num_client_hellos_ == 1;
+}
+
+bool QuicCryptoClientHandshaker::ReceivedInchoateReject() const {
+  QUIC_BUG_IF(!one_rtt_keys_available_);
+  return num_client_hellos_ == 3;
+}
+
 int QuicCryptoClientHandshaker::num_scup_messages_received() const {
   return num_scup_messages_received_;
 }
diff --git a/quic/core/quic_crypto_client_handshaker.h b/quic/core/quic_crypto_client_handshaker.h
index be3907d..8c33ee9 100644
--- a/quic/core/quic_crypto_client_handshaker.h
+++ b/quic/core/quic_crypto_client_handshaker.h
@@ -38,6 +38,8 @@
   bool CryptoConnect() override;
   int num_sent_client_hellos() const override;
   bool IsResumption() const override;
+  bool EarlyDataAccepted() const override;
+  bool ReceivedInchoateReject() const override;
   int num_scup_messages_received() const override;
   std::string chlo_hash() const override;
   bool encryption_established() const override;
diff --git a/quic/core/quic_crypto_client_stream.cc b/quic/core/quic_crypto_client_stream.cc
index aa8c1b5..62990c1 100644
--- a/quic/core/quic_crypto_client_stream.cc
+++ b/quic/core/quic_crypto_client_stream.cc
@@ -65,6 +65,14 @@
   return handshaker_->IsResumption();
 }
 
+bool QuicCryptoClientStream::EarlyDataAccepted() const {
+  return handshaker_->EarlyDataAccepted();
+}
+
+bool QuicCryptoClientStream::ReceivedInchoateReject() const {
+  return handshaker_->ReceivedInchoateReject();
+}
+
 int QuicCryptoClientStream::num_scup_messages_received() const {
   return handshaker_->num_scup_messages_received();
 }
diff --git a/quic/core/quic_crypto_client_stream.h b/quic/core/quic_crypto_client_stream.h
index 01f9612..5af0a66 100644
--- a/quic/core/quic_crypto_client_stream.h
+++ b/quic/core/quic_crypto_client_stream.h
@@ -30,6 +30,9 @@
   // is still connected.
   virtual bool CryptoConnect() = 0;
 
+  // DEPRECATED: Use IsResumption, EarlyDataAccepted, and/or
+  // ReceivedInchoateReject instead.
+  //
   // num_sent_client_hellos returns the number of client hello messages that
   // have been sent. If the handshake has completed then this is one greater
   // than the number of round-trips needed for the handshake.
@@ -42,6 +45,15 @@
   // complete.
   virtual bool IsResumption() const = 0;
 
+  // Returns true if early data (0-RTT) was accepted in the connection.
+  virtual bool EarlyDataAccepted() const = 0;
+
+  // Returns true if the client received an inchoate REJ during the handshake,
+  // extending the handshake by one round trip. This only applies for QUIC
+  // crypto handshakes. The equivalent feature in IETF QUIC is a Retry packet,
+  // but that is handled at the connection layer instead of the crypto layer.
+  virtual bool ReceivedInchoateReject() const = 0;
+
   // The number of server config update messages received by the
   // client.  Does not count update messages that were received prior
   // to handshake confirmation.
@@ -81,6 +93,9 @@
     // connection is still connected.
     virtual bool CryptoConnect() = 0;
 
+    // DEPRECATED: Use IsResumption, EarlyDataAccepted, and/or
+    // ReceivedInchoateReject instead.
+    //
     // num_sent_client_hellos returns the number of client hello messages that
     // have been sent. If the handshake has completed then this is one greater
     // than the number of round-trips needed for the handshake.
@@ -93,6 +108,15 @@
     // complete.
     virtual bool IsResumption() const = 0;
 
+    // Returns true if early data (0-RTT) was accepted in the connection.
+    virtual bool EarlyDataAccepted() const = 0;
+
+    // Returns true if the client received an inchoate REJ during the handshake,
+    // extending the handshake by one round trip. This only applies for QUIC
+    // crypto handshakes. The equivalent feature in IETF QUIC is a Retry packet,
+    // but that is handled at the connection layer instead of the crypto layer.
+    virtual bool ReceivedInchoateReject() const = 0;
+
     // The number of server config update messages received by the
     // client.  Does not count update messages that were received prior
     // to handshake confirmation.
@@ -161,6 +185,8 @@
   bool CryptoConnect() override;
   int num_sent_client_hellos() const override;
   bool IsResumption() const override;
+  bool EarlyDataAccepted() const override;
+  bool ReceivedInchoateReject() const override;
 
   int num_scup_messages_received() const override;
 
diff --git a/quic/core/tls_client_handshaker.cc b/quic/core/tls_client_handshaker.cc
index 42955ce..ece7a05 100644
--- a/quic/core/tls_client_handshaker.cc
+++ b/quic/core/tls_client_handshaker.cc
@@ -204,7 +204,6 @@
 }
 
 int TlsClientHandshaker::num_sent_client_hellos() const {
-  // TODO(nharper): Return a sensible value here.
   return 0;
 }
 
@@ -213,6 +212,17 @@
   return SSL_session_reused(ssl()) == 1;
 }
 
+bool TlsClientHandshaker::EarlyDataAccepted() const {
+  QUIC_BUG_IF(!one_rtt_keys_available_);
+  return SSL_early_data_accepted(ssl()) == 1;
+}
+
+bool TlsClientHandshaker::ReceivedInchoateReject() const {
+  QUIC_BUG_IF(!one_rtt_keys_available_);
+  // REJ messages are a QUIC crypto feature, so TLS always returns false.
+  return false;
+}
+
 int TlsClientHandshaker::num_scup_messages_received() const {
   // SCUP messages aren't sent or received when using the TLS handshake.
   return 0;
diff --git a/quic/core/tls_client_handshaker.h b/quic/core/tls_client_handshaker.h
index 5c5390f..7cba7ad 100644
--- a/quic/core/tls_client_handshaker.h
+++ b/quic/core/tls_client_handshaker.h
@@ -40,6 +40,8 @@
   bool CryptoConnect() override;
   int num_sent_client_hellos() const override;
   bool IsResumption() const override;
+  bool EarlyDataAccepted() const override;
+  bool ReceivedInchoateReject() const override;
   int num_scup_messages_received() const override;
   std::string chlo_hash() const override;