dns.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2024 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_CXX_NET_DNS_HPP
23 #define NDN_CXX_NET_DNS_HPP
24 
26 #include "ndn-cxx/util/time.hpp"
27 
28 #include <boost/asio/ip/address.hpp>
29 
30 #include <functional>
31 #include <string>
32 
33 namespace ndn::dns {
34 
35 using AddressSelector = std::function<bool(const boost::asio::ip::address&)>;
36 
37 struct AnyAddress
38 {
39  bool
40  operator()(const boost::asio::ip::address&) const
41  {
42  return true;
43  }
44 };
45 
46 struct Ipv4Only
47 {
48  bool
49  operator()(const boost::asio::ip::address& address) const
50  {
51  return address.is_v4();
52  }
53 };
54 
55 struct Ipv6Only
56 {
57  bool
58  operator()(const boost::asio::ip::address& address) const
59  {
60  return address.is_v6();
61  }
62 };
63 
64 using SuccessCallback = std::function<void(const boost::asio::ip::address& address)>;
65 using ErrorCallback = std::function<void(const std::string& reason)>;
66 
84 void
85 asyncResolve(const std::string& host,
86  const SuccessCallback& onSuccess,
87  const ErrorCallback& onError,
88  boost::asio::io_context& ioCtx,
89  const AddressSelector& addressSelector = AnyAddress(),
90  time::nanoseconds timeout = 4_s);
91 
92 } // namespace ndn::dns
93 
94 #endif // NDN_CXX_NET_DNS_HPP
Definition: dns.cpp:28
std::function< bool(const boost::asio::ip::address &)> AddressSelector
Definition: dns.hpp:35
void asyncResolve(const std::string &host, const SuccessCallback &onSuccess, const ErrorCallback &onError, boost::asio::io_context &ioCtx, const AddressSelector &addressSelector, time::nanoseconds timeout)
Asynchronously resolve host.
Definition: dns.cpp:116
std::function< void(const boost::asio::ip::address &address)> SuccessCallback
Definition: dns.hpp:64
std::function< void(const std::string &reason)> ErrorCallback
Definition: dns.hpp:65
::boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:54
bool operator()(const boost::asio::ip::address &) const
Definition: dns.hpp:40
bool operator()(const boost::asio::ip::address &address) const
Definition: dns.hpp:49
bool operator()(const boost::asio::ip::address &address) const
Definition: dns.hpp:58