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