| 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/tools/quic/quic_time_wait_list_manager.h" | 5 #include "net/tools/quic/quic_time_wait_list_manager.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 | 8 |
| 9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "net/base/ip_endpoint.h" | 12 #include "net/base/ip_endpoint.h" |
| 13 #include "net/quic/crypto/crypto_protocol.h" | 13 #include "net/quic/crypto/crypto_protocol.h" |
| 14 #include "net/quic/crypto/quic_decrypter.h" | 14 #include "net/quic/crypto/quic_decrypter.h" |
| 15 #include "net/quic/crypto/quic_encrypter.h" | 15 #include "net/quic/crypto/quic_encrypter.h" |
| 16 #include "net/quic/quic_clock.h" | 16 #include "net/quic/quic_clock.h" |
| 17 #include "net/quic/quic_framer.h" | 17 #include "net/quic/quic_framer.h" |
| 18 #include "net/quic/quic_protocol.h" | 18 #include "net/quic/quic_protocol.h" |
| 19 #include "net/quic/quic_utils.h" | 19 #include "net/quic/quic_utils.h" |
| 20 | 20 |
| 21 using std::make_pair; |
| 22 |
| 21 namespace net { | 23 namespace net { |
| 22 namespace tools { | 24 namespace tools { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 // Time period for which the guid should live in time wait state.. | 28 // Time period for which the guid should live in time wait state.. |
| 27 const int kTimeWaitSeconds = 5; | 29 const int kTimeWaitSeconds = 5; |
| 28 | 30 |
| 29 } // namespace | 31 } // namespace |
| 30 | 32 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 const IPEndPoint server_address_; | 86 const IPEndPoint server_address_; |
| 85 const IPEndPoint client_address_; | 87 const IPEndPoint client_address_; |
| 86 scoped_ptr<QuicEncryptedPacket> packet_; | 88 scoped_ptr<QuicEncryptedPacket> packet_; |
| 87 | 89 |
| 88 DISALLOW_COPY_AND_ASSIGN(QueuedPacket); | 90 DISALLOW_COPY_AND_ASSIGN(QueuedPacket); |
| 89 }; | 91 }; |
| 90 | 92 |
| 91 QuicTimeWaitListManager::QuicTimeWaitListManager( | 93 QuicTimeWaitListManager::QuicTimeWaitListManager( |
| 92 QuicPacketWriter* writer, | 94 QuicPacketWriter* writer, |
| 93 EpollServer* epoll_server) | 95 EpollServer* epoll_server) |
| 94 : framer_(kQuicVersion1, | 96 : framer_(QUIC_VERSION_6, |
| 95 QuicTime::Zero(), // unused | 97 QuicTime::Zero(), // unused |
| 96 true), | 98 true), |
| 97 epoll_server_(epoll_server), | 99 epoll_server_(epoll_server), |
| 98 kTimeWaitPeriod_(QuicTime::Delta::FromSeconds(kTimeWaitSeconds)), | 100 kTimeWaitPeriod_(QuicTime::Delta::FromSeconds(kTimeWaitSeconds)), |
| 99 guid_clean_up_alarm_(new GuidCleanUpAlarm(this)), | 101 guid_clean_up_alarm_(new GuidCleanUpAlarm(this)), |
| 100 clock_(epoll_server), | 102 clock_(epoll_server), |
| 101 writer_(writer), | 103 writer_(writer), |
| 102 is_write_blocked_(false) { | 104 is_write_blocked_(false) { |
| 103 framer_.set_visitor(this); | 105 framer_.set_visitor(this); |
| 104 SetGuidCleanUpAlarm(); | 106 SetGuidCleanUpAlarm(); |
| 105 } | 107 } |
| 106 | 108 |
| 107 QuicTimeWaitListManager::~QuicTimeWaitListManager() { | 109 QuicTimeWaitListManager::~QuicTimeWaitListManager() { |
| 108 guid_clean_up_alarm_->UnregisterIfRegistered(); | 110 guid_clean_up_alarm_->UnregisterIfRegistered(); |
| 109 STLDeleteElements(&time_ordered_guid_list_); | 111 STLDeleteElements(&time_ordered_guid_list_); |
| 110 STLDeleteElements(&pending_packets_queue_); | 112 STLDeleteElements(&pending_packets_queue_); |
| 111 } | 113 } |
| 112 | 114 |
| 113 void QuicTimeWaitListManager::AddGuidToTimeWait(QuicGuid guid) { | 115 void QuicTimeWaitListManager::AddGuidToTimeWait(QuicGuid guid, |
| 116 QuicVersion version) { |
| 114 DCHECK(!IsGuidInTimeWait(guid)); | 117 DCHECK(!IsGuidInTimeWait(guid)); |
| 115 // Initialize the guid with 0 packets received. | 118 // Initialize the guid with 0 packets received. |
| 116 guid_map_.insert(std::make_pair(guid, 0)); | 119 GuidData data(0, version); |
| 120 guid_map_.insert(make_pair(guid, data)); |
| 117 time_ordered_guid_list_.push_back(new GuidAddTime(guid, | 121 time_ordered_guid_list_.push_back(new GuidAddTime(guid, |
| 118 clock_.ApproximateNow())); | 122 clock_.ApproximateNow())); |
| 119 } | 123 } |
| 120 | 124 |
| 121 bool QuicTimeWaitListManager::IsGuidInTimeWait(QuicGuid guid) const { | 125 bool QuicTimeWaitListManager::IsGuidInTimeWait(QuicGuid guid) const { |
| 122 return guid_map_.find(guid) != guid_map_.end(); | 126 return guid_map_.find(guid) != guid_map_.end(); |
| 123 } | 127 } |
| 124 | 128 |
| 125 void QuicTimeWaitListManager::ProcessPacket( | 129 void QuicTimeWaitListManager::ProcessPacket( |
| 126 const IPEndPoint& server_address, | 130 const IPEndPoint& server_address, |
| 127 const IPEndPoint& client_address, | 131 const IPEndPoint& client_address, |
| 128 QuicGuid guid, | 132 QuicGuid guid, |
| 129 const QuicEncryptedPacket& packet) { | 133 const QuicEncryptedPacket& packet) { |
| 130 DCHECK(IsGuidInTimeWait(guid)); | 134 DCHECK(IsGuidInTimeWait(guid)); |
| 131 server_address_ = server_address; | 135 server_address_ = server_address; |
| 132 client_address_ = client_address; | 136 client_address_ = client_address; |
| 133 // TODO(satyamshekhar): Also store the version of protocol for and | 137 |
| 134 // update the protocol version of the framer before processing. | 138 // Set the framer to the appropriate version for this GUID, before processing. |
| 139 QuicVersion version = GetQuicVersionFromGuid(guid); |
| 140 framer_.set_version(version); |
| 141 |
| 135 framer_.ProcessPacket(packet); | 142 framer_.ProcessPacket(packet); |
| 136 } | 143 } |
| 137 | 144 |
| 145 QuicVersion QuicTimeWaitListManager::GetQuicVersionFromGuid(QuicGuid guid) { |
| 146 GuidMapIterator it = guid_map_.find(guid); |
| 147 DCHECK(it != guid_map_.end()); |
| 148 return (it->second).version; |
| 149 } |
| 150 |
| 138 bool QuicTimeWaitListManager::OnCanWrite() { | 151 bool QuicTimeWaitListManager::OnCanWrite() { |
| 139 is_write_blocked_ = false; | 152 is_write_blocked_ = false; |
| 140 while (!is_write_blocked_ && !pending_packets_queue_.empty()) { | 153 while (!is_write_blocked_ && !pending_packets_queue_.empty()) { |
| 141 QueuedPacket* queued_packet = pending_packets_queue_.front(); | 154 QueuedPacket* queued_packet = pending_packets_queue_.front(); |
| 142 WriteToWire(queued_packet); | 155 WriteToWire(queued_packet); |
| 143 if (!is_write_blocked_) { | 156 if (!is_write_blocked_) { |
| 144 pending_packets_queue_.pop_front(); | 157 pending_packets_queue_.pop_front(); |
| 145 delete queued_packet; | 158 delete queued_packet; |
| 146 } | 159 } |
| 147 } | 160 } |
| 148 | 161 |
| 149 return !is_write_blocked_; | 162 return !is_write_blocked_; |
| 150 } | 163 } |
| 151 | 164 |
| 152 void QuicTimeWaitListManager::OnError(QuicFramer* framer) { | 165 void QuicTimeWaitListManager::OnError(QuicFramer* framer) { |
| 153 DLOG(INFO) << QuicUtils::ErrorToString(framer->error()); | 166 DLOG(INFO) << QuicUtils::ErrorToString(framer->error()); |
| 154 } | 167 } |
| 155 | 168 |
| 156 bool QuicTimeWaitListManager::OnProtocolVersionMismatch( | 169 bool QuicTimeWaitListManager::OnProtocolVersionMismatch( |
| 157 QuicTag received_version) { | 170 QuicVersion received_version) { |
| 158 // Drop such packets whose version don't match. | 171 // Drop such packets whose version don't match. |
| 159 return false; | 172 return false; |
| 160 } | 173 } |
| 161 | 174 |
| 162 bool QuicTimeWaitListManager::OnStreamFrame(const QuicStreamFrame& frame) { | 175 bool QuicTimeWaitListManager::OnStreamFrame(const QuicStreamFrame& frame) { |
| 163 return false; | 176 return false; |
| 164 } | 177 } |
| 165 | 178 |
| 166 bool QuicTimeWaitListManager::OnAckFrame(const QuicAckFrame& frame) { | 179 bool QuicTimeWaitListManager::OnAckFrame(const QuicAckFrame& frame) { |
| 167 return false; | 180 return false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 185 bool QuicTimeWaitListManager::OnGoAwayFrame(const QuicGoAwayFrame& frame) { | 198 bool QuicTimeWaitListManager::OnGoAwayFrame(const QuicGoAwayFrame& frame) { |
| 186 return false; | 199 return false; |
| 187 } | 200 } |
| 188 | 201 |
| 189 bool QuicTimeWaitListManager::OnPacketHeader(const QuicPacketHeader& header) { | 202 bool QuicTimeWaitListManager::OnPacketHeader(const QuicPacketHeader& header) { |
| 190 // TODO(satyamshekhar): Think about handling packets from different client | 203 // TODO(satyamshekhar): Think about handling packets from different client |
| 191 // addresses. | 204 // addresses. |
| 192 GuidMapIterator it = guid_map_.find(header.public_header.guid); | 205 GuidMapIterator it = guid_map_.find(header.public_header.guid); |
| 193 DCHECK(it != guid_map_.end()); | 206 DCHECK(it != guid_map_.end()); |
| 194 // Increment the received packet count. | 207 // Increment the received packet count. |
| 195 ++(it->second); | 208 ++((it->second).num_packets); |
| 196 if (ShouldSendPublicReset(it->second)) { | 209 if (ShouldSendPublicReset((it->second).num_packets)) { |
| 197 // We don't need the packet anymore. Just tell the client what sequence | 210 // We don't need the packet anymore. Just tell the client what sequence |
| 198 // number we rejected. | 211 // number we rejected. |
| 199 SendPublicReset(server_address_, | 212 SendPublicReset(server_address_, |
| 200 client_address_, | 213 client_address_, |
| 201 header.public_header.guid, | 214 header.public_header.guid, |
| 202 header.packet_sequence_number); | 215 header.packet_sequence_number); |
| 203 } | 216 } |
| 204 // Never process the body of the packet in time wait state. | 217 // Never process the body of the packet in time wait state. |
| 205 return false; | 218 return false; |
| 206 } | 219 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 // This guid has lived its age, retire it now. | 312 // This guid has lived its age, retire it now. |
| 300 guid_map_.erase(oldest_guid->guid); | 313 guid_map_.erase(oldest_guid->guid); |
| 301 time_ordered_guid_list_.pop_front(); | 314 time_ordered_guid_list_.pop_front(); |
| 302 delete oldest_guid; | 315 delete oldest_guid; |
| 303 } | 316 } |
| 304 SetGuidCleanUpAlarm(); | 317 SetGuidCleanUpAlarm(); |
| 305 } | 318 } |
| 306 | 319 |
| 307 } // namespace tools | 320 } // namespace tools |
| 308 } // namespace net | 321 } // namespace net |
| OLD | NEW |