Public Member Functions | |
Node (const ptr_lib::shared_ptr< Transport > &transport, const ptr_lib::shared_ptr< const Transport::ConnectionInfo > &connectionInfo) | |
Create a new Node for communication with an NDN hub with the given Transport object and connectionInfo. More... | |
void | expressInterest (uint64_t pendingInterestId, const ptr_lib::shared_ptr< const Interest > &interestCopy, const OnData &onData, const OnTimeout &onTimeout, const OnNetworkNack &onNetworkNack, WireFormat &wireFormat, Face *face) |
Send the Interest through the transport, read the entire response and call onData, onTimeout or onNetworkNack as described below. More... | |
void | removePendingInterest (uint64_t pendingInterestId) |
Remove the pending interest entry with the pendingInterestId from the pending interest table. More... | |
void | makeCommandInterest (Interest &interest, KeyChain &keyChain, const Name &certificateName, WireFormat &wireFormat) |
Append a timestamp component and a random value component to interest's name. More... | |
void | registerPrefix (uint64_t registeredPrefixId, const ptr_lib::shared_ptr< const Name > &prefixCopy, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, const OnRegisterSuccess &onRegisterSuccess, const ForwardingFlags &flags, WireFormat &wireFormat, KeyChain &commandKeyChain, const Name &commandCertificateName, Face *face) |
Register prefix with the connected NDN hub and call onInterest when a matching interest is received. More... | |
void | registerPrefix (uint64_t registeredPrefixId, const ptr_lib::shared_ptr< const Name > &prefixCopy, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, const OnRegisterSuccess &onRegisterSuccess, const ForwardingFlags &flags, WireFormat &wireFormat, Face *face) |
This is the same as registerPrefix above except get the commandKeyChain and commandCertificateName directly from face. | |
void | removeRegisteredPrefix (uint64_t registeredPrefixId) |
Remove the registered prefix entry with the registeredPrefixId from the registered prefix table. More... | |
void | setInterestFilter (uint64_t interestFilterId, const ptr_lib::shared_ptr< const InterestFilter > &filterCopy, const OnInterestCallback &onInterest, Face *face) |
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 | 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... | |
const ptr_lib::shared_ptr< Transport > & | getTransport () |
const ptr_lib::shared_ptr< const Transport::ConnectionInfo > & | getConnectionInfo () |
void | onReceivedElement (const uint8_t *element, size_t elementLength) |
This is called when an entire element is received. 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 () |
void | callLater (Milliseconds delayMilliseconds, const Face::Callback &callback) |
Call callback() after the given delay. More... | |
uint64_t | getNextEntryId () |
Get the next unique entry ID for the pending interest table, interest filter table, etc. More... | |
Static Public Member Functions | |
static size_t | getMaxNdnPacketSize () |
Get the practical limit of the size of a network-layer packet. More... | |
Additional Inherited Members | |
Public Attributes inherited from ndn_ElementListener | |
ndn_OnReceivedElement | onReceivedElement |
see ndn_ElementListener_initialize | |
ndn::Node::Node | ( | const ptr_lib::shared_ptr< Transport > & | transport, |
const ptr_lib::shared_ptr< const Transport::ConnectionInfo > & | connectionInfo | ||
) |
Create a new Node for communication with an NDN hub with the given Transport object and connectionInfo.
transport | A shared_ptr to a Transport object used for communication. |
transport | A shared_ptr to a Transport::ConnectionInfo to be used to connect to the transport. |
|
inline |
Call callback() after the given delay.
This adds to delayedCallTable_ which is used by processEvents().
delayMilliseconds | The delay in milliseconds. |
callback | This calls callback() after the delay. |
void ndn::Node::expressInterest | ( | uint64_t | pendingInterestId, |
const ptr_lib::shared_ptr< const Interest > & | interestCopy, | ||
const OnData & | onData, | ||
const OnTimeout & | onTimeout, | ||
const OnNetworkNack & | onNetworkNack, | ||
WireFormat & | wireFormat, | ||
Face * | face | ||
) |
Send the Interest through the transport, read the entire response and call onData, onTimeout or onNetworkNack as described below.
pendingInterestId | The getNextEntryId() for the pending interest ID which Face got so it could return it to the caller. |
interestCopy | The Interest which is NOT copied for this internal Node method. The Face expressInterest is responsible for making a copy and passing a shared_ptr for Node to use. |
onData | When a matching data packet is received, this calls onData(interest, data) where interest is the interest given to expressInterest and data is the received Data object. This copies the function object, so you may need to use func_lib::ref() as appropriate. |
onTimeout | If the interest times out according to the interest lifetime, this calls onTimeout(interest) where interest is the interest given to expressInterest. 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. |
onNetworkNack | When a network Nack packet for the interest is received and onNetworkNack is not null, this calls onNetworkNack(interest, networkNack) and does not call onTimeout. However, if a network Nack is received and onNetworkNack is an empty OnNetworkNack(), do nothing and wait for the interest to time out. This copies the function object, so you may need to use func_lib::ref() as appropriate. |
wireFormat | A WireFormat object used to encode the message. |
face | The face which has the callLater method, used for interest timeouts. The callLater method may be overridden in a subclass of Face. |
runtime_error | If the encoded interest size exceeds 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()].
uint64_t ndn::Node::getNextEntryId | ( | ) |
Get the next unique entry ID for the pending interest table, interest filter table, etc.
This uses an atomic_uint64_t to be thread safe. Most entry IDs are for the pending interest table (there usually are not many interest filter table entries) so we use a common pool to only have to do the thread safe operation in one method which is called by Face.
|
inline |
|
inline |
Append a timestamp component and a random value component to interest's name.
Then use the keyChain and certificateName to sign the interest. If the interest lifetime is not set, this sets it.
interest | The interest whose name is append with components. |
keyChain | The KeyChain object for signing interests. |
certificateName | The certificate name for signing interests. |
wireFormat | A WireFormat object used to encode the SignatureInfo and to encode interest name for signing. |
|
virtual |
This is called when an entire element is received.
You must extend this class to override this method.
element | pointer to the element. This buffer is only valid during this call. If you need the data later, you must copy. |
elementLength | length of element |
Implements ndn::ElementListener.
void ndn::Node::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).
This | may 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::Node::registerPrefix | ( | uint64_t | registeredPrefixId, |
const ptr_lib::shared_ptr< const Name > & | prefixCopy, | ||
const OnInterestCallback & | onInterest, | ||
const OnRegisterFailed & | onRegisterFailed, | ||
const OnRegisterSuccess & | onRegisterSuccess, | ||
const ForwardingFlags & | flags, | ||
WireFormat & | wireFormat, | ||
KeyChain & | commandKeyChain, | ||
const Name & | commandCertificateName, | ||
Face * | face | ||
) |
Register prefix with the connected NDN hub and call onInterest when a matching interest is received.
registeredPrefixId | The getNextEntryId() for the registered prefix ID which Face got so it could return it to the caller. |
prefixCopy | The Name for the prefix to register, which is NOT copied for this internal Node method. The Face registerPrefix is responsible for making a copy and passing a shared_ptr for Node to use. |
onInterest | (optional) If not an empty OnInterestCallback(), 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 an empty OnInterestCallback(), it is ignored and you must call setInterestFilter. |
onRegisterFailed | A 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. |
onRegisterSuccess | A function object to call when registerPrefix receives a success message from the forwarder. This calls onRegisterSuccess(prefix, registeredPrefixId) where prefix and registeredPrefixId are the values given to registerPrefix. If onRegisterSuccess is an empty OnRegisterSuccess(), this does not use it. |
flags | The flags for finer control of which interests are forwarded to the application. |
wireFormat | A WireFormat object used to encode the message. |
commandKeyChain | The KeyChain object for signing interests. |
commandCertificateName | The certificate name for signing interests. |
face | The face which is passed to the onInterest callback. If onInterest is null, this is ignored. |
|
inline |
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.
pendingInterestId | The ID returned from expressInterest. |
|
inline |
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 there is no entry with the registeredPrefixId, do nothing. If an interest filter was automatically created by registerPrefix, also remove it.
registeredPrefixId | The ID returned from registerPrefix. |
void ndn::Node::send | ( | const uint8_t * | encoding, |
size_t | encodingLength | ||
) |
Send the encoded packet out through the face.
encoding | The array of bytes for the encoded packet to send. |
encodingLength | The number of bytes in the encoding array. |
runtime_error | If the encoded Data packet size exceeds getMaxNdnPacketSize(). |
|
inline |
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.
interestFilterId | The getNextEntryId() for the interest filter ID which Face got so it could return it to the caller. |
filterCopy | The InterestFilter with a prefix and optional regex filter used to match the name of an incoming Interest, which is NOT copied for this internal Node method. The Face setInterestFilter is responsible for making a copy and passing a shared_ptr for Node to use. |
onInterest | When an Interest is received which matches the filter, this calls onInterest(prefix, interest, face, interestFilterId, filter). |
face | The face which is passed to the onInterest callback. |
|
inline |
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.
interestFilterId | The ID returned from setInterestFilter. |