Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 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 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 25 | #include "common.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 26 | |
| 27 | #include "name.hpp" |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 28 | #include "interest.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 29 | #include "interest-filter.hpp" |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 30 | #include "data.hpp" |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame] | 31 | #include "encoding/nfd-constants.hpp" |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 32 | #include "lp/nack.hpp" |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame] | 33 | #include "security/signing-info.hpp" |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 34 | |
| 35 | #define NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING |
| 36 | |
| 37 | #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 38 | #include "security/identity-certificate.hpp" |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 39 | #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 40 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 41 | namespace boost { |
| 42 | namespace asio { |
| 43 | class io_service; |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 44 | } // namespace asio |
| 45 | } // namespace boost |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 46 | |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 47 | namespace ndn { |
| 48 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 49 | class Transport; |
| 50 | |
| 51 | class PendingInterestId; |
| 52 | class RegisteredPrefixId; |
| 53 | class InterestFilterId; |
| 54 | |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 55 | namespace security { |
| 56 | class KeyChain; |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 57 | } // namespace security |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 58 | using security::KeyChain; |
| 59 | |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 60 | namespace nfd { |
| 61 | class Controller; |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 62 | } // namespace nfd |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 63 | |
Jeff Thompson | fe08e5a | 2013-08-13 11:15:59 -0700 | [diff] [blame] | 64 | /** |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 65 | * @brief Callback called when expressed Interest gets satisfied with a Data packet |
| 66 | */ |
| 67 | typedef function<void(const Interest&, const Data&)> DataCallback; |
| 68 | |
| 69 | /** |
| 70 | * @brief Callback called when Nack is sent in response to expressed Interest |
| 71 | */ |
| 72 | typedef function<void(const Interest&, const lp::Nack&)> NackCallback; |
| 73 | |
| 74 | /** |
| 75 | * @brief Callback called when expressed Interest times out |
| 76 | */ |
| 77 | typedef function<void(const Interest&)> TimeoutCallback; |
| 78 | |
| 79 | /** |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 80 | * @brief Callback called when expressed Interest gets satisfied with Data packet |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 81 | * @deprecated use DataCallback |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 82 | */ |
| 83 | typedef function<void(const Interest&, Data&)> OnData; |
| 84 | |
| 85 | /** |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 86 | * @brief Callback called when expressed Interest times out |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 87 | * @deprecated use TimeoutCallback |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 88 | */ |
| 89 | typedef function<void(const Interest&)> OnTimeout; |
| 90 | |
| 91 | /** |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 92 | * @brief Callback called when incoming Interest matches the specified InterestFilter |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 93 | */ |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 94 | typedef function<void (const InterestFilter&, const Interest&)> OnInterest; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 95 | |
| 96 | /** |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 97 | * @brief Callback called when registerPrefix or setInterestFilter command succeeds |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 98 | */ |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 99 | typedef function<void(const Name&)> RegisterPrefixSuccessCallback; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 100 | |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 101 | /** |
| 102 | * @brief Callback called when registerPrefix or setInterestFilter command fails |
| 103 | */ |
| 104 | typedef function<void(const Name&, const std::string&)> RegisterPrefixFailureCallback; |
| 105 | |
| 106 | /** |
| 107 | * @brief Callback called when unregisterPrefix or unsetInterestFilter command succeeds |
| 108 | */ |
| 109 | typedef function<void()> UnregisterPrefixSuccessCallback; |
| 110 | |
| 111 | /** |
| 112 | * @brief Callback called when unregisterPrefix or unsetInterestFilter command fails |
| 113 | */ |
| 114 | typedef function<void(const std::string&)> UnregisterPrefixFailureCallback; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 115 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 116 | /** |
| 117 | * @brief Abstraction to communicate with local or remote NDN forwarder |
Jeff Thompson | fe08e5a | 2013-08-13 11:15:59 -0700 | [diff] [blame] | 118 | */ |
Alexander Afanasyev | 8460afb | 2014-02-15 20:31:42 -0800 | [diff] [blame] | 119 | class Face : noncopyable |
| 120 | { |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 121 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 122 | class Error : public std::runtime_error |
| 123 | { |
| 124 | public: |
| 125 | explicit |
| 126 | Error(const std::string& what) |
| 127 | : std::runtime_error(what) |
| 128 | { |
| 129 | } |
| 130 | }; |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 131 | |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 132 | public: // constructors |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 133 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 134 | * @brief Create a new Face using the default transport (UnixTransport) |
| 135 | * |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 136 | * @throws ConfigFile::Error on configuration file parse failure |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 137 | * @throws ConfigFile::Error if configuration file specifies an unsupported protocol |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 138 | */ |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 139 | Face(); |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 140 | |
| 141 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 142 | * @brief Create a new Face using the default transport (UnixTransport) |
| 143 | * |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 144 | * @par Usage examples: |
| 145 | * |
| 146 | * Face face1; |
| 147 | * Face face2(face1.getIoService()); |
| 148 | * |
| 149 | * // Now the following ensures that events on both faces are processed |
| 150 | * face1.processEvents(); |
| 151 | * // or face1.getIoService().run(); |
| 152 | * |
| 153 | * @par or |
| 154 | * |
| 155 | * boost::asio::io_service ioService; |
| 156 | * Face face1(ioService); |
| 157 | * Face face2(ioService); |
| 158 | * ... |
| 159 | * |
| 160 | * ioService.run(); |
| 161 | * |
| 162 | * @param ioService A reference to boost::io_service object that should control all |
| 163 | * IO operations. |
| 164 | * @throws ConfigFile::Error on configuration file parse failure |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 165 | * @throws ConfigFile::Error if configuration file specifies an unsupported protocol |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 166 | */ |
| 167 | explicit |
| 168 | Face(boost::asio::io_service& ioService); |
| 169 | |
| 170 | /** |
| 171 | * @brief Create a new Face using TcpTransport |
| 172 | * |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 173 | * @param host The host of the NDN forwarder |
| 174 | * @param port (optional) The port or service name of the NDN forwarder (**default**: "6363") |
Jeff Thompson | fe08e5a | 2013-08-13 11:15:59 -0700 | [diff] [blame] | 175 | */ |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 176 | Face(const std::string& host, const std::string& port = "6363"); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 177 | |
| 178 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 179 | * @brief Create a new Face using the given Transport |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 180 | * @param transport the Transport used for communication. If nullptr, then the default |
| 181 | * transport will be used. |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 182 | * |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 183 | * @throws ConfigFile::Error if @p transport is nullptr on configuration file parse failure |
| 184 | * @throws ConfigFile::Error if @p transport is nullptr and the configuration file |
| 185 | * specifies an unsupported protocol |
| 186 | * @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] | 187 | */ |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 188 | explicit |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 189 | Face(shared_ptr<Transport> transport); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 190 | |
| 191 | /** |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 192 | * @brief Create a new Face using the given Transport and KeyChain instance |
| 193 | * @param transport the Transport used for communication. If nullptr, then the default |
| 194 | * transport will be used. |
| 195 | * @param keyChain the KeyChain to sign commands |
| 196 | * |
| 197 | * @throws ConfigFile::Error if @p transport is nullptr on configuration file parse failure |
| 198 | * @throws ConfigFile::Error if @p transport is nullptr and the configuration file |
| 199 | * specifies an unsupported protocol |
| 200 | * @note shared_ptr is passed by value because ownership is shared with this class |
| 201 | */ |
| 202 | Face(shared_ptr<Transport> transport, KeyChain& keyChain); |
| 203 | |
| 204 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 205 | * @brief Create a new Face using the given Transport and IO service object |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 206 | * @param transport the Transport used for communication. If nullptr, then the default |
| 207 | * transport will be used. |
| 208 | * @param ioService the io_service that controls all IO operations |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 209 | * |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 210 | * @sa Face(boost::asio::io_service&) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 211 | * |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 212 | * @throws ConfigFile::Error if @p transport is nullptr on configuration file parse failure |
| 213 | * @throws ConfigFile::Error if @p transport is nullptr and the configuration file |
| 214 | * specifies an unsupported protocol |
| 215 | * @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] | 216 | */ |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 217 | Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService); |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 218 | |
Jeff Thompson | 4fe4551 | 2013-08-23 14:06:38 -0700 | [diff] [blame] | 219 | /** |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 220 | * @brief Create a new Face using the given Transport and IO service object |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 221 | * @param transport the Transport used for communication. If nullptr, then the default |
| 222 | * transport will be used. |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 223 | * @param ioService the io_service that controls all IO operations |
| 224 | * @param keyChain the KeyChain to sign commands |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 225 | * |
| 226 | * @throws ConfigFile::Error if @p transport is nullptr on configuration file parse failure |
| 227 | * @throws ConfigFile::Error if @p transport is nullptr and the configuration file |
| 228 | * specifies an unsupported protocol |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 229 | * @note shared_ptr is passed by value because ownership is shared with this class |
| 230 | */ |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 231 | Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, KeyChain& keyChain); |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 232 | |
| 233 | ~Face(); |
| 234 | |
| 235 | public: // consumer |
| 236 | /** |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 237 | * @brief Express Interest |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 238 | * @param interest the Interest; a copy will be made, so that the caller is not |
| 239 | * required to maintain the argument unchanged |
| 240 | * @param afterSatisfied function to be invoked if Data is returned |
| 241 | * @param afterNacked function to be invoked if Network NACK is returned |
| 242 | * @param afterTimeout function to be invoked if neither Data nor Network NACK |
| 243 | * is returned within InterestLifetime |
| 244 | */ |
| 245 | const PendingInterestId* |
| 246 | expressInterest(const Interest& interest, |
| 247 | const DataCallback& afterSatisfied, |
| 248 | const NackCallback& afterNacked, |
| 249 | const TimeoutCallback& afterTimeout); |
| 250 | |
| 251 | /** |
| 252 | * @brief Express Interest |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 253 | * |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 254 | * @param interest An Interest to be expressed |
| 255 | * @param onData Callback to be called when a matching data packet is received |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 256 | * @param onTimeout (optional) A function object to call if the interest times out or is Nacked |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 257 | * |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 258 | * @return The pending interest ID which can be used with removePendingInterest |
Alexander Afanasyev | 49bb1fb | 2014-07-21 12:54:01 -0700 | [diff] [blame] | 259 | * |
| 260 | * @throws Error when Interest size exceeds maximum limit (MAX_NDN_PACKET_SIZE) |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 261 | * |
| 262 | * @deprecated use expressInterest(Interest, DataCallback, NackCallback, TimeoutCallback) |
Jeff Thompson | 4fe4551 | 2013-08-23 14:06:38 -0700 | [diff] [blame] | 263 | */ |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 264 | const PendingInterestId* |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 265 | expressInterest(const Interest& interest, |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 266 | const OnData& onData, |
| 267 | const OnTimeout& onTimeout = nullptr); |
Jeff Thompson | 4fe4551 | 2013-08-23 14:06:38 -0700 | [diff] [blame] | 268 | |
| 269 | /** |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 270 | * @brief Express Interest using name and Interest template |
| 271 | * |
| 272 | * @param name Name of the Interest |
| 273 | * @param tmpl Interest template to fill parameters |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 274 | * @param onData Callback to be called when a matching data packet is received |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 275 | * @param onTimeout (optional) A function object to call if the interest times out or is Nacked |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 276 | * |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 277 | * @return Opaque pending interest ID which can be used with removePendingInterest |
Alexander Afanasyev | 49bb1fb | 2014-07-21 12:54:01 -0700 | [diff] [blame] | 278 | * |
| 279 | * @throws Error when Interest size exceeds maximum limit (MAX_NDN_PACKET_SIZE) |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 280 | * |
| 281 | * @deprecated use expressInterest(Interest, DataCallback, NackCallback, TimeoutCallback) |
Jeff Thompson | 7aec025 | 2013-08-22 17:29:57 -0700 | [diff] [blame] | 282 | */ |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 283 | const PendingInterestId* |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 284 | expressInterest(const Name& name, |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 285 | const Interest& tmpl, |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 286 | const OnData& onData, |
| 287 | const OnTimeout& onTimeout = nullptr); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 288 | |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 289 | /** |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 290 | * @brief Cancel previously expressed Interest |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 291 | * |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 292 | * @param pendingInterestId The ID returned from expressInterest. |
| 293 | */ |
| 294 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 295 | removePendingInterest(const PendingInterestId* pendingInterestId); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 296 | |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 297 | /** |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 298 | * @brief Cancel all previously expressed Interests |
| 299 | */ |
| 300 | void |
| 301 | removeAllPendingInterests(); |
| 302 | |
| 303 | /** |
Alexander Afanasyev | 6fcdde2 | 2014-08-22 19:03:36 -0700 | [diff] [blame] | 304 | * @brief Get number of pending Interests |
| 305 | */ |
| 306 | size_t |
| 307 | getNPendingInterests() const; |
| 308 | |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 309 | public: // producer |
Alexander Afanasyev | 6fcdde2 | 2014-08-22 19:03:36 -0700 | [diff] [blame] | 310 | /** |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 311 | * @brief Set InterestFilter to dispatch incoming matching interest to onInterest |
| 312 | * callback and register the filtered prefix with the connected NDN forwarder |
| 313 | * |
| 314 | * This version of setInterestFilter combines setInterestFilter and registerPrefix |
| 315 | * operations and is intended to be used when only one filter for the same prefix needed |
| 316 | * to be set. When multiple names sharing the same prefix should be dispatched to |
| 317 | * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by |
| 318 | * a series of setInterestFilter calls. |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 319 | * |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 320 | * @param interestFilter Interest filter (prefix part will be registered with the forwarder) |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 321 | * @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] | 322 | * @param onFailure A callback to be called when prefixRegister command fails |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 323 | * @param flags (optional) RIB flags |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 324 | * @param signingInfo (optional) Signing parameters. When omitted, a default parameters |
| 325 | * used in the signature will be used. |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 326 | * |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 327 | * @return Opaque registered prefix ID which can be used with unsetInterestFilter or |
| 328 | * removeRegisteredPrefix |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 329 | */ |
| 330 | const RegisteredPrefixId* |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 331 | setInterestFilter(const InterestFilter& interestFilter, |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 332 | const OnInterest& onInterest, |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 333 | const RegisterPrefixFailureCallback& onFailure, |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 334 | const security::SigningInfo& signingInfo = security::SigningInfo(), |
Alexander Afanasyev | 0866f51 | 2014-08-11 13:25:09 -0700 | [diff] [blame] | 335 | uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT); |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 336 | |
| 337 | /** |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 338 | * @brief Set InterestFilter to dispatch incoming matching interest to onInterest |
| 339 | * callback and register the filtered prefix with the connected NDN forwarder |
| 340 | * |
| 341 | * This version of setInterestFilter combines setInterestFilter and registerPrefix |
| 342 | * operations and is intended to be used when only one filter for the same prefix needed |
| 343 | * to be set. When multiple names sharing the same prefix should be dispatched to |
| 344 | * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by |
| 345 | * a series of setInterestFilter calls. |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 346 | * |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 347 | * @param interestFilter Interest filter (prefix part will be registered with the forwarder) |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 348 | * @param onInterest A callback to be called when a matching interest is received |
| 349 | * @param onSuccess A callback to be called when prefixRegister command succeeds |
| 350 | * @param onFailure A callback to be called when prefixRegister command fails |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 351 | * @param flags (optional) RIB flags |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 352 | * @param signingInfo (optional) Signing parameters. When omitted, a default parameters |
| 353 | * used in the signature will be used. |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 354 | * |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 355 | * @return Opaque registered prefix ID which can be used with unsetInterestFilter or |
| 356 | * removeRegisteredPrefix |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 357 | */ |
| 358 | const RegisteredPrefixId* |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 359 | setInterestFilter(const InterestFilter& interestFilter, |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 360 | const OnInterest& onInterest, |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 361 | const RegisterPrefixSuccessCallback& onSuccess, |
| 362 | const RegisterPrefixFailureCallback& onFailure, |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 363 | const security::SigningInfo& signingInfo = security::SigningInfo(), |
Alexander Afanasyev | 0866f51 | 2014-08-11 13:25:09 -0700 | [diff] [blame] | 364 | uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 365 | |
| 366 | /** |
| 367 | * @brief Set InterestFilter to dispatch incoming matching interest to onInterest callback |
| 368 | * |
| 369 | * @param interestFilter Interest |
| 370 | * @param onInterest A callback to be called when a matching interest is received |
| 371 | * |
| 372 | * This method modifies library's FIB only, and does not register the prefix with the |
| 373 | * forwarder. It will always succeed. To register prefix with the forwarder, use |
| 374 | * registerPrefix, or use the setInterestFilter overload taking two callbacks. |
| 375 | * |
| 376 | * @return Opaque interest filter ID which can be used with unsetInterestFilter |
| 377 | */ |
| 378 | const InterestFilterId* |
| 379 | setInterestFilter(const InterestFilter& interestFilter, |
| 380 | const OnInterest& onInterest); |
| 381 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 382 | #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING |
| 383 | /** |
| 384 | * @deprecated Use override with SigningInfo instead of this function |
| 385 | * @brief Set InterestFilter to dispatch incoming matching interest to onInterest |
| 386 | * callback and register the filtered prefix with the connected NDN forwarder |
| 387 | * |
| 388 | * This version of setInterestFilter combines setInterestFilter and registerPrefix |
| 389 | * operations and is intended to be used when only one filter for the same prefix needed |
| 390 | * to be set. When multiple names sharing the same prefix should be dispatched to |
| 391 | * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by |
| 392 | * a series of setInterestFilter calls. |
| 393 | * |
| 394 | * @param interestFilter Interest filter (prefix part will be registered with the forwarder) |
| 395 | * @param onInterest A callback to be called when a matching interest is received |
| 396 | * @param onSuccess A callback to be called when prefixRegister command succeeds |
| 397 | * @param onFailure A callback to be called when prefixRegister command fails |
| 398 | * @param flags (optional) RIB flags |
| 399 | * @param certificate (optional) A certificate under which the prefix registration |
| 400 | * command is signed. When omitted, a default certificate of |
| 401 | * the default identity is used to sign the registration command |
| 402 | * |
| 403 | * @return Opaque registered prefix ID which can be used with unsetInterestFilter or |
| 404 | * removeRegisteredPrefix |
| 405 | */ |
philo | bb778e7 | 2015-08-25 14:49:19 -0700 | [diff] [blame] | 406 | DEPRECATED( |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 407 | const RegisteredPrefixId* |
| 408 | setInterestFilter(const InterestFilter& interestFilter, |
| 409 | const OnInterest& onInterest, |
| 410 | const RegisterPrefixSuccessCallback& onSuccess, |
| 411 | const RegisterPrefixFailureCallback& onFailure, |
| 412 | const IdentityCertificate& certificate, |
philo | bb778e7 | 2015-08-25 14:49:19 -0700 | [diff] [blame] | 413 | uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT)); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 414 | |
| 415 | /** |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 416 | * @deprecated Use override with SigningInfo instead of this function |
| 417 | * @brief Set InterestFilter to dispatch incoming matching interest to onInterest |
| 418 | * callback and register the filtered prefix with the connected NDN forwarder |
| 419 | * |
| 420 | * This version of setInterestFilter combines setInterestFilter and registerPrefix |
| 421 | * operations and is intended to be used when only one filter for the same prefix needed |
| 422 | * to be set. When multiple names sharing the same prefix should be dispatched to |
| 423 | * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by |
| 424 | * a series of setInterestFilter calls. |
| 425 | * |
| 426 | * @param interestFilter Interest filter (prefix part will be registered with the forwarder) |
| 427 | * @param onInterest A callback to be called when a matching interest is received |
| 428 | * @param onFailure A callback to be called when prefixRegister command fails |
| 429 | * @param flags (optional) RIB flags |
| 430 | * @param certificate (optional) A certificate under which the prefix registration |
| 431 | * command is signed. When omitted, a default certificate of |
| 432 | * the default identity is used to sign the registration command |
| 433 | * |
| 434 | * @return Opaque registered prefix ID which can be used with unsetInterestFilter or |
| 435 | * removeRegisteredPrefix |
| 436 | */ |
philo | bb778e7 | 2015-08-25 14:49:19 -0700 | [diff] [blame] | 437 | DEPRECATED( |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 438 | const RegisteredPrefixId* |
| 439 | setInterestFilter(const InterestFilter& interestFilter, |
| 440 | const OnInterest& onInterest, |
| 441 | const RegisterPrefixFailureCallback& onFailure, |
| 442 | const IdentityCertificate& certificate, |
philo | bb778e7 | 2015-08-25 14:49:19 -0700 | [diff] [blame] | 443 | uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT)); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 444 | |
| 445 | /** |
| 446 | * @deprecated Use override with SigningInfo instead of this function |
| 447 | * @brief Set InterestFilter to dispatch incoming matching interest to onInterest |
| 448 | * callback and register the filtered prefix with the connected NDN forwarder |
| 449 | * |
| 450 | * This version of setInterestFilter combines setInterestFilter and registerPrefix |
| 451 | * operations and is intended to be used when only one filter for the same prefix needed |
| 452 | * to be set. When multiple names sharing the same prefix should be dispatched to |
| 453 | * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by |
| 454 | * a series of setInterestFilter calls. |
| 455 | * |
| 456 | * @param interestFilter Interest filter (prefix part will be registered with the forwarder) |
| 457 | * @param onInterest A callback to be called when a matching interest is received |
| 458 | * @param onSuccess A callback to be called when prefixRegister command succeeds |
| 459 | * @param onFailure A callback to be called when prefixRegister command fails |
| 460 | * @param identity A signing identity. A prefix registration command is signed |
| 461 | * under the default certificate of this identity |
| 462 | * @param flags (optional) RIB flags |
| 463 | * |
| 464 | * @return Opaque registered prefix ID which can be used with removeRegisteredPrefix |
| 465 | */ |
philo | bb778e7 | 2015-08-25 14:49:19 -0700 | [diff] [blame] | 466 | DEPRECATED( |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 467 | const RegisteredPrefixId* |
| 468 | setInterestFilter(const InterestFilter& interestFilter, |
| 469 | const OnInterest& onInterest, |
| 470 | const RegisterPrefixSuccessCallback& onSuccess, |
| 471 | const RegisterPrefixFailureCallback& onFailure, |
| 472 | const Name& identity, |
philo | bb778e7 | 2015-08-25 14:49:19 -0700 | [diff] [blame] | 473 | uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT)); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 474 | |
| 475 | /** |
| 476 | * @deprecated Use override with SigningInfo instead of this function |
| 477 | * @brief Set InterestFilter to dispatch incoming matching interest to onInterest |
| 478 | * callback and register the filtered prefix with the connected NDN forwarder |
| 479 | * |
| 480 | * This version of setInterestFilter combines setInterestFilter and registerPrefix |
| 481 | * operations and is intended to be used when only one filter for the same prefix needed |
| 482 | * to be set. When multiple names sharing the same prefix should be dispatched to |
| 483 | * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by |
| 484 | * a series of setInterestFilter calls. |
| 485 | * |
| 486 | * @param interestFilter Interest filter (prefix part will be registered with the forwarder) |
| 487 | * @param onInterest A callback to be called when a matching interest is received |
| 488 | * @param onFailure A callback to be called when prefixRegister command fails |
| 489 | * @param identity A signing identity. A prefix registration command is signed |
| 490 | * under the default certificate of this identity |
| 491 | * @param flags (optional) RIB flags |
| 492 | * |
| 493 | * @return Opaque registered prefix ID which can be used with removeRegisteredPrefix |
| 494 | */ |
philo | bb778e7 | 2015-08-25 14:49:19 -0700 | [diff] [blame] | 495 | DEPRECATED( |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 496 | const RegisteredPrefixId* |
| 497 | setInterestFilter(const InterestFilter& interestFilter, |
| 498 | const OnInterest& onInterest, |
| 499 | const RegisterPrefixFailureCallback& onFailure, |
| 500 | const Name& identity, |
philo | bb778e7 | 2015-08-25 14:49:19 -0700 | [diff] [blame] | 501 | uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT)); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 502 | #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING |
| 503 | |
| 504 | /** |
| 505 | * @brief Register prefix with the connected NDN forwarder |
| 506 | * |
| 507 | * This method only modifies forwarder's RIB and does not associate any |
| 508 | * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to |
| 509 | * the right callbacks. |
| 510 | * |
| 511 | * @param prefix A prefix to register with the connected NDN forwarder |
| 512 | * @param onSuccess A callback to be called when prefixRegister command succeeds |
| 513 | * @param onFailure A callback to be called when prefixRegister command fails |
| 514 | * @param signingInfo (optional) Signing parameters. When omitted, a default parameters |
| 515 | * used in the signature will be used. |
Alexander Afanasyev | f2a4622 | 2015-09-17 18:01:30 -0700 | [diff] [blame] | 516 | * @param flags Prefix registration flags |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 517 | * |
| 518 | * @return The registered prefix ID which can be used with unregisterPrefix |
Alexander Afanasyev | f2a4622 | 2015-09-17 18:01:30 -0700 | [diff] [blame] | 519 | * @see nfd::RouteFlags |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 520 | */ |
| 521 | const RegisteredPrefixId* |
| 522 | registerPrefix(const Name& prefix, |
| 523 | const RegisterPrefixSuccessCallback& onSuccess, |
| 524 | const RegisterPrefixFailureCallback& onFailure, |
| 525 | const security::SigningInfo& signingInfo = security::SigningInfo(), |
| 526 | uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 527 | |
| 528 | #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING |
| 529 | /** |
| 530 | * @deprecated Use override with SigningInfo instead of this function |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 531 | * @brief Register prefix with the connected NDN forwarder |
| 532 | * |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 533 | * This method only modifies forwarder's RIB and does not associate any |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 534 | * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to |
| 535 | * the right callbacks. |
| 536 | * |
| 537 | * @param prefix A prefix to register with the connected NDN forwarder |
| 538 | * @param onSuccess A callback to be called when prefixRegister command succeeds |
| 539 | * @param onFailure A callback to be called when prefixRegister command fails |
| 540 | * @param certificate (optional) A certificate under which the prefix registration |
Junxiao Shi | 6a90f37 | 2014-10-13 20:29:30 -0700 | [diff] [blame] | 541 | * command is signed. When omitted, a default certificate of |
| 542 | * the default identity is used to sign the registration command |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 543 | * @param flags (optional) RIB flags |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 544 | * |
| 545 | * @return The registered prefix ID which can be used with unregisterPrefix |
| 546 | */ |
philo | bb778e7 | 2015-08-25 14:49:19 -0700 | [diff] [blame] | 547 | DEPRECATED( |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 548 | const RegisteredPrefixId* |
| 549 | registerPrefix(const Name& prefix, |
| 550 | const RegisterPrefixSuccessCallback& onSuccess, |
| 551 | const RegisterPrefixFailureCallback& onFailure, |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 552 | const IdentityCertificate& certificate, |
philo | bb778e7 | 2015-08-25 14:49:19 -0700 | [diff] [blame] | 553 | uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT)); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 554 | |
| 555 | /** |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 556 | * @deprecated Use override with SigningInfo instead of this function |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 557 | * @brief Register prefix with the connected NDN forwarder and call onInterest when a matching |
| 558 | * interest is received. |
| 559 | * |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 560 | * This method only modifies forwarder's RIB and does not associate any |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 561 | * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to |
| 562 | * the right callbacks. |
| 563 | * |
| 564 | * @param prefix A prefix to register with the connected NDN forwarder |
| 565 | * @param onSuccess A callback to be called when prefixRegister command succeeds |
| 566 | * @param onFailure A callback to be called when prefixRegister command fails |
Junxiao Shi | 6a90f37 | 2014-10-13 20:29:30 -0700 | [diff] [blame] | 567 | * @param identity A signing identity. A prefix registration command is signed |
| 568 | * under the default certificate of this identity |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 569 | * @param flags (optional) RIB flags |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 570 | * |
| 571 | * @return The registered prefix ID which can be used with unregisterPrefix |
| 572 | */ |
philo | bb778e7 | 2015-08-25 14:49:19 -0700 | [diff] [blame] | 573 | DEPRECATED( |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 574 | const RegisteredPrefixId* |
| 575 | registerPrefix(const Name& prefix, |
| 576 | const RegisterPrefixSuccessCallback& onSuccess, |
| 577 | const RegisterPrefixFailureCallback& onFailure, |
Alexander Afanasyev | 0866f51 | 2014-08-11 13:25:09 -0700 | [diff] [blame] | 578 | const Name& identity, |
philo | bb778e7 | 2015-08-25 14:49:19 -0700 | [diff] [blame] | 579 | uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT)); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 580 | #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 581 | |
| 582 | /** |
Alexander Afanasyev | 1b01c31 | 2014-05-26 16:58:10 +0300 | [diff] [blame] | 583 | * @brief Remove the registered prefix entry with the registeredPrefixId |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 584 | * |
| 585 | * This does not affect another registered prefix with a different registeredPrefixId, |
| 586 | * even it if has the same prefix name. If there is no entry with the |
| 587 | * registeredPrefixId, do nothing. |
| 588 | * |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 589 | * unsetInterestFilter will use the same credentials as original |
| 590 | * setInterestFilter/registerPrefix command |
| 591 | * |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 592 | * @param registeredPrefixId The ID returned from registerPrefix |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 593 | */ |
| 594 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 595 | unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId); |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 596 | |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 597 | /** |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 598 | * @brief Remove previously set InterestFilter from library's FIB |
| 599 | * |
| 600 | * This method always succeeds and will **NOT** send any request to the connected |
| 601 | * forwarder. |
| 602 | * |
| 603 | * @param interestFilterId The ID returned from setInterestFilter. |
| 604 | */ |
| 605 | void |
| 606 | unsetInterestFilter(const InterestFilterId* interestFilterId); |
| 607 | |
| 608 | /** |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 609 | * @brief Unregister prefix from RIB |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 610 | * |
| 611 | * unregisterPrefix will use the same credentials as original |
| 612 | * setInterestFilter/registerPrefix command |
| 613 | * |
| 614 | * If registeredPrefixId was obtained using setInterestFilter, the corresponding |
| 615 | * InterestFilter will be unset too. |
| 616 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 617 | * @param registeredPrefixId The ID returned from registerPrefix |
| 618 | * @param onSuccess Callback to be called when operation succeeds |
| 619 | * @param onFailure Callback to be called when operation fails |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 620 | */ |
| 621 | void |
| 622 | unregisterPrefix(const RegisteredPrefixId* registeredPrefixId, |
| 623 | const UnregisterPrefixSuccessCallback& onSuccess, |
| 624 | const UnregisterPrefixFailureCallback& onFailure); |
| 625 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 626 | /** |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 627 | * @brief Publish data packet |
| 628 | * |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 629 | * This method can be called to satisfy the incoming Interest or to put Data packet into |
Alexander Afanasyev | 6a05b4b | 2014-07-18 17:23:00 -0700 | [diff] [blame] | 630 | * the cache of the local NDN forwarder. |
| 631 | * |
| 632 | * @param data Data packet to publish. It is highly recommended to use Data packet that |
| 633 | * was created using make_shared<Data>(...). Otherwise, put() will make an |
| 634 | * extra copy of the Data packet to ensure validity of published Data until |
| 635 | * asynchronous put() operation finishes. |
Alexander Afanasyev | 49bb1fb | 2014-07-21 12:54:01 -0700 | [diff] [blame] | 636 | * |
| 637 | * @throws Error when Data size exceeds maximum limit (MAX_NDN_PACKET_SIZE) |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 638 | */ |
| 639 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 640 | put(const Data& data); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 641 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 642 | /** |
| 643 | * @brief sends a Network NACK |
| 644 | * @param nack the Nack; a copy will be made, so that the caller is not required to |
| 645 | * maintain the argument unchanged |
| 646 | */ |
| 647 | void |
| 648 | put(const lp::Nack& nack); |
| 649 | |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 650 | public: // IO routine |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 651 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 652 | * @brief Process any data to receive or call timeout callbacks. |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 653 | * |
| 654 | * This call will block forever (default timeout == 0) to process IO on the face. |
| 655 | * To exit, one expected to call face.shutdown() from one of the callback methods. |
| 656 | * |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 657 | * If positive timeout is specified, then processEvents will exit after this timeout, if |
| 658 | * not stopped earlier with face.shutdown() or when all active events finish. The call |
| 659 | * can be called repeatedly, if desired. |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 660 | * |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 661 | * If negative timeout is specified, then processEvents will not block and process only |
| 662 | * pending events. |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 663 | * |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 664 | * @param timeout maximum time to block the thread |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 665 | * @param keepThread Keep thread in a blocked state (in event processing), even when |
| 666 | * there are no outstanding events (e.g., no Interest/Data is expected) |
| 667 | * |
| 668 | * @throw This may throw an exception for reading data or in the callback for processing |
| 669 | * the data. If you call this from an main event loop, you may want to catch and |
| 670 | * log/disregard all exceptions. |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 671 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 672 | void |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 673 | processEvents(const time::milliseconds& timeout = time::milliseconds::zero(), |
| 674 | bool keepThread = false); |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 675 | |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 676 | /** |
| 677 | * @brief Shutdown face operations |
| 678 | * |
| 679 | * This method cancels all pending operations and closes connection to NDN Forwarder. |
| 680 | * |
| 681 | * Note that this method does not stop IO service and if the same IO service is shared |
| 682 | * between multiple Faces or with other IO objects (e.g., Scheduler). |
| 683 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 684 | void |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 685 | shutdown(); |
Yingdi Yu | 0d92081 | 2014-01-30 14:50:57 -0800 | [diff] [blame] | 686 | |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 687 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 688 | * @brief Get reference to IO service object |
| 689 | */ |
| 690 | boost::asio::io_service& |
| 691 | getIoService() |
| 692 | { |
Junxiao Shi | 2cced06 | 2014-11-02 21:27:38 -0700 | [diff] [blame] | 693 | return m_ioService; |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 694 | } |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 695 | |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 696 | NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
| 697 | /** |
| 698 | * @brief Get the underlying transport of the face |
| 699 | */ |
| 700 | shared_ptr<Transport> |
| 701 | getTransport(); |
| 702 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 703 | private: |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 704 | |
| 705 | /** |
| 706 | * @throws ConfigFile::Error on parse error and unsupported protocols |
| 707 | */ |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 708 | shared_ptr<Transport> |
| 709 | makeDefaultTransport(); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 710 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 711 | /** |
| 712 | * @throws Face::Error on unsupported protocol |
Junxiao Shi | 2cced06 | 2014-11-02 21:27:38 -0700 | [diff] [blame] | 713 | * @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] | 714 | */ |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 715 | void |
Joao Pereira | 68c0d88 | 2015-05-19 14:27:55 -0400 | [diff] [blame] | 716 | construct(shared_ptr<Transport> transport, KeyChain& keyChain); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 717 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 718 | void |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 719 | onReceiveElement(const Block& blockFromDaemon); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 720 | |
Alexander Afanasyev | 7dced46 | 2014-03-19 15:12:32 -0700 | [diff] [blame] | 721 | void |
| 722 | asyncShutdown(); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 723 | |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 724 | private: |
Junxiao Shi | 2cced06 | 2014-11-02 21:27:38 -0700 | [diff] [blame] | 725 | /// the IO service owned by this Face, could be null |
| 726 | unique_ptr<boost::asio::io_service> m_internalIoService; |
| 727 | /// the IO service used by this Face |
| 728 | boost::asio::io_service& m_ioService; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 729 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 730 | shared_ptr<Transport> m_transport; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 731 | |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 732 | /** @brief if not null, a pointer to an internal KeyChain owned by Face |
| 733 | * @note if a KeyChain is supplied to constructor, this pointer will be null, |
| 734 | * and the passed KeyChain is given to nfdController; |
| 735 | * currently Face does not keep the KeyChain passed in constructor |
| 736 | * because it's not needed, but this may change in the future |
| 737 | */ |
Joao Pereira | 68c0d88 | 2015-05-19 14:27:55 -0400 | [diff] [blame] | 738 | unique_ptr<KeyChain> m_internalKeyChain; |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 739 | |
Joao Pereira | 68c0d88 | 2015-05-19 14:27:55 -0400 | [diff] [blame] | 740 | unique_ptr<nfd::Controller> m_nfdController; |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 741 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 742 | class Impl; |
Joao Pereira | 68c0d88 | 2015-05-19 14:27:55 -0400 | [diff] [blame] | 743 | unique_ptr<Impl> m_impl; |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 744 | }; |
| 745 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 746 | } // namespace ndn |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 747 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 748 | #endif // NDN_FACE_HPP |