25 #include <ndn-cpp/common.hpp>
26 #include <ndn-cpp/interest.hpp>
27 #include <ndn-cpp/data.hpp>
28 #include <ndn-cpp/forwarding-flags.hpp>
29 #include <ndn-cpp/interest-filter.hpp>
30 #include <ndn-cpp/face.hpp>
31 #include "util/command-interest-generator.hpp"
32 #include "encoding/element-listener.hpp"
47 Node(
const ptr_lib::shared_ptr<Transport>& transport,
const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& connectionInfo);
89 (interest, keyChain, certificateName, wireFormat);
118 const Name& commandCertificateName,
Face* face);
150 uint64_t interestFilterId = InterestFilterEntry::getNextInterestFilterId();
151 interestFilterTable_.push_back(ptr_lib::make_shared<InterestFilterEntry>
152 (interestFilterId, ptr_lib::make_shared<const InterestFilter>(filter),
155 return interestFilterId;
187 send(
const uint8_t *encoding,
size_t encodingLength);
204 const ptr_lib::shared_ptr<Transport>&
205 getTransport() {
return transport_; }
207 const ptr_lib::shared_ptr<const Transport::ConnectionInfo>&
208 getConnectionInfo() {
return connectionInfo_; }
219 isLocal() {
return transport_->isLocal(*connectionInfo_); }
235 class PendingInterest {
245 (uint64_t pendingInterestId,
const ptr_lib::shared_ptr<const Interest>& interest,
const OnData& onData,
252 getNextPendingInterestId()
254 return ++lastPendingInterestId_;
261 getPendingInterestId() {
return pendingInterestId_; }
263 const ptr_lib::shared_ptr<const Interest>&
264 getInterest() {
return interest_; }
267 getOnData() {
return onData_; }
277 return timeoutTimeMilliseconds_ >= 0.0 && nowMilliseconds >= timeoutTimeMilliseconds_;
287 ptr_lib::shared_ptr<const Interest> interest_;
288 static uint64_t lastPendingInterestId_;
289 uint64_t pendingInterestId_;
301 class RegisteredPrefix {
312 (uint64_t registeredPrefixId,
const ptr_lib::shared_ptr<const Name>& prefix,
313 uint64_t relatedInterestFilterId)
314 : registeredPrefixId_(registeredPrefixId), prefix_(prefix),
315 relatedInterestFilterId_(relatedInterestFilterId)
324 getNextRegisteredPrefixId()
326 return ++lastRegisteredPrefixId_;
334 getRegisteredPrefixId() {
return registeredPrefixId_; }
340 const ptr_lib::shared_ptr<const Name>&
341 getPrefix() {
return prefix_; }
348 getRelatedInterestFilterId() {
return relatedInterestFilterId_; }
351 static uint64_t lastRegisteredPrefixId_;
352 uint64_t registeredPrefixId_;
353 ptr_lib::shared_ptr<const Name> prefix_;
354 uint64_t relatedInterestFilterId_;
361 class InterestFilterEntry {
373 (uint64_t interestFilterId,
374 const ptr_lib::shared_ptr<const InterestFilter>& filter,
376 : interestFilterId_(interestFilterId), filter_(filter),
377 prefix_(new Name(filter->getPrefix())), onInterest_(onInterest), face_(face)
388 getNextInterestFilterId()
390 return RegisteredPrefix::getNextRegisteredPrefixId();
398 getInterestFilterId() {
return interestFilterId_; }
404 const ptr_lib::shared_ptr<const InterestFilter>&
405 getFilter() {
return filter_; }
413 const ptr_lib::shared_ptr<const Name>&
414 getPrefix() {
return prefix_; }
421 getOnInterest() {
return onInterest_; }
428 getFace() {
return *face_; }
431 uint64_t interestFilterId_;
432 ptr_lib::shared_ptr<const InterestFilter> filter_;
433 ptr_lib::shared_ptr<const Name> prefix_;
442 class NdndIdFetcher {
445 NdndIdFetcher(ptr_lib::shared_ptr<NdndIdFetcher::Info> info)
456 operator()(
const ptr_lib::shared_ptr<const Interest>& interest,
const ptr_lib::shared_ptr<Data>& ndndIdData);
463 operator()(
const ptr_lib::shared_ptr<const Interest>& timedOutInterest);
482 : node_(*node), registeredPrefixId_(registeredPrefixId),
483 prefix_(new
Name(prefix)), onInterest_(onInterest),
484 onRegisterFailed_(onRegisterFailed), flags_(flags),
485 wireFormat_(wireFormat), face_(face)
490 uint64_t registeredPrefixId_;
491 ptr_lib::shared_ptr<const Name> prefix_;
500 ptr_lib::shared_ptr<Info> info_;
510 class RegisterResponse {
513 RegisterResponse(ptr_lib::shared_ptr<RegisterResponse::Info> info)
524 operator()(
const ptr_lib::shared_ptr<const Interest>& interest,
525 const ptr_lib::shared_ptr<Data>& responseData);
532 operator()(
const ptr_lib::shared_ptr<const Interest>& timedOutInterest);
536 Info(
Node* node,
const ptr_lib::shared_ptr<const Name>& prefix,
540 bool isNfdCommand,
Face* face)
541 : node_(*node), prefix_(prefix), onInterest_(onInterest),
542 onRegisterFailed_(onRegisterFailed), flags_(flags),
543 wireFormat_(wireFormat), isNfdCommand_(isNfdCommand), face_(face)
548 ptr_lib::shared_ptr<const Name> prefix_;
558 ptr_lib::shared_ptr<Info> info_;
570 extractEntriesForExpressedInterest
572 std::vector<ptr_lib::shared_ptr<PendingInterest> > &entries);
589 (uint64_t registeredPrefixId,
const ptr_lib::shared_ptr<const Name>& prefix,
609 (uint64_t registeredPrefixId,
const ptr_lib::shared_ptr<const Name>& prefix,
614 ptr_lib::shared_ptr<Transport> transport_;
615 ptr_lib::shared_ptr<const Transport::ConnectionInfo> connectionInfo_;
616 std::vector<ptr_lib::shared_ptr<PendingInterest> > pendingInterestTable_;
617 std::vector<ptr_lib::shared_ptr<RegisteredPrefix> > registeredPrefixTable_;
618 std::vector<ptr_lib::shared_ptr<InterestFilterEntry> > interestFilterTable_;
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
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
void processEvents()
Process any packets to receive and call callbacks such as onData, onInterest or onTimeout.
Definition: node.cpp:592
The Face class provides the main methods for NDN communication.
Definition: face.hpp:72
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:34
uint64_t registerPrefix(const Name &prefix, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, 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:241
static size_t getMaxNdnPacketSize()
Get the practical limit of the size of a network-layer packet.
Definition: node.hpp:232
An ndn_Interest holds an ndn_Name and other fields for an interest.
Definition: interest-types.h:70
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:192
void send(const uint8_t *encoding, size_t encodingLength)
Send the encoded packet out through the face.
Definition: node.cpp:334
void unsetInterestFilter(uint64_t interestFilterId)
Remove the interest filter entry which has the interestFilterId from the interest filter table...
Definition: node.cpp:306
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 binary XML element is received.
Definition: node.cpp:612
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
uint64_t expressInterest(const Interest &interest, const OnData &onData, const OnTimeout &onTimeout, WireFormat &wireFormat)
Send the Interest through the transport, read the entire response and call onData(interest, data).
Definition: node.cpp:200
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:85
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:282
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
void putData(const Data &data, WireFormat &wireFormat)
The OnInterestCallback calls this to put a Data packet which satisfies an Interest.
Definition: node.cpp:323
An CommandInterestGenerator keeps track of a timestamp and generates command interests according to t...
Definition: command-interest-generator.hpp:35
Info(Node *node, uint64_t registeredPrefixId, const Name &prefix, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, const ForwardingFlags &flags, WireFormat &wireFormat, Face *face)
Definition: node.hpp:478
bool isLocal()
Check if the face is local based on the current connection through the Transport; some Transport may ...
Definition: node.hpp:219
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 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:223
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
uint64_t setInterestFilter(const InterestFilter &filter, 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.hpp:147