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_H |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 7 | #define NDN_INTEREST_H |
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.h" |
| 10 | #include "publisher-public-key-digest.h" |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 11 | |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 12 | #ifdef __cplusplus |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 13 | extern "C" { |
| 14 | #endif |
| 15 | |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 16 | typedef enum { |
| 17 | ndn_Exclude_COMPONENT = 0, |
| 18 | ndn_Exclude_ANY = 1 |
| 19 | } ndn_ExcludeType; |
| 20 | |
| 21 | /** |
| 22 | * An ndn_ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds a pointer to the component value. |
| 23 | */ |
| 24 | struct ndn_ExcludeEntry { |
| 25 | ndn_ExcludeType type; |
| 26 | unsigned char *component; /**< pointer to the pre-allocated buffer for the component value */ |
| 27 | unsigned int componentLength; /**< the number of bytes in value */ |
| 28 | }; |
| 29 | |
| 30 | /** |
| 31 | * |
| 32 | * @param self pointer to the ndn_NameComponent struct |
| 33 | * @param type one of the ndn_ExcludeType enum |
| 34 | * @param component the pre-allocated buffer for the component value, only used if type is ndn_Exclude_COMPONENT |
| 35 | * @param componentLength the number of bytes in value, only used if type is ndn_Exclude_COMPONENT |
| 36 | */ |
| 37 | static inline void ndn_ExcludeEntry_init(struct ndn_ExcludeEntry *self, ndn_ExcludeType type, unsigned char *component, unsigned int componentLength) |
| 38 | { |
| 39 | self->type = type; |
| 40 | self->component = component; |
| 41 | self->componentLength = componentLength; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * An ndn_Exclude holds an array of ndn_ExcludeEntry. |
| 46 | */ |
| 47 | struct ndn_Exclude { |
| 48 | struct ndn_ExcludeEntry *entries; /**< pointer to the array of entries. */ |
| 49 | unsigned int maxEntries; /**< the number of elements in the allocated entries array */ |
| 50 | unsigned int nEntries; /**< the number of entries in the exclude, 0 for no exclude */ |
| 51 | }; |
| 52 | /** |
| 53 | * Initialize an ndn_Exclude struct with the entries array. |
| 54 | * @param self pointer to the ndn_Exclude struct |
| 55 | * @param entries the pre-allocated array of ndn_ExcludeEntry |
| 56 | * @param maxEntries the number of elements in the allocated entries array |
| 57 | */ |
| 58 | static inline void ndn_Exclude_init(struct ndn_Exclude *self, struct ndn_ExcludeEntry *entries, unsigned int maxEntries) |
| 59 | { |
| 60 | self->entries = entries; |
| 61 | self->maxEntries = maxEntries; |
| 62 | self->nEntries = 0; |
| 63 | } |
| 64 | |
Jeff Thompson | 2e0e088 | 2013-08-12 17:55:13 -0700 | [diff] [blame^] | 65 | /** |
| 66 | * Compare the components using NDN component ordering. |
| 67 | * A component is less if it is shorter, otherwise if equal length do a byte comparison. |
| 68 | * @param component1 A pointer to the first name component. |
| 69 | * @param component2 A pointer to the second name component. |
| 70 | * @return -1 if component1 is less than component2, 1 if greater or 0 if equal. |
| 71 | */ |
| 72 | int ndn_Exclude_compareComponents(struct ndn_NameComponent *component1, struct ndn_NameComponent *component2); |
| 73 | |
Jeff Thompson | ba70f8c | 2013-07-08 15:34:20 -0700 | [diff] [blame] | 74 | enum { |
| 75 | ndn_Interest_CHILD_SELECTOR_LEFT = 0, |
| 76 | ndn_Interest_CHILD_SELECTOR_RIGHT = 1, |
| 77 | ndn_Interest_ANSWER_CONTENT_STORE = 1, |
| 78 | ndn_Interest_ANSWER_GENERATED = 2, |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 79 | ndn_Interest_ANSWER_STALE = 4, // Stale answer OK |
| 80 | ndn_Interest_MARK_STALE = 16, // Must have scope 0. Michael calls this a "hack" |
Jeff Thompson | ba70f8c | 2013-07-08 15:34:20 -0700 | [diff] [blame] | 81 | |
| 82 | ndn_Interest_DEFAULT_ANSWER_ORIGIN_KIND = ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED |
| 83 | }; |
| 84 | |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 85 | /** |
| 86 | * An ndn_Interest holds an ndn_Name and other fields for an interest. |
| 87 | */ |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 88 | struct ndn_Interest { |
| 89 | struct ndn_Name name; |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 90 | int minSuffixComponents; /**< -1 for none */ |
| 91 | int maxSuffixComponents; /**< -1 for none */ |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 92 | struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest; |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 93 | struct ndn_Exclude exclude; |
| 94 | int childSelector; /**< -1 for none */ |
| 95 | int answerOriginKind; /**< -1 for none */ |
| 96 | int scope; /**< -1 for none */ |
| 97 | double interestLifetimeMilliseconds; /**< milliseconds. -1.0 for none */ |
| 98 | unsigned char *nonce; /**< pointer to pre-allocated buffer. 0 for none */ |
Jeff Thompson | 88ab5dd | 2013-07-07 20:47:46 -0700 | [diff] [blame] | 99 | unsigned int nonceLength; /**< length of nonce. 0 for none */ |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 102 | /** |
Jeff Thompson | b825c63 | 2013-07-10 17:59:29 -0700 | [diff] [blame] | 103 | * Initialize an ndn_Interest struct with the pre-allocated nameComponents and excludeEntries, |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 104 | * and defaults for all the values. |
| 105 | * @param self pointer to the ndn_Interest struct |
| 106 | * @param nameComponents the pre-allocated array of ndn_NameComponent |
| 107 | * @param maxNameComponents the number of elements in the allocated nameComponents array |
| 108 | * @param excludeEntries the pre-allocated array of ndn_ExcludeEntry |
| 109 | * @param maxExcludeEntries the number of elements in the allocated excludeEntries array |
| 110 | */ |
| 111 | static inline void ndn_Interest_init |
| 112 | (struct ndn_Interest *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents, |
| 113 | struct ndn_ExcludeEntry *excludeEntries, unsigned int maxExcludeEntries) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 114 | { |
| 115 | ndn_Name_init(&self->name, nameComponents, maxNameComponents); |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 116 | self->minSuffixComponents = -1; |
Jeff Thompson | f2e5e28 | 2013-07-08 15:26:16 -0700 | [diff] [blame] | 117 | self->maxSuffixComponents = -1; |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 118 | ndn_PublisherPublicKeyDigest_init(&self->publisherPublicKeyDigest); |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 119 | ndn_Exclude_init(&self->exclude, excludeEntries, maxExcludeEntries); |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 120 | self->childSelector = -1; |
| 121 | self->answerOriginKind = -1; |
| 122 | self->scope = -1; |
| 123 | self->interestLifetimeMilliseconds = -1.0; |
| 124 | self->nonce = 0; |
| 125 | self->nonceLength = 0; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 128 | #ifdef __cplusplus |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 129 | } |
| 130 | #endif |
| 131 | |
| 132 | #endif |
| 133 | |