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