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