Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef NDN_INTEREST_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 7 | #define NDN_INTEREST_HPP |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 8 | |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 9 | #include "name.hpp" |
| 10 | #include "publisher-public-key-digest.hpp" |
| 11 | #include "c/interest.h" |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 12 | |
| 13 | namespace ndn { |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 14 | |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 15 | /** |
| 16 | * An ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds the component value. |
| 17 | */ |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 18 | class ExcludeEntry { |
| 19 | public: |
| 20 | /** |
| 21 | * Create an ExcludeEntry of type ndn_Exclude_ANY |
| 22 | */ |
| 23 | ExcludeEntry() |
| 24 | : type_(ndn_Exclude_ANY) |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Create an ExcludeEntry of type ndn_Exclude_COMPONENT |
| 30 | */ |
| 31 | ExcludeEntry(unsigned char *component, unsigned int componentLen) |
Jeff Thompson | 38d0e08 | 2013-08-12 18:07:44 -0700 | [diff] [blame] | 32 | : type_(ndn_Exclude_COMPONENT), component_(component, componentLen) |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 33 | { |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Set the type in the excludeEntryStruct and to point to this component, without copying any memory. |
| 38 | * WARNING: The resulting pointer in excludeEntryStruct is invalid after a further use of this object which could reallocate memory. |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 39 | * @param excludeEntryStruct the C ndn_NameComponent struct to receive the pointer |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 40 | */ |
| 41 | void get(struct ndn_ExcludeEntry &excludeEntryStruct) const |
| 42 | { |
| 43 | excludeEntryStruct.type = type_; |
Jeff Thompson | 38d0e08 | 2013-08-12 18:07:44 -0700 | [diff] [blame] | 44 | if (type_ == ndn_Exclude_COMPONENT) |
| 45 | component_.get(excludeEntryStruct.component); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | ndn_ExcludeType getType() const { return type_; } |
| 49 | |
Jeff Thompson | 38d0e08 | 2013-08-12 18:07:44 -0700 | [diff] [blame] | 50 | const Name::Component &getComponent() const { return component_; } |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | ndn_ExcludeType type_; |
Jeff Thompson | 38d0e08 | 2013-08-12 18:07:44 -0700 | [diff] [blame] | 54 | Name::Component component_; /**< only used if type_ is ndn_Exclude_COMPONENT */ |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 57 | /** |
| 58 | * An Exclude holds a vector of ExcludeEntry. |
| 59 | */ |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 60 | class Exclude { |
| 61 | public: |
| 62 | /** |
| 63 | * Create a new Exclude with no entries. |
| 64 | */ |
| 65 | Exclude() { |
| 66 | } |
| 67 | |
| 68 | unsigned int getEntryCount() const { |
| 69 | return entries_.size(); |
| 70 | } |
| 71 | |
| 72 | const ExcludeEntry &getEntry(unsigned int i) const { return entries_[i]; } |
| 73 | |
| 74 | /** |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 75 | * Set the excludeStruct to point to the entries in this Exclude, without copying any memory. |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 76 | * WARNING: The resulting pointers in excludeStruct are invalid after a further use of this object which could reallocate memory. |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 77 | * @param excludeStruct a C ndn_Exclude struct where the entries array is already allocated |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 78 | */ |
| 79 | void get(struct ndn_Exclude &excludeStruct) const; |
| 80 | |
| 81 | /** |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 82 | * Clear this Exclude, and set the entries by copying from the ndn_Exclude struct. |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 83 | * @param excludeStruct a C ndn_Exclude struct |
| 84 | */ |
Jeff Thompson | dd3d229 | 2013-07-10 11:59:44 -0700 | [diff] [blame] | 85 | void set(const struct ndn_Exclude &excludeStruct); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * Add a new entry of type ndn_Exclude_ANY |
| 89 | */ |
| 90 | void addAny() |
| 91 | { |
| 92 | entries_.push_back(ExcludeEntry()); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Add a new entry of type ndn_Exclude_COMPONENT, copying from component of length compnentLength |
| 97 | */ |
| 98 | void addComponent(unsigned char *component, unsigned int componentLen) |
| 99 | { |
| 100 | entries_.push_back(ExcludeEntry(component, componentLen)); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Clear all the entries. |
| 105 | */ |
| 106 | void clear() { |
| 107 | entries_.clear(); |
| 108 | } |
| 109 | |
| 110 | private: |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 111 | std::vector<ExcludeEntry> entries_; |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 112 | }; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 113 | |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 114 | /** |
| 115 | * An Interest holds a Name and other fields for an interest. |
| 116 | */ |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 117 | class Interest { |
| 118 | public: |
Jeff Thompson | 3423865 | 2013-07-10 18:25:00 -0700 | [diff] [blame] | 119 | Interest() |
| 120 | { |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 121 | construct(); |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | Interest(const Name &name) |
Jeff Thompson | f59a87a | 2013-07-31 16:55:41 -0700 | [diff] [blame] | 125 | : name_(name) |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 126 | { |
| 127 | name_ = name; |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 128 | construct(); |
Jeff Thompson | 3423865 | 2013-07-10 18:25:00 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Jeff Thompson | f59a87a | 2013-07-31 16:55:41 -0700 | [diff] [blame] | 131 | Interest(const Name &name, int minSuffixComponents, int maxSuffixComponents, |
| 132 | const PublisherPublicKeyDigest &publisherPublicKeyDigest, const Exclude &exclude, int childSelector, int answerOriginKind, |
| 133 | int scope, double interestLifetimeMilliseconds, const std::vector<unsigned char> &nonce) |
| 134 | : name_(name), minSuffixComponents_(minSuffixComponents), maxSuffixComponents_(maxSuffixComponents), |
| 135 | publisherPublicKeyDigest_(publisherPublicKeyDigest), exclude_(exclude), childSelector_(childSelector), |
| 136 | answerOriginKind_(answerOriginKind), scope_(scope), interestLifetimeMilliseconds_(interestLifetimeMilliseconds), |
| 137 | nonce_(nonce) |
| 138 | { |
| 139 | } |
| 140 | |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 141 | ptr_lib::shared_ptr<std::vector<unsigned char> > wireEncode(WireFormat &wireFormat) const |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 142 | { |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 143 | return wireFormat.encodeInterest(*this); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 144 | } |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 145 | ptr_lib::shared_ptr<std::vector<unsigned char> > wireEncode() const |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 146 | { |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 147 | return wireEncode(*WireFormat::getDefaultWireFormat()); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 148 | } |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 149 | void wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 150 | { |
| 151 | wireFormat.decodeInterest(*this, input, inputLength); |
| 152 | } |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 153 | void wireDecode(const unsigned char *input, unsigned int inputLength) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 154 | { |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 155 | wireDecode(input, inputLength, *WireFormat::getDefaultWireFormat()); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 156 | } |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 157 | void wireDecode(const std::vector<unsigned char> &input, WireFormat &wireFormat) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 158 | { |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 159 | wireDecode(&input[0], input.size(), wireFormat); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 160 | } |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 161 | void wireDecode(const std::vector<unsigned char> &input) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 162 | { |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 163 | wireDecode(&input[0], input.size()); |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 164 | } |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 165 | |
| 166 | /** |
| 167 | * Set the interestStruct to point to the components in this interest, without copying any memory. |
| 168 | * WARNING: The resulting pointers in interestStruct are invalid after a further use of this object which could reallocate memory. |
| 169 | * @param interestStruct a C ndn_Interest struct where the name components array is already allocated. |
| 170 | */ |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 171 | void get(struct ndn_Interest &interestStruct) const; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 172 | |
Jeff Thompson | 12c2776 | 2013-07-09 15:05:11 -0700 | [diff] [blame] | 173 | Name &getName() { return name_; } |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 174 | const Name &getName() const { return name_; } |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 175 | |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 176 | int getMinSuffixComponents() const { return minSuffixComponents_; } |
| 177 | |
| 178 | int getMaxSuffixComponents() const { return maxSuffixComponents_; } |
Jeff Thompson | 0a68172 | 2013-07-08 16:21:54 -0700 | [diff] [blame] | 179 | |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 180 | PublisherPublicKeyDigest &getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; } |
| 181 | const PublisherPublicKeyDigest &getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; } |
Jeff Thompson | 0a68172 | 2013-07-08 16:21:54 -0700 | [diff] [blame] | 182 | |
Jeff Thompson | 12c2776 | 2013-07-09 15:05:11 -0700 | [diff] [blame] | 183 | Exclude &getExclude() { return exclude_; } |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 184 | const Exclude &getExclude() const { return exclude_; } |
Jeff Thompson | 0a68172 | 2013-07-08 16:21:54 -0700 | [diff] [blame] | 185 | |
| 186 | int getChildSelector() const { return childSelector_; } |
| 187 | |
| 188 | int getAnswerOriginKind() const { return answerOriginKind_; } |
| 189 | |
| 190 | int getScope() const { return scope_; } |
Jeff Thompson | d345a5b | 2013-07-08 16:18:23 -0700 | [diff] [blame] | 191 | |
Jeff Thompson | 5a5e8b7 | 2013-07-11 14:28:03 -0700 | [diff] [blame] | 192 | double getInterestLifetimeMilliseconds() const { return interestLifetimeMilliseconds_; } |
Jeff Thompson | 0a68172 | 2013-07-08 16:21:54 -0700 | [diff] [blame] | 193 | |
Jeff Thompson | 4962c62 | 2013-08-13 13:47:21 -0700 | [diff] [blame] | 194 | const std::vector<unsigned char> &getNonce() const { return nonce_; } |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 195 | |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 196 | /** |
| 197 | * Clear this interest, and set the values by copying from the interest struct. |
| 198 | * @param interestStruct a C ndn_Interest struct |
| 199 | */ |
Jeff Thompson | dd3d229 | 2013-07-10 11:59:44 -0700 | [diff] [blame] | 200 | void set(const struct ndn_Interest &interestStruct); |
Jeff Thompson | eb316a8 | 2013-07-09 15:11:17 -0700 | [diff] [blame] | 201 | |
| 202 | void setMinSuffixComponents(int value) { minSuffixComponents_ = value; } |
| 203 | |
| 204 | void setMaxSuffixComponents(int value) { maxSuffixComponents_ = value; } |
| 205 | |
Jeff Thompson | eb316a8 | 2013-07-09 15:11:17 -0700 | [diff] [blame] | 206 | void setChildSelector(int value) { childSelector_ = value; } |
| 207 | |
| 208 | void setAnswerOriginKind(int value) { answerOriginKind_ = value; } |
| 209 | |
| 210 | void setScope(int value) { scope_ = value; } |
| 211 | |
Jeff Thompson | 5a5e8b7 | 2013-07-11 14:28:03 -0700 | [diff] [blame] | 212 | void setInterestLifetimeMilliseconds(double value) { interestLifetimeMilliseconds_ = value; } |
Jeff Thompson | eb316a8 | 2013-07-09 15:11:17 -0700 | [diff] [blame] | 213 | |
| 214 | void setNonce(const std::vector<unsigned char> &value) { nonce_ = value; } |
| 215 | |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 216 | private: |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 217 | void construct() |
| 218 | { |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 219 | minSuffixComponents_ = -1; |
| 220 | maxSuffixComponents_ = -1; |
| 221 | childSelector_ = -1; |
| 222 | answerOriginKind_ = -1; |
| 223 | scope_ = -1; |
| 224 | interestLifetimeMilliseconds_ = -1.0; |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 225 | } |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 226 | |
| 227 | Name name_; |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 228 | int minSuffixComponents_; |
| 229 | int maxSuffixComponents_; |
| 230 | PublisherPublicKeyDigest publisherPublicKeyDigest_; |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 231 | Exclude exclude_; |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 232 | int childSelector_; |
| 233 | int answerOriginKind_; |
| 234 | int scope_; |
| 235 | double interestLifetimeMilliseconds_; |
| 236 | std::vector<unsigned char> nonce_; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 237 | }; |
| 238 | |
| 239 | } |
| 240 | |
| 241 | #endif |