blob: b6d26804984c97c54c2fa45f4af079518c18cfc6 [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"
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"
Joao Pereira0b3cac52015-07-02 14:49:49 -040034
35#define NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
36
37#ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
Alexander Afanasyev984ad192014-05-02 19:11:15 -070038#include "security/identity-certificate.hpp"
Joao Pereira0b3cac52015-07-02 14:49:49 -040039#endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080040
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070041namespace boost {
42namespace asio {
43class io_service;
44}
45}
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080046
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070047namespace ndn {
48
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070049class Transport;
50
51class PendingInterestId;
52class RegisteredPrefixId;
53class InterestFilterId;
54
Yingdi Yu1b0311c2015-06-10 14:58:47 -070055namespace security {
56class KeyChain;
57}
58using security::KeyChain;
59
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070060namespace nfd {
61class Controller;
62}
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070063
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -070064/**
Eric Newberry83872fd2015-08-06 17:01:24 -070065 * @brief Callback called when expressed Interest gets satisfied with a Data packet
66 */
67typedef function<void(const Interest&, const Data&)> DataCallback;
68
69/**
70 * @brief Callback called when Nack is sent in response to expressed Interest
71 */
72typedef function<void(const Interest&, const lp::Nack&)> NackCallback;
73
74/**
75 * @brief Callback called when expressed Interest times out
76 */
77typedef function<void(const Interest&)> TimeoutCallback;
78
79/**
Alexander Afanasyev984ad192014-05-02 19:11:15 -070080 * @brief Callback called when expressed Interest gets satisfied with Data packet
Eric Newberry83872fd2015-08-06 17:01:24 -070081 * @deprecated use DataCallback
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080082 */
83typedef function<void(const Interest&, Data&)> OnData;
84
85/**
Alexander Afanasyev984ad192014-05-02 19:11:15 -070086 * @brief Callback called when expressed Interest times out
Eric Newberry83872fd2015-08-06 17:01:24 -070087 * @deprecated use TimeoutCallback
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080088 */
89typedef function<void(const Interest&)> OnTimeout;
90
91/**
Alexander Afanasyev984ad192014-05-02 19:11:15 -070092 * @brief Callback called when incoming Interest matches the specified InterestFilter
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080093 */
Alexander Afanasyev90164962014-03-06 08:29:59 +000094typedef function<void (const InterestFilter&, const Interest&)> OnInterest;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080095
96/**
Alexander Afanasyev984ad192014-05-02 19:11:15 -070097 * @brief Callback called when registerPrefix or setInterestFilter command succeeds
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080098 */
Alexander Afanasyev984ad192014-05-02 19:11:15 -070099typedef function<void(const Name&)> RegisterPrefixSuccessCallback;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800100
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700101/**
102 * @brief Callback called when registerPrefix or setInterestFilter command fails
103 */
104typedef function<void(const Name&, const std::string&)> RegisterPrefixFailureCallback;
105
106/**
107 * @brief Callback called when unregisterPrefix or unsetInterestFilter command succeeds
108 */
109typedef function<void()> UnregisterPrefixSuccessCallback;
110
111/**
112 * @brief Callback called when unregisterPrefix or unsetInterestFilter command fails
113 */
114typedef function<void(const std::string&)> UnregisterPrefixFailureCallback;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800115
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800116/**
117 * @brief Abstraction to communicate with local or remote NDN forwarder
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -0700118 */
Alexander Afanasyev8460afb2014-02-15 20:31:42 -0800119class Face : noncopyable
120{
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700121public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700122 class Error : public std::runtime_error
123 {
124 public:
125 explicit
126 Error(const std::string& what)
127 : std::runtime_error(what)
128 {
129 }
130 };
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800131
Junxiao Shiedd834e2014-10-28 20:28:58 -0700132public: // constructors
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800133 /**
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700134 * @brief Create a new Face using the default transport (UnixTransport)
135 *
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600136 * @throws ConfigFile::Error on configuration file parse failure
137 * @throws Face::Error on unsupported protocol
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800138 */
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -0800139 Face();
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800140
141 /**
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700142 * @brief Create a new Face using the default transport (UnixTransport)
143 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700144 * @par Usage examples:
145 *
146 * Face face1;
147 * Face face2(face1.getIoService());
148 *
149 * // Now the following ensures that events on both faces are processed
150 * face1.processEvents();
151 * // or face1.getIoService().run();
152 *
153 * @par or
154 *
155 * boost::asio::io_service ioService;
156 * Face face1(ioService);
157 * Face face2(ioService);
158 * ...
159 *
160 * ioService.run();
161 *
162 * @param ioService A reference to boost::io_service object that should control all
163 * IO operations.
164 * @throws ConfigFile::Error on configuration file parse failure
165 * @throws Face::Error on unsupported protocol
166 */
167 explicit
168 Face(boost::asio::io_service& ioService);
169
170 /**
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700171 * @brief Create a new Face using the given Transport
Alexander Afanasyevbb64c172015-12-29 20:32:45 -0800172 * @param transport the Transport used for communication. If nullptr, then the default
173 * transport will be used.
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700174 *
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600175 * @throws Face::Error on unsupported protocol
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800176 */
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -0800177 explicit
Alexander Afanasyevbb64c172015-12-29 20:32:45 -0800178 Face(shared_ptr<Transport> transport);
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800179
180 /**
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700181 * @brief Create a new Face using the given Transport and IO service object
Alexander Afanasyevbb64c172015-12-29 20:32:45 -0800182 * @param transport the Transport used for communication. If nullptr, then the default
183 * transport will be used.
184 * @param ioService the io_service that controls all IO operations
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800185 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700186 * @sa Face(boost::asio::io_service&)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800187 *
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600188 * @throws Face::Error on unsupported protocol
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800189 */
Alexander Afanasyevbb64c172015-12-29 20:32:45 -0800190 Face(shared_ptr<Transport> transport,
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700191 boost::asio::io_service& ioService);
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800192
Jeff Thompson4fe45512013-08-23 14:06:38 -0700193 /**
Junxiao Shiedd834e2014-10-28 20:28:58 -0700194 * @brief Create a new Face using the given Transport and IO service object
Alexander Afanasyevbb64c172015-12-29 20:32:45 -0800195 * @param transport the Transport used for communication. If nullptr, then the default
196 * transport will be used.
Junxiao Shiedd834e2014-10-28 20:28:58 -0700197 * @param ioService the io_service that controls all IO operations
198 * @param keyChain the KeyChain to sign commands
199 * @throws Face::Error on unsupported protocol
200 * @note shared_ptr is passed by value because ownership is shared with this class
201 */
202 Face(shared_ptr<Transport> transport,
203 boost::asio::io_service& ioService,
204 KeyChain& keyChain);
205
206 ~Face();
207
208public: // consumer
209 /**
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800210 * @brief Express Interest
Eric Newberry83872fd2015-08-06 17:01:24 -0700211 * @param interest the Interest; a copy will be made, so that the caller is not
212 * required to maintain the argument unchanged
213 * @param afterSatisfied function to be invoked if Data is returned
214 * @param afterNacked function to be invoked if Network NACK is returned
215 * @param afterTimeout function to be invoked if neither Data nor Network NACK
216 * is returned within InterestLifetime
217 */
218 const PendingInterestId*
219 expressInterest(const Interest& interest,
220 const DataCallback& afterSatisfied,
221 const NackCallback& afterNacked,
222 const TimeoutCallback& afterTimeout);
223
224 /**
225 * @brief Express Interest
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800226 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700227 * @param interest An Interest to be expressed
228 * @param onData Callback to be called when a matching data packet is received
Eric Newberry83872fd2015-08-06 17:01:24 -0700229 * @param onTimeout (optional) A function object to call if the interest times out or is Nacked
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800230 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700231 * @return The pending interest ID which can be used with removePendingInterest
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700232 *
233 * @throws Error when Interest size exceeds maximum limit (MAX_NDN_PACKET_SIZE)
Eric Newberry83872fd2015-08-06 17:01:24 -0700234 *
235 * @deprecated use expressInterest(Interest, DataCallback, NackCallback, TimeoutCallback)
Jeff Thompson4fe45512013-08-23 14:06:38 -0700236 */
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800237 const PendingInterestId*
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800238 expressInterest(const Interest& interest,
Eric Newberry83872fd2015-08-06 17:01:24 -0700239 const OnData& onData,
240 const OnTimeout& onTimeout = nullptr);
Jeff Thompson4fe45512013-08-23 14:06:38 -0700241
242 /**
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800243 * @brief Express Interest using name and Interest template
244 *
245 * @param name Name of the Interest
246 * @param tmpl Interest template to fill parameters
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700247 * @param onData Callback to be called when a matching data packet is received
Eric Newberry83872fd2015-08-06 17:01:24 -0700248 * @param onTimeout (optional) A function object to call if the interest times out or is Nacked
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800249 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700250 * @return Opaque pending interest ID which can be used with removePendingInterest
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700251 *
252 * @throws Error when Interest size exceeds maximum limit (MAX_NDN_PACKET_SIZE)
Eric Newberry83872fd2015-08-06 17:01:24 -0700253 *
254 * @deprecated use expressInterest(Interest, DataCallback, NackCallback, TimeoutCallback)
Jeff Thompson7aec0252013-08-22 17:29:57 -0700255 */
Alexander Afanasyevb790d952014-01-24 12:07:53 -0800256 const PendingInterestId*
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800257 expressInterest(const Name& name,
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800258 const Interest& tmpl,
Eric Newberry83872fd2015-08-06 17:01:24 -0700259 const OnData& onData,
260 const OnTimeout& onTimeout = nullptr);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700261
Jeff Thompson11095142013-10-01 16:20:28 -0700262 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700263 * @brief Cancel previously expressed Interest
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700264 *
Jeff Thompson11095142013-10-01 16:20:28 -0700265 * @param pendingInterestId The ID returned from expressInterest.
266 */
267 void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800268 removePendingInterest(const PendingInterestId* pendingInterestId);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700269
Jeff Thompson432c8be2013-08-09 16:16:08 -0700270 /**
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500271 * @brief Cancel all previously expressed Interests
272 */
273 void
274 removeAllPendingInterests();
275
276 /**
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -0700277 * @brief Get number of pending Interests
278 */
279 size_t
280 getNPendingInterests() const;
281
Junxiao Shiedd834e2014-10-28 20:28:58 -0700282public: // producer
Alexander Afanasyev6fcdde22014-08-22 19:03:36 -0700283 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700284 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
285 * callback and register the filtered prefix with the connected NDN forwarder
286 *
287 * This version of setInterestFilter combines setInterestFilter and registerPrefix
288 * operations and is intended to be used when only one filter for the same prefix needed
289 * to be set. When multiple names sharing the same prefix should be dispatched to
290 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
291 * a series of setInterestFilter calls.
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700292 *
Alexander Afanasyev90164962014-03-06 08:29:59 +0000293 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700294 * @param onInterest A callback to be called when a matching interest is received
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700295 * @param onFailure A callback to be called when prefixRegister command fails
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400296 * @param flags (optional) RIB flags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400297 * @param signingInfo (optional) Signing parameters. When omitted, a default parameters
298 * used in the signature will be used.
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700299 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700300 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
301 * removeRegisteredPrefix
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700302 */
303 const RegisteredPrefixId*
Alexander Afanasyev90164962014-03-06 08:29:59 +0000304 setInterestFilter(const InterestFilter& interestFilter,
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700305 const OnInterest& onInterest,
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700306 const RegisterPrefixFailureCallback& onFailure,
Joao Pereira0b3cac52015-07-02 14:49:49 -0400307 const security::SigningInfo& signingInfo = security::SigningInfo(),
Alexander Afanasyev0866f512014-08-11 13:25:09 -0700308 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700309
310 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700311 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
312 * callback and register the filtered prefix with the connected NDN forwarder
313 *
314 * This version of setInterestFilter combines setInterestFilter and registerPrefix
315 * operations and is intended to be used when only one filter for the same prefix needed
316 * to be set. When multiple names sharing the same prefix should be dispatched to
317 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
318 * a series of setInterestFilter calls.
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700319 *
Alexander Afanasyev90164962014-03-06 08:29:59 +0000320 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700321 * @param onInterest A callback to be called when a matching interest is received
322 * @param onSuccess A callback to be called when prefixRegister command succeeds
323 * @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.
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700327 *
Joao Pereira0b3cac52015-07-02 14:49:49 -0400328 * @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,
Yingdi Yue66bf2a2014-04-28 17:07:36 -0700333 const OnInterest& onInterest,
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700334 const RegisterPrefixSuccessCallback& onSuccess,
335 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);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700338
339 /**
340 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest callback
341 *
342 * @param interestFilter Interest
343 * @param onInterest A callback to be called when a matching interest is received
344 *
345 * This method modifies library's FIB only, and does not register the prefix with the
346 * forwarder. It will always succeed. To register prefix with the forwarder, use
347 * registerPrefix, or use the setInterestFilter overload taking two callbacks.
348 *
349 * @return Opaque interest filter ID which can be used with unsetInterestFilter
350 */
351 const InterestFilterId*
352 setInterestFilter(const InterestFilter& interestFilter,
353 const OnInterest& onInterest);
354
Joao Pereira0b3cac52015-07-02 14:49:49 -0400355#ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
356 /**
357 * @deprecated Use override with SigningInfo instead of this function
358 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
359 * callback and register the filtered prefix with the connected NDN forwarder
360 *
361 * This version of setInterestFilter combines setInterestFilter and registerPrefix
362 * operations and is intended to be used when only one filter for the same prefix needed
363 * to be set. When multiple names sharing the same prefix should be dispatched to
364 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
365 * a series of setInterestFilter calls.
366 *
367 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
368 * @param onInterest A callback to be called when a matching interest is received
369 * @param onSuccess A callback to be called when prefixRegister command succeeds
370 * @param onFailure A callback to be called when prefixRegister command fails
371 * @param flags (optional) RIB flags
372 * @param certificate (optional) A certificate under which the prefix registration
373 * command is signed. When omitted, a default certificate of
374 * the default identity is used to sign the registration command
375 *
376 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
377 * removeRegisteredPrefix
378 */
philobb778e72015-08-25 14:49:19 -0700379 DEPRECATED(
Joao Pereira0b3cac52015-07-02 14:49:49 -0400380 const RegisteredPrefixId*
381 setInterestFilter(const InterestFilter& interestFilter,
382 const OnInterest& onInterest,
383 const RegisterPrefixSuccessCallback& onSuccess,
384 const RegisterPrefixFailureCallback& onFailure,
385 const IdentityCertificate& certificate,
philobb778e72015-08-25 14:49:19 -0700386 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700387
388 /**
Joao Pereira0b3cac52015-07-02 14:49:49 -0400389 * @deprecated Use override with SigningInfo instead of this function
390 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
391 * callback and register the filtered prefix with the connected NDN forwarder
392 *
393 * This version of setInterestFilter combines setInterestFilter and registerPrefix
394 * operations and is intended to be used when only one filter for the same prefix needed
395 * to be set. When multiple names sharing the same prefix should be dispatched to
396 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
397 * a series of setInterestFilter calls.
398 *
399 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
400 * @param onInterest A callback to be called when a matching interest is received
401 * @param onFailure A callback to be called when prefixRegister command fails
402 * @param flags (optional) RIB flags
403 * @param certificate (optional) A certificate under which the prefix registration
404 * command is signed. When omitted, a default certificate of
405 * the default identity is used to sign the registration command
406 *
407 * @return Opaque registered prefix ID which can be used with unsetInterestFilter or
408 * removeRegisteredPrefix
409 */
philobb778e72015-08-25 14:49:19 -0700410 DEPRECATED(
Joao Pereira0b3cac52015-07-02 14:49:49 -0400411 const RegisteredPrefixId*
412 setInterestFilter(const InterestFilter& interestFilter,
413 const OnInterest& onInterest,
414 const RegisterPrefixFailureCallback& onFailure,
415 const IdentityCertificate& certificate,
philobb778e72015-08-25 14:49:19 -0700416 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400417
418 /**
419 * @deprecated Use override with SigningInfo instead of this function
420 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
421 * callback and register the filtered prefix with the connected NDN forwarder
422 *
423 * This version of setInterestFilter combines setInterestFilter and registerPrefix
424 * operations and is intended to be used when only one filter for the same prefix needed
425 * to be set. When multiple names sharing the same prefix should be dispatched to
426 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
427 * a series of setInterestFilter calls.
428 *
429 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
430 * @param onInterest A callback to be called when a matching interest is received
431 * @param onSuccess A callback to be called when prefixRegister command succeeds
432 * @param onFailure A callback to be called when prefixRegister command fails
433 * @param identity A signing identity. A prefix registration command is signed
434 * under the default certificate of this identity
435 * @param flags (optional) RIB flags
436 *
437 * @return Opaque registered prefix ID which can be used with 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 RegisterPrefixSuccessCallback& onSuccess,
444 const RegisterPrefixFailureCallback& onFailure,
445 const Name& identity,
philobb778e72015-08-25 14:49:19 -0700446 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400447
448 /**
449 * @deprecated Use override with SigningInfo instead of this function
450 * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
451 * callback and register the filtered prefix with the connected NDN forwarder
452 *
453 * This version of setInterestFilter combines setInterestFilter and registerPrefix
454 * operations and is intended to be used when only one filter for the same prefix needed
455 * to be set. When multiple names sharing the same prefix should be dispatched to
456 * different callbacks, use one registerPrefix call, followed (in onSuccess callback) by
457 * a series of setInterestFilter calls.
458 *
459 * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
460 * @param onInterest A callback to be called when a matching interest is received
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 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#endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
476
477 /**
478 * @brief Register prefix with the connected NDN forwarder
479 *
480 * This method only modifies forwarder's RIB and does not associate any
481 * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to
482 * the right callbacks.
483 *
484 * @param prefix A prefix to register with the connected NDN forwarder
485 * @param onSuccess A callback to be called when prefixRegister command succeeds
486 * @param onFailure A callback to be called when prefixRegister command fails
487 * @param signingInfo (optional) Signing parameters. When omitted, a default parameters
488 * used in the signature will be used.
Alexander Afanasyevf2a46222015-09-17 18:01:30 -0700489 * @param flags Prefix registration flags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400490 *
491 * @return The registered prefix ID which can be used with unregisterPrefix
Alexander Afanasyevf2a46222015-09-17 18:01:30 -0700492 * @see nfd::RouteFlags
Joao Pereira0b3cac52015-07-02 14:49:49 -0400493 */
494 const RegisteredPrefixId*
495 registerPrefix(const Name& prefix,
496 const RegisterPrefixSuccessCallback& onSuccess,
497 const RegisterPrefixFailureCallback& onFailure,
498 const security::SigningInfo& signingInfo = security::SigningInfo(),
499 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
500
501#ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
502 /**
503 * @deprecated Use override with SigningInfo instead of this function
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700504 * @brief Register prefix with the connected NDN forwarder
505 *
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400506 * This method only modifies forwarder's RIB and does not associate any
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700507 * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to
508 * the right callbacks.
509 *
510 * @param prefix A prefix to register with the connected NDN forwarder
511 * @param onSuccess A callback to be called when prefixRegister command succeeds
512 * @param onFailure A callback to be called when prefixRegister command fails
513 * @param certificate (optional) A certificate under which the prefix registration
Junxiao Shi6a90f372014-10-13 20:29:30 -0700514 * command is signed. When omitted, a default certificate of
515 * the default identity is used to sign the registration command
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400516 * @param flags (optional) RIB flags
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700517 *
518 * @return The registered prefix ID which can be used with unregisterPrefix
519 */
philobb778e72015-08-25 14:49:19 -0700520 DEPRECATED(
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700521 const RegisteredPrefixId*
522 registerPrefix(const Name& prefix,
523 const RegisterPrefixSuccessCallback& onSuccess,
524 const RegisterPrefixFailureCallback& onFailure,
Joao Pereira0b3cac52015-07-02 14:49:49 -0400525 const IdentityCertificate& certificate,
philobb778e72015-08-25 14:49:19 -0700526 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700527
528 /**
Joao Pereira0b3cac52015-07-02 14:49:49 -0400529 * @deprecated Use override with SigningInfo instead of this function
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700530 * @brief Register prefix with the connected NDN forwarder and call onInterest when a matching
531 * interest is received.
532 *
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400533 * This method only modifies forwarder's RIB and does not associate any
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700534 * onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to
535 * the right callbacks.
536 *
537 * @param prefix A prefix to register with the connected NDN forwarder
538 * @param onSuccess A callback to be called when prefixRegister command succeeds
539 * @param onFailure A callback to be called when prefixRegister command fails
Junxiao Shi6a90f372014-10-13 20:29:30 -0700540 * @param identity A signing identity. A prefix registration command is signed
541 * under the default certificate of this identity
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400542 * @param flags (optional) RIB flags
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700543 *
544 * @return The registered prefix ID which can be used with unregisterPrefix
545 */
philobb778e72015-08-25 14:49:19 -0700546 DEPRECATED(
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700547 const RegisteredPrefixId*
548 registerPrefix(const Name& prefix,
549 const RegisterPrefixSuccessCallback& onSuccess,
550 const RegisterPrefixFailureCallback& onFailure,
Alexander Afanasyev0866f512014-08-11 13:25:09 -0700551 const Name& identity,
philobb778e72015-08-25 14:49:19 -0700552 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400553#endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700554
555 /**
Alexander Afanasyev1b01c312014-05-26 16:58:10 +0300556 * @brief Remove the registered prefix entry with the registeredPrefixId
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700557 *
558 * This does not affect another registered prefix with a different registeredPrefixId,
559 * even it if has the same prefix name. If there is no entry with the
560 * registeredPrefixId, do nothing.
561 *
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700562 * unsetInterestFilter will use the same credentials as original
563 * setInterestFilter/registerPrefix command
564 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700565 * @param registeredPrefixId The ID returned from registerPrefix
Jeff Thompson11095142013-10-01 16:20:28 -0700566 */
567 void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800568 unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId);
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800569
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700570 /**
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700571 * @brief Remove previously set InterestFilter from library's FIB
572 *
573 * This method always succeeds and will **NOT** send any request to the connected
574 * forwarder.
575 *
576 * @param interestFilterId The ID returned from setInterestFilter.
577 */
578 void
579 unsetInterestFilter(const InterestFilterId* interestFilterId);
580
581 /**
Joao Pereiraba1e3b92015-06-01 17:50:37 -0400582 * @brief Unregister prefix from RIB
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700583 *
584 * unregisterPrefix will use the same credentials as original
585 * setInterestFilter/registerPrefix command
586 *
587 * If registeredPrefixId was obtained using setInterestFilter, the corresponding
588 * InterestFilter will be unset too.
589 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700590 * @param registeredPrefixId The ID returned from registerPrefix
591 * @param onSuccess Callback to be called when operation succeeds
592 * @param onFailure Callback to be called when operation fails
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700593 */
594 void
595 unregisterPrefix(const RegisteredPrefixId* registeredPrefixId,
596 const UnregisterPrefixSuccessCallback& onSuccess,
597 const UnregisterPrefixFailureCallback& onFailure);
598
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800599 /**
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800600 * @brief Publish data packet
601 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700602 * This method can be called to satisfy the incoming Interest or to put Data packet into
Alexander Afanasyev6a05b4b2014-07-18 17:23:00 -0700603 * the cache of the local NDN forwarder.
604 *
605 * @param data Data packet to publish. It is highly recommended to use Data packet that
606 * was created using make_shared<Data>(...). Otherwise, put() will make an
607 * extra copy of the Data packet to ensure validity of published Data until
608 * asynchronous put() operation finishes.
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700609 *
610 * @throws Error when Data size exceeds maximum limit (MAX_NDN_PACKET_SIZE)
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800611 */
612 void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800613 put(const Data& data);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700614
Eric Newberry83872fd2015-08-06 17:01:24 -0700615 /**
616 * @brief sends a Network NACK
617 * @param nack the Nack; a copy will be made, so that the caller is not required to
618 * maintain the argument unchanged
619 */
620 void
621 put(const lp::Nack& nack);
622
Junxiao Shiedd834e2014-10-28 20:28:58 -0700623public: // IO routine
Jeff Thompson86507bc2013-08-23 20:51:38 -0700624 /**
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700625 * @brief Process any data to receive or call timeout callbacks.
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800626 *
627 * This call will block forever (default timeout == 0) to process IO on the face.
628 * To exit, one expected to call face.shutdown() from one of the callback methods.
629 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700630 * If positive timeout is specified, then processEvents will exit after this timeout, if
631 * not stopped earlier with face.shutdown() or when all active events finish. The call
632 * can be called repeatedly, if desired.
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800633 *
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700634 * If negative timeout is specified, then processEvents will not block and process only
635 * pending events.
Alexander Afanasyevf75a0aa2014-01-09 14:29:22 -0800636 *
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700637 * @param timeout maximum time to block the thread
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700638 * @param keepThread Keep thread in a blocked state (in event processing), even when
639 * there are no outstanding events (e.g., no Interest/Data is expected)
640 *
641 * @throw This may throw an exception for reading data or in the callback for processing
642 * the data. If you call this from an main event loop, you may want to catch and
643 * log/disregard all exceptions.
Jeff Thompson432c8be2013-08-09 16:16:08 -0700644 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700645 void
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700646 processEvents(const time::milliseconds& timeout = time::milliseconds::zero(),
647 bool keepThread = false);
Jeff Thompson432c8be2013-08-09 16:16:08 -0700648
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700649 /**
650 * @brief Shutdown face operations
651 *
652 * This method cancels all pending operations and closes connection to NDN Forwarder.
653 *
654 * Note that this method does not stop IO service and if the same IO service is shared
655 * between multiple Faces or with other IO objects (e.g., Scheduler).
656 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700657 void
Jeff Thompson0050abe2013-09-17 12:50:25 -0700658 shutdown();
Yingdi Yu0d920812014-01-30 14:50:57 -0800659
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700660 /**
Alexander Afanasyev787be412016-09-08 15:15:43 -0700661 * @brief Return nullptr (cannot use IoService in simulations), preserved for API compatibility
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700662 */
663 boost::asio::io_service&
664 getIoService()
665 {
Alexander Afanasyev787be412016-09-08 15:15:43 -0700666 return *static_cast<boost::asio::io_service*>(nullptr);
Alexander Afanasyev691c3ce2014-04-23 14:28:04 -0700667 }
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800668
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800669NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
670 /**
671 * @brief Get the underlying transport of the face
672 */
673 shared_ptr<Transport>
674 getTransport();
675
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800676private:
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -0700677
678 /**
679 * @throws ConfigFile::Error on parse error and unsupported protocols
680 */
Alexander Afanasyevbb64c172015-12-29 20:32:45 -0800681 shared_ptr<Transport>
682 makeDefaultTransport();
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -0700683
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600684 /**
685 * @throws Face::Error on unsupported protocol
Junxiao Shi2cced062014-11-02 21:27:38 -0700686 * @note shared_ptr is passed by value because ownership is transferred to this function
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600687 */
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800688 void
Joao Pereira68c0d882015-05-19 14:27:55 -0400689 construct(shared_ptr<Transport> transport, KeyChain& keyChain);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600690
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700691 void
Eric Newberry83872fd2015-08-06 17:01:24 -0700692 onReceiveElement(const Block& blockFromDaemon);
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800693
Alexander Afanasyev7dced462014-03-19 15:12:32 -0700694 void
695 asyncShutdown();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700696
Jeff Thompsonb982b6d2013-07-15 18:15:45 -0700697private:
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800698 shared_ptr<Transport> m_transport;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800699
Joao Pereira68c0d882015-05-19 14:27:55 -0400700 unique_ptr<nfd::Controller> m_nfdController;
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600701
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -0700702 class Impl;
Joao Pereira68c0d882015-05-19 14:27:55 -0400703 unique_ptr<Impl> m_impl;
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700704};
705
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800706} // namespace ndn
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700707
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800708#endif // NDN_FACE_HPP