tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ChildDNSService.h (2832B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set sw=2 ts=8 et tw=80 : */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_net_ChildDNSService_h
      8 #define mozilla_net_ChildDNSService_h
      9 
     10 #include "DNSServiceBase.h"
     11 #include "nsPIDNSService.h"
     12 #include "mozilla/Attributes.h"
     13 #include "mozilla/Mutex.h"
     14 #include "DNSRequestChild.h"
     15 #include "DNSRequestParent.h"
     16 #include "nsHashKeys.h"
     17 #include "nsClassHashtable.h"
     18 
     19 namespace mozilla {
     20 namespace net {
     21 
     22 class TRRServiceParent;
     23 
     24 class ChildDNSService final : public DNSServiceBase, public nsPIDNSService {
     25 public:
     26  // AsyncResolve (and CancelAsyncResolve) can be called off-main
     27  NS_DECL_ISUPPORTS_INHERITED
     28  NS_DECL_NSPIDNSSERVICE
     29  NS_DECL_NSIDNSSERVICE
     30  NS_DECL_NSIOBSERVER
     31 
     32  ChildDNSService();
     33 
     34  static already_AddRefed<ChildDNSService> GetSingleton();
     35 
     36  void NotifyRequestDone(DNSRequestSender* aDnsRequest);
     37 
     38  void SetTRRDomain(const nsACString& aTRRDomain);
     39  void SetTRRModeInChild(nsIDNSService::ResolverMode mode,
     40                         nsIDNSService::ResolverMode modeFromPref);
     41 
     42 private:
     43  virtual ~ChildDNSService() = default;
     44 
     45  void MOZ_ALWAYS_INLINE GetDNSRecordHashKey(
     46      const nsACString& aHost, const nsACString& aTrrServer, int32_t aPort,
     47      uint16_t aType, const OriginAttributes& aOriginAttributes,
     48      nsIDNSService::DNSFlags aFlags, uintptr_t aListenerAddr,
     49      nsACString& aHashKey);
     50  nsresult AsyncResolveInternal(const nsACString& hostname, uint16_t type,
     51                                nsIDNSService::DNSFlags flags,
     52                                nsIDNSAdditionalInfo* aInfo,
     53                                nsIDNSListener* listener,
     54                                nsIEventTarget* target_,
     55                                const OriginAttributes& aOriginAttributes,
     56                                nsICancelable** result);
     57  nsresult CancelAsyncResolveInternal(
     58      const nsACString& aHostname, uint16_t aType,
     59      nsIDNSService::DNSFlags aFlags, nsIDNSAdditionalInfo* aInfo,
     60      nsIDNSListener* aListener, nsresult aReason,
     61      const OriginAttributes& aOriginAttributes);
     62 
     63  // We need to remember pending dns requests to be able to cancel them.
     64  nsClassHashtable<nsCStringHashKey, nsTArray<RefPtr<DNSRequestSender>>>
     65      mPendingRequests;
     66  Mutex mPendingRequestsLock MOZ_UNANNOTATED{"DNSPendingRequestsLock"};
     67  RefPtr<TRRServiceParent> mTRRServiceParent;
     68 
     69  nsCString mTRRDomain;
     70  // Only set in the content process.
     71  nsIDNSService::ResolverMode mTRRMode =
     72      nsIDNSService::ResolverMode::MODE_NATIVEONLY;
     73 };
     74 
     75 }  // namespace net
     76 }  // namespace mozilla
     77 
     78 #endif  // mozilla_net_ChildDNSService_h