| 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 #include "net/tools/quic/quic_server_session.h" |
| 20 | 21 |
| 21 using base::StringPiece; | 22 using base::StringPiece; |
| 22 using std::make_pair; | 23 using std::make_pair; |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| 25 namespace tools { | 26 namespace tools { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 // Time period for which the guid should live in time wait state.. | 30 // Time period for which the guid should live in time wait state.. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 private: | 87 private: |
| 87 const IPEndPoint server_address_; | 88 const IPEndPoint server_address_; |
| 88 const IPEndPoint client_address_; | 89 const IPEndPoint client_address_; |
| 89 scoped_ptr<QuicEncryptedPacket> packet_; | 90 scoped_ptr<QuicEncryptedPacket> packet_; |
| 90 | 91 |
| 91 DISALLOW_COPY_AND_ASSIGN(QueuedPacket); | 92 DISALLOW_COPY_AND_ASSIGN(QueuedPacket); |
| 92 }; | 93 }; |
| 93 | 94 |
| 94 QuicTimeWaitListManager::QuicTimeWaitListManager( | 95 QuicTimeWaitListManager::QuicTimeWaitListManager( |
| 95 QuicPacketWriter* writer, | 96 QuicPacketWriter* writer, |
| 97 QuicServerSessionVisitor* visitor, |
| 96 EpollServer* epoll_server, | 98 EpollServer* epoll_server, |
| 97 const QuicVersionVector& supported_versions) | 99 const QuicVersionVector& supported_versions) |
| 98 : epoll_server_(epoll_server), | 100 : epoll_server_(epoll_server), |
| 99 kTimeWaitPeriod_(QuicTime::Delta::FromSeconds(kTimeWaitSeconds)), | 101 kTimeWaitPeriod_(QuicTime::Delta::FromSeconds(kTimeWaitSeconds)), |
| 100 guid_clean_up_alarm_(new GuidCleanUpAlarm(this)), | 102 guid_clean_up_alarm_(new GuidCleanUpAlarm(this)), |
| 101 clock_(epoll_server_), | 103 clock_(epoll_server_), |
| 102 writer_(writer) { | 104 writer_(writer), |
| 105 visitor_(visitor) { |
| 103 SetGuidCleanUpAlarm(); | 106 SetGuidCleanUpAlarm(); |
| 104 } | 107 } |
| 105 | 108 |
| 106 QuicTimeWaitListManager::~QuicTimeWaitListManager() { | 109 QuicTimeWaitListManager::~QuicTimeWaitListManager() { |
| 107 guid_clean_up_alarm_->UnregisterIfRegistered(); | 110 guid_clean_up_alarm_->UnregisterIfRegistered(); |
| 108 STLDeleteElements(&time_ordered_guid_list_); | 111 STLDeleteElements(&time_ordered_guid_list_); |
| 109 STLDeleteElements(&pending_packets_queue_); | 112 STLDeleteElements(&pending_packets_queue_); |
| 110 for (GuidMapIterator it = guid_map_.begin(); it != guid_map_.end(); ++it) { | 113 for (GuidMapIterator it = guid_map_.begin(); it != guid_map_.end(); ++it) { |
| 111 delete it->second.close_packet; | 114 delete it->second.close_packet; |
| 112 } | 115 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 if (WriteToWire(packet)) { | 211 if (WriteToWire(packet)) { |
| 209 delete packet; | 212 delete packet; |
| 210 } else { | 213 } else { |
| 211 // pending_packets_queue takes the ownership of the queued packet. | 214 // pending_packets_queue takes the ownership of the queued packet. |
| 212 pending_packets_queue_.push_back(packet); | 215 pending_packets_queue_.push_back(packet); |
| 213 } | 216 } |
| 214 } | 217 } |
| 215 | 218 |
| 216 bool QuicTimeWaitListManager::WriteToWire(QueuedPacket* queued_packet) { | 219 bool QuicTimeWaitListManager::WriteToWire(QueuedPacket* queued_packet) { |
| 217 if (writer_->IsWriteBlocked()) { | 220 if (writer_->IsWriteBlocked()) { |
| 221 visitor_->OnWriteBlocked(this); |
| 218 return false; | 222 return false; |
| 219 } | 223 } |
| 220 WriteResult result = writer_->WritePacket( | 224 WriteResult result = writer_->WritePacket( |
| 221 queued_packet->packet()->data(), | 225 queued_packet->packet()->data(), |
| 222 queued_packet->packet()->length(), | 226 queued_packet->packet()->length(), |
| 223 queued_packet->server_address().address(), | 227 queued_packet->server_address().address(), |
| 224 queued_packet->client_address(), | 228 queued_packet->client_address(), |
| 225 this); | 229 this); |
| 226 if (result.status == WRITE_STATUS_BLOCKED) { | 230 if (result.status == WRITE_STATUS_BLOCKED) { |
| 227 // If blocked and unbuffered, return false to retry sending. | 231 // If blocked and unbuffered, return false to retry sending. |
| 228 DCHECK(writer_->IsWriteBlocked()); | 232 DCHECK(writer_->IsWriteBlocked()); |
| 233 visitor_->OnWriteBlocked(this); |
| 229 return writer_->IsWriteBlockedDataBuffered(); | 234 return writer_->IsWriteBlockedDataBuffered(); |
| 230 } else if (result.status == WRITE_STATUS_ERROR) { | 235 } else if (result.status == WRITE_STATUS_ERROR) { |
| 231 LOG(WARNING) << "Received unknown error while sending reset packet to " | 236 LOG(WARNING) << "Received unknown error while sending reset packet to " |
| 232 << queued_packet->client_address().ToString() << ": " | 237 << queued_packet->client_address().ToString() << ": " |
| 233 << strerror(result.error_code); | 238 << strerror(result.error_code); |
| 234 } | 239 } |
| 235 return true; | 240 return true; |
| 236 } | 241 } |
| 237 | 242 |
| 238 void QuicTimeWaitListManager::SetGuidCleanUpAlarm() { | 243 void QuicTimeWaitListManager::SetGuidCleanUpAlarm() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 269 delete it->second.close_packet; | 274 delete it->second.close_packet; |
| 270 guid_map_.erase(oldest_guid->guid); | 275 guid_map_.erase(oldest_guid->guid); |
| 271 time_ordered_guid_list_.pop_front(); | 276 time_ordered_guid_list_.pop_front(); |
| 272 delete oldest_guid; | 277 delete oldest_guid; |
| 273 } | 278 } |
| 274 SetGuidCleanUpAlarm(); | 279 SetGuidCleanUpAlarm(); |
| 275 } | 280 } |
| 276 | 281 |
| 277 } // namespace tools | 282 } // namespace tools |
| 278 } // namespace net | 283 } // namespace net |
| OLD | NEW |