| /** |
| * Copyright (C) 2013 Regents of the University of California. |
| * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| * See COPYING for copyright and distribution information. |
| */ |
| |
| #include <cstdlib> |
| #include <sstream> |
| #include <iostream> |
| #include "../ndn-cpp/interest.hpp" |
| #include "../ndn-cpp/data.hpp" |
| #include "../ndn-cpp/forwarding-entry.hpp" |
| #include "../ndn-cpp/security/key-chain.hpp" |
| |
| using namespace std; |
| using namespace ndn; |
| |
| uint8_t Interest1[] = { |
| 0x01, 0xd2, 0xf2, 0xfa, 0xa5, 0x6e, 0x64, 0x6e, 0x78, 0x00, 0xfa, 0x02, 0x85, 0xe0, 0xa0, 0x1e, 0x09, 0x39, 0x68, |
| 0xf9, 0x74, 0x0c, 0xe7, 0xf4, 0x36, 0x1b, 0xab, 0xf5, 0xbb, 0x05, 0xa4, 0xe5, 0x5a, 0xac, 0xa5, 0xe5, 0x8f, 0x73, |
| 0xed, 0xde, 0xb8, 0xe0, 0x13, 0xaa, 0x8f, 0x00, 0xfa, 0xcd, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x72, 0x65, 0x67, |
| 0x00, 0xfa, 0x29, 0xad, 0x04, 0x82, 0x02, 0xaa, 0x03, 0xb2, 0x08, 0x85, 0x4d, 0xdb, 0xf6, 0x97, 0x79, 0xcd, 0xf4, |
| 0xef, 0x74, 0xbe, 0x99, 0x47, 0x44, 0x78, 0xc8, 0xbc, 0x3c, 0xa0, 0x87, 0x3e, 0x0f, 0xfa, 0x1f, 0xa6, 0x01, 0x20, |
| 0xaa, 0x27, 0x6d, 0xb1, 0x22, 0xb8, 0x34, 0x04, 0xe5, 0x95, 0xa8, 0xa3, 0xca, 0xea, 0xf0, 0x96, 0x30, 0x27, 0x66, |
| 0x58, 0xba, 0x4e, 0x7b, 0xea, 0xad, 0xb4, 0xb9, 0x1a, 0x8c, 0xc5, 0x8e, 0x19, 0xac, 0x4a, 0x42, 0x28, 0x95, 0x07, |
| 0xed, 0x8d, 0x60, 0x9a, 0xa9, 0xbe, 0xf6, 0x1a, 0x5a, 0x50, 0x7f, 0x34, 0x9c, 0x83, 0xd2, 0x94, 0x4b, 0x8c, 0x16, |
| 0xfe, 0xcf, 0xd9, 0x0d, 0x4a, 0x40, 0xdd, 0xb8, 0x68, 0x75, 0x92, 0xc0, 0xa5, 0x75, 0x17, 0x56, 0x42, 0x35, 0xb2, |
| 0xe3, 0x59, 0xdb, 0x54, 0xf5, 0x1a, 0x37, 0xe1, 0xac, 0x39, 0xe5, 0x18, 0xa2, 0x19, 0x6e, 0x3f, 0xfd, 0xa7, 0xeb, |
| 0x2f, 0xb3, 0x01, 0xf3, 0xc4, 0x04, 0xdd, 0x00, 0x00, 0xf2, 0x00, 0x01, 0xa2, 0x03, 0xe2, 0x02, 0x85, 0xef, 0x7c, |
| 0x4f, 0x5d, 0x47, 0x43, 0xa8, 0xb8, 0x58, 0x6e, 0xa2, 0xe7, 0x41, 0xb7, 0xfc, 0x39, 0xd1, 0xdc, 0x0d, 0xbe, 0x1b, |
| 0x19, 0x30, 0xe7, 0x87, 0xcf, 0xd1, 0xd8, 0x33, 0xea, 0x7a, 0x61, 0x00, 0x02, 0xba, 0xb5, 0x04, 0xfc, 0xe9, 0xe2, |
| 0x53, 0xd7, 0x00, 0x01, 0xe2, 0x01, 0x82, 0x19, 0xfd, 0x30, 0x82, 0x01, 0x9b, 0x30, 0x82, 0x01, 0x04, 0x02, 0x09, |
| 0x00, 0xb7, 0xd8, 0x5c, 0x90, 0x6b, 0xad, 0x52, 0xee, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, |
| 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x12, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x07, 0x61, |
| 0x78, 0x65, 0x6c, 0x63, 0x64, 0x76, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x32, 0x30, 0x34, 0x32, 0x38, 0x32, 0x33, 0x34, |
| 0x34, 0x33, 0x37, 0x5a, 0x17, 0x0d, 0x31, 0x32, 0x30, 0x35, 0x32, 0x38, 0x32, 0x33, 0x34, 0x34, 0x33, 0x37, 0x5a, |
| 0x30, 0x12, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x07, 0x61, 0x78, 0x65, 0x6c, 0x63, 0x64, |
| 0x76, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, |
| 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xe1, 0x7d, 0x30, 0xa7, 0xd8, 0x28, 0xab, 0x1b, |
| 0x84, 0x0b, 0x17, 0x54, 0x2d, 0xca, 0xf6, 0x20, 0x7a, 0xfd, 0x22, 0x1e, 0x08, 0x6b, 0x2a, 0x60, 0xd1, 0x6c, 0xb7, |
| 0xf5, 0x44, 0x48, 0xba, 0x9f, 0x3f, 0x08, 0xbc, 0xd0, 0x99, 0xdb, 0x21, 0xdd, 0x16, 0x2a, 0x77, 0x9e, 0x61, 0xaa, |
| 0x89, 0xee, 0xe5, 0x54, 0xd3, 0xa4, 0x7d, 0xe2, 0x30, 0xbc, 0x7a, 0xc5, 0x90, 0xd5, 0x24, 0x06, 0x7c, 0x38, 0x98, |
| 0xbb, 0xa6, 0xf5, 0xdc, 0x43, 0x60, 0xb8, 0x45, 0xed, 0xa4, 0x8c, 0xbd, 0x9c, 0xf1, 0x26, 0xa7, 0x23, 0x44, 0x5f, |
| 0x0e, 0x19, 0x52, 0xd7, 0x32, 0x5a, 0x75, 0xfa, 0xf5, 0x56, 0x14, 0x4f, 0x9a, 0x98, 0xaf, 0x71, 0x86, 0xb0, 0x27, |
| 0x86, 0x85, 0xb8, 0xe2, 0xc0, 0x8b, 0xea, 0x87, 0x17, 0x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x65, 0x6c, 0x66, 0x72, 0x65, 0x67, 0x00, 0xf2, 0xfa, 0xa5, 0x6d, 0x65, 0x6b, 0x69, 0x00, 0x00, 0x04, 0xfa, 0x8e, |
| 0x33, 0x00, 0x03, 0xd2, 0xd6, 0x32, 0x31, 0x34, 0x37, 0x34, 0x38, 0x33, 0x36, 0x34, 0x37, 0x00, 0x00, 0x00, 0x00, |
| 0x00, 0x00, 0x02, 0xd2, 0x8e, 0x31, 0x00, 0x00, |
| 1 |
| }; |
| |
| static inline string toString(const vector<uint8_t>& v) |
| { |
| if (!&v) |
| return ""; |
| |
| return string(&v[0], &v[0] + v.size()); |
| } |
| |
| static void dumpForwardingEntry(const ForwardingEntry& forwardingEntry) |
| { |
| cout << "action: " << forwardingEntry.getAction() << endl; |
| cout << "prefix: " << forwardingEntry.getPrefix().to_uri() << endl; |
| cout << "publisherPublicKeyDigest: " |
| << (forwardingEntry.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() > 0 ? toHex(*forwardingEntry.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest()) : "<none>") << endl; |
| cout << "faceId: "; |
| if (forwardingEntry.getFaceId() >= 0) |
| cout << forwardingEntry.getFaceId() << endl; |
| else |
| cout << "<none>" << endl; |
| |
| cout << "forwardingFlags:"; |
| if (forwardingEntry.getForwardingFlags().getActive()) |
| cout << " active"; |
| if (forwardingEntry.getForwardingFlags().getChildInherit()) |
| cout << " childInherit"; |
| if (forwardingEntry.getForwardingFlags().getAdvertise()) |
| cout << " advertise"; |
| if (forwardingEntry.getForwardingFlags().getLast()) |
| cout << " last"; |
| if (forwardingEntry.getForwardingFlags().getCapture()) |
| cout << " capture"; |
| if (forwardingEntry.getForwardingFlags().getLocal()) |
| cout << " local"; |
| if (forwardingEntry.getForwardingFlags().getTap()) |
| cout << " tap"; |
| if (forwardingEntry.getForwardingFlags().getCaptureOk()) |
| cout << " captureOk"; |
| cout << endl; |
| |
| cout << "freshnessSeconds: "; |
| if (forwardingEntry.getFreshnessSeconds() >= 0) |
| cout << forwardingEntry.getFreshnessSeconds() << endl; |
| else |
| cout << "<none>" << endl; |
| } |
| |
| /** |
| * Show the interest name and scope, and expect the name to have 4 components where the last component is a data packet |
| * whose content is a forwarding entry. |
| */ |
| static void dumpInterestWithForwardingEntry(const Interest& interest) |
| { |
| if (interest.getName().getComponentCount() != 4) { |
| cout << "Error: expected the interest name to have 4 components. Got: " << interest.getName().to_uri() << endl; |
| return; |
| } |
| |
| cout << "scope: "; |
| if (interest.getScope() >= 0) |
| cout << interest.getScope() << endl; |
| else |
| cout << "<none>" << endl; |
| cout << "name[0]: " << toString(*interest.getName().getComponent(0).getValue()) << endl; |
| cout << "name[1]: " << toHex(*interest.getName().getComponent(1).getValue()) << endl; |
| cout << "name[2]: " << toString(*interest.getName().getComponent(2).getValue()) << endl; |
| cout << "name[3] decoded as Data, showing content as ForwardingEntry: " << endl; |
| |
| Data data; |
| data.wireDecode(*interest.getName().getComponent(3).getValue()); |
| |
| ForwardingEntry forwardingEntry; |
| forwardingEntry.wireDecode(*data.getContent()); |
| dumpForwardingEntry(forwardingEntry); |
| } |
| |
| int main(int argc, char** argv) |
| { |
| try { |
| Interest interest; |
| interest.wireDecode(Interest1, sizeof(Interest1)); |
| cout << "Interest:" << endl; |
| dumpInterestWithForwardingEntry(interest); |
| |
| Blob encoding = interest.wireEncode(); |
| cout << endl << "Re-encoded interest " << toHex(*encoding) << endl; |
| |
| Interest reDecodedInterest; |
| reDecodedInterest.wireDecode(*encoding); |
| cout << "Re-decoded Interest:" << endl; |
| dumpInterestWithForwardingEntry(reDecodedInterest); |
| } catch (exception& e) { |
| cout << "exception: " << e.what() << endl; |
| } |
| return 0; |
| } |