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 | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 35 | Blob wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 36 | { |
| 37 | return wireFormat.encodeForwardingEntry(*this); |
| 38 | } |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 39 | void wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 40 | { |
| 41 | wireFormat.decodeForwardingEntry(*this, input, inputLength); |
| 42 | } |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 43 | void wireDecode(const std::vector<unsigned char>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 44 | { |
| 45 | wireDecode(&input[0], input.size(), wireFormat); |
| 46 | } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Set the forwardingEntryStruct to point to the components in this forwarding entry, without copying any memory. |
| 50 | * WARNING: The resulting pointers in forwardingEntryStruct are invalid after a further use of this object which could reallocate memory. |
| 51 | * @param forwardingEntryStruct a C ndn_ForwardingEntry struct where the prefix name components array is already allocated. |
| 52 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 53 | void get(struct ndn_ForwardingEntry& forwardingEntryStruct) const; |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 54 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 55 | const std::string& getAction() const { return action_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 56 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 57 | Name& getPrefix() { return prefix_; } |
| 58 | const Name& getPrefix() const { return prefix_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 59 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 60 | PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; } |
| 61 | const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 62 | |
| 63 | int getFaceId() const { return faceId_; } |
| 64 | |
| 65 | int getForwardingFlags() const { return forwardingFlags_; } |
| 66 | |
| 67 | int getFreshnessSeconds() const { return freshnessSeconds_; } |
| 68 | |
| 69 | /** |
| 70 | * Clear this forwarding entry, and set the values by copying from forwardingEntryStruct. |
| 71 | * @param forwardingEntryStruct a C ndn_ForwardingEntry struct. |
| 72 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 73 | void set(const struct ndn_ForwardingEntry& forwardingEntryStruct); |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 74 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 75 | void setAction(const std::string& value) { action_ = value; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 76 | |
| 77 | void setFaceId(int value) { faceId_ = value; } |
| 78 | |
| 79 | void setForwardingFlags(int value) { forwardingFlags_ = value; } |
| 80 | |
| 81 | void setFreshnessSeconds(int value) { freshnessSeconds_ = value; } |
| 82 | |
| 83 | std::string action_; /**< empty for none. */ |
| 84 | Name prefix_; |
| 85 | PublisherPublicKeyDigest publisherPublicKeyDigest_; |
| 86 | int faceId_; /**< -1 for none. */ |
| 87 | int forwardingFlags_; /**< -1 for none. */ |
| 88 | int freshnessSeconds_; /**< -1 for none. */ |
| 89 | }; |
| 90 | |
| 91 | } |
| 92 | |
| 93 | #endif |