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 26 matching lines...) Expand all Loading... |
37 // writer - the entity that writes to the socket. (Owned by the dispatcher) | 37 // writer - the entity that writes to the socket. (Owned by the dispatcher) |
38 // epoll_server - used to run clean up alarms. (Owned by the dispatcher) | 38 // epoll_server - used to run clean up alarms. (Owned by the dispatcher) |
39 QuicTimeWaitListManager(QuicPacketWriter* writer, | 39 QuicTimeWaitListManager(QuicPacketWriter* writer, |
40 EpollServer* epoll_server); | 40 EpollServer* epoll_server); |
41 virtual ~QuicTimeWaitListManager(); | 41 virtual ~QuicTimeWaitListManager(); |
42 | 42 |
43 // Adds the given guid to time wait state for kTimeWaitPeriod. Henceforth, | 43 // Adds the given guid to time wait state for kTimeWaitPeriod. Henceforth, |
44 // any packet bearing this guid should not be processed while the guid remains | 44 // any packet bearing this guid should not be processed while the guid remains |
45 // in this list. Public reset packets are sent to the clients by the time wait | 45 // in this list. Public reset packets are sent to the clients by the time wait |
46 // list manager that send packets to guids in this state. DCHECKs that guid is | 46 // list manager that send packets to guids in this state. DCHECKs that guid is |
47 // not already on the list. | 47 // not already on the list. Pass in the version as well so that if a public |
48 void AddGuidToTimeWait(QuicGuid guid); | 48 // reset packet needs to be sent the framer version can be set first. |
| 49 void AddGuidToTimeWait(QuicGuid guid, QuicVersion version); |
49 | 50 |
50 // Returns true if the guid is in time wait state, false otherwise. Packets | 51 // Returns true if the guid is in time wait state, false otherwise. Packets |
51 // received for this guid should not lead to creation of new QuicSessions. | 52 // received for this guid should not lead to creation of new QuicSessions. |
52 bool IsGuidInTimeWait(QuicGuid guid) const; | 53 bool IsGuidInTimeWait(QuicGuid guid) const; |
53 | 54 |
54 // Called when a packet is received for a guid that is in time wait state. | 55 // Called when a packet is received for a guid that is in time wait state. |
55 // Sends a public reset packet to the client which sent this guid. Sending | 56 // Sends a public reset packet to the client which sent this guid. Sending |
56 // of the public reset packet is throttled by using exponential back off. | 57 // of the public reset packet is throttled by using exponential back off. |
57 // DCHECKs for the guid to be in time wait state. | 58 // DCHECKs for the guid to be in time wait state. |
58 // virtual to override in tests. | 59 // virtual to override in tests. |
59 virtual void ProcessPacket(const IPEndPoint& server_address, | 60 virtual void ProcessPacket(const IPEndPoint& server_address, |
60 const IPEndPoint& client_address, | 61 const IPEndPoint& client_address, |
61 QuicGuid guid, | 62 QuicGuid guid, |
62 const QuicEncryptedPacket& packet); | 63 const QuicEncryptedPacket& packet); |
63 | 64 |
64 // Called by the dispatcher when the underlying socket becomes writable again, | 65 // Called by the dispatcher when the underlying socket becomes writable again, |
65 // since we might need to send pending public reset packets which we didn't | 66 // since we might need to send pending public reset packets which we didn't |
66 // send because the underlying socket was write blocked. | 67 // send because the underlying socket was write blocked. |
67 virtual bool OnCanWrite() OVERRIDE; | 68 virtual bool OnCanWrite() OVERRIDE; |
68 | 69 |
69 // Used to delete guid entries that have outlived their time wait period. | 70 // Used to delete guid entries that have outlived their time wait period. |
70 void CleanUpOldGuids(); | 71 void CleanUpOldGuids(); |
71 | 72 |
72 // FramerVisitorInterface | 73 // FramerVisitorInterface |
73 virtual void OnError(QuicFramer* framer) OVERRIDE; | 74 virtual void OnError(QuicFramer* framer) OVERRIDE; |
74 virtual bool OnProtocolVersionMismatch(QuicTag received_version) OVERRIDE; | 75 virtual bool OnProtocolVersionMismatch(QuicVersion received_version) OVERRIDE; |
75 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE; | 76 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE; |
76 virtual void OnPacket() OVERRIDE {} | 77 virtual void OnPacket() OVERRIDE {} |
77 virtual void OnPublicResetPacket( | 78 virtual void OnPublicResetPacket( |
78 const QuicPublicResetPacket& packet) OVERRIDE {} | 79 const QuicPublicResetPacket& packet) OVERRIDE {} |
79 virtual void OnVersionNegotiationPacket( | 80 virtual void OnVersionNegotiationPacket( |
80 const QuicVersionNegotiationPacket& /*packet*/) OVERRIDE {} | 81 const QuicVersionNegotiationPacket& /*packet*/) OVERRIDE {} |
81 | 82 |
82 virtual void OnPacketComplete() OVERRIDE {} | 83 virtual void OnPacketComplete() OVERRIDE {} |
83 // The following methods should never get called because we always return | 84 // The following methods should never get called because we always return |
84 // false from OnPacketHeader(). We never need to process body of a packet. | 85 // false from OnPacketHeader(). We never need to process body of a packet. |
85 virtual void OnRevivedPacket() OVERRIDE {} | 86 virtual void OnRevivedPacket() OVERRIDE {} |
86 virtual void OnFecProtectedPayload(base::StringPiece payload) OVERRIDE {} | 87 virtual void OnFecProtectedPayload(base::StringPiece payload) OVERRIDE {} |
87 virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE; | 88 virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE; |
88 virtual bool OnAckFrame(const QuicAckFrame& frame) OVERRIDE; | 89 virtual bool OnAckFrame(const QuicAckFrame& frame) OVERRIDE; |
89 virtual bool OnCongestionFeedbackFrame( | 90 virtual bool OnCongestionFeedbackFrame( |
90 const QuicCongestionFeedbackFrame& frame) OVERRIDE; | 91 const QuicCongestionFeedbackFrame& frame) OVERRIDE; |
91 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE; | 92 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE; |
92 virtual bool OnConnectionCloseFrame( | 93 virtual bool OnConnectionCloseFrame( |
93 const QuicConnectionCloseFrame & frame) OVERRIDE; | 94 const QuicConnectionCloseFrame & frame) OVERRIDE; |
94 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& frame) OVERRIDE; | 95 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& frame) OVERRIDE; |
95 virtual void OnFecData(const QuicFecData& fec) OVERRIDE {} | 96 virtual void OnFecData(const QuicFecData& fec) OVERRIDE {} |
96 | 97 |
| 98 QuicVersion version() const { return framer_.version(); } |
| 99 |
97 protected: | 100 protected: |
98 // Exposed for tests. | 101 // Exposed for tests. |
99 bool is_write_blocked() const { return is_write_blocked_; } | 102 bool is_write_blocked() const { return is_write_blocked_; } |
100 | 103 |
101 // Decides if public reset packet should be sent for this guid based on the | 104 // Decides if public reset packet should be sent for this guid based on the |
102 // number of received pacekts. | 105 // number of received pacekts. |
103 bool ShouldSendPublicReset(int received_packet_count); | 106 bool ShouldSendPublicReset(int received_packet_count); |
104 | 107 |
105 // Exposed for tests. | 108 // Exposed for tests. |
106 const QuicTime::Delta time_wait_period() const { return kTimeWaitPeriod_; } | 109 const QuicTime::Delta time_wait_period() const { return kTimeWaitPeriod_; } |
107 | 110 |
| 111 // Given a GUID that exists in the time wait list, returns the QuicVersion |
| 112 // associated with it. Used internally to set the framer version before |
| 113 // writing the public reset packet. |
| 114 QuicVersion GetQuicVersionFromGuid(QuicGuid guid); |
| 115 |
108 private: | 116 private: |
109 // Stores the guid and the time it was added to time wait state. | 117 // Stores the guid and the time it was added to time wait state. |
110 struct GuidAddTime; | 118 struct GuidAddTime; |
111 // Internal structure to store pending public reset packets. | 119 // Internal structure to store pending public reset packets. |
112 class QueuedPacket; | 120 class QueuedPacket; |
113 | 121 |
114 // Creates a public reset packet and sends it or queues it to be sent later. | 122 // Creates a public reset packet and sends it or queues it to be sent later. |
115 void SendPublicReset(const IPEndPoint& server_address, | 123 void SendPublicReset(const IPEndPoint& server_address, |
116 const IPEndPoint& client_address, | 124 const IPEndPoint& client_address, |
117 QuicGuid guid, | 125 QuicGuid guid, |
118 QuicPacketSequenceNumber rejected_sequence_number); | 126 QuicPacketSequenceNumber rejected_sequence_number); |
119 | 127 |
120 // Either sends the packet and deletes it or makes pending_packets_queue_ the | 128 // Either sends the packet and deletes it or makes pending_packets_queue_ the |
121 // owner of the packet. | 129 // owner of the packet. |
122 void SendOrQueuePacket(QueuedPacket* packet); | 130 void SendOrQueuePacket(QueuedPacket* packet); |
123 | 131 |
124 // Should only be called when write_blocked_ == false. We only care if the | 132 // Should only be called when write_blocked_ == false. We only care if the |
125 // writing was unsuccessful because the socket got blocked, which can be | 133 // writing was unsuccessful because the socket got blocked, which can be |
126 // tested using write_blocked_ == true. In case of all other errors we drop | 134 // tested using write_blocked_ == true. In case of all other errors we drop |
127 // the packet. Hence, we return void. | 135 // the packet. Hence, we return void. |
128 void WriteToWire(QueuedPacket* packet); | 136 void WriteToWire(QueuedPacket* packet); |
129 | 137 |
130 // Register the alarm with the epoll server to wake up at appropriate time. | 138 // Register the alarm with the epoll server to wake up at appropriate time. |
131 void SetGuidCleanUpAlarm(); | 139 void SetGuidCleanUpAlarm(); |
132 | 140 |
133 // A map from a recently closed guid to the number of packets received after | 141 // A map from a recently closed guid to the number of packets received after |
134 // the termination of the connection bound to the guid. | 142 // the termination of the connection bound to the guid. |
135 base::hash_map<QuicGuid, int> guid_map_; | 143 struct GuidData { |
136 typedef base::hash_map<QuicGuid, int>::iterator GuidMapIterator; | 144 GuidData(int num_packets_, QuicVersion version_) |
| 145 : num_packets(num_packets_), version(version_) {} |
| 146 int num_packets; |
| 147 QuicVersion version; |
| 148 }; |
| 149 base::hash_map<QuicGuid, GuidData> guid_map_; |
| 150 typedef base::hash_map<QuicGuid, GuidData>::iterator GuidMapIterator; |
137 | 151 |
138 // Maintains a list of GuidAddTime elements which it owns, in the | 152 // Maintains a list of GuidAddTime elements which it owns, in the |
139 // order they should be deleted. | 153 // order they should be deleted. |
140 std::deque<GuidAddTime*> time_ordered_guid_list_; | 154 std::deque<GuidAddTime*> time_ordered_guid_list_; |
141 | 155 |
142 // Pending public reset packets that need to be sent out to the client | 156 // Pending public reset packets that need to be sent out to the client |
143 // when we are given a chance to write by the dispatcher. | 157 // when we are given a chance to write by the dispatcher. |
144 std::deque<QueuedPacket*> pending_packets_queue_; | 158 std::deque<QueuedPacket*> pending_packets_queue_; |
145 | 159 |
146 // Used to parse incoming packets. | 160 // Used to parse incoming packets. |
(...skipping 24 matching lines...) Expand all Loading... |
171 // on sendmsg. | 185 // on sendmsg. |
172 bool is_write_blocked_; | 186 bool is_write_blocked_; |
173 | 187 |
174 DISALLOW_COPY_AND_ASSIGN(QuicTimeWaitListManager); | 188 DISALLOW_COPY_AND_ASSIGN(QuicTimeWaitListManager); |
175 }; | 189 }; |
176 | 190 |
177 } // namespace tools | 191 } // namespace tools |
178 } // namespace net | 192 } // namespace net |
179 | 193 |
180 #endif // NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ | 194 #endif // NET_TOOLS_QUIC_QUIC_TIME_WAIT_LIST_MANAGER_H_ |
OLD | NEW |