Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NDN_FORWARDING_ENTRY_HPP |
| 8 | #define NDN_FORWARDING_ENTRY_HPP |
| 9 | |
| 10 | #include <string> |
| 11 | #include "name.hpp" |
| 12 | #include "publisher-public-key-digest.hpp" |
| 13 | #include "c/forwarding-entry.h" |
| 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | /** |
| 18 | * An ForwardingEntry holds an action and Name prefix and other fields for an forwarding entry. |
| 19 | */ |
| 20 | class ForwardingEntry { |
| 21 | public: |
| 22 | ForwardingEntry |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 23 | (const std::string& action, const Name& prefix, const PublisherPublicKeyDigest publisherPublicKeyDigest, |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 24 | int faceId, int forwardingFlags, int freshnessSeconds) |
| 25 | : action_(action), prefix_(prefix), publisherPublicKeyDigest_(publisherPublicKeyDigest), |
| 26 | faceId_(faceId), forwardingFlags_(forwardingFlags), freshnessSeconds_(freshnessSeconds) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | ForwardingEntry() |
| 31 | : faceId_(-1), forwardingFlags_(-1), freshnessSeconds_(-1) |
| 32 | { |
| 33 | } |
| 34 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 35 | Blob |
| 36 | wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 37 | { |
| 38 | return wireFormat.encodeForwardingEntry(*this); |
| 39 | } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 40 | |
| 41 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame^] | 42 | wireDecode(const uint8_t *input, unsigned int inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 43 | { |
| 44 | wireFormat.decodeForwardingEntry(*this, input, inputLength); |
| 45 | } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 46 | |
| 47 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame^] | 48 | wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 49 | { |
| 50 | wireDecode(&input[0], input.size(), wireFormat); |
| 51 | } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Set the forwardingEntryStruct to point to the components in this forwarding entry, without copying any memory. |
| 55 | * WARNING: The resulting pointers in forwardingEntryStruct are invalid after a further use of this object which could reallocate memory. |
| 56 | * @param forwardingEntryStruct a C ndn_ForwardingEntry struct where the prefix name components array is already allocated. |
| 57 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 58 | void |
| 59 | get(struct ndn_ForwardingEntry& forwardingEntryStruct) const; |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 60 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 61 | const std::string& |
| 62 | getAction() const { return action_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 63 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 64 | Name& |
| 65 | getPrefix() { return prefix_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 66 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 67 | const Name& |
| 68 | getPrefix() const { return prefix_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 69 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 70 | PublisherPublicKeyDigest& |
| 71 | getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; } |
| 72 | |
| 73 | const PublisherPublicKeyDigest& |
| 74 | getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; } |
| 75 | |
| 76 | int |
| 77 | getFaceId() const { return faceId_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 78 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 79 | int |
| 80 | getForwardingFlags() const { return forwardingFlags_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 81 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 82 | int |
| 83 | getFreshnessSeconds() const { return freshnessSeconds_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Clear this forwarding entry, and set the values by copying from forwardingEntryStruct. |
| 87 | * @param forwardingEntryStruct a C ndn_ForwardingEntry struct. |
| 88 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 89 | void |
| 90 | set(const struct ndn_ForwardingEntry& forwardingEntryStruct); |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 91 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 92 | void |
| 93 | setAction(const std::string& value) { action_ = value; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 94 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 95 | void |
| 96 | setFaceId(int value) { faceId_ = value; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 97 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 98 | void |
| 99 | setForwardingFlags(int value) { forwardingFlags_ = value; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 100 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 101 | void |
| 102 | setFreshnessSeconds(int value) { freshnessSeconds_ = value; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 103 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 104 | private: |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 105 | std::string action_; /**< empty for none. */ |
| 106 | Name prefix_; |
| 107 | PublisherPublicKeyDigest publisherPublicKeyDigest_; |
| 108 | int faceId_; /**< -1 for none. */ |
| 109 | int forwardingFlags_; /**< -1 for none. */ |
| 110 | int freshnessSeconds_; /**< -1 for none. */ |
| 111 | }; |
| 112 | |
| 113 | } |
| 114 | |
| 115 | #endif |