Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 8 | // correct way to include NDN-CPP headers |
| 9 | // #include <ndn-cpp-dev/face.hpp> |
| 10 | // #include <ndn-cpp-dev/security/key-chain.hpp> |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 11 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 12 | #include "face.hpp" |
| 13 | #include "security/key-chain.hpp" |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 14 | |
| 15 | #if NDN_CPP_HAVE_CXX11 |
| 16 | // In the std library, the placeholders are in a different namespace than boost. |
| 17 | using namespace ndn::func_lib::placeholders; |
| 18 | #endif |
| 19 | |
| 20 | using namespace ndn; |
| 21 | |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 22 | class Producer |
| 23 | { |
| 24 | public: |
| 25 | //////////////////////////////////////////////////////////////////////////////////////// |
| 26 | // CREATE TEST KEYCHAIN (THIS CODE IS ONLY FOR DEBUGGING, NOT TO BE USED IN REAL APPS // |
| 27 | //////////////////////////////////////////////////////////////////////////////////////// |
| 28 | Producer() |
Yingdi Yu | f4330ee | 2014-01-14 14:34:46 -0800 | [diff] [blame] | 29 | : keyChain_() |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 30 | { |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 31 | } |
| 32 | //////////////////////////////////////////////////////////////////////////////////////// |
| 33 | //////////////////////////////////////////////////////////////////////////////////////// |
| 34 | //////////////////////////////////////////////////////////////////////////////////////// |
| 35 | |
| 36 | void |
| 37 | onInterest(const ptr_lib::shared_ptr<const Name> &name, const ptr_lib::shared_ptr<const Interest> &interest) |
| 38 | { |
| 39 | std::cout << "<< I: " << *interest << std::endl; |
| 40 | |
| 41 | ndn::Data data(ndn::Name(interest->getName()).append("testApp").appendVersion()); |
| 42 | data.setFreshnessPeriod(1000); // 10 sec |
| 43 | |
| 44 | data.setContent((const uint8_t*)"HELLO KITTY", sizeof("HELLO KITTY")); |
| 45 | |
| 46 | keyChain_.sign(data); |
| 47 | |
| 48 | std::cout << ">> D: " << data << std::endl; |
| 49 | face_.put(data); |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | onRegisterFailed(const ptr_lib::shared_ptr<const Name>&) |
| 54 | { |
| 55 | std::cerr << "ERROR: Failed to register prefix in local hub's daemon" << std::endl; |
| 56 | face_.shutdown(); |
| 57 | } |
| 58 | |
| 59 | void |
| 60 | listen() |
| 61 | { |
| 62 | face_.setInterestFilter("/localhost/testApp", |
| 63 | func_lib::bind(&Producer::onInterest, this, _1, _2), |
| 64 | func_lib::bind(&Producer::onRegisterFailed, this, _1)); |
| 65 | face_.processEvents(); |
| 66 | } |
| 67 | |
| 68 | private: |
| 69 | ndn::Face face_; |
Alexander Afanasyev | 22a315f | 2014-01-16 21:29:37 -0800 | [diff] [blame] | 70 | KeyChain keyChain_; |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 71 | |
| 72 | Buffer ndndId_; |
| 73 | }; |
| 74 | |
| 75 | int main() |
| 76 | { |
| 77 | try { |
| 78 | Producer producer; |
| 79 | producer.listen(); |
| 80 | } |
| 81 | catch(std::exception &e) { |
| 82 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 83 | } |
| 84 | return 0; |
| 85 | } |