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/. */
9 #include "mozilla/Base64.h"
10 #include "nsIURIMutator.h"
11 #include "ODoHService.h"
12 #include "TRRService.h"
13 // Put DNSLogging.h at the end to avoid LOG being overwritten by other headers.
14 #include "DNSLogging.h"
15 #include "nsNetUtil.h"
23 RecordReason(TRRSkippedReason::TRR_SEND_FAILED
);
24 FailData(NS_ERROR_FAILURE
);
28 if (!gODoHService
->ODoHConfigs()) {
30 "ODoH::Run ODoHConfigs is not available mTriedDownloadODoHConfigs=%d\n",
31 mTriedDownloadODoHConfigs
));
32 // Make this lookup fail if we don't have a valid ODoHConfig and we already
34 if (NS_SUCCEEDED(gODoHService
->UpdateODoHConfig()) &&
35 !mTriedDownloadODoHConfigs
) {
36 gODoHService
->AppendPendingODoHRequest(this);
37 mTriedDownloadODoHConfigs
= true;
39 RecordReason(TRRSkippedReason::ODOH_UPDATE_KEY_FAILED
);
40 FailData(NS_ERROR_FAILURE
);
49 DNSPacket
* ODoH::GetOrCreateDNSPacket() {
51 mPacket
= MakeUnique
<ODoHDNSPacket
>();
57 nsresult
ODoH::CreateQueryURI(nsIURI
** aOutURI
) {
59 nsCOMPtr
<nsIURI
> dnsURI
;
60 gODoHService
->GetRequestURI(uri
);
62 nsresult rv
= NS_NewURI(getter_AddRefs(dnsURI
), uri
);
67 dnsURI
.forget(aOutURI
);
71 void ODoH::HandleTimeout() {
72 // If this request is still in the pending queue, it means we can't get the
73 // ODoHConfigs within the timeout.
74 if (gODoHService
->RemovePendingODoHRequest(this)) {
75 RecordReason(TRRSkippedReason::ODOH_KEY_NOT_AVAILABLE
);
81 void ODoH::HandleEncodeError(nsresult aStatusCode
) {
82 MOZ_ASSERT(NS_FAILED(aStatusCode
));
84 DNSPacketStatus status
= mPacket
->PacketStatus();
85 MOZ_ASSERT(status
!= DNSPacketStatus::Success
);
87 if (status
== DNSPacketStatus::KeyNotAvailable
) {
88 RecordReason(TRRSkippedReason::ODOH_KEY_NOT_AVAILABLE
);
89 } else if (status
== DNSPacketStatus::KeyNotUsable
) {
90 RecordReason(TRRSkippedReason::ODOH_KEY_NOT_USABLE
);
91 } else if (status
== DNSPacketStatus::EncryptError
) {
92 RecordReason(TRRSkippedReason::ODOH_ENCRYPTION_FAILED
);
94 MOZ_ASSERT_UNREACHABLE("Unexpected status code.");
98 void ODoH::HandleDecodeError(nsresult aStatusCode
) {
99 MOZ_ASSERT(NS_FAILED(aStatusCode
));
101 DNSPacketStatus status
= mPacket
->PacketStatus();
102 MOZ_ASSERT(status
!= DNSPacketStatus::Success
);
104 if (status
== DNSPacketStatus::DecryptError
) {
105 RecordReason(TRRSkippedReason::ODOH_DECRYPTION_FAILED
);
108 TRR::HandleDecodeError(aStatusCode
);
112 } // namespace mozilla