• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "dns_resolv_config.h"
17 
18 namespace OHOS::nmd {
DelayedTaskWrapper(std::string hostName,NetManagerStandard::LRUCache<AddrInfo> & cache)19 DnsResolvConfig::DelayedTaskWrapper::DelayedTaskWrapper(std::string hostName,
20                                                         NetManagerStandard::LRUCache<AddrInfo> &cache)
21     : hostName_(std::move(hostName)), cache_(cache)
22 {
23 }
24 
Execute() const25 void DnsResolvConfig::DelayedTaskWrapper::Execute() const
26 {
27     cache_.Delete(hostName_);
28 }
29 
operator <(const DelayedTaskWrapper & other) const30 bool DnsResolvConfig::DelayedTaskWrapper::operator<(const DelayedTaskWrapper &other) const
31 {
32     return hostName_ < other.hostName_;
33 }
34 
DnsResolvConfig()35 DnsResolvConfig::DnsResolvConfig() : netId_(0), netIdIsSet_(false), revisionId_(0), timeoutMsec_(0), retryCount_(0) {}
36 
SetNetId(uint16_t netId)37 void DnsResolvConfig::SetNetId(uint16_t netId)
38 {
39     if (netIdIsSet_) {
40         return;
41     }
42     netIdIsSet_ = true;
43     netId_ = netId;
44 }
45 
GetNetId() const46 uint16_t DnsResolvConfig::GetNetId() const
47 {
48     return netId_;
49 }
50 
SetTimeoutMsec(int32_t baseTimeoutMsec)51 void DnsResolvConfig::SetTimeoutMsec(int32_t baseTimeoutMsec)
52 {
53     timeoutMsec_ = baseTimeoutMsec;
54 }
55 
GetTimeoutMsec() const56 uint16_t DnsResolvConfig::GetTimeoutMsec() const
57 {
58     return timeoutMsec_;
59 }
60 
SetRetryCount(uint8_t retryCount)61 void DnsResolvConfig::SetRetryCount(uint8_t retryCount)
62 {
63     retryCount_ = retryCount;
64 }
65 
GetRetryCount() const66 uint8_t DnsResolvConfig::GetRetryCount() const
67 {
68     return retryCount_;
69 }
70 
SetServers(const std::vector<std::string> & servers)71 void DnsResolvConfig::SetServers(const std::vector<std::string> &servers)
72 {
73     nameServers_ = servers;
74     revisionId_++;
75 }
76 
GetServers() const77 std::vector<std::string> DnsResolvConfig::GetServers() const
78 {
79     return nameServers_;
80 }
81 
SetDomains(const std::vector<std::string> & domains)82 void DnsResolvConfig::SetDomains(const std::vector<std::string> &domains)
83 {
84     searchDomains_ = domains;
85 }
86 
GetDomains() const87 std::vector<std::string> DnsResolvConfig::GetDomains() const
88 {
89     return searchDomains_;
90 }
91 
GetCache()92 NetManagerStandard::LRUCache<AddrInfo> &DnsResolvConfig::GetCache()
93 {
94     return cache_;
95 }
96 
SetCacheDelayed(const std::string & hostName)97 void DnsResolvConfig::SetCacheDelayed(const std::string &hostName)
98 {
99     delayedQueue_.Put(DelayedTaskWrapper(hostName, cache_));
100 }
101 } // namespace OHOS::nmd
102