• 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 #ifndef INCLUDE_MANAGER_DNS_MANAGER_H
17 #define INCLUDE_MANAGER_DNS_MANAGER_H
18 
19 #include <vector>
20 
21 #include "dns_getaddrinfo.h"
22 #include "dns_param_cache.h"
23 #include "dns_proxy_listen.h"
24 #include "i_net_dns_result_callback.h"
25 #include "i_net_dns_health_callback.h"
26 
27 namespace OHOS {
28 namespace nmd {
29 class DnsManager {
30 public:
31     DnsManager();
32     ~DnsManager() = default;
33 
34     /**
35      * Set the Resolver Config object
36      *
37      * @param netId network ID
38      * @param baseTimeoutMillis base Timeout Ms, default 5000
39      * @param retryCount retry Count, default 2
40      * @param servers server name set in config
41      * @param domains domain set in config
42      * @return int32_t 0:success -1:failed
43      */
44     int32_t SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMillis, uint8_t retryCount,
45                               const std::vector<std::string> &servers, const std::vector<std::string> &domains);
46 
47     /**
48      * Get the Resolver Config object
49      *
50      * @param netId network ID
51      * @param servers return value server name
52      * @param domains return value doamin
53      * @param baseTimeoutMillis return value Timeout Ms
54      * @param retryCount return value retry Count
55      * @return int32_t 0:success -1:failed
56      */
57     int32_t GetResolverConfig(uint16_t netId, std::vector<std::string> &servers, std::vector<std::string> &domains,
58                               uint16_t &baseTimeoutMillis, uint8_t &retryCount);
59 
60     /**
61      * Create a Network Cache object
62      *
63      * @param netId network ID
64      * @return int32_t 0:success -1:failed
65      */
66     int32_t CreateNetworkCache(uint16_t netId);
67 
68     /**
69      * Set the Default Network object
70      *
71      * @param netId network ID
72      */
73     void SetDefaultNetwork(uint16_t netId);
74 
75     /**
76      * Network share set netId
77      *
78      * @param netId network ID
79      */
80     void ShareDnsSet(uint16_t netId);
81 
82     /**
83      * Start Dns proxy for network share
84      *
85      */
86     void StartDnsProxyListen();
87 
88     /**
89      * Stop Dns proxy for network share
90      *
91      */
92     void StopDnsProxyListen();
93 
94     /**
95      * Get the Dump Info object, this is for dump.
96      *
97      * @param info Infos for dump
98      */
99     void GetDumpInfo(std::string &info);
100 
101     /**
102      * dns resolution object
103      *
104      * @param node hostname
105      * @param service service name
106      * @param hints limit
107      * @param result return value
108      * @param netId network id
109      * @return int32_t  0 is success -1 is failed
110      */
111     int32_t GetAddrInfo(const std::string &hostName, const std::string &serverName, const AddrInfo &hints,
112                         uint16_t netId, std::vector<AddrInfo> &res);
113 
114     /**
115      * destroy this netid's cache
116      * @param netId network's id
117      * @return destroy is success? 0 : -1
118      */
119     int32_t DestroyNetworkCache(uint16_t netId);
120 
121     void EnableIpv6(uint16_t netId, std::string &destination, const std::string &nextHop);
122 
123     int32_t RegisterDnsResultCallback(const sptr<NetsysNative::INetDnsResultCallback> &callback, uint32_t timeStep);
124     int32_t UnregisterDnsResultCallback(const sptr<NetsysNative::INetDnsResultCallback> &callback);
125     int32_t RegisterDnsHealthCallback(const sptr<NetsysNative::INetDnsHealthCallback> &callback);
126     int32_t UnregisterDnsHealthCallback(const sptr<NetsysNative::INetDnsHealthCallback> &callback);
127 
128 private:
129     std::shared_ptr<DnsProxyListen> dnsProxyListen_;
130     std::shared_ptr<DnsGetAddrInfo> dnsGetAddrInfo_;
131     int32_t FillAddrInfo(std::vector<AddrInfo> &addrInfo, addrinfo *res);
132 };
133 } // namespace nmd
134 } // namespace OHOS
135 #endif // INCLUDE_MANAGER_DNS_MANAGER_H
136