blob: 9c6ccb0d941ffc9934f7615887ddf599a1b17d35 [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 Afanasyev9d158f02015-02-17 21:30:19 -08003 * Copyright (c) 2013-2015 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"
Joao Pereira0b3cac52015-07-02 14:49:49 -040031#include "security/signing-info.hpp"
32
33#define NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
34
35#ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
Alexander Afanasyev984ad192014-05-02 19:11:15 -070036#include "security/identity-certificate.hpp"
Joao Pereira0b3cac52015-07-02 14:49:49 -040037#endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080038
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070039namespace boost {
40namespace asio {
41class io_service;
42}
43}
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080044
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070045namespace ndn {
46
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070047class Transport;
48
49class PendingInterestId;
50class RegisteredPrefixId;
51class InterestFilterId;
52
Yingdi Yu1b0311c2015-06-10 14:58:47 -070053namespace security {
54class KeyChain;
55}
56using security::KeyChain;
57
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070058namespace nfd {
59class Controller;
60}
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070061
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -070062/**
Alexander Afanasyev984ad192014-05-02 19:11:15 -070063 * @brief Callback called when expressed Interest gets satisfied with Data packet
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080064 */
65typedef function<void(const Interest&, Data&)> OnData;
66
67/**
Alexander Afanasyev984ad192014-05-02 19:11:15 -070068 * @brief Callback called when expressed Interest times out
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080069 */
70typedef function<void(const Interest&)> OnTimeout;
71
72/**
Alexander Afanasyev984ad192014-05-02 19:11:15 -070073 * @brief Callback called when incoming Interest matches the specified InterestFilter
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080074 */
Alexander Afanasyev90164962014-03-06 08:29:59 +000075typedef function<void (const InterestFilter&, const Interest&)> OnInterest;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080076
77/**
Alexander Afanasyev984ad192014-05-02 19:11:15 -070078 * @brief Callback called when registerPrefix or setInterestFilter command succeeds
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080079 */
Alexander Afanasyev984ad192014-05-02 19:11:15 -070080typedef function<void(const Name&)> RegisterPrefixSuccessCallback;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080081
Alexander Afanasyev984ad192014-05-02 19:11:15 -070082/**
83 * @brief Callback called when registerPrefix or setInterestFilter command fails
84 */
85typedef function<void(const Name&, const std::string&)> RegisterPrefixFailureCallback;
86
87/**
88 * @brief Callback called when unregisterPrefix or unsetInterestFilter command succeeds
89 */
90typedef function<void()> UnregisterPrefixSuccessCallback;
91
92/**
93 * @brief Callback called when unregisterPrefix or unsetInterestFilter command fails
94 */
95typedef function<void(const std::string&)> UnregisterPrefixFailureCallback;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080096
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080097/**
98 * @brief Abstraction to communicate with local or remote NDN forwarder
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -070099 */
Alexander Afanasyev8460afb2014-02-15 20:31:42 -0800100class Face : noncopyable
101{
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700102public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700103 class Error : public std::runtime_error
104 {
105 public:
106 explicit
107 Error(const std::string& what)
108 : std::runtime_error(what)
109 {
110 }
111 };
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800112
Junxiao Shiedd834e2014-10-28 20:28:58 -0700113public: // constructors
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800114 /**
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700115 * @brief Create a new Face using the default transport (UnixTransport)
116 *
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600117 * @throws ConfigFile::Error on configuration file parse failure
118 * @throws Face::Error on unsupported protocol
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800119 */
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -0800120 Face();
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800121
122 /**
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700123 * @brief Create a new Face using the default transport (UnixTransport)
124 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700125 * @par Usage examples:
126 *
127 * Face face1;
128 * Face face2(face1.getIoService());
129 *
130 * // Now the following ensures that events on both faces are processed
131 * face1.processEvents();
132 * // or face1.getIoService().run();
133 *
134 * @par or
135 *
136 * boost::asio::io_service ioService;
137 * Face face1(ioService);
138 * Face face2(ioService);
139 * ...
140 *
141 * ioService.run();
142 *
143 * @param ioService A reference to boost::io_service object that should control all
144 * IO operations.
145 * @throws ConfigFile::Error on configuration file parse failure
146 * @throws Face::Error on unsupported protocol
147 */
148 explicit
149 Face(boost::asio::io_service& ioService);
150
Junxiao Shiedd834e2014-10-28 20:28:58 -0700151 ~Face();
152
153public: // consumer
154 /**
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800155 * @brief Express Interest
156 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700157 * @param interest An Interest to be expressed
158 * @param onData Callback to be called when a matching data packet is received
159 * @param onTimeout (optional) A function object to call if the interest times out
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800160 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700161 * @return The pending interest ID which can be used with removePendingInterest
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700162 *
163 * @throws Error when Interest size exceeds maximum limit (MAX_NDN_PACKET_SIZE)
Jeff Thompson4fe45512013-08-23 14:06:38 -0700164 */
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800165 const PendingInterestId*
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800166 expressInterest(const Interest& interest,
167 const OnData& onData, const OnTimeout& onTimeout = OnTimeout());
Jeff Thompson4fe45512013-08-23 14:06:38 -0700168
169 /**
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800170 * @brief Express Interest using name and Interest template
171 *
172 * @param name Name of the Interest
173 * @param tmpl Interest template to fill parameters
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700174 * @param onData Callback to be called when a matching data packet is received
175 * @param onTimeout (optional) A function object to call if the interest times out
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800176 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700177 * @return Opaque pending interest ID which can be used with removePendingInterest
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700178 *
179 * @throws Error when Interest size exceeds maximum limit (MAX_NDN_PACKET_SIZE)
Jeff Thompson7aec0252013-08-22 17:29:57 -0700180 */
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800181 const PendingInterestId*
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800182 expressInterest(const Name& name,
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800183 const Interest& tmpl,
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800184 const OnData& onData, const OnTimeout& onTimeout = OnTimeout());
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700185
Jeff Thompson11095142013-10-01 16:20:28 -0700186 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700187 * @brief Cancel previously expressed Interest
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700188 *
Jeff Thompson11095142013-10-01 16:20:28 -0700189 * @param pendingInterestId The ID returned from expressInterest.
190 */
191 void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800192 removePendingInterest(const PendingInterestId* pendingInterestId);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700193
Jeff Thompson432c8be2013-08-09 16:16:08 -0700194 /**
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -0700195 * @brief Get number of pending Interests
196 */
197 size_t
198 getNPendingInterests() const;
199
Junxiao Shiedd834e2014-10-28 20:28:58 -0700200public: // producer
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -0700201 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700202 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
203 * callback and register the filtered prefix with the connected NDN forwarder
204 *
205 * This version of setInterestFilter combines setInterestFilter and registerPrefix
206 * operations and is intended to be used when only one filter for the same prefix needed
207 * to be set. When multiple names sharing the same prefix should be dispatched to
208 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
209 * a series of setInterestFilter calls.
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700210 *
Alexander Afanasyev90164962014-03-06 08:29:59 +0000211 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700212 * @param onInterest A callback to be called when a matching interest is received
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700213 * @param onFailure A callback to be called when prefixRegister command fails
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400214 * @param flags (optional) RIB flags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400215 * @param signingInfo (optional) Signing parameters. When omitted, a default parameters
216 * used in the signature will be used.
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700217 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700218 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
219 * removeRegisteredPrefix
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700220 */
221 const RegisteredPrefixId*
Alexander Afanasyev90164962014-03-06 08:29:59 +0000222 setInterestFilter(const InterestFilter& interestFilter,
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700223 const OnInterest& onInterest,
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700224 const RegisterPrefixFailureCallback& onFailure,
Joao Pereira0b3cac52015-07-02 14:49:49 -0400225 const security::SigningInfo& signingInfo = security::SigningInfo(),
Alexander Afanasyev0866f512014-08-11 13:25:09 -0700226 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700227
228 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700229 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
230 * callback and register the filtered prefix with the connected NDN forwarder
231 *
232 * This version of setInterestFilter combines setInterestFilter and registerPrefix
233 * operations and is intended to be used when only one filter for the same prefix needed
234 * to be set. When multiple names sharing the same prefix should be dispatched to
235 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
236 * a series of setInterestFilter calls.
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700237 *
Alexander Afanasyev90164962014-03-06 08:29:59 +0000238 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700239 * @param onInterest A callback to be called when a matching interest is received
240 * @param onSuccess A callback to be called when prefixRegister command succeeds
241 * @param onFailure A callback to be called when prefixRegister command fails
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400242 * @param flags (optional) RIB flags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400243 * @param signingInfo (optional) Signing parameters. When omitted, a default parameters
244 * used in the signature will be used.
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700245 *
Joao Pereira0b3cac52015-07-02 14:49:49 -0400246 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
247 * removeRegisteredPrefix
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700248 */
249 const RegisteredPrefixId*
Alexander Afanasyev90164962014-03-06 08:29:59 +0000250 setInterestFilter(const InterestFilter& interestFilter,
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700251 const OnInterest& onInterest,
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700252 const RegisterPrefixSuccessCallback& onSuccess,
253 const RegisterPrefixFailureCallback& onFailure,
Joao Pereira0b3cac52015-07-02 14:49:49 -0400254 const security::SigningInfo& signingInfo = security::SigningInfo(),
Alexander Afanasyev0866f512014-08-11 13:25:09 -0700255 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700256
257 /**
258 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest callback
259 *
260 * @param interestFilter Interest
261 * @param onInterest A callback to be called when a matching interest is received
262 *
263 * This method modifies library's FIB only, and does not register the prefix with the
264 * forwarder. It will always succeed. To register prefix with the forwarder, use
265 * registerPrefix, or use the setInterestFilter overload taking two callbacks.
266 *
267 * @return Opaque interest filter ID which can be used with unsetInterestFilter
268 */
269 const InterestFilterId*
270 setInterestFilter(const InterestFilter& interestFilter,
271 const OnInterest& onInterest);
272
Joao Pereira0b3cac52015-07-02 14:49:49 -0400273#ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
274 /**
275 * @deprecated Use override with SigningInfo instead of this function
276 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
277 * callback and register the filtered prefix with the connected NDN forwarder
278 *
279 * This version of setInterestFilter combines setInterestFilter and registerPrefix
280 * operations and is intended to be used when only one filter for the same prefix needed
281 * to be set. When multiple names sharing the same prefix should be dispatched to
282 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
283 * a series of setInterestFilter calls.
284 *
285 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
286 * @param onInterest A callback to be called when a matching interest is received
287 * @param onSuccess A callback to be called when prefixRegister command succeeds
288 * @param onFailure A callback to be called when prefixRegister command fails
289 * @param flags (optional) RIB flags
290 * @param certificate (optional) A certificate under which the prefix registration
291 * command is signed. When omitted, a default certificate of
292 * the default identity is used to sign the registration command
293 *
294 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
295 * removeRegisteredPrefix
296 */
297 const RegisteredPrefixId*
298 setInterestFilter(const InterestFilter& interestFilter,
299 const OnInterest& onInterest,
300 const RegisterPrefixSuccessCallback& onSuccess,
301 const RegisterPrefixFailureCallback& onFailure,
302 const IdentityCertificate& certificate,
303 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700304
305 /**
Joao Pereira0b3cac52015-07-02 14:49:49 -0400306 * @deprecated Use override with SigningInfo instead of this function
307 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
308 * callback and register the filtered prefix with the connected NDN forwarder
309 *
310 * This version of setInterestFilter combines setInterestFilter and registerPrefix
311 * operations and is intended to be used when only one filter for the same prefix needed
312 * to be set. When multiple names sharing the same prefix should be dispatched to
313 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
314 * a series of setInterestFilter calls.
315 *
316 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
317 * @param onInterest A callback to be called when a matching interest is received
318 * @param onFailure A callback to be called when prefixRegister command fails
319 * @param flags (optional) RIB flags
320 * @param certificate (optional) A certificate under which the prefix registration
321 * command is signed. When omitted, a default certificate of
322 * the default identity is used to sign the registration command
323 *
324 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
325 * removeRegisteredPrefix
326 */
327 const RegisteredPrefixId*
328 setInterestFilter(const InterestFilter& interestFilter,
329 const OnInterest& onInterest,
330 const RegisterPrefixFailureCallback& onFailure,
331 const IdentityCertificate& certificate,
332 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
333
334 /**
335 * @deprecated Use override with SigningInfo instead of this function
336 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
337 * callback and register the filtered prefix with the connected NDN forwarder
338 *
339 * This version of setInterestFilter combines setInterestFilter and registerPrefix
340 * operations and is intended to be used when only one filter for the same prefix needed
341 * to be set. When multiple names sharing the same prefix should be dispatched to
342 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
343 * a series of setInterestFilter calls.
344 *
345 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
346 * @param onInterest A callback to be called when a matching interest is received
347 * @param onSuccess A callback to be called when prefixRegister command succeeds
348 * @param onFailure A callback to be called when prefixRegister command fails
349 * @param identity A signing identity. A prefix registration command is signed
350 * under the default certificate of this identity
351 * @param flags (optional) RIB flags
352 *
353 * @return Opaque registered prefix ID which can be used with removeRegisteredPrefix
354 */
355 const RegisteredPrefixId*
356 setInterestFilter(const InterestFilter& interestFilter,
357 const OnInterest& onInterest,
358 const RegisterPrefixSuccessCallback& onSuccess,
359 const RegisterPrefixFailureCallback& onFailure,
360 const Name& identity,
361 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
362
363 /**
364 * @deprecated Use override with SigningInfo instead of this function
365 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
366 * callback and register the filtered prefix with the connected NDN forwarder
367 *
368 * This version of setInterestFilter combines setInterestFilter and registerPrefix
369 * operations and is intended to be used when only one filter for the same prefix needed
370 * to be set. When multiple names sharing the same prefix should be dispatched to
371 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
372 * a series of setInterestFilter calls.
373 *
374 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
375 * @param onInterest A callback to be called when a matching interest is received
376 * @param onFailure A callback to be called when prefixRegister command fails
377 * @param identity A signing identity. A prefix registration command is signed
378 * under the default certificate of this identity
379 * @param flags (optional) RIB flags
380 *
381 * @return Opaque registered prefix ID which can be used with removeRegisteredPrefix
382 */
383 const RegisteredPrefixId*
384 setInterestFilter(const InterestFilter& interestFilter,
385 const OnInterest& onInterest,
386 const RegisterPrefixFailureCallback& onFailure,
387 const Name& identity,
388 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
389#endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
390
391 /**
392 * @brief Register prefix with the connected NDN forwarder
393 *
394 * This method only modifies forwarder's RIB and does not associate any
395 * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to
396 * the right callbacks.
397 *
398 * @param prefix A prefix to register with the connected NDN forwarder
399 * @param onSuccess A callback to be called when prefixRegister command succeeds
400 * @param onFailure A callback to be called when prefixRegister command fails
401 * @param signingInfo (optional) Signing parameters. When omitted, a default parameters
402 * used in the signature will be used.
403 *
404 * @return The registered prefix ID which can be used with unregisterPrefix
405 */
406 const RegisteredPrefixId*
407 registerPrefix(const Name& prefix,
408 const RegisterPrefixSuccessCallback& onSuccess,
409 const RegisterPrefixFailureCallback& onFailure,
410 const security::SigningInfo& signingInfo = security::SigningInfo(),
411 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
412
413#ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
414 /**
415 * @deprecated Use override with SigningInfo instead of this function
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700416 * @brief Register prefix with the connected NDN forwarder
417 *
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400418 * This method only modifies forwarder's RIB and does not associate any
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700419 * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to
420 * the right callbacks.
421 *
422 * @param prefix A prefix to register with the connected NDN forwarder
423 * @param onSuccess A callback to be called when prefixRegister command succeeds
424 * @param onFailure A callback to be called when prefixRegister command fails
425 * @param certificate (optional) A certificate under which the prefix registration
Junxiao Shi6a90f372014-10-13 20:29:30 -0700426 * command is signed. When omitted, a default certificate of
427 * the default identity is used to sign the registration command
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400428 * @param flags (optional) RIB flags
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700429 *
430 * @return The registered prefix ID which can be used with unregisterPrefix
431 */
432 const RegisteredPrefixId*
433 registerPrefix(const Name& prefix,
434 const RegisterPrefixSuccessCallback& onSuccess,
435 const RegisterPrefixFailureCallback& onFailure,
Joao Pereira0b3cac52015-07-02 14:49:49 -0400436 const IdentityCertificate& certificate,
Alexander Afanasyev0866f512014-08-11 13:25:09 -0700437 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700438
439 /**
Joao Pereira0b3cac52015-07-02 14:49:49 -0400440 * @deprecated Use override with SigningInfo instead of this function
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700441 * @brief Register prefix with the connected NDN forwarder and call onInterest when a matching
442 * interest is received.
443 *
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400444 * This method only modifies forwarder's RIB and does not associate any
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700445 * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to
446 * the right callbacks.
447 *
448 * @param prefix A prefix to register with the connected NDN forwarder
449 * @param onSuccess A callback to be called when prefixRegister command succeeds
450 * @param onFailure A callback to be called when prefixRegister command fails
Junxiao Shi6a90f372014-10-13 20:29:30 -0700451 * @param identity A signing identity. A prefix registration command is signed
452 * under the default certificate of this identity
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400453 * @param flags (optional) RIB flags
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700454 *
455 * @return The registered prefix ID which can be used with unregisterPrefix
456 */
457 const RegisteredPrefixId*
458 registerPrefix(const Name& prefix,
459 const RegisterPrefixSuccessCallback& onSuccess,
460 const RegisterPrefixFailureCallback& onFailure,
Alexander Afanasyev0866f512014-08-11 13:25:09 -0700461 const Name& identity,
462 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400463#endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700464
465 /**
Alexander Afanasyev1b01c312014-05-26 16:58:10 +0300466 * @brief Remove the registered prefix entry with the registeredPrefixId
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700467 *
468 * This does not affect another registered prefix with a different registeredPrefixId,
469 * even it if has the same prefix name. If there is no entry with the
470 * registeredPrefixId, do nothing.
471 *
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700472 * unsetInterestFilter will use the same credentials as original
473 * setInterestFilter/registerPrefix command
474 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700475 * @param registeredPrefixId The ID returned from registerPrefix
Jeff Thompson11095142013-10-01 16:20:28 -0700476 */
477 void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800478 unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId);
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800479
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700480 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700481 * @brief Remove previously set InterestFilter from library's FIB
482 *
483 * This method always succeeds and will **NOT** send any request to the connected
484 * forwarder.
485 *
486 * @param interestFilterId The ID returned from setInterestFilter.
487 */
488 void
489 unsetInterestFilter(const InterestFilterId* interestFilterId);
490
491 /**
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400492 * @brief Unregister prefix from RIB
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700493 *
494 * unregisterPrefix will use the same credentials as original
495 * setInterestFilter/registerPrefix command
496 *
497 * If registeredPrefixId was obtained using setInterestFilter, the corresponding
498 * InterestFilter will be unset too.
499 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700500 * @param registeredPrefixId The ID returned from registerPrefix
501 * @param onSuccess Callback to be called when operation succeeds
502 * @param onFailure Callback to be called when operation fails
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700503 */
504 void
505 unregisterPrefix(const RegisteredPrefixId* registeredPrefixId,
506 const UnregisterPrefixSuccessCallback& onSuccess,
507 const UnregisterPrefixFailureCallback& onFailure);
508
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800509 /**
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800510 * @brief Publish data packet
511 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700512 * This method can be called to satisfy the incoming Interest or to put Data packet into
Alexander Afanasyev6a05b4b2014-07-18 17:23:00 -0700513 * the cache of the local NDN forwarder.
514 *
515 * @param data Data packet to publish. It is highly recommended to use Data packet that
516 * was created using make_shared<Data>(...). Otherwise, put() will make an
517 * extra copy of the Data packet to ensure validity of published Data until
518 * asynchronous put() operation finishes.
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700519 *
520 * @throws Error when Data size exceeds maximum limit (MAX_NDN_PACKET_SIZE)
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800521 */
522 void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800523 put(const Data& data);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700524
Junxiao Shiedd834e2014-10-28 20:28:58 -0700525public: // IO routine
Jeff Thompson86507bc2013-08-23 20:51:38 -0700526 /**
Alexander Afanasyeve9741322015-08-19 23:04:52 -0700527 * @brief Noop (kept for compatibility)
Jeff Thompson432c8be2013-08-09 16:16:08 -0700528 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700529 void
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700530 processEvents(const time::milliseconds& timeout = time::milliseconds::zero(),
531 bool keepThread = false);
Jeff Thompson432c8be2013-08-09 16:16:08 -0700532
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700533 /**
534 * @brief Shutdown face operations
535 *
536 * This method cancels all pending operations and closes connection to NDN Forwarder.
537 *
538 * Note that this method does not stop IO service and if the same IO service is shared
539 * between multiple Faces or with other IO objects (e.g., Scheduler).
540 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700541 void
Jeff Thompson0050abe2013-09-17 12:50:25 -0700542 shutdown();
Yingdi Yu0d920812014-01-30 14:50:57 -0800543
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700544 /**
Alexander Afanasyeve9741322015-08-19 23:04:52 -0700545 * @brief Return nullptr (kept for compatibility)
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700546 */
547 boost::asio::io_service&
548 getIoService()
549 {
Alexander Afanasyeve9741322015-08-19 23:04:52 -0700550 return *static_cast<boost::asio::io_service*>(nullptr);
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700551 }
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800552
553private:
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -0700554 void
Alexander Afanasyeve9741322015-08-19 23:04:52 -0700555 construct();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700556
Jeff Thompsonb982b6d2013-07-15 18:15:45 -0700557private:
Alexander Afanasyeve9741322015-08-19 23:04:52 -0700558 class Impl;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700559
Alexander Afanasyeve9741322015-08-19 23:04:52 -0700560private:
Junxiao Shiedd834e2014-10-28 20:28:58 -0700561 /** @brief if not null, a pointer to an internal KeyChain owned by Face
562 * @note if a KeyChain is supplied to constructor, this pointer will be null,
563 * and the passed KeyChain is given to nfdController;
564 * currently Face does not keep the KeyChain passed in constructor
565 * because it's not needed, but this may change in the future
566 */
Joao Pereira68c0d882015-05-19 14:27:55 -0400567 unique_ptr<KeyChain> m_internalKeyChain;
Junxiao Shiedd834e2014-10-28 20:28:58 -0700568
Joao Pereira68c0d882015-05-19 14:27:55 -0400569 unique_ptr<nfd::Controller> m_nfdController;
Joao Pereira68c0d882015-05-19 14:27:55 -0400570 unique_ptr<Impl> m_impl;
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700571};
572
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800573} // namespace ndn
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700574
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800575#endif // NDN_FACE_HPP