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 connection_ids in time wait state by discarding the | 5 // Handles packets for connection_ids in time wait state by discarding the |
6 // packet and sending the clients a public reset packet with exponential | 6 // packet and sending the clients a public reset packet with exponential |
7 // backoff. | 7 // backoff. |
8 | 8 |
9 #ifndef NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ | 9 #ifndef NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ |
10 #define NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ | 10 #define NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ |
(...skipping 17 matching lines...) Expand all Loading... |
28 namespace tools { | 28 namespace tools { |
29 | 29 |
30 class ConnectionIdCleanUpAlarm; | 30 class ConnectionIdCleanUpAlarm; |
31 class QuicServerSessionVisitor; | 31 class QuicServerSessionVisitor; |
32 | 32 |
33 namespace test { | 33 namespace test { |
34 class QuicTimeWaitListManagerPeer; | 34 class QuicTimeWaitListManagerPeer; |
35 } // namespace test | 35 } // namespace test |
36 | 36 |
37 // Maintains a list of all connection_ids that have been recently closed. A | 37 // Maintains a list of all connection_ids that have been recently closed. A |
38 // connection_id lives in this state for kTimeWaitPeriod. All packets received | 38 // connection_id lives in this state for time_wait_period_. All packets received |
39 // for connection_ids in this state are handed over to the | 39 // for connection_ids in this state are handed over to the |
40 // QuicTimeWaitListManager by the QuicDispatcher. Decides whether to send a | 40 // QuicTimeWaitListManager by the QuicDispatcher. Decides whether to send a |
41 // public reset packet, a copy of the previously sent connection close packet, | 41 // public reset packet, a copy of the previously sent connection close packet, |
42 // or nothing to the client which sent a packet with the connection_id in time | 42 // or nothing to the client which sent a packet with the connection_id in time |
43 // wait state. After the connection_id expires its time wait period, a new | 43 // wait state. After the connection_id expires its time wait period, a new |
44 // connection/session will be created if a packet is received for this | 44 // connection/session will be created if a packet is received for this |
45 // connection_id. | 45 // connection_id. |
46 class QuicTimeWaitListManager : public QuicBlockedWriterInterface { | 46 class QuicTimeWaitListManager : public QuicBlockedWriterInterface { |
47 public: | 47 public: |
48 // writer - the entity that writes to the socket. (Owned by the dispatcher) | 48 // writer - the entity that writes to the socket. (Owned by the dispatcher) |
49 // visitor - the entity that manages blocked writers. (The dispatcher) | 49 // visitor - the entity that manages blocked writers. (The dispatcher) |
50 // epoll_server - used to run clean up alarms. (Owned by the dispatcher) | 50 // epoll_server - used to run clean up alarms. (Owned by the dispatcher) |
51 QuicTimeWaitListManager(QuicPacketWriter* writer, | 51 QuicTimeWaitListManager(QuicPacketWriter* writer, |
52 QuicServerSessionVisitor* visitor, | 52 QuicServerSessionVisitor* visitor, |
53 EpollServer* epoll_server, | 53 EpollServer* epoll_server, |
54 const QuicVersionVector& supported_versions); | 54 const QuicVersionVector& supported_versions); |
55 ~QuicTimeWaitListManager() override; | 55 ~QuicTimeWaitListManager() override; |
56 | 56 |
57 // Adds the given connection_id to time wait state for kTimeWaitPeriod. | 57 // Adds the given connection_id to time wait state for time_wait_period_. |
58 // Henceforth, any packet bearing this connection_id should not be processed | 58 // Henceforth, any packet bearing this connection_id should not be processed |
59 // while the connection_id remains in this list. If a non-nullptr | 59 // while the connection_id remains in this list. If a non-nullptr |
60 // |close_packet| is provided, it is sent again when packets are received for | 60 // |close_packet| is provided, the TimeWaitListManager takes ownership of it |
61 // added connection_ids. If nullptr, a public reset packet is sent with the | 61 // and sends it again when packets are received for added connection_ids. If |
62 // specified |version|. DCHECKs that connection_id is not already on the list. | 62 // nullptr, a public reset packet is sent with the specified |version|. |
63 void AddConnectionIdToTimeWait(QuicConnectionId connection_id, | 63 // DCHECKs that connection_id is not already on the list. "virtual" to |
64 QuicVersion version, | 64 // override in tests. |
65 QuicEncryptedPacket* close_packet); // Owned. | 65 virtual void AddConnectionIdToTimeWait(QuicConnectionId connection_id, |
| 66 QuicVersion version, |
| 67 QuicEncryptedPacket* close_packet); |
66 | 68 |
67 // Returns true if the connection_id is in time wait state, false otherwise. | 69 // Returns true if the connection_id is in time wait state, false otherwise. |
68 // Packets received for this connection_id should not lead to creation of new | 70 // Packets received for this connection_id should not lead to creation of new |
69 // QuicSessions. | 71 // QuicSessions. |
70 bool IsConnectionIdInTimeWait(QuicConnectionId connection_id) const; | 72 bool IsConnectionIdInTimeWait(QuicConnectionId connection_id) const; |
71 | 73 |
72 // Called when a packet is received for a connection_id that is in time wait | 74 // Called when a packet is received for a connection_id that is in time wait |
73 // state. Sends a public reset packet to the client which sent this | 75 // state. Sends a public reset packet to the client which sent this |
74 // connection_id. Sending of the public reset packet is throttled by using | 76 // connection_id. Sending of the public reset packet is throttled by using |
75 // exponential back off. DCHECKs for the connection_id to be in time wait | 77 // exponential back off. DCHECKs for the connection_id to be in time wait |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 168 |
167 // Pending public reset packets that need to be sent out to the client | 169 // Pending public reset packets that need to be sent out to the client |
168 // when we are given a chance to write by the dispatcher. | 170 // when we are given a chance to write by the dispatcher. |
169 std::deque<QueuedPacket*> pending_packets_queue_; | 171 std::deque<QueuedPacket*> pending_packets_queue_; |
170 | 172 |
171 // Used to schedule alarms to delete old connection_ids which have been in the | 173 // Used to schedule alarms to delete old connection_ids which have been in the |
172 // list for too long. | 174 // list for too long. |
173 EpollServer* epoll_server_; | 175 EpollServer* epoll_server_; |
174 | 176 |
175 // Time period for which connection_ids should remain in time wait state. | 177 // Time period for which connection_ids should remain in time wait state. |
176 const QuicTime::Delta kTimeWaitPeriod_; | 178 const QuicTime::Delta time_wait_period_; |
177 | 179 |
178 // Alarm registered with the epoll server to clean up connection_ids that have | 180 // Alarm registered with the epoll server to clean up connection_ids that have |
179 // out lived their duration in time wait state. | 181 // out lived their duration in time wait state. |
180 scoped_ptr<ConnectionIdCleanUpAlarm> connection_id_clean_up_alarm_; | 182 scoped_ptr<ConnectionIdCleanUpAlarm> connection_id_clean_up_alarm_; |
181 | 183 |
182 // Clock to efficiently measure approximate time from the epoll server. | 184 // Clock to efficiently measure approximate time from the epoll server. |
183 QuicEpollClock clock_; | 185 QuicEpollClock clock_; |
184 | 186 |
185 // Interface that writes given buffer to the socket. | 187 // Interface that writes given buffer to the socket. |
186 QuicPacketWriter* writer_; | 188 QuicPacketWriter* writer_; |
187 | 189 |
188 // Interface that manages blocked writers. | 190 // Interface that manages blocked writers. |
189 QuicServerSessionVisitor* visitor_; | 191 QuicServerSessionVisitor* visitor_; |
190 | 192 |
191 DISALLOW_COPY_AND_ASSIGN(QuicTimeWaitListManager); | 193 DISALLOW_COPY_AND_ASSIGN(QuicTimeWaitListManager); |
192 }; | 194 }; |
193 | 195 |
194 } // namespace tools | 196 } // namespace tools |
195 } // namespace net | 197 } // namespace net |
196 | 198 |
197 #endif // NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ | 199 #endif // NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ |
OLD | NEW |