Land Recent QUIC changes.

Implemented RTO calculation for TCP sender.

Merge internal change: 49182038

Introduce a different proof-demand type for ECDSA certs.

In cl/48309237, wtc enabled ECDSA certificates for QUIC. However,
Windows XP can't cope with them so we mustn't return ECDSA certs to
those clients.

The value of ECDSA over RSA in QUIC is much less than in TLS because the
server doesn't need to sign every connection. However, they are likely
to be ~192 bytes smaller, which might be useful.

This change disables ECDSA certificates for the <X509> tag and
introduces a new <X59E> tag by which the client can advertise that it
supports ECDSA certificates.

Merge internal change: 49170028

Added whitespace.

Merge internal change: 49130502

QUIC: check that encryption sequence numbers always increase.

Since sequence number reuse is causes the end of the world, check that
it never happens.

This makes me feel more warm and fuzzy.

Merge internal change: 49113162

QUIC: Send larger client hellos when hoping for certificates.

With cl/49050453, larger client hellos can get larger rejection messages.
This change causes the client to send larger client hellos when it's
likely that we'll be getting certificates. In the event that the
certificates fit in the larger space, but not the smaller one, this
saves a round trip.

Merge internal change: 49109243

QUIC: allow larger ClientHellos to get larger certificate chains.

At the moment we hope that the certificate chain compression gets the
certs down to under 400 bytes and then we feel ok about sending them in
a reply to an unverified source address.

But since we're switching to 2K certs that's basically hopeless: the
leaf certificate will have two, uncompressable blobs in it: the public
key and the signature and, for 2K, they are 256 bytes each.

This change allows a client to send a client hello with more padding and
get a larger reply to an unverified source address. What we don't want
is to become a DDoS amplifier so we make the attacker work in order to
get more from us.

Merge internal change: 49050453

QUIC: Update the common certificate set with GIAG2.

This doesn't break the protocol, but it does mean that clients with the
old certificate set won't be able to elide any certificates. But since
Chrome isn't working with QUIC HTTPS yet anyway, that's not a problem.

Merge internal change: 49050091

Modify QuicStreamSequencer::OnStreamFrame to not call ProcessRawData
with zero length data.  Fixes http://crbug.com/257041 

Merge internal change: 48912969
BUG=257041

Change ReliableQuicStream::OnStreamFrame to simply delegate fin
handling to the QuicStreamSequencer. 

Merge internal change: 48900554

Spliting QuicPacketEntropyManager into QuicReceivedEntropyManager and
QuicSentEntropyManager, in preparation for a larger refactor to create
a ReceivedPacketManager. 

Merge internal change: 48860732

Add a test to recreate the invalid ack created when an Ack is sent
immediately in response to a received ack, but the incoming ack's
corresponding headers, and hence packet entropy, has not been
processed. 

Merge internal change: 48848920

Aggregate ACK and Feedback frames properly.

Existing code tried to pack acks with feedback info, and regulate
transmission of control packets. There was a bug where it sometimes
didn't pack together an ack with a feedback frame (specifically when
we were blocked from sending non-retransmittable data). There was a
second bug wherein a control frame might be prematurely serialized,
when it could *not* be sent immediately. Specifically when the control
frame was the first frame in a packet, and non-retransmittable data
could be sent, the control frame could be errantly added.

We now consistently aggregate ack frames with feedback frames in a
single packet whenever the coalescing won't delay the sending of the
just-in-time calculated frames. We now also avoid adding a control
frame into a packet unless we are sure it can be sent immediately (so
that we don't block or delay future ack and feedback transmission).

The CL includes updates to tests so that they fail with the old code,
but pass with the new code, as well as a bunch of additions to
comments. This CL is based on the Chromium CL 17341005 (which is not
landing until its merge time comes around), and resolves chromium bug
256116.

FIXED=9502307

Merge internal change: 48841932
BUG=256116

Add logging to the QUIC write path.

merge chromium CL: 17518002

Merge internal change: 48811324

Most of the changes were already in chromium except for comment change.

Fix broken test (opt mode) in cl/48802264.

Merge internal change: 48806857

Demote LOG(ERROR) to DLOG(INFO) when a client sends a packet with
unsupported version. This should not be considered an ERROR
server-side, as a client is free to send us whatever they like. We
deal with it by sending a version negotiation packet and all is well. 

Updated tests, and added some comments.

Merge internal change: 48802264

Added time_wait_list_manager helper method to QuicDispatcher.

Merge internal change: 48787571

QUIC: encode the cluster in the first four bytes of the orbit value.

In order to try and measure, in Chrome, when we might have saved a round-trip
with a cluster-wide strike-register we need to know when we hit another server
in the same cluster. We could do that by IP address somewhat, but it's a little
complex and there's the /8 vs /5 between core and ....

This change causes the first four bytes of the orbit to include a hash of the
cluster (or ... rack name) so that we can easily track this in Chrome.

Merge internal change: 48784059

Fix a bug in ReliableQuicStream::OnDecompressorAvailable where a
decompression failure would result in an infinite loop. 

Merge internal change: 48696905

patch from issue 20054002

Enabling ChannelId for QUIC, and passing the ChannelId header to
google backends if we're using it.  Not flag protected as we're not
doing secure-quic in prod yet. 

Merge internal change: 48645878

* Removed QuicTag kQuicVersion1
* Replaced this with enum QuicVersion, which currently has
  QUIC_VERSION_6 and QUIC_VERSION_7
* End to end tests are run with both versions
* Framer tests are run with both versions
* QuicConnection now takes a QuicVersion parameter
* TimeWaitListManager now stores QuicVersion in the GUID map and sets
  the framer version appropriately using this before sending reset 

Merge internal change: 48634592

[email protected]

Review URL: https://chromiumcodereview.appspot.com/20227003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213914 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/quic/quic_protocol.h b/net/quic/quic_protocol.h
index 4090f4c..93a53333 100644
--- a/net/quic/quic_protocol.h
+++ b/net/quic/quic_protocol.h
@@ -63,9 +63,6 @@
 // Signifies that the QuicPacket will contain version of the protocol.
 const bool kIncludeVersion = true;
 
-// Returns true if |version| is a supported protocol version.
-NET_EXPORT_PRIVATE bool IsSupportedVersion(QuicTag version);
-
 // Index of the first byte in a QUIC packet which is used in hash calculation.
 const size_t kStartOfHashData = 0;
 
@@ -175,6 +172,59 @@
   PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
 };
 
