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