blob: 4e09ebe3984ced2410641e0c43ca026dfbb801c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef ODoHService_h_
#define ODoHService_h_
#include "DNS.h"
#include "mozilla/Atomics.h"
#include "mozilla/Maybe.h"
#include "mozilla/Mutex.h"
#include "nsString.h"
#include "nsIDNSListener.h"
#include "nsIObserver.h"
#include "nsIStreamLoader.h"
#include "nsITimer.h"
#include "nsWeakReference.h"
namespace mozilla {
namespace net {
class ODoH;
class ODoHService : public nsIDNSListener,
public nsIObserver,
public nsSupportsWeakReference,
public nsITimerCallback,
public nsINamed,
public nsIStreamLoaderObserver {
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIDNSLISTENER
NS_DECL_NSIOBSERVER
NS_DECL_NSITIMERCALLBACK
NS_DECL_NSINAMED
NS_DECL_NSISTREAMLOADEROBSERVER
ODoHService();
bool Init();
bool Enabled() const;
const Maybe<nsTArray<ObliviousDoHConfig>>& ODoHConfigs();
void AppendPendingODoHRequest(ODoH* aRequest);
bool RemovePendingODoHRequest(ODoH* aRequest);
void GetRequestURI(nsACString& aResult);
// Send a DNS query to reterive the ODoHConfig.
nsresult UpdateODoHConfig();
private:
virtual ~ODoHService();
nsresult ReadPrefs(const char* aName);
void OnODoHPrefsChange(bool aInit);
void BuildODoHRequestURI();
void StartTTLTimer(uint32_t aTTL);
void OnODohConfigsURIChanged();
void ODoHConfigUpdateDone(uint32_t aTTL, Span<const uint8_t> aRawConfig);
nsresult UpdateODoHConfigFromHTTPSRR();
nsresult UpdateODoHConfigFromURI();
mozilla::Mutex mLock;
Atomic<bool, Relaxed> mQueryODoHConfigInProgress;
nsCString mODoHProxyURI MOZ_GUARDED_BY(mLock);
nsCString mODoHTargetHost MOZ_GUARDED_BY(mLock);
nsCString mODoHTargetPath MOZ_GUARDED_BY(mLock);
nsCString mODoHRequestURI MOZ_GUARDED_BY(mLock);
nsCString mODoHConfigsUri MOZ_GUARDED_BY(mLock);
Maybe<nsTArray<ObliviousDoHConfig>> mODoHConfigs MOZ_GUARDED_BY(mLock);
nsTArray<RefPtr<ODoH>> mPendingRequests MOZ_GUARDED_BY(mLock);
// This timer is always touched on main thread to avoid race conditions.
nsCOMPtr<nsITimer> mTTLTimer;
nsCOMPtr<nsIStreamLoader> mLoader MOZ_GUARDED_BY(mLock);
};
extern ODoHService* gODoHService;
} // namespace net
} // namespace mozilla
#endif
|