Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dab596a3 authored by Ken Chen's avatar Ken Chen Committed by Automerger Merge Worker
Browse files

Set global limiter from INT_MAX to 2500 by default am: 5e1de553 am: 99de1f69

parents 465d9991 99de1f69
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -70,20 +70,19 @@ using std::span;

namespace android {

using netdutils::MAX_QUERIES_IN_TOTAL;
using netdutils::MAX_QUERIES_PER_UID;
using netdutils::ResponseCode;
using netdutils::Stopwatch;

namespace net {
namespace {

// Limits the number of outstanding DNS queries by client UID.
constexpr int MAX_QUERIES_PER_UID = 256;

android::netdutils::OperationLimiter<uid_t> queryLimiter(MAX_QUERIES_PER_UID);

bool startQueryLimiter(uid_t uid) {
    const int globalLimit =
            android::net::Experiments::getInstance()->getFlag("max_queries_global", INT_MAX);
    const int globalLimit = android::net::Experiments::getInstance()->getFlag("max_queries_global",
                                                                              MAX_QUERIES_IN_TOTAL);
    return queryLimiter.start(uid, globalLimit);
}

+7 −2
Original line number Diff line number Diff line
@@ -28,6 +28,11 @@
namespace android {
namespace netdutils {

// Limits the number of outstanding DNS queries by client UID.
constexpr int MAX_QUERIES_PER_UID = 256;
// Limits the total number of outstanding DNS queries.
constexpr int MAX_QUERIES_IN_TOTAL = 2500;

// Tracks the number of operations in progress on behalf of a particular key or
// ID, rejecting further attempts to start new operations after a configurable
// limit has been reached.
@@ -56,11 +61,11 @@ class OperationLimiter {
    //
    // Note: each successful start(key) must be matched by exactly one call to
    // finish(key).
    bool start(KeyType key, int globalLimit = INT_MAX) EXCLUDES(mMutex) {
    bool start(KeyType key, int globalLimit = MAX_QUERIES_IN_TOTAL) EXCLUDES(mMutex) {
        std::lock_guard lock(mMutex);
        if (globalLimit < mLimitPerKey) {
            LOG(ERROR) << "Misconfiguration on max_queries_global " << globalLimit;
            globalLimit = INT_MAX;
            globalLimit = MAX_QUERIES_IN_TOTAL;
        }
        if (mGlobalCounter >= globalLimit) {
            // Oh, no!