Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 2ed9e07 | 2017-08-13 16:45:48 +0000 | [diff] [blame] | 2 | /* |
Junxiao Shi | 68b5385 | 2018-07-25 13:56:38 -0600 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Jeff Thompson | b9e3c8e | 2013-08-02 11:42:51 -0700 | [diff] [blame] | 22 | #ifndef NDN_FACE_HPP |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 23 | #define NDN_FACE_HPP |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 24 | |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 25 | #include "data.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 26 | #include "name.hpp" |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 27 | #include "interest.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 28 | #include "interest-filter.hpp" |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame] | 29 | #include "encoding/nfd-constants.hpp" |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 30 | #include "lp/nack.hpp" |
Davide Pesavento | 4d0d096 | 2017-12-19 22:23:14 -0500 | [diff] [blame] | 31 | #include "net/asio-fwd.hpp" |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame] | 32 | #include "security/key-chain.hpp" |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 33 | #include "security/signing-info.hpp" |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 34 | |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 35 | namespace ndn { |
| 36 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 37 | class Transport; |
| 38 | |
| 39 | class PendingInterestId; |
| 40 | class RegisteredPrefixId; |
| 41 | class InterestFilterId; |
| 42 | |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 43 | namespace nfd { |
| 44 | class Controller; |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 45 | } // namespace nfd |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 46 | |
Jeff Thompson | fe08e5a | 2013-08-13 11:15:59 -0700 | [diff] [blame] | 47 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 48 | * @brief Callback invoked when expressed Interest gets satisfied with a Data packet |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 49 | */ |
| 50 | typedef function<void(const Interest&, const Data&)> DataCallback; |
| 51 | |
| 52 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 53 | * @brief Callback invoked when Nack is sent in response to expressed Interest |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 54 | */ |
| 55 | typedef function<void(const Interest&, const lp::Nack&)> NackCallback; |
| 56 | |
| 57 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 58 | * @brief Callback invoked when expressed Interest times out |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 59 | */ |
| 60 | typedef function<void(const Interest&)> TimeoutCallback; |
| 61 | |
| 62 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 63 | * @brief Callback invoked when incoming Interest matches the specified InterestFilter |
| 64 | */ |
| 65 | typedef function<void(const InterestFilter&, const Interest&)> InterestCallback; |
| 66 | |
| 67 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 68 | * @brief Callback invoked when registerPrefix or setInterestFilter command succeeds |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 69 | */ |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 70 | typedef function<void(const Name&)> RegisterPrefixSuccessCallback; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 71 | |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 72 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 73 | * @brief Callback invoked when registerPrefix or setInterestFilter command fails |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 74 | */ |
| 75 | typedef function<void(const Name&, const std::string&)> RegisterPrefixFailureCallback; |
| 76 | |
| 77 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 78 | * @brief Callback invoked when unregisterPrefix or unsetInterestFilter command succeeds |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 79 | */ |
| 80 | typedef function<void()> UnregisterPrefixSuccessCallback; |
| 81 | |
| 82 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 83 | * @brief Callback invoked when unregisterPrefix or unsetInterestFilter command fails |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 84 | */ |
| 85 | typedef function<void(const std::string&)> UnregisterPrefixFailureCallback; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 86 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 87 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 88 | * @brief Provide a communication channel with local or remote NDN forwarder |
Jeff Thompson | fe08e5a | 2013-08-13 11:15:59 -0700 | [diff] [blame] | 89 | */ |
Alexander Afanasyev | 8460afb | 2014-02-15 20:31:42 -0800 | [diff] [blame] | 90 | class Face : noncopyable |
| 91 | { |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 92 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 93 | class Error : public std::runtime_error |
| 94 | { |
| 95 | public: |
Junxiao Shi | 68b5385 | 2018-07-25 13:56:38 -0600 | [diff] [blame] | 96 | using std::runtime_error::runtime_error; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 97 | }; |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 98 | |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 99 | /** |
| 100 | * @brief Exception thrown when attempting to send a packet over size limit |
| 101 | */ |
| 102 | class OversizedPacketError : public Error |
| 103 | { |
| 104 | public: |
| 105 | /** |
| 106 | * @brief Constructor |
| 107 | * @param pktType packet type, 'I' for Interest, 'D' for Data, 'N' for Nack |
| 108 | * @param name packet name |
| 109 | * @param wireSize wire encoding size |
| 110 | */ |
| 111 | OversizedPacketError(char pktType, const Name& name, size_t wireSize); |
| 112 | |
| 113 | public: |
| 114 | const char pktType; |
| 115 | const Name name; |
| 116 | const size_t wireSize; |
| 117 | }; |
| 118 | |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 119 | public: // constructors |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 120 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 121 | * @brief Create Face using given transport (or default transport if omitted) |
| 122 | * @param transport the transport for lower layer communication. If nullptr, |
| 123 | * a default transport will be used. The default transport is |
| 124 | * determined from a FaceUri in NDN_CLIENT_TRANSPORT environ, |
| 125 | * a FaceUri in configuration file 'transport' key, or UnixTransport. |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 126 | * |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 127 | * @throw ConfigFile::Error @p transport is nullptr, and the configuration file cannot be |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 128 | * parsed or specifies an unsupported protocol |
| 129 | * @note shared_ptr is passed by value because ownership is shared with this class |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 130 | */ |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 131 | explicit |
| 132 | Face(shared_ptr<Transport> transport = nullptr); |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 133 | |
| 134 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 135 | * @brief Create Face using default transport and given io_service |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 136 | * |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 137 | * Usage examples: |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 138 | * |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 139 | * @code |
| 140 | * Face face1; |
| 141 | * Face face2(face1.getIoService()); |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 142 | * |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 143 | * // Now the following ensures that events on both faces are processed |
| 144 | * face1.processEvents(); |
| 145 | * // or face1.getIoService().run(); |
| 146 | * @endcode |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 147 | * |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 148 | * or |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 149 | * |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 150 | * @code |
| 151 | * boost::asio::io_service ioService; |
| 152 | * Face face1(ioService); |
| 153 | * Face face2(ioService); |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 154 | * |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 155 | * ioService.run(); |
| 156 | * @endcode |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 157 | * |
| 158 | * @param ioService A reference to boost::io_service object that should control all |
| 159 | * IO operations. |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 160 | * @throw ConfigFile::Error the configuration file cannot be parsed or specifies an unsupported protocol |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 161 | */ |
| 162 | explicit |
| 163 | Face(boost::asio::io_service& ioService); |
| 164 | |
| 165 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 166 | * @brief Create Face using TcpTransport |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 167 | * |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 168 | * @param host IP address or hostname of the NDN forwarder |
| 169 | * @param port port number or service name of the NDN forwarder (**default**: "6363") |
Jeff Thompson | fe08e5a | 2013-08-13 11:15:59 -0700 | [diff] [blame] | 170 | */ |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 171 | explicit |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 172 | Face(const std::string& host, const std::string& port = "6363"); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 173 | |
| 174 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 175 | * @brief Create Face using given transport and KeyChain |
| 176 | * @param transport the transport for lower layer communication. If nullptr, |
| 177 | * a default transport will be used. |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 178 | * @param keyChain the KeyChain to sign commands |
| 179 | * |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 180 | * @sa Face(shared_ptr<Transport>) |
| 181 | * |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 182 | * @throw ConfigFile::Error @p transport is nullptr, and the configuration file cannot be |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 183 | * parsed or specifies an unsupported protocol |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 184 | * @note shared_ptr is passed by value because ownership is shared with this class |
| 185 | */ |
| 186 | Face(shared_ptr<Transport> transport, KeyChain& keyChain); |
| 187 | |
| 188 | /** |
Eric Newberry | 3306339 | 2018-06-23 01:59:36 -0700 | [diff] [blame] | 189 | * @brief Create Face using given transport and io_service |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 190 | * @param transport the transport for lower layer communication. If nullptr, |
| 191 | * a default transport will be used. |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 192 | * @param ioService the io_service that controls all IO operations |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 193 | * |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 194 | * @sa Face(boost::asio::io_service&) |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 195 | * @sa Face(shared_ptr<Transport>) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 196 | * |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 197 | * @throw ConfigFile::Error @p transport is nullptr, and the configuration file cannot be |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 198 | * parsed or specifies an unsupported protocol |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 199 | * @note shared_ptr is passed by value because ownership is shared with this class |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 200 | */ |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 201 | Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService); |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 202 | |
Jeff Thompson | 4fe4551 | 2013-08-23 14:06:38 -0700 | [diff] [blame] | 203 | /** |
Eric Newberry | 3306339 | 2018-06-23 01:59:36 -0700 | [diff] [blame] | 204 | * @brief Create a new Face using given Transport and io_service |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 205 | * @param transport the transport for lower layer communication. If nullptr, |
| 206 | * a default transport will be used. |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 207 | * @param ioService the io_service that controls all IO operations |
| 208 | * @param keyChain the KeyChain to sign commands |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 209 | * |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 210 | * @sa Face(boost::asio::io_service&) |
| 211 | * @sa Face(shared_ptr<Transport>, KeyChain&) |
| 212 | * |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 213 | * @throw ConfigFile::Error @p transport is nullptr, and the configuration file cannot be |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 214 | * parsed or specifies an unsupported protocol |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 215 | * @note shared_ptr is passed by value because ownership is shared with this class |
| 216 | */ |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 217 | Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, KeyChain& keyChain); |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 218 | |
Davide Pesavento | 7f20d6e | 2017-01-16 14:43:58 -0500 | [diff] [blame] | 219 | virtual |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 220 | ~Face(); |
| 221 | |
| 222 | public: // consumer |
| 223 | /** |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 224 | * @brief Express Interest |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 225 | * @param interest the Interest; a copy will be made, so that the caller is not |
| 226 | * required to maintain the argument unchanged |
| 227 | * @param afterSatisfied function to be invoked if Data is returned |
| 228 | * @param afterNacked function to be invoked if Network NACK is returned |
| 229 | * @param afterTimeout function to be invoked if neither Data nor Network NACK |
| 230 | * is returned within InterestLifetime |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 231 | * @throw OversizedPacketError encoded Interest size exceeds MAX_NDN_PACKET_SIZE |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 232 | */ |
| 233 | const PendingInterestId* |
| 234 | expressInterest(const Interest& interest, |
| 235 | const DataCallback& afterSatisfied, |
| 236 | const NackCallback& afterNacked, |
| 237 | const TimeoutCallback& afterTimeout); |
| 238 | |
| 239 | /** |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 240 | * @brief Cancel previously expressed Interest |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 241 | * |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 242 | * @param pendingInterestId The ID returned from expressInterest. |
| 243 | */ |
| 244 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 245 | removePendingInterest(const PendingInterestId* pendingInterestId); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 246 | |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 247 | /** |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 248 | * @brief Cancel all previously expressed Interests |
| 249 | */ |
| 250 | void |
| 251 | removeAllPendingInterests(); |
| 252 | |
| 253 | /** |
Alexander Afanasyev | 6fcdde2 | 2014-08-22 19:03:36 -0700 | [diff] [blame] | 254 | * @brief Get number of pending Interests |
| 255 | */ |
| 256 | size_t |
| 257 | getNPendingInterests() const; |
| 258 | |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 259 | public: // producer |
Alexander Afanasyev | 6fcdde2 | 2014-08-22 19:03:36 -0700 | [diff] [blame] | 260 | /** |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 261 | * @brief Set InterestFilter to dispatch incoming matching interest to onInterest |
| 262 | * callback and register the filtered prefix with the connected NDN forwarder |
| 263 | * |
| 264 | * This version of setInterestFilter combines setInterestFilter and registerPrefix |
| 265 | * operations and is intended to be used when only one filter for the same prefix needed |
| 266 | * to be set. When multiple names sharing the same prefix should be dispatched to |
| 267 | * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by |
| 268 | * a series of setInterestFilter calls. |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 269 | * |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 270 | * @param interestFilter Interest filter (prefix part will be registered with the forwarder) |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 271 | * @param onInterest A callback to be called when a matching interest is received |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 272 | * @param onFailure A callback to be called when prefixRegister command fails |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 273 | * @param flags (optional) RIB flags |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 274 | * @param signingInfo (optional) Signing parameters. When omitted, a default parameters |
| 275 | * used in the signature will be used. |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 276 | * |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 277 | * @return Opaque registered prefix ID which can be used with unsetInterestFilter or |
| 278 | * removeRegisteredPrefix |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 279 | */ |
| 280 | const RegisteredPrefixId* |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 281 | setInterestFilter(const InterestFilter& interestFilter, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 282 | const InterestCallback& onInterest, |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 283 | const RegisterPrefixFailureCallback& onFailure, |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 284 | const security::SigningInfo& signingInfo = security::SigningInfo(), |
Alexander Afanasyev | 0866f51 | 2014-08-11 13:25:09 -0700 | [diff] [blame] | 285 | uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT); |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 286 | |
| 287 | /** |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 288 | * @brief Set InterestFilter to dispatch incoming matching interest to onInterest |
| 289 | * callback and register the filtered prefix with the connected NDN forwarder |
| 290 | * |
| 291 | * This version of setInterestFilter combines setInterestFilter and registerPrefix |
| 292 | * operations and is intended to be used when only one filter for the same prefix needed |
| 293 | * to be set. When multiple names sharing the same prefix should be dispatched to |
| 294 | * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by |
| 295 | * a series of setInterestFilter calls. |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 296 | * |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 297 | * @param interestFilter Interest filter (prefix part will be registered with the forwarder) |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 298 | * @param onInterest A callback to be called when a matching interest is received |
| 299 | * @param onSuccess A callback to be called when prefixRegister command succeeds |
| 300 | * @param onFailure A callback to be called when prefixRegister command fails |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 301 | * @param flags (optional) RIB flags |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 302 | * @param signingInfo (optional) Signing parameters. When omitted, a default parameters |
| 303 | * used in the signature will be used. |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 304 | * |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 305 | * @return Opaque registered prefix ID which can be used with unsetInterestFilter or |
| 306 | * removeRegisteredPrefix |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 307 | */ |
| 308 | const RegisteredPrefixId* |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 309 | setInterestFilter(const InterestFilter& interestFilter, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 310 | const InterestCallback& onInterest, |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 311 | const RegisterPrefixSuccessCallback& onSuccess, |
| 312 | const RegisterPrefixFailureCallback& onFailure, |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 313 | const security::SigningInfo& signingInfo = security::SigningInfo(), |
Alexander Afanasyev | 0866f51 | 2014-08-11 13:25:09 -0700 | [diff] [blame] | 314 | uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 315 | |
| 316 | /** |
| 317 | * @brief Set InterestFilter to dispatch incoming matching interest to onInterest callback |
| 318 | * |
| 319 | * @param interestFilter Interest |
| 320 | * @param onInterest A callback to be called when a matching interest is received |
| 321 | * |
| 322 | * This method modifies library's FIB only, and does not register the prefix with the |
| 323 | * forwarder. It will always succeed. To register prefix with the forwarder, use |
| 324 | * registerPrefix, or use the setInterestFilter overload taking two callbacks. |
| 325 | * |
| 326 | * @return Opaque interest filter ID which can be used with unsetInterestFilter |
| 327 | */ |
| 328 | const InterestFilterId* |
| 329 | setInterestFilter(const InterestFilter& interestFilter, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 330 | const InterestCallback& onInterest); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 331 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 332 | /** |
| 333 | * @brief Register prefix with the connected NDN forwarder |
| 334 | * |
| 335 | * This method only modifies forwarder's RIB and does not associate any |
| 336 | * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to |
| 337 | * the right callbacks. |
| 338 | * |
| 339 | * @param prefix A prefix to register with the connected NDN forwarder |
| 340 | * @param onSuccess A callback to be called when prefixRegister command succeeds |
| 341 | * @param onFailure A callback to be called when prefixRegister command fails |
| 342 | * @param signingInfo (optional) Signing parameters. When omitted, a default parameters |
| 343 | * used in the signature will be used. |
Alexander Afanasyev | f2a4622 | 2015-09-17 18:01:30 -0700 | [diff] [blame] | 344 | * @param flags Prefix registration flags |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 345 | * |
| 346 | * @return The registered prefix ID which can be used with unregisterPrefix |
Alexander Afanasyev | f2a4622 | 2015-09-17 18:01:30 -0700 | [diff] [blame] | 347 | * @see nfd::RouteFlags |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 348 | */ |
| 349 | const RegisteredPrefixId* |
| 350 | registerPrefix(const Name& prefix, |
| 351 | const RegisterPrefixSuccessCallback& onSuccess, |
| 352 | const RegisterPrefixFailureCallback& onFailure, |
| 353 | const security::SigningInfo& signingInfo = security::SigningInfo(), |
| 354 | uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 355 | |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 356 | /** |
Alexander Afanasyev | 1b01c31 | 2014-05-26 16:58:10 +0300 | [diff] [blame] | 357 | * @brief Remove the registered prefix entry with the registeredPrefixId |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 358 | * |
| 359 | * This does not affect another registered prefix with a different registeredPrefixId, |
| 360 | * even it if has the same prefix name. If there is no entry with the |
| 361 | * registeredPrefixId, do nothing. |
| 362 | * |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 363 | * unsetInterestFilter will use the same credentials as original |
| 364 | * setInterestFilter/registerPrefix command |
| 365 | * |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 366 | * @param registeredPrefixId The ID returned from registerPrefix |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 367 | */ |
| 368 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 369 | unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId); |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 370 | |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 371 | /** |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 372 | * @brief Remove previously set InterestFilter from library's FIB |
| 373 | * |
| 374 | * This method always succeeds and will **NOT** send any request to the connected |
| 375 | * forwarder. |
| 376 | * |
| 377 | * @param interestFilterId The ID returned from setInterestFilter. |
| 378 | */ |
| 379 | void |
| 380 | unsetInterestFilter(const InterestFilterId* interestFilterId); |
| 381 | |
| 382 | /** |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 383 | * @brief Unregister prefix from RIB |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 384 | * |
| 385 | * unregisterPrefix will use the same credentials as original |
| 386 | * setInterestFilter/registerPrefix command |
| 387 | * |
| 388 | * If registeredPrefixId was obtained using setInterestFilter, the corresponding |
| 389 | * InterestFilter will be unset too. |
| 390 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 391 | * @param registeredPrefixId The ID returned from registerPrefix |
| 392 | * @param onSuccess Callback to be called when operation succeeds |
| 393 | * @param onFailure Callback to be called when operation fails |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 394 | */ |
| 395 | void |
| 396 | unregisterPrefix(const RegisteredPrefixId* registeredPrefixId, |
| 397 | const UnregisterPrefixSuccessCallback& onSuccess, |
| 398 | const UnregisterPrefixFailureCallback& onFailure); |
| 399 | |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 400 | /** |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 401 | * @brief Publish data packet |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 402 | * @param data the Data; a copy will be made, so that the caller is not required to |
| 403 | * maintain the argument unchanged |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 404 | * |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 405 | * This method can be called to satisfy incoming Interests, or to add Data packet into the cache |
| 406 | * of the local NDN forwarder if forwarder is configured to accept unsolicited Data. |
Alexander Afanasyev | 6a05b4b | 2014-07-18 17:23:00 -0700 | [diff] [blame] | 407 | * |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 408 | * @throw OversizedPacketError encoded Data size exceeds MAX_NDN_PACKET_SIZE |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 409 | */ |
| 410 | void |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 411 | put(Data data); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 412 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 413 | /** |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 414 | * @brief Send a network NACK |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 415 | * @param nack the Nack; a copy will be made, so that the caller is not required to |
| 416 | * maintain the argument unchanged |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 417 | * @throw OversizedPacketError encoded Nack size exceeds MAX_NDN_PACKET_SIZE |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 418 | */ |
| 419 | void |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 420 | put(lp::Nack nack); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 421 | |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 422 | public: // IO routine |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 423 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 424 | * @brief Process any data to receive or call timeout callbacks. |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 425 | * |
| 426 | * This call will block forever (default timeout == 0) to process IO on the face. |
Eric Newberry | 3306339 | 2018-06-23 01:59:36 -0700 | [diff] [blame] | 427 | * To exit cleanly on a producer, unset any Interest filters with unsetInterestFilter() and wait |
| 428 | * for processEvents() to return. To exit after an error, one can call shutdown(). |
| 429 | * In consumer applications, processEvents() will return when all expressed Interests have been |
| 430 | * satisfied, Nacked, or timed out. To terminate earlier, a consumer application should call |
| 431 | * removePendingInterests() for all previously expressed and still-pending Interests. |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 432 | * |
Eric Newberry | 3306339 | 2018-06-23 01:59:36 -0700 | [diff] [blame] | 433 | * If a positive timeout is specified, then processEvents() will exit after this timeout, provided |
| 434 | * it is not stopped earlier with shutdown() or when all active events finish. processEvents() |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 435 | * can be called repeatedly, if desired. |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 436 | * |
Eric Newberry | 3306339 | 2018-06-23 01:59:36 -0700 | [diff] [blame] | 437 | * If a negative timeout is specified, then processEvents will not block and will process only |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 438 | * pending events. |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 439 | * |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 440 | * @param timeout maximum time to block the thread |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 441 | * @param keepThread Keep thread in a blocked state (in event processing), even when |
Eric Newberry | 3306339 | 2018-06-23 01:59:36 -0700 | [diff] [blame] | 442 | * there are no outstanding events (e.g., no Interest/Data is expected). |
| 443 | * If timeout is zero and this parameter is true, the only way to stop |
| 444 | * processEvents() is to call shutdown(). |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 445 | * |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 446 | * @note This may throw an exception for reading data or in the callback for processing |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 447 | * the data. If you call this from an main event loop, you may want to catch and |
| 448 | * log/disregard all exceptions. |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 449 | * |
| 450 | * @throw OversizedPacketError encoded packet size exceeds MAX_NDN_PACKET_SIZE |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 451 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 452 | void |
Junxiao Shi | 2ed9e07 | 2017-08-13 16:45:48 +0000 | [diff] [blame] | 453 | processEvents(time::milliseconds timeout = time::milliseconds::zero(), |
Junxiao Shi | c828dfc | 2016-09-15 13:26:22 +0000 | [diff] [blame] | 454 | bool keepThread = false) |
| 455 | { |
| 456 | this->doProcessEvents(timeout, keepThread); |
| 457 | } |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 458 | |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 459 | /** |
| 460 | * @brief Shutdown face operations |
| 461 | * |
| 462 | * This method cancels all pending operations and closes connection to NDN Forwarder. |
| 463 | * |
Eric Newberry | 3306339 | 2018-06-23 01:59:36 -0700 | [diff] [blame] | 464 | * Note that this method does not stop the io_service if it is shared between multiple Faces or |
| 465 | * with other IO objects (e.g., Scheduler). |
| 466 | * |
| 467 | * @warning Calling this method could cause outgoing packets to be lost. Producers that shut down |
| 468 | * immediately after sending a Data packet should instead use unsetInterestFilter() to |
| 469 | * shut down cleanly. |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 470 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 471 | void |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 472 | shutdown(); |
Yingdi Yu | 0d92081 | 2014-01-30 14:50:57 -0800 | [diff] [blame] | 473 | |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 474 | /** |
Eric Newberry | 3306339 | 2018-06-23 01:59:36 -0700 | [diff] [blame] | 475 | * @return reference to io_service object |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 476 | */ |
| 477 | boost::asio::io_service& |
| 478 | getIoService() |
| 479 | { |
Junxiao Shi | 2cced06 | 2014-11-02 21:27:38 -0700 | [diff] [blame] | 480 | return m_ioService; |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 481 | } |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 482 | |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 483 | NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
| 484 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 485 | * @return underlying transport |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 486 | */ |
| 487 | shared_ptr<Transport> |
| 488 | getTransport(); |
| 489 | |
Junxiao Shi | c828dfc | 2016-09-15 13:26:22 +0000 | [diff] [blame] | 490 | protected: |
| 491 | virtual void |
Junxiao Shi | 2ed9e07 | 2017-08-13 16:45:48 +0000 | [diff] [blame] | 492 | doProcessEvents(time::milliseconds timeout, bool keepThread); |
Junxiao Shi | c828dfc | 2016-09-15 13:26:22 +0000 | [diff] [blame] | 493 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 494 | private: |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 495 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 496 | * @throw ConfigFile::Error on parse error and unsupported protocols |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 497 | */ |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 498 | shared_ptr<Transport> |
| 499 | makeDefaultTransport(); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 500 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 501 | /** |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 502 | * @throw Face::Error on unsupported protocol |
Junxiao Shi | 2cced06 | 2014-11-02 21:27:38 -0700 | [diff] [blame] | 503 | * @note shared_ptr is passed by value because ownership is transferred to this function |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 504 | */ |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 505 | void |
Joao Pereira | 68c0d88 | 2015-05-19 14:27:55 -0400 | [diff] [blame] | 506 | construct(shared_ptr<Transport> transport, KeyChain& keyChain); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 507 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 508 | void |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 509 | onReceiveElement(const Block& blockFromDaemon); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 510 | |
Alexander Afanasyev | 7dced46 | 2014-03-19 15:12:32 -0700 | [diff] [blame] | 511 | void |
| 512 | asyncShutdown(); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 513 | |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 514 | private: |
Eric Newberry | 3306339 | 2018-06-23 01:59:36 -0700 | [diff] [blame] | 515 | /// the io_service owned by this Face, could be null |
Junxiao Shi | 2cced06 | 2014-11-02 21:27:38 -0700 | [diff] [blame] | 516 | unique_ptr<boost::asio::io_service> m_internalIoService; |
Eric Newberry | 3306339 | 2018-06-23 01:59:36 -0700 | [diff] [blame] | 517 | /// the io_service used by this Face |
Junxiao Shi | 2cced06 | 2014-11-02 21:27:38 -0700 | [diff] [blame] | 518 | boost::asio::io_service& m_ioService; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 519 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 520 | shared_ptr<Transport> m_transport; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 521 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 522 | /** |
| 523 | * @brief if not null, a pointer to an internal KeyChain owned by Face |
| 524 | * @note if a KeyChain is supplied to constructor, this pointer will be null, |
| 525 | * and the passed KeyChain is given to nfdController; |
| 526 | * currently Face does not keep the KeyChain passed in constructor |
| 527 | * because it's not needed, but this may change in the future |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 528 | */ |
Joao Pereira | 68c0d88 | 2015-05-19 14:27:55 -0400 | [diff] [blame] | 529 | unique_ptr<KeyChain> m_internalKeyChain; |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 530 | |
Joao Pereira | 68c0d88 | 2015-05-19 14:27:55 -0400 | [diff] [blame] | 531 | unique_ptr<nfd::Controller> m_nfdController; |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 532 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 533 | class Impl; |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 534 | shared_ptr<Impl> m_impl; |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 535 | }; |
| 536 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 537 | } // namespace ndn |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 538 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 539 | #endif // NDN_FACE_HPP |