blob: 1940928bb278b868036afe664c5097e94dd89c77 [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
234 ~Face();
235
236public: // consumer
237 /**
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800238 * @brief Express Interest
Eric Newberry83872fd2015-08-06 17:01:24 -0700239 * @param interest the Interest; a copy will be made, so that the caller is not
240 * required to maintain the argument unchanged
241 * @param afterSatisfied function to be invoked if Data is returned
242 * @param afterNacked function to be invoked if Network NACK is returned
243 * @param afterTimeout function to be invoked if neither Data nor Network NACK
244 * is returned within InterestLifetime
245 */
246 const PendingInterestId*
247 expressInterest(const Interest& interest,
248 const DataCallback& afterSatisfied,
249 const NackCallback& afterNacked,
250 const TimeoutCallback& afterTimeout);
251
252 /**
253 * @brief Express Interest
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800254 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700255 * @param interest An Interest to be expressed
256 * @param onData Callback to be called when a matching data packet is received
Eric Newberry83872fd2015-08-06 17:01:24 -0700257 * @param onTimeout (optional) A function object to call if the interest times out or is Nacked
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800258 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700259 * @return The pending interest ID which can be used with removePendingInterest
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700260 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000261 * @throw Error when Interest size exceeds maximum limit (MAX_NDN_PACKET_SIZE)
Eric Newberry83872fd2015-08-06 17:01:24 -0700262 *
263 * @deprecated use expressInterest(Interest, DataCallback, NackCallback, TimeoutCallback)
Jeff Thompson4fe45512013-08-23 14:06:38 -0700264 */
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800265 const PendingInterestId*
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800266 expressInterest(const Interest& interest,
Eric Newberry83872fd2015-08-06 17:01:24 -0700267 const OnData& onData,
268 const OnTimeout& onTimeout = nullptr);
Jeff Thompson4fe45512013-08-23 14:06:38 -0700269
270 /**
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800271 * @brief Express Interest using name and Interest template
272 *
273 * @param name Name of the Interest
274 * @param tmpl Interest template to fill parameters
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700275 * @param onData Callback to be called when a matching data packet is received
Eric Newberry83872fd2015-08-06 17:01:24 -0700276 * @param onTimeout (optional) A function object to call if the interest times out or is Nacked
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800277 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700278 * @return Opaque pending interest ID which can be used with removePendingInterest
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700279 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000280 * @throw Error when Interest size exceeds maximum limit (MAX_NDN_PACKET_SIZE)
Eric Newberry83872fd2015-08-06 17:01:24 -0700281 *
282 * @deprecated use expressInterest(Interest, DataCallback, NackCallback, TimeoutCallback)
Jeff Thompson7aec0252013-08-22 17:29:57 -0700283 */
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800284 const PendingInterestId*
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800285 expressInterest(const Name& name,
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800286 const Interest& tmpl,
Eric Newberry83872fd2015-08-06 17:01:24 -0700287 const OnData& onData,
288 const OnTimeout& onTimeout = nullptr);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700289
Jeff Thompson11095142013-10-01 16:20:28 -0700290 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700291 * @brief Cancel previously expressed Interest
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700292 *
Jeff Thompson11095142013-10-01 16:20:28 -0700293 * @param pendingInterestId The ID returned from expressInterest.
294 */
295 void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800296 removePendingInterest(const PendingInterestId* pendingInterestId);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700297
Jeff Thompson432c8be2013-08-09 16:16:08 -0700298 /**
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500299 * @brief Cancel all previously expressed Interests
300 */
301 void
302 removeAllPendingInterests();
303
304 /**
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -0700305 * @brief Get number of pending Interests
306 */
307 size_t
308 getNPendingInterests() const;
309
Junxiao Shiedd834e2014-10-28 20:28:58 -0700310public: // producer
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -0700311 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700312 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
313 * callback and register the filtered prefix with the connected NDN forwarder
314 *
315 * This version of setInterestFilter combines setInterestFilter and registerPrefix
316 * operations and is intended to be used when only one filter for the same prefix needed
317 * to be set. When multiple names sharing the same prefix should be dispatched to
318 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
319 * a series of setInterestFilter calls.
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700320 *
Alexander Afanasyev90164962014-03-06 08:29:59 +0000321 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700322 * @param onInterest A callback to be called when a matching interest is received
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700323 * @param onFailure A callback to be called when prefixRegister command fails
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400324 * @param flags (optional) RIB flags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400325 * @param signingInfo (optional) Signing parameters. When omitted, a default parameters
326 * used in the signature will be used.
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700327 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700328 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
329 * removeRegisteredPrefix
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700330 */
331 const RegisteredPrefixId*
Alexander Afanasyev90164962014-03-06 08:29:59 +0000332 setInterestFilter(const InterestFilter& interestFilter,
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000333 const InterestCallback& onInterest,
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700334 const RegisterPrefixFailureCallback& onFailure,
Joao Pereira0b3cac52015-07-02 14:49:49 -0400335 const security::SigningInfo& signingInfo = security::SigningInfo(),
Alexander Afanasyev0866f512014-08-11 13:25:09 -0700336 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700337
338 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700339 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
340 * callback and register the filtered prefix with the connected NDN forwarder
341 *
342 * This version of setInterestFilter combines setInterestFilter and registerPrefix
343 * operations and is intended to be used when only one filter for the same prefix needed
344 * to be set. When multiple names sharing the same prefix should be dispatched to
345 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
346 * a series of setInterestFilter calls.
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700347 *
Alexander Afanasyev90164962014-03-06 08:29:59 +0000348 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700349 * @param onInterest A callback to be called when a matching interest is received
350 * @param onSuccess A callback to be called when prefixRegister command succeeds
351 * @param onFailure A callback to be called when prefixRegister command fails
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400352 * @param flags (optional) RIB flags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400353 * @param signingInfo (optional) Signing parameters. When omitted, a default parameters
354 * used in the signature will be used.
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700355 *
Joao Pereira0b3cac52015-07-02 14:49:49 -0400356 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
357 * removeRegisteredPrefix
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700358 */
359 const RegisteredPrefixId*
Alexander Afanasyev90164962014-03-06 08:29:59 +0000360 setInterestFilter(const InterestFilter& interestFilter,
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000361 const InterestCallback& onInterest,
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700362 const RegisterPrefixSuccessCallback& onSuccess,
363 const RegisterPrefixFailureCallback& onFailure,
Joao Pereira0b3cac52015-07-02 14:49:49 -0400364 const security::SigningInfo& signingInfo = security::SigningInfo(),
Alexander Afanasyev0866f512014-08-11 13:25:09 -0700365 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700366
367 /**
368 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest callback
369 *
370 * @param interestFilter Interest
371 * @param onInterest A callback to be called when a matching interest is received
372 *
373 * This method modifies library's FIB only, and does not register the prefix with the
374 * forwarder. It will always succeed. To register prefix with the forwarder, use
375 * registerPrefix, or use the setInterestFilter overload taking two callbacks.
376 *
377 * @return Opaque interest filter ID which can be used with unsetInterestFilter
378 */
379 const InterestFilterId*
380 setInterestFilter(const InterestFilter& interestFilter,
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000381 const InterestCallback& onInterest);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700382
Joao Pereira0b3cac52015-07-02 14:49:49 -0400383#ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
384 /**
385 * @deprecated Use override with SigningInfo instead of this function
386 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
387 * callback and register the filtered prefix with the connected NDN forwarder
388 *
389 * This version of setInterestFilter combines setInterestFilter and registerPrefix
390 * operations and is intended to be used when only one filter for the same prefix needed
391 * to be set. When multiple names sharing the same prefix should be dispatched to
392 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
393 * a series of setInterestFilter calls.
394 *
395 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
396 * @param onInterest A callback to be called when a matching interest is received
397 * @param onSuccess A callback to be called when prefixRegister command succeeds
398 * @param onFailure A callback to be called when prefixRegister command fails
399 * @param flags (optional) RIB flags
400 * @param certificate (optional) A certificate under which the prefix registration
401 * command is signed. When omitted, a default certificate of
402 * the default identity is used to sign the registration command
403 *
404 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
405 * removeRegisteredPrefix
406 */
philobb778e72015-08-25 14:49:19 -0700407 DEPRECATED(
Joao Pereira0b3cac52015-07-02 14:49:49 -0400408 const RegisteredPrefixId*
409 setInterestFilter(const InterestFilter& interestFilter,
410 const OnInterest& onInterest,
411 const RegisterPrefixSuccessCallback& onSuccess,
412 const RegisterPrefixFailureCallback& onFailure,
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700413 const security::v1::IdentityCertificate& certificate,
philobb778e72015-08-25 14:49:19 -0700414 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700415
416 /**
Joao Pereira0b3cac52015-07-02 14:49:49 -0400417 * @deprecated Use override with SigningInfo instead of this function
418 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
419 * callback and register the filtered prefix with the connected NDN forwarder
420 *
421 * This version of setInterestFilter combines setInterestFilter and registerPrefix
422 * operations and is intended to be used when only one filter for the same prefix needed
423 * to be set. When multiple names sharing the same prefix should be dispatched to
424 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
425 * a series of setInterestFilter calls.
426 *
427 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
428 * @param onInterest A callback to be called when a matching interest is received
429 * @param onFailure A callback to be called when prefixRegister command fails
430 * @param flags (optional) RIB flags
431 * @param certificate (optional) A certificate under which the prefix registration
432 * command is signed. When omitted, a default certificate of
433 * the default identity is used to sign the registration command
434 *
435 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
436 * removeRegisteredPrefix
437 */
philobb778e72015-08-25 14:49:19 -0700438 DEPRECATED(
Joao Pereira0b3cac52015-07-02 14:49:49 -0400439 const RegisteredPrefixId*
440 setInterestFilter(const InterestFilter& interestFilter,
441 const OnInterest& onInterest,
442 const RegisterPrefixFailureCallback& onFailure,
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700443 const security::v1::IdentityCertificate& certificate,
philobb778e72015-08-25 14:49:19 -0700444 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400445
446 /**
447 * @deprecated Use override with SigningInfo instead of this function
448 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
449 * callback and register the filtered prefix with the connected NDN forwarder
450 *
451 * This version of setInterestFilter combines setInterestFilter and registerPrefix
452 * operations and is intended to be used when only one filter for the same prefix needed
453 * to be set. When multiple names sharing the same prefix should be dispatched to
454 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
455 * a series of setInterestFilter calls.
456 *
457 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
458 * @param onInterest A callback to be called when a matching interest is received
459 * @param onSuccess A callback to be called when prefixRegister command succeeds
460 * @param onFailure A callback to be called when prefixRegister command fails
461 * @param identity A signing identity. A prefix registration command is signed
462 * under the default certificate of this identity
463 * @param flags (optional) RIB flags
464 *
465 * @return Opaque registered prefix ID which can be used with removeRegisteredPrefix
466 */
philobb778e72015-08-25 14:49:19 -0700467 DEPRECATED(
Joao Pereira0b3cac52015-07-02 14:49:49 -0400468 const RegisteredPrefixId*
469 setInterestFilter(const InterestFilter& interestFilter,
470 const OnInterest& onInterest,
471 const RegisterPrefixSuccessCallback& onSuccess,
472 const RegisterPrefixFailureCallback& onFailure,
473 const Name& identity,
philobb778e72015-08-25 14:49:19 -0700474 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400475
476 /**
477 * @deprecated Use override with SigningInfo instead of this function
478 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
479 * callback and register the filtered prefix with the connected NDN forwarder
480 *
481 * This version of setInterestFilter combines setInterestFilter and registerPrefix
482 * operations and is intended to be used when only one filter for the same prefix needed
483 * to be set. When multiple names sharing the same prefix should be dispatched to
484 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
485 * a series of setInterestFilter calls.
486 *
487 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
488 * @param onInterest A callback to be called when a matching interest is received
489 * @param onFailure A callback to be called when prefixRegister command fails
490 * @param identity A signing identity. A prefix registration command is signed
491 * under the default certificate of this identity
492 * @param flags (optional) RIB flags
493 *
494 * @return Opaque registered prefix ID which can be used with removeRegisteredPrefix
495 */
philobb778e72015-08-25 14:49:19 -0700496 DEPRECATED(
Joao Pereira0b3cac52015-07-02 14:49:49 -0400497 const RegisteredPrefixId*
498 setInterestFilter(const InterestFilter& interestFilter,
499 const OnInterest& onInterest,
500 const RegisterPrefixFailureCallback& onFailure,
501 const Name& identity,
philobb778e72015-08-25 14:49:19 -0700502 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400503#endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
504
505 /**
506 * @brief Register prefix with the connected NDN forwarder
507 *
508 * This method only modifies forwarder's RIB and does not associate any
509 * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to
510 * the right callbacks.
511 *
512 * @param prefix A prefix to register with the connected NDN forwarder
513 * @param onSuccess A callback to be called when prefixRegister command succeeds
514 * @param onFailure A callback to be called when prefixRegister command fails
515 * @param signingInfo (optional) Signing parameters. When omitted, a default parameters
516 * used in the signature will be used.
Alexander Afanasyevf2a46222015-09-17 18:01:30 -0700517 * @param flags Prefix registration flags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400518 *
519 * @return The registered prefix ID which can be used with unregisterPrefix
Alexander Afanasyevf2a46222015-09-17 18:01:30 -0700520 * @see nfd::RouteFlags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400521 */
522 const RegisteredPrefixId*
523 registerPrefix(const Name& prefix,
524 const RegisterPrefixSuccessCallback& onSuccess,
525 const RegisterPrefixFailureCallback& onFailure,
526 const security::SigningInfo& signingInfo = security::SigningInfo(),
527 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
528
529#ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
530 /**
531 * @deprecated Use override with SigningInfo instead of this function
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700532 * @brief Register prefix with the connected NDN forwarder
533 *
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400534 * This method only modifies forwarder's RIB and does not associate any
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700535 * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to
536 * the right callbacks.
537 *
538 * @param prefix A prefix to register with the connected NDN forwarder
539 * @param onSuccess A callback to be called when prefixRegister command succeeds
540 * @param onFailure A callback to be called when prefixRegister command fails
541 * @param certificate (optional) A certificate under which the prefix registration
Junxiao Shi6a90f372014-10-13 20:29:30 -0700542 * command is signed. When omitted, a default certificate of
543 * the default identity is used to sign the registration command
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400544 * @param flags (optional) RIB flags
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700545 *
546 * @return The registered prefix ID which can be used with unregisterPrefix
547 */
philobb778e72015-08-25 14:49:19 -0700548 DEPRECATED(
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700549 const RegisteredPrefixId*
550 registerPrefix(const Name& prefix,
551 const RegisterPrefixSuccessCallback& onSuccess,
552 const RegisterPrefixFailureCallback& onFailure,
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700553 const security::v1::IdentityCertificate& certificate,
philobb778e72015-08-25 14:49:19 -0700554 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700555
556 /**
Joao Pereira0b3cac52015-07-02 14:49:49 -0400557 * @deprecated Use override with SigningInfo instead of this function
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700558 * @brief Register prefix with the connected NDN forwarder and call onInterest when a matching
559 * interest is received.
560 *
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400561 * This method only modifies forwarder's RIB and does not associate any
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700562 * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to
563 * the right callbacks.
564 *
565 * @param prefix A prefix to register with the connected NDN forwarder
566 * @param onSuccess A callback to be called when prefixRegister command succeeds
567 * @param onFailure A callback to be called when prefixRegister command fails
Junxiao Shi6a90f372014-10-13 20:29:30 -0700568 * @param identity A signing identity. A prefix registration command is signed
569 * under the default certificate of this identity
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400570 * @param flags (optional) RIB flags
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700571 *
572 * @return The registered prefix ID which can be used with unregisterPrefix
573 */
philobb778e72015-08-25 14:49:19 -0700574 DEPRECATED(
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700575 const RegisteredPrefixId*
576 registerPrefix(const Name& prefix,
577 const RegisterPrefixSuccessCallback& onSuccess,
578 const RegisterPrefixFailureCallback& onFailure,
Alexander Afanasyev0866f512014-08-11 13:25:09 -0700579 const Name& identity,
philobb778e72015-08-25 14:49:19 -0700580 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400581#endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700582
583 /**
Alexander Afanasyev1b01c312014-05-26 16:58:10 +0300584 * @brief Remove the registered prefix entry with the registeredPrefixId
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700585 *
586 * This does not affect another registered prefix with a different registeredPrefixId,
587 * even it if has the same prefix name. If there is no entry with the
588 * registeredPrefixId, do nothing.
589 *
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700590 * unsetInterestFilter will use the same credentials as original
591 * setInterestFilter/registerPrefix command
592 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700593 * @param registeredPrefixId The ID returned from registerPrefix
Jeff Thompson11095142013-10-01 16:20:28 -0700594 */
595 void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800596 unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId);
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800597
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700598 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700599 * @brief Remove previously set InterestFilter from library's FIB
600 *
601 * This method always succeeds and will **NOT** send any request to the connected
602 * forwarder.
603 *
604 * @param interestFilterId The ID returned from setInterestFilter.
605 */
606 void
607 unsetInterestFilter(const InterestFilterId* interestFilterId);
608
609 /**
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400610 * @brief Unregister prefix from RIB
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700611 *
612 * unregisterPrefix will use the same credentials as original
613 * setInterestFilter/registerPrefix command
614 *
615 * If registeredPrefixId was obtained using setInterestFilter, the corresponding
616 * InterestFilter will be unset too.
617 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700618 * @param registeredPrefixId The ID returned from registerPrefix
619 * @param onSuccess Callback to be called when operation succeeds
620 * @param onFailure Callback to be called when operation fails
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700621 */
622 void
623 unregisterPrefix(const RegisteredPrefixId* registeredPrefixId,
624 const UnregisterPrefixSuccessCallback& onSuccess,
625 const UnregisterPrefixFailureCallback& onFailure);
626
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800627 /**
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800628 * @brief Publish data packet
629 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700630 * This method can be called to satisfy the incoming Interest or to put Data packet into
Alexander Afanasyev6a05b4b2014-07-18 17:23:00 -0700631 * the cache of the local NDN forwarder.
632 *
633 * @param data Data packet to publish. It is highly recommended to use Data packet that
634 * was created using make_shared<Data>(...). Otherwise, put() will make an
635 * extra copy of the Data packet to ensure validity of published Data until
636 * asynchronous put() operation finishes.
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700637 *
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000638 * @throw Error when Data size exceeds maximum limit (MAX_NDN_PACKET_SIZE)
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800639 */
640 void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800641 put(const Data& data);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700642
Eric Newberry83872fd2015-08-06 17:01:24 -0700643 /**
644 * @brief sends a Network NACK
645 * @param nack the Nack; a copy will be made, so that the caller is not required to
646 * maintain the argument unchanged
647 */
648 void
649 put(const lp::Nack& nack);
650
Junxiao Shiedd834e2014-10-28 20:28:58 -0700651public: // IO routine
Jeff Thompson86507bc2013-08-23 20:51:38 -0700652 /**
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700653 * @brief Process any data to receive or call timeout callbacks.
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800654 *
655 * This call will block forever (default timeout == 0) to process IO on the face.
656 * To exit, one expected to call face.shutdown() from one of the callback methods.
657 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700658 * If positive timeout is specified, then processEvents will exit after this timeout, if
659 * not stopped earlier with face.shutdown() or when all active events finish. The call
660 * can be called repeatedly, if desired.
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800661 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700662 * If negative timeout is specified, then processEvents will not block and process only
663 * pending events.
Alexander Afanasyevf75a0aa2014-01-09 14:29:22 -0800664 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700665 * @param timeout maximum time to block the thread
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700666 * @param keepThread Keep thread in a blocked state (in event processing), even when
667 * there are no outstanding events (e.g., no Interest/Data is expected)
668 *
669 * @throw This may throw an exception for reading data or in the callback for processing
670 * the data. If you call this from an main event loop, you may want to catch and
671 * log/disregard all exceptions.
Jeff Thompson432c8be2013-08-09 16:16:08 -0700672 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700673 void
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700674 processEvents(const time::milliseconds& timeout = time::milliseconds::zero(),
Junxiao Shic828dfc2016-09-15 13:26:22 +0000675 bool keepThread = false)
676 {
677 this->doProcessEvents(timeout, keepThread);
678 }
Jeff Thompson432c8be2013-08-09 16:16:08 -0700679
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700680 /**
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 Afanasyevfdbfc6d2014-04-14 15:12:11 -0700688 void
Jeff Thompson0050abe2013-09-17 12:50:25 -0700689 shutdown();
Yingdi Yu0d920812014-01-30 14:50:57 -0800690
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700691 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000692 * @return reference to IO service object
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700693 */
694 boost::asio::io_service&
695 getIoService()
696 {
Junxiao Shi2cced062014-11-02 21:27:38 -0700697 return m_ioService;
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700698 }
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800699
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800700NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
701 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000702 * @return underlying transport
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800703 */
704 shared_ptr<Transport>
705 getTransport();
706
Junxiao Shic828dfc2016-09-15 13:26:22 +0000707protected:
708 virtual void
709 doProcessEvents(const time::milliseconds& timeout, bool keepThread);
710
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800711private:
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -0700712 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000713 * @throw ConfigFile::Error on parse error and unsupported protocols
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -0700714 */
Alexander Afanasyevbb64c172015-12-29 20:32:45 -0800715 shared_ptr<Transport>
716 makeDefaultTransport();
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -0700717
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600718 /**
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000719 * @throw Face::Error on unsupported protocol
Junxiao Shi2cced062014-11-02 21:27:38 -0700720 * @note shared_ptr is passed by value because ownership is transferred to this function
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600721 */
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800722 void
Joao Pereira68c0d882015-05-19 14:27:55 -0400723 construct(shared_ptr<Transport> transport, KeyChain& keyChain);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600724
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700725 void
Eric Newberry83872fd2015-08-06 17:01:24 -0700726 onReceiveElement(const Block& blockFromDaemon);
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800727
Alexander Afanasyev7dced462014-03-19 15:12:32 -0700728 void
729 asyncShutdown();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700730
Jeff Thompsonb982b6d2013-07-15 18:15:45 -0700731private:
Junxiao Shi2cced062014-11-02 21:27:38 -0700732 /// the IO service owned by this Face, could be null
733 unique_ptr<boost::asio::io_service> m_internalIoService;
734 /// the IO service used by this Face
735 boost::asio::io_service& m_ioService;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700736
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800737 shared_ptr<Transport> m_transport;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800738
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000739 /**
740 * @brief if not null, a pointer to an internal KeyChain owned by Face
741 * @note if a KeyChain is supplied to constructor, this pointer will be null,
742 * and the passed KeyChain is given to nfdController;
743 * currently Face does not keep the KeyChain passed in constructor
744 * because it's not needed, but this may change in the future
Junxiao Shiedd834e2014-10-28 20:28:58 -0700745 */
Joao Pereira68c0d882015-05-19 14:27:55 -0400746 unique_ptr<KeyChain> m_internalKeyChain;
Junxiao Shiedd834e2014-10-28 20:28:58 -0700747
Joao Pereira68c0d882015-05-19 14:27:55 -0400748 unique_ptr<nfd::Controller> m_nfdController;
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600749
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -0700750 class Impl;
Junxiao Shiae0b4182016-08-08 22:53:17 +0000751 shared_ptr<Impl> m_impl;
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700752};
753
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800754} // namespace ndn
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700755
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800756#endif // NDN_FACE_HPP