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

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

Keep the lock held in getStatusForMetrics() am: abf09b51

parents 204dcfc2 abf09b51
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -158,12 +158,16 @@ void PrivateDnsConfiguration::clearDot(int32_t netId) {
}

PrivateDnsStatus PrivateDnsConfiguration::getStatus(unsigned netId) const {
    std::lock_guard guard(mPrivateDnsLock);
    return getStatusLocked(netId);
}

PrivateDnsStatus PrivateDnsConfiguration::getStatusLocked(unsigned netId) const {
    PrivateDnsStatus status{
            .mode = PrivateDnsMode::OFF,
            .dotServersMap = {},
            .dohServersMap = {},
    };
    std::lock_guard guard(mPrivateDnsLock);

    const auto mode = mPrivateDnsModes.find(netId);
    if (mode == mPrivateDnsModes.end()) return status;
@@ -189,19 +193,18 @@ PrivateDnsStatus PrivateDnsConfiguration::getStatus(unsigned netId) const {
}

NetworkDnsServerSupportReported PrivateDnsConfiguration::getStatusForMetrics(unsigned netId) const {
    NetworkDnsServerSupportReported event;
    {
    std::lock_guard guard(mPrivateDnsLock);
        if (const auto it = mPrivateDnsModes.find(netId); it != mPrivateDnsModes.end()) {
            event.set_private_dns_modes(convert_enum_type(it->second));
        } else {
            return event;
        }

    if (mPrivateDnsModes.find(netId) == mPrivateDnsModes.end()) {
        // Return NetworkDnsServerSupportReported with private_dns_modes set to PDM_UNKNOWN.
        return {};
    }

    const PrivateDnsStatus status = getStatusLocked(netId);
    NetworkDnsServerSupportReported event = {};
    event.set_network_type(resolv_get_network_types_for_net(netId));
    event.set_private_dns_modes(convert_enum_type(status.mode));

    const PrivateDnsStatus status = getStatus(netId);
    std::lock_guard guard(mPrivateDnsLock);
    if (const auto it = mUnorderedDnsTracker.find(netId); it != mUnorderedDnsTracker.end()) {
        for (size_t i = 0; i < it->second.size(); i++) {
            Server* server = event.mutable_servers()->add_server();
+3 −0
Original line number Diff line number Diff line
@@ -147,6 +147,9 @@ class PrivateDnsConfiguration {
    base::Result<DnsTlsServer*> getDotServerLocked(const ServerIdentity& identity, unsigned netId)
            REQUIRES(mPrivateDnsLock);

    // TODO: change the return type to Result<PrivateDnsStatus>.
    PrivateDnsStatus getStatusLocked(unsigned netId) const REQUIRES(mPrivateDnsLock);

    // Launchs a thread to run the validation for the DoT server |server| on the network |netId|.
    // |isRevalidation| is true if this call is due to a revalidation request.
    void startDotValidation(const ServerIdentity& identity, unsigned netId, bool isRevalidation)