| 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 // Handles packets for guids in time wait state by discarding the packet and | 5 // Handles packets for guids in time wait state by discarding the packet and |
| 6 // sending the clients a public reset packet with exponential backoff. | 6 // sending the clients a public reset packet with exponential backoff. |
| 7 | 7 |
| 8 #ifndef NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ | 8 #ifndef NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ |
| 9 #define NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ | 9 #define NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 } // namespace test | 29 } // namespace test |
| 30 | 30 |
| 31 // Maintains a list of all guids that have been recently closed. A guid lives in | 31 // Maintains a list of all guids that have been recently closed. A guid lives in |
| 32 // this state for kTimeWaitPeriod. All packets received for guids in this state | 32 // this state for kTimeWaitPeriod. All packets received for guids in this state |
| 33 // are handed over to the QuicTimeWaitListManager by the QuicDispatcher. | 33 // are handed over to the QuicTimeWaitListManager by the QuicDispatcher. |
| 34 // Decides whether to send a public reset packet, a copy of the previously sent | 34 // Decides whether to send a public reset packet, a copy of the previously sent |
| 35 // connection close packet, or nothing to the client which sent a packet | 35 // connection close packet, or nothing to the client which sent a packet |
| 36 // with the guid in time wait state. After the guid expires its time wait | 36 // with the guid in time wait state. After the guid expires its time wait |
| 37 // period, a new connection/session will be created if a packet is received | 37 // period, a new connection/session will be created if a packet is received |
| 38 // for this guid. | 38 // for this guid. |
| 39 class QuicTimeWaitListManager : public QuicBlockedWriterInterface, | 39 class QuicTimeWaitListManager : public QuicBlockedWriterInterface { |
| 40 public QuicFramerVisitorInterface { | |
| 41 public: | 40 public: |
| 42 // writer - the entity that writes to the socket. (Owned by the dispatcher) | 41 // writer - the entity that writes to the socket. (Owned by the dispatcher) |
| 43 // epoll_server - used to run clean up alarms. (Owned by the dispatcher) | 42 // epoll_server - used to run clean up alarms. (Owned by the dispatcher) |
| 44 QuicTimeWaitListManager(QuicPacketWriter* writer, | 43 QuicTimeWaitListManager(QuicPacketWriter* writer, |
| 45 EpollServer* epoll_server, | 44 EpollServer* epoll_server, |
| 46 const QuicVersionVector& supported_versions); | 45 const QuicVersionVector& supported_versions); |
| 47 virtual ~QuicTimeWaitListManager(); | 46 virtual ~QuicTimeWaitListManager(); |
| 48 | 47 |
| 49 // Adds the given guid to time wait state for kTimeWaitPeriod. Henceforth, | 48 // Adds the given guid to time wait state for kTimeWaitPeriod. Henceforth, |
| 50 // any packet bearing this guid should not be processed while the guid remains | 49 // any packet bearing this guid should not be processed while the guid remains |
| (...skipping 10 matching lines...) Expand all Loading... |
| 61 bool IsGuidInTimeWait(QuicGuid guid) const; | 60 bool IsGuidInTimeWait(QuicGuid guid) const; |
| 62 | 61 |
| 63 // Called when a packet is received for a guid that is in time wait state. | 62 // Called when a packet is received for a guid that is in time wait state. |
| 64 // Sends a public reset packet to the client which sent this guid. Sending | 63 // Sends a public reset packet to the client which sent this guid. Sending |
| 65 // of the public reset packet is throttled by using exponential back off. | 64 // of the public reset packet is throttled by using exponential back off. |
| 66 // DCHECKs for the guid to be in time wait state. | 65 // DCHECKs for the guid to be in time wait state. |
| 67 // virtual to override in tests. | 66 // virtual to override in tests. |
| 68 virtual void ProcessPacket(const IPEndPoint& server_address, | 67 virtual void ProcessPacket(const IPEndPoint& server_address, |
| 69 const IPEndPoint& client_address, | 68 const IPEndPoint& client_address, |
| 70 QuicGuid guid, | 69 QuicGuid guid, |
| 71 const QuicEncryptedPacket& packet); | 70 QuicPacketSequenceNumber sequence_number); |
| 72 | 71 |
| 73 // Called by the dispatcher when the underlying socket becomes writable again, | 72 // Called by the dispatcher when the underlying socket becomes writable again, |
| 74 // since we might need to send pending public reset packets which we didn't | 73 // since we might need to send pending public reset packets which we didn't |
| 75 // send because the underlying socket was write blocked. | 74 // send because the underlying socket was write blocked. |
| 76 virtual bool OnCanWrite() OVERRIDE; | 75 virtual bool OnCanWrite() OVERRIDE; |
| 77 | 76 |
| 78 // Used to delete guid entries that have outlived their time wait period. | 77 // Used to delete guid entries that have outlived their time wait period. |
| 79 void CleanUpOldGuids(); | 78 void CleanUpOldGuids(); |
| 80 | 79 |
| 81 // QuicFramerVisitorInterface | 80 // Given a GUID that exists in the time wait list, returns the QuicVersion |
| 82 virtual void OnError(QuicFramer* framer) OVERRIDE; | 81 // associated with it. |
| 83 virtual bool OnProtocolVersionMismatch(QuicVersion received_version) OVERRIDE; | 82 QuicVersion GetQuicVersionFromGuid(QuicGuid guid); |
| 84 virtual bool OnUnauthenticatedHeader(const QuicPacketHeader& header) OVERRIDE; | |
| 85 virtual void OnPacket() OVERRIDE {} | |
| 86 virtual void OnPublicResetPacket( | |
| 87 const QuicPublicResetPacket& /*packet*/) OVERRIDE {} | |
| 88 virtual void OnVersionNegotiationPacket( | |
| 89 const QuicVersionNegotiationPacket& /*packet*/) OVERRIDE {} | |
| 90 | |
| 91 virtual void OnPacketComplete() OVERRIDE {} | |
| 92 // The following methods should never get called because we always return | |
| 93 // false from OnUnauthenticatedHeader(). We never process the encrypted bytes. | |
| 94 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE; | |
| 95 virtual void OnRevivedPacket() OVERRIDE; | |
| 96 virtual void OnFecProtectedPayload(base::StringPiece /*payload*/) OVERRIDE; | |
| 97 virtual bool OnStreamFrame(const QuicStreamFrame& /*frame*/) OVERRIDE; | |
| 98 virtual bool OnAckFrame(const QuicAckFrame& /*frame*/) OVERRIDE; | |
| 99 virtual bool OnCongestionFeedbackFrame( | |
| 100 const QuicCongestionFeedbackFrame& /*frame*/) OVERRIDE; | |
| 101 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& /*frame*/) OVERRIDE; | |
| 102 virtual bool OnConnectionCloseFrame( | |
| 103 const QuicConnectionCloseFrame & /*frame*/) OVERRIDE; | |
| 104 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& /*frame*/) OVERRIDE; | |
| 105 virtual void OnFecData(const QuicFecData& /*fec*/) OVERRIDE; | |
| 106 | 83 |
| 107 private: | 84 private: |
| 108 friend class test::QuicTimeWaitListManagerPeer; | 85 friend class test::QuicTimeWaitListManagerPeer; |
| 109 | 86 |
| 110 // Stores the guid and the time it was added to time wait state. | 87 // Stores the guid and the time it was added to time wait state. |
| 111 struct GuidAddTime; | 88 struct GuidAddTime; |
| 112 // Internal structure to store pending public reset packets. | 89 // Internal structure to store pending public reset packets. |
| 113 class QueuedPacket; | 90 class QueuedPacket; |
| 114 | 91 |
| 115 // Decides if a packet should be sent for this guid based on the number of | 92 // Decides if a packet should be sent for this guid based on the number of |
| 116 // received packets. | 93 // received packets. |
| 117 bool ShouldSendResponse(int received_packet_count); | 94 bool ShouldSendResponse(int received_packet_count); |
| 118 | 95 |
| 119 // Given a GUID that exists in the time wait list, returns the QuicVersion | |
| 120 // associated with it. Used internally to set the framer version before | |
| 121 // writing the public reset packet. | |
| 122 QuicVersion GetQuicVersionFromGuid(QuicGuid guid); | |
| 123 | |
| 124 // Creates a public reset packet and sends it or queues it to be sent later. | 96 // Creates a public reset packet and sends it or queues it to be sent later. |
| 125 void SendPublicReset(const IPEndPoint& server_address, | 97 void SendPublicReset(const IPEndPoint& server_address, |
| 126 const IPEndPoint& client_address, | 98 const IPEndPoint& client_address, |
| 127 QuicGuid guid, | 99 QuicGuid guid, |
| 128 QuicPacketSequenceNumber rejected_sequence_number); | 100 QuicPacketSequenceNumber rejected_sequence_number); |
| 129 | 101 |
| 130 // Either sends the packet and deletes it or makes pending_packets_queue_ the | 102 // Either sends the packet and deletes it or makes pending_packets_queue_ the |
| 131 // owner of the packet. | 103 // owner of the packet. |
| 132 void SendOrQueuePacket(QueuedPacket* packet); | 104 void SendOrQueuePacket(QueuedPacket* packet); |
| 133 | 105 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 157 typedef base::hash_map<QuicGuid, GuidData>::iterator GuidMapIterator; | 129 typedef base::hash_map<QuicGuid, GuidData>::iterator GuidMapIterator; |
| 158 | 130 |
| 159 // Maintains a list of GuidAddTime elements which it owns, in the | 131 // Maintains a list of GuidAddTime elements which it owns, in the |
| 160 // order they should be deleted. | 132 // order they should be deleted. |
| 161 std::deque<GuidAddTime*> time_ordered_guid_list_; | 133 std::deque<GuidAddTime*> time_ordered_guid_list_; |
| 162 | 134 |
| 163 // Pending public reset packets that need to be sent out to the client | 135 // Pending public reset packets that need to be sent out to the client |
| 164 // when we are given a chance to write by the dispatcher. | 136 // when we are given a chance to write by the dispatcher. |
| 165 std::deque<QueuedPacket*> pending_packets_queue_; | 137 std::deque<QueuedPacket*> pending_packets_queue_; |
| 166 | 138 |
| 167 // Used to parse incoming packets. | |
| 168 QuicFramer framer_; | |
| 169 | |
| 170 // Server and client address of the last packet processed. | |
| 171 IPEndPoint server_address_; | |
| 172 IPEndPoint client_address_; | |
| 173 | |
| 174 // Used to schedule alarms to delete old guids which have been in the list for | 139 // Used to schedule alarms to delete old guids which have been in the list for |
| 175 // too long. Owned by the dispatcher. | 140 // too long. Owned by the dispatcher. |
| 176 EpollServer* epoll_server_; | 141 EpollServer* epoll_server_; |
| 177 | 142 |
| 178 // Time period for which guids should remain in time wait state. | 143 // Time period for which guids should remain in time wait state. |
| 179 const QuicTime::Delta kTimeWaitPeriod_; | 144 const QuicTime::Delta kTimeWaitPeriod_; |
| 180 | 145 |
| 181 // Alarm registered with the epoll server to clean up guids that have out | 146 // Alarm registered with the epoll server to clean up guids that have out |
| 182 // lived their duration in time wait state. | 147 // lived their duration in time wait state. |
| 183 scoped_ptr<GuidCleanUpAlarm> guid_clean_up_alarm_; | 148 scoped_ptr<GuidCleanUpAlarm> guid_clean_up_alarm_; |
| 184 | 149 |
| 185 // Clock to efficiently measure approximate time from the epoll server. | 150 // Clock to efficiently measure approximate time from the epoll server. |
| 186 QuicEpollClock clock_; | 151 QuicEpollClock clock_; |
| 187 | 152 |
| 188 // Interface that writes given buffer to the socket. Owned by the dispatcher. | 153 // Interface that writes given buffer to the socket. Owned by the dispatcher. |
| 189 QuicPacketWriter* writer_; | 154 QuicPacketWriter* writer_; |
| 190 | 155 |
| 191 // True if the underlying udp socket is write blocked, i.e will return EAGAIN | 156 // True if the underlying udp socket is write blocked, i.e will return EAGAIN |
| 192 // on sendmsg. | 157 // on sendmsg. |
| 193 bool is_write_blocked_; | 158 bool is_write_blocked_; |
| 194 | 159 |
| 195 DISALLOW_COPY_AND_ASSIGN(QuicTimeWaitListManager); | 160 DISALLOW_COPY_AND_ASSIGN(QuicTimeWaitListManager); |
| 196 }; | 161 }; |
| 197 | 162 |
| 198 } // namespace tools | 163 } // namespace tools |
| 199 } // namespace net | 164 } // namespace net |
| 200 | 165 |
| 201 #endif // NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ | 166 #endif // NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ |
| OLD | NEW |