Sese Framework
x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
DnsService.h
浏览该文件的文档.
1
// Copyright 2024 libsese
2
//
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
19
20
#pragma once
21
22
#include <
sese/service/Service.h
>
23
#include <
sese/service/dns/Config.h
>
24
#include <
sese/net/dns/Resolver.h
>
25
#include <
sese/net/dns/DnsPackage.h
>
26
#include <
sese/thread/Thread.h
>
27
28
#include <asio.hpp>
29
30
namespace
sese::internal::net::service::dns
{
31
33
class
DnsService
final :
public
sese::service::Service
{
34
asio::io_service
io_service
;
35
asio::ip::udp::socket
socket
;
36
asio::error_code
error
;
37
std::array<uint8_t, 512>
buffer
;
38
sese::net::dns::Resolver
resolver
;
39
Thread::Ptr
thread
;
40
std::atomic_bool
running
;
41
42
std::map<std::string, sese::net::IPv4Address::Ptr>
v4map
;
43
std::map<std::string, sese::net::IPv6Address::Ptr>
v6map
;
44
45
void
handleBySelf
(
46
std::vector<sese::net::dns::DnsPackage::Question> &questions,
47
sese::net::dns::DnsPackage::Ptr
&send_package
48
);
49
50
void
handleByUpstream
(
51
std::vector<sese::net::dns::DnsPackage::Question> &questions,
52
sese::net::dns::DnsPackage::Ptr
&send_package
53
);
54
55
void
handle
();
56
57
public
:
58
60
DnsService
();
61
65
bool
bind
(
const
sese::net::IPAddress::Ptr
&address);
66
69
void
setCallback
(
const
sese::service::dns::Callback
&
callback
);
70
73
void
addUpstreamNameServer
(
const
sese::net::IPAddress::Ptr
&address);
74
79
bool
addUpstreamNameServer
(
const
std::string &ip, uint16_t port = 53);
80
84
void
addRecord
(
const
std::string &name,
const
sese::net::IPAddress::Ptr
&address);
85
88
bool
startup
()
override
;
89
92
bool
shutdown
()
override
;
93
96
int
getLastError
()
override
;
97
100
std::string
getLastErrorMessage
()
override
;
101
102
private
:
103
sese::service::dns::Callback
callback
;
104
};
105
106
}
// namespace sese::internal::net::service::dns
sese
internal
service
dns
DnsService.h
生成于 2024年 十一月 4日 星期一 09:58:00 , 为 Sese Framework使用
1.11.0