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

Commit 69a3a081 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6053205 from 09b13147 to rvc-release

Change-Id: I95dfbbbb702627bc90c4eb937a43797dd2a5c456
parents bd570a8b 09b13147
Loading
Loading
Loading
Loading
+9 −3
Original line number Original line Diff line number Diff line
@@ -101,14 +101,17 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const std::list<DnsTlsServer>&
    for (const auto& server : orderedServers) {
    for (const auto& server : orderedServers) {
        DnsQueryEvent* dnsQueryEvent =
        DnsQueryEvent* dnsQueryEvent =
                statp->event->mutable_dns_query_events()->add_dns_query_event();
                statp->event->mutable_dns_query_events()->add_dns_query_event();

        bool connectTriggered = false;
        Stopwatch queryStopwatch;
        Stopwatch queryStopwatch;
        code = this->query(server, statp->_mark, query, ans, resplen);
        code = this->query(server, statp->_mark, query, ans, resplen, &connectTriggered);


        dnsQueryEvent->set_latency_micros(saturate_cast<int32_t>(queryStopwatch.timeTakenUs()));
        dnsQueryEvent->set_latency_micros(saturate_cast<int32_t>(queryStopwatch.timeTakenUs()));
        dnsQueryEvent->set_dns_server_index(serverCount++);
        dnsQueryEvent->set_dns_server_index(serverCount++);
        dnsQueryEvent->set_ip_version(ipFamilyToIPVersion(server.ss.ss_family));
        dnsQueryEvent->set_ip_version(ipFamilyToIPVersion(server.ss.ss_family));
        dnsQueryEvent->set_protocol(PROTO_DOT);
        dnsQueryEvent->set_protocol(PROTO_DOT);
        dnsQueryEvent->set_type(getQueryType(query.base(), query.size()));
        dnsQueryEvent->set_type(getQueryType(query.base(), query.size()));
        dnsQueryEvent->set_connected(connectTriggered);


        switch (code) {
        switch (code) {
            // These response codes are valid responses and not expected to
            // These response codes are valid responses and not expected to
@@ -141,8 +144,9 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const std::list<DnsTlsServer>&
}
}


DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, unsigned mark,
DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, unsigned mark,
                                                  const Slice query,
                                                  const Slice query, const Slice ans, int* resplen,
                                                  const Slice ans, int *resplen) {
                                                  bool* connectTriggered) {
    uint32_t connectCounter;
    const Key key = std::make_pair(mark, server);
    const Key key = std::make_pair(mark, server);
    Transport* xport;
    Transport* xport;
    {
    {
@@ -155,6 +159,7 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, un
            xport = it->second.get();
            xport = it->second.get();
        }
        }
        ++xport->useCount;
        ++xport->useCount;
        connectCounter = xport->transport.getConnectCounter();
    }
    }


    LOG(DEBUG) << "Sending query of length " << query.size();
    LOG(DEBUG) << "Sending query of length " << query.size();
