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