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