From 1b89d64d4ba6819cd35badb300bdd6b786b35d4f Mon Sep 17 00:00:00 2001 From: Hevake Lee Date: Sun, 7 May 2023 18:18:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/network/dns.cpp | 0 modules/network/dns.h | 35 +++++++++++++++++++++++++++++++++ modules/network/dns_request.cpp | 1 + modules/network/dns_request.h | 5 +++-- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 modules/network/dns.cpp create mode 100644 modules/network/dns.h diff --git a/modules/network/dns.cpp b/modules/network/dns.cpp new file mode 100644 index 00000000..e69de29b diff --git a/modules/network/dns.h b/modules/network/dns.h new file mode 100644 index 00000000..7b44ec52 --- /dev/null +++ b/modules/network/dns.h @@ -0,0 +1,35 @@ +#ifndef TBOX_NETWORK_DNS_H_20230507 +#define TBOX_NETWORK_DNS_H_20230507 + +#include +#include "dns_request.h" + +namespace tbox { +namespace network { + +/// DNS +/// +/// 用于向其它模块提供IP地址查询服务 + +class Dns { + public: + explicit DnsRequest(event::Loop *wp_loop); + explicit DnsRequest(event::Loop *wp_loop, const IPAddressVec &dns_ip_vec); + virtual ~DnsRequest(); + + private: + DnsRequest dns_req_; //!< DNS请求器 + + std::map ip_address_cache_; + struct QueryInfo { + DnsRequest::ReqId req_id; + std::vector + }; + std::map ip_address_cache_; + std::map query_info_; +}; + +} +} + +#endif //TBOX_NETWORK_DNS_H_20230507 diff --git a/modules/network/dns_request.cpp b/modules/network/dns_request.cpp index d49c3f2e..416c70e8 100644 --- a/modules/network/dns_request.cpp +++ b/modules/network/dns_request.cpp @@ -209,6 +209,7 @@ void DnsRequest::onUdpRecv(const void *data_ptr, size_t data_size, const SockAdd uint8_t rcode = flags & 0x000f; Result result; + result.req_id = req_id; if (rcode == 0) { //! 正常 uint16_t qd_count, an_count, ns_count, ar_count; diff --git a/modules/network/dns_request.h b/modules/network/dns_request.h index 906d8cf8..67d7da7b 100644 --- a/modules/network/dns_request.h +++ b/modules/network/dns_request.h @@ -16,6 +16,8 @@ namespace network { /// 用于发送DNS请求,支持并行发送多个DNS清求 class DnsRequest { public: + using ReqId = uint16_t; + struct A { uint32_t ttl; IPAddress ip; @@ -37,6 +39,7 @@ class DnsRequest { kFail, //!< 其它错误 }; + ReqId req_id = 0; //!< 请求号 Status status = Status::kSuccess; //!< 结果状态 std::vector a_vec; //!< A记录列表 std::vector cname_vec; //!< CNAME记录列表 @@ -47,8 +50,6 @@ class DnsRequest { /// 请求结束回调 using Callback = std::function; - using ReqId = uint16_t; - public: explicit DnsRequest(event::Loop *wp_loop); explicit DnsRequest(event::Loop *wp_loop, const IPAddressVec &dns_ip_vec); -- Gitee