Kea: io_fetch.h Source File

| Kea 3.2.0-git

io_fetch.h
Go to the documentation of this file.
1// Copyright (C) 2010-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef IO_FETCH_H
8#define IO_FETCH_H
9
10#include <config.h>
11
12#include <asiolink/io_address.h>
13#include <asiolink/io_service.h>
14#include <dns/message.h>
15#include <dns/question.h>
16#include <util/buffer.h>
17
18#include <boost/asio/coroutine.hpp>
19#include <boost/asio/system_timer.hpp>
20#include <boost/date_time/posix_time/posix_time_types.hpp>
21#include <boost/shared_array.hpp>
22#include <boost/shared_ptr.hpp>
23#include <boost/system/error_code.hpp>
24
25namespace isc {
26namespace asiodns {
27
28// Forward declarations
29struct IOFetchData;
30
34 class IOFetch : public boost::asio::coroutine {
35public:
37 enum Protocol {
38 UDP = 0,
39 TCP = 1
40 };
41
46 enum Origin {
47 NONE = 0, // No asynchronous call outstanding
48 OPEN = 1,
49 SEND = 2,
50 RECEIVE = 3,
51 CLOSE = 4
52 };
53
59 enum Result : uint16_t {
60 SUCCESS = 0, // Success, fetch completed
61 TIME_OUT = 1, // Failure, fetch timed out
62 STOPPED = 2, // Control code, fetch has been stopped
63 NOTSET = 3, // For testing, indicates value not set
64 };
65
71 static std::string const& resultToText(Result const& result) {
72 static std::vector<std::string> const text_vector {
73 "SUCCESS",
74 "TIME_OUT",
75 "STOPPED",
76 "NOTSET",
77 };
78 static std::string const unknown("UNKNOWN");
79 return (result < text_vector.size() ? text_vector[result] : unknown);
80 }
81
84
86 enum {
87 STAGING_LENGTH = 8192 // Size of staging buffer
88 };
89
102 class Callback {
103 public:
105 Callback() = default;
106
108 virtual ~Callback() = default;
109
115 virtual void operator()(Result result) = 0;
116 };
117
137 IOFetch(Protocol protocol,
138 const isc::asiolink::IOServicePtr& service,
139 const isc::dns::Question& question,
140 const isc::asiolink::IOAddress& address,
141 uint16_t port,
142 isc::util::OutputBufferPtr& buff,
143 Callback* cb,
144 int wait = -1,
145 bool edns = true);
146
167 IOFetch(Protocol protocol,
168 const isc::asiolink::IOServicePtr& service,
169 isc::dns::ConstMessagePtr query_message,
170 const isc::asiolink::IOAddress& address,
171 uint16_t port,
172 isc::util::OutputBufferPtr& buff,
173 Callback* cb,
174 int wait = -1);
175
195 IOFetch(Protocol protocol,
196 const isc::asiolink::IOServicePtr& service,
197 isc::util::OutputBufferPtr& outpkt,
198 const isc::asiolink::IOAddress& address,
199 uint16_t port,
200 isc::util::OutputBufferPtr& buff,
201 Callback* cb,
202 int wait = -1);
203
207 Protocol getProtocol() const;
208
216 void operator()(boost::system::error_code ec = boost::system::error_code(),
217 size_t length = 0);
218
231 void stop(Result reason = STOPPED);
232
233private:
240 void initIOFetch(isc::dns::MessagePtr& query_message,
241 Protocol protocol,
242 const isc::asiolink::IOServicePtr& service,
243 const isc::dns::Question& question,
244 const isc::asiolink::IOAddress& address,
245 uint16_t port,
246 isc::util::OutputBufferPtr& buff,
247 Callback* cb, int wait,
248 bool edns = true);
249
255 void logIOFailure(boost::system::error_code ec);
256
260 boost::shared_ptr<IOFetchData> data_;
261};
262
264 typedef boost::shared_ptr<IOFetch> IOFetchPtr;
265
266} // namespace asiodns
267} // namespace isc
268
269#endif // IO_FETCH_H
buffer.h
isc::asiodns::IOFetch::Callback
I/O Fetch Callback.
Definition io_fetch.h:102
isc::asiodns::IOFetch::Callback::operator()
virtual void operator()(Result result)=0
Callback method.
isc::asiodns::IOFetch::Callback::~Callback
virtual ~Callback()=default
Destructor.
isc::asiodns::IOFetch::Callback::Callback
Callback()=default
Constructor.
isc::asiodns::IOFetch::resultToText
static std::string const & resultToText(Result const &result)
Convert enum to string.
Definition io_fetch.h:71
isc::asiodns::IOFetch::Result
Result
Result of Upstream Fetch.
Definition io_fetch.h:59
isc::asiodns::IOFetch::NOTSET
@ NOTSET
Definition io_fetch.h:63
isc::asiodns::IOFetch::STOPPED
@ STOPPED
Definition io_fetch.h:62
isc::asiodns::IOFetch::TIME_OUT
@ TIME_OUT
Definition io_fetch.h:61
isc::asiodns::IOFetch::SUCCESS
@ SUCCESS
Definition io_fetch.h:60
isc::asiodns::IOFetch::IOFetch
IOFetch(Protocol protocol, const isc::asiolink::IOServicePtr &service, const isc::dns::Question &question, const isc::asiolink::IOAddress &address, uint16_t port, isc::util::OutputBufferPtr &buff, Callback *cb, int wait=-1, bool edns=true)
Constructor.
Definition io_fetch.cc:143
isc::asiodns::IOFetch::operator()
void operator()(boost::system::error_code ec=boost::system::error_code(), size_t length=0)
Coroutine entry point.
Definition io_fetch.cc:202
isc::asiodns::IOFetch::Origin
Origin
Origin of Asynchronous I/O Call.
Definition io_fetch.h:46
isc::asiodns::IOFetch::SEND
@ SEND
Definition io_fetch.h:49
isc::asiodns::IOFetch::RECEIVE
@ RECEIVE
Definition io_fetch.h:50
isc::asiodns::IOFetch::OPEN
@ OPEN
Definition io_fetch.h:48
isc::asiodns::IOFetch::CLOSE
@ CLOSE
Definition io_fetch.h:51
isc::asiodns::IOFetch::NONE
@ NONE
Definition io_fetch.h:47
isc::asiodns::IOFetch::Protocol
Protocol
Protocol to use on the fetch.
Definition io_fetch.h:37
isc::asiodns::IOFetch::TCP
@ TCP
Definition io_fetch.h:39
isc::asiodns::IOFetch::UDP
@ UDP
Definition io_fetch.h:38
isc::asiodns::IOFetch::stop
void stop(Result reason=STOPPED)
Terminate query.
Definition io_fetch.cc:297
isc::asiodns::IOFetch::getProtocol
Protocol getProtocol() const
Return Current Protocol.
Definition io_fetch.cc:197
isc::asiodns::IOFetch::STAGING_LENGTH
@ STAGING_LENGTH
Definition io_fetch.h:87
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:53
isc::dns::Question
The Question class encapsulates the common search key of DNS lookup, consisting of owner name,...
Definition question.h:88
io_address.h
io_service.h
message.h
isc::asiodns
Definition asiodns_messages.cc:8
isc::asiodns::IOFetchPtr
boost::shared_ptr< IOFetch > IOFetchPtr
Defines a pointer to an IOFetch.
Definition io_fetch.h:264
isc::asiolink::IOServicePtr
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
Definition io_service.h:35
isc::cb
Definition base_config_backend.h:18
isc::dns::ConstMessagePtr
boost::shared_ptr< const Message > ConstMessagePtr
Definition message.h:671
isc::dns::MessagePtr
boost::shared_ptr< Message > MessagePtr
Pointer-like type pointing to a Message.
Definition message.h:670
isc::util::OutputBufferPtr
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Type of pointers to output buffers.
Definition buffer.h:574
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
question.h
isc::asiodns::IOFetchData
IOFetch Data.
Definition io_fetch.cc:59