aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2022-04-25 12:24:44 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-04-25 12:24:44 +0000
commitbfe94814f3f2b02162e24159902524e4b90a0828 (patch)
tree684882ef8ea10f48fecca72ae8132f6eef82e80c
parentc1afb03e6d0f8ed4671aaff867e91362d1d7397e (diff)
parenta3e650899e31e5cc61f836a11edc78de324d18df (diff)
downloadDnsResolver-bfe94814f3f2b02162e24159902524e4b90a0828.tar.gz
Merge "Add experiment flag for DNS query global limiter" am: 7299cab99f am: a3e650899e
Original change: https://android-review.googlesource.com/c/platform/packages/modules/DnsResolver/+/2071247 Change-Id: I22b771876ed17d2bc307b5a90f19e3876ec6e6af Ignore-AOSP-First: this is an automerge Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--Experiments.h1
-rw-r--r--OperationLimiter.h19
2 files changed, 13 insertions, 7 deletions
diff --git a/Experiments.h b/Experiments.h
index 2511012e..209a208e 100644
--- a/Experiments.h
+++ b/Experiments.h
@@ -68,6 +68,7 @@ class Experiments {
"doh_idle_timeout_ms",
"doh_session_resumption",
"mdns_resolution",
+ "max_queries_global",
};
// This value is used in updateInternal as the default value if any flags can't be found.
static constexpr int kFlagIntDefault = INT_MIN;
diff --git a/OperationLimiter.h b/OperationLimiter.h
index 1fa1bf23..332157a7 100644
--- a/OperationLimiter.h
+++ b/OperationLimiter.h
@@ -23,6 +23,8 @@
#include <android-base/logging.h>
#include <android-base/thread_annotations.h>
+#include "Experiments.h"
+
namespace android {
namespace netdutils {
@@ -43,8 +45,7 @@ namespace netdutils {
template <typename KeyType>
class OperationLimiter {
public:
- OperationLimiter(int limitPerKey, int globalLimit = INT_MAX)
- : mLimitPerKey(limitPerKey), mGlobalLimit(globalLimit) {}
+ OperationLimiter(int limitPerKey) : mLimitPerKey(limitPerKey) {}
~OperationLimiter() {
DCHECK(mCounters.empty()) << "Destroying OperationLimiter with active operations";
@@ -57,15 +58,22 @@ class OperationLimiter {
// finish(key).
bool start(KeyType key) EXCLUDES(mMutex) {
std::lock_guard lock(mMutex);
-
- if (mGlobalCounter >= mGlobalLimit) {
+ int globalLimit =
+ android::net::Experiments::getInstance()->getFlag("max_queries_global", INT_MAX);
+ if (globalLimit < mLimitPerKey) {
+ LOG(ERROR) << "Misconfiguration on max_queries_global " << globalLimit;
+ globalLimit = INT_MAX;
+ }
+ if (mGlobalCounter >= globalLimit) {
// Oh, no!
+ LOG(ERROR) << "Query from " << key << " denied due to global limit: " << globalLimit;
return false;
}
auto& cnt = mCounters[key]; // operator[] creates new entries as needed.
if (cnt >= mLimitPerKey) {
// Oh, no!
+ LOG(ERROR) << "Query from " << key << " denied due to limit: " << mLimitPerKey;
return false;
}
@@ -109,9 +117,6 @@ class OperationLimiter {
// Maximum number of outstanding queries from a single key.
const int mLimitPerKey;
-
- // Maximum number of outstanding queries, globally.
- const int mGlobalLimit;
};
} // namespace netdutils