• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 #ifndef OHOS_DHCP_DNS_REPOSITORY_H
16 #define OHOS_DHCP_DNS_REPOSITORY_H
17 #include <string>
18 #include <vector>
19 #include <unordered_set>
20 #include <mutex>
21 #include "dhcp_ipv6_define.h"
22 #include "dhcp_ipv6_info.h"
23 namespace OHOS {
24 namespace DHCP {
25 class DnsServerRepository {
26 private:
27     static const int NUM_CURRENT_SERVERS = 3;
28     static const int NUM_SERVERS = 12;
29     static const int DEFAULT_MIN_RDNSS_LIFETIME = 120;
30     std::unordered_set<std::string> currentServers_;  // curent use server
31     std::vector<DnsServerEntry> allServers_;          // all existing server
32     uint32_t minLifetime_ = DEFAULT_MIN_RDNSS_LIFETIME;
33     std::mutex mutex;
34 
35 public:
36     DnsServerRepository(int minLifeTime = DEFAULT_MIN_RDNSS_LIFETIME);
37     ~DnsServerRepository();
38     bool Clear(); // clear all dns server info
39     bool AddServers(uint32_t lifetime, const std::vector<std::string>& addresses);  // add new dns server info
40     bool SetCurrentServers(DhcpIpv6Info &ipv6Info); //set current servers to ipv6Info
41 private:
42     bool UpdateExistingEntry(const std::string& address, uint64_t expiry);
43     bool UpdateCurrentServers();
44 };
45 }
46 }
47 #endif