| 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_ |
| 11 | 11 |
| 12 #include <deque> | 12 #include <deque> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
| 16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
| 17 #include "net/base/linked_hash_map.h" | 17 #include "net/base/linked_hash_map.h" |
| 18 #include "net/quic/quic_blocked_writer_interface.h" | 18 #include "net/quic/quic_blocked_writer_interface.h" |
| 19 #include "net/quic/quic_connection.h" |
| 19 #include "net/quic/quic_framer.h" | 20 #include "net/quic/quic_framer.h" |
| 20 #include "net/quic/quic_packet_writer.h" | 21 #include "net/quic/quic_packet_writer.h" |
| 21 #include "net/quic/quic_protocol.h" | 22 #include "net/quic/quic_protocol.h" |
| 22 #include "net/tools/quic/quic_epoll_clock.h" | |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 | 25 |
| 26 class EpollServer; | |
| 27 | |
| 28 namespace tools { | 26 namespace tools { |
| 29 | 27 |
| 30 class ConnectionIdCleanUpAlarm; | 28 class ConnectionIdCleanUpAlarm; |
| 31 class QuicServerSessionVisitor; | 29 class QuicServerSessionVisitor; |
| 32 | 30 |
| 33 namespace test { | 31 namespace test { |
| 34 class QuicTimeWaitListManagerPeer; | 32 class QuicTimeWaitListManagerPeer; |
| 35 } // namespace test | 33 } // namespace test |
| 36 | 34 |
| 37 // Maintains a list of all connection_ids that have been recently closed. A | 35 // 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 | 36 // 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 | 37 // for connection_ids in this state are handed over to the |
| 40 // QuicTimeWaitListManager by the QuicDispatcher. Decides whether to send a | 38 // QuicTimeWaitListManager by the QuicDispatcher. Decides whether to send a |
| 41 // public reset packet, a copy of the previously sent connection close packet, | 39 // 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 | 40 // 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 | 41 // 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 | 42 // connection/session will be created if a packet is received for this |
| 45 // connection_id. | 43 // connection_id. |
| 46 class QuicTimeWaitListManager : public QuicBlockedWriterInterface { | 44 class QuicTimeWaitListManager : public QuicBlockedWriterInterface { |
| 47 public: | 45 public: |
| 48 // writer - the entity that writes to the socket. (Owned by the dispatcher) | 46 // writer - the entity that writes to the socket. (Owned by the dispatcher) |
| 49 // visitor - the entity that manages blocked writers. (The dispatcher) | 47 // visitor - the entity that manages blocked writers. (The dispatcher) |
| 50 // epoll_server - used to run clean up alarms. (Owned by the dispatcher) | 48 // helper - used to run clean up alarms. (Owned by the dispatcher) |
| 51 QuicTimeWaitListManager(QuicPacketWriter* writer, | 49 QuicTimeWaitListManager(QuicPacketWriter* writer, |
| 52 QuicServerSessionVisitor* visitor, | 50 QuicServerSessionVisitor* visitor, |
| 53 EpollServer* epoll_server, | 51 QuicConnectionHelperInterface* helper, |
| 54 const QuicVersionVector& supported_versions); | 52 const QuicVersionVector& supported_versions); |
| 55 ~QuicTimeWaitListManager() override; | 53 ~QuicTimeWaitListManager() override; |
| 56 | 54 |
| 57 // Adds the given connection_id to time wait state for kTimeWaitPeriod. | 55 // Adds the given connection_id to time wait state for |
| 58 // Henceforth, any packet bearing this connection_id should not be processed | 56 // time_wait_period_. Henceforth, any packet bearing this |
| 59 // while the connection_id remains in this list. If a non-nullptr | 57 // connection_id should not be processed while the connection_id |
| 60 // |close_packet| is provided, it is sent again when packets are received for | 58 // remains in this list. If a non-nullptr |close_packet| is |
| 61 // added connection_ids. If nullptr, a public reset packet is sent with the | 59 // provided, the TimeWaitListManager takes ownership of it and sends |
| 62 // specified |version|. DCHECKs that connection_id is not already on the list. | 60 // it again when packets are received for added connection_ids. If |
| 63 void AddConnectionIdToTimeWait(QuicConnectionId connection_id, | 61 // nullptr, a public reset packet is sent with the specified |
| 64 QuicVersion version, | 62 // |version|. DCHECKs that connection_id is not already on the list. |
| 65 QuicEncryptedPacket* close_packet); // Owned. | 63 // virtual to override in tests. |
| 64 virtual void AddConnectionIdToTimeWait(QuicConnectionId connection_id, |
| 65 QuicVersion version, |
| 66 QuicEncryptedPacket* close_packet); |
| 66 | 67 |
| 67 // Returns true if the connection_id is in time wait state, false otherwise. | 68 // 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 | 69 // Packets received for this connection_id should not lead to creation of new |
| 69 // QuicSessions. | 70 // QuicSessions. |
| 70 bool IsConnectionIdInTimeWait(QuicConnectionId connection_id) const; | 71 bool IsConnectionIdInTimeWait(QuicConnectionId connection_id) const; |
| 71 | 72 |
| 72 // Called when a packet is received for a connection_id that is in time wait | 73 // 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 | 74 // 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 | 75 // 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 | 76 // exponential back off. DCHECKs for the connection_id to be in time wait |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // Either sends the packet and deletes it or makes pending_packets_queue_ the | 124 // Either sends the packet and deletes it or makes pending_packets_queue_ the |
| 124 // owner of the packet. | 125 // owner of the packet. |
| 125 void SendOrQueuePacket(QueuedPacket* packet); | 126 void SendOrQueuePacket(QueuedPacket* packet); |
| 126 | 127 |
| 127 // Sends the packet out. Returns true if the packet was successfully consumed. | 128 // Sends the packet out. Returns true if the packet was successfully consumed. |
| 128 // If the writer got blocked and did not buffer the packet, we'll need to keep | 129 // If the writer got blocked and did not buffer the packet, we'll need to keep |
| 129 // the packet and retry sending. In case of all other errors we drop the | 130 // the packet and retry sending. In case of all other errors we drop the |
| 130 // packet. | 131 // packet. |
| 131 bool WriteToWire(QueuedPacket* packet); | 132 bool WriteToWire(QueuedPacket* packet); |
| 132 | 133 |
| 133 // Register the alarm with the epoll server to wake up at appropriate time. | 134 // Register the alarm server to wake up at appropriate time. |
| 134 void SetConnectionIdCleanUpAlarm(); | 135 void SetConnectionIdCleanUpAlarm(); |
| 135 | 136 |
| 136 // Removes the oldest connection from the time-wait list if it was added prior | 137 // Removes the oldest connection from the time-wait list if it was added prior |
| 137 // to "expiration_time". To unconditionally remove the oldest connection, use | 138 // to "expiration_time". To unconditionally remove the oldest connection, use |
| 138 // a QuicTime::Delta:Infinity(). This function modifies the | 139 // a QuicTime::Delta:Infinity(). This function modifies the |
| 139 // connection_id_map_. If you plan to call this function in a loop, any | 140 // connection_id_map_. If you plan to call this function in a loop, any |
| 140 // iterators that you hold before the call to this function may be invalid | 141 // iterators that you hold before the call to this function may be invalid |
| 141 // afterward. Returns true if the oldest connection was expired. Returns | 142 // afterward. Returns true if the oldest connection was expired. Returns |
| 142 // false if the map is empty or the oldest connection has not expired. | 143 // false if the map is empty or the oldest connection has not expired. |
| 143 bool MaybeExpireOldestConnection(QuicTime expiration_time); | 144 bool MaybeExpireOldestConnection(QuicTime expiration_time); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 161 }; | 162 }; |
| 162 | 163 |
| 163 // linked_hash_map allows lookup by ConnectionId and traversal in add order. | 164 // linked_hash_map allows lookup by ConnectionId and traversal in add order. |
| 164 typedef linked_hash_map<QuicConnectionId, ConnectionIdData> ConnectionIdMap; | 165 typedef linked_hash_map<QuicConnectionId, ConnectionIdData> ConnectionIdMap; |
| 165 ConnectionIdMap connection_id_map_; | 166 ConnectionIdMap connection_id_map_; |
| 166 | 167 |
| 167 // Pending public reset packets that need to be sent out to the client | 168 // 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. | 169 // when we are given a chance to write by the dispatcher. |
| 169 std::deque<QueuedPacket*> pending_packets_queue_; | 170 std::deque<QueuedPacket*> pending_packets_queue_; |
| 170 | 171 |
| 171 // Used to schedule alarms to delete old connection_ids which have been in the | 172 // Time period for which connection_ids should remain in time wait state. |
| 172 // list for too long. | 173 const QuicTime::Delta time_wait_period_; |
| 173 EpollServer* epoll_server_; | |
| 174 | 174 |
| 175 // Time period for which connection_ids should remain in time wait state. | 175 // Alarm to clean up connection_ids that have out lived their duration in |
| 176 const QuicTime::Delta kTimeWaitPeriod_; | 176 // time wait state. |
| 177 scoped_ptr<QuicAlarm> connection_id_clean_up_alarm_; |
| 177 | 178 |
| 178 // Alarm registered with the epoll server to clean up connection_ids that have | 179 // Clock to efficiently measure approximate time. |
| 179 // out lived their duration in time wait state. | 180 const QuicClock* clock_; |
| 180 scoped_ptr<ConnectionIdCleanUpAlarm> connection_id_clean_up_alarm_; | |
| 181 | |
| 182 // Clock to efficiently measure approximate time from the epoll server. | |
| 183 QuicEpollClock clock_; | |
| 184 | 181 |
| 185 // Interface that writes given buffer to the socket. | 182 // Interface that writes given buffer to the socket. |
| 186 QuicPacketWriter* writer_; | 183 QuicPacketWriter* writer_; |
| 187 | 184 |
| 188 // Interface that manages blocked writers. | 185 // Interface that manages blocked writers. |
| 189 QuicServerSessionVisitor* visitor_; | 186 QuicServerSessionVisitor* visitor_; |
| 190 | 187 |
| 191 DISALLOW_COPY_AND_ASSIGN(QuicTimeWaitListManager); | 188 DISALLOW_COPY_AND_ASSIGN(QuicTimeWaitListManager); |
| 192 }; | 189 }; |
| 193 | 190 |
| 194 } // namespace tools | 191 } // namespace tools |
| 195 } // namespace net | 192 } // namespace net |
| 196 | 193 |
| 197 #endif // NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ | 194 #endif // NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ |
| OLD | NEW |