blob: a7ba291ad3f321f187af11119505526a9b950998 [file] [log] [blame]
Jeff Thompsoncf624b92013-08-23 20:51:06 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#include <cstdlib>
7#include <sstream>
8#include <iostream>
9#include <time.h>
10#include "../ndn-cpp/face.hpp"
11#include "../ndn-cpp/key-chain.hpp"
12
13using namespace std;
14using namespace ndn;
15using namespace ptr_lib;
16using namespace func_lib;
17
18class Echo {
19public:
20 Echo()
21 {
22 interestCount_ = 0;
23 }
24
25 void operator()(const ptr_lib::shared_ptr<const Name> &prefix, const ptr_lib::shared_ptr<const Interest> &interest) {
26 ++interestCount_;
27
28 // Make and sign a Data packet.
29 Data data(interest->getName());
30 string content(string("Echo ") + interest->getName().toUri());
31 data.setContent((const unsigned char*)&content[0], sizeof(content));
32 data.getSignedInfo().setTimestampMilliseconds(time(NULL) * 1000.0);
33 KeyChain::defaultSign(data);
34
35 // TODO: Need to put the Data.
36 }
37
38 int interestCount_;
39};
40
41int main(int argc, char** argv)
42{
43 try {
44 Face face("localhost");
45
46 Echo echo;
47 Name prefix("/testecho");
48 cout << "Register prefix " << prefix.toUri() << endl;
49 face.registerPrefix(prefix, ref(echo));
50
51 // The main event loop.
52 while (echo.interestCount_ < 1) {
53 face.processEvents();
54 // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
55 usleep(10000);
56 }
57 } catch (std::exception &e) {
58 cout << "exception: " << e.what() << endl;
59 }
60 return 0;
61}