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-2021 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 namespace ndn {
31 namespace dns {
32 
33 typedef boost::asio::ip::address IpAddress;
34 typedef function<bool (const IpAddress& address)> AddressSelector;
35 
36 struct AnyAddress
37 {
38  bool
39  operator()(const IpAddress& address) const
40  {
41  return true;
42  }
43 };
44 
45 struct Ipv4Only
46 {
47  bool
48  operator()(const IpAddress& address) const
49  {
50  return address.is_v4();
51  }
52 };
53 
54 struct Ipv6Only
55 {
56  bool
57  operator()(const IpAddress& address) const
58  {
59  return address.is_v6();
60  }
61 };
62 
63 class Error : public std::runtime_error
64 {
65 public:
66  using std::runtime_error::runtime_error;
67 };
68 
69 typedef function<void (const IpAddress& address)> SuccessCallback;
70 typedef function<void (const std::string& reason)> ErrorCallback;
71 
88 void
89 asyncResolve(const std::string& host,
90  const SuccessCallback& onSuccess,
91  const ErrorCallback& onError,
92  boost::asio::io_service& ioService,
93  const AddressSelector& addressSelector = AnyAddress(),
94  time::nanoseconds timeout = 4_s);
95 
107 IpAddress
108 syncResolve(const std::string& host,
109  boost::asio::io_service& ioService,
110  const AddressSelector& addressSelector = AnyAddress());
111 
112 } // namespace dns
113 } // namespace ndn
114 
115 #endif // NDN_CXX_NET_DNS_HPP
boost::asio::ip::address IpAddress
Definition: dns.hpp:33
void asyncResolve(const std::string &host, const SuccessCallback &onSuccess, const ErrorCallback &onError, boost::asio::io_service &ioService, const AddressSelector &addressSelector, time::nanoseconds timeout)
Asynchronously resolve host.
Definition: dns.cpp:145
function< void(const IpAddress &address)> SuccessCallback
Definition: dns.hpp:69
function< bool(const IpAddress &address)> AddressSelector
Definition: dns.hpp:34
function< void(const std::string &reason)> ErrorCallback
Definition: dns.hpp:70
IpAddress syncResolve(const std::string &host, boost::asio::io_service &ioService, const AddressSelector &addressSelector)
Synchronously resolve host.
Definition: dns.cpp:158
boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:50
Definition: data.cpp:25
bool operator()(const IpAddress &address) const
Definition: dns.hpp:39
bool operator()(const IpAddress &address) const
Definition: dns.hpp:48
bool operator()(const IpAddress &address) const
Definition: dns.hpp:57