blob: a6cd4dac3b195c6d3723358940b2cd06536d2187 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -07002/**
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -08003 * Copyright (c) 2013-2017 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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 Thompsonaa4e6db2013-07-15 17:25:23 -070020 */
21
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070022#ifndef NDN_FACE_HPP
Jeff Thompsona0d18c92013-08-06 13:55:32 -070023#define NDN_FACE_HPP
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070024
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080025#include "common.hpp"
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070026
27#include "name.hpp"
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080028#include "interest.hpp"
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070029#include "interest-filter.hpp"
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080030#include "data.hpp"
Junxiao Shi4b469982015-12-03 18:20:19 +000031#include "encoding/nfd-constants.hpp"
Eric Newberry83872fd2015-08-06 17:01:24 -070032#include "lp/nack.hpp"
Junxiao Shi4b469982015-12-03 18:20:19 +000033#include "security/signing-info.hpp"
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080034#include "security/key-chain.hpp"
Joao Pereira0b3cac52015-07-02 14:49:49 -040035
36#define NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
37
38#ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070039#include "security/v1/identity-certificate.hpp"
Joao Pereira0b3cac52015-07-02 14:49:49 -040040#endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080041
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070042namespace boost {
43namespace asio {
44class io_service;
Alexander Afanasyev8cf1c562016-06-23 16:01:55 -070045} // namespace asio
46} // namespace boost
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080047
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070048namespace ndn {
49
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070050class Transport;
51
52class PendingInterestId;
53class RegisteredPrefixId;
54class InterestFilterId;
55
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070056namespace nfd {
57class Controller;
Alexander Afanasyev8cf1c562016-06-23 16:01:55 -070058} // namespace nfd
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070059
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -070060/**
Junxiao Shi103d8ed2016-08-07 20:34:10 +000061 * @brief Callback invoked when expressed Interest gets satisfied with a Data packet
Eric Newberry83872fd2015-08-06 17:01:24 -070062 */
63typedef function<void(const Interest&, const Data&)> DataCallback;
64
65/**
Junxiao Shi103d8ed2016-08-07 20:34:10 +000066 * @brief Callback invoked when Nack is sent in response to expressed Interest
Eric Newberry83872fd2015-08-06 17:01:24 -070067 */
68typedef function<void(const Interest&, const lp::Nack&)> NackCallback;
69
70/**
Junxiao Shi103d8ed2016-08-07 20:34:10 +000071 * @brief Callback invoked when expressed Interest times out
Eric Newberry83872fd2015-08-06 17:01:24 -070072 */
73typedef function<void(const Interest&)> TimeoutCallback;
74
75/**
Junxiao Shi103d8ed2016-08-07 20:34:10 +000076 * @brief Callback invoked when expressed Interest gets satisfied with Data packet
Eric Newberry83872fd2015-08-06 17:01:24 -070077 * @deprecated use DataCallback
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080078 */
79typedef function<void(const Interest&, Data&)> OnData;
80
81/**
Junxiao Shi103d8ed2016-08-07 20:34:10 +000082 * @brief Callback invoked when expressed Interest times out
Eric Newberry83872fd2015-08-06 17:01:24 -070083 * @deprecated use TimeoutCallback
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080084 */
85typedef function<void(const Interest&)> OnTimeout;
86
87/**
Junxiao Shi103d8ed2016-08-07 20:34:10 +000088 * @brief Callback invoked when incoming Interest matches the specified InterestFilter
89 */
90typedef 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 Afanasyev0222fba2014-02-09 23:16:02 -080095 */
Alexander Afanasyev90164962014-03-06 08:29:59 +000096typedef function<void (const InterestFilter&, const Interest&)> OnInterest;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080097
98/**
Junxiao Shi103d8ed2016-08-07 20:34:10 +000099 * @brief Callback invoked when registerPrefix or setInterestFilter command succeeds
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800100 */
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700101typedef function<void(const Name&)> RegisterPrefixSuccessCallback;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800102
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700103/**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000104 * @brief Callback invoked when registerPrefix or setInterestFilter command fails
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700105 */
106typedef function<void(const Name&, const std::string&)> RegisterPrefixFailureCallback;
107
108/**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000109 * @brief Callback invoked when unregisterPrefix or unsetInterestFilter command succeeds
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700110 */
111typedef function<void()> UnregisterPrefixSuccessCallback;
112
113/**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000114 * @brief Callback invoked when unregisterPrefix or unsetInterestFilter command fails
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700115 */
116typedef function<void(const std::string&)> UnregisterPrefixFailureCallback;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800117
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800118/**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000119 * @brief Provide a communication channel with local or remote NDN forwarder
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -0700120 */
Alexander Afanasyev8460afb2014-02-15 20:31:42 -0800121class Face : noncopyable
122{
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700123public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700124 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 Afanasyevb790d952014-01-24 12:07:53 -0800133
Junxiao Shiedd834e2014-10-28 20:28:58 -0700134public: // constructors
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800135 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000136 * @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 Afanasyev691c3ce2014-04-23 14:28:04 -0700141 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000142 * @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 Afanasyevb790d952014-01-24 12:07:53 -0800145 */
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000146 explicit
147 Face(shared_ptr<Transport> transport = nullptr);
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800148
149 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000150 * @brief Create Face using default transport and given io_service
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700151 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000152 * Usage examples:
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700153 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000154 * @code
155 * Face face1;
156 * Face face2(face1.getIoService());
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700157 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000158 * // Now the following ensures that events on both faces are processed
159 * face1.processEvents();
160 * // or face1.getIoService().run();
161 * @endcode
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700162 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000163 * or
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700164 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000165 * @code
166 * boost::asio::io_service ioService;
167 * Face face1(ioService);
168 * Face face2(ioService);
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700169 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000170 * ioService.run();
171 * @endcode
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700172 *
173 * @param ioService A reference to boost::io_service object that should control all
174 * IO operations.
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000175 * @throw ConfigFile::Error the configuration file cannot be parsed or specifies an unsupported protocol
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700176 */
177 explicit
178 Face(boost::asio::io_service& ioService);
179
180 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000181 * @brief Create Face using TcpTransport
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700182 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000183 * @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 Thompsonfe08e5a2013-08-13 11:15:59 -0700185 */
Junxiao Shiae0b4182016-08-08 22:53:17 +0000186 explicit
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800187 Face(const std::string& host, const std::string& port = "6363");
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800188
189 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000190 * @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 Afanasyev8cf1c562016-06-23 16:01:55 -0700193 * @param keyChain the KeyChain to sign commands
194 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000195 * @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 Afanasyev8cf1c562016-06-23 16:01:55 -0700199 * @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 Shi103d8ed2016-08-07 20:34:10 +0000204 * @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 Afanasyevbb64c172015-12-29 20:32:45 -0800207 * @param ioService the io_service that controls all IO operations
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800208 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700209 * @sa Face(boost::asio::io_service&)
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000210 * @sa Face(shared_ptr<Transport>)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800211 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000212 * @throw ConfigFile::Error if @p transport is nullptr, and the configuration file cannot be
213 * parsed or specifies an unsupported protocol
Alexander Afanasyev8cf1c562016-06-23 16:01:55 -0700214 * @note shared_ptr is passed by value because ownership is shared with this class
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800215 */
Alexander Afanasyev8cf1c562016-06-23 16:01:55 -0700216 Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService);
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800217
Jeff Thompson4fe45512013-08-23 14:06:38 -0700218 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000219 * @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 Shiedd834e2014-10-28 20:28:58 -0700222 * @param ioService the io_service that controls all IO operations
223 * @param keyChain the KeyChain to sign commands
Alexander Afanasyev8cf1c562016-06-23 16:01:55 -0700224 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000225 * @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 Shiedd834e2014-10-28 20:28:58 -0700230 * @note shared_ptr is passed by value because ownership is shared with this class
231 */
Alexander Afanasyev8cf1c562016-06-23 16:01:55 -0700232 Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, KeyChain& keyChain);
Junxiao Shiedd834e2014-10-28 20:28:58 -0700233
Davide Pesavento7f20d6e2017-01-16 14:43:58 -0500234 virtual
Junxiao Shiedd834e2014-10-28 20:28:58 -0700235 ~Face();
236
237public: // consumer
238 /**
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800239 * @brief Express Interest
Eric Newberry83872fd2015-08-06 17:01:24 -0700240 * @param interest the Interest; a copy will be made, so that the caller is not
241 * required to maintain the argument unchanged
242 * @param afterSatisfied function to be invoked if Data is returned
243 * @param afterNacked function to be invoked if Network NACK is returned
244 * @param afterTimeout function to be invoked if neither Data nor Network NACK
245 * is returned within InterestLifetime
246 */
247 const PendingInterestId*
248 expressInterest(const Interest& interest,
249 const DataCallback& afterSatisfied,
250 const NackCallback& afterNacked,
251 const TimeoutCallback& afterTimeout);
252
253 /**
254 * @brief Express Interest
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800255 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700256 * @param interest An Interest to be expressed
257 * @param onData Callback to be called when a matching data packet is received
Eric Newberry83872fd2015-08-06 17:01:24 -0700258 * @param onTimeout (optional) A function object to call if the interest times out or is Nacked
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800259 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700260 * @return The pending interest ID which can be used with removePendingInterest
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700261 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000262 * @throw Error when Interest size exceeds maximum limit (MAX_NDN_PACKET_SIZE)
Eric Newberry83872fd2015-08-06 17:01:24 -0700263 *
264 * @deprecated use expressInterest(Interest, DataCallback, NackCallback, TimeoutCallback)
Jeff Thompson4fe45512013-08-23 14:06:38 -0700265 */
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800266 const PendingInterestId*
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800267 expressInterest(const Interest& interest,
Eric Newberry83872fd2015-08-06 17:01:24 -0700268 const OnData& onData,
269 const OnTimeout& onTimeout = nullptr);
Jeff Thompson4fe45512013-08-23 14:06:38 -0700270
271 /**
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800272 * @brief Express Interest using name and Interest template
273 *
274 * @param name Name of the Interest
275 * @param tmpl Interest template to fill parameters
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700276 * @param onData Callback to be called when a matching data packet is received
Eric Newberry83872fd2015-08-06 17:01:24 -0700277 * @param onTimeout (optional) A function object to call if the interest times out or is Nacked
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800278 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700279 * @return Opaque pending interest ID which can be used with removePendingInterest
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700280 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000281 * @throw Error when Interest size exceeds maximum limit (MAX_NDN_PACKET_SIZE)
Eric Newberry83872fd2015-08-06 17:01:24 -0700282 *
283 * @deprecated use expressInterest(Interest, DataCallback, NackCallback, TimeoutCallback)
Jeff Thompson7aec0252013-08-22 17:29:57 -0700284 */
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800285 const PendingInterestId*
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800286 expressInterest(const Name& name,
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800287 const Interest& tmpl,
Eric Newberry83872fd2015-08-06 17:01:24 -0700288 const OnData& onData,
289 const OnTimeout& onTimeout = nullptr);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700290
Jeff Thompson11095142013-10-01 16:20:28 -0700291 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700292 * @brief Cancel previously expressed Interest
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700293 *
Jeff Thompson11095142013-10-01 16:20:28 -0700294 * @param pendingInterestId The ID returned from expressInterest.
295 */
296 void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800297 removePendingInterest(const PendingInterestId* pendingInterestId);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700298
Jeff Thompson432c8be2013-08-09 16:16:08 -0700299 /**
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500300 * @brief Cancel all previously expressed Interests
301 */
302 void
303 removeAllPendingInterests();
304
305 /**
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -0700306 * @brief Get number of pending Interests
307 */
308 size_t
309 getNPendingInterests() const;
310
Junxiao Shiedd834e2014-10-28 20:28:58 -0700311public: // producer
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -0700312 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700313 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
314 * callback and register the filtered prefix with the connected NDN forwarder
315 *
316 * This version of setInterestFilter combines setInterestFilter and registerPrefix
317 * operations and is intended to be used when only one filter for the same prefix needed
318 * to be set. When multiple names sharing the same prefix should be dispatched to
319 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
320 * a series of setInterestFilter calls.
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700321 *
Alexander Afanasyev90164962014-03-06 08:29:59 +0000322 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700323 * @param onInterest A callback to be called when a matching interest is received
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700324 * @param onFailure A callback to be called when prefixRegister command fails
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400325 * @param flags (optional) RIB flags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400326 * @param signingInfo (optional) Signing parameters. When omitted, a default parameters
327 * used in the signature will be used.
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700328 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700329 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
330 * removeRegisteredPrefix
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700331 */
332 const RegisteredPrefixId*
Alexander Afanasyev90164962014-03-06 08:29:59 +0000333 setInterestFilter(const InterestFilter& interestFilter,
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000334 const InterestCallback& onInterest,
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700335 const RegisterPrefixFailureCallback& onFailure,
Joao Pereira0b3cac52015-07-02 14:49:49 -0400336 const security::SigningInfo& signingInfo = security::SigningInfo(),
Alexander Afanasyev0866f512014-08-11 13:25:09 -0700337 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700338
339 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700340 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
341 * callback and register the filtered prefix with the connected NDN forwarder
342 *
343 * This version of setInterestFilter combines setInterestFilter and registerPrefix
344 * operations and is intended to be used when only one filter for the same prefix needed
345 * to be set. When multiple names sharing the same prefix should be dispatched to
346 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
347 * a series of setInterestFilter calls.
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700348 *
Alexander Afanasyev90164962014-03-06 08:29:59 +0000349 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700350 * @param onInterest A callback to be called when a matching interest is received
351 * @param onSuccess A callback to be called when prefixRegister command succeeds
352 * @param onFailure A callback to be called when prefixRegister command fails
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400353 * @param flags (optional) RIB flags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400354 * @param signingInfo (optional) Signing parameters. When omitted, a default parameters
355 * used in the signature will be used.
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700356 *
Joao Pereira0b3cac52015-07-02 14:49:49 -0400357 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
358 * removeRegisteredPrefix
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700359 */
360 const RegisteredPrefixId*
Alexander Afanasyev90164962014-03-06 08:29:59 +0000361 setInterestFilter(const InterestFilter& interestFilter,
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000362 const InterestCallback& onInterest,
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700363 const RegisterPrefixSuccessCallback& onSuccess,
364 const RegisterPrefixFailureCallback& onFailure,
Joao Pereira0b3cac52015-07-02 14:49:49 -0400365 const security::SigningInfo& signingInfo = security::SigningInfo(),
Alexander Afanasyev0866f512014-08-11 13:25:09 -0700366 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700367
368 /**
369 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest callback
370 *
371 * @param interestFilter Interest
372 * @param onInterest A callback to be called when a matching interest is received
373 *
374 * This method modifies library's FIB only, and does not register the prefix with the
375 * forwarder. It will always succeed. To register prefix with the forwarder, use
376 * registerPrefix, or use the setInterestFilter overload taking two callbacks.
377 *
378 * @return Opaque interest filter ID which can be used with unsetInterestFilter
379 */
380 const InterestFilterId*
381 setInterestFilter(const InterestFilter& interestFilter,
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000382 const InterestCallback& onInterest);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700383
Joao Pereira0b3cac52015-07-02 14:49:49 -0400384#ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
385 /**
386 * @deprecated Use override with SigningInfo instead of this function
387 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
388 * callback and register the filtered prefix with the connected NDN forwarder
389 *
390 * This version of setInterestFilter combines setInterestFilter and registerPrefix
391 * operations and is intended to be used when only one filter for the same prefix needed
392 * to be set. When multiple names sharing the same prefix should be dispatched to
393 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
394 * a series of setInterestFilter calls.
395 *
396 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
397 * @param onInterest A callback to be called when a matching interest is received
398 * @param onSuccess A callback to be called when prefixRegister command succeeds
399 * @param onFailure A callback to be called when prefixRegister command fails
400 * @param flags (optional) RIB flags
401 * @param certificate (optional) A certificate under which the prefix registration
402 * command is signed. When omitted, a default certificate of
403 * the default identity is used to sign the registration command
404 *
405 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
406 * removeRegisteredPrefix
407 */
philobb778e72015-08-25 14:49:19 -0700408 DEPRECATED(
Joao Pereira0b3cac52015-07-02 14:49:49 -0400409 const RegisteredPrefixId*
410 setInterestFilter(const InterestFilter& interestFilter,
411 const OnInterest& onInterest,
412 const RegisterPrefixSuccessCallback& onSuccess,
413 const RegisterPrefixFailureCallback& onFailure,
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700414 const security::v1::IdentityCertificate& certificate,
philobb778e72015-08-25 14:49:19 -0700415 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700416
417 /**
Joao Pereira0b3cac52015-07-02 14:49:49 -0400418 * @deprecated Use override with SigningInfo instead of this function
419 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
420 * callback and register the filtered prefix with the connected NDN forwarder
421 *
422 * This version of setInterestFilter combines setInterestFilter and registerPrefix
423 * operations and is intended to be used when only one filter for the same prefix needed
424 * to be set. When multiple names sharing the same prefix should be dispatched to
425 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
426 * a series of setInterestFilter calls.
427 *
428 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
429 * @param onInterest A callback to be called when a matching interest is received
430 * @param onFailure A callback to be called when prefixRegister command fails
431 * @param flags (optional) RIB flags
432 * @param certificate (optional) A certificate under which the prefix registration
433 * command is signed. When omitted, a default certificate of
434 * the default identity is used to sign the registration command
435 *
436 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
437 * removeRegisteredPrefix
438 */
philobb778e72015-08-25 14:49:19 -0700439 DEPRECATED(
Joao Pereira0b3cac52015-07-02 14:49:49 -0400440 const RegisteredPrefixId*
441 setInterestFilter(const InterestFilter& interestFilter,
442 const OnInterest& onInterest,
443 const RegisterPrefixFailureCallback& onFailure,
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700444 const security::v1::IdentityCertificate& certificate,
philobb778e72015-08-25 14:49:19 -0700445 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400446
447 /**
448 * @deprecated Use override with SigningInfo instead of this function
449 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
450 * callback and register the filtered prefix with the connected NDN forwarder
451 *
452 * This version of setInterestFilter combines setInterestFilter and registerPrefix
453 * operations and is intended to be used when only one filter for the same prefix needed
454 * to be set. When multiple names sharing the same prefix should be dispatched to
455 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
456 * a series of setInterestFilter calls.
457 *
458 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
459 * @param onInterest A callback to be called when a matching interest is received
460 * @param onSuccess A callback to be called when prefixRegister command succeeds
461 * @param onFailure A callback to be called when prefixRegister command fails
462 * @param identity A signing identity. A prefix registration command is signed
463 * under the default certificate of this identity
464 * @param flags (optional) RIB flags
465 *
466 * @return Opaque registered prefix ID which can be used with removeRegisteredPrefix
467 */
philobb778e72015-08-25 14:49:19 -0700468 DEPRECATED(
Joao Pereira0b3cac52015-07-02 14:49:49 -0400469 const RegisteredPrefixId*
470 setInterestFilter(const InterestFilter& interestFilter,
471 const OnInterest& onInterest,
472 const RegisterPrefixSuccessCallback& onSuccess,
473 const RegisterPrefixFailureCallback& onFailure,
474 const Name& identity,
philobb778e72015-08-25 14:49:19 -0700475 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400476
477 /**
478 * @deprecated Use override with SigningInfo instead of this function
479 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
480 * callback and register the filtered prefix with the connected NDN forwarder
481 *
482 * This version of setInterestFilter combines setInterestFilter and registerPrefix
483 * operations and is intended to be used when only one filter for the same prefix needed
484 * to be set. When multiple names sharing the same prefix should be dispatched to
485 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
486 * a series of setInterestFilter calls.
487 *
488 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
489 * @param onInterest A callback to be called when a matching interest is received
490 * @param onFailure A callback to be called when prefixRegister command fails
491 * @param identity A signing identity. A prefix registration command is signed
492 * under the default certificate of this identity
493 * @param flags (optional) RIB flags
494 *
495 * @return Opaque registered prefix ID which can be used with removeRegisteredPrefix
496 */
philobb778e72015-08-25 14:49:19 -0700497 DEPRECATED(
Joao Pereira0b3cac52015-07-02 14:49:49 -0400498 const RegisteredPrefixId*
499 setInterestFilter(const InterestFilter& interestFilter,
500 const OnInterest& onInterest,
501 const RegisterPrefixFailureCallback& onFailure,
502 const Name& identity,
philobb778e72015-08-25 14:49:19 -0700503 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400504#endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
505
506 /**
507 * @brief Register prefix with the connected NDN forwarder
508 *
509 * This method only modifies forwarder's RIB and does not associate any
510 * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to
511 * the right callbacks.
512 *
513 * @param prefix A prefix to register with the connected NDN forwarder
514 * @param onSuccess A callback to be called when prefixRegister command succeeds
515 * @param onFailure A callback to be called when prefixRegister command fails
516 * @param signingInfo (optional) Signing parameters. When omitted, a default parameters
517 * used in the signature will be used.
Alexander Afanasyevf2a46222015-09-17 18:01:30 -0700518 * @param flags Prefix registration flags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400519 *
520 * @return The registered prefix ID which can be used with unregisterPrefix
Alexander Afanasyevf2a46222015-09-17 18:01:30 -0700521 * @see nfd::RouteFlags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400522 */
523 const RegisteredPrefixId*
524 registerPrefix(const Name& prefix,
525 const RegisterPrefixSuccessCallback& onSuccess,
526 const RegisterPrefixFailureCallback& onFailure,
527 const security::SigningInfo& signingInfo = security::SigningInfo(),
528 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
529
530#ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
531 /**
532 * @deprecated Use override with SigningInfo instead of this function
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700533 * @brief Register prefix with the connected NDN forwarder
534 *
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400535 * This method only modifies forwarder's RIB and does not associate any
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700536 * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to
537 * the right callbacks.
538 *
539 * @param prefix A prefix to register with the connected NDN forwarder
540 * @param onSuccess A callback to be called when prefixRegister command succeeds
541 * @param onFailure A callback to be called when prefixRegister command fails
542 * @param certificate (optional) A certificate under which the prefix registration
Junxiao Shi6a90f372014-10-13 20:29:30 -0700543 * command is signed. When omitted, a default certificate of
544 * the default identity is used to sign the registration command
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400545 * @param flags (optional) RIB flags
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700546 *
547 * @return The registered prefix ID which can be used with unregisterPrefix
548 */
philobb778e72015-08-25 14:49:19 -0700549 DEPRECATED(
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700550 const RegisteredPrefixId*
551 registerPrefix(const Name& prefix,
552 const RegisterPrefixSuccessCallback& onSuccess,
553 const RegisterPrefixFailureCallback& onFailure,
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700554 const security::v1::IdentityCertificate& certificate,
philobb778e72015-08-25 14:49:19 -0700555 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700556
557 /**
Joao Pereira0b3cac52015-07-02 14:49:49 -0400558 * @deprecated Use override with SigningInfo instead of this function
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700559 * @brief Register prefix with the connected NDN forwarder and call onInterest when a matching
560 * interest is received.
561 *
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400562 * This method only modifies forwarder's RIB and does not associate any
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700563 * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to
564 * the right callbacks.
565 *
566 * @param prefix A prefix to register with the connected NDN forwarder
567 * @param onSuccess A callback to be called when prefixRegister command succeeds
568 * @param onFailure A callback to be called when prefixRegister command fails
Junxiao Shi6a90f372014-10-13 20:29:30 -0700569 * @param identity A signing identity. A prefix registration command is signed
570 * under the default certificate of this identity
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400571 * @param flags (optional) RIB flags
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700572 *
573 * @return The registered prefix ID which can be used with unregisterPrefix
574 */
philobb778e72015-08-25 14:49:19 -0700575 DEPRECATED(
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700576 const RegisteredPrefixId*
577 registerPrefix(const Name& prefix,
578 const RegisterPrefixSuccessCallback& onSuccess,
579 const RegisterPrefixFailureCallback& onFailure,
Alexander Afanasyev0866f512014-08-11 13:25:09 -0700580 const Name& identity,
philobb778e72015-08-25 14:49:19 -0700581 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400582#endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700583
584 /**
Alexander Afanasyev1b01c312014-05-26 16:58:10 +0300585 * @brief Remove the registered prefix entry with the registeredPrefixId
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700586 *
587 * This does not affect another registered prefix with a different registeredPrefixId,
588 * even it if has the same prefix name. If there is no entry with the
589 * registeredPrefixId, do nothing.
590 *
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700591 * unsetInterestFilter will use the same credentials as original
592 * setInterestFilter/registerPrefix command
593 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700594 * @param registeredPrefixId The ID returned from registerPrefix
Jeff Thompson11095142013-10-01 16:20:28 -0700595 */
596 void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800597 unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId);
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800598
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700599 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700600 * @brief Remove previously set InterestFilter from library's FIB
601 *
602 * This method always succeeds and will **NOT** send any request to the connected
603 * forwarder.
604 *
605 * @param interestFilterId The ID returned from setInterestFilter.
606 */
607 void
608 unsetInterestFilter(const InterestFilterId* interestFilterId);
609
610 /**
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400611 * @brief Unregister prefix from RIB
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700612 *
613 * unregisterPrefix will use the same credentials as original
614 * setInterestFilter/registerPrefix command
615 *
616 * If registeredPrefixId was obtained using setInterestFilter, the corresponding
617 * InterestFilter will be unset too.
618 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700619 * @param registeredPrefixId The ID returned from registerPrefix
620 * @param onSuccess Callback to be called when operation succeeds
621 * @param onFailure Callback to be called when operation fails
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700622 */
623 void
624 unregisterPrefix(const RegisteredPrefixId* registeredPrefixId,
625 const UnregisterPrefixSuccessCallback& onSuccess,
626 const UnregisterPrefixFailureCallback& onFailure);
627
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800628 /**
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800629 * @brief Publish data packet
630 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700631 * This method can be called to satisfy the incoming Interest or to put Data packet into
Alexander Afanasyev6a05b4b2014-07-18 17:23:00 -0700632 * the cache of the local NDN forwarder.
633 *
634 * @param data Data packet to publish. It is highly recommended to use Data packet that
635 * was created using make_shared<Data>(...). Otherwise, put() will make an
636 * extra copy of the Data packet to ensure validity of published Data until
637 * asynchronous put() operation finishes.
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700638 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000639 * @throw Error when Data size exceeds maximum limit (MAX_NDN_PACKET_SIZE)
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800640 */
641 void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800642 put(const Data& data);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700643
Eric Newberry83872fd2015-08-06 17:01:24 -0700644 /**
645 * @brief sends a Network NACK
646 * @param nack the Nack; a copy will be made, so that the caller is not required to
647 * maintain the argument unchanged
648 */
649 void
650 put(const lp::Nack& nack);
651
Junxiao Shiedd834e2014-10-28 20:28:58 -0700652public: // IO routine
Jeff Thompson86507bc2013-08-23 20:51:38 -0700653 /**
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700654 * @brief Process any data to receive or call timeout callbacks.
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800655 *
656 * This call will block forever (default timeout == 0) to process IO on the face.
657 * To exit, one expected to call face.shutdown() from one of the callback methods.
658 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700659 * If positive timeout is specified, then processEvents will exit after this timeout, if
660 * not stopped earlier with face.shutdown() or when all active events finish. The call
661 * can be called repeatedly, if desired.
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800662 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700663 * If negative timeout is specified, then processEvents will not block and process only
664 * pending events.
Alexander Afanasyevf75a0aa2014-01-09 14:29:22 -0800665 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700666 * @param timeout maximum time to block the thread
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700667 * @param keepThread Keep thread in a blocked state (in event processing), even when
668 * there are no outstanding events (e.g., no Interest/Data is expected)
669 *
670 * @throw This may throw an exception for reading data or in the callback for processing
671 * the data. If you call this from an main event loop, you may want to catch and
672 * log/disregard all exceptions.
Jeff Thompson432c8be2013-08-09 16:16:08 -0700673 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700674 void
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700675 processEvents(const time::milliseconds& timeout = time::milliseconds::zero(),
Junxiao Shic828dfc2016-09-15 13:26:22 +0000676 bool keepThread = false)
677 {
678 this->doProcessEvents(timeout, keepThread);
679 }
Jeff Thompson432c8be2013-08-09 16:16:08 -0700680
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700681 /**
682 * @brief Shutdown face operations
683 *
684 * This method cancels all pending operations and closes connection to NDN Forwarder.
685 *
686 * Note that this method does not stop IO service and if the same IO service is shared
687 * between multiple Faces or with other IO objects (e.g., Scheduler).
688 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700689 void
Jeff Thompson0050abe2013-09-17 12:50:25 -0700690 shutdown();
Yingdi Yu0d920812014-01-30 14:50:57 -0800691
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700692 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000693 * @return reference to IO service object
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700694 */
695 boost::asio::io_service&
696 getIoService()
697 {
Junxiao Shi2cced062014-11-02 21:27:38 -0700698 return m_ioService;
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700699 }
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800700
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800701NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
702 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000703 * @return underlying transport
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800704 */
705 shared_ptr<Transport>
706 getTransport();
707
Junxiao Shic828dfc2016-09-15 13:26:22 +0000708protected:
709 virtual void
710 doProcessEvents(const time::milliseconds& timeout, bool keepThread);
711
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800712private:
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -0700713 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000714 * @throw ConfigFile::Error on parse error and unsupported protocols
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -0700715 */
Alexander Afanasyevbb64c172015-12-29 20:32:45 -0800716 shared_ptr<Transport>
717 makeDefaultTransport();
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -0700718
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600719 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000720 * @throw Face::Error on unsupported protocol
Junxiao Shi2cced062014-11-02 21:27:38 -0700721 * @note shared_ptr is passed by value because ownership is transferred to this function
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600722 */
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800723 void
Joao Pereira68c0d882015-05-19 14:27:55 -0400724 construct(shared_ptr<Transport> transport, KeyChain& keyChain);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600725
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700726 void
Eric Newberry83872fd2015-08-06 17:01:24 -0700727 onReceiveElement(const Block& blockFromDaemon);
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800728
Alexander Afanasyev7dced462014-03-19 15:12:32 -0700729 void
730 asyncShutdown();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700731
Jeff Thompsonb982b6d2013-07-15 18:15:45 -0700732private:
Junxiao Shi2cced062014-11-02 21:27:38 -0700733 /// the IO service owned by this Face, could be null
734 unique_ptr<boost::asio::io_service> m_internalIoService;
735 /// the IO service used by this Face
736 boost::asio::io_service& m_ioService;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700737
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800738 shared_ptr<Transport> m_transport;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800739
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000740 /**
741 * @brief if not null, a pointer to an internal KeyChain owned by Face
742 * @note if a KeyChain is supplied to constructor, this pointer will be null,
743 * and the passed KeyChain is given to nfdController;
744 * currently Face does not keep the KeyChain passed in constructor
745 * because it's not needed, but this may change in the future
Junxiao Shiedd834e2014-10-28 20:28:58 -0700746 */
Joao Pereira68c0d882015-05-19 14:27:55 -0400747 unique_ptr<KeyChain> m_internalKeyChain;
Junxiao Shiedd834e2014-10-28 20:28:58 -0700748
Joao Pereira68c0d882015-05-19 14:27:55 -0400749 unique_ptr<nfd::Controller> m_nfdController;
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600750
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -0700751 class Impl;
Junxiao Shiae0b4182016-08-08 22:53:17 +0000752 shared_ptr<Impl> m_impl;
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700753};
754
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800755} // namespace ndn
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700756
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800757#endif // NDN_FACE_HPP