interest.h
1 
21 #ifndef NDN_INTEREST_H
22 #define NDN_INTEREST_H
23 
24 #include <ndn-cpp/c/interest-types.h>
25 #include "name.h"
26 #include "publisher-public-key-digest.h"
27 #include "key-locator.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
40 static __inline void ndn_ExcludeEntry_initialize(struct ndn_ExcludeEntry *self, ndn_ExcludeType type, const uint8_t *component, size_t componentLength)
41 {
42  self->type = type;
43  ndn_NameComponent_initialize(&self->component, component, componentLength);
44 }
45 
51 static __inline void
52 ndn_ExcludeEntry_setFromExcludeEntry
53  (struct ndn_ExcludeEntry *self, const struct ndn_ExcludeEntry *other)
54 {
55  *self = *other;
56 }
57 
64 static __inline void ndn_Exclude_initialize(struct ndn_Exclude *self, struct ndn_ExcludeEntry *entries, size_t maxEntries)
65 {
66  self->entries = entries;
67  self->maxEntries = maxEntries;
68  self->nEntries = 0;
69 }
70 
74 static __inline void
75 ndn_Exclude_clear(struct ndn_Exclude *self)
76 {
77  self->nEntries = 0;
78 }
79 
86 ndn_Error
87 ndn_Exclude_appendAny(struct ndn_Exclude *self);
88 
98 ndn_Error
99 ndn_Exclude_appendComponent
100  (struct ndn_Exclude *self, const uint8_t* component, size_t componentLength);
101 
109 ndn_Error
110 ndn_Exclude_setFromExclude
111  (struct ndn_Exclude *self, const struct ndn_Exclude *other);
112 
124 static __inline void ndn_Interest_initialize
125  (struct ndn_Interest *self, struct ndn_NameComponent *nameComponents, size_t maxNameComponents,
126  struct ndn_ExcludeEntry *excludeEntries, size_t maxExcludeEntries, struct ndn_NameComponent *keyNameComponents,
127  size_t maxKeyNameComponents)
128 {
129  ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
130  self->minSuffixComponents = -1;
131  self->maxSuffixComponents = -1;
132  ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
133  ndn_Exclude_initialize(&self->exclude, excludeEntries, maxExcludeEntries);
134  self->childSelector = -1;
135  self->answerOriginKind = -1;
136  self->scope = -1;
137  self->interestLifetimeMilliseconds = -1.0;
138  ndn_Blob_initialize(&self->nonce, 0, 0);
139  ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
140 }
141 
148 static __inline int ndn_Interest_getMustBeFresh(const struct ndn_Interest *self)
149 {
150  if (self->answerOriginKind < 0)
151  return 1;
152  else
153  return (self->answerOriginKind & ndn_Interest_ANSWER_STALE) == 0 ? 1 : 0;
154 }
155 
163 static __inline void
164 ndn_Interest_setMustBeFresh(struct ndn_Interest *self, int mustBeFresh)
165 {
166  if (self->answerOriginKind < 0) {
167  // It is is already the default where MustBeFresh is true.
168  if (!mustBeFresh)
169  // Set answerOriginKind so that getMustBeFresh returns false.
170  self->answerOriginKind = ndn_Interest_ANSWER_STALE;
171  }
172  else {
173  if (mustBeFresh)
174  // Clear the stale bit.
175  self->answerOriginKind &= ~ndn_Interest_ANSWER_STALE;
176  else
177  // Set the stale bit.
178  self->answerOriginKind |= ndn_Interest_ANSWER_STALE;
179  }
180 }
181 
189 static __inline ndn_Error
190 ndn_Interest_setFromInterest
191  (struct ndn_Interest *self, const struct ndn_Interest *other)
192 {
193  ndn_Error error;
194 
195  if (other == self)
196  // Setting to itself. Do nothing.
197  return NDN_ERROR_success;
198 
199  if ((error = ndn_Name_setFromName(&self->name, &other->name)))
200  return error;
201  self->minSuffixComponents = other->minSuffixComponents;
202  self->maxSuffixComponents = other->maxSuffixComponents;
203  self->publisherPublicKeyDigest = other->publisherPublicKeyDigest;
204  if ((error = ndn_Exclude_setFromExclude(&self->exclude, &other->exclude)))
205  return error;
206  self->childSelector = other->childSelector;
207  self->answerOriginKind = other->answerOriginKind;
208  self->scope = other->scope;
209  self->interestLifetimeMilliseconds = other->interestLifetimeMilliseconds;
210  ndn_Blob_setFromBlob(&self->nonce, &other->nonce);
211  if ((error = ndn_KeyLocator_setFromKeyLocator
212  (&self->keyLocator, &other->keyLocator)))
213  return error;
214 
215  return NDN_ERROR_success;
216 }
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 
222 #endif
223 
An ndn_ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds a pointer to the com...
Definition: interest-types.h:40
int childSelector
-1 for none
Definition: interest-types.h:79
struct ndn_Blob nonce
The blob whose value is a pointer to a pre-allocated buffer.
Definition: interest-types.h:83
ndn_Milliseconds interestLifetimeMilliseconds
-1.0 for none
Definition: interest-types.h:82
An ndn_Interest holds an ndn_Name and other fields for an interest.
Definition: interest-types.h:70
int scope
-1 for none
Definition: interest-types.h:81
struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest
Definition: interest-types.h:76
int minSuffixComponents
-1 for none
Definition: interest-types.h:72
An ndn_Exclude holds an array of ndn_ExcludeEntry.
Definition: interest-types.h:48
Copyright (C) 2015 Regents of the University of California.
Definition: name-types.h:33
int answerOriginKind
-1 for none.
Definition: interest-types.h:80
int maxSuffixComponents
-1 for none
Definition: interest-types.h:73