OLD | NEW |
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 <string.h> | 7 #include <string.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 return false; | 436 return false; |
437 } | 437 } |
438 | 438 |
439 // Will be decrement below if we fall through to return true; | 439 // Will be decrement below if we fall through to return true; |
440 ++stats_.packets_dropped; | 440 ++stats_.packets_dropped; |
441 | 441 |
442 if (header.public_header.connection_id != connection_id_) { | 442 if (header.public_header.connection_id != connection_id_) { |
443 DVLOG(1) << ENDPOINT << "Ignoring packet from unexpected ConnectionId: " | 443 DVLOG(1) << ENDPOINT << "Ignoring packet from unexpected ConnectionId: " |
444 << header.public_header.connection_id << " instead of " | 444 << header.public_header.connection_id << " instead of " |
445 << connection_id_; | 445 << connection_id_; |
| 446 if (debug_visitor_.get() != NULL) { |
| 447 debug_visitor_->OnIncorrectConnectionId( |
| 448 header.public_header.connection_id); |
| 449 } |
446 return false; | 450 return false; |
447 } | 451 } |
448 | 452 |
449 if (!Near(header.packet_sequence_number, | 453 if (!Near(header.packet_sequence_number, |
450 last_header_.packet_sequence_number)) { | 454 last_header_.packet_sequence_number)) { |
451 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number | 455 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number |
452 << " out of bounds. Discarding"; | 456 << " out of bounds. Discarding"; |
453 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER, | 457 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER, |
454 "Packet sequence number out of bounds"); | 458 "Packet sequence number out of bounds"); |
455 return false; | 459 return false; |
456 } | 460 } |
457 | 461 |
458 // If this packet has already been seen, or that the sender | 462 // If this packet has already been seen, or that the sender |
459 // has told us will not be retransmitted, then stop processing the packet. | 463 // has told us will not be retransmitted, then stop processing the packet. |
460 if (!received_packet_manager_.IsAwaitingPacket( | 464 if (!received_packet_manager_.IsAwaitingPacket( |
461 header.packet_sequence_number)) { | 465 header.packet_sequence_number)) { |
462 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number | 466 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number |
463 << " no longer being waited for. Discarding."; | 467 << " no longer being waited for. Discarding."; |
464 // TODO(jri): Log reception of duplicate packets or packets the peer has | 468 if (debug_visitor_.get() != NULL) { |
465 // told us to stop waiting for. | 469 debug_visitor_->OnDuplicatePacket(header.packet_sequence_number); |
| 470 } |
466 return false; | 471 return false; |
467 } | 472 } |
468 | 473 |
469 if (version_negotiation_state_ != NEGOTIATED_VERSION) { | 474 if (version_negotiation_state_ != NEGOTIATED_VERSION) { |
470 if (is_server_) { | 475 if (is_server_) { |
471 if (!header.public_header.version_flag) { | 476 if (!header.public_header.version_flag) { |
472 DLOG(WARNING) << ENDPOINT << "Packet " << header.packet_sequence_number | 477 DLOG(WARNING) << ENDPOINT << "Packet " << header.packet_sequence_number |
473 << " without version flag before version negotiated."; | 478 << " without version flag before version negotiated."; |
474 // Packets should have the version flag till version negotiation is | 479 // Packets should have the version flag till version negotiation is |
475 // done. | 480 // done. |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 last_size_ = packet.length(); | 1085 last_size_ = packet.length(); |
1081 | 1086 |
1082 CheckForAddressMigration(self_address, peer_address); | 1087 CheckForAddressMigration(self_address, peer_address); |
1083 | 1088 |
1084 stats_.bytes_received += packet.length(); | 1089 stats_.bytes_received += packet.length(); |
1085 ++stats_.packets_received; | 1090 ++stats_.packets_received; |
1086 | 1091 |
1087 if (!framer_.ProcessPacket(packet)) { | 1092 if (!framer_.ProcessPacket(packet)) { |
1088 // If we are unable to decrypt this packet, it might be | 1093 // If we are unable to decrypt this packet, it might be |
1089 // because the CHLO or SHLO packet was lost. | 1094 // because the CHLO or SHLO packet was lost. |
1090 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && | 1095 if (framer_.error() == QUIC_DECRYPTION_FAILURE) { |
1091 framer_.error() == QUIC_DECRYPTION_FAILURE && | 1096 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && |
1092 undecryptable_packets_.size() < kMaxUndecryptablePackets) { | 1097 undecryptable_packets_.size() < kMaxUndecryptablePackets) { |
1093 QueueUndecryptablePacket(packet); | 1098 QueueUndecryptablePacket(packet); |
| 1099 } else if (debug_visitor_ != NULL) { |
| 1100 debug_visitor_->OnUndecryptablePacket(); |
| 1101 } |
1094 } | 1102 } |
1095 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " | 1103 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " |
1096 << last_header_.packet_sequence_number; | 1104 << last_header_.packet_sequence_number; |
1097 return; | 1105 return; |
1098 } | 1106 } |
1099 | 1107 |
1100 ++stats_.packets_processed; | 1108 ++stats_.packets_processed; |
1101 MaybeProcessUndecryptablePackets(); | 1109 MaybeProcessUndecryptablePackets(); |
1102 MaybeProcessRevivedPacket(); | 1110 MaybeProcessRevivedPacket(); |
1103 MaybeSendInResponseToPacket(); | 1111 MaybeSendInResponseToPacket(); |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1680 DVLOG(1) << ENDPOINT << "Processed undecryptable packet!"; | 1688 DVLOG(1) << ENDPOINT << "Processed undecryptable packet!"; |
1681 ++stats_.packets_processed; | 1689 ++stats_.packets_processed; |
1682 delete packet; | 1690 delete packet; |
1683 undecryptable_packets_.pop_front(); | 1691 undecryptable_packets_.pop_front(); |
1684 } | 1692 } |
1685 | 1693 |
1686 // Once forward secure encryption is in use, there will be no | 1694 // Once forward secure encryption is in use, there will be no |
1687 // new keys installed and hence any undecryptable packets will | 1695 // new keys installed and hence any undecryptable packets will |
1688 // never be able to be decrypted. | 1696 // never be able to be decrypted. |
1689 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE) { | 1697 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE) { |
| 1698 if (debug_visitor_ != NULL) { |
| 1699 for (size_t i = 0; i < undecryptable_packets_.size(); ++i) { |
| 1700 debug_visitor_->OnUndecryptablePacket(); |
| 1701 } |
| 1702 } |
1690 STLDeleteElements(&undecryptable_packets_); | 1703 STLDeleteElements(&undecryptable_packets_); |
1691 } | 1704 } |
1692 } | 1705 } |
1693 | 1706 |
1694 void QuicConnection::MaybeProcessRevivedPacket() { | 1707 void QuicConnection::MaybeProcessRevivedPacket() { |
1695 QuicFecGroup* group = GetFecGroup(); | 1708 QuicFecGroup* group = GetFecGroup(); |
1696 if (!connected_ || group == NULL || !group->CanRevive()) { | 1709 if (!connected_ || group == NULL || !group->CanRevive()) { |
1697 return; | 1710 return; |
1698 } | 1711 } |
1699 QuicPacketHeader revived_header; | 1712 QuicPacketHeader revived_header; |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1970 // If we changed the generator's batch state, restore original batch state. | 1983 // If we changed the generator's batch state, restore original batch state. |
1971 if (!already_in_batch_mode_) { | 1984 if (!already_in_batch_mode_) { |
1972 DVLOG(1) << "Leaving Batch Mode."; | 1985 DVLOG(1) << "Leaving Batch Mode."; |
1973 connection_->packet_generator_.FinishBatchOperations(); | 1986 connection_->packet_generator_.FinishBatchOperations(); |
1974 } | 1987 } |
1975 DCHECK_EQ(already_in_batch_mode_, | 1988 DCHECK_EQ(already_in_batch_mode_, |
1976 connection_->packet_generator_.InBatchMode()); | 1989 connection_->packet_generator_.InBatchMode()); |
1977 } | 1990 } |
1978 | 1991 |
1979 } // namespace net | 1992 } // namespace net |
OLD | NEW |