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" |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 13 | #include "forwarding-flags.hpp" |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 14 | #include "c/forwarding-entry.h" |
| 15 | |
| 16 | namespace ndn { |
| 17 | |
| 18 | /** |
| 19 | * An ForwardingEntry holds an action and Name prefix and other fields for an forwarding entry. |
| 20 | */ |
| 21 | class ForwardingEntry { |
| 22 | public: |
| 23 | ForwardingEntry |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 24 | (const std::string& action, const Name& prefix, const PublisherPublicKeyDigest publisherPublicKeyDigest, |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 25 | int faceId, const ForwardingFlags& forwardingFlags, int freshnessSeconds) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 26 | : action_(action), prefix_(prefix), publisherPublicKeyDigest_(publisherPublicKeyDigest), |
| 27 | faceId_(faceId), forwardingFlags_(forwardingFlags), freshnessSeconds_(freshnessSeconds) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | ForwardingEntry() |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 32 | : faceId_(-1), freshnessSeconds_(-1) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 33 | { |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 34 | forwardingFlags_.setActive(true); |
| 35 | forwardingFlags_.setChildInherit(true); |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 38 | Blob |
| 39 | wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 40 | { |
| 41 | return wireFormat.encodeForwardingEntry(*this); |
| 42 | } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 43 | |
| 44 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 45 | wireDecode(const uint8_t *input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 46 | { |
| 47 | wireFormat.decodeForwardingEntry(*this, input, inputLength); |
| 48 | } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 49 | |
| 50 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 51 | wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 52 | { |
| 53 | wireDecode(&input[0], input.size(), wireFormat); |
| 54 | } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Set the forwardingEntryStruct to point to the components in this forwarding entry, without copying any memory. |
| 58 | * WARNING: The resulting pointers in forwardingEntryStruct are invalid after a further use of this object which could reallocate memory. |
| 59 | * @param forwardingEntryStruct a C ndn_ForwardingEntry struct where the prefix name components array is already allocated. |
| 60 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 61 | void |
| 62 | get(struct ndn_ForwardingEntry& forwardingEntryStruct) const; |
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 | const std::string& |
| 65 | getAction() const { return action_; } |
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 | Name& |
| 68 | getPrefix() { 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 | const Name& |
| 71 | getPrefix() const { return prefix_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 72 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 73 | PublisherPublicKeyDigest& |
| 74 | getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; } |
| 75 | |
| 76 | const PublisherPublicKeyDigest& |
| 77 | getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; } |
| 78 | |
| 79 | int |
| 80 | getFaceId() const { return faceId_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 81 | |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 82 | const ForwardingFlags& |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 83 | getForwardingFlags() const { return forwardingFlags_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 84 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 85 | int |
| 86 | getFreshnessSeconds() const { return freshnessSeconds_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * Clear this forwarding entry, and set the values by copying from forwardingEntryStruct. |
| 90 | * @param forwardingEntryStruct a C ndn_ForwardingEntry struct. |
| 91 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 92 | void |
| 93 | set(const struct ndn_ForwardingEntry& forwardingEntryStruct); |
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 | setAction(const std::string& value) { action_ = 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 | setFaceId(int value) { faceId_ = 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 |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 102 | setForwardingFlags(const ForwardingFlags& value) { forwardingFlags_ = 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 | void |
| 105 | setFreshnessSeconds(int value) { freshnessSeconds_ = value; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 106 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 107 | private: |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 108 | std::string action_; /**< empty for none. */ |
| 109 | Name prefix_; |
| 110 | PublisherPublicKeyDigest publisherPublicKeyDigest_; |
| 111 | int faceId_; /**< -1 for none. */ |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 112 | ForwardingFlags forwardingFlags_; |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 113 | int freshnessSeconds_; /**< -1 for none. */ |
| 114 | }; |
| 115 | |
| 116 | } |
| 117 | |
| 118 | #endif |