summaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_store_update.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/test_namestore_api_store_update.c')
-rw-r--r--src/namestore/test_namestore_api_store_update.c326
1 files changed, 163 insertions, 163 deletions
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c
index b1c0770ae..5e9885b3e 100644
--- a/src/namestore/test_namestore_api_store_update.c
+++ b/src/namestore/test_namestore_api_store_update.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_store_update.c 21 * @file namestore/test_namestore_api_store_update.c
22 * @brief testcase for namestore_api.c: store a record, update it and perform a lookup 22 * @brief testcase for namestore_api.c: store a record, update it and perform a lookup
@@ -39,7 +39,7 @@
39 39
40#define TEST_RECORD_DATA2 'b' 40#define TEST_RECORD_DATA2 'b'
41 41
42#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 42#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
43 43
44 44
45static struct GNUNET_NAMESTORE_Handle *nsh; 45static struct GNUNET_NAMESTORE_Handle *nsh;
@@ -69,217 +69,217 @@ static const char *name = "dummy";
69 * @param cls handle to use to re-connect. 69 * @param cls handle to use to re-connect.
70 */ 70 */
71static void 71static void
72endbadly (void *cls) 72endbadly(void *cls)
73{ 73{
74 GNUNET_break (0); 74 GNUNET_break(0);
75 endbadly_task = NULL; 75 endbadly_task = NULL;
76 GNUNET_SCHEDULER_shutdown (); 76 GNUNET_SCHEDULER_shutdown();
77 res = 1; 77 res = 1;
78} 78}
79 79
80 80
81static void 81static void
82end (void *cls) 82end(void *cls)
83{ 83{
84 if (NULL != endbadly_task) 84 if (NULL != endbadly_task)
85 { 85 {
86 GNUNET_SCHEDULER_cancel (endbadly_task); 86 GNUNET_SCHEDULER_cancel(endbadly_task);
87 endbadly_task = NULL; 87 endbadly_task = NULL;
88 } 88 }
89 if (NULL != nsqe) 89 if (NULL != nsqe)
90 { 90 {
91 GNUNET_NAMESTORE_cancel (nsqe); 91 GNUNET_NAMESTORE_cancel(nsqe);
92 nsqe = NULL; 92 nsqe = NULL;
93 } 93 }
94 if (NULL != ncqe) 94 if (NULL != ncqe)
95 { 95 {
96 GNUNET_NAMECACHE_cancel (ncqe); 96 GNUNET_NAMECACHE_cancel(ncqe);
97 ncqe = NULL; 97 ncqe = NULL;
98 } 98 }
99 if (NULL != nsh) 99 if (NULL != nsh)
100 { 100 {
101 GNUNET_NAMESTORE_disconnect (nsh); 101 GNUNET_NAMESTORE_disconnect(nsh);
102 nsh = NULL; 102 nsh = NULL;
103 } 103 }
104 if (NULL != nch) 104 if (NULL != nch)
105 { 105 {
106 GNUNET_NAMECACHE_disconnect (nch); 106 GNUNET_NAMECACHE_disconnect(nch);
107 nch = NULL; 107 nch = NULL;
108 } 108 }
109 if (NULL != privkey) 109 if (NULL != privkey)
110 { 110 {
111 GNUNET_free (privkey); 111 GNUNET_free(privkey);
112 privkey = NULL; 112 privkey = NULL;
113 } 113 }
114} 114}
115 115
116 116
117static void 117static void
118put_cont (void *cls, 118put_cont(void *cls,
119 int32_t success, 119 int32_t success,
120 const char *emsg); 120 const char *emsg);
121 121
122 122
123static void 123static void
124rd_decrypt_cb (void *cls, 124rd_decrypt_cb(void *cls,
125 unsigned int rd_count, 125 unsigned int rd_count,
126 const struct GNUNET_GNSRECORD_Data *rd) 126 const struct GNUNET_GNSRECORD_Data *rd)
127{ 127{
128 struct GNUNET_GNSRECORD_Data rd_new; 128 struct GNUNET_GNSRECORD_Data rd_new;
129 129
130 GNUNET_assert (1 == rd_count); 130 GNUNET_assert(1 == rd_count);
131 GNUNET_assert (NULL != rd); 131 GNUNET_assert(NULL != rd);
132 132
133 if (GNUNET_NO == update_performed) 133 if (GNUNET_NO == update_performed)
134 { 134 {
135 char rd_cmp_data[TEST_RECORD_DATALEN]; 135 char rd_cmp_data[TEST_RECORD_DATALEN];
136 136
137 memset (rd_cmp_data, 137 memset(rd_cmp_data,
138 TEST_RECORD_DATA, 138 TEST_RECORD_DATA,
139 TEST_RECORD_DATALEN); 139 TEST_RECORD_DATALEN);
140 GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); 140 GNUNET_assert(TEST_RECORD_TYPE == rd[0].record_type);
141 GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); 141 GNUNET_assert(TEST_RECORD_DATALEN == rd[0].data_size);
142 GNUNET_assert (0 == memcmp (&rd_cmp_data, 142 GNUNET_assert(0 == memcmp(&rd_cmp_data,
143 rd[0].data, 143 rd[0].data,
144 TEST_RECORD_DATALEN)); 144 TEST_RECORD_DATALEN));
145 145
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 146 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
147 "Block was decrypted successfully, updating record \n"); 147 "Block was decrypted successfully, updating record \n");
148 148
149 rd_new.flags = GNUNET_GNSRECORD_RF_NONE; 149 rd_new.flags = GNUNET_GNSRECORD_RF_NONE;
150 rd_new.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 150 rd_new.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
151 rd_new.record_type = TEST_RECORD_TYPE; 151 rd_new.record_type = TEST_RECORD_TYPE;
152 rd_new.data_size = TEST_RECORD_DATALEN2; 152 rd_new.data_size = TEST_RECORD_DATALEN2;
153 rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); 153 rd_new.data = GNUNET_malloc(TEST_RECORD_DATALEN2);
154 memset ((char *) rd_new.data, 154 memset((char *)rd_new.data,
155 TEST_RECORD_DATA2, 155 TEST_RECORD_DATA2,
156 TEST_RECORD_DATALEN2); 156 TEST_RECORD_DATALEN2);
157 157
158 nsqe = GNUNET_NAMESTORE_records_store (nsh, 158 nsqe = GNUNET_NAMESTORE_records_store(nsh,
159 privkey, 159 privkey,
160 name, 160 name,
161 1, 161 1,
162 &rd_new, 162 &rd_new,
163 &put_cont, 163 &put_cont,
164 (void *) name); 164 (void *)name);
165 update_performed = GNUNET_YES; 165 update_performed = GNUNET_YES;
166 } 166 }
167 else 167 else
168 { 168 {
169 char rd_cmp_data[TEST_RECORD_DATALEN2]; 169 char rd_cmp_data[TEST_RECORD_DATALEN2];
170 170
171 memset (rd_cmp_data, 171 memset(rd_cmp_data,
172 TEST_RECORD_DATA2, 172 TEST_RECORD_DATA2,
173 TEST_RECORD_DATALEN2); 173 TEST_RECORD_DATALEN2);
174 GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); 174 GNUNET_assert(TEST_RECORD_TYPE == rd[0].record_type);
175 GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); 175 GNUNET_assert(TEST_RECORD_DATALEN2 == rd[0].data_size);
176 GNUNET_assert (0 == memcmp (&rd_cmp_data, 176 GNUNET_assert(0 == memcmp(&rd_cmp_data,
177 rd[0].data, 177 rd[0].data,
178 TEST_RECORD_DATALEN2)); 178 TEST_RECORD_DATALEN2));
179 GNUNET_SCHEDULER_shutdown (); 179 GNUNET_SCHEDULER_shutdown();
180 res = 0; 180 res = 0;
181 } 181 }
182} 182}
183 183
184 184
185static void 185static void
186name_lookup_proc (void *cls, 186name_lookup_proc(void *cls,
187 const struct GNUNET_GNSRECORD_Block *block) 187 const struct GNUNET_GNSRECORD_Block *block)
188{ 188{
189 const char *name = cls; 189 const char *name = cls;
190 190
191 ncqe = NULL; 191 ncqe = NULL;
192 GNUNET_assert (NULL != cls); 192 GNUNET_assert(NULL != cls);
193 if (NULL == block) 193 if (NULL == block)
194 { 194 {
195 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 195 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
196 _("Namecache returned no block for `%s'\n"), 196 _("Namecache returned no block for `%s'\n"),
197 name); 197 name);
198 GNUNET_SCHEDULER_shutdown (); 198 GNUNET_SCHEDULER_shutdown();
199 return; 199 return;
200 } 200 }
201 201
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 202 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
203 "Namecache returned block, decrypting \n"); 203 "Namecache returned block, decrypting \n");
204 GNUNET_assert (GNUNET_OK == 204 GNUNET_assert(GNUNET_OK ==
205 GNUNET_GNSRECORD_block_decrypt (block, 205 GNUNET_GNSRECORD_block_decrypt(block,
206 &pubkey, 206 &pubkey,
207 name, 207 name,
208 &rd_decrypt_cb, 208 &rd_decrypt_cb,
209 (void *) name)); 209 (void *)name));
210} 210}
211 211
212 212
213static void 213static void
214put_cont (void *cls, 214put_cont(void *cls,
215 int32_t success, 215 int32_t success,
216 const char *emsg) 216 const char *emsg)
217{ 217{
218 const char *name = cls; 218 const char *name = cls;
219 struct GNUNET_HashCode derived_hash; 219 struct GNUNET_HashCode derived_hash;
220 220
221 nsqe = NULL; 221 nsqe = NULL;
222 GNUNET_assert (NULL != cls); 222 GNUNET_assert(NULL != cls);
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 223 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
224 "Name store added record for `%s': %s\n", 224 "Name store added record for `%s': %s\n",
225 name, 225 name,
226 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 226 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
227 /* Create derived hash */ 227 /* Create derived hash */
228 GNUNET_GNSRECORD_query_from_private_key (privkey, 228 GNUNET_GNSRECORD_query_from_private_key(privkey,
229 name, 229 name,
230 &derived_hash); 230 &derived_hash);
231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 231 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
232 "Looking in namecache for `%s'\n", 232 "Looking in namecache for `%s'\n",
233 GNUNET_h2s (&derived_hash)); 233 GNUNET_h2s(&derived_hash));
234 ncqe = GNUNET_NAMECACHE_lookup_block (nch, 234 ncqe = GNUNET_NAMECACHE_lookup_block(nch,
235 &derived_hash, 235 &derived_hash,
236 &name_lookup_proc, (void *) name); 236 &name_lookup_proc, (void *)name);
237} 237}
238 238
239 239
240static void 240static void
241run (void *cls, 241run(void *cls,
242 const struct GNUNET_CONFIGURATION_Handle *cfg, 242 const struct GNUNET_CONFIGURATION_Handle *cfg,
243 struct GNUNET_TESTING_Peer *peer) 243 struct GNUNET_TESTING_Peer *peer)
244{ 244{
245 struct GNUNET_GNSRECORD_Data rd; 245 struct GNUNET_GNSRECORD_Data rd;
246 246
247 update_performed = GNUNET_NO; 247 update_performed = GNUNET_NO;
248 GNUNET_SCHEDULER_add_shutdown (&end, 248 GNUNET_SCHEDULER_add_shutdown(&end,
249 NULL); 249 NULL);
250 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 250 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
251 &endbadly, 251 &endbadly,
252 NULL); 252 NULL);
253 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 253 privkey = GNUNET_CRYPTO_ecdsa_key_create();
254 GNUNET_assert (privkey != NULL); 254 GNUNET_assert(privkey != NULL);
255 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 255 GNUNET_CRYPTO_ecdsa_key_get_public(privkey,
256 &pubkey); 256 &pubkey);
257 rd.flags = GNUNET_GNSRECORD_RF_NONE; 257 rd.flags = GNUNET_GNSRECORD_RF_NONE;
258 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 258 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
259 rd.record_type = TEST_RECORD_TYPE; 259 rd.record_type = TEST_RECORD_TYPE;
260 rd.data_size = TEST_RECORD_DATALEN; 260 rd.data_size = TEST_RECORD_DATALEN;
261 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 261 rd.data = GNUNET_malloc(TEST_RECORD_DATALEN);
262 memset ((char *) rd.data, 262 memset((char *)rd.data,
263 TEST_RECORD_DATA, 263 TEST_RECORD_DATA,
264 TEST_RECORD_DATALEN); 264 TEST_RECORD_DATALEN);
265 265
266 nsh = GNUNET_NAMESTORE_connect (cfg); 266 nsh = GNUNET_NAMESTORE_connect(cfg);
267 GNUNET_break (NULL != nsh); 267 GNUNET_break(NULL != nsh);
268 nch = GNUNET_NAMECACHE_connect (cfg); 268 nch = GNUNET_NAMECACHE_connect(cfg);
269 GNUNET_break (NULL != nch); 269 GNUNET_break(NULL != nch);
270 nsqe = GNUNET_NAMESTORE_records_store (nsh, 270 nsqe = GNUNET_NAMESTORE_records_store(nsh,
271 privkey, 271 privkey,
272 name, 272 name,
273 1, 273 1,
274 &rd, 274 &rd,
275 &put_cont, 275 &put_cont,
276 (void *) name); 276 (void *)name);
277 if (NULL == nsqe) 277 if (NULL == nsqe)
278 { 278 {
279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 279 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
280 _("Namestore cannot store no block\n")); 280 _("Namestore cannot store no block\n"));
281 } 281 }
282 GNUNET_free ((void *)rd.data); 282 GNUNET_free((void *)rd.data);
283} 283}
284 284
285 285
@@ -287,25 +287,25 @@ run (void *cls,
287 287
288 288
289int 289int
290main (int argc, 290main(int argc,
291 char *argv[]) 291 char *argv[])
292{ 292{
293 const char *plugin_name; 293 const char *plugin_name;
294 char *cfg_name; 294 char *cfg_name;
295 295
296 SETUP_CFG (plugin_name, cfg_name); 296 SETUP_CFG(plugin_name, cfg_name);
297 res = 1; 297 res = 1;
298 if (0 != 298 if (0 !=
299 GNUNET_TESTING_peer_run ("test-namestore-api-store-update", 299 GNUNET_TESTING_peer_run("test-namestore-api-store-update",
300 cfg_name, 300 cfg_name,
301 &run, 301 &run,
302 NULL)) 302 NULL))
303 { 303 {
304 res = 1; 304 res = 1;
305 } 305 }
306 GNUNET_DISK_purge_cfg_dir (cfg_name, 306 GNUNET_DISK_purge_cfg_dir(cfg_name,
307 "GNUNET_TEST_HOME"); 307 "GNUNET_TEST_HOME");
308 GNUNET_free (cfg_name); 308 GNUNET_free(cfg_name);
309 return res; 309 return res;
310} 310}
311 311