diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 18:51:53 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 18:51:53 +0000 |
commit | 82c71ba49a999ffa2b9c57aefc664dfd9bbe8186 (patch) | |
tree | a119d96375aa37d2609cfc911ed5a9c84c594f4b /net/base/backoff_entry.cc | |
parent | 4d768302d3e793d3b717bedea907b6038e391bff (diff) | |
download | chromium_src-82c71ba49a999ffa2b9c57aefc664dfd9bbe8186.zip chromium_src-82c71ba49a999ffa2b9c57aefc664dfd9bbe8186.tar.gz chromium_src-82c71ba49a999ffa2b9c57aefc664dfd9bbe8186.tar.bz2 |
Anti-DDoS enhancements: Log to net log, UMA stats, improved policy.
Count only certain error codes as failures. Don't count malformed body
for codes already counted failures. Start with fresh entry when
outdated, which makes policy slightly less aggressive.
Add registration/unregistration to NetworkChangeNotifier, and reset
throttling state on network changes, to avoid degenerate corner cases.
Add UMA stats for throttling, and unit tests for them.
Add hash-location-only URL to unit test.
Enable testing of AJAX behavior via backoff_server.
BUG=83775
TEST=net_unittests
Review URL: http://codereview.chromium.org/6966038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87056 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/backoff_entry.cc')
-rw-r--r-- | net/base/backoff_entry.cc | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/net/base/backoff_entry.cc b/net/base/backoff_entry.cc index e7b7b55..5fcaed9 100644 --- a/net/base/backoff_entry.cc +++ b/net/base/backoff_entry.cc @@ -13,12 +13,9 @@ namespace net { BackoffEntry::BackoffEntry(const BackoffEntry::Policy* const policy) - : failure_count_(0), - policy_(policy) { + : policy_(policy) { DCHECK(policy_); - - // Can't use GetTimeNow() as it's virtual. - exponential_backoff_release_time_ = base::TimeTicks::Now(); + Reset(); } BackoffEntry::~BackoffEntry() { @@ -42,21 +39,22 @@ void BackoffEntry::InformOfRequest(bool succeeded) { if (failure_count_ > 0) --failure_count_; - // The reason why we are not just cutting the release time to GetTimeNow() - // is on the one hand, it would unset a release time set by - // SetCustomReleaseTime and on the other we would like to push every - // request up to our "horizon" when dealing with multiple in-flight - // requests. Ex: If we send three requests and we receive 2 failures and - // 1 success. The success that follows those failures will not reset the - // release time, further requests will then need to wait the delay caused - // by the 2 failures. + // The reason why we are not just cutting the release time to + // ImplGetTimeNow() is on the one hand, it would unset a release + // time set by SetCustomReleaseTime and on the other we would like + // to push every request up to our "horizon" when dealing with + // multiple in-flight requests. Ex: If we send three requests and + // we receive 2 failures and 1 success. The success that follows + // those failures will not reset the release time, further + // requests will then need to wait the delay caused by the 2 + // failures. exponential_backoff_release_time_ = std::max( - GetTimeNow(), exponential_backoff_release_time_); + ImplGetTimeNow(), exponential_backoff_release_time_); } } bool BackoffEntry::ShouldRejectRequest() const { - return exponential_backoff_release_time_ > GetTimeNow(); + return exponential_backoff_release_time_ > ImplGetTimeNow(); } base::TimeTicks BackoffEntry::GetReleaseTime() const { @@ -71,7 +69,7 @@ bool BackoffEntry::CanDiscard() const { if (policy_->entry_lifetime_ms == -1) return false; - base::TimeTicks now = GetTimeNow(); + base::TimeTicks now = ImplGetTimeNow(); int64 unused_since_ms = (now - exponential_backoff_release_time_).InMilliseconds(); @@ -92,7 +90,18 @@ bool BackoffEntry::CanDiscard() const { return unused_since_ms >= policy_->entry_lifetime_ms; } -base::TimeTicks BackoffEntry::GetTimeNow() const { +void BackoffEntry::Reset() { + failure_count_ = 0; + + // We leave exponential_backoff_release_time_ unset, meaning 0. We could + // initialize to ImplGetTimeNow() but because it's a virtual method it's + // not safe to call in the constructor (and the constructor calls Reset()). + // The effects are the same, i.e. ShouldRejectRequest() will return false + // right after Reset(). + exponential_backoff_release_time_ = base::TimeTicks(); +} + +base::TimeTicks BackoffEntry::ImplGetTimeNow() const { return base::TimeTicks::Now(); } @@ -102,7 +111,7 @@ base::TimeTicks BackoffEntry::CalculateReleaseTime() const { if (effective_failure_count == 0) { // Never reduce previously set release horizon, e.g. due to Retry-After // header. - return std::max(GetTimeNow(), exponential_backoff_release_time_); + return std::max(ImplGetTimeNow(), exponential_backoff_release_time_); } // The delay is calculated with this formula: @@ -119,8 +128,9 @@ base::TimeTicks BackoffEntry::CalculateReleaseTime() const { // Never reduce previously set release horizon, e.g. due to Retry-After // header. - return std::max(GetTimeNow() + base::TimeDelta::FromMilliseconds(delay_int), - exponential_backoff_release_time_); + return std::max( + ImplGetTimeNow() + base::TimeDelta::FromMilliseconds(delay_int), + exponential_backoff_release_time_); } } // namespace net |