Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 2 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #ifndef NDN_FORWARDING_ENTRY_HPP |
| 9 | #define NDN_FORWARDING_ENTRY_HPP |
| 10 | |
| 11 | #include <string> |
| 12 | #include "name.hpp" |
| 13 | #include "publisher-public-key-digest.hpp" |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 14 | #include "forwarding-flags.hpp" |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 15 | #include "encoding/wire-format.hpp" |
| 16 | |
| 17 | struct ndn_ForwardingEntry; |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 18 | |
| 19 | namespace ndn { |
| 20 | |
| 21 | /** |
| 22 | * An ForwardingEntry holds an action and Name prefix and other fields for an forwarding entry. |
| 23 | */ |
| 24 | class ForwardingEntry { |
| 25 | public: |
| 26 | ForwardingEntry |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 27 | (const std::string& action, const Name& prefix, const PublisherPublicKeyDigest publisherPublicKeyDigest, |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 28 | int faceId, const ForwardingFlags& forwardingFlags, int freshnessSeconds) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 29 | : action_(action), prefix_(prefix), publisherPublicKeyDigest_(publisherPublicKeyDigest), |
| 30 | faceId_(faceId), forwardingFlags_(forwardingFlags), freshnessSeconds_(freshnessSeconds) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | ForwardingEntry() |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 35 | : faceId_(-1), freshnessSeconds_(-1) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 36 | { |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 37 | forwardingFlags_.setActive(true); |
| 38 | forwardingFlags_.setChildInherit(true); |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 41 | Blob |
| 42 | wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 43 | { |
| 44 | return wireFormat.encodeForwardingEntry(*this); |
| 45 | } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 46 | |
| 47 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 48 | wireDecode(const uint8_t *input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 49 | { |
| 50 | wireFormat.decodeForwardingEntry(*this, input, inputLength); |
| 51 | } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 52 | |
| 53 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 54 | wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 55 | { |
| 56 | wireDecode(&input[0], input.size(), wireFormat); |
| 57 | } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 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 | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 64 | void |
| 65 | get(struct ndn_ForwardingEntry& forwardingEntryStruct) const; |
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 std::string& |
| 68 | getAction() const { return action_; } |
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 | Name& |
| 71 | getPrefix() { 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 | const Name& |
| 74 | getPrefix() const { return prefix_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 75 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 76 | PublisherPublicKeyDigest& |
| 77 | getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; } |
| 78 | |
| 79 | const PublisherPublicKeyDigest& |
| 80 | getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; } |
| 81 | |
| 82 | int |
| 83 | getFaceId() const { return faceId_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 84 | |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 85 | const ForwardingFlags& |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 86 | getForwardingFlags() const { return forwardingFlags_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 87 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 88 | int |
| 89 | getFreshnessSeconds() const { return freshnessSeconds_; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * Clear this forwarding entry, and set the values by copying from forwardingEntryStruct. |
| 93 | * @param forwardingEntryStruct a C ndn_ForwardingEntry struct. |
| 94 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 95 | void |
| 96 | set(const struct ndn_ForwardingEntry& forwardingEntryStruct); |
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 | setAction(const std::string& value) { action_ = 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 | setFaceId(int value) { faceId_ = 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 |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 105 | setForwardingFlags(const ForwardingFlags& value) { forwardingFlags_ = 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 | void |
| 108 | setFreshnessSeconds(int value) { freshnessSeconds_ = value; } |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 109 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 110 | private: |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 111 | std::string action_; /**< empty for none. */ |
| 112 | Name prefix_; |
| 113 | PublisherPublicKeyDigest publisherPublicKeyDigest_; |
| 114 | int faceId_; /**< -1 for none. */ |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 115 | ForwardingFlags forwardingFlags_; |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 116 | int freshnessSeconds_; /**< -1 for none. */ |
| 117 | }; |
| 118 | |
| 119 | } |
| 120 | |
| 121 | #endif |