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

Commit cb7358aa authored by Mike Yu's avatar Mike Yu Committed by Automerger Merge Worker
Browse files

Merge "Add PrivateDnsCommon.h and PrivateDnsValidationObserver.h" am: 7c8ebcc7 am: 7eb28a3f

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Idb9b0433a610864fa6dc102ef45d827e78dca9d4
parents 66eaa2db 7eb28a3f
Loading
Loading
Loading
Loading
+2 −10
Original line number Diff line number Diff line
@@ -24,19 +24,11 @@

#include <params.h>

#include "PrivateDnsCommon.h"

namespace android {
namespace net {

// Validation status of a DNS over TLS server (on a specific netId).
enum class Validation : uint8_t {
    in_process,
    success,
    success_but_expired,
    fail,
    unknown_server,
    unknown_netid,
};

// DnsTlsServer represents a recursive resolver that supports, or may support, a
// secure protocol.
struct DnsTlsServer {

PrivateDnsCommon.h

0 → 100644
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

namespace android::net {

// Validation status of a private DNS server on a specific netId.
enum class Validation : uint8_t {
    in_process,
    success,
    success_but_expired,
    fail,
    unknown_server,
    unknown_netid,
};

// The private DNS mode on a specific netId.
enum class PrivateDnsMode : uint8_t {
    OFF,
    OPPORTUNISTIC,
    STRICT,
};

}  // namespace android::net
+1 −1
Original line number Diff line number Diff line
@@ -330,7 +330,7 @@ bool PrivateDnsConfiguration::needsValidation(const DnsTlsServer& server) {
    return false;
}

void PrivateDnsConfiguration::setObserver(Observer* observer) {
void PrivateDnsConfiguration::setObserver(PrivateDnsValidationObserver* observer) {
    std::lock_guard guard(mPrivateDnsLock);
    mObserver = observer;
}
+4 −18
Original line number Diff line number Diff line
@@ -25,13 +25,11 @@
#include <netdutils/InternetAddresses.h>

#include "DnsTlsServer.h"
#include "PrivateDnsValidationObserver.h"

namespace android {
namespace net {

// The DNS over TLS mode on a specific netId.
enum class PrivateDnsMode : uint8_t { OFF, OPPORTUNISTIC, STRICT };

struct PrivateDnsStatus {
    PrivateDnsMode mode;

@@ -116,24 +114,12 @@ class PrivateDnsConfiguration {
    // Any pending validation threads will continue running because we have no way to cancel them.
    std::map<unsigned, PrivateDnsTracker> mPrivateDnsTransports GUARDED_BY(mPrivateDnsLock);

    // For testing. The observer is notified of onValidationStateUpdate 1) when a validation is
    // about to begin or 2) when a validation finishes. If a validation finishes when in OFF mode
    // or when the network has been destroyed, |validation| will be Validation::fail.
    // WARNING: The Observer is notified while the lock is being held. Be careful not to call
    // any method of PrivateDnsConfiguration from the observer.
    // TODO: fix the reentrancy problem.
    class Observer {
      public:
        virtual ~Observer(){};
        virtual void onValidationStateUpdate(const std::string& serverIp, Validation validation,
                                             uint32_t netId) = 0;
    };

    void setObserver(Observer* observer);
    void setObserver(PrivateDnsValidationObserver* observer);
    void notifyValidationStateUpdate(const std::string& serverIp, Validation validation,
                                     uint32_t netId) const REQUIRES(mPrivateDnsLock);

    Observer* mObserver GUARDED_BY(mPrivateDnsLock);
    // TODO: fix the reentrancy problem.
    PrivateDnsValidationObserver* mObserver GUARDED_BY(mPrivateDnsLock);

    friend class PrivateDnsConfigurationTest;
};
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ class PrivateDnsConfigurationTest : public ::testing::Test {
    }

  protected:
    class MockObserver : public PrivateDnsConfiguration::Observer {
    class MockObserver : public PrivateDnsValidationObserver {
      public:
        MOCK_METHOD(void, onValidationStateUpdate,
                    (const std::string& serverIp, Validation validation, uint32_t netId),
Loading