| Index: net/quic/quic_connection.cc
|
| diff --git a/net/quic/quic_connection.cc b/net/quic/quic_connection.cc
|
| index f4076069d488d8615c733551a38361bf2d6f93e2..11f72cf65b6afdb77db06ebc49e9d9831fb6852a 100644
|
| --- a/net/quic/quic_connection.cc
|
| +++ b/net/quic/quic_connection.cc
|
| @@ -69,8 +69,9 @@ bool Near(QuicPacketSequenceNumber a, QuicPacketSequenceNumber b) {
|
| QuicConnection::QuicConnection(QuicGuid guid,
|
| IPEndPoint address,
|
| QuicConnectionHelperInterface* helper,
|
| - bool is_server)
|
| - : framer_(kQuicVersion1,
|
| + bool is_server,
|
| + QuicVersion version)
|
| + : framer_(version,
|
| helper->GetClock()->ApproximateNow(),
|
| is_server),
|
| helper_(helper),
|
| @@ -133,17 +134,20 @@ QuicConnection::~QuicConnection() {
|
| }
|
|
|
| bool QuicConnection::SelectMutualVersion(
|
| - const QuicTagVector& available_versions) {
|
| - // TODO(satyamshekhar): Make this generic.
|
| - if (std::find(available_versions.begin(), available_versions.end(),
|
| - kQuicVersion1) == available_versions.end()) {
|
| - return false;
|
| + const QuicVersionVector& available_versions) {
|
| + // Try to find the highest mutual version by iterating over supported
|
| + // versions, starting with the highest, and breaking out of the loop once we
|
| + // find a matching version in the provided available_versions vector.
|
| + for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
|
| + const QuicVersion& version = kSupportedQuicVersions[i];
|
| + if (std::find(available_versions.begin(), available_versions.end(),
|
| + version) != available_versions.end()) {
|
| + framer_.set_version(version);
|
| + return true;
|
| + }
|
| }
|
|
|
| - // Right now we only support kQuicVersion1 so it's okay not to
|
| - // update the framer version. When we start supporting more
|
| - // versions please update.
|
| - return true;
|
| + return false;
|
| }
|
|
|
| void QuicConnection::OnError(QuicFramer* framer) {
|
| @@ -166,7 +170,7 @@ void QuicConnection::OnPublicResetPacket(
|
| CloseConnection(QUIC_PUBLIC_RESET, true);
|
| }
|
|
|
| -bool QuicConnection::OnProtocolVersionMismatch(QuicTag received_version) {
|
| +bool QuicConnection::OnProtocolVersionMismatch(QuicVersion received_version) {
|
| // TODO(satyamshekhar): Implement no server state in this mode.
|
| if (!is_server_) {
|
| LOG(DFATAL) << ENDPOINT << "Framer called OnProtocolVersionMismatch. "
|
| @@ -205,10 +209,11 @@ bool QuicConnection::OnProtocolVersionMismatch(QuicTag received_version) {
|
| DCHECK(false);
|
| }
|
|
|
| - // Right now we only support kQuicVersion1 so it's okay not to
|
| - // update the framer version. When we start supporting more
|
| - // versions please update.
|
| version_negotiation_state_ = NEGOTIATED_VERSION;
|
| +
|
| + // Store the new version.
|
| + framer_.set_version(received_version);
|
| +
|
| // TODO(satyamshekhar): Store the sequence number of this packet and close the
|
| // connection if we ever received a packet with incorrect version and whose
|
| // sequence number is greater.
|
| @@ -697,8 +702,10 @@ void QuicConnection::MaybeSendAckInResponseToPacket() {
|
| }
|
|
|
| void QuicConnection::SendVersionNegotiationPacket() {
|
| - QuicTagVector supported_versions;
|
| - supported_versions.push_back(kQuicVersion1);
|
| + QuicVersionVector supported_versions;
|
| + for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
|
| + supported_versions.push_back(kSupportedQuicVersions[i]);
|
| + }
|
| QuicEncryptedPacket* encrypted =
|
| packet_creator_.SerializeVersionNegotiationPacket(supported_versions);
|
| // TODO(satyamshekhar): implement zero server state negotiation.
|
|
|