1 /* -*- Mode: C++; tab-width: 2; 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/. */
7 #ifndef mozilla_net_TRRQuery_h
8 #define mozilla_net_TRRQuery_h
10 #include "nsHostResolver.h"
11 #include "DNSPacket.h"
16 class TRRQuery
: public AHostResolver
{
17 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TRRQuery
, override
)
20 TRRQuery(nsHostResolver
* aHostResolver
, nsHostRecord
* aHostRecord
)
21 : mHostResolver(aHostResolver
),
23 mTrrLock("TRRQuery.mTrrLock") {}
25 nsresult
DispatchLookup(TRR
* pushedTRR
= nullptr);
27 void Cancel(nsresult aStatus
);
29 enum TRRState
{ INIT
, STARTED
, OK
, FAILED
};
30 TRRState mTrrAUsed
= INIT
;
31 TRRState mTrrAAAAUsed
= INIT
;
33 TRRSkippedReason mTRRAFailReason
= TRRSkippedReason::TRR_UNSET
;
34 TRRSkippedReason mTRRAAAAFailReason
= TRRSkippedReason::TRR_UNSET
;
36 virtual LookupStatus
CompleteLookup(nsHostRecord
*, nsresult
,
37 mozilla::net::AddrInfo
*, bool pb
,
38 const nsACString
& aOriginsuffix
,
39 nsHostRecord::TRRSkippedReason aReason
,
40 TRR
* aTRRRequest
) override
;
41 virtual LookupStatus
CompleteLookupByType(
42 nsHostRecord
*, nsresult
, mozilla::net::TypeRecordResultType
& aResult
,
43 uint32_t aTtl
, bool pb
) override
;
44 virtual nsresult
GetHostRecord(const nsACString
& host
,
45 const nsACString
& aTrrServer
, uint16_t type
,
46 nsIDNSService::DNSFlags flags
, uint16_t af
,
47 bool pb
, const nsCString
& originSuffix
,
48 nsHostRecord
** result
) override
{
50 return NS_ERROR_FAILURE
;
52 return mHostResolver
->GetHostRecord(host
, aTrrServer
, type
, flags
, af
, pb
,
53 originSuffix
, result
);
55 virtual nsresult
TrrLookup_unlocked(
56 nsHostRecord
* rec
, mozilla::net::TRR
* pushedTRR
= nullptr) override
{
58 return NS_ERROR_FAILURE
;
60 return mHostResolver
->TrrLookup_unlocked(rec
, pushedTRR
);
62 virtual void MaybeRenewHostRecord(nsHostRecord
* aRec
) override
{
66 mHostResolver
->MaybeRenewHostRecord(aRec
);
69 mozilla::TimeDuration
Duration() { return mTrrDuration
; }
72 nsresult
DispatchByTypeLookup(TRR
* pushedTRR
= nullptr);
75 ~TRRQuery() = default;
77 void MarkSendingTRR(TRR
* trr
, TrrType rectype
, MutexAutoLock
&);
78 void PrepareQuery(TrrType aRecType
, nsTArray
<RefPtr
<TRR
>>& aRequestsToSend
);
79 bool SendQueries(nsTArray
<RefPtr
<TRR
>>& aRequestsToSend
);
81 RefPtr
<nsHostResolver
> mHostResolver
;
82 RefPtr
<nsHostRecord
> mRecord
;
85 MOZ_UNANNOTATED
; // lock when accessing the mTrrA[AAA] pointers
86 RefPtr
<mozilla::net::TRR
> mTrrA
;
87 RefPtr
<mozilla::net::TRR
> mTrrAAAA
;
88 RefPtr
<mozilla::net::TRR
> mTrrByType
;
89 // |mTRRRequestCounter| indicates the number of TRR requests that were
90 // dispatched sucessfully. Generally, this counter is increased to 2 after
91 // mTrrA and mTrrAAAA are dispatched, and is decreased by 1 when
92 // CompleteLookup is called. Note that nsHostResolver::CompleteLookup is only
93 // called when this counter equals to 0.
94 Atomic
<uint32_t> mTRRRequestCounter
{0};
96 uint8_t mTRRSuccess
= 0; // number of successful TRR responses
97 bool mCalledCompleteLookup
= false;
99 mozilla::TimeDuration mTrrDuration
;
100 mozilla::TimeStamp mTrrStart
;
102 RefPtr
<mozilla::net::AddrInfo
> mAddrInfoA
;
103 RefPtr
<mozilla::net::AddrInfo
> mAddrInfoAAAA
;
104 nsresult mAResult
= NS_OK
;
105 nsresult mAAAAResult
= NS_OK
;
109 } // namespace mozilla
111 #endif // mozilla_net_TRRQuery_h