@@ -178,6 +183,7 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, un
    auto now = std::chrono::steady_clock::now();
    auto now = std::chrono::steady_clock::now();
    {
    {
        std::lock_guard guard(sLock);
        std::lock_guard guard(sLock);
        *connectTriggered = (xport->transport.getConnectCounter() > connectCounter);
        --xport->useCount;
        --xport->useCount;
        xport->lastUsed = now;
        xport->lastUsed = now;
        cleanup(now);
        cleanup(now);
+4 −3
Original line number Original line Diff line number Diff line
@@ -54,11 +54,12 @@ class DnsTlsDispatcher {
                                    const netdutils::Slice ans, int* _Nonnull resplen);
                                    const netdutils::Slice ans, int* _Nonnull resplen);


    // Given a |query|, sends it to the server on the network indicated by |mark|,
    // Given a |query|, sends it to the server on the network indicated by |mark|,
    // and writes the response into |ans|,  and indicates
    // and writes the response into |ans|, and indicates the number of bytes written in |resplen|.
    // the number of bytes written in |resplen|.  Returns a success or error code.
    // If the whole procedure above triggers (or experiences) any new connection, |connectTriggered|
    // is set. Returns a success or error code.
    DnsTlsTransport::Response query(const DnsTlsServer& server, unsigned mark,
    DnsTlsTransport::Response query(const DnsTlsServer& server, unsigned mark,
                                    const netdutils::Slice query, const netdutils::Slice ans,
                                    const netdutils::Slice query, const netdutils::Slice ans,
                                    int* _Nonnull resplen);
                                    int* _Nonnull resplen, bool* _Nonnull connectTriggered);


  private:
  private:
    // This lock is static so that it can be used to annotate the Transport struct.
    // This lock is static so that it can be used to annotate the Transport struct.
+3 −3
Original line number Original line Diff line number Diff line
@@ -74,6 +74,9 @@ class DnsTlsQueryMap {
    // Returns true if there are no pending queries.
    // Returns true if there are no pending queries.
    bool empty();
    bool empty();


    // The maximum number of times we will send a query before abandoning it.
    static constexpr int kMaxTries = 3;

  private:
  private:
    std::mutex mLock;
    std::mutex mLock;


@@ -87,9 +90,6 @@ class DnsTlsQueryMap {
        std::promise<Result> result;
        std::promise<Result> result;
    };
    };


    // The maximum number of times we will send a query before abandoning it.
    static constexpr int kMaxTries = 3;

    // Outstanding queries by newId.
    // Outstanding queries by newId.
    std::map<uint16_t, QueryPromise> mQueries GUARDED_BY(mLock);
    std::map<uint16_t, QueryPromise> mQueries GUARDED_BY(mLock);


+6 −0
Original line number Original line Diff line number Diff line
@@ -51,6 +51,11 @@ std::future<DnsTlsTransport::Result> DnsTlsTransport::query(const netdutils::Sli
    return std::move(record->result);
    return std::move(record->result);
}
}


uint32_t DnsTlsTransport::getConnectCounter() const {
    std::lock_guard guard(mLock);
    return mConnectCounter;
}

bool DnsTlsTransport::sendQuery(const DnsTlsQueryMap::Query q) {
bool DnsTlsTransport::sendQuery(const DnsTlsQueryMap::Query q) {
    // Strip off the ID number and send the new ID instead.
    // Strip off the ID number and send the new ID instead.
    bool sent = mSocket->query(q.newId, netdutils::drop(q.query, 2));
    bool sent = mSocket->query(q.newId, netdutils::drop(q.query, 2));
@@ -63,6 +68,7 @@ bool DnsTlsTransport::sendQuery(const DnsTlsQueryMap::Query q) {
void DnsTlsTransport::doConnect() {
void DnsTlsTransport::doConnect() {
    LOG(DEBUG) << "Constructing new socket";
    LOG(DEBUG) << "Constructing new socket";
    mSocket = mFactory->createDnsTlsSocket(mServer, mMark, this, &mCache);
    mSocket = mFactory->createDnsTlsSocket(mServer, mMark, this, &mCache);
    mConnectCounter++;


    if (mSocket) {
    if (mSocket) {
        auto queries = mQueries.getAll();
        auto queries = mQueries.getAll();
+6 −1
Original line number Original line Diff line number Diff line
@@ -57,12 +57,14 @@ class DnsTlsTransport : public IDnsTlsSocketObserver {
    // on networks where it doesn't actually work.
    // on networks where it doesn't actually work.
    static bool validate(const DnsTlsServer& server, unsigned netid, uint32_t mark);
    static bool validate(const DnsTlsServer& server, unsigned netid, uint32_t mark);


    uint32_t getConnectCounter() const EXCLUDES(mLock);

    // Implement IDnsTlsSocketObserver
    // Implement IDnsTlsSocketObserver
    void onResponse(std::vector<uint8_t> response) override;
    void onResponse(std::vector<uint8_t> response) override;
    void onClosed() override EXCLUDES(mLock);
    void onClosed() override EXCLUDES(mLock);


  private:
  private:
    std::mutex mLock;
    mutable std::mutex mLock;


    DnsTlsSessionCache mCache;
    DnsTlsSessionCache mCache;
    DnsTlsQueryMap mQueries;
    DnsTlsQueryMap mQueries;
@@ -85,6 +87,9 @@ class DnsTlsTransport : public IDnsTlsSocketObserver {


    // Send a query to the socket.
    // Send a query to the socket.
    bool sendQuery(const DnsTlsQueryMap::Query q) REQUIRES(mLock);
    bool sendQuery(const DnsTlsQueryMap::Query q) REQUIRES(mLock);

    // The number of times an attempt to connect the nameserver.
    uint32_t mConnectCounter GUARDED_BY(mLock) = 0;
};
};


}  // end of namespace net
}  // end of namespace net
Loading