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