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

Commit ac949907 authored by Mike Yu's avatar Mike Yu Committed by Gerrit Code Review
Browse files

Merge "Initialize DnsTlsDispatcher instance only when needed"

parents df311fe7 9e8cf8d5
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -41,6 +41,11 @@ DnsTlsDispatcher::DnsTlsDispatcher() {
    mFactory.reset(new DnsTlsSocketFactory());
}

DnsTlsDispatcher& DnsTlsDispatcher::getInstance() {
    static DnsTlsDispatcher instance;
    return instance;
}

std::list<DnsTlsServer> DnsTlsDispatcher::getOrderedServerList(
        const std::list<DnsTlsServer> &tlsServers, unsigned mark) const {
    // Our preferred DnsTlsServer order is:
+4 −3
Original line number Diff line number Diff line
@@ -37,13 +37,12 @@ namespace net {
// Queries made here are dispatched to an existing or newly constructed DnsTlsTransport.
class DnsTlsDispatcher {
  public:
    // Default constructor.
    DnsTlsDispatcher();

    // Constructor with dependency injection for testing.
    explicit DnsTlsDispatcher(std::unique_ptr<IDnsTlsSocketFactory> factory)
        : mFactory(std::move(factory)) {}

    static DnsTlsDispatcher& getInstance();

    // Enqueues |query| for resolution via the given |tlsServers| on the
    // network indicated by |mark|; writes the response into |ans|, and stores
    // the count of bytes written in |resplen|. Returns a success or error code.
@@ -62,6 +61,8 @@ class DnsTlsDispatcher {
                                    int* _Nonnull resplen, bool* _Nonnull connectTriggered);

  private:
    DnsTlsDispatcher();

    // This lock is static so that it can be used to annotate the Transport struct.
    // DnsTlsDispatcher is a singleton in practice, so making this static does not change
    // the locking behavior.
+2 −4
Original line number Diff line number Diff line
@@ -144,8 +144,6 @@ using android::netdutils::IPSockAddr;
using android::netdutils::Slice;
using android::netdutils::Stopwatch;

static DnsTlsDispatcher sDnsTlsDispatcher;

static int send_vc(res_state statp, res_params* params, const uint8_t* buf, int buflen,
                   uint8_t* ans, int anssiz, int* terrno, size_t ns, time_t* at, int* rcode,
                   int* delay);
@@ -1255,8 +1253,8 @@ static int res_tls_send(res_state statp, const Slice query, const Slice answer,

    LOG(INFO) << __func__ << ": performing query over TLS";

    const auto response = sDnsTlsDispatcher.query(privateDnsStatus.validatedServers(), statp, query,
                                                  answer, &resplen);
    const auto response = DnsTlsDispatcher::getInstance().query(privateDnsStatus.validatedServers(),
                                                                statp, query, answer, &resplen);

    LOG(INFO) << __func__ << ": TLS query result: " << static_cast<int>(response);