Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / net / quic / quic_crypto_server_stream.cc
index 8bd1ae2..dac2087 100644 (file)
@@ -11,6 +11,7 @@
 #include "net/quic/crypto/quic_crypto_server_config.h"
 #include "net/quic/crypto/source_address_token.h"
 #include "net/quic/quic_config.h"
+#include "net/quic/quic_flags.h"
 #include "net/quic/quic_protocol.h"
 #include "net/quic/quic_session.h"
 
@@ -30,10 +31,9 @@ QuicCryptoServerStream::QuicCryptoServerStream(
     QuicSession* session)
     : QuicCryptoStream(session),
       crypto_config_(crypto_config),
-      validate_client_hello_cb_(NULL),
+      validate_client_hello_cb_(nullptr),
       num_handshake_messages_(0),
-      num_server_config_update_messages_sent_(0) {
-}
+      num_server_config_update_messages_sent_(0) {}
 
 QuicCryptoServerStream::~QuicCryptoServerStream() {
   CancelOutstandingCallbacks();
@@ -41,7 +41,7 @@ QuicCryptoServerStream::~QuicCryptoServerStream() {
 
 void QuicCryptoServerStream::CancelOutstandingCallbacks() {
   // Detach from the validation callback.  Calling this multiple times is safe.
-  if (validate_client_hello_cb_ != NULL) {
+  if (validate_client_hello_cb_ != nullptr) {
     validate_client_hello_cb_->Cancel();
   }
 }
@@ -62,7 +62,7 @@ void QuicCryptoServerStream::OnHandshakeMessage(
     return;
   }
 
-  if (validate_client_hello_cb_ != NULL) {
+  if (validate_client_hello_cb_ != nullptr) {
     // Already processing some other handshake message.  The protocol
     // does not allow for clients to send multiple handshake messages
     // before the server has a chance to respond.
@@ -82,8 +82,8 @@ void QuicCryptoServerStream::FinishProcessingHandshakeMessage(
     const CryptoHandshakeMessage& message,
     const ValidateClientHelloResultCallback::Result& result) {
   // Clear the callback that got us here.
-  DCHECK(validate_client_hello_cb_ != NULL);
-  validate_client_hello_cb_ = NULL;
+  DCHECK(validate_client_hello_cb_ != nullptr);
+  validate_client_hello_cb_ = nullptr;
 
   string error_details;
   CryptoHandshakeMessage reply;
@@ -120,8 +120,7 @@ void QuicCryptoServerStream::FinishProcessingHandshakeMessage(
   session()->connection()->SetEncrypter(
       ENCRYPTION_INITIAL,
       crypto_negotiated_params_.initial_crypters.encrypter.release());
-  session()->connection()->SetDefaultEncryptionLevel(
-      ENCRYPTION_INITIAL);
+  session()->connection()->SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
   // Set the decrypter immediately so that we no longer accept unencrypted
   // packets.
   session()->connection()->SetDecrypter(
@@ -141,8 +140,10 @@ void QuicCryptoServerStream::FinishProcessingHandshakeMessage(
   session()->connection()->SetEncrypter(
       ENCRYPTION_FORWARD_SECURE,
       crypto_negotiated_params_.forward_secure_crypters.encrypter.release());
-  session()->connection()->SetDefaultEncryptionLevel(
-      ENCRYPTION_FORWARD_SECURE);
+  if (!FLAGS_enable_quic_delay_forward_security) {
+    session()->connection()->SetDefaultEncryptionLevel(
+        ENCRYPTION_FORWARD_SECURE);
+  }
   session()->connection()->SetAlternativeDecrypter(
       crypto_negotiated_params_.forward_secure_crypters.decrypter.release(),
       ENCRYPTION_FORWARD_SECURE, false /* don't latch */);
@@ -150,10 +151,6 @@ void QuicCryptoServerStream::FinishProcessingHandshakeMessage(
   encryption_established_ = true;
   handshake_confirmed_ = true;
   session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED);
-
-  // Now that the handshake is complete, send an updated server config and
-  // source-address token to the client.
-  SendServerConfigUpdate(NULL);
 }
 
 void QuicCryptoServerStream::SendServerConfigUpdate(
@@ -178,7 +175,7 @@ void QuicCryptoServerStream::SendServerConfigUpdate(
   DVLOG(1) << "Server: Sending server config update: "
            << server_config_update_message.DebugString();
   const QuicData& data = server_config_update_message.GetSerialized();
-  WriteOrBufferData(string(data.data(), data.length()), false, NULL);
+  WriteOrBufferData(string(data.data(), data.length()), false, nullptr);
 
   ++num_server_config_update_messages_sent_;
 }
@@ -187,6 +184,12 @@ void QuicCryptoServerStream::OnServerHelloAcked() {
   session()->connection()->OnHandshakeComplete();
 }
 
+void QuicCryptoServerStream::set_previous_cached_network_params(
+    CachedNetworkParameters cached_network_params) {
+  previous_cached_network_params_.reset(
+      new CachedNetworkParameters(cached_network_params));
+}
+
 bool QuicCryptoServerStream::GetBase64SHA256ClientChannelID(
     string* output) const {
   if (!encryption_established_ ||
@@ -222,6 +225,12 @@ QuicErrorCode QuicCryptoServerStream::ProcessClientHello(
     const ValidateClientHelloResultCallback::Result& result,
     CryptoHandshakeMessage* reply,
     string* error_details) {
+  // Store the bandwidth estimate from the client.
+  if (result.cached_network_params.bandwidth_estimate_bytes_per_second() > 0) {
+    previous_cached_network_params_.reset(
+        new CachedNetworkParameters(result.cached_network_params));
+  }
+
   return crypto_config_.ProcessClientHello(
       result,
       session()->connection()->connection_id(),
@@ -236,18 +245,21 @@ QuicErrorCode QuicCryptoServerStream::ProcessClientHello(
 void QuicCryptoServerStream::OverrideQuicConfigDefaults(QuicConfig* config) {
 }
 
+CachedNetworkParameters*
+QuicCryptoServerStream::get_previous_cached_network_params() {
+  return previous_cached_network_params_.get();
+}
+
 QuicCryptoServerStream::ValidateCallback::ValidateCallback(
     QuicCryptoServerStream* parent) : parent_(parent) {
 }
 
-void QuicCryptoServerStream::ValidateCallback::Cancel() {
-  parent_ = NULL;
-}
+void QuicCryptoServerStream::ValidateCallback::Cancel() { parent_ = nullptr; }
 
 void QuicCryptoServerStream::ValidateCallback::RunImpl(
     const CryptoHandshakeMessage& client_hello,
     const Result& result) {
-  if (parent_ != NULL) {
+  if (parent_ != nullptr) {
     parent_->FinishProcessingHandshakeMessage(client_hello, result);
   }
 }