Public Member Functions | Static Public Member Functions | List of all members
ndn::Face Class Reference

The Face class provides the main methods for NDN communication. More...

#include <face.hpp>

Public Member Functions

 Face (const ptr_lib::shared_ptr< Transport > &transport, const ptr_lib::shared_ptr< const Transport::ConnectionInfo > &connectionInfo)
 Create a new Face for communication with an NDN hub with the given Transport object and connectionInfo. More...
 
 Face (const char *host, unsigned short port=6363)
 Create a new Face for communication with an NDN hub at host:port using the default TcpTransport. More...
 
 Face ()
 Create a new Face for communication with an NDN hub using a default connection as follows. More...
 
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). More...
 
uint64_t expressInterest (const Name &name, const Interest *interestTemplate, const OnData &onData, const OnTimeout &onTimeout=OnTimeout(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Encode name as an Interest. More...
 
uint64_t expressInterest (const Name &name, const OnData &onData, const OnTimeout &onTimeout=OnTimeout(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Encode name as an Interest, using a default interest lifetime. More...
 
void removePendingInterest (uint64_t pendingInterestId)
 Remove the pending interest entry with the pendingInterestId from the pending interest table. More...
 
void setCommandSigningInfo (KeyChain &keyChain, const Name &certificateName)
 Set the KeyChain and certificate name used to sign command interests (e.g. More...
 
void setCommandCertificateName (const Name &certificateName)
 Set the certificate name used to sign command interest (e.g. More...
 
void makeCommandInterest (Interest &interest, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Append a timestamp component and a random value component to interest's name. More...
 
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. More...
 
uint64_t DEPRECATED_IN_NDN_CPP registerPrefix (const Name &prefix, const OnInterest &onInterest, const OnRegisterFailed &onRegisterFailed, const ForwardingFlags &flags=ForwardingFlags(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 
void removeRegisteredPrefix (uint64_t registeredPrefixId)
 Remove the registered prefix entry with the registeredPrefixId from the registered prefix table. More...
 
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 incoming Interest. More...
 
uint64_t setInterestFilter (const Name &prefix, const OnInterestCallback &onInterest)
 Add an entry to the local interest filter table to call the onInterest callback for a matching incoming Interest. More...
 
void unsetInterestFilter (uint64_t interestFilterId)
 Remove the interest filter entry which has the interestFilterId from the interest filter table. More...
 
void putData (const Data &data, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 The OnInterestCallback calls this to put a Data packet which satisfies an Interest. More...
 
void send (const Blob &encoding)
 Send the encoded packet out through the face. More...
 
void send (const uint8_t *encoding, size_t encodingLength)
 Send the encoded packet out through the face. More...
 
void processEvents ()
 Process any packets to receive and call callbacks such as onData, onInterest or onTimeout. More...
 
bool isLocal ()
 Check if the face is local based on the current connection through the Transport; some Transport may cause network I/O (e.g. More...
 
void shutdown ()
 Shut down and disconnect this Face.
 

Static Public Member Functions

static size_t getMaxNdnPacketSize ()
 Get the practical limit of the size of a network-layer packet. More...
 

Detailed Description

The Face class provides the main methods for NDN communication.

Constructor & Destructor Documentation

ndn::Face::Face ( const ptr_lib::shared_ptr< Transport > &  transport,
const ptr_lib::shared_ptr< const Transport::ConnectionInfo > &  connectionInfo 
)

Create a new Face for communication with an NDN hub with the given Transport object and connectionInfo.

Parameters
transportA shared_ptr to a Transport object used for communication.
transportA shared_ptr to a Transport::ConnectionInfo to be used to connect to the transport.
ndn::Face::Face ( const char *  host,
unsigned short  port = 6363 
)

Create a new Face for communication with an NDN hub at host:port using the default TcpTransport.

Parameters
hostThe host of the NDN hub.
port(optional) The port of the NDN hub. If omitted. use 6363.
ndn::Face::Face ( )

Create a new Face for communication with an NDN hub using a default connection as follows.

If the forwarder's Unix socket file exists, then connect using UnixTransport. Otherwise, connect to "localhost" on port 6363 using TcpTransport.

Member Function Documentation

uint64_t ndn::Face::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).

Parameters
interestA reference to the Interest. This copies the Interest.
onDataA function object to call when a matching data packet is received. This copies the function object, so you may need to use func_lib::ref() as appropriate.
onTimeoutA function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it. This copies the function object, so you may need to use func_lib::ref() as appropriate.
wireFormatA WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat().
Returns
The pending interest ID which can be used with removePendingInterest.
Exceptions
runtime_errorIf the encoded interest size exceeds getMaxNdnPacketSize().
uint64_t ndn::Face::expressInterest ( const Name name,
const Interest interestTemplate,
const OnData onData,
const OnTimeout onTimeout = OnTimeout(),
WireFormat wireFormat = *WireFormat::getDefaultWireFormat() 
)

Encode name as an Interest.

If interestTemplate is not 0, use its interest selectors. Send the interest through the transport, read the entire response and call onData(interest, data).

Parameters
nameA reference to a Name for the interest. This copies the Name.
interestTemplateif not 0, copy interest selectors from the template. This does not keep a pointer to the Interest object.
onDataA function object to call when a matching data packet is received. This copies the function object, so you may need to use func_lib::ref() as appropriate.
onTimeoutA function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it. This copies the function object, so you may need to use func_lib::ref() as appropriate.
wireFormatA WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat().
Returns
The pending interest ID which can be used with removePendingInterest.
Exceptions
runtime_errorIf the encoded interest size exceeds getMaxNdnPacketSize().
uint64_t ndn::Face::expressInterest ( const Name name,
const OnData onData,
const OnTimeout onTimeout = OnTimeout(),
WireFormat wireFormat = *WireFormat::getDefaultWireFormat() 
)
inline

Encode name as an Interest, using a default interest lifetime.

Send the interest through the transport, read the entire response and call onData(interest, data).

Parameters
nameA reference to a Name for the interest. This copies the Name.
onDataA function object to call when a matching data packet is received. This copies the function object, so you may need to use func_lib::ref() as appropriate.
onTimeoutA function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it. This copies the function object, so you may need to use func_lib::ref() as appropriate.
wireFormatA WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat().
Returns
The pending interest ID which can be used with removePendingInterest.
Exceptions
runtime_errorIf the encoded interest size exceeds getMaxNdnPacketSize().
static size_t ndn::Face::getMaxNdnPacketSize ( )
inlinestatic

Get the practical limit of the size of a network-layer packet.

If a packet is larger than this, the library or application MAY drop it. This is a static inline method wrapping a const, so you can to use as a constant, e.g.: uint8_t buffer[Face::getMaxNdnPacketSize()].

Returns
The maximum NDN packet size.
bool ndn::Face::isLocal ( )

Check if the face is local based on the current connection through the Transport; some Transport may cause network I/O (e.g.

an IP host name lookup).

Returns
True if the face is local, false if not.
Note
This is an experimental feature. This API may change in the future.
void ndn::Face::makeCommandInterest ( Interest interest,
WireFormat wireFormat = *WireFormat::getDefaultWireFormat() 
)

Append a timestamp component and a random value component to interest's name.

Then use the keyChain and certificateName from setCommandSigningInfo to sign the interest. If the interest lifetime is not set, this sets it.

Parameters
interestThe interest whose name is appended with components.
wireFormatA WireFormat object used to encode the SignatureInfo and to encode the interest name for signing. If omitted, use WireFormat getDefaultWireFormat().
Note
This method is an experimental feature. See the API docs for more detail at http://named-data.net/doc/ndn-ccl-api/face.html#face-makecommandinterest-method .
void ndn::Face::processEvents ( )

Process any packets to receive and call callbacks such as onData, onInterest or onTimeout.

This returns immediately if there is no data to receive. This blocks while calling the callbacks. You should repeatedly call this from an event loop, with calls to sleep as needed so that the loop doesn’t use 100% of the CPU. Since processEvents modifies the pending interest table, your application should make sure that it calls processEvents in the same thread as expressInterest (which also modifies the pending interest table).

Exceptions
Thismay throw an exception for reading data or in the callback for processing the data. If you call this from an main event loop, you may want to catch and log/disregard all exceptions.
void ndn::Face::putData ( const Data data,
WireFormat wireFormat = *WireFormat::getDefaultWireFormat() 
)

The OnInterestCallback calls this to put a Data packet which satisfies an Interest.

Parameters
dataThe Data packet which satisfies the interest.
wireFormat(optional) A WireFormat object used to encode the Data packet. If omitted, use WireFormat getDefaultWireFormat().
Exceptions
runtime_errorIf the encoded Data packet size exceeds getMaxNdnPacketSize().
uint64_t ndn::Face::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.

If you have not called setCommandSigningInfo, this assumes you are connecting to NDNx. If you have called setCommandSigningInfo, this first sends an NFD registration request, and if that times out then this sends an NDNx registration request. If you need to register a prefix with NFD, you must first call setCommandSigningInfo.

Parameters
prefixA reference to a Name for the prefix to register. This copies the Name.
onInterest(optional) If not null, this creates an interest filter from prefix so that when an Interest is received which matches the filter, this calls the function object onInterest(prefix, interest, face, interestFilterId, filter). This copies the function object, so you may need to use func_lib::ref() as appropriate. If onInterest is null, it is ignored and you must call setInterestFilter.
onRegisterFailedA function object to call if failed to retrieve the connected hub’s ID or failed to register the prefix. This calls onRegisterFailed(prefix) where prefix is the prefix given to registerPrefix.
flagsThe flags for finer control of which interests are forward to the application. If omitted, use the default flags defined by the default ForwardingFlags constructor.
wireFormatA WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat().
Returns
The registered prefix ID which can be used with removeRegisteredPrefix.
uint64_t ndn::Face::registerPrefix ( const Name prefix,
const OnInterest onInterest,
const OnRegisterFailed onRegisterFailed,
const ForwardingFlags flags = ForwardingFlags(),
WireFormat wireFormat = *WireFormat::getDefaultWireFormat() 
)
Deprecated:
Use registerPrefix where onInterest is an OnInterestCallback (which is passed this Face for calling putData) instead of the deprecated OnInterest (which is passed a Transport object).
void ndn::Face::removePendingInterest ( uint64_t  pendingInterestId)

Remove the pending interest entry with the pendingInterestId from the pending interest table.

This does not affect another pending interest with a different pendingInterestId, even if it has the same interest name. If there is no entry with the pendingInterestId, do nothing.

Parameters
pendingInterestIdThe ID returned from expressInterest.
void ndn::Face::removeRegisteredPrefix ( uint64_t  registeredPrefixId)

Remove the registered prefix entry with the registeredPrefixId from the registered prefix table.

This does not affect another registered prefix with a different registeredPrefixId, even if it has the same prefix name. If an interest filter was automatically created by registerPrefix, also remove it. If there is no entry with the registeredPrefixId, do nothing.

Parameters
registeredPrefixIdThe ID returned from registerPrefix.
void ndn::Face::send ( const Blob encoding)
inline

Send the encoded packet out through the face.

Parameters
encodingThe blob with the the encoded packet to send.
Exceptions
runtime_errorIf the encoded Data packet size exceeds getMaxNdnPacketSize().
void ndn::Face::send ( const uint8_t *  encoding,
size_t  encodingLength 
)

Send the encoded packet out through the face.

Parameters
encodingThe array of bytes for the encoded packet to send.
encodingLengthThe number of bytes in the encoding array.
Exceptions
runtime_errorIf the encoded Data packet size exceeds getMaxNdnPacketSize().
void ndn::Face::setCommandCertificateName ( const Name certificateName)
inline

Set the certificate name used to sign command interest (e.g.

for registerPrefix), using the KeyChain that was set with setCommandSigningInfo.

Parameters
certificateNameThe certificate name for signing interest. This makes a copy of the Name.
void ndn::Face::setCommandSigningInfo ( KeyChain keyChain,
const Name certificateName 
)
inline

Set the KeyChain and certificate name used to sign command interests (e.g.

for registerPrefix).

Parameters
keyChainThe KeyChain object for signing interests, which must remain valid for the life of this Face. You must create the KeyChain object and pass it in. You can create a default KeyChain for your system with the default KeyChain constructor.
certificateNameThe certificate name for signing interests. This makes a copy of the Name. You can get the default certificate name with keyChain.getDefaultCertificateName() .
uint64_t ndn::Face::setInterestFilter ( const InterestFilter filter,
const OnInterestCallback onInterest 
)

Add an entry to the local interest filter table to call the onInterest callback for a matching incoming Interest.

This method only modifies the library's local callback table and does not register the prefix with the forwarder. It will always succeed. To register a prefix with the forwarder, use registerPrefix.

Parameters
filterThe InterestFilter with a prefix and optional regex filter used to match the name of an incoming Interest. This makes a copy of filter.
onInterestWhen an Interest is received which matches the filter, this calls onInterest(prefix, interest, face, interestFilterId, filter).
Returns
The interest filter ID which can be used with unsetInterestFilter.
uint64_t ndn::Face::setInterestFilter ( const Name prefix,
const OnInterestCallback onInterest 
)

Add an entry to the local interest filter table to call the onInterest callback for a matching incoming Interest.

This method only modifies the library's local callback table and does not register the prefix with the forwarder. It will always succeed. To register a prefix with the forwarder, use registerPrefix.

Parameters
prefixThe Name prefix used to match the name of an incoming Interest.
onInterestThis creates an interest filter from prefix so that when an Interest is received which matches the filter, this calls onInterest(prefix, interest, face, interestFilterId, filter).
Returns
The interest filter ID which can be used with unsetInterestFilter.
void ndn::Face::unsetInterestFilter ( uint64_t  interestFilterId)

Remove the interest filter entry which has the interestFilterId from the interest filter table.

This does not affect another interest filter with a different interestFilterId, even if it has the same prefix name. If there is no entry with the interestFilterId, do nothing.

Parameters
interestFilterIdThe ID returned from setInterestFilter.

The documentation for this class was generated from the following files: