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