ndn-lite
interest.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018-2019 Zhiyi Zhang
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v3.0. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #ifndef NDN_ENCODING_INTEREST_H
10 #define NDN_ENCODING_INTEREST_H
11 
12 #include "name.h"
13 #include "signature.h"
14 #include "../security/ndn-lite-crypto-key.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
23 typedef struct interest_params {
25  uint32_t size;
27 
31 typedef struct ndn_interest {
39  uint32_t nonce;
43  uint64_t lifetime;
44 
47 
53 
57  uint8_t hop_limit;
58  uint8_t enable_HopLimit;
59 
66 
73 static inline void
75 {
76  interest->enable_CanBePrefix = 0;
77  interest->enable_MustBeFresh = 0;
78  interest->enable_HopLimit = 0;
79  interest->enable_Parameters = 0;
80  interest->is_SignedInterest = 0;
81 
82  interest->nonce = 0;
84  interest->hop_limit = 0;
85 }
86 
94 static inline void
96 {
97  interest->name = *name;
98 
99  interest->enable_CanBePrefix = 0;
100  interest->enable_MustBeFresh = 0;
101  interest->enable_HopLimit = 0;
102  interest->enable_Parameters = 0;
103  interest->is_SignedInterest = 0;
104 
105  interest->nonce = 0;
107  interest->hop_limit = 0;
108 }
109 
117 int
118 ndn_interest_from_block(ndn_interest_t* interest, const uint8_t* block_value, uint32_t block_size);
119 
125 static inline void
126 ndn_interest_set_CanBePrefix(ndn_interest_t* interest, uint8_t can_be_prefix)
127 {
128  interest->enable_CanBePrefix = (can_be_prefix > 0 ? 1 : 0);
129 }
130 
136 static inline void
137 ndn_interest_set_MustBeFresh(ndn_interest_t* interest, uint8_t must_be_fresh)
138 {
139  interest->enable_MustBeFresh = (must_be_fresh > 0 ? 1 : 0);
140 }
141 
147 static inline void
149 {
150  interest->enable_HopLimit = 1;
151  interest->hop_limit = hop;
152 }
153 
161 static inline int
163  const uint8_t* params_value, uint32_t params_size)
164 {
165  if (params_size > NDN_INTEREST_PARAMS_BUFFER_SIZE)
166  return NDN_OVERSIZE;
167  interest->enable_Parameters = 1;
168  memcpy(interest->parameters.value, params_value, params_size);
169  interest->parameters.size = params_size;
170  return 0;
171 }
172 
180 int
182 
195 int
196 ndn_interest_name_compare_block(const uint8_t* lhs_block_value, uint32_t lhs_block_size,
197  const uint8_t* rhs_block_value, uint32_t rhs_block_size);
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif // NDN_ENCODING_INTEREST_H
uint8_t value[NDN_INTEREST_PARAMS_BUFFER_SIZE]
Definition: interest.h:24
The structure to represent an NDN Interest packet.
Definition: interest.h:31
struct interest_params interest_params_t
The structure to represent the Interest parameters element.
uint8_t hop_limit
The HopLimit of the Interest.
Definition: interest.h:57
static void ndn_interest_set_MustBeFresh(ndn_interest_t *interest, uint8_t must_be_fresh)
Set MustBeFresh flag of the Interest.
Definition: interest.h:137
The structure to represent the Name.
Definition: name.h:24
int ndn_interest_tlv_encode(ndn_encoder_t *encoder, ndn_interest_t *interest)
Encode the Interest into wire format (TLV block).
Definition: interest.c:142
uint8_t is_SignedInterest
Definition: interest.h:60
interest_params_t parameters
The Parameters of the Interest.
Definition: interest.h:51
static int ndn_interest_set_Parameters(ndn_interest_t *interest, const uint8_t *params_value, uint32_t params_size)
Set Parameters element of the Interest.
Definition: interest.h:162
The structure to represent the Signature.
Definition: signature.h:38
uint64_t lifetime
The lifetime of the Interest.
Definition: interest.h:43
#define NDN_DEFAULT_INTEREST_LIFETIME
Definition: ndn-constants.h:30
static void ndn_interest_init(ndn_interest_t *interest)
Init an Interest packet.
Definition: interest.h:74
int ndn_interest_name_compare_block(const uint8_t *lhs_block_value, uint32_t lhs_block_size, const uint8_t *rhs_block_value, uint32_t rhs_block_size)
Compare two encoded Interests' names.
Definition: interest.c:236
static void ndn_interest_from_name(ndn_interest_t *interest, const ndn_name_t *name)
Init an Interest packet from a.
Definition: interest.h:95
struct ndn_interest ndn_interest_t
The structure to represent an NDN Interest packet.
uint8_t enable_MustBeFresh
Definition: interest.h:46
uint32_t size
Definition: interest.h:25
static void ndn_interest_set_CanBePrefix(ndn_interest_t *interest, uint8_t can_be_prefix)
Set CanBePrefix flag of the Interest.
Definition: interest.h:126
ndn_signature_t signature
The signature structure.
Definition: interest.h:64
static void ndn_interest_set_HopLimit(ndn_interest_t *interest, uint8_t hop)
Set HopLimit element of the Interest.
Definition: interest.h:148
#define NDN_INTEREST_PARAMS_BUFFER_SIZE
Definition: ndn-constants.h:27
uint8_t enable_CanBePrefix
Definition: interest.h:45
uint8_t enable_HopLimit
Definition: interest.h:58
#define NDN_OVERSIZE
The object given is larger than expected.
Definition: ndn-error-code.h:33
The structure to keep the state when doing NDN TLV encoding.
Definition: encoder.h:31
The structure to represent the Interest parameters element.
Definition: interest.h:23
int ndn_interest_from_block(ndn_interest_t *interest, const uint8_t *block_value, uint32_t block_size)
Decode an Interest TLV block into an ndn_interest_t.
Definition: interest.c:51
uint8_t enable_Parameters
Definition: interest.h:52
ndn_name_t name
The name of the Interest.
Definition: interest.h:35
uint32_t nonce
The nonce of the Interest.
Definition: interest.h:39