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 30 matching lines...) Expand all Loading... |
41 public: | 41 public: |
42 // writer - the entity that writes to the socket. (Owned by the dispatcher) | 42 // writer - the entity that writes to the socket. (Owned by the dispatcher) |
43 // visitor - the entity that manages blocked writers. (The dispatcher) | 43 // visitor - the entity that manages blocked writers. (The dispatcher) |
44 // helper - used to run clean up alarms. (Owned by the dispatcher) | 44 // helper - used to run clean up alarms. (Owned by the dispatcher) |
45 QuicTimeWaitListManager(QuicPacketWriter* writer, | 45 QuicTimeWaitListManager(QuicPacketWriter* writer, |
46 QuicServerSessionVisitor* visitor, | 46 QuicServerSessionVisitor* visitor, |
47 QuicConnectionHelperInterface* helper); | 47 QuicConnectionHelperInterface* helper); |
48 ~QuicTimeWaitListManager() override; | 48 ~QuicTimeWaitListManager() override; |
49 | 49 |
50 // Adds the given connection_id to time wait state for time_wait_period_. | 50 // Adds the given connection_id to time wait state for time_wait_period_. |
51 // Henceforth, any packet bearing this connection_id should not be processed | 51 // If |termination_packets| are provided, copies of these packets will be sent |
52 // while the connection_id remains in this list. If a non-nullptr | 52 // when a packet with this connection ID is processed. If no termination |
53 // |close_packet| is provided, the TimeWaitListManager takes ownership of it | 53 // packets are provided, then a PUBLIC_RESET will be sent with the specified |
54 // and sends it again when packets are received for added connection_ids. If | 54 // |version|. Any termination packets will be move from |termination_packets| |
55 // nullptr, a public reset packet is sent with the specified |version|. | 55 // and will become owned by the manager. If |connection_rejected_statelessly| |
56 // DCHECKs that connection_id is not already on the list. "virtual" to | 56 // is true, it means that the connection was closed due to a stateless reject, |
57 // override in tests. If "connection_rejected_statelessly" is true, it means | 57 // and termination packets are expected. |
58 // that the connection was closed due to a stateless reject, and no close | 58 virtual void AddConnectionIdToTimeWait( |
59 // packet is expected. Any packets that are received for connection_id will | 59 QuicConnectionId connection_id, |
60 // be black-holed. | 60 QuicVersion version, |
61 // TODO(jokulik): In the future, we plan send (redundant) SREJ packets back to | 61 bool connection_rejected_statelessly, |
62 // the client in response to stray data-packets that arrive after the first | 62 std::vector<QuicEncryptedPacket*>* termination_packets); |
63 // SREJ. This requires some new plumbing, so we black-hole for now. | |
64 virtual void AddConnectionIdToTimeWait(QuicConnectionId connection_id, | |
65 QuicVersion version, | |
66 bool connection_rejected_statelessly, | |
67 QuicEncryptedPacket* close_packet); | |
68 | 63 |
69 // Returns true if the connection_id is in time wait state, false otherwise. | 64 // Returns true if the connection_id is in time wait state, false otherwise. |
70 // Packets received for this connection_id should not lead to creation of new | 65 // Packets received for this connection_id should not lead to creation of new |
71 // QuicSessions. | 66 // QuicSessions. |
72 bool IsConnectionIdInTimeWait(QuicConnectionId connection_id) const; | 67 bool IsConnectionIdInTimeWait(QuicConnectionId connection_id) const; |
73 | 68 |
74 // Called when a packet is received for a connection_id that is in time wait | 69 // Called when a packet is received for a connection_id that is in time wait |
75 // state. Sends a public reset packet to the client which sent this | 70 // state. Sends a public reset packet to the client which sent this |
76 // connection_id. Sending of the public reset packet is throttled by using | 71 // connection_id. Sending of the public reset packet is throttled by using |
77 // exponential back off. DCHECKs for the connection_id to be in time wait | 72 // exponential back off. DCHECKs for the connection_id to be in time wait |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // false if the map is empty or the oldest connection has not expired. | 139 // false if the map is empty or the oldest connection has not expired. |
145 bool MaybeExpireOldestConnection(QuicTime expiration_time); | 140 bool MaybeExpireOldestConnection(QuicTime expiration_time); |
146 | 141 |
147 // A map from a recently closed connection_id to the number of packets | 142 // A map from a recently closed connection_id to the number of packets |
148 // received after the termination of the connection bound to the | 143 // received after the termination of the connection bound to the |
149 // connection_id. | 144 // connection_id. |
150 struct ConnectionIdData { | 145 struct ConnectionIdData { |
151 ConnectionIdData(int num_packets_, | 146 ConnectionIdData(int num_packets_, |
152 QuicVersion version_, | 147 QuicVersion version_, |
153 QuicTime time_added_, | 148 QuicTime time_added_, |
154 QuicEncryptedPacket* close_packet, | 149 bool connection_rejected_statelessly); |
155 bool connection_rejected_statelessly) | 150 |
156 : num_packets(num_packets_), | 151 ~ConnectionIdData(); |
157 version(version_), | 152 |
158 time_added(time_added_), | |
159 close_packet(close_packet), | |
160 connection_rejected_statelessly(connection_rejected_statelessly) {} | |
161 int num_packets; | 153 int num_packets; |
162 QuicVersion version; | 154 QuicVersion version; |
163 QuicTime time_added; | 155 QuicTime time_added; |
164 QuicEncryptedPacket* close_packet; | 156 // These packets may contain CONNECTION_CLOSE frames, or SREJ messages. |
| 157 std::vector<QuicEncryptedPacket*> termination_packets; |
165 bool connection_rejected_statelessly; | 158 bool connection_rejected_statelessly; |
166 }; | 159 }; |
167 | 160 |
168 // linked_hash_map allows lookup by ConnectionId and traversal in add order. | 161 // linked_hash_map allows lookup by ConnectionId and traversal in add order. |
169 typedef linked_hash_map<QuicConnectionId, ConnectionIdData> ConnectionIdMap; | 162 typedef linked_hash_map<QuicConnectionId, ConnectionIdData> ConnectionIdMap; |
170 ConnectionIdMap connection_id_map_; | 163 ConnectionIdMap connection_id_map_; |
171 | 164 |
172 // Pending public reset packets that need to be sent out to the client | 165 // Pending public reset packets that need to be sent out to the client |
173 // when we are given a chance to write by the dispatcher. | 166 // when we are given a chance to write by the dispatcher. |
174 std::deque<QueuedPacket*> pending_packets_queue_; | 167 std::deque<QueuedPacket*> pending_packets_queue_; |
(...skipping 14 matching lines...) Expand all Loading... |
189 // Interface that manages blocked writers. | 182 // Interface that manages blocked writers. |
190 QuicServerSessionVisitor* visitor_; | 183 QuicServerSessionVisitor* visitor_; |
191 | 184 |
192 DISALLOW_COPY_AND_ASSIGN(QuicTimeWaitListManager); | 185 DISALLOW_COPY_AND_ASSIGN(QuicTimeWaitListManager); |
193 }; | 186 }; |
194 | 187 |
195 } // namespace tools | 188 } // namespace tools |
196 } // namespace net | 189 } // namespace net |
197 | 190 |
198 #endif // NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ | 191 #endif // NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ |
OLD | NEW |