-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproducer.cpp
59 lines (47 loc) · 2.36 KB
/
producer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/security/key-chain.hpp>
#include <iostream>
using namespace ndn;
int main(int argc, char** argv)
{
Face faceToNFD;
KeyChain appKeyChain;
appKeyChain.createIdentity("/cs217/100");
Name dataName("/cs217/100/test-data");
auto onInterest = [&] (const InterestFilter& filter, const Interest& interest) {
std::cout << "<< I: " << interest << std::endl;
Data data(dataName);
appKeyChain.sign(data);
faceToNFD.put(data);
};
auto onFailure = [] (const Name& prefix, const std::string& reason) {
std::cout << "fail to register " << prefix << " due to: " << reason << std::endl;
};
faceToNFD.setInterestFilter(dataName, onInterest, onFailure);
faceToNFD.processEvents();
return 0;
}
/*
|------------------------------------------------------------------------------|
| Set InterestFilter to dispatch incoming matching interest to onInterest |
| callback and register the filtered prefix with the connected NDN forwarder |
|------------------------------------------------------------------------------|
const RegisteredPrefixId*
setInterestFilter(const InterestFilter& interestFilter,
const InterestCallback& onInterest,
const RegisterPrefixFailureCallback& onFailure,
const security::SigningInfo& signingInfo = security::SigningInfo(),
uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
|------------------------------------------------------------------------------|
| Construct an InterestFilter to match Interests by prefix |
|------------------------------------------------------------------------------|
InterestFilter(const Name& prefix)
|------------------------------------------------------------------------------|
| Callback invoked when incoming Interest matches the specified InterestFilter |
|------------------------------------------------------------------------------|
typedef function<void(const InterestFilter&, const Interest&)> InterestCallback;
|------------------------------------------------------------------------------|
| Callback invoked when registerPrefix or setInterestFilter command fails |
|------------------------------------------------------------------------------|
typedef function<void(const Name&, const std::string&)> RegisterPrefixFailureCallback;
*/