Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
Jeff Thompson | 3b3aabf | 2013-06-21 16:50:20 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <cstdlib> |
| 7 | #include <sstream> |
| 8 | #include <iostream> |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 9 | #include <ndn-cpp/Interest.hpp> |
Jeff Thompson | 0d567da | 2013-07-14 22:10:21 -0700 | [diff] [blame^] | 10 | #include <ndn-cpp/c/network/TcpTransport.h> |
Jeff Thompson | 3b3aabf | 2013-06-21 16:50:20 -0700 | [diff] [blame] | 11 | |
| 12 | using namespace std; |
| 13 | using namespace ndn; |
| 14 | |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 15 | unsigned char Interest1[] = { |
Jeff Thompson | 7afc98e | 2013-06-27 14:33:53 -0700 | [diff] [blame] | 16 | 0x01, 0xd2, |
| 17 | 0xf2, 0xfa, 0x9d, 0x6e, 0x64, 0x6e, 0x00, 0xfa, 0x9d, 0x61, 0x62, 0x63, 0x00, 0x00, |
Jeff Thompson | 06f824a | 2013-07-08 17:14:30 -0700 | [diff] [blame] | 18 | 0x05, 0x9a, 0x9e, 0x31, 0x32, 0x33, 0x00, |
Jeff Thompson | 7afc98e | 2013-06-27 14:33:53 -0700 | [diff] [blame] | 19 | 0x05, 0xa2, 0x8e, 0x34, 0x00, |
| 20 | 0x03, 0xe2, |
| 21 | 0x02, 0x85, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 22 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 23 | 0x00, |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 24 | 0x02, 0xda, 0xfa, 0x9d, 0x61, 0x62, 0x63, 0x00, 0xea, 0x00, 0x00, |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 25 | 0x05, 0xaa, 0x8e, 0x31, 0x00, |
| 26 | 0x02, 0xfa, 0x8e, 0x34, 0x00, |
| 27 | 0x02, 0xd2, 0x8e, 0x32, 0x00, |
| 28 | 0x03, 0x82, 0x9d, 0x01, 0xe0, 0x00, 0x00, |
| 29 | 0x02, 0xca, 0xb5, 0x61, 0x62, 0x61, 0x62, 0x61, 0x62, 0x00, |
| 30 | 0x00, |
Jeff Thompson | 7afc98e | 2013-06-27 14:33:53 -0700 | [diff] [blame] | 31 | 1 |
| 32 | }; |
| 33 | |
Jeff Thompson | 3b3aabf | 2013-06-21 16:50:20 -0700 | [diff] [blame] | 34 | /* |
| 35 | * |
| 36 | */ |
Jeff Thompson | 7afc98e | 2013-06-27 14:33:53 -0700 | [diff] [blame] | 37 | int main(int argc, char** argv) |
| 38 | { |
| 39 | try { |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 40 | Interest interest; |
Jeff Thompson | 0d567da | 2013-07-14 22:10:21 -0700 | [diff] [blame^] | 41 | #if 0 |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 42 | interest.decode(Interest1, sizeof(Interest1)); |
| 43 | cout << "Interest name " << interest.getName().to_uri() << endl; |
Jeff Thompson | 06f824a | 2013-07-08 17:14:30 -0700 | [diff] [blame] | 44 | cout << "Interest minSuffixComponents " << interest.getMinSuffixComponents() << endl; |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 45 | cout << "Interest publisherPublicKeyDigest length " << interest.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() << endl; |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 46 | cout << "Interest excludeEntryCount " << interest.getExclude().getEntryCount() << endl; |
Jeff Thompson | 5a5e8b7 | 2013-07-11 14:28:03 -0700 | [diff] [blame] | 47 | cout << "InterestLifetimeMilliseconds " << interest.getInterestLifetimeMilliseconds() << endl; |
Jeff Thompson | 0d567da | 2013-07-14 22:10:21 -0700 | [diff] [blame^] | 48 | #endif |
Jeff Thompson | 2fb4b1b | 2013-07-01 15:10:43 -0700 | [diff] [blame] | 49 | |
Jeff Thompson | 1f3f517 | 2013-07-01 19:02:36 -0700 | [diff] [blame] | 50 | vector<unsigned char> encoding; |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 51 | interest.encode(encoding); |
Jeff Thompson | 06f824a | 2013-07-08 17:14:30 -0700 | [diff] [blame] | 52 | cout << "Interest encoding length " << encoding.size() << " vs. sizeof(Interest1) " << sizeof(Interest1) << endl; |
Jeff Thompson | 0d567da | 2013-07-14 22:10:21 -0700 | [diff] [blame^] | 53 | |
| 54 | struct ndn_TcpTransport transport; |
| 55 | ndn_TcpTransport_init(&transport); |
| 56 | ndn_Error error; |
| 57 | if (error = ndn_TcpTransport_connect(&transport, (char *)"E.hub.ndn.ucla.edu", 9695)) |
| 58 | return error; |
| 59 | if (error = ndn_TcpTransport_send(&transport, &encoding[0], encoding.size())) |
| 60 | return error; |
Jeff Thompson | 06f824a | 2013-07-08 17:14:30 -0700 | [diff] [blame] | 61 | |
Jeff Thompson | 0d567da | 2013-07-14 22:10:21 -0700 | [diff] [blame^] | 62 | unsigned char buffer[1000]; |
| 63 | unsigned int nBytes; |
| 64 | if (error = ndn_TcpTransport_receive(&transport, buffer, sizeof(buffer), &nBytes)) |
| 65 | return error; |
| 66 | |
| 67 | for (int i = 0; i < nBytes; ++i) |
| 68 | printf("%02X ", (unsigned int)buffer[i]); |
| 69 | |
| 70 | #if 0 |
Jeff Thompson | 06f824a | 2013-07-08 17:14:30 -0700 | [diff] [blame] | 71 | Interest reDecodedInterest; |
| 72 | reDecodedInterest.decode(encoding); |
| 73 | cout << "Re-decoded Interest name " << reDecodedInterest.getName().to_uri() << endl; |
| 74 | cout << "Re-decoded Interest minSuffixComponents " << reDecodedInterest.getMinSuffixComponents() << endl; |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 75 | cout << "Re-decoded Interest publisherPublicKeyDigest length " << reDecodedInterest.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() << endl; |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 76 | cout << "Re-decoded Interest excludeEntryCount " << reDecodedInterest.getExclude().getEntryCount() << endl; |
Jeff Thompson | 5a5e8b7 | 2013-07-11 14:28:03 -0700 | [diff] [blame] | 77 | cout << "Re-decoded InterestLifetimeMilliseconds " << reDecodedInterest.getInterestLifetimeMilliseconds() << endl; |
Jeff Thompson | 0d567da | 2013-07-14 22:10:21 -0700 | [diff] [blame^] | 78 | #endif |
Jeff Thompson | 7afc98e | 2013-06-27 14:33:53 -0700 | [diff] [blame] | 79 | } catch (exception &e) { |
Jeff Thompson | 8b66600 | 2013-07-08 01:16:26 -0700 | [diff] [blame] | 80 | cout << "exception: " << e.what() << endl; |
Jeff Thompson | 7afc98e | 2013-06-27 14:33:53 -0700 | [diff] [blame] | 81 | } |
Jeff Thompson | 3b3aabf | 2013-06-21 16:50:20 -0700 | [diff] [blame] | 82 | return 0; |
| 83 | } |