Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: net/quic/quic_connection.cc

Issue 19858003: * Removed QuicTag kQuicVersion1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compiler errors Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 return delta <= kMaxPacketGap; 62 return delta <= kMaxPacketGap;
63 } 63 }
64 64
65 } // namespace 65 } // namespace
66 66
67 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") 67 #define ENDPOINT (is_server_ ? "Server: " : " Client: ")
68 68
69 QuicConnection::QuicConnection(QuicGuid guid, 69 QuicConnection::QuicConnection(QuicGuid guid,
70 IPEndPoint address, 70 IPEndPoint address,
71 QuicConnectionHelperInterface* helper, 71 QuicConnectionHelperInterface* helper,
72 bool is_server) 72 bool is_server,
73 : framer_(kQuicVersion1, 73 QuicVersion version)
74 : framer_(version,
74 helper->GetClock()->ApproximateNow(), 75 helper->GetClock()->ApproximateNow(),
75 is_server), 76 is_server),
76 helper_(helper), 77 helper_(helper),
77 encryption_level_(ENCRYPTION_NONE), 78 encryption_level_(ENCRYPTION_NONE),
78 clock_(helper->GetClock()), 79 clock_(helper->GetClock()),
79 random_generator_(helper->GetRandomGenerator()), 80 random_generator_(helper->GetRandomGenerator()),
80 guid_(guid), 81 guid_(guid),
81 peer_address_(address), 82 peer_address_(address),
82 largest_seen_packet_with_ack_(0), 83 largest_seen_packet_with_ack_(0),
83 peer_largest_observed_packet_(0), 84 peer_largest_observed_packet_(0),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 STLDeleteValues(&unacked_packets_); 127 STLDeleteValues(&unacked_packets_);
127 STLDeleteValues(&group_map_); 128 STLDeleteValues(&group_map_);
128 for (QueuedPacketList::iterator it = queued_packets_.begin(); 129 for (QueuedPacketList::iterator it = queued_packets_.begin();
129 it != queued_packets_.end(); ++it) { 130 it != queued_packets_.end(); ++it) {
130 delete it->packet; 131 delete it->packet;
131 } 132 }
132 DLOG(INFO) << ENDPOINT << "write_blocked: " << write_blocked_; 133 DLOG(INFO) << ENDPOINT << "write_blocked: " << write_blocked_;
133 } 134 }
134 135
135 bool QuicConnection::SelectMutualVersion( 136 bool QuicConnection::SelectMutualVersion(
136 const QuicTagVector& available_versions) { 137 const QuicVersionVector& available_versions) {
137 // TODO(satyamshekhar): Make this generic. 138 // Try to find the highest mutual version by iterating over supported
138 if (std::find(available_versions.begin(), available_versions.end(), 139 // versions, starting with the highest, and breaking out of the loop once we
139 kQuicVersion1) == available_versions.end()) { 140 // find a matching version in the provided available_versions vector.
140 return false; 141 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSupportedQuicVersions); ++i) {
142 const QuicVersion& version = kSupportedQuicVersions[i];
143 if (std::find(available_versions.begin(), available_versions.end(),
144 version) != available_versions.end()) {
145 framer_.set_version(version);
146 return true;
147 }
141 } 148 }
142 149
143 // Right now we only support kQuicVersion1 so it's okay not to 150 return false;
144 // update the framer version. When we start supporting more
145 // versions please update.
146 return true;
147 } 151 }
148 152
149 void QuicConnection::OnError(QuicFramer* framer) { 153 void QuicConnection::OnError(QuicFramer* framer) {
150 // Packets that we cannot decrypt are dropped. 154 // Packets that we cannot decrypt are dropped.
151 // TODO(rch): add stats to measure this. 155 // TODO(rch): add stats to measure this.
152 if (!connected_ || framer->error() == QUIC_DECRYPTION_FAILURE) { 156 if (!connected_ || framer->error() == QUIC_DECRYPTION_FAILURE) {
153 return; 157 return;
154 } 158 }
155 SendConnectionClose(framer->error()); 159 SendConnectionClose(framer->error());
156 } 160 }
157 161
158 void QuicConnection::OnPacket() { 162 void QuicConnection::OnPacket() {
159 } 163 }
160 164
161 void QuicConnection::OnPublicResetPacket( 165 void QuicConnection::OnPublicResetPacket(
162 const QuicPublicResetPacket& packet) { 166 const QuicPublicResetPacket& packet) {
163 if (debug_visitor_) { 167 if (debug_visitor_) {
164 debug_visitor_->OnPublicResetPacket(packet); 168 debug_visitor_->OnPublicResetPacket(packet);
165 } 169 }
166 CloseConnection(QUIC_PUBLIC_RESET, true); 170 CloseConnection(QUIC_PUBLIC_RESET, true);
167 } 171 }
168 172
169 bool QuicConnection::OnProtocolVersionMismatch(QuicTag received_version) { 173 bool QuicConnection::OnProtocolVersionMismatch(QuicVersion received_version) {
170 // TODO(satyamshekhar): Implement no server state in this mode. 174 // TODO(satyamshekhar): Implement no server state in this mode.
171 if (!is_server_) { 175 if (!is_server_) {
172 LOG(DFATAL) << ENDPOINT << "Framer called OnProtocolVersionMismatch. " 176 LOG(DFATAL) << ENDPOINT << "Framer called OnProtocolVersionMismatch. "
173 << "Closing connection."; 177 << "Closing connection.";
174 CloseConnection(QUIC_INTERNAL_ERROR, false); 178 CloseConnection(QUIC_INTERNAL_ERROR, false);
175 return false; 179 return false;
176 } 180 }
177 DCHECK_NE(version(), received_version); 181 DCHECK_NE(version(), received_version);
178 182
179 if (debug_visitor_) { 183 if (debug_visitor_) {
(...skipping 18 matching lines...) Expand all
198 202
199 case NEGOTIATED_VERSION: 203 case NEGOTIATED_VERSION:
200 // Might be old packets that were sent by the client before the version 204 // Might be old packets that were sent by the client before the version
201 // was negotiated. Drop these. 205 // was negotiated. Drop these.
202 return false; 206 return false;
203 207
204 default: 208 default:
205 DCHECK(false); 209 DCHECK(false);
206 } 210 }
207 211
208 // Right now we only support kQuicVersion1 so it's okay not to
209 // update the framer version. When we start supporting more
210 // versions please update.
211 version_negotiation_state_ = NEGOTIATED_VERSION; 212 version_negotiation_state_ = NEGOTIATED_VERSION;
213
214 // Store the new version.
215 framer_.set_version(received_version);
216
212 // TODO(satyamshekhar): Store the sequence number of this packet and close the 217 // TODO(satyamshekhar): Store the sequence number of this packet and close the
213 // connection if we ever received a packet with incorrect version and whose 218 // connection if we ever received a packet with incorrect version and whose
214 // sequence number is greater. 219 // sequence number is greater.
215 return true; 220 return true;
216 } 221 }
217 222
218 // Handles version negotiation for client connection. 223 // Handles version negotiation for client connection.
219 void QuicConnection::OnVersionNegotiationPacket( 224 void QuicConnection::OnVersionNegotiationPacket(
220 const QuicVersionNegotiationPacket& packet) { 225 const QuicVersionNegotiationPacket& packet) {
221 if (is_server_) { 226 if (is_server_) {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 SendAck(); 695 SendAck();
691 } else if (!last_stream_frames_.empty()) { 696 } else if (!last_stream_frames_.empty()) {
692 // TODO(alyssar) this case should really be "if the packet contained any 697 // TODO(alyssar) this case should really be "if the packet contained any
693 // non-ack frame", rather than "if the packet contained a stream frame" 698 // non-ack frame", rather than "if the packet contained a stream frame"
694 helper_->SetAckAlarm(congestion_manager_.DefaultRetransmissionTime()); 699 helper_->SetAckAlarm(congestion_manager_.DefaultRetransmissionTime());
695 } 700 }
696 send_ack_in_response_to_packet_ = !send_ack_in_response_to_packet_; 701 send_ack_in_response_to_packet_ = !send_ack_in_response_to_packet_;
697 } 702 }
698 703
699 void QuicConnection::SendVersionNegotiationPacket() { 704 void QuicConnection::SendVersionNegotiationPacket() {
700 QuicTagVector supported_versions; 705 QuicVersionVector supported_versions;
701 supported_versions.push_back(kQuicVersion1); 706 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSupportedQuicVersions); ++i) {
707 supported_versions.push_back(kSupportedQuicVersions[i]);
708 }
702 QuicEncryptedPacket* encrypted = 709 QuicEncryptedPacket* encrypted =
703 packet_creator_.SerializeVersionNegotiationPacket(supported_versions); 710 packet_creator_.SerializeVersionNegotiationPacket(supported_versions);
704 // TODO(satyamshekhar): implement zero server state negotiation. 711 // TODO(satyamshekhar): implement zero server state negotiation.
705 int error; 712 int error;
706 helper_->WritePacketToWire(*encrypted, &error); 713 helper_->WritePacketToWire(*encrypted, &error);
707 delete encrypted; 714 delete encrypted;
708 } 715 }
709 716
710 QuicConsumedData QuicConnection::SendStreamData(QuicStreamId id, 717 QuicConsumedData QuicConnection::SendStreamData(QuicStreamId id,
711 base::StringPiece data, 718 base::StringPiece data,
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 if (connection_timeout < timeout) { 1571 if (connection_timeout < timeout) {
1565 timeout = connection_timeout; 1572 timeout = connection_timeout;
1566 } 1573 }
1567 } 1574 }
1568 1575
1569 helper_->SetTimeoutAlarm(timeout); 1576 helper_->SetTimeoutAlarm(timeout);
1570 return false; 1577 return false;
1571 } 1578 }
1572 1579
1573 } // namespace net 1580 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698