blob: d081cb3770ed4963b7b76b7f2c5eb909a7bacbfe [file] [log] [blame]
Alexander Afanasyevc4b75982014-01-09 14:51:45 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
Alexander Afanasyev09c613f2014-01-29 00:23:58 -08008// correct way to include NDN-CPP headers
9// #include <ndn-cpp-dev/face.hpp>
10// #include <ndn-cpp-dev/security/key-chain.hpp>
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080011
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080012#include "face.hpp"
13#include "security/key-chain.hpp"
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080014
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080015using namespace ndn;
16
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080017class Producer
18{
19public:
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080020 Producer()
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080021 {
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080022 }
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080023
24 void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080025 onInterest(const Name& name, const Interest& interest)
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080026 {
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080027 std::cout << "<< I: " << interest << std::endl;
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080028
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080029 ndn::Data data(ndn::Name(interest.getName()).append("testApp").appendVersion());
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080030 data.setFreshnessPeriod(1000); // 10 sec
31
32 data.setContent((const uint8_t*)"HELLO KITTY", sizeof("HELLO KITTY"));
33
34 keyChain_.sign(data);
35
36 std::cout << ">> D: " << data << std::endl;
37 face_.put(data);
38 }
39
Alexander Afanasyeve289b532014-02-09 22:14:44 -080040
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080041 void
Alexander Afanasyeve289b532014-02-09 22:14:44 -080042 onRegisterFailed (const ndn::Name& prefix, const std::string& reason)
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080043 {
Alexander Afanasyeve289b532014-02-09 22:14:44 -080044 std::cerr << "ERROR: Failed to register prefix in local hub's daemon (" << reason << ")" << std::endl;
45 face_.shutdown ();
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080046 }
47
48 void
49 listen()
50 {
51 face_.setInterestFilter("/localhost/testApp",
52 func_lib::bind(&Producer::onInterest, this, _1, _2),
Alexander Afanasyeve289b532014-02-09 22:14:44 -080053 func_lib::bind(&Producer::onRegisterFailed, this, _1, _2));
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080054 face_.processEvents();
55 }
56
57private:
58 ndn::Face face_;
Alexander Afanasyev22a315f2014-01-16 21:29:37 -080059 KeyChain keyChain_;
Alexander Afanasyevc4b75982014-01-09 14:51:45 -080060
61 Buffer ndndId_;
62};
63
64int main()
65{
66 try {
67 Producer producer;
68 producer.listen();
69 }
70 catch(std::exception &e) {
71 std::cerr << "ERROR: " << e.what() << std::endl;
72 }
73 return 0;
74}