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

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

Issue 12254037: Add a DebugVisitor to QuicConnection to facilitate logging the activity on a QUIC connection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
« no previous file with comments | « net/quic/quic_connection.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 random_generator_(helper->GetRandomGenerator()), 91 random_generator_(helper->GetRandomGenerator()),
92 guid_(guid), 92 guid_(guid),
93 peer_address_(address), 93 peer_address_(address),
94 should_send_ack_(false), 94 should_send_ack_(false),
95 should_send_congestion_feedback_(false), 95 should_send_congestion_feedback_(false),
96 largest_seen_packet_with_ack_(0), 96 largest_seen_packet_with_ack_(0),
97 peer_largest_observed_packet_(0), 97 peer_largest_observed_packet_(0),
98 peer_least_packet_awaiting_ack_(0), 98 peer_least_packet_awaiting_ack_(0),
99 handling_retransmission_timeout_(false), 99 handling_retransmission_timeout_(false),
100 write_blocked_(false), 100 write_blocked_(false),
101 debug_visitor_(NULL),
101 packet_creator_(guid_, &framer_), 102 packet_creator_(guid_, &framer_),
102 timeout_(QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)), 103 timeout_(QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)),
103 time_of_last_packet_(clock_->Now()), 104 time_of_last_packet_(clock_->Now()),
104 congestion_manager_(clock_, kTCP), 105 congestion_manager_(clock_, kTCP),
105 connected_(true), 106 connected_(true),
106 received_truncated_ack_(false), 107 received_truncated_ack_(false),
107 send_ack_in_response_to_packet_(false) { 108 send_ack_in_response_to_packet_(false) {
108 helper_->SetConnection(this); 109 helper_->SetConnection(this);
109 helper_->SetTimeoutAlarm(timeout_); 110 helper_->SetTimeoutAlarm(timeout_);
110 framer_.set_visitor(this); 111 framer_.set_visitor(this);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 time_of_last_packet_ = clock_->Now(); 177 time_of_last_packet_ = clock_->Now();
177 DVLOG(1) << "last packet: " << time_of_last_packet_.ToMicroseconds(); 178 DVLOG(1) << "last packet: " << time_of_last_packet_.ToMicroseconds();
178 179
179 // TODO(alyssar, rch) handle migration! 180 // TODO(alyssar, rch) handle migration!
180 self_address_ = last_self_address_; 181 self_address_ = last_self_address_;
181 peer_address_ = last_peer_address_; 182 peer_address_ = last_peer_address_;
182 } 183 }
183 184
184 void QuicConnection::OnPublicResetPacket( 185 void QuicConnection::OnPublicResetPacket(
185 const QuicPublicResetPacket& packet) { 186 const QuicPublicResetPacket& packet) {
187 if (debug_visitor_) {
188 debug_visitor_->OnPublicResetPacket(packet);
189 }
186 CloseConnection(QUIC_PUBLIC_RESET, true); 190 CloseConnection(QUIC_PUBLIC_RESET, true);
187 } 191 }
188 192
189 void QuicConnection::OnRevivedPacket() { 193 void QuicConnection::OnRevivedPacket() {
190 } 194 }
191 195
192 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { 196 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) {
197 if (debug_visitor_) {
198 debug_visitor_->OnPacketHeader(header);
199 }
193 if (header.public_header.guid != guid_) { 200 if (header.public_header.guid != guid_) {
194 DLOG(INFO) << "Ignoring packet from unexpected GUID: " 201 DLOG(INFO) << "Ignoring packet from unexpected GUID: "
195 << header.public_header.guid << " instead of " << guid_; 202 << header.public_header.guid << " instead of " << guid_;
196 return false; 203 return false;
197 } 204 }
198 205
199 if (!Near(header.packet_sequence_number, 206 if (!Near(header.packet_sequence_number,
200 last_header_.packet_sequence_number)) { 207 last_header_.packet_sequence_number)) {
201 DLOG(INFO) << "Packet " << header.packet_sequence_number 208 DLOG(INFO) << "Packet " << header.packet_sequence_number
202 << " out of bounds. Discarding"; 209 << " out of bounds. Discarding";
(...skipping 12 matching lines...) Expand all
215 return true; 222 return true;
216 } 223 }
217 224
218 void QuicConnection::OnFecProtectedPayload(StringPiece payload) { 225 void QuicConnection::OnFecProtectedPayload(StringPiece payload) {
219 DCHECK_NE(0u, last_header_.fec_group); 226 DCHECK_NE(0u, last_header_.fec_group);
220 QuicFecGroup* group = GetFecGroup(); 227 QuicFecGroup* group = GetFecGroup();
221 group->Update(last_header_, payload); 228 group->Update(last_header_, payload);
222 } 229 }
223 230
224 void QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { 231 void QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) {
232 if (debug_visitor_) {
233 debug_visitor_->OnStreamFrame(frame);
234 }
225 last_stream_frames_.push_back(frame); 235 last_stream_frames_.push_back(frame);
226 } 236 }
227 237
228 void QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) { 238 void QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) {
239 if (debug_visitor_) {
240 debug_visitor_->OnAckFrame(incoming_ack);
241 }
229 DVLOG(1) << "Ack packet: " << incoming_ack; 242 DVLOG(1) << "Ack packet: " << incoming_ack;
230 243
231 if (last_header_.packet_sequence_number <= largest_seen_packet_with_ack_) { 244 if (last_header_.packet_sequence_number <= largest_seen_packet_with_ack_) {
232 DLOG(INFO) << "Received an old ack frame: ignoring"; 245 DLOG(INFO) << "Received an old ack frame: ignoring";
233 return; 246 return;
234 } 247 }
235 largest_seen_packet_with_ack_ = last_header_.packet_sequence_number; 248 largest_seen_packet_with_ack_ = last_header_.packet_sequence_number;
236 249
237 if (!ValidateAckFrame(incoming_ack)) { 250 if (!ValidateAckFrame(incoming_ack)) {
238 SendConnectionClose(QUIC_INVALID_ACK_DATA); 251 SendConnectionClose(QUIC_INVALID_ACK_DATA);
(...skipping 18 matching lines...) Expand all
257 if (!write_blocked_) { 270 if (!write_blocked_) {
258 OnCanWrite(); 271 OnCanWrite();
259 } 272 }
260 } else { 273 } else {
261 helper_->SetSendAlarm(delay); 274 helper_->SetSendAlarm(delay);
262 } 275 }
263 } 276 }
264 277
265 void QuicConnection::OnCongestionFeedbackFrame( 278 void QuicConnection::OnCongestionFeedbackFrame(
266 const QuicCongestionFeedbackFrame& feedback) { 279 const QuicCongestionFeedbackFrame& feedback) {
280 if (debug_visitor_) {
281 debug_visitor_->OnCongestionFeedbackFrame(feedback);
282 }
267 congestion_manager_.OnIncomingQuicCongestionFeedbackFrame(feedback); 283 congestion_manager_.OnIncomingQuicCongestionFeedbackFrame(feedback);
268 } 284 }
269 285
270 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { 286 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) {
271 if (incoming_ack.received_info.largest_observed > 287 if (incoming_ack.received_info.largest_observed >
272 packet_creator_.sequence_number()) { 288 packet_creator_.sequence_number()) {
273 DLOG(ERROR) << "Client observed unsent packet:" 289 DLOG(ERROR) << "Client observed unsent packet:"
274 << incoming_ack.received_info.largest_observed << " vs " 290 << incoming_ack.received_info.largest_observed << " vs "
275 << packet_creator_.sequence_number(); 291 << packet_creator_.sequence_number();
276 // We got an error for data we have not sent. Error out. 292 // We got an error for data we have not sent. Error out.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 CloseFecGroupsBefore(incoming_ack.sent_info.least_unacked + 1); 447 CloseFecGroupsBefore(incoming_ack.sent_info.least_unacked + 1);
432 } 448 }
433 449
434 void QuicConnection::OnFecData(const QuicFecData& fec) { 450 void QuicConnection::OnFecData(const QuicFecData& fec) {
435 DCHECK_NE(0u, last_header_.fec_group); 451 DCHECK_NE(0u, last_header_.fec_group);
436 QuicFecGroup* group = GetFecGroup(); 452 QuicFecGroup* group = GetFecGroup();
437 group->UpdateFec(last_header_.packet_sequence_number, fec); 453 group->UpdateFec(last_header_.packet_sequence_number, fec);
438 } 454 }
439 455
440 void QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { 456 void QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) {
457 if (debug_visitor_) {
458 debug_visitor_->OnRstStreamFrame(frame);
459 }
441 DLOG(INFO) << "Stream reset with error " 460 DLOG(INFO) << "Stream reset with error "
442 << QuicUtils::ErrorToString(frame.error_code); 461 << QuicUtils::ErrorToString(frame.error_code);
443 visitor_->OnRstStream(frame); 462 visitor_->OnRstStream(frame);
444 } 463 }
445 464
446 void QuicConnection::OnConnectionCloseFrame( 465 void QuicConnection::OnConnectionCloseFrame(
447 const QuicConnectionCloseFrame& frame) { 466 const QuicConnectionCloseFrame& frame) {
467 if (debug_visitor_) {
468 debug_visitor_->OnConnectionCloseFrame(frame);
469 }
448 DLOG(INFO) << "Connection closed with error " 470 DLOG(INFO) << "Connection closed with error "
449 << QuicUtils::ErrorToString(frame.error_code); 471 << QuicUtils::ErrorToString(frame.error_code);
450 CloseConnection(frame.error_code, true); 472 CloseConnection(frame.error_code, true);
451 } 473 }
452 474
453 void QuicConnection::OnPacketComplete() { 475 void QuicConnection::OnPacketComplete() {
454 if (!last_packet_revived_) { 476 if (!last_packet_revived_) {
455 DLOG(INFO) << "Got packet " << last_header_.packet_sequence_number 477 DLOG(INFO) << "Got packet " << last_header_.packet_sequence_number
456 << " with " << last_stream_frames_.size() 478 << " with " << last_stream_frames_.size()
457 << " stream frames for " << last_header_.public_header.guid; 479 << " stream frames for " << last_header_.public_header.guid;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 561
540 // Try to write immediately if possible. 562 // Try to write immediately if possible.
541 if (CanWrite(!kIsRetransmission)) { 563 if (CanWrite(!kIsRetransmission)) {
542 WriteQueuedData(kFlush); 564 WriteQueuedData(kFlush);
543 } 565 }
544 } 566 }
545 567
546 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, 568 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address,
547 const IPEndPoint& peer_address, 569 const IPEndPoint& peer_address,
548 const QuicEncryptedPacket& packet) { 570 const QuicEncryptedPacket& packet) {
571 if (debug_visitor_) {
572 debug_visitor_->OnPacketReceived(self_address, peer_address, packet);
jar (doing other things) 2013/02/14 17:13:19 nit/comment: It is IMO common for the observer to
Ryan Hamilton 2013/02/14 17:46:19 *nod* Definitely something to consider. At the m
573 }
549 last_packet_revived_ = false; 574 last_packet_revived_ = false;
550 last_size_ = packet.length(); 575 last_size_ = packet.length();
551 last_self_address_ = self_address; 576 last_self_address_ = self_address;
552 last_peer_address_ = peer_address; 577 last_peer_address_ = peer_address;
553 framer_.ProcessPacket(packet); 578 framer_.ProcessPacket(packet);
554 MaybeProcessRevivedPacket(); 579 MaybeProcessRevivedPacket();
555 } 580 }
556 581
557 bool QuicConnection::OnCanWrite() { 582 bool QuicConnection::OnCanWrite() {
558 write_blocked_ = false; 583 write_blocked_ = false;
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 char revived_payload[kMaxPacketSize]; 960 char revived_payload[kMaxPacketSize];
936 size_t len = group->Revive(&revived_header, revived_payload, kMaxPacketSize); 961 size_t len = group->Revive(&revived_header, revived_payload, kMaxPacketSize);
937 revived_header.public_header.guid = guid_; 962 revived_header.public_header.guid = guid_;
938 revived_header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; 963 revived_header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE;
939 revived_header.private_flags = PACKET_PRIVATE_FLAGS_NONE; 964 revived_header.private_flags = PACKET_PRIVATE_FLAGS_NONE;
940 revived_header.fec_group = kNoFecOffset; 965 revived_header.fec_group = kNoFecOffset;
941 group_map_.erase(last_header_.fec_group); 966 group_map_.erase(last_header_.fec_group);
942 delete group; 967 delete group;
943 968
944 last_packet_revived_ = true; 969 last_packet_revived_ = true;
970 if (debug_visitor_) {
971 debug_visitor_->OnRevivedPacket(revived_header,
972 StringPiece(revived_payload, len));
973 }
945 framer_.ProcessRevivedPacket(revived_header, 974 framer_.ProcessRevivedPacket(revived_header,
946 StringPiece(revived_payload, len)); 975 StringPiece(revived_payload, len));
947 } 976 }
948 977
949 QuicFecGroup* QuicConnection::GetFecGroup() { 978 QuicFecGroup* QuicConnection::GetFecGroup() {
950 QuicFecGroupNumber fec_group_num = last_header_.fec_group; 979 QuicFecGroupNumber fec_group_num = last_header_.fec_group;
951 if (fec_group_num == 0) { 980 if (fec_group_num == 0) {
952 return NULL; 981 return NULL;
953 } 982 }
954 if (group_map_.count(fec_group_num) == 0) { 983 if (group_map_.count(fec_group_num) == 0) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 << " delta:" << delta.ToMicroseconds(); 1048 << " delta:" << delta.ToMicroseconds();
1020 if (delta >= timeout_) { 1049 if (delta >= timeout_) {
1021 SendConnectionClose(QUIC_CONNECTION_TIMED_OUT); 1050 SendConnectionClose(QUIC_CONNECTION_TIMED_OUT);
1022 return true; 1051 return true;
1023 } 1052 }
1024 helper_->SetTimeoutAlarm(timeout_.Subtract(delta)); 1053 helper_->SetTimeoutAlarm(timeout_.Subtract(delta));
1025 return false; 1054 return false;
1026 } 1055 }
1027 1056
1028 } // namespace net 1057 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698