27 #include <ndnboost/atomic.hpp>
28 #include <ndn-cpp/common.hpp>
29 #include <ndn-cpp/interest.hpp>
30 #include <ndn-cpp/data.hpp>
31 #include <ndn-cpp/forwarding-flags.hpp>
32 #include <ndn-cpp/interest-filter.hpp>
33 #include <ndn-cpp/face.hpp>
34 #include "util/command-interest-generator.hpp"
35 #include "encoding/element-listener.hpp"
50 Node(
const ptr_lib::shared_ptr<Transport>& transport,
const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& connectionInfo);
71 (uint64_t pendingInterestId,
72 const ptr_lib::shared_ptr<const Interest>& interestCopy,
101 (interest, keyChain, certificateName, wireFormat);
134 (uint64_t registeredPrefixId,
135 const ptr_lib::shared_ptr<const Name>& prefixCopy,
140 const Name& commandCertificateName,
Face* face);
148 (uint64_t registeredPrefixId,
149 const ptr_lib::shared_ptr<const Name>& prefixCopy,
156 (registeredPrefixId, prefixCopy, onInterest, onRegisterFailed,
157 onRegisterSuccess, flags, wireFormat, *face->getCommandKeyChain(),
158 face->getCommandCertificateName(), face);
191 (uint64_t interestFilterId,
192 const ptr_lib::shared_ptr<const InterestFilter>& filterCopy,
213 send(
const uint8_t *encoding,
size_t encodingLength);
230 const ptr_lib::shared_ptr<Transport>&
231 getTransport() {
return transport_; }
233 const ptr_lib::shared_ptr<const Transport::ConnectionInfo>&
234 getConnectionInfo() {
return connectionInfo_; }
245 isLocal() {
return transport_->isLocal(*connectionInfo_); }
282 ConnectStatus_UNCONNECTED = 1,
283 ConnectStatus_CONNECT_REQUESTED = 2,
284 ConnectStatus_CONNECT_COMPLETE = 3
305 getCallTime()
const {
return callTime_; }
312 callCallback()
const { callback_(); }
321 (
const ptr_lib::shared_ptr<const DelayedCall>& x,
322 const ptr_lib::shared_ptr<const DelayedCall>& y)
const
324 return x->callTime_ < y->callTime_;
333 class PendingInterest {
344 (uint64_t pendingInterestId,
const ptr_lib::shared_ptr<const Interest>& interest,
const OnData& onData,
351 getPendingInterestId() {
return pendingInterestId_; }
353 const ptr_lib::shared_ptr<const Interest>&
354 getInterest() {
return interest_; }
357 getOnData() {
return onData_; }
363 setIsRemoved() { isRemoved_ =
true; }
370 getIsRemoved() {
return isRemoved_; }
379 ptr_lib::shared_ptr<const Interest> interest_;
380 uint64_t pendingInterestId_;
392 class RegisteredPrefix {
404 (uint64_t registeredPrefixId,
const ptr_lib::shared_ptr<const Name>& prefix,
405 uint64_t relatedInterestFilterId)
406 : registeredPrefixId_(registeredPrefixId), prefix_(prefix),
407 relatedInterestFilterId_(relatedInterestFilterId)
416 getRegisteredPrefixId() {
return registeredPrefixId_; }
422 const ptr_lib::shared_ptr<const Name>&
423 getPrefix() {
return prefix_; }
430 getRelatedInterestFilterId() {
return relatedInterestFilterId_; }
433 uint64_t registeredPrefixId_;
434 ptr_lib::shared_ptr<const Name> prefix_;
435 uint64_t relatedInterestFilterId_;
442 class InterestFilterEntry {
454 (uint64_t interestFilterId,
455 const ptr_lib::shared_ptr<const InterestFilter>& filter,
457 : interestFilterId_(interestFilterId), filter_(filter),
458 prefix_(new Name(filter->getPrefix())), onInterest_(onInterest), face_(face)
467 getInterestFilterId() {
return interestFilterId_; }
473 const ptr_lib::shared_ptr<const InterestFilter>&
474 getFilter() {
return filter_; }
482 const ptr_lib::shared_ptr<const Name>&
483 getPrefix() {
return prefix_; }
490 getOnInterest() {
return onInterest_; }
497 getFace() {
return *face_; }
500 uint64_t interestFilterId_;
501 ptr_lib::shared_ptr<const InterestFilter> filter_;
502 ptr_lib::shared_ptr<const Name> prefix_;
513 class RegisterResponse {
516 RegisterResponse(ptr_lib::shared_ptr<RegisterResponse::Info> info)
527 operator()(
const ptr_lib::shared_ptr<const Interest>& interest,
528 const ptr_lib::shared_ptr<Data>& responseData);
535 operator()(
const ptr_lib::shared_ptr<const Interest>& timedOutInterest);
539 Info(
const ptr_lib::shared_ptr<const Name>& prefix,
542 uint64_t registeredPrefixId)
543 : prefix_(prefix), onRegisterFailed_(onRegisterFailed),
544 onRegisterSuccess_(onRegisterSuccess),
545 registeredPrefixId_(registeredPrefixId)
549 ptr_lib::shared_ptr<const Name> prefix_;
552 uint64_t registeredPrefixId_;
556 ptr_lib::shared_ptr<Info> info_;
577 expressInterestHelper
578 (uint64_t pendingInterestId,
579 const ptr_lib::shared_ptr<const Interest>& interestCopy,
590 processInterestTimeout(ptr_lib::shared_ptr<PendingInterest> pendingInterest);
601 extractEntriesForExpressedInterest
603 std::vector<ptr_lib::shared_ptr<PendingInterest> > &entries);
621 (uint64_t registeredPrefixId,
const ptr_lib::shared_ptr<const Name>& prefix,
625 KeyChain& commandKeyChain,
const Name& commandCertificateName,
634 ptr_lib::shared_ptr<Transport> transport_;
635 ptr_lib::shared_ptr<const Transport::ConnectionInfo> connectionInfo_;
636 std::vector<ptr_lib::shared_ptr<PendingInterest> > pendingInterestTable_;
637 std::vector<ptr_lib::shared_ptr<RegisteredPrefix> > registeredPrefixTable_;
638 std::vector<ptr_lib::shared_ptr<InterestFilterEntry> > interestFilterTable_;
640 std::deque<ptr_lib::shared_ptr<DelayedCall> > delayedCallTable_;
642 std::vector<Face::Callback> onConnectedCallbacks_;
648 ndnboost::atomic_uint64_t lastEntryId_;
649 ConnectStatus connectStatus_;
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
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:111
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
void expressInterest(uint64_t pendingInterestId, const ptr_lib::shared_ptr< const Interest > &interestCopy, const OnData &onData, const OnTimeout &onTimeout, WireFormat &wireFormat, Face *face)
Send the Interest through the transport, read the entire response and call onData(interest, data).
Definition: node.cpp:52
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 incomi...
Definition: node.cpp:163
void callLater(Milliseconds delayMilliseconds, const Face::Callback &callback)
Call callback() after the given delay.
Definition: node.cpp:456
void processEvents()
Process any packets to receive and call callbacks such as onData, onInterest or onTimeout.
Definition: node.cpp:320
The Face class provides the main methods for NDN communication.
Definition: face.hpp:78
An ElementListener extends an ndn_ElementListener struct to proved an abstract virtual onReceivedElem...
Definition: element-listener.hpp:33
A ForwardingFlags object holds the flags which specify how the forwarding daemon should forward an in...
Definition: forwarding-flags.hpp:35
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &, uint64_t)> OnRegisterSuccess
An OnRegisterSuccess function object is used to report when registerPrefix succeeds.
Definition: face.hpp:70
static size_t getMaxNdnPacketSize()
Get the practical limit of the size of a network-layer packet.
Definition: node.hpp:258
An ndn_Interest holds an ndn_Name and other fields for an interest.
Definition: interest-types.h:61
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 connectionInf...
Definition: node.cpp:43
void send(const uint8_t *encoding, size_t encodingLength)
Send the encoded packet out through the face.
Definition: node.cpp:189
void unsetInterestFilter(uint64_t interestFilterId)
Remove the interest filter entry which has the interestFilterId from the interest filter table...
Definition: node.cpp:172
KeyChain is the main class of the security library.
Definition: key-chain.hpp:45
void onReceivedElement(const uint8_t *element, size_t elementLength)
This is called when an entire element is received.
Definition: node.cpp:340
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:38
func_lib::function< void()> Callback
Face::Callback is used internally in callLater.
Definition: face.hpp:461
void makeCommandInterest(Interest &interest, KeyChain &keyChain, const Name &certificateName, WireFormat &wireFormat)
Append a timestamp component and a random value component to interest's name.
Definition: node.hpp:97
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:116
void removeRegisteredPrefix(uint64_t registeredPrefixId)
Remove the registered prefix entry with the registeredPrefixId from the registered prefix table...
Definition: node.cpp:138
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
uint64_t getNextEntryId()
Get the next unique entry ID for the pending interest table, interest filter table, etc.
Definition: node.cpp:199
An CommandInterestGenerator keeps track of a timestamp and generates command interests according to t...
Definition: command-interest-generator.hpp:35
bool isLocal()
Check if the face is local based on the current connection through the Transport; some Transport may ...
Definition: node.hpp:245
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
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...
Definition: node.cpp:123
void generate(Interest &interest, KeyChain &keyChain, const Name &certificateName, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Append a timestamp component and a random value component to interest's name.
Definition: command-interest-generator.cpp:40
void removePendingInterest(uint64_t pendingInterestId)
Remove the pending interest entry with the pendingInterestId from the pending interest table...
Definition: node.cpp:102
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
Compare shared_ptrs to DelayedCall based only on callTime_.
Definition: node.hpp:317