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