Kea 3.1.5
io_fetch.h
Go to the documentation of this file.
1// Copyright (C) 2010-2025 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/deadline_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
34class 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,
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,
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,
173 Callback* cb,
174 int wait = -1);
175
195 IOFetch(Protocol protocol,
196 const isc::asiolink::IOServicePtr& service,
198 const isc::asiolink::IOAddress& address,
199 uint16_t port,
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,
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
264typedef boost::shared_ptr<IOFetch> IOFetchPtr;
265
266} // namespace asiodns
267} // namespace isc
268
269#endif // IO_FETCH_H
I/O Fetch Callback.
Definition io_fetch.h:102
virtual void operator()(Result result)=0
Callback method.
virtual ~Callback()=default
Destructor.
Callback()=default
Constructor.
static std::string const & resultToText(Result const &result)
Convert enum to string.
Definition io_fetch.h:71
Result
Result of Upstream Fetch.
Definition io_fetch.h:59
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:142
void operator()(boost::system::error_code ec=boost::system::error_code(), size_t length=0)
Coroutine entry point.
Definition io_fetch.cc:201
Origin
Origin of Asynchronous I/O Call.
Definition io_fetch.h:46
Protocol
Protocol to use on the fetch.
Definition io_fetch.h:37
void stop(Result reason=STOPPED)
Terminate query.
Definition io_fetch.cc:296
Protocol getProtocol() const
Return Current Protocol.
Definition io_fetch.cc:196
The Question class encapsulates the common search key of DNS lookup, consisting of owner name,...
Definition question.h:88
boost::shared_ptr< IOFetch > IOFetchPtr
Defines a pointer to an IOFetch.
Definition io_fetch.h:264
boost::shared_ptr< const Message > ConstMessagePtr
Definition message.h:671
boost::shared_ptr< Message > MessagePtr
Pointer-like type pointing to a Message.
Definition message.h:670
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Type of pointers to output buffers.
Definition buffer.h:574
Defines the logger used by the top-level component of kea-lfc.