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