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

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

Remove validity time constraint in DNS query log am: 80f6ad2f am: 719acbef...

Remove validity time constraint in DNS query log am: 80f6ad2f am: 719acbef am: f6cab2fd am: 8c4a1bc9

Original change: https://android-review.googlesource.com/c/platform/packages/modules/DnsResolver/+/2614129



Change-Id: Ia1ad241918615dcdbc06cfdf9ac2b1289da50c44
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 5f1595d0 8c4a1bc9
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -58,13 +58,10 @@ uint64_t DnsQueryLog::getLogSizeFromSysProp() {
}

void DnsQueryLog::dump(netdutils::DumpWriter& dw) const {
    dw.println("DNS query log (last %lld minutes):", (mValidityTimeMs / 60000).count());
    dw.println("DNS query log:");
    netdutils::ScopedIndent indentStats(dw);
    const auto now = std::chrono::system_clock::now();

    for (const auto& record : mQueue.copy()) {
        if (now - record.timestamp > mValidityTimeMs) continue;

        const std::string maskedHostname = maskHostname(record.hostname);
        const std::string maskedIpsStr = maskIps(record.addrs);
        const std::string time = timestampToString(record.timestamp);
+2 −7
Original line number Diff line number Diff line
@@ -51,25 +51,20 @@ class DnsQueryLog {

    DnsQueryLog() : DnsQueryLog(getLogSizeFromSysProp()) {}

    // Allow the tests to set the capacity and the validaty time in milliseconds.
    DnsQueryLog(size_t size, std::chrono::milliseconds time = kDefaultValidityMinutes)
        : mQueue(size), mValidityTimeMs(time) {}
    // Allow the tests to set the capacity.
    DnsQueryLog(size_t size) : mQueue(size) {}

    void push(Record&& record);
    void dump(netdutils::DumpWriter& dw) const;

  private:
    LockedRingBuffer<Record> mQueue;
    const std::chrono::milliseconds mValidityTimeMs;

    // The capacity of the circular buffer.
    static constexpr size_t kDefaultLogSize = 200;
    // The upper bound of the circular buffer.
    static constexpr size_t kMaxLogSize = 10000;

    // Limit to dump the queries within last |kDefaultValidityMinutes| minutes.
    static constexpr std::chrono::minutes kDefaultValidityMinutes{60};

    uint64_t getLogSizeFromSysProp();
};

+0 −22
Original line number Diff line number Diff line
@@ -141,28 +141,6 @@ TEST_F(DnsQueryLogTest, CapacityFull) {
    verifyDumpOutput(output, expectedNetIds);
}

TEST_F(DnsQueryLogTest, ValidityTime) {
    DnsQueryLog::Record r1(30, 1000, 1000, "www.example.com", serversV4, 10);
    DnsQueryLog queryLog(3, 100ms);
    queryLog.push(std::move(r1));

    // Dump the output and verify the correctness by checking netId.
    std::string output = captureDumpOutput(queryLog);
    verifyDumpOutput(output, {30});

    std::this_thread::sleep_for(150ms);

    // The record is expired thus not shown in the output.
    output = captureDumpOutput(queryLog);
    verifyDumpOutput(output, {});

    // Push another record to ensure it still works.
    DnsQueryLog::Record r2(31, 1000, 1000, "example.com", serversV4V6, 10);
    queryLog.push(std::move(r2));
    output = captureDumpOutput(queryLog);
    verifyDumpOutput(output, {31});
}

TEST_F(DnsQueryLogTest, SizeCustomization) {
    const size_t logSize = 3;
    const ScopedSystemProperties sp(kQueryLogSize, std::to_string(logSize));