NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
face.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_FACE_HPP
23 #define NDN_FACE_HPP
24 
25 #include "common.hpp"
26 
27 #include "name.hpp"
28 #include "interest.hpp"
29 #include "interest-filter.hpp"
30 #include "data.hpp"
32 
33 #define NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
34 
35 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
37 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
38 
39 namespace boost {
40 namespace asio {
41 class io_service;
42 }
43 }
44 
45 namespace ndn {
46 
47 class Transport;
48 
49 class PendingInterestId;
50 class RegisteredPrefixId;
51 class InterestFilterId;
52 
53 namespace security {
54 class KeyChain;
55 }
56 using security::KeyChain;
57 
58 namespace nfd {
59 class Controller;
60 }
61 
65 typedef function<void(const Interest&, Data&)> OnData;
66 
70 typedef function<void(const Interest&)> OnTimeout;
71 
75 typedef function<void (const InterestFilter&, const Interest&)> OnInterest;
76 
80 typedef function<void(const Name&)> RegisterPrefixSuccessCallback;
81 
85 typedef function<void(const Name&, const std::string&)> RegisterPrefixFailureCallback;
86 
90 typedef function<void()> UnregisterPrefixSuccessCallback;
91 
95 typedef function<void(const std::string&)> UnregisterPrefixFailureCallback;
96 
100 class Face : noncopyable
101 {
102 public:
103  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  };
112 
113 public: // constructors
120  Face();
121 
148  explicit
149  Face(boost::asio::io_service& ioService);
150 
151  ~Face();
152 
153 public: // consumer
165  const PendingInterestId*
166  expressInterest(const Interest& interest,
167  const OnData& onData, const OnTimeout& onTimeout = OnTimeout());
168 
181  const PendingInterestId*
182  expressInterest(const Name& name,
183  const Interest& tmpl,
184  const OnData& onData, const OnTimeout& onTimeout = OnTimeout());
185 
191  void
192  removePendingInterest(const PendingInterestId* pendingInterestId);
193 
197  size_t
198  getNPendingInterests() const;
199 
200 public: // producer
221  const RegisteredPrefixId*
222  setInterestFilter(const InterestFilter& interestFilter,
223  const OnInterest& onInterest,
224  const RegisterPrefixFailureCallback& onFailure,
225  const security::SigningInfo& signingInfo = security::SigningInfo(),
226  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
227 
249  const RegisteredPrefixId*
250  setInterestFilter(const InterestFilter& interestFilter,
251  const OnInterest& onInterest,
252  const RegisterPrefixSuccessCallback& onSuccess,
253  const RegisterPrefixFailureCallback& onFailure,
254  const security::SigningInfo& signingInfo = security::SigningInfo(),
255  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
256 
269  const InterestFilterId*
270  setInterestFilter(const InterestFilter& interestFilter,
271  const OnInterest& onInterest);
272 
273 #ifdef NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
274 
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);
304 
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 
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 
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 
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 
432  const RegisteredPrefixId*
433  registerPrefix(const Name& prefix,
434  const RegisterPrefixSuccessCallback& onSuccess,
435  const RegisterPrefixFailureCallback& onFailure,
436  const IdentityCertificate& certificate,
437  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
438 
457  const RegisteredPrefixId*
458  registerPrefix(const Name& prefix,
459  const RegisterPrefixSuccessCallback& onSuccess,
460  const RegisterPrefixFailureCallback& onFailure,
461  const Name& identity,
462  uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
463 #endif // NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
464 
477  void
478  unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId);
479 
488  void
489  unsetInterestFilter(const InterestFilterId* interestFilterId);
490 
504  void
505  unregisterPrefix(const RegisteredPrefixId* registeredPrefixId,
506  const UnregisterPrefixSuccessCallback& onSuccess,
507  const UnregisterPrefixFailureCallback& onFailure);
508 
522  void
523  put(const Data& data);
524 
525 public: // IO routine
529  void
530  processEvents(const time::milliseconds& timeout = time::milliseconds::zero(),
531  bool keepThread = false);
532 
541  void
542  shutdown();
543 
547  boost::asio::io_service&
549  {
550  return *static_cast<boost::asio::io_service*>(nullptr);
551  }
552 
553 private:
554  void
555  construct();
556 
557 private:
558  class Impl;
559 
560 private:
567  unique_ptr<KeyChain> m_internalKeyChain;
568 
569  unique_ptr<nfd::Controller> m_nfdController;
570  unique_ptr<Impl> m_impl;
571 };
572 
573 } // namespace ndn
574 
575 #endif // NDN_FACE_HPP
Copyright (c) 2011-2015 Regents of the University of California.
Error(const std::string &what)
Definition: face.hpp:107
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback called when unregisterPrefix or unsetInterestFilter command fails.
Definition: face.hpp:95
Copyright (c) 2013-2015 Regents of the University of California.
STL namespace.
represents an Interest packet
Definition: interest.hpp:45
function< void(const Interest &)> OnTimeout
Callback called when expressed Interest times out.
Definition: face.hpp:70
function< void(const InterestFilter &, const Interest &)> OnInterest
Callback called when incoming Interest matches the specified InterestFilter.
Definition: face.hpp:75
Copyright (c) 2013-2014 Regents of the University of California.
Signing parameters passed to KeyChain.
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
Abstraction to communicate with local or remote NDN forwarder.
Definition: face.hpp:100
function< void(const Name &, const std::string &)> RegisterPrefixFailureCallback
Callback called when registerPrefix or setInterestFilter command fails.
Definition: face.hpp:85
function< void(const Name &)> RegisterPrefixSuccessCallback
Callback called when registerPrefix or setInterestFilter command succeeds.
Definition: face.hpp:80
Name abstraction to represent an absolute name.
Definition: name.hpp:46
ndn cxx Face
Copyright (c) 2013-2015 Regents of the University of California.
Definition: face.cpp:25
boost::asio::io_service & getIoService()
Return nullptr (kept for compatibility)
Definition: face.hpp:548
function< void(const Interest &, Data &)> OnData
Callback called when expressed Interest gets satisfied with Data packet.
Definition: face.hpp:65
function< void()> UnregisterPrefixSuccessCallback
Callback called when unregisterPrefix or unsetInterestFilter command succeeds.
Definition: face.hpp:90
represents a Data packet
Definition: data.hpp:39