Jeff Thompson | cf624b9 | 2013-08-23 20:51:06 -0700 | [diff] [blame^] | 1 | /** |
| 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 | |
| 13 | using namespace std; |
| 14 | using namespace ndn; |
| 15 | using namespace ptr_lib; |
| 16 | using namespace func_lib; |
| 17 | |
| 18 | class Echo { |
| 19 | public: |
| 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 | |
| 41 | int 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 | } |