+// The available versions of QUIC. Guaranteed that the integer value of the enum
+// will match the version number.
+// When adding a new version to this enum you should add it to
+// kSupportedVersions (if appropriate), and also add a new case to the helper
+// methods QuicVersionToQuicTag, and QuicTagToQuicVersion.
+enum QuicVersion {
+  // Special case to indicate unknown/unsupported QUIC version.
+  QUIC_VERSION_UNSUPPORTED = 0,
+
+  QUIC_VERSION_6 = 6,  // Current version.
+};
+
+// This vector contains QUIC versions which we currently support.
+// This should be ordered such that the highest supported version is the first
+// element, with subsequent elements in descending order (versions can be
+// skipped as necessary).
+static const QuicVersion kSupportedQuicVersions[] = {QUIC_VERSION_6};
+
+typedef std::vector<QuicVersion> QuicVersionVector;
+
+// Upper limit on versions we support.
+NET_EXPORT_PRIVATE QuicVersion QuicVersionMax();
+
+// QuicTag is written to and read from the wire, but we prefer to use
+// the more readable QuicVersion at other levels.
+// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
+// if QuicVersion is unsupported.
+NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
+
+// Returns appropriate QuicVersion from a QuicTag.
+// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
+NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
+
+// Helper function which translates from a QuicVersion to a string.
+// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
+NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
+
+// Returns comma separated list of string representations of QuicVersion enum
+// values in the supplied QuicVersionArray.
+NET_EXPORT_PRIVATE std::string QuicVersionArrayToString(
+    const QuicVersion versions[], int num_versions);
+
+// Version and Crypto tags are written to the wire with a big-endian
+// representation of the name of the tag.  For example
+// the client hello tag (CHLO) will be written as the
+// following 4 bytes: 'C' 'H' 'L' 'O'.  Since it is
+// stored in memory as a little endian uint32, we need
+// to reverse the order of the bytes.
+
+// MakeQuicTag returns a value given the four bytes. For example:
+//   MakeQuicTag('C', 'H', 'L', 'O');
+NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
+
 // Size in bytes of the data or fec packet header.
 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicPacketHeader header);
 
@@ -323,27 +373,6 @@
   QUIC_LAST_ERROR,
 };
 
-// Version and Crypto tags are written to the wire with a big-endian
-// representation of the name of the tag.  For example
-// the client hello tag (CHLO) will be written as the
-// following 4 bytes: 'C' 'H' 'L' 'O'.  Since it is
-// stored in memory as a little endian uint32, we need
-// to reverse the order of the bytes.
-//
-// The TAG macro is used in header files to ensure that we don't create static
-// initialisers. In normal code, the MakeQuicTag function should be used.
-#define TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a)
-const QuicTag kUnsupportedVersion = -1;
-// Each time the wire format changes, this need needs to be incremented.
-// At some point, we will actually freeze the wire format and make an official
-// version number, but this works for now.
-const QuicTag kQuicVersion1 = TAG('Q', '0', '0', '6');
-#undef TAG
-
-// MakeQuicTag returns a value given the four bytes. For example:
-//   MakeQuicTag('C', 'H', 'L', 'O');
-uint32 NET_EXPORT_PRIVATE MakeQuicTag(char a, char b, char c, char d);
-
 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
   QuicPacketPublicHeader();
   explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
@@ -357,7 +386,7 @@
   bool reset_flag;
   bool version_flag;
   QuicSequenceNumberLength sequence_number_length;
-  QuicTagVector versions;
+  QuicVersionVector versions;
 };
 
 // Header for Data or FEC packets.