blob: 35b2c4be82147141e2aff4fc19c19f85bfd1e14e [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
Jeff Thompsonb7f95562013-07-03 18:36:42 -07004 */
5
6#ifndef NDN_INTEREST_H
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07007#define NDN_INTEREST_H
Jeff Thompsonb7f95562013-07-03 18:36:42 -07008
Jeff Thompson53412192013-08-06 13:35:50 -07009#include "name.h"
10#include "publisher-public-key-digest.h"
Jeff Thompsonb7f95562013-07-03 18:36:42 -070011
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070012#ifdef __cplusplus
Jeff Thompsonb7f95562013-07-03 18:36:42 -070013extern "C" {
14#endif
15
Jeff Thompsonf084ec62013-07-09 12:32:52 -070016typedef 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 */
24struct ndn_ExcludeEntry {
25 ndn_ExcludeType type;
Jeff Thompson38d0e082013-08-12 18:07:44 -070026 struct ndn_NameComponent component;
Jeff Thompsonf084ec62013-07-09 12:32:52 -070027};
28
29/**
30 *
31 * @param self pointer to the ndn_NameComponent struct
32 * @param type one of the ndn_ExcludeType enum
33 * @param component the pre-allocated buffer for the component value, only used if type is ndn_Exclude_COMPONENT
34 * @param componentLength the number of bytes in value, only used if type is ndn_Exclude_COMPONENT
35 */
Jeff Thompsond1427fb2013-08-29 17:20:32 -070036static inline void ndn_ExcludeEntry_initialize(struct ndn_ExcludeEntry *self, ndn_ExcludeType type, unsigned char *component, unsigned int componentLength)
Jeff Thompsonf084ec62013-07-09 12:32:52 -070037{
38 self->type = type;
Jeff Thompsond1427fb2013-08-29 17:20:32 -070039 ndn_NameComponent_initialize(&self->component, component, componentLength);
Jeff Thompsonf084ec62013-07-09 12:32:52 -070040}
41
42/**
43 * An ndn_Exclude holds an array of ndn_ExcludeEntry.
44 */
45struct ndn_Exclude {
46 struct ndn_ExcludeEntry *entries; /**< pointer to the array of entries. */
47 unsigned int maxEntries; /**< the number of elements in the allocated entries array */
48 unsigned int nEntries; /**< the number of entries in the exclude, 0 for no exclude */
49};
50/**
51 * Initialize an ndn_Exclude struct with the entries array.
Jeff Thompson3548a962013-08-12 18:23:09 -070052 * @param self A pointer to the ndn_Exclude struct.
Jeff Thompsonf084ec62013-07-09 12:32:52 -070053 * @param entries the pre-allocated array of ndn_ExcludeEntry
54 * @param maxEntries the number of elements in the allocated entries array
55 */
Jeff Thompsond1427fb2013-08-29 17:20:32 -070056static inline void ndn_Exclude_initialize(struct ndn_Exclude *self, struct ndn_ExcludeEntry *entries, unsigned int maxEntries)
Jeff Thompsonf084ec62013-07-09 12:32:52 -070057{
58 self->entries = entries;
59 self->maxEntries = maxEntries;
60 self->nEntries = 0;
61}
62
Jeff Thompson2e0e0882013-08-12 17:55:13 -070063/**
64 * Compare the components using NDN component ordering.
65 * A component is less if it is shorter, otherwise if equal length do a byte comparison.
66 * @param component1 A pointer to the first name component.
67 * @param component2 A pointer to the second name component.
68 * @return -1 if component1 is less than component2, 1 if greater or 0 if equal.
69 */
70int ndn_Exclude_compareComponents(struct ndn_NameComponent *component1, struct ndn_NameComponent *component2);
71
Jeff Thompson3548a962013-08-12 18:23:09 -070072/**
73 * Check if the component matches any of the exclude criteria.
74 * @param self A pointer to the ndn_Exclude struct.
75 * @param component A pointer to the name component to check.
76 * @return 1 if the component matches any of the exclude criteria, otherwise 0.
77 */
78int ndn_Exclude_matches(struct ndn_Exclude *self, struct ndn_NameComponent *component);
79
Jeff Thompsonba70f8c2013-07-08 15:34:20 -070080enum {
81 ndn_Interest_CHILD_SELECTOR_LEFT = 0,
82 ndn_Interest_CHILD_SELECTOR_RIGHT = 1,
83 ndn_Interest_ANSWER_CONTENT_STORE = 1,
84 ndn_Interest_ANSWER_GENERATED = 2,
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070085 ndn_Interest_ANSWER_STALE = 4, // Stale answer OK
86 ndn_Interest_MARK_STALE = 16, // Must have scope 0. Michael calls this a "hack"
Jeff Thompsonba70f8c2013-07-08 15:34:20 -070087
88 ndn_Interest_DEFAULT_ANSWER_ORIGIN_KIND = ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED
89};
90
Jeff Thompson8238d002013-07-10 11:56:49 -070091/**
92 * An ndn_Interest holds an ndn_Name and other fields for an interest.
93 */
Jeff Thompsonb7f95562013-07-03 18:36:42 -070094struct ndn_Interest {
95 struct ndn_Name name;
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070096 int minSuffixComponents; /**< -1 for none */
97 int maxSuffixComponents; /**< -1 for none */
Jeff Thompson8238d002013-07-10 11:56:49 -070098 struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070099 struct ndn_Exclude exclude;
100 int childSelector; /**< -1 for none */
101 int answerOriginKind; /**< -1 for none */
102 int scope; /**< -1 for none */
103 double interestLifetimeMilliseconds; /**< milliseconds. -1.0 for none */
104 unsigned char *nonce; /**< pointer to pre-allocated buffer. 0 for none */
Jeff Thompson88ab5dd2013-07-07 20:47:46 -0700105 unsigned int nonceLength; /**< length of nonce. 0 for none */
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700106};
107
Jeff Thompsonf084ec62013-07-09 12:32:52 -0700108/**
Jeff Thompsonb825c632013-07-10 17:59:29 -0700109 * Initialize an ndn_Interest struct with the pre-allocated nameComponents and excludeEntries,
Jeff Thompsonf084ec62013-07-09 12:32:52 -0700110 * and defaults for all the values.
111 * @param self pointer to the ndn_Interest struct
112 * @param nameComponents the pre-allocated array of ndn_NameComponent
113 * @param maxNameComponents the number of elements in the allocated nameComponents array
114 * @param excludeEntries the pre-allocated array of ndn_ExcludeEntry
115 * @param maxExcludeEntries the number of elements in the allocated excludeEntries array
116 */
Jeff Thompsond1427fb2013-08-29 17:20:32 -0700117static inline void ndn_Interest_initialize
Jeff Thompsonf084ec62013-07-09 12:32:52 -0700118 (struct ndn_Interest *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents,
119 struct ndn_ExcludeEntry *excludeEntries, unsigned int maxExcludeEntries)
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700120{
Jeff Thompsond1427fb2013-08-29 17:20:32 -0700121 ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -0700122 self->minSuffixComponents = -1;
Jeff Thompsonf2e5e282013-07-08 15:26:16 -0700123 self->maxSuffixComponents = -1;
Jeff Thompsond1427fb2013-08-29 17:20:32 -0700124 ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
125 ndn_Exclude_initialize(&self->exclude, excludeEntries, maxExcludeEntries);
Jeff Thompson2d27e2f2013-08-09 12:55:00 -0700126 self->childSelector = -1;
127 self->answerOriginKind = -1;
128 self->scope = -1;
129 self->interestLifetimeMilliseconds = -1.0;
130 self->nonce = 0;
131 self->nonceLength = 0;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700132}
133
Jeff Thompsonac9b2c82013-08-13 10:51:59 -0700134/**
135 * Check if self's name matches the given name (using ndn_Name_match) and the given name also conforms to the
136 * interest selectors.
137 * @param self A pointer to the ndn_Interest struct.
138 * @param name A pointer to the name to check.
139 * @return 1 if the name and interest selectors match, 0 otherwise.
140 */
141int ndn_Interest_matchesName(struct ndn_Interest *self, struct ndn_Name *name);
142
Jeff Thompson2d27e2f2013-08-09 12:55:00 -0700143#ifdef __cplusplus
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700144}
145#endif
146
147#endif
148