Land Recent QUIC Changes

QUIC crypto: move config objects.

Currently the client and server configs are setup and torn-down for each
connection. Since they are supposed to be per-client and per-server objects,
this change makes them parameters that are passed into the connection

Merge internal change: 44269387

QUIC crypto steps 6 and 7: per-server strike register.

This change adds a per-server strike-register that allows the server to
complete 0-RTT connections if the client has enough information cached.

Due to the fact that the per-server and per-client objects
(QuicCryptoServerConfig and QuicCryptoClientConfig) are currently setup and
torn down for each connection, there's no tests in this change for a 0-RTT
handshake because we can't do one yet. The next change will move these objects
into the right place so that 0-RTT handshakes can be tested.

This change also reminded me why I had a server nonce: without it the server
cannot terminate any connections if the strike-register fails. So the server
nonce is firmly back.

Merge internal change: 44228897

[email protected]

Review URL: https://codereview.chromium.org/13976007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194634 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/quic/test_tools/crypto_test_utils.cc b/net/quic/test_tools/crypto_test_utils.cc
index 5086044..c2d5988 100644
--- a/net/quic/test_tools/crypto_test_utils.cc
+++ b/net/quic/test_tools/crypto_test_utils.cc
@@ -5,8 +5,11 @@
 #include "net/quic/test_tools/crypto_test_utils.h"
 
 #include "base/strings/string_piece.h"
+#include "net/quic/crypto/crypto_handshake.h"
 #include "net/quic/crypto/quic_decrypter.h"
 #include "net/quic/crypto/quic_encrypter.h"
+#include "net/quic/crypto/quic_random.h"
+#include "net/quic/quic_clock.h"
 #include "net/quic/quic_crypto_client_stream.h"
 #include "net/quic/quic_crypto_server_stream.h"
 #include "net/quic/quic_crypto_stream.h"
@@ -75,7 +78,15 @@
   PacketSavingConnection* server_conn =
       new PacketSavingConnection(guid, addr, true);
   TestSession server_session(server_conn, true);
-  QuicCryptoServerStream server(&server_session);
+
+  QuicConfig config;
+  QuicCryptoServerConfig crypto_config(QuicCryptoServerConfig::TESTING);
+  SetupCryptoServerConfigForTest(
+      server_session.connection()->clock(),
+      server_session.connection()->random_generator(),
+      &config, &crypto_config);
+
+  QuicCryptoServerStream server(config, crypto_config, &server_session);
 
   // The client's handshake must have been started already.
   CHECK_NE(0u, client_conn->packets_.size());
@@ -96,7 +107,13 @@
   PacketSavingConnection* client_conn =
       new PacketSavingConnection(guid, addr, false);
   TestSession client_session(client_conn, true);
-  QuicCryptoClientStream client(&client_session, "test.example.com");
+  QuicConfig config;
+  QuicCryptoClientConfig crypto_config;
+
+  config.SetDefaults();
+  crypto_config.SetDefaults();
+  QuicCryptoClientStream client("test.example.com", config, &client_session,
+                                &crypto_config);
 
   CHECK(client.CryptoConnect());
   CHECK_EQ(1u, client_conn->packets_.size());
@@ -107,6 +124,23 @@
 }
 
 // static
+void CryptoTestUtils::SetupCryptoServerConfigForTest(
+    const QuicClock* clock,
+    QuicRandom* rand,
+    QuicConfig* config,
+    QuicCryptoServerConfig* crypto_config) {
+  config->SetDefaults();
+  CryptoHandshakeMessage extra_tags;
+  config->ToHandshakeMessage(&extra_tags);
+
+  scoped_ptr<CryptoHandshakeMessage> scfg(
+      crypto_config->AddDefaultConfig(rand, clock, extra_tags));
+  if (!config->SetFromHandshakeMessage(*scfg)) {
+    CHECK(false) << "Crypto config could not be parsed by QuicConfig.";
+  }
+}
+
+// static
 string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message,
                                        CryptoTag tag) {
   CryptoTagValueMap::const_iterator it = message.tag_value_map().find(tag);