face.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_FACE_HPP
23 #define NDN_FACE_HPP
24 
25 #include "interest.hpp"
26 #include "data.hpp"
27 #include "forwarding-flags.hpp"
28 #include "encoding/wire-format.hpp"
29 #include "interest-filter.hpp"
30 #include "transport/transport.hpp"
31 
32 namespace ndn {
33 
34 class Face;
35 
39 typedef func_lib::function<void(const ptr_lib::shared_ptr<const Interest>&, const ptr_lib::shared_ptr<Data>&)> OnData;
40 
44 typedef func_lib::function<void(const ptr_lib::shared_ptr<const Interest>&)> OnTimeout;
45 
49 typedef func_lib::function<void
50  (const ptr_lib::shared_ptr<const Name>&, const ptr_lib::shared_ptr<const Interest>&, Transport&, uint64_t)> OnInterest;
51 
56 typedef func_lib::function<void
57  (const ptr_lib::shared_ptr<const Name>&,
58  const ptr_lib::shared_ptr<const Interest>&, Face&, uint64_t,
59  const ptr_lib::shared_ptr<const InterestFilter>&)> OnInterestCallback;
60 
64 typedef func_lib::function<void(const ptr_lib::shared_ptr<const Name>&)> OnRegisterFailed;
65 
66 class Node;
67 class KeyChain;
68 
72 class Face {
73 public:
79  Face(const ptr_lib::shared_ptr<Transport>& transport, const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& connectionInfo);
80 
87  Face(const char *host, unsigned short port = 6363);
88 
95  Face();
96 
97  ~Face();
98 
111  uint64_t
113  (const Interest& interest, const OnData& onData, const OnTimeout& onTimeout = OnTimeout(),
115 
130  uint64_t
132  (const Name& name, const Interest *interestTemplate, const OnData& onData, const OnTimeout& onTimeout = OnTimeout(),
134 
147  uint64_t
149  (const Name& name, const OnData& onData, const OnTimeout& onTimeout = OnTimeout(),
151  {
152  return expressInterest(name, 0, onData, onTimeout, wireFormat);
153  }
154 
161  void
162  removePendingInterest(uint64_t pendingInterestId);
163 
175  void
176  setCommandSigningInfo(KeyChain& keyChain, const Name& certificateName)
177  {
178  commandKeyChain_ = &keyChain;
179  commandCertificateName_ = certificateName;
180  }
181 
188  void
189  setCommandCertificateName(const Name& certificateName)
190  {
191  commandCertificateName_ = certificateName;
192  }
193 
205  void
207  (Interest& interest,
209 
232  uint64_t
234  (const Name& prefix, const OnInterestCallback& onInterest,
235  const OnRegisterFailed& onRegisterFailed,
236  const ForwardingFlags& flags = ForwardingFlags(),
238 
244  uint64_t
245  DEPRECATED_IN_NDN_CPP registerPrefix
246  (const Name& prefix, const OnInterest& onInterest,
247  const OnRegisterFailed& onRegisterFailed,
248  const ForwardingFlags& flags = ForwardingFlags(),
250 
259  void
260  removeRegisteredPrefix(uint64_t registeredPrefixId);
261 
275  uint64_t
277  (const InterestFilter& filter, const OnInterestCallback& onInterest);
278 
292  uint64_t
293  setInterestFilter(const Name& prefix, const OnInterestCallback& onInterest);
294 
302  void
303  unsetInterestFilter(uint64_t interestFilterId);
304 
314  void
315  putData
316  (const Data& data,
318 
325  void
326  send(const Blob& encoding)
327  {
328  send(encoding.buf(), encoding.size());
329  }
330 
338  void
339  send(const uint8_t *encoding, size_t encodingLength);
340 
353  void
354  processEvents();
355 
362  bool
363  isLocal();
364 
368  void
369  shutdown();
370 
378  static size_t
379  getMaxNdnPacketSize() { return MAX_NDN_PACKET_SIZE; }
380 
381 private:
387  static void
388  onInterestWrapper
389  (const ptr_lib::shared_ptr<const Name>& prefix,
390  const ptr_lib::shared_ptr<const Interest>& interest, Face& face,
391  uint64_t interestFilterId,
392  const ptr_lib::shared_ptr<const InterestFilter>& filter,
393  const OnInterest callerOnInterest);
394 
395  Node *node_;
396  KeyChain* commandKeyChain_;
397  Name commandCertificateName_;
398 };
399 
400 }
401 
402 #endif
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &)> OnTimeout
An OnTimeout function object is used to pass a callback to expressInterest.
Definition: face.hpp:44
Definition: transport.hpp:32
void setCommandCertificateName(const Name &certificateName)
Set the certificate name used to sign command interest (e.g.
Definition: face.hpp:189
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &, const ptr_lib::shared_ptr< const Interest > &, Transport &, uint64_t)> OnInterest
Definition: face.hpp:50
Definition: data.hpp:36
The Face class provides the main methods for NDN communication.
Definition: face.hpp:72
void removeRegisteredPrefix(uint64_t registeredPrefixId)
Remove the registered prefix entry with the registeredPrefixId from the registered prefix table...
Definition: face.cpp:169
uint64_t expressInterest(const Interest &interest, const OnData &onData, const OnTimeout &onTimeout=OnTimeout(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Send the Interest through the transport, read the entire response and call onData(interest, data).
Definition: face.cpp:97
A ForwardingFlags object holds the flags which specify how the forwarding daemon should forward an in...
Definition: forwarding-flags.hpp:34
void removePendingInterest(uint64_t pendingInterestId)
Remove the pending interest entry with the pendingInterestId from the pending interest table...
Definition: face.cpp:118
KeyChain is the main class of the security library.
Definition: key-chain.hpp:45
void putData(const Data &data, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
The OnInterestCallback calls this to put a Data packet which satisfies an Interest.
Definition: face.cpp:194
void unsetInterestFilter(uint64_t interestFilterId)
Remove the interest filter entry which has the interestFilterId from the interest filter table...
Definition: face.cpp:188
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:42
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:41
const uint8_t * buf() const
Return a const pointer to the first byte of the immutable byte array, or 0 if the pointer is null...
Definition: blob.hpp:138
static size_t getMaxNdnPacketSize()
Get the practical limit of the size of a network-layer packet.
Definition: face.hpp:379
Face()
Create a new Face for communication with an NDN hub using a default connection as follows...
Definition: face.cpp:84
void makeCommandInterest(Interest &interest, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Append a timestamp component and a random value component to interest's name.
Definition: face.cpp:124
size_t size() const
Return the length of the immutable byte array.
Definition: blob.hpp:126
uint64_t setInterestFilter(const InterestFilter &filter, const OnInterestCallback &onInterest)
Add an entry to the local interest filter table to call the onInterest callback for a matching incomi...
Definition: face.cpp:176
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &, const ptr_lib::shared_ptr< const Interest > &, Face &, uint64_t, const ptr_lib::shared_ptr< const InterestFilter > &)> OnInterestCallback
An OnInterestCallback function object is used to pass a callback to setInterestFilter and optionally ...
Definition: face.hpp:59
Definition: node.hpp:40
uint64_t registerPrefix(const Name &prefix, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, const ForwardingFlags &flags=ForwardingFlags(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Register prefix with the connected NDN hub and call onInterest when a matching interest is received...
Definition: face.cpp:132
bool isLocal()
Check if the face is local based on the current connection through the Transport; some Transport may ...
Definition: face.cpp:213
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:36
void shutdown()
Shut down and disconnect this Face.
Definition: face.cpp:219
void processEvents()
Process any packets to receive and call callbacks such as onData, onInterest or onTimeout.
Definition: face.cpp:206
Definition: wire-format.hpp:37
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &)> OnRegisterFailed
An OnRegisterFailed function object is used to report when registerPrefix fails.
Definition: face.hpp:64
An InterestFilter holds a Name prefix and optional regex match expression for use in Face::setInteres...
Definition: interest-filter.hpp:33
void send(const Blob &encoding)
Send the encoded packet out through the face.
Definition: face.hpp:326
void setCommandSigningInfo(KeyChain &keyChain, const Name &certificateName)
Set the KeyChain and certificate name used to sign command interests (e.g.
Definition: face.hpp:176
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &, const ptr_lib::shared_ptr< Data > &)> OnData
An OnData function object is used to pass a callback to expressInterest.
Definition: face.hpp:34