Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Side by Side Diff: net/url_request/url_request_throttler_entry.h

Issue 6966038: Anti-DDoS enhancements: Log to net log, UMA stats, improved policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/tools/testserver/backoff_server.py ('k') | net/url_request/url_request_throttler_entry.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_ 5 #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_
6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_ 6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_
7 #pragma once 7 #pragma once
8 8
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/time.h"
13 #include "net/base/backoff_entry.h" 14 #include "net/base/backoff_entry.h"
15 #include "net/base/net_log.h"
14 #include "net/url_request/url_request_throttler_entry_interface.h" 16 #include "net/url_request/url_request_throttler_entry_interface.h"
15 17
16 namespace net { 18 namespace net {
17 19
18 class URLRequestThrottlerManager; 20 class URLRequestThrottlerManager;
19 21
20 // URLRequestThrottlerEntry represents an entry of URLRequestThrottlerManager. 22 // URLRequestThrottlerEntry represents an entry of URLRequestThrottlerManager.
21 // It analyzes requests of a specific URL over some period of time, in order to 23 // It analyzes requests of a specific URL over some period of time, in order to
22 // deduce the back-off time for every request. 24 // deduce the back-off time for every request.
23 // The back-off algorithm consists of two parts. Firstly, exponential back-off 25 // The back-off algorithm consists of two parts. Firstly, exponential back-off
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 64
63 // Name of the header that sites can use to opt out of exponential back-off 65 // Name of the header that sites can use to opt out of exponential back-off
64 // throttling. 66 // throttling.
65 static const char kExponentialThrottlingHeader[]; 67 static const char kExponentialThrottlingHeader[];
66 68
67 // Value for exponential throttling header that can be used to opt out of 69 // Value for exponential throttling header that can be used to opt out of
68 // exponential back-off throttling. 70 // exponential back-off throttling.
69 static const char kExponentialThrottlingDisableValue[]; 71 static const char kExponentialThrottlingDisableValue[];
70 72
71 // The manager object's lifetime must enclose the lifetime of this object. 73 // The manager object's lifetime must enclose the lifetime of this object.
72 explicit URLRequestThrottlerEntry(URLRequestThrottlerManager* manager); 74 explicit URLRequestThrottlerEntry(URLRequestThrottlerManager* manager,
75 const std::string& url_id);
73 76
74 // The life span of instances created with this constructor is set to 77 // The life span of instances created with this constructor is set to
75 // infinite, and the number of initial errors to ignore is set to 0. 78 // infinite, and the number of initial errors to ignore is set to 0.
76 // It is only used by unit tests. 79 // It is only used by unit tests.
77 URLRequestThrottlerEntry(URLRequestThrottlerManager* manager, 80 URLRequestThrottlerEntry(URLRequestThrottlerManager* manager,
81 const std::string& url_id,
78 int sliding_window_period_ms, 82 int sliding_window_period_ms,
79 int max_send_threshold, 83 int max_send_threshold,
80 int initial_backoff_ms, 84 int initial_backoff_ms,
81 double multiply_factor, 85 double multiply_factor,
82 double jitter_factor, 86 double jitter_factor,
83 int maximum_backoff_ms); 87 int maximum_backoff_ms);
84 88
85 // Used by the manager, returns true if the entry needs to be garbage 89 // Used by the manager, returns true if the entry needs to be garbage
86 // collected. 90 // collected.
87 bool IsEntryOutdated() const; 91 bool IsEntryOutdated() const;
88 92
89 // Causes this entry to never reject requests due to back-off. 93 // Causes this entry to never reject requests due to back-off.
90 void DisableBackoffThrottling(); 94 void DisableBackoffThrottling();
91 95
92 // Causes this entry to NULL its manager pointer. 96 // Causes this entry to NULL its manager pointer.
93 void DetachManager(); 97 void DetachManager();
94 98
95 // Implementation of URLRequestThrottlerEntryInterface. 99 // Implementation of URLRequestThrottlerEntryInterface.
96 virtual bool IsDuringExponentialBackoff() const; 100 virtual bool IsDuringExponentialBackoff() const;
97 virtual int64 ReserveSendingTimeForNextRequest( 101 virtual int64 ReserveSendingTimeForNextRequest(
98 const base::TimeTicks& earliest_time); 102 const base::TimeTicks& earliest_time);
99 virtual base::TimeTicks GetExponentialBackoffReleaseTime() const; 103 virtual base::TimeTicks GetExponentialBackoffReleaseTime() const;
100 virtual void UpdateWithResponse( 104 virtual void UpdateWithResponse(
101 const std::string& host, 105 const std::string& host,
102 const URLRequestThrottlerHeaderInterface* response); 106 const URLRequestThrottlerHeaderInterface* response);
103 virtual void ReceivedContentWasMalformed(); 107 virtual void ReceivedContentWasMalformed(int response_code);
104 108
105 protected: 109 protected:
106 virtual ~URLRequestThrottlerEntry(); 110 virtual ~URLRequestThrottlerEntry();
107 111
108 void Initialize(); 112 void Initialize();
109 113
114 // Returns true if the given response code is considered an error for
115 // throttling purposes.
116 bool IsConsideredError(int response_code);
117
110 // Equivalent to TimeTicks::Now(), virtual to be mockable for testing purpose. 118 // Equivalent to TimeTicks::Now(), virtual to be mockable for testing purpose.
111 virtual base::TimeTicks GetTimeNow() const; 119 virtual base::TimeTicks ImplGetTimeNow() const;
112 120
113 // Used internally to increase release time following a retry-after header. 121 // Used internally to increase release time following a retry-after header.
114 void HandleCustomRetryAfter(const std::string& header_value); 122 void HandleCustomRetryAfter(const std::string& header_value);
115 123
116 // Used internally to handle the opt-out header. 124 // Used internally to handle the opt-out header.
117 void HandleThrottlingHeader(const std::string& header_value, 125 void HandleThrottlingHeader(const std::string& header_value,
118 const std::string& host); 126 const std::string& host);
119 127
128 // Used internally to keep track of failure->success transitions and
129 // generate statistics about them.
130 void HandleMetricsTracking(int response_code);
131
120 // Retrieves the back-off entry object we're using. Used to enable a 132 // Retrieves the back-off entry object we're using. Used to enable a
121 // unit testing seam for dependency injection in tests. 133 // unit testing seam for dependency injection in tests.
122 virtual const BackoffEntry* GetBackoffEntry() const; 134 virtual const BackoffEntry* GetBackoffEntry() const;
123 virtual BackoffEntry* GetBackoffEntry(); 135 virtual BackoffEntry* GetBackoffEntry();
124 136
125 // Used by tests. 137 // Used by tests.
126 base::TimeTicks sliding_window_release_time() const { 138 base::TimeTicks sliding_window_release_time() const {
127 return sliding_window_release_time_; 139 return sliding_window_release_time_;
128 } 140 }
129 141
(...skipping 17 matching lines...) Expand all
147 159
148 const base::TimeDelta sliding_window_period_; 160 const base::TimeDelta sliding_window_period_;
149 const int max_send_threshold_; 161 const int max_send_threshold_;
150 162
151 // True if DisableBackoffThrottling() has been called on this object. 163 // True if DisableBackoffThrottling() has been called on this object.
152 bool is_backoff_disabled_; 164 bool is_backoff_disabled_;
153 165
154 // Access it through GetBackoffEntry() to allow a unit test seam. 166 // Access it through GetBackoffEntry() to allow a unit test seam.
155 BackoffEntry backoff_entry_; 167 BackoffEntry backoff_entry_;
156 168
169 // The time of the last successful response, plus knowledge of whether
170 // the last response was successful or not, let us generate statistics on
171 // the length of perceived downtime for a given URL, and the error count
172 // when such transitions occur. This is useful for experiments with
173 // throttling but will likely become redundant after they are finished.
174 // TODO(joi): Remove when the time is right
175 base::TimeTicks last_successful_response_time_;
176 bool last_response_was_success_;
177
157 // Weak back-reference to the manager object managing us. 178 // Weak back-reference to the manager object managing us.
158 URLRequestThrottlerManager* manager_; 179 URLRequestThrottlerManager* manager_;
159 180
181 // Canonicalized URL string that this entry is for; used for logging only.
182 std::string url_id_;
183
184 BoundNetLog net_log_;
185
160 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerEntry); 186 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerEntry);
161 }; 187 };
162 188
163 } // namespace net 189 } // namespace net
164 190
165 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_ 191 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_
OLDNEW
« no previous file with comments | « net/tools/testserver/backoff_server.py ('k') | net/url_request/url_request_throttler_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698