diff options
Diffstat (limited to 'src/namestore')
32 files changed, 1266 insertions, 1143 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 32b1a39d0..753ee79d1 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -80,6 +80,11 @@ static struct GNUNET_NAMESTORE_QueueEntry *add_qe_uri; | |||
80 | static struct GNUNET_NAMESTORE_QueueEntry *add_qe; | 80 | static struct GNUNET_NAMESTORE_QueueEntry *add_qe; |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Queue entry for the 'lookup' operation. | ||
84 | */ | ||
85 | static struct GNUNET_NAMESTORE_QueueEntry *get_qe; | ||
86 | |||
87 | /** | ||
83 | * Queue entry for the 'reverse lookup' operation (in combination with a name). | 88 | * Queue entry for the 'reverse lookup' operation (in combination with a name). |
84 | */ | 89 | */ |
85 | static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; | 90 | static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; |
@@ -234,6 +239,11 @@ do_shutdown (void *cls) | |||
234 | GNUNET_NAMESTORE_cancel (add_qe_uri); | 239 | GNUNET_NAMESTORE_cancel (add_qe_uri); |
235 | add_qe_uri = NULL; | 240 | add_qe_uri = NULL; |
236 | } | 241 | } |
242 | if (NULL != get_qe) | ||
243 | { | ||
244 | GNUNET_NAMESTORE_cancel (get_qe); | ||
245 | get_qe = NULL; | ||
246 | } | ||
237 | if (NULL != del_qe) | 247 | if (NULL != del_qe) |
238 | { | 248 | { |
239 | GNUNET_NAMESTORE_cancel (del_qe); | 249 | GNUNET_NAMESTORE_cancel (del_qe); |
@@ -271,6 +281,7 @@ test_finished () | |||
271 | { | 281 | { |
272 | if ( (NULL == add_qe) && | 282 | if ( (NULL == add_qe) && |
273 | (NULL == add_qe_uri) && | 283 | (NULL == add_qe_uri) && |
284 | (NULL == get_qe) && | ||
274 | (NULL == del_qe) && | 285 | (NULL == del_qe) && |
275 | (NULL == reverse_qe) && | 286 | (NULL == reverse_qe) && |
276 | (NULL == list_it) ) | 287 | (NULL == list_it) ) |
@@ -492,6 +503,30 @@ display_record_monitor (void *cls, | |||
492 | 503 | ||
493 | 504 | ||
494 | /** | 505 | /** |
506 | * Process a record that was stored in the namestore. | ||
507 | * | ||
508 | * @param cls closure | ||
509 | * @param zone_key private key of the zone | ||
510 | * @param rname name that is being mapped (at most 255 characters long) | ||
511 | * @param rd_len number of entries in @a rd array | ||
512 | * @param rd array of records with data to store | ||
513 | */ | ||
514 | static void | ||
515 | display_record_lookup (void *cls, | ||
516 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | ||
517 | const char *rname, | ||
518 | unsigned int rd_len, | ||
519 | const struct GNUNET_GNSRECORD_Data *rd) | ||
520 | { | ||
521 | get_qe = NULL; | ||
522 | display_record (rname, | ||
523 | rd_len, | ||
524 | rd); | ||
525 | test_finished (); | ||
526 | } | ||
527 | |||
528 | |||
529 | /** | ||
495 | * Function called once we are in sync in monitor mode. | 530 | * Function called once we are in sync in monitor mode. |
496 | * | 531 | * |
497 | * @param cls NULL | 532 | * @param cls NULL |
@@ -522,12 +557,29 @@ monitor_error_cb (void *cls) | |||
522 | 557 | ||
523 | 558 | ||
524 | /** | 559 | /** |
525 | * Function called if lookup fails. | 560 | * Function called on errors while monitoring. |
561 | * | ||
562 | * @param cls NULL | ||
526 | */ | 563 | */ |
527 | static void | 564 | static void |
528 | lookup_error_cb (void *cls) | 565 | lookup_error_cb (void *cls) |
529 | { | 566 | { |
530 | (void) cls; | 567 | (void) cls; |
568 | get_qe = NULL; | ||
569 | FPRINTF (stderr, | ||
570 | "%s", | ||
571 | "Failed to lookup record.\n"); | ||
572 | test_finished (); | ||
573 | } | ||
574 | |||
575 | |||
576 | /** | ||
577 | * Function called if lookup fails. | ||
578 | */ | ||
579 | static void | ||
580 | add_error_cb (void *cls) | ||
581 | { | ||
582 | (void) cls; | ||
531 | add_qe = NULL; | 583 | add_qe = NULL; |
532 | GNUNET_break (0); | 584 | GNUNET_break (0); |
533 | ret = 1; | 585 | ret = 1; |
@@ -970,7 +1022,7 @@ identity_cb (void *cls, | |||
970 | add_qe = GNUNET_NAMESTORE_records_lookup (ns, | 1022 | add_qe = GNUNET_NAMESTORE_records_lookup (ns, |
971 | &zone_pkey, | 1023 | &zone_pkey, |
972 | name, | 1024 | name, |
973 | &lookup_error_cb, | 1025 | &add_error_cb, |
974 | NULL, | 1026 | NULL, |
975 | &get_existing_record, | 1027 | &get_existing_record, |
976 | NULL); | 1028 | NULL); |
@@ -996,14 +1048,23 @@ identity_cb (void *cls, | |||
996 | } | 1048 | } |
997 | if (list) | 1049 | if (list) |
998 | { | 1050 | { |
999 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | 1051 | if (NULL != name) |
1000 | &zone_pkey, | 1052 | get_qe = GNUNET_NAMESTORE_records_lookup (ns, |
1001 | &zone_iteration_error_cb, | 1053 | &zone_pkey, |
1002 | NULL, | 1054 | name, |
1003 | &display_record_iterator, | 1055 | &lookup_error_cb, |
1004 | NULL, | 1056 | NULL, |
1005 | &zone_iteration_finished, | 1057 | &display_record_lookup, |
1006 | NULL); | 1058 | NULL); |
1059 | else | ||
1060 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | ||
1061 | &zone_pkey, | ||
1062 | &zone_iteration_error_cb, | ||
1063 | NULL, | ||
1064 | &display_record_iterator, | ||
1065 | NULL, | ||
1066 | &zone_iteration_finished, | ||
1067 | NULL); | ||
1007 | } | 1068 | } |
1008 | if (NULL != reverse_pkey) | 1069 | if (NULL != reverse_pkey) |
1009 | { | 1070 | { |
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index f47c8776b..8e88558de 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012, 2013, 2014 GNUnet e.V. | 3 | Copyright (C) 2012, 2013, 2014, 2018 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -23,6 +23,9 @@ | |||
23 | * @brief namestore for the GNUnet naming system | 23 | * @brief namestore for the GNUnet naming system |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | * | ||
27 | * TODO: | ||
28 | * - run testcases, make sure everything works! | ||
26 | */ | 29 | */ |
27 | #include "platform.h" | 30 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 31 | #include "gnunet_util_lib.h" |
@@ -37,6 +40,11 @@ | |||
37 | 40 | ||
38 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) | 41 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) |
39 | 42 | ||
43 | /** | ||
44 | * If a monitor takes more than 1 minute to process an event, print a warning. | ||
45 | */ | ||
46 | #define MONITOR_STALL_WARN_DELAY GNUNET_TIME_UNIT_MINUTES | ||
47 | |||
40 | 48 | ||
41 | /** | 49 | /** |
42 | * A namestore client | 50 | * A namestore client |
@@ -161,6 +169,16 @@ struct ZoneMonitor | |||
161 | struct GNUNET_SCHEDULER_Task *task; | 169 | struct GNUNET_SCHEDULER_Task *task; |
162 | 170 | ||
163 | /** | 171 | /** |
172 | * Task to warn about slow monitors. | ||
173 | */ | ||
174 | struct GNUNET_SCHEDULER_Task *sa_wait_warning; | ||
175 | |||
176 | /** | ||
177 | * Since when are we blocked on this monitor? | ||
178 | */ | ||
179 | struct GNUNET_TIME_Absolute sa_waiting_start; | ||
180 | |||
181 | /** | ||
164 | * Last sequence number in the zone iteration used to address next | 182 | * Last sequence number in the zone iteration used to address next |
165 | * result of the zone iteration in the store | 183 | * result of the zone iteration in the store |
166 | * | 184 | * |
@@ -175,6 +193,27 @@ struct ZoneMonitor | |||
175 | */ | 193 | */ |
176 | uint64_t limit; | 194 | uint64_t limit; |
177 | 195 | ||
196 | /** | ||
197 | * How many more requests may we receive from the iterator | ||
198 | * before it is at the limit we gave it? Will be below or | ||
199 | * equal to @e limit. The effective limit for monitor | ||
200 | * events is thus @e iteration_cnt - @e limit! | ||
201 | */ | ||
202 | uint64_t iteration_cnt; | ||
203 | |||
204 | /** | ||
205 | * Are we (still) in the initial iteration pass? | ||
206 | */ | ||
207 | int in_first_iteration; | ||
208 | |||
209 | /** | ||
210 | * Is there a store activity waiting for this monitor? We only raise the | ||
211 | * flag when it happens and search the DLL for the store activity when we | ||
212 | * had a limit increase. If we cannot find any waiting store activity at | ||
213 | * that time, we clear the flag again. | ||
214 | */ | ||
215 | int sa_waiting; | ||
216 | |||
178 | }; | 217 | }; |
179 | 218 | ||
180 | 219 | ||
@@ -212,6 +251,57 @@ struct CacheOperation | |||
212 | 251 | ||
213 | 252 | ||
214 | /** | 253 | /** |
254 | * Information for an ongoing #handle_record_store() operation. | ||
255 | * Needed as we may wait for monitors to be ready for the notification. | ||
256 | */ | ||
257 | struct StoreActivity | ||
258 | { | ||
259 | /** | ||
260 | * Kept in a DLL. | ||
261 | */ | ||
262 | struct StoreActivity *next; | ||
263 | |||
264 | /** | ||
265 | * Kept in a DLL. | ||
266 | */ | ||
267 | struct StoreActivity *prev; | ||
268 | |||
269 | /** | ||
270 | * Which client triggered the store activity? | ||
271 | */ | ||
272 | struct NamestoreClient *nc; | ||
273 | |||
274 | /** | ||
275 | * Copy of the original store message (as data fields in @e rd will | ||
276 | * point into it!). | ||
277 | */ | ||
278 | const struct RecordStoreMessage *rsm; | ||
279 | |||
280 | /** | ||
281 | * Array of record data to store (without NICK unless this is about | ||
282 | * #GNUNET_GNS_EMPTY_LABEL_AT). Length is in @e rd_count. | ||
283 | */ | ||
284 | struct GNUNET_GNSRECORD_Data *rd; | ||
285 | |||
286 | /** | ||
287 | * Next zone monitor that still needs to be notified about this PUT. | ||
288 | */ | ||
289 | struct ZoneMonitor *zm_pos; | ||
290 | |||
291 | /** | ||
292 | * Label nicely canonicalized (lower case). | ||
293 | */ | ||
294 | char *conv_name; | ||
295 | |||
296 | /** | ||
297 | * How many records do we try to store? | ||
298 | */ | ||
299 | unsigned int rd_count; | ||
300 | |||
301 | }; | ||
302 | |||
303 | |||
304 | /** | ||
215 | * Public key of all zeros. | 305 | * Public key of all zeros. |
216 | */ | 306 | */ |
217 | static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero; | 307 | static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero; |
@@ -262,6 +352,16 @@ static struct ZoneMonitor *monitor_head; | |||
262 | static struct ZoneMonitor *monitor_tail; | 352 | static struct ZoneMonitor *monitor_tail; |
263 | 353 | ||
264 | /** | 354 | /** |
355 | * Head of DLL of monitor-blocked store activities. | ||
356 | */ | ||
357 | static struct StoreActivity *sa_head; | ||
358 | |||
359 | /** | ||
360 | * Tail of DLL of monitor-blocked store activities. | ||
361 | */ | ||
362 | static struct StoreActivity *sa_tail; | ||
363 | |||
364 | /** | ||
265 | * Notification context shared by all monitors. | 365 | * Notification context shared by all monitors. |
266 | */ | 366 | */ |
267 | static struct GNUNET_NotificationContext *monitor_nc; | 367 | static struct GNUNET_NotificationContext *monitor_nc; |
@@ -326,80 +426,21 @@ cleanup_task (void *cls) | |||
326 | 426 | ||
327 | 427 | ||
328 | /** | 428 | /** |
329 | * Called whenever a client is disconnected. | 429 | * Release memory used by @a sa. |
330 | * Frees our resources associated with that client. | ||
331 | * | 430 | * |
332 | * @param cls closure | 431 | * @param sa activity to free |
333 | * @param client identification of the client | ||
334 | * @param app_ctx the `struct NamestoreClient` of @a client | ||
335 | */ | 432 | */ |
336 | static void | 433 | static void |
337 | client_disconnect_cb (void *cls, | 434 | free_store_activity (struct StoreActivity *sa) |
338 | struct GNUNET_SERVICE_Client *client, | ||
339 | void *app_ctx) | ||
340 | { | ||
341 | struct NamestoreClient *nc = app_ctx; | ||
342 | struct ZoneIteration *no; | ||
343 | struct ZoneMonitor *zm; | ||
344 | struct CacheOperation *cop; | ||
345 | |||
346 | (void) cls; | ||
347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
348 | "Client %p disconnected\n", | ||
349 | client); | ||
350 | for (zm = monitor_head; NULL != zm; zm = zm->next) | ||
351 | { | ||
352 | if (nc == zm->nc) | ||
353 | { | ||
354 | GNUNET_CONTAINER_DLL_remove (monitor_head, | ||
355 | monitor_tail, | ||
356 | zm); | ||
357 | if (NULL != zm->task) | ||
358 | { | ||
359 | GNUNET_SCHEDULER_cancel (zm->task); | ||
360 | zm->task = NULL; | ||
361 | } | ||
362 | GNUNET_free (zm); | ||
363 | break; | ||
364 | } | ||
365 | } | ||
366 | while (NULL != (no = nc->op_head)) | ||
367 | { | ||
368 | GNUNET_CONTAINER_DLL_remove (nc->op_head, | ||
369 | nc->op_tail, | ||
370 | no); | ||
371 | GNUNET_free (no); | ||
372 | } | ||
373 | for (cop = cop_head; NULL != cop; cop = cop->next) | ||
374 | if (nc == cop->nc) | ||
375 | cop->nc = NULL; | ||
376 | GNUNET_free (nc); | ||
377 | } | ||
378 | |||
379 | |||
380 | /** | ||
381 | * Add a client to our list of active clients. | ||
382 | * | ||
383 | * @param cls NULL | ||
384 | * @param client client to add | ||
385 | * @param mq message queue for @a client | ||
386 | * @return internal namestore client structure for this client | ||
387 | */ | ||
388 | static void * | ||
389 | client_connect_cb (void *cls, | ||
390 | struct GNUNET_SERVICE_Client *client, | ||
391 | struct GNUNET_MQ_Handle *mq) | ||
392 | { | 435 | { |
393 | struct NamestoreClient *nc; | 436 | GNUNET_CONTAINER_DLL_remove (sa_head, |
394 | 437 | sa_tail, | |
395 | (void) cls; | 438 | sa); |
396 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 439 | GNUNET_array_grow (sa->rd, |
397 | "Client %p connected\n", | 440 | sa->rd_count, |
398 | client); | 441 | 0); |
399 | nc = GNUNET_new (struct NamestoreClient); | 442 | GNUNET_free (sa->conv_name); |
400 | nc->client = client; | 443 | GNUNET_free (sa); |
401 | nc->mq = mq; | ||
402 | return nc; | ||
403 | } | 444 | } |
404 | 445 | ||
405 | 446 | ||
@@ -509,18 +550,16 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd, | |||
509 | uint64_t latest_expiration; | 550 | uint64_t latest_expiration; |
510 | size_t req; | 551 | size_t req; |
511 | char *data; | 552 | char *data; |
512 | int record_offset; | ||
513 | size_t data_offset; | 553 | size_t data_offset; |
514 | 554 | ||
515 | (*rdc_res) = 1 + rd2_length; | 555 | (*rdc_res) = 1 + rd2_length; |
516 | if (0 == 1 + rd2_length) | 556 | if (0 == 1 + rd2_length) |
517 | { | 557 | { |
558 | GNUNET_break (0); | ||
518 | (*rd_res) = NULL; | 559 | (*rd_res) = NULL; |
519 | return; | 560 | return; |
520 | } | 561 | } |
521 | req = 0; | 562 | req = sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd->data_size; |
522 | for (unsigned int c=0; c< 1; c++) | ||
523 | req += sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd[c].data_size; | ||
524 | for (unsigned int c=0; c< rd2_length; c++) | 563 | for (unsigned int c=0; c< rd2_length; c++) |
525 | req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size; | 564 | req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size; |
526 | (*rd_res) = GNUNET_malloc (req); | 565 | (*rd_res) = GNUNET_malloc (req); |
@@ -539,20 +578,19 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd, | |||
539 | latest_expiration = rd2[c].expiration_time; | 578 | latest_expiration = rd2[c].expiration_time; |
540 | (*rd_res)[c] = rd2[c]; | 579 | (*rd_res)[c] = rd2[c]; |
541 | (*rd_res)[c].data = (void *) &data[data_offset]; | 580 | (*rd_res)[c].data = (void *) &data[data_offset]; |
542 | GNUNET_memcpy ((void *) (*rd_res)[c].data, | 581 | GNUNET_memcpy (&data[data_offset], |
543 | rd2[c].data, | 582 | rd2[c].data, |
544 | rd2[c].data_size); | 583 | rd2[c].data_size); |
545 | data_offset += (*rd_res)[c].data_size; | 584 | data_offset += (*rd_res)[c].data_size; |
546 | } | 585 | } |
547 | /* append nick */ | 586 | /* append nick */ |
548 | record_offset = rd2_length; | 587 | (*rd_res)[rd2_length] = *nick_rd; |
549 | (*rd_res)[record_offset] = *nick_rd; | 588 | (*rd_res)[rd2_length].expiration_time = latest_expiration; |
550 | (*rd_res)[record_offset].expiration_time = latest_expiration; | 589 | (*rd_res)[rd2_length].data = (void *) &data[data_offset]; |
551 | (*rd_res)[record_offset].data = (void *) &data[data_offset]; | 590 | GNUNET_memcpy ((void *) (*rd_res)[rd2_length].data, |
552 | GNUNET_memcpy ((void *) (*rd_res)[record_offset].data, | ||
553 | nick_rd->data, | 591 | nick_rd->data, |
554 | nick_rd->data_size); | 592 | nick_rd->data_size); |
555 | data_offset += (*rd_res)[record_offset].data_size; | 593 | data_offset += (*rd_res)[rd2_length].data_size; |
556 | GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset); | 594 | GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset); |
557 | } | 595 | } |
558 | 596 | ||
@@ -606,7 +644,8 @@ send_lookup_response (struct NamestoreClient *nc, | |||
606 | } | 644 | } |
607 | 645 | ||
608 | name_len = strlen (name) + 1; | 646 | name_len = strlen (name) + 1; |
609 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res); | 647 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, |
648 | res); | ||
610 | env = GNUNET_MQ_msg_extra (zir_msg, | 649 | env = GNUNET_MQ_msg_extra (zir_msg, |
611 | name_len + rd_ser_len, | 650 | name_len + rd_ser_len, |
612 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); | 651 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); |
@@ -655,6 +694,10 @@ send_store_response (struct NamestoreClient *nc, | |||
655 | 694 | ||
656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
657 | "Sending RECORD_STORE_RESPONSE message\n"); | 696 | "Sending RECORD_STORE_RESPONSE message\n"); |
697 | GNUNET_STATISTICS_update (statistics, | ||
698 | "Store requests completed", | ||
699 | 1, | ||
700 | GNUNET_NO); | ||
658 | env = GNUNET_MQ_msg (rcr_msg, | 701 | env = GNUNET_MQ_msg (rcr_msg, |
659 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); | 702 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); |
660 | rcr_msg->gns_header.r_id = htonl (rid); | 703 | rcr_msg->gns_header.r_id = htonl (rid); |
@@ -795,6 +838,208 @@ refresh_block (struct NamestoreClient *nc, | |||
795 | 838 | ||
796 | 839 | ||
797 | /** | 840 | /** |
841 | * Print a warning that one of our monitors is no longer reacting. | ||
842 | * | ||
843 | * @param cls a `struct ZoneMonitor` to warn about | ||
844 | */ | ||
845 | static void | ||
846 | warn_monitor_slow (void *cls) | ||
847 | { | ||
848 | struct ZoneMonitor *zm = cls; | ||
849 | |||
850 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
851 | "No response from monitor since %s\n", | ||
852 | GNUNET_STRINGS_absolute_time_to_string (zm->sa_waiting_start)); | ||
853 | zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, | ||
854 | &warn_monitor_slow, | ||
855 | zm); | ||
856 | } | ||
857 | |||
858 | |||
859 | /** | ||
860 | * Continue processing the @a sa. | ||
861 | * | ||
862 | * @param sa store activity to process | ||
863 | */ | ||
864 | static void | ||
865 | continue_store_activity (struct StoreActivity *sa) | ||
866 | { | ||
867 | const struct RecordStoreMessage *rp_msg = sa->rsm; | ||
868 | |||
869 | for (struct ZoneMonitor *zm = sa->zm_pos; | ||
870 | NULL != zm; | ||
871 | zm = sa->zm_pos) | ||
872 | { | ||
873 | if ( (0 != memcmp (&rp_msg->private_key, | ||
874 | &zm->zone, | ||
875 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) && | ||
876 | (0 != memcmp (&zm->zone, | ||
877 | &zero, | ||
878 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ) | ||
879 | sa->zm_pos = zm->next; /* not interesting to this monitor */ | ||
880 | if (zm->limit == zm->iteration_cnt) | ||
881 | { | ||
882 | zm->sa_waiting = GNUNET_YES; | ||
883 | zm->sa_waiting_start = GNUNET_TIME_absolute_get (); | ||
884 | if (NULL != zm->sa_wait_warning) | ||
885 | GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); | ||
886 | zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, | ||
887 | &warn_monitor_slow, | ||
888 | zm); | ||
889 | return; /* blocked on zone monitor */ | ||
890 | } | ||
891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
892 | "Notifying monitor about changes under label `%s'\n", | ||
893 | sa->conv_name); | ||
894 | zm->limit--; | ||
895 | send_lookup_response (zm->nc, | ||
896 | 0, | ||
897 | &rp_msg->private_key, | ||
898 | sa->conv_name, | ||
899 | sa->rd_count, | ||
900 | sa->rd); | ||
901 | sa->zm_pos = zm->next; | ||
902 | } | ||
903 | /* great, done with the monitors, unpack (again) for refresh_block operation */ | ||
904 | { | ||
905 | size_t name_len; | ||
906 | size_t rd_ser_len; | ||
907 | uint32_t rid; | ||
908 | const char *name_tmp; | ||
909 | const char *rd_ser; | ||
910 | unsigned int rd_count; | ||
911 | |||
912 | rid = ntohl (rp_msg->gns_header.r_id); | ||
913 | name_len = ntohs (rp_msg->name_len); | ||
914 | rd_count = ntohs (rp_msg->rd_count); | ||
915 | rd_ser_len = ntohs (rp_msg->rd_len); | ||
916 | name_tmp = (const char *) &rp_msg[1]; | ||
917 | rd_ser = &name_tmp[name_len]; | ||
918 | { | ||
919 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | ||
920 | |||
921 | /* We did this before, must succeed again */ | ||
922 | GNUNET_assert (GNUNET_OK == | ||
923 | GNUNET_GNSRECORD_records_deserialize (rd_ser_len, | ||
924 | rd_ser, | ||
925 | rd_count, | ||
926 | rd)); | ||
927 | refresh_block (sa->nc, | ||
928 | rid, | ||
929 | &rp_msg->private_key, | ||
930 | sa->conv_name, | ||
931 | rd_count, | ||
932 | rd); | ||
933 | } | ||
934 | } | ||
935 | GNUNET_SERVICE_client_continue (sa->nc->client); | ||
936 | free_store_activity (sa); | ||
937 | } | ||
938 | |||
939 | |||
940 | /** | ||
941 | * Called whenever a client is disconnected. | ||
942 | * Frees our resources associated with that client. | ||
943 | * | ||
944 | * @param cls closure | ||
945 | * @param client identification of the client | ||
946 | * @param app_ctx the `struct NamestoreClient` of @a client | ||
947 | */ | ||
948 | static void | ||
949 | client_disconnect_cb (void *cls, | ||
950 | struct GNUNET_SERVICE_Client *client, | ||
951 | void *app_ctx) | ||
952 | { | ||
953 | struct NamestoreClient *nc = app_ctx; | ||
954 | struct ZoneIteration *no; | ||
955 | struct CacheOperation *cop; | ||
956 | |||
957 | (void) cls; | ||
958 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
959 | "Client %p disconnected\n", | ||
960 | client); | ||
961 | for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next) | ||
962 | { | ||
963 | struct StoreActivity *san; | ||
964 | |||
965 | if (nc != zm->nc) | ||
966 | continue; | ||
967 | GNUNET_CONTAINER_DLL_remove (monitor_head, | ||
968 | monitor_tail, | ||
969 | zm); | ||
970 | if (NULL != zm->task) | ||
971 | { | ||
972 | GNUNET_SCHEDULER_cancel (zm->task); | ||
973 | zm->task = NULL; | ||
974 | } | ||
975 | if (NULL != zm->sa_wait_warning) | ||
976 | { | ||
977 | GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); | ||
978 | zm->sa_wait_warning = NULL; | ||
979 | } | ||
980 | for (struct StoreActivity *sa = sa_head; NULL != sa; sa = san) | ||
981 | { | ||
982 | san = sa->next; | ||
983 | if (zm == sa->zm_pos) | ||
984 | { | ||
985 | sa->zm_pos = zm->next; | ||
986 | /* this may free sa */ | ||
987 | continue_store_activity (sa); | ||
988 | } | ||
989 | } | ||
990 | GNUNET_free (zm); | ||
991 | break; | ||
992 | } | ||
993 | for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next) | ||
994 | { | ||
995 | if (sa->nc == nc) | ||
996 | { | ||
997 | /* this may free sa */ | ||
998 | free_store_activity (sa); | ||
999 | break; /* there can only be one per nc */ | ||
1000 | } | ||
1001 | } | ||
1002 | while (NULL != (no = nc->op_head)) | ||
1003 | { | ||
1004 | GNUNET_CONTAINER_DLL_remove (nc->op_head, | ||
1005 | nc->op_tail, | ||
1006 | no); | ||
1007 | GNUNET_free (no); | ||
1008 | } | ||
1009 | for (cop = cop_head; NULL != cop; cop = cop->next) | ||
1010 | if (nc == cop->nc) | ||
1011 | cop->nc = NULL; | ||
1012 | GNUNET_free (nc); | ||
1013 | } | ||
1014 | |||
1015 | |||
1016 | /** | ||
1017 | * Add a client to our list of active clients. | ||
1018 | * | ||
1019 | * @param cls NULL | ||
1020 | * @param client client to add | ||
1021 | * @param mq message queue for @a client | ||
1022 | * @return internal namestore client structure for this client | ||
1023 | */ | ||
1024 | static void * | ||
1025 | client_connect_cb (void *cls, | ||
1026 | struct GNUNET_SERVICE_Client *client, | ||
1027 | struct GNUNET_MQ_Handle *mq) | ||
1028 | { | ||
1029 | struct NamestoreClient *nc; | ||
1030 | |||
1031 | (void) cls; | ||
1032 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1033 | "Client %p connected\n", | ||
1034 | client); | ||
1035 | nc = GNUNET_new (struct NamestoreClient); | ||
1036 | nc->client = client; | ||
1037 | nc->mq = mq; | ||
1038 | return nc; | ||
1039 | } | ||
1040 | |||
1041 | |||
1042 | /** | ||
798 | * Closure for #lookup_it(). | 1043 | * Closure for #lookup_it(). |
799 | */ | 1044 | */ |
800 | struct RecordLookupContext | 1045 | struct RecordLookupContext |
@@ -1073,7 +1318,7 @@ handle_record_store (void *cls, | |||
1073 | const char *rd_ser; | 1318 | const char *rd_ser; |
1074 | unsigned int rd_count; | 1319 | unsigned int rd_count; |
1075 | int res; | 1320 | int res; |
1076 | struct ZoneMonitor *zm; | 1321 | struct StoreActivity *sa; |
1077 | 1322 | ||
1078 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1079 | "Received NAMESTORE_RECORD_STORE message\n"); | 1324 | "Received NAMESTORE_RECORD_STORE message\n"); |
@@ -1085,7 +1330,9 @@ handle_record_store (void *cls, | |||
1085 | name_tmp = (const char *) &rp_msg[1]; | 1330 | name_tmp = (const char *) &rp_msg[1]; |
1086 | rd_ser = &name_tmp[name_len]; | 1331 | rd_ser = &name_tmp[name_len]; |
1087 | { | 1332 | { |
1088 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 1333 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; |
1334 | struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)]; | ||
1335 | unsigned int rd_clean_off; | ||
1089 | 1336 | ||
1090 | if (GNUNET_OK != | 1337 | if (GNUNET_OK != |
1091 | GNUNET_GNSRECORD_records_deserialize (rd_ser_len, | 1338 | GNUNET_GNSRECORD_records_deserialize (rd_ser_len, |
@@ -1108,6 +1355,10 @@ handle_record_store (void *cls, | |||
1108 | GNUNET_SERVICE_client_drop (nc->client); | 1355 | GNUNET_SERVICE_client_drop (nc->client); |
1109 | return; | 1356 | return; |
1110 | } | 1357 | } |
1358 | GNUNET_STATISTICS_update (statistics, | ||
1359 | "Well-formed store requests received", | ||
1360 | 1, | ||
1361 | GNUNET_NO); | ||
1111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1112 | "Creating %u records for name `%s'\n", | 1363 | "Creating %u records for name `%s'\n", |
1113 | (unsigned int) rd_count, | 1364 | (unsigned int) rd_count, |
@@ -1128,9 +1379,6 @@ handle_record_store (void *cls, | |||
1128 | } | 1379 | } |
1129 | else | 1380 | else |
1130 | { | 1381 | { |
1131 | struct GNUNET_GNSRECORD_Data rd_clean[rd_count]; | ||
1132 | unsigned int rd_clean_off; | ||
1133 | |||
1134 | /* remove "NICK" records, unless this is for the | 1382 | /* remove "NICK" records, unless this is for the |
1135 | #GNUNET_GNS_EMPTY_LABEL_AT label */ | 1383 | #GNUNET_GNS_EMPTY_LABEL_AT label */ |
1136 | rd_clean_off = 0; | 1384 | rd_clean_off = 0; |
@@ -1147,59 +1395,39 @@ handle_record_store (void *cls, | |||
1147 | conv_name, | 1395 | conv_name, |
1148 | rd_clean_off, | 1396 | rd_clean_off, |
1149 | rd_clean); | 1397 | rd_clean); |
1150 | if (GNUNET_OK == res) | ||
1151 | { | ||
1152 | for (zm = monitor_head; NULL != zm; zm = zm->next) | ||
1153 | { | ||
1154 | if ( (0 == memcmp (&rp_msg->private_key, | ||
1155 | &zm->zone, | ||
1156 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) || | ||
1157 | (0 == memcmp (&zm->zone, | ||
1158 | &zero, | ||
1159 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ) | ||
1160 | { | ||
1161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1162 | "Notifying monitor about changes under label `%s'\n", | ||
1163 | conv_name); | ||
1164 | send_lookup_response (zm->nc, | ||
1165 | 0, | ||
1166 | &rp_msg->private_key, | ||
1167 | conv_name, | ||
1168 | rd_count, rd); | ||
1169 | } | ||
1170 | else | ||
1171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1172 | "Monitor is for another zone\n"); | ||
1173 | } | ||
1174 | if (NULL == monitor_head) | ||
1175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1176 | "No monitors active\n"); | ||
1177 | } | ||
1178 | else | ||
1179 | { | ||
1180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1181 | "Error storing record: %d\n", | ||
1182 | res); | ||
1183 | } | ||
1184 | } | 1398 | } |
1185 | if (GNUNET_OK == res) | 1399 | |
1400 | if (GNUNET_OK != res) | ||
1186 | { | 1401 | { |
1187 | refresh_block (nc, | 1402 | /* store not successful, not need to tell monitors */ |
1188 | rid, | 1403 | send_store_response (nc, |
1189 | &rp_msg->private_key, | 1404 | res, |
1190 | conv_name, | 1405 | rid); |
1191 | rd_count, | ||
1192 | rd); | ||
1193 | GNUNET_SERVICE_client_continue (nc->client); | 1406 | GNUNET_SERVICE_client_continue (nc->client); |
1194 | GNUNET_free (conv_name); | 1407 | GNUNET_free (conv_name); |
1195 | return; | 1408 | return; |
1196 | } | 1409 | } |
1197 | GNUNET_free (conv_name); | 1410 | |
1411 | sa = GNUNET_malloc (sizeof (struct StoreActivity) + | ||
1412 | ntohs (rp_msg->gns_header.header.size)); | ||
1413 | GNUNET_CONTAINER_DLL_insert (sa_head, | ||
1414 | sa_tail, | ||
1415 | sa); | ||
1416 | sa->nc = nc; | ||
1417 | sa->rsm = (const struct RecordStoreMessage *) &sa[1]; | ||
1418 | GNUNET_memcpy (&sa[1], | ||
1419 | rp_msg, | ||
1420 | ntohs (rp_msg->gns_header.header.size)); | ||
1421 | sa->zm_pos = monitor_head; | ||
1422 | sa->conv_name = conv_name; | ||
1423 | GNUNET_array_grow (sa->rd, | ||
1424 | sa->rd_count, | ||
1425 | rd_clean_off); | ||
1426 | GNUNET_memcpy (sa->rd, | ||
1427 | rd_clean, | ||
1428 | sizeof (struct GNUNET_GNSRECORD_Data) * rd_clean_off); | ||
1429 | continue_store_activity (sa); | ||
1198 | } | 1430 | } |
1199 | send_store_response (nc, | ||
1200 | res, | ||
1201 | rid); | ||
1202 | GNUNET_SERVICE_client_continue (nc->client); | ||
1203 | } | 1431 | } |
1204 | 1432 | ||
1205 | 1433 | ||
@@ -1311,8 +1539,7 @@ handle_zone_to_name (void *cls, | |||
1311 | struct ZoneToNameResponseMessage *ztnr_msg; | 1539 | struct ZoneToNameResponseMessage *ztnr_msg; |
1312 | 1540 | ||
1313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1541 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1314 | "Received `%s' message\n", | 1542 | "Received ZONE_TO_NAME message\n"); |
1315 | "ZONE_TO_NAME"); | ||
1316 | ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); | 1543 | ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); |
1317 | ztn_ctx.nc = nc; | 1544 | ztn_ctx.nc = nc; |
1318 | ztn_ctx.success = GNUNET_NO; | 1545 | ztn_ctx.success = GNUNET_NO; |
@@ -1601,6 +1828,46 @@ handle_iteration_next (void *cls, | |||
1601 | 1828 | ||
1602 | 1829 | ||
1603 | /** | 1830 | /** |
1831 | * Function called when the monitor is ready for more data, and we | ||
1832 | * should thus unblock PUT operations that were blocked on the | ||
1833 | * monitor not being ready. | ||
1834 | */ | ||
1835 | static void | ||
1836 | monitor_unblock (struct ZoneMonitor *zm) | ||
1837 | { | ||
1838 | struct StoreActivity *sa = sa_head; | ||
1839 | |||
1840 | while ( (NULL != sa) && | ||
1841 | (zm->limit > zm->iteration_cnt) ) | ||
1842 | { | ||
1843 | struct StoreActivity *sn = sa->next; | ||
1844 | |||
1845 | if (sa->zm_pos == zm) | ||
1846 | continue_store_activity (sa); | ||
1847 | sa = sn; | ||
1848 | } | ||
1849 | if (zm->limit > zm->iteration_cnt) | ||
1850 | { | ||
1851 | zm->sa_waiting = GNUNET_NO; | ||
1852 | if (NULL != zm->sa_wait_warning) | ||
1853 | { | ||
1854 | GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); | ||
1855 | zm->sa_wait_warning = NULL; | ||
1856 | } | ||
1857 | } | ||
1858 | else if (GNUNET_YES == zm->sa_waiting) | ||
1859 | { | ||
1860 | zm->sa_waiting_start = GNUNET_TIME_absolute_get (); | ||
1861 | if (NULL != zm->sa_wait_warning) | ||
1862 | GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); | ||
1863 | zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, | ||
1864 | &warn_monitor_slow, | ||
1865 | zm); | ||
1866 | } | ||
1867 | } | ||
1868 | |||
1869 | |||
1870 | /** | ||
1604 | * Send 'sync' message to zone monitor, we're now in sync. | 1871 | * Send 'sync' message to zone monitor, we're now in sync. |
1605 | * | 1872 | * |
1606 | * @param zm monitor that is now in sync | 1873 | * @param zm monitor that is now in sync |
@@ -1615,16 +1882,22 @@ monitor_sync (struct ZoneMonitor *zm) | |||
1615 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC); | 1882 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC); |
1616 | GNUNET_MQ_send (zm->nc->mq, | 1883 | GNUNET_MQ_send (zm->nc->mq, |
1617 | env); | 1884 | env); |
1885 | /* mark iteration done */ | ||
1886 | zm->in_first_iteration = GNUNET_NO; | ||
1887 | zm->iteration_cnt = 0; | ||
1888 | if ( (zm->limit > 0) && | ||
1889 | (zm->sa_waiting) ) | ||
1890 | monitor_unblock (zm); | ||
1618 | } | 1891 | } |
1619 | 1892 | ||
1620 | 1893 | ||
1621 | /** | 1894 | /** |
1622 | * Obtain the next datum during the zone monitor's zone intiial iteration. | 1895 | * Obtain the next datum during the zone monitor's zone initial iteration. |
1623 | * | 1896 | * |
1624 | * @param cls zone monitor that does its initial iteration | 1897 | * @param cls zone monitor that does its initial iteration |
1625 | */ | 1898 | */ |
1626 | static void | 1899 | static void |
1627 | monitor_next (void *cls); | 1900 | monitor_iteration_next (void *cls); |
1628 | 1901 | ||
1629 | 1902 | ||
1630 | /** | 1903 | /** |
@@ -1658,14 +1931,23 @@ monitor_iterate_cb (void *cls, | |||
1658 | "Monitor notifications sent", | 1931 | "Monitor notifications sent", |
1659 | 1, | 1932 | 1, |
1660 | GNUNET_NO); | 1933 | GNUNET_NO); |
1934 | zm->limit--; | ||
1935 | zm->iteration_cnt--; | ||
1661 | send_lookup_response (zm->nc, | 1936 | send_lookup_response (zm->nc, |
1662 | 0, | 1937 | 0, |
1663 | zone_key, | 1938 | zone_key, |
1664 | name, | 1939 | name, |
1665 | rd_count, | 1940 | rd_count, |
1666 | rd); | 1941 | rd); |
1667 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, | 1942 | if ( (0 == zm->iteration_cnt) && |
1668 | zm); | 1943 | (0 != zm->limit) ) |
1944 | { | ||
1945 | /* We are done with the current iteration batch, AND the | ||
1946 | client would right now accept more, so go again! */ | ||
1947 | GNUNET_assert (NULL == zm->task); | ||
1948 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next, | ||
1949 | zm); | ||
1950 | } | ||
1669 | } | 1951 | } |
1670 | 1952 | ||
1671 | 1953 | ||
@@ -1687,6 +1969,8 @@ handle_monitor_start (void *cls, | |||
1687 | zm = GNUNET_new (struct ZoneMonitor); | 1969 | zm = GNUNET_new (struct ZoneMonitor); |
1688 | zm->nc = nc; | 1970 | zm->nc = nc; |
1689 | zm->zone = zis_msg->zone; | 1971 | zm->zone = zis_msg->zone; |
1972 | zm->limit = 1; | ||
1973 | zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first)); | ||
1690 | GNUNET_CONTAINER_DLL_insert (monitor_head, | 1974 | GNUNET_CONTAINER_DLL_insert (monitor_head, |
1691 | monitor_tail, | 1975 | monitor_tail, |
1692 | zm); | 1976 | zm); |
@@ -1694,8 +1978,8 @@ handle_monitor_start (void *cls, | |||
1694 | GNUNET_SERVICE_client_continue (nc->client); | 1978 | GNUNET_SERVICE_client_continue (nc->client); |
1695 | GNUNET_notification_context_add (monitor_nc, | 1979 | GNUNET_notification_context_add (monitor_nc, |
1696 | nc->mq); | 1980 | nc->mq); |
1697 | if (GNUNET_YES == ntohl (zis_msg->iterate_first)) | 1981 | if (zm->in_first_iteration) |
1698 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, | 1982 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next, |
1699 | zm); | 1983 | zm); |
1700 | else | 1984 | else |
1701 | monitor_sync (zm); | 1985 | monitor_sync (zm); |
@@ -1708,12 +1992,17 @@ handle_monitor_start (void *cls, | |||
1708 | * @param cls zone monitor that does its initial iteration | 1992 | * @param cls zone monitor that does its initial iteration |
1709 | */ | 1993 | */ |
1710 | static void | 1994 | static void |
1711 | monitor_next (void *cls) | 1995 | monitor_iteration_next (void *cls) |
1712 | { | 1996 | { |
1713 | struct ZoneMonitor *zm = cls; | 1997 | struct ZoneMonitor *zm = cls; |
1714 | int ret; | 1998 | int ret; |
1715 | 1999 | ||
1716 | zm->task = NULL; | 2000 | zm->task = NULL; |
2001 | GNUNET_assert (0 == zm->iteration_cnt); | ||
2002 | if (zm->limit > 16) | ||
2003 | zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */ | ||
2004 | else | ||
2005 | zm->iteration_cnt = zm->limit; /* use it all */ | ||
1717 | ret = GSN_database->iterate_records (GSN_database->cls, | 2006 | ret = GSN_database->iterate_records (GSN_database->cls, |
1718 | (0 == memcmp (&zm->zone, | 2007 | (0 == memcmp (&zm->zone, |
1719 | &zero, | 2008 | &zero, |
@@ -1721,7 +2010,7 @@ monitor_next (void *cls) | |||
1721 | ? NULL | 2010 | ? NULL |
1722 | : &zm->zone, | 2011 | : &zm->zone, |
1723 | zm->seq, | 2012 | zm->seq, |
1724 | 1, | 2013 | zm->iteration_cnt, |
1725 | &monitor_iterate_cb, | 2014 | &monitor_iterate_cb, |
1726 | zm); | 2015 | zm); |
1727 | if (GNUNET_SYSERR == ret) | 2016 | if (GNUNET_SYSERR == ret) |
@@ -1773,13 +2062,30 @@ handle_monitor_next (void *cls, | |||
1773 | return; | 2062 | return; |
1774 | } | 2063 | } |
1775 | zm->limit += inc; | 2064 | zm->limit += inc; |
1776 | #if 0 | 2065 | if ( (zm->in_first_iteration) && |
1777 | if (GNUNET_YES == ntohl (zis_msg->iterate_first)) | 2066 | (zm->limit == inc) ) |
1778 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, | 2067 | { |
1779 | zm); | 2068 | /* We are still iterating, and the previous iteration must |
1780 | else | 2069 | have stopped due to the client's limit, so continue it! */ |
1781 | monitor_sync (zm); | 2070 | GNUNET_assert (NULL == zm->task); |
1782 | #endif | 2071 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next, |
2072 | zm); | ||
2073 | } | ||
2074 | GNUNET_assert (zm->iteration_cnt <= zm->limit); | ||
2075 | if ( (zm->limit > zm->iteration_cnt) && | ||
2076 | (zm->sa_waiting) ) | ||
2077 | { | ||
2078 | monitor_unblock (zm); | ||
2079 | } | ||
2080 | else if (GNUNET_YES == zm->sa_waiting) | ||
2081 | { | ||
2082 | if (NULL != zm->sa_wait_warning) | ||
2083 | GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); | ||
2084 | zm->sa_waiting_start = GNUNET_TIME_absolute_get (); | ||
2085 | zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, | ||
2086 | &warn_monitor_slow, | ||
2087 | zm); | ||
2088 | } | ||
1783 | } | 2089 | } |
1784 | 2090 | ||
1785 | 2091 | ||
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c index 0fd0a4ab8..b394178a6 100644 --- a/src/namestore/gnunet-zoneimport.c +++ b/src/namestore/gnunet-zoneimport.c | |||
@@ -59,6 +59,11 @@ | |||
59 | #define SERIES_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10) | 59 | #define SERIES_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10) |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * How long do DNS records have to last at least after being imported? | ||
63 | */ | ||
64 | static struct GNUNET_TIME_Relative minimum_expiration_time; | ||
65 | |||
66 | /** | ||
62 | * How many requests do we request from NAMESTORE in one batch | 67 | * How many requests do we request from NAMESTORE in one batch |
63 | * during our initial iteration? | 68 | * during our initial iteration? |
64 | */ | 69 | */ |
@@ -429,9 +434,9 @@ get_label (struct Request *req) | |||
429 | GNUNET_break (0); | 434 | GNUNET_break (0); |
430 | return NULL; | 435 | return NULL; |
431 | } | 436 | } |
432 | memcpy (label, | 437 | GNUNET_memcpy (label, |
433 | req->hostname, | 438 | req->hostname, |
434 | dot - req->hostname); | 439 | dot - req->hostname); |
435 | label[dot - req->hostname] = '\0'; | 440 | label[dot - req->hostname] = '\0'; |
436 | return label; | 441 | return label; |
437 | } | 442 | } |
@@ -486,9 +491,9 @@ build_dns_query (struct Request *req, | |||
486 | GNUNET_free (rawp); | 491 | GNUNET_free (rawp); |
487 | return NULL; | 492 | return NULL; |
488 | } | 493 | } |
489 | memcpy (raw, | 494 | GNUNET_memcpy (raw, |
490 | rawp, | 495 | rawp, |
491 | *raw_size); | 496 | *raw_size); |
492 | GNUNET_free (rawp); | 497 | GNUNET_free (rawp); |
493 | return raw; | 498 | return raw; |
494 | } | 499 | } |
@@ -632,10 +637,19 @@ check_for_glue (void *cls, | |||
632 | size_t off; | 637 | size_t off; |
633 | char ip[INET6_ADDRSTRLEN+1]; | 638 | char ip[INET6_ADDRSTRLEN+1]; |
634 | socklen_t ip_size = (socklen_t) sizeof (ip); | 639 | socklen_t ip_size = (socklen_t) sizeof (ip); |
640 | struct GNUNET_TIME_Absolute expiration_time; | ||
641 | struct GNUNET_TIME_Relative left; | ||
635 | 642 | ||
636 | if (0 != strcasecmp (rec->name, | 643 | if (0 != strcasecmp (rec->name, |
637 | gc->ns)) | 644 | gc->ns)) |
638 | return; | 645 | return; |
646 | expiration_time = rec->expiration_time; | ||
647 | left = GNUNET_TIME_absolute_get_remaining (expiration_time); | ||
648 | if (0 == left.rel_value_us) | ||
649 | return; /* ignore expired glue records */ | ||
650 | /* if expiration window is too short, bump it to configured minimum */ | ||
651 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) | ||
652 | expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time); | ||
639 | dst_len = sizeof (dst); | 653 | dst_len = sizeof (dst); |
640 | off = 0; | 654 | off = 0; |
641 | switch (rec->type) | 655 | switch (rec->type) |
@@ -668,7 +682,7 @@ check_for_glue (void *cls, | |||
668 | { | 682 | { |
669 | add_record (gc->req, | 683 | add_record (gc->req, |
670 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 684 | GNUNET_GNSRECORD_TYPE_GNS2DNS, |
671 | rec->expiration_time, | 685 | expiration_time, |
672 | dst, | 686 | dst, |
673 | off); | 687 | off); |
674 | gc->found = GNUNET_YES; | 688 | gc->found = GNUNET_YES; |
@@ -702,7 +716,7 @@ check_for_glue (void *cls, | |||
702 | { | 716 | { |
703 | add_record (gc->req, | 717 | add_record (gc->req, |
704 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 718 | GNUNET_GNSRECORD_TYPE_GNS2DNS, |
705 | rec->expiration_time, | 719 | expiration_time, |
706 | dst, | 720 | dst, |
707 | off); | 721 | off); |
708 | gc->found = GNUNET_YES; | 722 | gc->found = GNUNET_YES; |
@@ -722,7 +736,7 @@ check_for_glue (void *cls, | |||
722 | { | 736 | { |
723 | add_record (gc->req, | 737 | add_record (gc->req, |
724 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 738 | GNUNET_GNSRECORD_TYPE_GNS2DNS, |
725 | rec->expiration_time, | 739 | expiration_time, |
726 | dst, | 740 | dst, |
727 | off); | 741 | off); |
728 | gc->found = GNUNET_YES; | 742 | gc->found = GNUNET_YES; |
@@ -768,6 +782,8 @@ process_record (void *cls, | |||
768 | char dst[65536]; | 782 | char dst[65536]; |
769 | size_t dst_len; | 783 | size_t dst_len; |
770 | size_t off; | 784 | size_t off; |
785 | struct GNUNET_TIME_Absolute expiration_time; | ||
786 | struct GNUNET_TIME_Relative left; | ||
771 | 787 | ||
772 | dst_len = sizeof (dst); | 788 | dst_len = sizeof (dst); |
773 | off = 0; | 789 | off = 0; |
@@ -783,18 +799,27 @@ process_record (void *cls, | |||
783 | return; /* does not match hostname, might be glue, but | 799 | return; /* does not match hostname, might be glue, but |
784 | not useful for this pass! */ | 800 | not useful for this pass! */ |
785 | } | 801 | } |
786 | if (0 == | 802 | expiration_time = rec->expiration_time; |
787 | GNUNET_TIME_absolute_get_remaining (rec->expiration_time).rel_value_us) | 803 | left = GNUNET_TIME_absolute_get_remaining (expiration_time); |
804 | if (0 == left.rel_value_us) | ||
788 | { | 805 | { |
789 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
790 | "DNS returned expired record for `%s'\n", | 807 | "DNS returned expired record for `%s'\n", |
791 | req->hostname); | 808 | req->hostname); |
809 | GNUNET_STATISTICS_update (stats, | ||
810 | "# expired records obtained from DNS", | ||
811 | 1, | ||
812 | GNUNET_NO); | ||
792 | return; /* record expired */ | 813 | return; /* record expired */ |
793 | } | 814 | } |
815 | |||
794 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 816 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
795 | "DNS returned record that expires at %s for `%s'\n", | 817 | "DNS returned record that expires at %s for `%s'\n", |
796 | GNUNET_STRINGS_absolute_time_to_string (rec->expiration_time), | 818 | GNUNET_STRINGS_absolute_time_to_string (expiration_time), |
797 | req->hostname); | 819 | req->hostname); |
820 | /* if expiration window is too short, bump it to configured minimum */ | ||
821 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) | ||
822 | expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time); | ||
798 | switch (rec->type) | 823 | switch (rec->type) |
799 | { | 824 | { |
800 | case GNUNET_DNSPARSER_TYPE_NS: | 825 | case GNUNET_DNSPARSER_TYPE_NS: |
@@ -828,7 +853,7 @@ process_record (void *cls, | |||
828 | rec->name); | 853 | rec->name); |
829 | add_record (req, | 854 | add_record (req, |
830 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 855 | GNUNET_GNSRECORD_TYPE_GNS2DNS, |
831 | rec->expiration_time, | 856 | expiration_time, |
832 | dst, | 857 | dst, |
833 | off); | 858 | off); |
834 | } | 859 | } |
@@ -853,7 +878,7 @@ process_record (void *cls, | |||
853 | rec->name); | 878 | rec->name); |
854 | add_record (req, | 879 | add_record (req, |
855 | rec->type, | 880 | rec->type, |
856 | rec->expiration_time, | 881 | expiration_time, |
857 | dst, | 882 | dst, |
858 | off); | 883 | off); |
859 | } | 884 | } |
@@ -878,7 +903,7 @@ process_record (void *cls, | |||
878 | rec->name); | 903 | rec->name); |
879 | add_record (req, | 904 | add_record (req, |
880 | rec->type, | 905 | rec->type, |
881 | rec->expiration_time, | 906 | expiration_time, |
882 | dst, | 907 | dst, |
883 | off); | 908 | off); |
884 | } | 909 | } |
@@ -896,7 +921,7 @@ process_record (void *cls, | |||
896 | rec->name); | 921 | rec->name); |
897 | add_record (req, | 922 | add_record (req, |
898 | rec->type, | 923 | rec->type, |
899 | rec->expiration_time, | 924 | expiration_time, |
900 | dst, | 925 | dst, |
901 | off); | 926 | off); |
902 | } | 927 | } |
@@ -913,7 +938,7 @@ process_record (void *cls, | |||
913 | rec->name); | 938 | rec->name); |
914 | add_record (req, | 939 | add_record (req, |
915 | rec->type, | 940 | rec->type, |
916 | rec->expiration_time, | 941 | expiration_time, |
917 | dst, | 942 | dst, |
918 | off); | 943 | off); |
919 | } | 944 | } |
@@ -931,7 +956,7 @@ process_record (void *cls, | |||
931 | rec->name); | 956 | rec->name); |
932 | add_record (req, | 957 | add_record (req, |
933 | rec->type, | 958 | rec->type, |
934 | rec->expiration_time, | 959 | expiration_time, |
935 | dst, | 960 | dst, |
936 | off); | 961 | off); |
937 | } | 962 | } |
@@ -948,7 +973,7 @@ process_record (void *cls, | |||
948 | rec->name); | 973 | rec->name); |
949 | add_record (req, | 974 | add_record (req, |
950 | rec->type, | 975 | rec->type, |
951 | rec->expiration_time, | 976 | expiration_time, |
952 | dst, | 977 | dst, |
953 | off); | 978 | off); |
954 | } | 979 | } |
@@ -966,7 +991,7 @@ process_record (void *cls, | |||
966 | rec->name); | 991 | rec->name); |
967 | add_record (req, | 992 | add_record (req, |
968 | rec->type, | 993 | rec->type, |
969 | rec->expiration_time, | 994 | expiration_time, |
970 | rec->data.raw.data, | 995 | rec->data.raw.data, |
971 | rec->data.raw.data_len); | 996 | rec->data.raw.data_len); |
972 | break; | 997 | break; |
@@ -1551,7 +1576,17 @@ ns_lookup_result_cb (void *cls, | |||
1551 | { | 1576 | { |
1552 | struct GNUNET_TIME_Absolute at; | 1577 | struct GNUNET_TIME_Absolute at; |
1553 | 1578 | ||
1554 | at.abs_value_us = rd->expiration_time; | 1579 | if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) |
1580 | { | ||
1581 | struct GNUNET_TIME_Relative rel; | ||
1582 | |||
1583 | rel.rel_value_us = rd->expiration_time; | ||
1584 | at = GNUNET_TIME_relative_to_absolute (rel); | ||
1585 | } | ||
1586 | else | ||
1587 | { | ||
1588 | at.abs_value_us = rd->expiration_time; | ||
1589 | } | ||
1555 | add_record (req, | 1590 | add_record (req, |
1556 | rd->record_type, | 1591 | rd->record_type, |
1557 | at, | 1592 | at, |
@@ -1648,9 +1683,9 @@ queue (const char *hostname) | |||
1648 | req = GNUNET_malloc (sizeof (struct Request) + hlen); | 1683 | req = GNUNET_malloc (sizeof (struct Request) + hlen); |
1649 | req->zone = zone; | 1684 | req->zone = zone; |
1650 | req->hostname = (char *) &req[1]; | 1685 | req->hostname = (char *) &req[1]; |
1651 | memcpy (req->hostname, | 1686 | GNUNET_memcpy (req->hostname, |
1652 | hostname, | 1687 | hostname, |
1653 | hlen); | 1688 | hlen); |
1654 | req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 1689 | req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
1655 | UINT16_MAX); | 1690 | UINT16_MAX); |
1656 | GNUNET_CRYPTO_hash (req->hostname, | 1691 | GNUNET_CRYPTO_hash (req->hostname, |
@@ -1800,14 +1835,14 @@ process_stdin (void *cls) | |||
1800 | if (0 == idot) | 1835 | if (0 == idot) |
1801 | last = GNUNET_TIME_absolute_get (); | 1836 | last = GNUNET_TIME_absolute_get (); |
1802 | idot++; | 1837 | idot++; |
1803 | if (0 == idot % 10000) | 1838 | if (0 == idot % 100000) |
1804 | { | 1839 | { |
1805 | struct GNUNET_TIME_Relative delta; | 1840 | struct GNUNET_TIME_Relative delta; |
1806 | 1841 | ||
1807 | delta = GNUNET_TIME_absolute_get_duration (last); | 1842 | delta = GNUNET_TIME_absolute_get_duration (last); |
1808 | last = GNUNET_TIME_absolute_get (); | 1843 | last = GNUNET_TIME_absolute_get (); |
1809 | fprintf (stderr, | 1844 | fprintf (stderr, |
1810 | "Imported 10000 records in %s\n", | 1845 | "Read 10000 domain names in %s\n", |
1811 | GNUNET_STRINGS_relative_time_to_string (delta, | 1846 | GNUNET_STRINGS_relative_time_to_string (delta, |
1812 | GNUNET_YES)); | 1847 | GNUNET_YES)); |
1813 | GNUNET_STATISTICS_set (stats, | 1848 | GNUNET_STATISTICS_set (stats, |
@@ -1986,6 +2021,11 @@ main (int argc, | |||
1986 | "MAPSIZE", | 2021 | "MAPSIZE", |
1987 | gettext_noop ("size to use for the main hash map"), | 2022 | gettext_noop ("size to use for the main hash map"), |
1988 | &map_size), | 2023 | &map_size), |
2024 | GNUNET_GETOPT_option_relative_time ('m', | ||
2025 | "minimum-expiration", | ||
2026 | "RELATIVETIME", | ||
2027 | gettext_noop ("minimum expiration time we assume for imported records"), | ||
2028 | &minimum_expiration_time), | ||
1989 | GNUNET_GETOPT_OPTION_END | 2029 | GNUNET_GETOPT_OPTION_END |
1990 | }; | 2030 | }; |
1991 | 2031 | ||
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index ab356838b..57bf8f81b 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -40,6 +40,11 @@ | |||
40 | 40 | ||
41 | #define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__) | 41 | #define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__) |
42 | 42 | ||
43 | /** | ||
44 | * We grant the namestore up to 1 minute of latency, if it is slower than | ||
45 | * that, store queries will fail. | ||
46 | */ | ||
47 | #define NAMESTORE_DELAY_TOLERANCE GNUNET_TIME_UNIT_MINUTES | ||
43 | 48 | ||
44 | /** | 49 | /** |
45 | * An QueueEntry used to store information for a pending | 50 | * An QueueEntry used to store information for a pending |
@@ -100,6 +105,11 @@ struct GNUNET_NAMESTORE_QueueEntry | |||
100 | struct GNUNET_MQ_Envelope *env; | 105 | struct GNUNET_MQ_Envelope *env; |
101 | 106 | ||
102 | /** | 107 | /** |
108 | * Task scheduled to warn us if the namestore is way too slow. | ||
109 | */ | ||
110 | struct GNUNET_SCHEDULER_Task *timeout_task; | ||
111 | |||
112 | /** | ||
103 | * The operation id this zone iteration operation has | 113 | * The operation id this zone iteration operation has |
104 | */ | 114 | */ |
105 | uint32_t op_id; | 115 | uint32_t op_id; |
@@ -300,6 +310,8 @@ free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe) | |||
300 | qe); | 310 | qe); |
301 | if (NULL != qe->env) | 311 | if (NULL != qe->env) |
302 | GNUNET_MQ_discard (qe->env); | 312 | GNUNET_MQ_discard (qe->env); |
313 | if (NULL != qe->timeout_task) | ||
314 | GNUNET_SCHEDULER_cancel (qe->timeout_task); | ||
303 | GNUNET_free (qe); | 315 | GNUNET_free (qe); |
304 | } | 316 | } |
305 | 317 | ||
@@ -968,6 +980,33 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h) | |||
968 | 980 | ||
969 | 981 | ||
970 | /** | 982 | /** |
983 | * Task launched to warn the user that the namestore is | ||
984 | * excessively slow and that a query was thus dropped. | ||
985 | * | ||
986 | * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *` | ||
987 | */ | ||
988 | static void | ||
989 | warn_delay (void *cls) | ||
990 | { | ||
991 | struct GNUNET_NAMESTORE_QueueEntry *qe = cls; | ||
992 | |||
993 | qe->timeout_task = NULL; | ||
994 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
995 | "Did not receive response from namestore after %s!\n", | ||
996 | GNUNET_STRINGS_relative_time_to_string (NAMESTORE_DELAY_TOLERANCE, | ||
997 | GNUNET_YES)); | ||
998 | if (NULL != qe->cont) | ||
999 | { | ||
1000 | qe->cont (qe->cont_cls, | ||
1001 | GNUNET_SYSERR, | ||
1002 | "timeout"); | ||
1003 | qe->cont = NULL; | ||
1004 | } | ||
1005 | GNUNET_NAMESTORE_cancel (qe); | ||
1006 | } | ||
1007 | |||
1008 | |||
1009 | /** | ||
971 | * Store an item in the namestore. If the item is already present, | 1010 | * Store an item in the namestore. If the item is already present, |
972 | * it is replaced with the new record. Use an empty array to | 1011 | * it is replaced with the new record. Use an empty array to |
973 | * remove all records under the given name. | 1012 | * remove all records under the given name. |
@@ -1048,12 +1087,20 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
1048 | "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", | 1087 | "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", |
1049 | label, | 1088 | label, |
1050 | rd_count); | 1089 | rd_count); |
1051 | 1090 | qe->timeout_task = GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE, | |
1091 | &warn_delay, | ||
1092 | qe); | ||
1052 | if (NULL == h->mq) | 1093 | if (NULL == h->mq) |
1094 | { | ||
1053 | qe->env = env; | 1095 | qe->env = env; |
1096 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1097 | "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n"); | ||
1098 | } | ||
1054 | else | 1099 | else |
1100 | { | ||
1055 | GNUNET_MQ_send (h->mq, | 1101 | GNUNET_MQ_send (h->mq, |
1056 | env); | 1102 | env); |
1103 | } | ||
1057 | return qe; | 1104 | return qe; |
1058 | } | 1105 | } |
1059 | 1106 | ||
diff --git a/src/namestore/perf_namestore_api_flat.conf b/src/namestore/perf_namestore_api_flat.conf index 26e2f2c51..f356e9061 100644 --- a/src/namestore/perf_namestore_api_flat.conf +++ b/src/namestore/perf_namestore_api_flat.conf | |||
@@ -5,3 +5,6 @@ DATABASE = flat | |||
5 | 5 | ||
6 | [namecache] | 6 | [namecache] |
7 | DISABLE = YES | 7 | DISABLE = YES |
8 | |||
9 | [namestore-flat] | ||
10 | FILENAME = $GNUNET_TEST_HOME/namestore/flat.db | ||
diff --git a/src/namestore/perf_namestore_api_postgres.conf b/src/namestore/perf_namestore_api_postgres.conf index 259ce35e7..16f530252 100644 --- a/src/namestore/perf_namestore_api_postgres.conf +++ b/src/namestore/perf_namestore_api_postgres.conf | |||
@@ -5,3 +5,7 @@ DATABASE = postgres | |||
5 | 5 | ||
6 | [namecache] | 6 | [namecache] |
7 | DISABLE = YES | 7 | DISABLE = YES |
8 | |||
9 | [namestore-postgres] | ||
10 | CONFIG = connect_timeout=10; dbname=gnunetcheck | ||
11 | TEMPORARY_TABLE = YES | ||
diff --git a/src/namestore/perf_namestore_api_sqlite.conf b/src/namestore/perf_namestore_api_sqlite.conf index 72b609226..de0fa3f1f 100644 --- a/src/namestore/perf_namestore_api_sqlite.conf +++ b/src/namestore/perf_namestore_api_sqlite.conf | |||
@@ -2,3 +2,6 @@ | |||
2 | 2 | ||
3 | [namecache] | 3 | [namecache] |
4 | DISABLE = YES | 4 | DISABLE = YES |
5 | |||
6 | [namestore-sqlite] | ||
7 | FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db | ||
diff --git a/src/namestore/perf_namestore_api_zone_iteration.c b/src/namestore/perf_namestore_api_zone_iteration.c index 4ef8d3407..55d6fafa0 100644 --- a/src/namestore/perf_namestore_api_zone_iteration.c +++ b/src/namestore/perf_namestore_api_zone_iteration.c | |||
@@ -69,8 +69,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *qe; | |||
69 | 69 | ||
70 | static int res; | 70 | static int res; |
71 | 71 | ||
72 | static char *directory; | ||
73 | |||
74 | static unsigned int off; | 72 | static unsigned int off; |
75 | 73 | ||
76 | static unsigned int left_until_next; | 74 | static unsigned int left_until_next; |
@@ -333,13 +331,6 @@ run (void *cls, | |||
333 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 331 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
334 | struct GNUNET_TESTING_Peer *peer) | 332 | struct GNUNET_TESTING_Peer *peer) |
335 | { | 333 | { |
336 | directory = NULL; | ||
337 | GNUNET_assert (GNUNET_OK == | ||
338 | GNUNET_CONFIGURATION_get_value_string(cfg, | ||
339 | "PATHS", | ||
340 | "GNUNET_TEST_HOME", | ||
341 | &directory)); | ||
342 | GNUNET_DISK_directory_remove (directory); | ||
343 | GNUNET_SCHEDULER_add_shutdown (&end, | 334 | GNUNET_SCHEDULER_add_shutdown (&end, |
344 | NULL); | 335 | NULL); |
345 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 336 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
@@ -367,6 +358,8 @@ main (int argc, | |||
367 | "perf_namestore_api_%s.conf", | 358 | "perf_namestore_api_%s.conf", |
368 | plugin_name); | 359 | plugin_name); |
369 | res = 1; | 360 | res = 1; |
361 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
362 | "GNUNET_TEST_HOME"); | ||
370 | if (0 != | 363 | if (0 != |
371 | GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration", | 364 | GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration", |
372 | cfg_name, | 365 | cfg_name, |
@@ -375,12 +368,9 @@ main (int argc, | |||
375 | { | 368 | { |
376 | res = 1; | 369 | res = 1; |
377 | } | 370 | } |
371 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
372 | "GNUNET_TEST_HOME"); | ||
378 | GNUNET_free (cfg_name); | 373 | GNUNET_free (cfg_name); |
379 | if (NULL != directory) | ||
380 | { | ||
381 | GNUNET_DISK_directory_remove (directory); | ||
382 | GNUNET_free (directory); | ||
383 | } | ||
384 | return res; | 374 | return res; |
385 | } | 375 | } |
386 | 376 | ||
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c index bbb9e3c62..35d8424b4 100644 --- a/src/namestore/plugin_namestore_flat.c +++ b/src/namestore/plugin_namestore_flat.c | |||
@@ -49,41 +49,6 @@ struct Plugin | |||
49 | */ | 49 | */ |
50 | struct GNUNET_CONTAINER_MultiHashMap *hm; | 50 | struct GNUNET_CONTAINER_MultiHashMap *hm; |
51 | 51 | ||
52 | /** | ||
53 | * Offset | ||
54 | */ | ||
55 | uint32_t offset; | ||
56 | |||
57 | /** | ||
58 | * Target Offset | ||
59 | */ | ||
60 | uint32_t target_offset; | ||
61 | |||
62 | /** | ||
63 | * Iterator closure | ||
64 | */ | ||
65 | void *iter_cls; | ||
66 | |||
67 | /** | ||
68 | * Iterator | ||
69 | */ | ||
70 | GNUNET_NAMESTORE_RecordIterator iter; | ||
71 | |||
72 | /** | ||
73 | * Zone to iterate | ||
74 | */ | ||
75 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *iter_zone; | ||
76 | |||
77 | /** | ||
78 | * PKEY to look for in zone to name | ||
79 | */ | ||
80 | const struct GNUNET_CRYPTO_EcdsaPublicKey *iter_pkey; | ||
81 | |||
82 | /** | ||
83 | * Iteration result found | ||
84 | */ | ||
85 | int iter_result_found; | ||
86 | |||
87 | }; | 52 | }; |
88 | 53 | ||
89 | 54 | ||
@@ -364,10 +329,10 @@ store_and_free_entries (void *cls, | |||
364 | &record_data_b64); | 329 | &record_data_b64); |
365 | } | 330 | } |
366 | GNUNET_asprintf (&line, | 331 | GNUNET_asprintf (&line, |
367 | "%s,%lu,%u,%s,%s\n", | 332 | "%s,%llu,%u,%s,%s\n", |
368 | zone_private_key, | 333 | zone_private_key, |
369 | entry->rvalue, | 334 | (unsigned long long) entry->rvalue, |
370 | entry->record_count, | 335 | (unsigned int) entry->record_count, |
371 | record_data_b64, | 336 | record_data_b64, |
372 | entry->label); | 337 | entry->label); |
373 | GNUNET_free (record_data_b64); | 338 | GNUNET_free (record_data_b64); |
@@ -608,7 +573,6 @@ iterate_zones (void *cls, | |||
608 | struct FlatFileEntry *entry = value; | 573 | struct FlatFileEntry *entry = value; |
609 | 574 | ||
610 | (void) key; | 575 | (void) key; |
611 | ic->pos++; | ||
612 | if (0 == ic->limit) | 576 | if (0 == ic->limit) |
613 | return GNUNET_NO; | 577 | return GNUNET_NO; |
614 | if ( (NULL != ic->zone) && | 578 | if ( (NULL != ic->zone) && |
@@ -616,6 +580,7 @@ iterate_zones (void *cls, | |||
616 | ic->zone, | 580 | ic->zone, |
617 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ) | 581 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ) |
618 | return GNUNET_YES; | 582 | return GNUNET_YES; |
583 | ic->pos++; | ||
619 | if (ic->offset > 0) | 584 | if (ic->offset > 0) |
620 | { | 585 | { |
621 | ic->offset--; | 586 | ic->offset--; |
@@ -670,17 +635,31 @@ namestore_flat_iterate_records (void *cls, | |||
670 | } | 635 | } |
671 | 636 | ||
672 | 637 | ||
638 | /** | ||
639 | * Closure for #zone_to_name. | ||
640 | */ | ||
641 | struct ZoneToNameContext | ||
642 | { | ||
643 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone; | ||
644 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone; | ||
645 | GNUNET_NAMESTORE_RecordIterator iter; | ||
646 | void *iter_cls; | ||
647 | |||
648 | int result_found; | ||
649 | }; | ||
650 | |||
651 | |||
673 | static int | 652 | static int |
674 | zone_to_name (void *cls, | 653 | zone_to_name (void *cls, |
675 | const struct GNUNET_HashCode *key, | 654 | const struct GNUNET_HashCode *key, |
676 | void *value) | 655 | void *value) |
677 | { | 656 | { |
678 | struct Plugin *plugin = cls; | 657 | struct ZoneToNameContext *ztn = cls; |
679 | struct FlatFileEntry *entry = value; | 658 | struct FlatFileEntry *entry = value; |
680 | 659 | ||
681 | (void) key; | 660 | (void) key; |
682 | if (0 != memcmp (entry->private_key, | 661 | if (0 != memcmp (entry->private_key, |
683 | plugin->iter_zone, | 662 | ztn->zone, |
684 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | 663 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) |
685 | return GNUNET_YES; | 664 | return GNUNET_YES; |
686 | 665 | ||
@@ -688,18 +667,17 @@ zone_to_name (void *cls, | |||
688 | { | 667 | { |
689 | if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type) | 668 | if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type) |
690 | continue; | 669 | continue; |
691 | if (0 == memcmp (plugin->iter_pkey, | 670 | if (0 == memcmp (ztn->value_zone, |
692 | entry->record_data[i].data, | 671 | entry->record_data[i].data, |
693 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 672 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) |
694 | { | 673 | { |
695 | plugin->iter (plugin->iter_cls, | 674 | ztn->iter (ztn->iter_cls, |
696 | 0, | 675 | 0, |
697 | entry->private_key, | 676 | entry->private_key, |
698 | entry->label, | 677 | entry->label, |
699 | entry->record_count, | 678 | entry->record_count, |
700 | entry->record_data); | 679 | entry->record_data); |
701 | plugin->iter_result_found = GNUNET_YES; | 680 | ztn->result_found = GNUNET_YES; |
702 | |||
703 | } | 681 | } |
704 | } | 682 | } |
705 | return GNUNET_YES; | 683 | return GNUNET_YES; |
@@ -725,21 +703,21 @@ namestore_flat_zone_to_name (void *cls, | |||
725 | void *iter_cls) | 703 | void *iter_cls) |
726 | { | 704 | { |
727 | struct Plugin *plugin = cls; | 705 | struct Plugin *plugin = cls; |
706 | struct ZoneToNameContext ztn = { | ||
707 | .iter = iter, | ||
708 | .iter_cls = iter_cls, | ||
709 | .zone = zone, | ||
710 | .value_zone = value_zone, | ||
711 | .result_found = GNUNET_NO | ||
712 | }; | ||
728 | 713 | ||
729 | /* FIXME: maybe use separate closure to better handle | ||
730 | recursive calls? */ | ||
731 | plugin->iter = iter; | ||
732 | plugin->iter_cls = iter_cls; | ||
733 | plugin->iter_zone = zone; | ||
734 | plugin->iter_pkey = value_zone; | ||
735 | plugin->iter_result_found = GNUNET_NO; | ||
736 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 714 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
737 | "Performing reverse lookup for `%s'\n", | 715 | "Performing reverse lookup for `%s'\n", |
738 | GNUNET_GNSRECORD_z2s (value_zone)); | 716 | GNUNET_GNSRECORD_z2s (value_zone)); |
739 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, | 717 | GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, |
740 | &zone_to_name, | 718 | &zone_to_name, |
741 | plugin); | 719 | &ztn); |
742 | return plugin->iter_result_found; | 720 | return ztn.result_found; |
743 | } | 721 | } |
744 | 722 | ||
745 | 723 | ||
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index f62be1e18..34e548613 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -106,72 +106,6 @@ struct Plugin | |||
106 | 106 | ||
107 | 107 | ||
108 | /** | 108 | /** |
109 | * @brief Prepare a SQL statement | ||
110 | * | ||
111 | * @param dbh handle to the database | ||
112 | * @param zSql SQL statement, UTF-8 encoded | ||
113 | * @param ppStmt set to the prepared statement | ||
114 | * @return 0 on success | ||
115 | */ | ||
116 | static int | ||
117 | sq_prepare (sqlite3 *dbh, | ||
118 | const char *zSql, | ||
119 | sqlite3_stmt **ppStmt) | ||
120 | { | ||
121 | char *dummy; | ||
122 | int result; | ||
123 | |||
124 | result = | ||
125 | sqlite3_prepare_v2 (dbh, | ||
126 | zSql, | ||
127 | strlen (zSql), | ||
128 | ppStmt, | ||
129 | (const char **) &dummy); | ||
130 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
131 | "Prepared `%s' / %p: %d\n", | ||
132 | zSql, | ||
133 | *ppStmt, | ||
134 | result); | ||
135 | return result; | ||
136 | } | ||
137 | |||
138 | |||
139 | /** | ||
140 | * Create our database indices. | ||
141 | * | ||
142 | * @param dbh handle to the database | ||
143 | */ | ||
144 | static void | ||
145 | create_indices (sqlite3 * dbh) | ||
146 | { | ||
147 | /* create indices */ | ||
148 | if ( (SQLITE_OK != | ||
149 | sqlite3_exec (dbh, | ||
150 | "CREATE INDEX IF NOT EXISTS ir_pkey_reverse " | ||
151 | "ON ns098records (zone_private_key,pkey)", | ||
152 | NULL, NULL, NULL)) || | ||
153 | (SQLITE_OK != | ||
154 | sqlite3_exec (dbh, | ||
155 | "CREATE INDEX IF NOT EXISTS ir_pkey_iter " | ||
156 | "ON ns098records (zone_private_key,uid)", | ||
157 | NULL, NULL, NULL)) ) | ||
158 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
159 | "Failed to create indices: %s\n", | ||
160 | sqlite3_errmsg (dbh)); | ||
161 | } | ||
162 | |||
163 | |||
164 | #if 0 | ||
165 | #define CHECK(a) GNUNET_break(a) | ||
166 | #define ENULL NULL | ||
167 | #else | ||
168 | #define ENULL &e | ||
169 | #define ENULL_DEFINED 1 | ||
170 | #define CHECK(a) if (! (a)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); } | ||
171 | #endif | ||
172 | |||
173 | |||
174 | /** | ||
175 | * Initialize the database connections and associated | 109 | * Initialize the database connections and associated |
176 | * data structures (create tables and indices | 110 | * data structures (create tables and indices |
177 | * as needed as well). | 111 | * as needed as well). |
@@ -182,17 +116,66 @@ create_indices (sqlite3 * dbh) | |||
182 | static int | 116 | static int |
183 | database_setup (struct Plugin *plugin) | 117 | database_setup (struct Plugin *plugin) |
184 | { | 118 | { |
185 | sqlite3_stmt *stmt; | 119 | char *sqlite_filename; |
186 | char *afsdir; | 120 | struct GNUNET_SQ_ExecuteStatement es[] = { |
187 | #if ENULL_DEFINED | 121 | GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"), |
188 | char *e; | 122 | GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"), |
189 | #endif | 123 | GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"), |
124 | GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"), | ||
125 | GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""), | ||
126 | GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=EXCLUSIVE"), | ||
127 | GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"), | ||
128 | GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records (" | ||
129 | " uid INTEGER PRIMARY KEY," | ||
130 | " zone_private_key BLOB NOT NULL," | ||
131 | " pkey BLOB," | ||
132 | " rvalue INT8 NOT NULL," | ||
133 | " record_count INT NOT NULL," | ||
134 | " record_data BLOB NOT NULL," | ||
135 | " label TEXT NOT NULL" | ||
136 | ")"), | ||
137 | GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse " | ||
138 | "ON ns098records (zone_private_key,pkey)"), | ||
139 | GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter " | ||
140 | "ON ns098records (zone_private_key,uid)"), | ||
141 | GNUNET_SQ_EXECUTE_STATEMENT_END | ||
142 | }; | ||
143 | struct GNUNET_SQ_PrepareStatement ps[] = { | ||
144 | GNUNET_SQ_make_prepare ("INSERT INTO ns098records " | ||
145 | "(zone_private_key,pkey,rvalue,record_count,record_data,label)" | ||
146 | " VALUES (?, ?, ?, ?, ?, ?)", | ||
147 | &plugin->store_records), | ||
148 | GNUNET_SQ_make_prepare ("DELETE FROM ns098records " | ||
149 | "WHERE zone_private_key=? AND label=?", | ||
150 | &plugin->delete_records), | ||
151 | GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label" | ||
152 | " FROM ns098records" | ||
153 | " WHERE zone_private_key=? AND pkey=?", | ||
154 | &plugin->zone_to_name), | ||
155 | GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label" | ||
156 | " FROM ns098records" | ||
157 | " WHERE zone_private_key=? AND _rowid_ >= ?" | ||
158 | " ORDER BY _rowid_ ASC" | ||
159 | " LIMIT ?", | ||
160 | &plugin->iterate_zone), | ||
161 | GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key" | ||
162 | " FROM ns098records" | ||
163 | " WHERE _rowid_ >= ?" | ||
164 | " ORDER BY _rowid_ ASC" | ||
165 | " LIMIT ?", | ||
166 | &plugin->iterate_all_zones), | ||
167 | GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key" | ||
168 | " FROM ns098records" | ||
169 | " WHERE zone_private_key=? AND label=?", | ||
170 | &plugin->lookup_label), | ||
171 | GNUNET_SQ_PREPARE_END | ||
172 | }; | ||
190 | 173 | ||
191 | if (GNUNET_OK != | 174 | if (GNUNET_OK != |
192 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, | 175 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, |
193 | "namestore-sqlite", | 176 | "namestore-sqlite", |
194 | "FILENAME", | 177 | "FILENAME", |
195 | &afsdir)) | 178 | &sqlite_filename)) |
196 | { | 179 | { |
197 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 180 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
198 | "namestore-sqlite", | 181 | "namestore-sqlite", |
@@ -200,132 +183,51 @@ database_setup (struct Plugin *plugin) | |||
200 | return GNUNET_SYSERR; | 183 | return GNUNET_SYSERR; |
201 | } | 184 | } |
202 | if (GNUNET_OK != | 185 | if (GNUNET_OK != |
203 | GNUNET_DISK_file_test (afsdir)) | 186 | GNUNET_DISK_file_test (sqlite_filename)) |
204 | { | 187 | { |
205 | if (GNUNET_OK != | 188 | if (GNUNET_OK != |
206 | GNUNET_DISK_directory_create_for_file (afsdir)) | 189 | GNUNET_DISK_directory_create_for_file (sqlite_filename)) |
207 | { | 190 | { |
208 | GNUNET_break (0); | 191 | GNUNET_break (0); |
209 | GNUNET_free (afsdir); | 192 | GNUNET_free (sqlite_filename); |
210 | return GNUNET_SYSERR; | 193 | return GNUNET_SYSERR; |
211 | } | 194 | } |
212 | } | 195 | } |
213 | /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ | 196 | /* sqlite_filename should be UTF-8-encoded. If it isn't, it's a bug */ |
214 | plugin->fn = afsdir; | 197 | plugin->fn = sqlite_filename; |
215 | 198 | ||
216 | /* Open database and precompile statements */ | 199 | /* Open database and precompile statements */ |
217 | if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK) | 200 | if (SQLITE_OK != |
201 | sqlite3_open (plugin->fn, | ||
202 | &plugin->dbh)) | ||
218 | { | 203 | { |
219 | LOG (GNUNET_ERROR_TYPE_ERROR, | 204 | LOG (GNUNET_ERROR_TYPE_ERROR, |
220 | _("Unable to initialize SQLite: %s.\n"), | 205 | _("Unable to initialize SQLite: %s.\n"), |
221 | sqlite3_errmsg (plugin->dbh)); | 206 | sqlite3_errmsg (plugin->dbh)); |
222 | return GNUNET_SYSERR; | 207 | return GNUNET_SYSERR; |
223 | } | 208 | } |
224 | CHECK (SQLITE_OK == | 209 | GNUNET_break (SQLITE_OK == |
225 | sqlite3_exec (plugin->dbh, | 210 | sqlite3_busy_timeout (plugin->dbh, |
226 | "PRAGMA temp_store=MEMORY", NULL, NULL, | 211 | BUSY_TIMEOUT_MS)); |
227 | ENULL)); | 212 | if (GNUNET_OK != |
228 | CHECK (SQLITE_OK == | 213 | GNUNET_SQ_exec_statements (plugin->dbh, |
229 | sqlite3_exec (plugin->dbh, | 214 | es)) |
230 | "PRAGMA synchronous=NORMAL", NULL, NULL, | ||
231 | ENULL)); | ||
232 | CHECK (SQLITE_OK == | ||
233 | sqlite3_exec (plugin->dbh, | ||
234 | "PRAGMA legacy_file_format=OFF", NULL, NULL, | ||
235 | ENULL)); | ||
236 | CHECK (SQLITE_OK == | ||
237 | sqlite3_exec (plugin->dbh, | ||
238 | "PRAGMA auto_vacuum=INCREMENTAL", NULL, | ||
239 | NULL, ENULL)); | ||
240 | CHECK (SQLITE_OK == | ||
241 | sqlite3_exec (plugin->dbh, | ||
242 | "PRAGMA encoding=\"UTF-8\"", NULL, | ||
243 | NULL, ENULL)); | ||
244 | CHECK (SQLITE_OK == | ||
245 | sqlite3_exec (plugin->dbh, | ||
246 | "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, | ||
247 | ENULL)); | ||
248 | CHECK (SQLITE_OK == | ||
249 | sqlite3_exec (plugin->dbh, | ||
250 | "PRAGMA page_size=4092", NULL, NULL, | ||
251 | ENULL)); | ||
252 | |||
253 | CHECK (SQLITE_OK == | ||
254 | sqlite3_busy_timeout (plugin->dbh, | ||
255 | BUSY_TIMEOUT_MS)); | ||
256 | |||
257 | |||
258 | /* Create table */ | ||
259 | CHECK (SQLITE_OK == | ||
260 | sq_prepare (plugin->dbh, | ||
261 | "SELECT 1 FROM sqlite_master WHERE tbl_name = 'ns098records'", | ||
262 | &stmt)); | ||
263 | if ( (sqlite3_step (stmt) == SQLITE_DONE) && | ||
264 | (SQLITE_OK != | ||
265 | sqlite3_exec (plugin->dbh, | ||
266 | "CREATE TABLE ns098records (" | ||
267 | " uid INTEGER PRIMARY KEY," | ||
268 | " zone_private_key BLOB NOT NULL," | ||
269 | " pkey BLOB," | ||
270 | " rvalue INT8 NOT NULL," | ||
271 | " record_count INT NOT NULL," | ||
272 | " record_data BLOB NOT NULL," | ||
273 | " label TEXT NOT NULL" | ||
274 | ")", | ||
275 | NULL, NULL, NULL)) ) | ||
276 | { | 215 | { |
277 | LOG_SQLITE (plugin, | 216 | GNUNET_break (0); |
278 | GNUNET_ERROR_TYPE_ERROR, | 217 | LOG (GNUNET_ERROR_TYPE_ERROR, |
279 | "sqlite3_exec"); | 218 | _("Failed to setup database at `%s'\n"), |
280 | sqlite3_finalize (stmt); | 219 | plugin->fn); |
281 | return GNUNET_SYSERR; | 220 | return GNUNET_SYSERR; |
282 | } | 221 | } |
283 | sqlite3_finalize (stmt); | 222 | |
284 | 223 | if (GNUNET_OK != | |
285 | create_indices (plugin->dbh); | 224 | GNUNET_SQ_prepare (plugin->dbh, |
286 | 225 | ps)) | |
287 | if ( (SQLITE_OK != | ||
288 | sq_prepare (plugin->dbh, | ||
289 | "INSERT INTO ns098records (zone_private_key, pkey, rvalue, record_count, record_data, label)" | ||
290 | " VALUES (?, ?, ?, ?, ?, ?)", | ||
291 | &plugin->store_records)) || | ||
292 | (SQLITE_OK != | ||
293 | sq_prepare (plugin->dbh, | ||
294 | "DELETE FROM ns098records WHERE zone_private_key=? AND label=?", | ||
295 | &plugin->delete_records)) || | ||
296 | (SQLITE_OK != | ||
297 | sq_prepare (plugin->dbh, | ||
298 | "SELECT uid,record_count,record_data,label" | ||
299 | " FROM ns098records" | ||
300 | " WHERE zone_private_key=? AND pkey=?", | ||
301 | &plugin->zone_to_name)) || | ||
302 | (SQLITE_OK != | ||
303 | sq_prepare (plugin->dbh, | ||
304 | "SELECT uid,record_count,record_data,label" | ||
305 | " FROM ns098records" | ||
306 | " WHERE zone_private_key=? AND _rowid_ >= ?" | ||
307 | " ORDER BY _rowid_ ASC" | ||
308 | " LIMIT ?", | ||
309 | &plugin->iterate_zone)) || | ||
310 | (SQLITE_OK != | ||
311 | sq_prepare (plugin->dbh, | ||
312 | "SELECT uid,record_count,record_data,label,zone_private_key" | ||
313 | " FROM ns098records" | ||
314 | " WHERE _rowid_ >= ?" | ||
315 | " ORDER BY _rowid_ ASC" | ||
316 | " LIMIT ?", | ||
317 | &plugin->iterate_all_zones)) || | ||
318 | (SQLITE_OK != | ||
319 | sq_prepare (plugin->dbh, | ||
320 | "SELECT uid,record_count,record_data,label,zone_private_key" | ||
321 | " FROM ns098records" | ||
322 | " WHERE zone_private_key=? AND label=?", | ||
323 | &plugin->lookup_label)) | ||
324 | ) | ||
325 | { | 226 | { |
326 | LOG_SQLITE (plugin, | 227 | GNUNET_break (0); |
327 | GNUNET_ERROR_TYPE_ERROR, | 228 | LOG (GNUNET_ERROR_TYPE_ERROR, |
328 | "precompiling"); | 229 | _("Failed to setup database at `%s'\n"), |
230 | plugin->fn); | ||
329 | return GNUNET_SYSERR; | 231 | return GNUNET_SYSERR; |
330 | } | 232 | } |
331 | return GNUNET_OK; | 233 | return GNUNET_OK; |
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf index 1e36c52fe..07409ea2b 100644 --- a/src/namestore/test_namestore_api.conf +++ b/src/namestore/test_namestore_api.conf | |||
@@ -15,13 +15,6 @@ AUTOSTART = YES | |||
15 | [identity] | 15 | [identity] |
16 | AUTOSTART = YES | 16 | AUTOSTART = YES |
17 | 17 | ||
18 | [namestore-sqlite] | ||
19 | FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db | ||
20 | |||
21 | [namestore-postgres] | ||
22 | CONFIG = connect_timeout=10; dbname=gnunetcheck | ||
23 | TEMPORARY_TABLE = YES | ||
24 | |||
25 | [nse] | 18 | [nse] |
26 | WORKBITS = 0 | 19 | WORKBITS = 0 |
27 | 20 | ||
diff --git a/src/namestore/test_namestore_api_flat.conf b/src/namestore/test_namestore_api_flat.conf index 49fe25468..6a28306e3 100644 --- a/src/namestore/test_namestore_api_flat.conf +++ b/src/namestore/test_namestore_api_flat.conf | |||
@@ -2,3 +2,6 @@ | |||
2 | 2 | ||
3 | [namestore] | 3 | [namestore] |
4 | DATABASE = flat | 4 | DATABASE = flat |
5 | |||
6 | [namestore-flat] | ||
7 | FILENAME = $GNUNET_TEST_HOME/namestore/flat.db | ||
diff --git a/src/namestore/test_namestore_api_lookup_nick.c b/src/namestore/test_namestore_api_lookup_nick.c index 50d1fd9a9..b9ae93bf2 100644 --- a/src/namestore/test_namestore_api_lookup_nick.c +++ b/src/namestore/test_namestore_api_lookup_nick.c | |||
@@ -52,7 +52,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | |||
52 | //static const char * name = "dummy.dummy.gnunet"; | 52 | //static const char * name = "dummy.dummy.gnunet"; |
53 | static const char * name = "d"; | 53 | static const char * name = "d"; |
54 | 54 | ||
55 | static char *directory; | ||
56 | 55 | ||
57 | static void | 56 | static void |
58 | cleanup () | 57 | cleanup () |
@@ -283,29 +282,22 @@ run (void *cls, | |||
283 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 282 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
284 | struct GNUNET_TESTING_Peer *peer) | 283 | struct GNUNET_TESTING_Peer *peer) |
285 | { | 284 | { |
286 | char *hostkey_file; | ||
287 | |||
288 | directory = NULL; | ||
289 | GNUNET_assert (GNUNET_OK == | ||
290 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory)); | ||
291 | GNUNET_DISK_directory_remove (directory); | ||
292 | |||
293 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 285 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
294 | &endbadly, NULL); | 286 | &endbadly, |
295 | GNUNET_asprintf (&hostkey_file, | 287 | NULL); |
296 | "zonefiles%s%s", | 288 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
297 | DIR_SEPARATOR_STR, | ||
298 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
300 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
301 | GNUNET_free (hostkey_file); | ||
302 | GNUNET_assert (privkey != NULL); | 289 | GNUNET_assert (privkey != NULL); |
303 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 290 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
291 | &pubkey); | ||
304 | 292 | ||
305 | nsh = GNUNET_NAMESTORE_connect (cfg); | 293 | nsh = GNUNET_NAMESTORE_connect (cfg); |
306 | GNUNET_break (NULL != nsh); | 294 | GNUNET_break (NULL != nsh); |
307 | 295 | ||
308 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, TEST_NICK, &nick_cont, (void *) name); | 296 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, |
297 | privkey, | ||
298 | TEST_NICK, | ||
299 | &nick_cont, | ||
300 | (void *) name); | ||
309 | if (NULL == nsqe) | 301 | if (NULL == nsqe) |
310 | { | 302 | { |
311 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 303 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -324,6 +316,8 @@ main (int argc, char *argv[]) | |||
324 | GNUNET_asprintf (&cfg_name, | 316 | GNUNET_asprintf (&cfg_name, |
325 | "test_namestore_api_%s.conf", | 317 | "test_namestore_api_%s.conf", |
326 | plugin_name); | 318 | plugin_name); |
319 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
320 | "GNUNET_TEST_HOME"); | ||
327 | res = 1; | 321 | res = 1; |
328 | if (0 != | 322 | if (0 != |
329 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick", | 323 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick", |
@@ -333,12 +327,9 @@ main (int argc, char *argv[]) | |||
333 | { | 327 | { |
334 | res = 1; | 328 | res = 1; |
335 | } | 329 | } |
330 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
331 | "GNUNET_TEST_HOME"); | ||
336 | GNUNET_free (cfg_name); | 332 | GNUNET_free (cfg_name); |
337 | if (NULL != directory) | ||
338 | { | ||
339 | GNUNET_DISK_directory_remove (directory); | ||
340 | GNUNET_free (directory); | ||
341 | } | ||
342 | return res; | 333 | return res; |
343 | } | 334 | } |
344 | 335 | ||
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c index 7866749f1..689e73a2e 100644 --- a/src/namestore/test_namestore_api_lookup_private.c +++ b/src/namestore/test_namestore_api_lookup_private.c | |||
@@ -48,7 +48,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | |||
48 | //static const char * name = "dummy.dummy.gnunet"; | 48 | //static const char * name = "dummy.dummy.gnunet"; |
49 | static const char * name = "d"; | 49 | static const char * name = "d"; |
50 | 50 | ||
51 | static char *directory; | ||
52 | 51 | ||
53 | static void | 52 | static void |
54 | cleanup () | 53 | cleanup () |
@@ -71,11 +70,11 @@ cleanup () | |||
71 | * Re-establish the connection to the service. | 70 | * Re-establish the connection to the service. |
72 | * | 71 | * |
73 | * @param cls handle to use to re-connect. | 72 | * @param cls handle to use to re-connect. |
74 | * @param tc scheduler context | ||
75 | */ | 73 | */ |
76 | static void | 74 | static void |
77 | endbadly (void *cls) | 75 | endbadly (void *cls) |
78 | { | 76 | { |
77 | endbadly_task = NULL; | ||
79 | if (NULL != nsqe) | 78 | if (NULL != nsqe) |
80 | { | 79 | { |
81 | GNUNET_NAMESTORE_cancel (nsqe); | 80 | GNUNET_NAMESTORE_cancel (nsqe); |
@@ -109,7 +108,7 @@ lookup_it (void *cls, | |||
109 | { | 108 | { |
110 | GNUNET_break(0); | 109 | GNUNET_break(0); |
111 | GNUNET_SCHEDULER_cancel (endbadly_task); | 110 | GNUNET_SCHEDULER_cancel (endbadly_task); |
112 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | 111 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
113 | return; | 112 | return; |
114 | } | 113 | } |
115 | 114 | ||
@@ -118,7 +117,7 @@ lookup_it (void *cls, | |||
118 | { | 117 | { |
119 | GNUNET_break(0); | 118 | GNUNET_break(0); |
120 | GNUNET_SCHEDULER_cancel (endbadly_task); | 119 | GNUNET_SCHEDULER_cancel (endbadly_task); |
121 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | 120 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
122 | return; | 121 | return; |
123 | } | 122 | } |
124 | 123 | ||
@@ -126,7 +125,7 @@ lookup_it (void *cls, | |||
126 | { | 125 | { |
127 | GNUNET_break(0); | 126 | GNUNET_break(0); |
128 | GNUNET_SCHEDULER_cancel (endbadly_task); | 127 | GNUNET_SCHEDULER_cancel (endbadly_task); |
129 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | 128 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
130 | return; | 129 | return; |
131 | } | 130 | } |
132 | 131 | ||
@@ -134,14 +133,14 @@ lookup_it (void *cls, | |||
134 | { | 133 | { |
135 | GNUNET_break(0); | 134 | GNUNET_break(0); |
136 | GNUNET_SCHEDULER_cancel (endbadly_task); | 135 | GNUNET_SCHEDULER_cancel (endbadly_task); |
137 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | 136 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
138 | return; | 137 | return; |
139 | } | 138 | } |
140 | 139 | ||
141 | /* Done */ | 140 | /* Done */ |
142 | GNUNET_SCHEDULER_cancel (endbadly_task); | 141 | GNUNET_SCHEDULER_cancel (endbadly_task); |
143 | endbadly_task = NULL; | 142 | endbadly_task = NULL; |
144 | GNUNET_SCHEDULER_add_now (&end, NULL ); | 143 | GNUNET_SCHEDULER_add_now (&end, NULL); |
145 | } | 144 | } |
146 | 145 | ||
147 | 146 | ||
@@ -153,7 +152,9 @@ fail_cb (void *cls) | |||
153 | 152 | ||
154 | 153 | ||
155 | static void | 154 | static void |
156 | put_cont (void *cls, int32_t success, const char *emsg) | 155 | put_cont (void *cls, |
156 | int32_t success, | ||
157 | const char *emsg) | ||
157 | { | 158 | { |
158 | const char *name = cls; | 159 | const char *name = cls; |
159 | 160 | ||
@@ -187,22 +188,11 @@ run (void *cls, | |||
187 | struct GNUNET_TESTING_Peer *peer) | 188 | struct GNUNET_TESTING_Peer *peer) |
188 | { | 189 | { |
189 | struct GNUNET_GNSRECORD_Data rd; | 190 | struct GNUNET_GNSRECORD_Data rd; |
190 | char *hostkey_file; | ||
191 | |||
192 | directory = NULL; | ||
193 | GNUNET_assert (GNUNET_OK == | ||
194 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory)); | ||
195 | GNUNET_DISK_directory_remove (directory); | ||
196 | 191 | ||
197 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 192 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
198 | &endbadly, NULL); | 193 | &endbadly, |
199 | GNUNET_asprintf (&hostkey_file, | 194 | NULL); |
200 | "zonefiles%s%s", | 195 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
201 | DIR_SEPARATOR_STR, | ||
202 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
204 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
205 | GNUNET_free (hostkey_file); | ||
206 | GNUNET_assert (privkey != NULL); | 196 | GNUNET_assert (privkey != NULL); |
207 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 197 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); |
208 | 198 | ||
@@ -215,8 +205,13 @@ run (void *cls, | |||
215 | 205 | ||
216 | nsh = GNUNET_NAMESTORE_connect (cfg); | 206 | nsh = GNUNET_NAMESTORE_connect (cfg); |
217 | GNUNET_break (NULL != nsh); | 207 | GNUNET_break (NULL != nsh); |
218 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | 208 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
219 | 1, &rd, &put_cont, (void *) name); | 209 | privkey, |
210 | name, | ||
211 | 1, | ||
212 | &rd, | ||
213 | &put_cont, | ||
214 | (void *) name); | ||
220 | if (NULL == nsqe) | 215 | if (NULL == nsqe) |
221 | { | 216 | { |
222 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -237,6 +232,8 @@ main (int argc, char *argv[]) | |||
237 | GNUNET_asprintf (&cfg_name, | 232 | GNUNET_asprintf (&cfg_name, |
238 | "test_namestore_api_%s.conf", | 233 | "test_namestore_api_%s.conf", |
239 | plugin_name); | 234 | plugin_name); |
235 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
236 | "GNUNET_TEST_HOME"); | ||
240 | res = 1; | 237 | res = 1; |
241 | if (0 != | 238 | if (0 != |
242 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private", | 239 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private", |
@@ -246,12 +243,9 @@ main (int argc, char *argv[]) | |||
246 | { | 243 | { |
247 | res = 1; | 244 | res = 1; |
248 | } | 245 | } |
246 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
247 | "GNUNET_TEST_HOME"); | ||
249 | GNUNET_free (cfg_name); | 248 | GNUNET_free (cfg_name); |
250 | if (NULL != directory) | ||
251 | { | ||
252 | GNUNET_DISK_directory_remove (directory); | ||
253 | GNUNET_free (directory); | ||
254 | } | ||
255 | return res; | 249 | return res; |
256 | } | 250 | } |
257 | 251 | ||
diff --git a/src/namestore/test_namestore_api_lookup_public.c b/src/namestore/test_namestore_api_lookup_public.c index 02ca16042..28a68daf9 100644 --- a/src/namestore/test_namestore_api_lookup_public.c +++ b/src/namestore/test_namestore_api_lookup_public.c | |||
@@ -51,7 +51,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | |||
51 | 51 | ||
52 | static struct GNUNET_NAMECACHE_QueueEntry *ncqe; | 52 | static struct GNUNET_NAMECACHE_QueueEntry *ncqe; |
53 | 53 | ||
54 | static char *directory; | ||
55 | 54 | ||
56 | static void | 55 | static void |
57 | cleanup () | 56 | cleanup () |
@@ -190,26 +189,15 @@ run (void *cls, | |||
190 | struct GNUNET_TESTING_Peer *peer) | 189 | struct GNUNET_TESTING_Peer *peer) |
191 | { | 190 | { |
192 | struct GNUNET_GNSRECORD_Data rd; | 191 | struct GNUNET_GNSRECORD_Data rd; |
193 | char *hostkey_file; | ||
194 | const char * name = "dummy.dummy.gnunet"; | 192 | const char * name = "dummy.dummy.gnunet"; |
195 | 193 | ||
196 | directory = NULL; | ||
197 | GNUNET_assert (GNUNET_OK == | ||
198 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory)); | ||
199 | GNUNET_DISK_directory_remove (directory); | ||
200 | |||
201 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 194 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
202 | &endbadly, NULL); | 195 | &endbadly, |
203 | GNUNET_asprintf (&hostkey_file, | 196 | NULL); |
204 | "zonefiles%s%s", | 197 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
205 | DIR_SEPARATOR_STR, | ||
206 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
208 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
209 | GNUNET_free (hostkey_file); | ||
210 | GNUNET_assert (privkey != NULL); | 198 | GNUNET_assert (privkey != NULL); |
211 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 199 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
212 | 200 | &pubkey); | |
213 | 201 | ||
214 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 202 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; |
215 | rd.record_type = TEST_RECORD_TYPE; | 203 | rd.record_type = TEST_RECORD_TYPE; |
@@ -244,6 +232,8 @@ main (int argc, char *argv[]) | |||
244 | GNUNET_asprintf (&cfg_name, | 232 | GNUNET_asprintf (&cfg_name, |
245 | "test_namestore_api_%s.conf", | 233 | "test_namestore_api_%s.conf", |
246 | plugin_name); | 234 | plugin_name); |
235 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
236 | "GNUNET_TEST_HOME"); | ||
247 | res = 1; | 237 | res = 1; |
248 | if (0 != | 238 | if (0 != |
249 | GNUNET_TESTING_peer_run ("test-namestore-api", | 239 | GNUNET_TESTING_peer_run ("test-namestore-api", |
@@ -253,12 +243,9 @@ main (int argc, char *argv[]) | |||
253 | { | 243 | { |
254 | res = 1; | 244 | res = 1; |
255 | } | 245 | } |
246 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
247 | "GNUNET_TEST_HOME"); | ||
256 | GNUNET_free (cfg_name); | 248 | GNUNET_free (cfg_name); |
257 | if (NULL != directory) | ||
258 | { | ||
259 | GNUNET_DISK_directory_remove (directory); | ||
260 | GNUNET_free (directory); | ||
261 | } | ||
262 | return res; | 249 | return res; |
263 | } | 250 | } |
264 | 251 | ||
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c b/src/namestore/test_namestore_api_lookup_shadow.c index e80335796..39ce4e564 100644 --- a/src/namestore/test_namestore_api_lookup_shadow.c +++ b/src/namestore/test_namestore_api_lookup_shadow.c | |||
@@ -53,7 +53,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | |||
53 | 53 | ||
54 | static struct GNUNET_NAMECACHE_QueueEntry *ncqe; | 54 | static struct GNUNET_NAMECACHE_QueueEntry *ncqe; |
55 | 55 | ||
56 | static char *directory; | ||
57 | 56 | ||
58 | static void | 57 | static void |
59 | cleanup () | 58 | cleanup () |
@@ -222,26 +221,15 @@ run (void *cls, | |||
222 | struct GNUNET_TESTING_Peer *peer) | 221 | struct GNUNET_TESTING_Peer *peer) |
223 | { | 222 | { |
224 | struct GNUNET_GNSRECORD_Data rd; | 223 | struct GNUNET_GNSRECORD_Data rd; |
225 | char *hostkey_file; | ||
226 | const char * name = "dummy.dummy.gnunet"; | 224 | const char * name = "dummy.dummy.gnunet"; |
227 | 225 | ||
228 | directory = NULL; | ||
229 | GNUNET_assert (GNUNET_OK == | ||
230 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory)); | ||
231 | GNUNET_DISK_directory_remove (directory); | ||
232 | |||
233 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 226 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
234 | &endbadly, NULL); | 227 | &endbadly, |
235 | GNUNET_asprintf (&hostkey_file, | 228 | NULL); |
236 | "zonefiles%s%s", | 229 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
237 | DIR_SEPARATOR_STR, | ||
238 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
240 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
241 | GNUNET_free (hostkey_file); | ||
242 | GNUNET_assert (privkey != NULL); | 230 | GNUNET_assert (privkey != NULL); |
243 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 231 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
244 | 232 | &pubkey); | |
245 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 233 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; |
246 | rd.record_type = TEST_RECORD_TYPE; | 234 | rd.record_type = TEST_RECORD_TYPE; |
247 | rd.data_size = TEST_RECORD_DATALEN; | 235 | rd.data_size = TEST_RECORD_DATALEN; |
@@ -253,8 +241,13 @@ run (void *cls, | |||
253 | nch = GNUNET_NAMECACHE_connect (cfg); | 241 | nch = GNUNET_NAMECACHE_connect (cfg); |
254 | GNUNET_break (NULL != nsh); | 242 | GNUNET_break (NULL != nsh); |
255 | GNUNET_break (NULL != nch); | 243 | GNUNET_break (NULL != nch); |
256 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | 244 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
257 | 1, &rd, &put_cont, (void *) name); | 245 | privkey, |
246 | name, | ||
247 | 1, | ||
248 | &rd, | ||
249 | &put_cont, | ||
250 | (void *) name); | ||
258 | if (NULL == nsqe) | 251 | if (NULL == nsqe) |
259 | { | 252 | { |
260 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 253 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -274,6 +267,8 @@ main (int argc, char *argv[]) | |||
274 | GNUNET_asprintf (&cfg_name, | 267 | GNUNET_asprintf (&cfg_name, |
275 | "test_namestore_api_%s.conf", | 268 | "test_namestore_api_%s.conf", |
276 | plugin_name); | 269 | plugin_name); |
270 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
271 | "GNUNET_TEST_HOME"); | ||
277 | res = 1; | 272 | res = 1; |
278 | if (0 != | 273 | if (0 != |
279 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow", | 274 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow", |
@@ -284,11 +279,8 @@ main (int argc, char *argv[]) | |||
284 | res = 1; | 279 | res = 1; |
285 | } | 280 | } |
286 | GNUNET_free (cfg_name); | 281 | GNUNET_free (cfg_name); |
287 | if (NULL != directory) | 282 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
288 | { | 283 | "GNUNET_TEST_HOME"); |
289 | GNUNET_DISK_directory_remove (directory); | ||
290 | GNUNET_free (directory); | ||
291 | } | ||
292 | return res; | 284 | return res; |
293 | } | 285 | } |
294 | 286 | ||
diff --git a/src/namestore/test_namestore_api_lookup_shadow_filter.c b/src/namestore/test_namestore_api_lookup_shadow_filter.c index 5b8811a23..09fd8ce07 100644 --- a/src/namestore/test_namestore_api_lookup_shadow_filter.c +++ b/src/namestore/test_namestore_api_lookup_shadow_filter.c | |||
@@ -66,7 +66,6 @@ static struct GNUNET_HashCode derived_hash; | |||
66 | 66 | ||
67 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 67 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
68 | 68 | ||
69 | static char *directory; | ||
70 | 69 | ||
71 | static void | 70 | static void |
72 | cleanup () | 71 | cleanup () |
@@ -291,26 +290,16 @@ run (void *cls, | |||
291 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 290 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
292 | struct GNUNET_TESTING_Peer *peer) | 291 | struct GNUNET_TESTING_Peer *peer) |
293 | { | 292 | { |
294 | char *hostkey_file; | ||
295 | |||
296 | directory = NULL; | ||
297 | GNUNET_assert (GNUNET_OK == | ||
298 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory)); | ||
299 | GNUNET_DISK_directory_remove (directory); | ||
300 | |||
301 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 293 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
302 | &endbadly, NULL); | 294 | &endbadly, |
303 | GNUNET_asprintf (&hostkey_file, | 295 | NULL); |
304 | "zonefiles%s%s", | 296 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
305 | DIR_SEPARATOR_STR, | ||
306 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
307 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
308 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
309 | GNUNET_free (hostkey_file); | ||
310 | GNUNET_assert (privkey != NULL); | 297 | GNUNET_assert (privkey != NULL); |
311 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 298 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
299 | &pubkey); | ||
312 | 300 | ||
313 | record_expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), EXPIRATION); | 301 | record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), |
302 | EXPIRATION); | ||
314 | records[0].expiration_time = record_expiration.abs_value_us; | 303 | records[0].expiration_time = record_expiration.abs_value_us; |
315 | records[0].record_type = TEST_RECORD_TYPE; | 304 | records[0].record_type = TEST_RECORD_TYPE; |
316 | records[0].data_size = TEST_RECORD_DATALEN; | 305 | records[0].data_size = TEST_RECORD_DATALEN; |
@@ -352,6 +341,8 @@ main (int argc, char *argv[]) | |||
352 | GNUNET_asprintf (&cfg_name, | 341 | GNUNET_asprintf (&cfg_name, |
353 | "test_namestore_api_%s.conf", | 342 | "test_namestore_api_%s.conf", |
354 | plugin_name); | 343 | plugin_name); |
344 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
345 | "GNUNET_TEST_HOME"); | ||
355 | res = 1; | 346 | res = 1; |
356 | if (0 != | 347 | if (0 != |
357 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter", | 348 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter", |
@@ -362,11 +353,8 @@ main (int argc, char *argv[]) | |||
362 | res = 1; | 353 | res = 1; |
363 | } | 354 | } |
364 | GNUNET_free (cfg_name); | 355 | GNUNET_free (cfg_name); |
365 | if (NULL != directory) | 356 | GNUNET_DISK_purge_cfg_dir (cfg_name, |
366 | { | 357 | "GNUNET_TEST_HOME"); |
367 | GNUNET_DISK_directory_remove (directory); | ||
368 | GNUNET_free (directory); | ||
369 | } | ||
370 | return res; | 358 | return res; |
371 | } | 359 | } |
372 | 360 | ||
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c index cd38b2c80..de202d535 100644 --- a/src/namestore/test_namestore_api_monitoring.c +++ b/src/namestore/test_namestore_api_monitoring.c | |||
@@ -56,7 +56,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3; | |||
56 | 56 | ||
57 | struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; | 57 | struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; |
58 | 58 | ||
59 | static char *directory; | ||
60 | 59 | ||
61 | static void | 60 | static void |
62 | do_shutdown () | 61 | do_shutdown () |
@@ -66,7 +65,6 @@ do_shutdown () | |||
66 | GNUNET_NAMESTORE_zone_monitor_stop (zm); | 65 | GNUNET_NAMESTORE_zone_monitor_stop (zm); |
67 | zm = NULL; | 66 | zm = NULL; |
68 | } | 67 | } |
69 | |||
70 | if (NULL != ns_ops[0]) | 68 | if (NULL != ns_ops[0]) |
71 | { | 69 | { |
72 | GNUNET_NAMESTORE_cancel(ns_ops[0]); | 70 | GNUNET_NAMESTORE_cancel(ns_ops[0]); |
@@ -82,13 +80,11 @@ do_shutdown () | |||
82 | GNUNET_NAMESTORE_cancel(ns_ops[2]); | 80 | GNUNET_NAMESTORE_cancel(ns_ops[2]); |
83 | ns_ops[2] = NULL; | 81 | ns_ops[2] = NULL; |
84 | } | 82 | } |
85 | |||
86 | if (NULL != nsh) | 83 | if (NULL != nsh) |
87 | { | 84 | { |
88 | GNUNET_NAMESTORE_disconnect (nsh); | 85 | GNUNET_NAMESTORE_disconnect (nsh); |
89 | nsh = NULL; | 86 | nsh = NULL; |
90 | } | 87 | } |
91 | |||
92 | GNUNET_free_non_null(s_name_1); | 88 | GNUNET_free_non_null(s_name_1); |
93 | GNUNET_free_non_null(s_name_2); | 89 | GNUNET_free_non_null(s_name_2); |
94 | GNUNET_free_non_null(s_name_3); | 90 | GNUNET_free_non_null(s_name_3); |
@@ -284,23 +280,8 @@ run (void *cls, | |||
284 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 280 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
285 | struct GNUNET_TESTING_Peer *peer) | 281 | struct GNUNET_TESTING_Peer *peer) |
286 | { | 282 | { |
287 | char *hostkey_file; | ||
288 | |||
289 | res = 1; | 283 | res = 1; |
290 | 284 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | |
291 | directory = NULL; | ||
292 | GNUNET_assert (GNUNET_OK == | ||
293 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory)); | ||
294 | GNUNET_DISK_directory_remove (directory); | ||
295 | |||
296 | GNUNET_asprintf(&hostkey_file, | ||
297 | "zonefiles%s%s", | ||
298 | DIR_SEPARATOR_STR, | ||
299 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
301 | "Using zonekey file `%s' \n", hostkey_file); | ||
302 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | ||
303 | GNUNET_free (hostkey_file); | ||
304 | GNUNET_assert (privkey != NULL); | 285 | GNUNET_assert (privkey != NULL); |
305 | 286 | ||
306 | /* Start monitoring */ | 287 | /* Start monitoring */ |
@@ -333,16 +314,12 @@ run (void *cls, | |||
333 | return; | 314 | return; |
334 | } | 315 | } |
335 | 316 | ||
336 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s", | 317 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); |
337 | DIR_SEPARATOR_STR, | ||
338 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); | ||
339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
340 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | ||
341 | GNUNET_free (hostkey_file); | ||
342 | GNUNET_assert (privkey2 != NULL); | 318 | GNUNET_assert (privkey2 != NULL); |
343 | 319 | ||
344 | 320 | ||
345 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); | 321 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
322 | "Created record 3\n"); | ||
346 | /* name in different zone */ | 323 | /* name in different zone */ |
347 | GNUNET_asprintf(&s_name_3, "dummy3"); | 324 | GNUNET_asprintf(&s_name_3, "dummy3"); |
348 | s_rd_3 = create_record(1); | 325 | s_rd_3 = create_record(1); |
@@ -358,22 +335,33 @@ run (void *cls, | |||
358 | "Created record 1\n"); | 335 | "Created record 1\n"); |
359 | GNUNET_asprintf(&s_name_1, "dummy1"); | 336 | GNUNET_asprintf(&s_name_1, "dummy1"); |
360 | s_rd_1 = create_record(1); | 337 | s_rd_1 = create_record(1); |
361 | GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, | 338 | GNUNET_assert (NULL != (ns_ops[0] = |
362 | 1, s_rd_1, &put_cont, s_name_1))); | 339 | GNUNET_NAMESTORE_records_store (nsh, |
340 | privkey, | ||
341 | s_name_1, | ||
342 | 1, | ||
343 | s_rd_1, | ||
344 | &put_cont, | ||
345 | s_name_1))); | ||
363 | 346 | ||
364 | 347 | ||
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); | 348 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); |
366 | GNUNET_asprintf(&s_name_2, "dummy2"); | 349 | GNUNET_asprintf(&s_name_2, "dummy2"); |
367 | s_rd_2 = create_record(1); | 350 | s_rd_2 = create_record(1); |
368 | GNUNET_assert (NULL != (ns_ops[1] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, | 351 | GNUNET_assert (NULL != (ns_ops[1] = |
369 | 1, s_rd_2, &put_cont, s_name_2))); | 352 | GNUNET_NAMESTORE_records_store (nsh, |
370 | 353 | privkey, | |
371 | 354 | s_name_2, | |
355 | 1, | ||
356 | s_rd_2, | ||
357 | &put_cont, | ||
358 | s_name_2))); | ||
372 | } | 359 | } |
373 | 360 | ||
374 | 361 | ||
375 | int | 362 | int |
376 | main (int argc, char *argv[]) | 363 | main (int argc, |
364 | char *argv[]) | ||
377 | { | 365 | { |
378 | const char *plugin_name; | 366 | const char *plugin_name; |
379 | char *cfg_name; | 367 | char *cfg_name; |
@@ -382,6 +370,8 @@ main (int argc, char *argv[]) | |||
382 | GNUNET_asprintf (&cfg_name, | 370 | GNUNET_asprintf (&cfg_name, |
383 | "test_namestore_api_%s.conf", | 371 | "test_namestore_api_%s.conf", |
384 | plugin_name); | 372 | plugin_name); |
373 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
374 | "GNUNET_TEST_HOME"); | ||
385 | res = 1; | 375 | res = 1; |
386 | if (0 != | 376 | if (0 != |
387 | GNUNET_TESTING_peer_run ("test-namestore-api-monitoring", | 377 | GNUNET_TESTING_peer_run ("test-namestore-api-monitoring", |
@@ -391,12 +381,9 @@ main (int argc, char *argv[]) | |||
391 | { | 381 | { |
392 | res = 1; | 382 | res = 1; |
393 | } | 383 | } |
384 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
385 | "GNUNET_TEST_HOME"); | ||
394 | GNUNET_free (cfg_name); | 386 | GNUNET_free (cfg_name); |
395 | if (NULL != directory) | ||
396 | { | ||
397 | GNUNET_DISK_directory_remove (directory); | ||
398 | GNUNET_free (directory); | ||
399 | } | ||
400 | return res; | 387 | return res; |
401 | } | 388 | } |
402 | 389 | ||
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c index f6a74609e..449b36d65 100644 --- a/src/namestore/test_namestore_api_monitoring_existing.c +++ b/src/namestore/test_namestore_api_monitoring_existing.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013, 2018 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -18,7 +18,7 @@ | |||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file namestore/test_namestore_api_monitoring.c | 21 | * @file namestore/test_namestore_api_monitoring_existing.c |
22 | * @brief testcase for zone monitoring functionality: add records first, then monitor | 22 | * @brief testcase for zone monitoring functionality: add records first, then monitor |
23 | */ | 23 | */ |
24 | #include "platform.h" | 24 | #include "platform.h" |
@@ -27,7 +27,7 @@ | |||
27 | #include "namestore.h" | 27 | #include "namestore.h" |
28 | 28 | ||
29 | 29 | ||
30 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) | 30 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
31 | 31 | ||
32 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 32 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
33 | 33 | ||
@@ -57,18 +57,30 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3; | |||
57 | 57 | ||
58 | struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; | 58 | struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; |
59 | 59 | ||
60 | static char *directory; | 60 | |
61 | /** | ||
62 | * Re-establish the connection to the service. | ||
63 | * | ||
64 | * @param cls handle to use to re-connect. | ||
65 | */ | ||
66 | static void | ||
67 | endbadly (void *cls) | ||
68 | { | ||
69 | endbadly_task = NULL; | ||
70 | GNUNET_break (0); | ||
71 | GNUNET_SCHEDULER_shutdown (); | ||
72 | res = 1; | ||
73 | } | ||
61 | 74 | ||
62 | 75 | ||
63 | static void | 76 | static void |
64 | do_shutdown () | 77 | end (void *cls) |
65 | { | 78 | { |
66 | if (NULL != zm) | 79 | if (NULL != zm) |
67 | { | 80 | { |
68 | GNUNET_NAMESTORE_zone_monitor_stop (zm); | 81 | GNUNET_NAMESTORE_zone_monitor_stop (zm); |
69 | zm = NULL; | 82 | zm = NULL; |
70 | } | 83 | } |
71 | |||
72 | if (NULL != ns_ops[0]) | 84 | if (NULL != ns_ops[0]) |
73 | { | 85 | { |
74 | GNUNET_NAMESTORE_cancel(ns_ops[0]); | 86 | GNUNET_NAMESTORE_cancel(ns_ops[0]); |
@@ -84,7 +96,11 @@ do_shutdown () | |||
84 | GNUNET_NAMESTORE_cancel(ns_ops[2]); | 96 | GNUNET_NAMESTORE_cancel(ns_ops[2]); |
85 | ns_ops[2] = NULL; | 97 | ns_ops[2] = NULL; |
86 | } | 98 | } |
87 | 99 | if (NULL != endbadly_task) | |
100 | { | ||
101 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
102 | endbadly_task = NULL; | ||
103 | } | ||
88 | if (NULL != nsh) | 104 | if (NULL != nsh) |
89 | { | 105 | { |
90 | GNUNET_NAMESTORE_disconnect (nsh); | 106 | GNUNET_NAMESTORE_disconnect (nsh); |
@@ -124,27 +140,6 @@ do_shutdown () | |||
124 | } | 140 | } |
125 | 141 | ||
126 | 142 | ||
127 | /** | ||
128 | * Re-establish the connection to the service. | ||
129 | * | ||
130 | * @param cls handle to use to re-connect. | ||
131 | */ | ||
132 | static void | ||
133 | endbadly (void *cls) | ||
134 | { | ||
135 | do_shutdown (); | ||
136 | res = 1; | ||
137 | } | ||
138 | |||
139 | |||
140 | static void | ||
141 | end (void *cls) | ||
142 | { | ||
143 | do_shutdown (); | ||
144 | res = 0; | ||
145 | } | ||
146 | |||
147 | |||
148 | static void | 143 | static void |
149 | zone_proc (void *cls, | 144 | zone_proc (void *cls, |
150 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 145 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
@@ -166,9 +161,7 @@ zone_proc (void *cls, | |||
166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
167 | "Monitoring returned wrong zone key\n"); | 162 | "Monitoring returned wrong zone key\n"); |
168 | GNUNET_break (0); | 163 | GNUNET_break (0); |
169 | GNUNET_SCHEDULER_cancel (endbadly_task); | 164 | GNUNET_SCHEDULER_shutdown (); |
170 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, | ||
171 | NULL); | ||
172 | return; | 165 | return; |
173 | } | 166 | } |
174 | 167 | ||
@@ -203,17 +196,16 @@ zone_proc (void *cls, | |||
203 | 1); | 196 | 1); |
204 | if (2 == ++returned_records) | 197 | if (2 == ++returned_records) |
205 | { | 198 | { |
206 | if (endbadly_task != NULL) | 199 | GNUNET_SCHEDULER_shutdown (); |
200 | if (GNUNET_YES == fail) | ||
207 | { | 201 | { |
208 | GNUNET_SCHEDULER_cancel (endbadly_task); | 202 | GNUNET_break (0); |
209 | endbadly_task = NULL; | 203 | res = 1; |
210 | } | 204 | } |
211 | if (GNUNET_YES == fail) | ||
212 | GNUNET_SCHEDULER_add_now (&endbadly, | ||
213 | NULL); | ||
214 | else | 205 | else |
215 | GNUNET_SCHEDULER_add_now (&end, | 206 | { |
216 | NULL); | 207 | res = 0; |
208 | } | ||
217 | } | 209 | } |
218 | } | 210 | } |
219 | 211 | ||
@@ -260,8 +252,9 @@ put_cont (void *cls, | |||
260 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 252 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
261 | "Failed to created records\n"); | 253 | "Failed to created records\n"); |
262 | GNUNET_break (0); | 254 | GNUNET_break (0); |
263 | GNUNET_SCHEDULER_cancel (endbadly_task); | 255 | res = 1; |
264 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | 256 | GNUNET_SCHEDULER_shutdown (); |
257 | return; | ||
265 | } | 258 | } |
266 | 259 | ||
267 | if (3 == c) | 260 | if (3 == c) |
@@ -281,8 +274,8 @@ put_cont (void *cls, | |||
281 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 274 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
282 | "Failed to create zone monitor\n"); | 275 | "Failed to create zone monitor\n"); |
283 | GNUNET_break (0); | 276 | GNUNET_break (0); |
284 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, | 277 | res = 1; |
285 | NULL); | 278 | GNUNET_SCHEDULER_shutdown (); |
286 | return; | 279 | return; |
287 | } | 280 | } |
288 | } | 281 | } |
@@ -316,30 +309,16 @@ run (void *cls, | |||
316 | const struct GNUNET_CONFIGURATION_Handle *mycfg, | 309 | const struct GNUNET_CONFIGURATION_Handle *mycfg, |
317 | struct GNUNET_TESTING_Peer *peer) | 310 | struct GNUNET_TESTING_Peer *peer) |
318 | { | 311 | { |
319 | char *hostkey_file; | ||
320 | |||
321 | directory = NULL; | ||
322 | GNUNET_assert (GNUNET_OK == | ||
323 | GNUNET_CONFIGURATION_get_value_string (mycfg, | ||
324 | "PATHS", | ||
325 | "GNUNET_TEST_HOME", | ||
326 | &directory)); | ||
327 | GNUNET_DISK_directory_remove (directory); | ||
328 | |||
329 | res = 1; | 312 | res = 1; |
330 | 313 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | |
331 | GNUNET_asprintf(&hostkey_file, | ||
332 | "zonefiles%s%s", | ||
333 | DIR_SEPARATOR_STR, | ||
334 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
335 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
336 | "Using zonekey file `%s' \n", hostkey_file); | ||
337 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | ||
338 | GNUNET_free (hostkey_file); | ||
339 | GNUNET_assert (privkey != NULL); | 314 | GNUNET_assert (privkey != NULL); |
340 | 315 | ||
341 | cfg = mycfg; | 316 | cfg = mycfg; |
342 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); | 317 | GNUNET_SCHEDULER_add_shutdown (&end, |
318 | NULL); | ||
319 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
320 | &endbadly, | ||
321 | NULL); | ||
343 | /* Connect to namestore */ | 322 | /* Connect to namestore */ |
344 | nsh = GNUNET_NAMESTORE_connect (cfg); | 323 | nsh = GNUNET_NAMESTORE_connect (cfg); |
345 | if (NULL == nsh) | 324 | if (NULL == nsh) |
@@ -350,12 +329,7 @@ run (void *cls, | |||
350 | return; | 329 | return; |
351 | } | 330 | } |
352 | 331 | ||
353 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s", | 332 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); |
354 | DIR_SEPARATOR_STR, | ||
355 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); | ||
356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
357 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | ||
358 | GNUNET_free (hostkey_file); | ||
359 | GNUNET_assert (privkey2 != NULL); | 333 | GNUNET_assert (privkey2 != NULL); |
360 | 334 | ||
361 | 335 | ||
@@ -363,16 +337,29 @@ run (void *cls, | |||
363 | /* name in different zone */ | 337 | /* name in different zone */ |
364 | GNUNET_asprintf(&s_name_3, "dummy3"); | 338 | GNUNET_asprintf(&s_name_3, "dummy3"); |
365 | s_rd_3 = create_record(1); | 339 | s_rd_3 = create_record(1); |
366 | GNUNET_assert (NULL != (ns_ops[2] = GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, | 340 | GNUNET_assert (NULL != (ns_ops[2] = |
367 | 1, s_rd_3, &put_cont, s_name_3))); | 341 | GNUNET_NAMESTORE_records_store (nsh, |
342 | privkey2, | ||
343 | s_name_3, | ||
344 | 1, | ||
345 | s_rd_3, | ||
346 | &put_cont, | ||
347 | s_name_3))); | ||
368 | 348 | ||
369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); | 349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
350 | "Created record 1\n"); | ||
370 | GNUNET_asprintf(&s_name_1, "dummy1"); | 351 | GNUNET_asprintf(&s_name_1, "dummy1"); |
371 | s_rd_1 = create_record(1); | 352 | s_rd_1 = create_record(1); |
372 | GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, | 353 | GNUNET_assert (NULL != (ns_ops[0] = |
373 | 1, s_rd_1, &put_cont, s_name_1))); | 354 | GNUNET_NAMESTORE_records_store(nsh, |
374 | 355 | privkey, | |
375 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); | 356 | s_name_1, |
357 | 1, | ||
358 | s_rd_1, | ||
359 | &put_cont, | ||
360 | s_name_1))); | ||
361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
362 | "Created record 2 \n"); | ||
376 | GNUNET_asprintf(&s_name_2, "dummy2"); | 363 | GNUNET_asprintf(&s_name_2, "dummy2"); |
377 | s_rd_2 = create_record(1); | 364 | s_rd_2 = create_record(1); |
378 | GNUNET_assert (NULL != (ns_ops[1] = | 365 | GNUNET_assert (NULL != (ns_ops[1] = |
@@ -397,6 +384,8 @@ main (int argc, char *argv[]) | |||
397 | "test_namestore_api_%s.conf", | 384 | "test_namestore_api_%s.conf", |
398 | plugin_name); | 385 | plugin_name); |
399 | res = 1; | 386 | res = 1; |
387 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
388 | "GNUNET_TEST_HOME"); | ||
400 | if (0 != | 389 | if (0 != |
401 | GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing", | 390 | GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing", |
402 | cfg_name, | 391 | cfg_name, |
@@ -405,12 +394,9 @@ main (int argc, char *argv[]) | |||
405 | { | 394 | { |
406 | res = 1; | 395 | res = 1; |
407 | } | 396 | } |
397 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
398 | "GNUNET_TEST_HOME"); | ||
408 | GNUNET_free (cfg_name); | 399 | GNUNET_free (cfg_name); |
409 | if (NULL != directory) | ||
410 | { | ||
411 | GNUNET_DISK_directory_remove (directory); | ||
412 | GNUNET_free (directory); | ||
413 | } | ||
414 | return res; | 400 | return res; |
415 | } | 401 | } |
416 | 402 | ||
diff --git a/src/namestore/test_namestore_api_postgres.conf b/src/namestore/test_namestore_api_postgres.conf index 397cb4b2f..9960e6315 100644 --- a/src/namestore/test_namestore_api_postgres.conf +++ b/src/namestore/test_namestore_api_postgres.conf | |||
@@ -2,3 +2,8 @@ | |||
2 | 2 | ||
3 | [namestore] | 3 | [namestore] |
4 | DATABASE = postgres | 4 | DATABASE = postgres |
5 | |||
6 | |||
7 | [namestore-postgres] | ||
8 | CONFIG = connect_timeout=10; dbname=gnunetcheck | ||
9 | TEMPORARY_TABLE = YES | ||
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c index 532a751da..c9e2802bd 100644 --- a/src/namestore/test_namestore_api_remove.c +++ b/src/namestore/test_namestore_api_remove.c | |||
@@ -48,7 +48,6 @@ static int removed; | |||
48 | 48 | ||
49 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | 49 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; |
50 | 50 | ||
51 | static char *directory; | ||
52 | 51 | ||
53 | static void | 52 | static void |
54 | cleanup () | 53 | cleanup () |
@@ -157,29 +156,12 @@ run (void *cls, | |||
157 | struct GNUNET_TESTING_Peer *peer) | 156 | struct GNUNET_TESTING_Peer *peer) |
158 | { | 157 | { |
159 | struct GNUNET_GNSRECORD_Data rd; | 158 | struct GNUNET_GNSRECORD_Data rd; |
160 | char *hostkey_file; | ||
161 | const char * name = "dummy.dummy.gnunet"; | 159 | const char * name = "dummy.dummy.gnunet"; |
162 | 160 | ||
163 | directory = NULL; | ||
164 | GNUNET_assert (GNUNET_OK == | ||
165 | GNUNET_CONFIGURATION_get_value_string(cfg, | ||
166 | "PATHS", | ||
167 | "GNUNET_TEST_HOME", | ||
168 | &directory)); | ||
169 | GNUNET_DISK_directory_remove (directory); | ||
170 | |||
171 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 161 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
172 | &endbadly, | 162 | &endbadly, |
173 | NULL); | 163 | NULL); |
174 | GNUNET_asprintf (&hostkey_file, | 164 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
175 | "zonefiles%s%s", | ||
176 | DIR_SEPARATOR_STR, | ||
177 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
179 | "Using zonekey file `%s' \n", | ||
180 | hostkey_file); | ||
181 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
182 | GNUNET_free (hostkey_file); | ||
183 | GNUNET_assert (privkey != NULL); | 165 | GNUNET_assert (privkey != NULL); |
184 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, | 166 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
185 | &pubkey); | 167 | &pubkey); |
@@ -191,12 +173,19 @@ run (void *cls, | |||
191 | rd.data_size = TEST_RECORD_DATALEN; | 173 | rd.data_size = TEST_RECORD_DATALEN; |
192 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); | 174 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); |
193 | rd.flags = 0; | 175 | rd.flags = 0; |
194 | memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); | 176 | memset ((char *) rd.data, |
177 | 'a', | ||
178 | TEST_RECORD_DATALEN); | ||
195 | 179 | ||
196 | nsh = GNUNET_NAMESTORE_connect (cfg); | 180 | nsh = GNUNET_NAMESTORE_connect (cfg); |
197 | GNUNET_break (NULL != nsh); | 181 | GNUNET_break (NULL != nsh); |
198 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | 182 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
199 | 1, &rd, &put_cont, (void *) name); | 183 | privkey, |
184 | name, | ||
185 | 1, | ||
186 | &rd, | ||
187 | &put_cont, | ||
188 | (void *) name); | ||
200 | if (NULL == nsqe) | 189 | if (NULL == nsqe) |
201 | { | 190 | { |
202 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 191 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -216,6 +205,8 @@ main (int argc, char *argv[]) | |||
216 | GNUNET_asprintf (&cfg_name, | 205 | GNUNET_asprintf (&cfg_name, |
217 | "test_namestore_api_%s.conf", | 206 | "test_namestore_api_%s.conf", |
218 | plugin_name); | 207 | plugin_name); |
208 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
209 | "GNUNET_TEST_HOME"); | ||
219 | res = 1; | 210 | res = 1; |
220 | if (0 != | 211 | if (0 != |
221 | GNUNET_TESTING_peer_run ("test-namestore-api-remove", | 212 | GNUNET_TESTING_peer_run ("test-namestore-api-remove", |
@@ -225,12 +216,9 @@ main (int argc, char *argv[]) | |||
225 | { | 216 | { |
226 | res = 1; | 217 | res = 1; |
227 | } | 218 | } |
219 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
220 | "GNUNET_TEST_HOME"); | ||
228 | GNUNET_free (cfg_name); | 221 | GNUNET_free (cfg_name); |
229 | if (NULL != directory) | ||
230 | { | ||
231 | GNUNET_DISK_directory_remove (directory); | ||
232 | GNUNET_free (directory); | ||
233 | } | ||
234 | return res; | 222 | return res; |
235 | } | 223 | } |
236 | 224 | ||
diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c b/src/namestore/test_namestore_api_remove_not_existing_record.c index 2f20c3636..d0438a7e1 100644 --- a/src/namestore/test_namestore_api_remove_not_existing_record.c +++ b/src/namestore/test_namestore_api_remove_not_existing_record.c | |||
@@ -46,7 +46,6 @@ static int res; | |||
46 | 46 | ||
47 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | 47 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; |
48 | 48 | ||
49 | static char *directory; | ||
50 | 49 | ||
51 | static void | 50 | static void |
52 | cleanup () | 51 | cleanup () |
@@ -92,7 +91,9 @@ end (void *cls) | |||
92 | 91 | ||
93 | 92 | ||
94 | static void | 93 | static void |
95 | put_cont (void *cls, int32_t success, const char *emsg) | 94 | put_cont (void *cls, |
95 | int32_t success, | ||
96 | const char *emsg) | ||
96 | { | 97 | { |
97 | GNUNET_assert (NULL != cls); | 98 | GNUNET_assert (NULL != cls); |
98 | nsqe = NULL; | 99 | nsqe = NULL; |
@@ -101,8 +102,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
101 | GNUNET_SCHEDULER_cancel (endbadly_task); | 102 | GNUNET_SCHEDULER_cancel (endbadly_task); |
102 | endbadly_task = NULL; | 103 | endbadly_task = NULL; |
103 | } | 104 | } |
104 | 105 | switch (success) | |
105 | switch (success) { | 106 | { |
106 | case GNUNET_NO: | 107 | case GNUNET_NO: |
107 | /* We expected GNUNET_NO, since record was not found */ | 108 | /* We expected GNUNET_NO, since record was not found */ |
108 | GNUNET_SCHEDULER_add_now (&end, NULL); | 109 | GNUNET_SCHEDULER_add_now (&end, NULL); |
@@ -129,25 +130,12 @@ run (void *cls, | |||
129 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 130 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
130 | struct GNUNET_TESTING_Peer *peer) | 131 | struct GNUNET_TESTING_Peer *peer) |
131 | { | 132 | { |
132 | char *hostkey_file; | ||
133 | const char * name = "dummy.dummy.gnunet"; | 133 | const char * name = "dummy.dummy.gnunet"; |
134 | 134 | ||
135 | directory = NULL; | ||
136 | GNUNET_assert (GNUNET_OK == | ||
137 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory)); | ||
138 | GNUNET_DISK_directory_remove (directory); | ||
139 | |||
140 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 135 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
141 | &endbadly, NULL); | 136 | &endbadly, |
142 | GNUNET_asprintf (&hostkey_file, | 137 | NULL); |
143 | "zonefiles%s%s", | 138 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
144 | DIR_SEPARATOR_STR, | ||
145 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
147 | "Using zonekey file `%s' \n", | ||
148 | hostkey_file); | ||
149 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
150 | GNUNET_free (hostkey_file); | ||
151 | GNUNET_assert (privkey != NULL); | 139 | GNUNET_assert (privkey != NULL); |
152 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 140 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); |
153 | 141 | ||
@@ -174,6 +162,8 @@ main (int argc, char *argv[]) | |||
174 | GNUNET_asprintf (&cfg_name, | 162 | GNUNET_asprintf (&cfg_name, |
175 | "test_namestore_api_%s.conf", | 163 | "test_namestore_api_%s.conf", |
176 | plugin_name); | 164 | plugin_name); |
165 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
166 | "GNUNET_TEST_HOME"); | ||
177 | res = 1; | 167 | res = 1; |
178 | if (0 != | 168 | if (0 != |
179 | GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record", | 169 | GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record", |
@@ -183,12 +173,9 @@ main (int argc, char *argv[]) | |||
183 | { | 173 | { |
184 | res = 1; | 174 | res = 1; |
185 | } | 175 | } |
176 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
177 | "GNUNET_TEST_HOME"); | ||
186 | GNUNET_free (cfg_name); | 178 | GNUNET_free (cfg_name); |
187 | if (NULL != directory) | ||
188 | { | ||
189 | GNUNET_DISK_directory_remove (directory); | ||
190 | GNUNET_free (directory); | ||
191 | } | ||
192 | return res; | 179 | return res; |
193 | } | 180 | } |
194 | 181 | ||
diff --git a/src/namestore/test_namestore_api_sqlite.conf b/src/namestore/test_namestore_api_sqlite.conf index 5416daec3..82663400a 100644 --- a/src/namestore/test_namestore_api_sqlite.conf +++ b/src/namestore/test_namestore_api_sqlite.conf | |||
@@ -2,3 +2,6 @@ | |||
2 | 2 | ||
3 | [namestore] | 3 | [namestore] |
4 | DATABASE = sqlite | 4 | DATABASE = sqlite |
5 | |||
6 | [namestore-sqlite] | ||
7 | FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db | ||
diff --git a/src/namestore/test_namestore_api_store.c b/src/namestore/test_namestore_api_store.c index 4e51678a1..4abcfa4d3 100644 --- a/src/namestore/test_namestore_api_store.c +++ b/src/namestore/test_namestore_api_store.c | |||
@@ -46,7 +46,6 @@ static int res; | |||
46 | 46 | ||
47 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | 47 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; |
48 | 48 | ||
49 | static char *directory; | ||
50 | 49 | ||
51 | static void | 50 | static void |
52 | cleanup () | 51 | cleanup () |
@@ -114,23 +113,11 @@ run (void *cls, | |||
114 | struct GNUNET_TESTING_Peer *peer) | 113 | struct GNUNET_TESTING_Peer *peer) |
115 | { | 114 | { |
116 | struct GNUNET_GNSRECORD_Data rd; | 115 | struct GNUNET_GNSRECORD_Data rd; |
117 | char *hostkey_file; | ||
118 | const char * name = "dummy.dummy.gnunet"; | 116 | const char * name = "dummy.dummy.gnunet"; |
119 | 117 | ||
120 | directory = NULL; | ||
121 | GNUNET_assert (GNUNET_OK == | ||
122 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory)); | ||
123 | GNUNET_DISK_directory_remove (directory); | ||
124 | |||
125 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 118 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
126 | &endbadly, NULL); | 119 | &endbadly, NULL); |
127 | GNUNET_asprintf (&hostkey_file, | 120 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
128 | "zonefiles%s%s", | ||
129 | DIR_SEPARATOR_STR, | ||
130 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
131 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
132 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
133 | GNUNET_free (hostkey_file); | ||
134 | GNUNET_assert (privkey != NULL); | 121 | GNUNET_assert (privkey != NULL); |
135 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 122 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); |
136 | 123 | ||
@@ -144,8 +131,13 @@ run (void *cls, | |||
144 | 131 | ||
145 | nsh = GNUNET_NAMESTORE_connect (cfg); | 132 | nsh = GNUNET_NAMESTORE_connect (cfg); |
146 | GNUNET_break (NULL != nsh); | 133 | GNUNET_break (NULL != nsh); |
147 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | 134 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
148 | 1, &rd, &put_cont, (void *) name); | 135 | privkey, |
136 | name, | ||
137 | 1, | ||
138 | &rd, | ||
139 | &put_cont, | ||
140 | (void *) name); | ||
149 | if (NULL == nsqe) | 141 | if (NULL == nsqe) |
150 | { | 142 | { |
151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 143 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -167,6 +159,8 @@ main (int argc, char *argv[]) | |||
167 | "test_namestore_api_%s.conf", | 159 | "test_namestore_api_%s.conf", |
168 | plugin_name); | 160 | plugin_name); |
169 | res = 1; | 161 | res = 1; |
162 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
163 | "GNUNET_TEST_HOME"); | ||
170 | if (0 != | 164 | if (0 != |
171 | GNUNET_TESTING_peer_run ("test-namestore-api", | 165 | GNUNET_TESTING_peer_run ("test-namestore-api", |
172 | cfg_name, | 166 | cfg_name, |
@@ -175,12 +169,9 @@ main (int argc, char *argv[]) | |||
175 | { | 169 | { |
176 | res = 1; | 170 | res = 1; |
177 | } | 171 | } |
172 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
173 | "GNUNET_TEST_HOME"); | ||
178 | GNUNET_free (cfg_name); | 174 | GNUNET_free (cfg_name); |
179 | if (NULL != directory) | ||
180 | { | ||
181 | GNUNET_DISK_directory_remove (directory); | ||
182 | GNUNET_free (directory); | ||
183 | } | ||
184 | return res; | 175 | return res; |
185 | } | 176 | } |
186 | 177 | ||
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c index 0a4551f21..7b13cd9c5 100644 --- a/src/namestore/test_namestore_api_store_update.c +++ b/src/namestore/test_namestore_api_store_update.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012, 2013 GNUnet e.V. | 3 | Copyright (C) 2012, 2013, 2018 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -21,6 +21,7 @@ | |||
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 |
23 | * @author Matthias Wachs | 23 | * @author Matthias Wachs |
24 | * @author Christian Grothoff | ||
24 | */ | 25 | */ |
25 | #include "platform.h" | 26 | #include "platform.h" |
26 | #include "gnunet_namecache_service.h" | 27 | #include "gnunet_namecache_service.h" |
@@ -33,7 +34,6 @@ | |||
33 | 34 | ||
34 | #define TEST_RECORD_DATA 'a' | 35 | #define TEST_RECORD_DATA 'a' |
35 | 36 | ||
36 | |||
37 | #define TEST_RECORD_TYPE2 4321 | 37 | #define TEST_RECORD_TYPE2 4321 |
38 | 38 | ||
39 | #define TEST_RECORD_DATALEN2 234 | 39 | #define TEST_RECORD_DATALEN2 234 |
@@ -63,38 +63,30 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe; | |||
63 | 63 | ||
64 | static const char *name = "dummy"; | 64 | static const char *name = "dummy"; |
65 | 65 | ||
66 | static char *directory; | ||
67 | 66 | ||
67 | /** | ||
68 | * Terminate test with error. | ||
69 | * | ||
70 | * @param cls handle to use to re-connect. | ||
71 | */ | ||
68 | static void | 72 | static void |
69 | cleanup () | 73 | endbadly (void *cls) |
70 | { | 74 | { |
71 | if (NULL != nsh) | 75 | GNUNET_break (0); |
72 | { | 76 | endbadly_task = NULL; |
73 | GNUNET_NAMESTORE_disconnect (nsh); | ||
74 | nsh = NULL; | ||
75 | } | ||
76 | if (NULL != nch) | ||
77 | { | ||
78 | GNUNET_NAMECACHE_disconnect (nch); | ||
79 | nch = NULL; | ||
80 | } | ||
81 | if (NULL != privkey) | ||
82 | { | ||
83 | GNUNET_free (privkey); | ||
84 | privkey = NULL; | ||
85 | } | ||
86 | GNUNET_SCHEDULER_shutdown (); | 77 | GNUNET_SCHEDULER_shutdown (); |
78 | res = 1; | ||
87 | } | 79 | } |
88 | 80 | ||
89 | 81 | ||
90 | /** | ||
91 | * Re-establish the connection to the service. | ||
92 | * | ||
93 | * @param cls handle to use to re-connect. | ||
94 | */ | ||
95 | static void | 82 | static void |
96 | endbadly (void *cls) | 83 | end (void *cls) |
97 | { | 84 | { |
85 | if (NULL != endbadly_task) | ||
86 | { | ||
87 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
88 | endbadly_task = NULL; | ||
89 | } | ||
98 | if (NULL != nsqe) | 90 | if (NULL != nsqe) |
99 | { | 91 | { |
100 | GNUNET_NAMESTORE_cancel (nsqe); | 92 | GNUNET_NAMESTORE_cancel (nsqe); |
@@ -105,21 +97,28 @@ endbadly (void *cls) | |||
105 | GNUNET_NAMECACHE_cancel (ncqe); | 97 | GNUNET_NAMECACHE_cancel (ncqe); |
106 | ncqe = NULL; | 98 | ncqe = NULL; |
107 | } | 99 | } |
108 | cleanup (); | 100 | if (NULL != nsh) |
109 | res = 1; | 101 | { |
110 | } | 102 | GNUNET_NAMESTORE_disconnect (nsh); |
111 | 103 | nsh = NULL; | |
112 | 104 | } | |
113 | static void | 105 | if (NULL != nch) |
114 | end (void *cls) | 106 | { |
115 | { | 107 | GNUNET_NAMECACHE_disconnect (nch); |
116 | cleanup (); | 108 | nch = NULL; |
117 | res = 0; | 109 | } |
110 | if (NULL != privkey) | ||
111 | { | ||
112 | GNUNET_free (privkey); | ||
113 | privkey = NULL; | ||
114 | } | ||
118 | } | 115 | } |
119 | 116 | ||
120 | 117 | ||
121 | static void | 118 | static void |
122 | put_cont (void *cls, int32_t success, const char *emsg); | 119 | put_cont (void *cls, |
120 | int32_t success, | ||
121 | const char *emsg); | ||
123 | 122 | ||
124 | 123 | ||
125 | static void | 124 | static void |
@@ -135,11 +134,15 @@ rd_decrypt_cb (void *cls, | |||
135 | if (GNUNET_NO == update_performed) | 134 | if (GNUNET_NO == update_performed) |
136 | { | 135 | { |
137 | char rd_cmp_data[TEST_RECORD_DATALEN]; | 136 | char rd_cmp_data[TEST_RECORD_DATALEN]; |
138 | memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | ||
139 | 137 | ||
138 | memset (rd_cmp_data, | ||
139 | TEST_RECORD_DATA, | ||
140 | TEST_RECORD_DATALEN); | ||
140 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); | 141 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); |
141 | GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); | 142 | GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); |
142 | GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)); | 143 | GNUNET_assert (0 == memcmp (&rd_cmp_data, |
144 | rd[0].data, | ||
145 | TEST_RECORD_DATALEN)); | ||
143 | 146 | ||
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
145 | "Block was decrypted successfully, updating record \n"); | 148 | "Block was decrypted successfully, updating record \n"); |
@@ -149,24 +152,33 @@ rd_decrypt_cb (void *cls, | |||
149 | rd_new.record_type = TEST_RECORD_TYPE2; | 152 | rd_new.record_type = TEST_RECORD_TYPE2; |
150 | rd_new.data_size = TEST_RECORD_DATALEN2; | 153 | rd_new.data_size = TEST_RECORD_DATALEN2; |
151 | rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); | 154 | rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); |
152 | memset ((char *) rd_new.data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2); | 155 | memset ((char *) rd_new.data, |
156 | TEST_RECORD_DATA2, | ||
157 | TEST_RECORD_DATALEN2); | ||
153 | 158 | ||
154 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | 159 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
155 | 1, &rd_new, &put_cont, (void *) name); | 160 | privkey, |
161 | name, | ||
162 | 1, | ||
163 | &rd_new, | ||
164 | &put_cont, | ||
165 | (void *) name); | ||
156 | update_performed = GNUNET_YES; | 166 | update_performed = GNUNET_YES; |
157 | } | 167 | } |
158 | else | 168 | else |
159 | { | 169 | { |
160 | char rd_cmp_data[TEST_RECORD_DATALEN2]; | 170 | char rd_cmp_data[TEST_RECORD_DATALEN2]; |
161 | memset (rd_cmp_data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2); | ||
162 | 171 | ||
172 | memset (rd_cmp_data, | ||
173 | TEST_RECORD_DATA2, | ||
174 | TEST_RECORD_DATALEN2); | ||
163 | GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type); | 175 | GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type); |
164 | GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); | 176 | GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); |
165 | GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN2)); | 177 | GNUNET_assert (0 == memcmp (&rd_cmp_data, |
166 | 178 | rd[0].data, | |
167 | GNUNET_SCHEDULER_cancel (endbadly_task); | 179 | TEST_RECORD_DATALEN2)); |
168 | endbadly_task = NULL; | 180 | GNUNET_SCHEDULER_shutdown (); |
169 | GNUNET_SCHEDULER_add_now (&end, NULL); | 181 | res = 0; |
170 | } | 182 | } |
171 | } | 183 | } |
172 | 184 | ||
@@ -184,21 +196,25 @@ name_lookup_proc (void *cls, | |||
184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 196 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
185 | _("Namecache returned no block for `%s'\n"), | 197 | _("Namecache returned no block for `%s'\n"), |
186 | name); | 198 | name); |
187 | if (endbadly_task != NULL) | 199 | GNUNET_SCHEDULER_shutdown (); |
188 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
189 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
190 | return; | 200 | return; |
191 | } | 201 | } |
192 | 202 | ||
193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
194 | "Namecache returned block, decrypting \n"); | 204 | "Namecache returned block, decrypting \n"); |
195 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, | 205 | GNUNET_assert (GNUNET_OK == |
196 | &pubkey, name, &rd_decrypt_cb, (void *) name)); | 206 | GNUNET_GNSRECORD_block_decrypt (block, |
207 | &pubkey, | ||
208 | name, | ||
209 | &rd_decrypt_cb, | ||
210 | (void *) name)); | ||
197 | } | 211 | } |
198 | 212 | ||
199 | 213 | ||
200 | static void | 214 | static void |
201 | put_cont (void *cls, int32_t success, const char *emsg) | 215 | put_cont (void *cls, |
216 | int32_t success, | ||
217 | const char *emsg) | ||
202 | { | 218 | { |
203 | const char *name = cls; | 219 | const char *name = cls; |
204 | struct GNUNET_HashCode derived_hash; | 220 | struct GNUNET_HashCode derived_hash; |
@@ -216,7 +232,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
217 | "Looking in namecache for `%s'\n", | 233 | "Looking in namecache for `%s'\n", |
218 | GNUNET_h2s (&derived_hash)); | 234 | GNUNET_h2s (&derived_hash)); |
219 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, | 235 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, |
236 | &derived_hash, | ||
220 | &name_lookup_proc, (void *) name); | 237 | &name_lookup_proc, (void *) name); |
221 | } | 238 | } |
222 | 239 | ||
@@ -227,41 +244,37 @@ run (void *cls, | |||
227 | struct GNUNET_TESTING_Peer *peer) | 244 | struct GNUNET_TESTING_Peer *peer) |
228 | { | 245 | { |
229 | struct GNUNET_GNSRECORD_Data rd; | 246 | struct GNUNET_GNSRECORD_Data rd; |
230 | char *hostkey_file; | ||
231 | |||
232 | directory = NULL; | ||
233 | GNUNET_assert (GNUNET_OK == | ||
234 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory)); | ||
235 | GNUNET_DISK_directory_remove (directory); | ||
236 | 247 | ||
237 | update_performed = GNUNET_NO; | 248 | update_performed = GNUNET_NO; |
249 | GNUNET_SCHEDULER_add_shutdown (&end, | ||
250 | NULL); | ||
238 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 251 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
239 | &endbadly, NULL); | 252 | &endbadly, |
240 | GNUNET_asprintf (&hostkey_file, | 253 | NULL); |
241 | "zonefiles%s%s", | 254 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
242 | DIR_SEPARATOR_STR, | ||
243 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
245 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
246 | GNUNET_free (hostkey_file); | ||
247 | GNUNET_assert (privkey != NULL); | 255 | GNUNET_assert (privkey != NULL); |
248 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 256 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
249 | 257 | &pubkey); | |
250 | rd.flags = GNUNET_GNSRECORD_RF_NONE; | 258 | rd.flags = GNUNET_GNSRECORD_RF_NONE; |
251 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 259 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; |
252 | rd.record_type = TEST_RECORD_TYPE; | 260 | rd.record_type = TEST_RECORD_TYPE; |
253 | rd.data_size = TEST_RECORD_DATALEN; | 261 | rd.data_size = TEST_RECORD_DATALEN; |
254 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); | 262 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); |
255 | memset ((char *) rd.data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | 263 | memset ((char *) rd.data, |
264 | TEST_RECORD_DATA, | ||
265 | TEST_RECORD_DATALEN); | ||
256 | 266 | ||
257 | nsh = GNUNET_NAMESTORE_connect (cfg); | 267 | nsh = GNUNET_NAMESTORE_connect (cfg); |
258 | GNUNET_break (NULL != nsh); | 268 | GNUNET_break (NULL != nsh); |
259 | nch = GNUNET_NAMECACHE_connect (cfg); | 269 | nch = GNUNET_NAMECACHE_connect (cfg); |
260 | GNUNET_break (NULL != nch); | 270 | GNUNET_break (NULL != nch); |
261 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | 271 | nsqe = GNUNET_NAMESTORE_records_store (nsh, |
262 | privkey, name, | 272 | privkey, |
263 | 1, &rd, | 273 | name, |
264 | &put_cont, (void *) name); | 274 | 1, |
275 | &rd, | ||
276 | &put_cont, | ||
277 | (void *) name); | ||
265 | if (NULL == nsqe) | 278 | if (NULL == nsqe) |
266 | { | 279 | { |
267 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -272,7 +285,8 @@ run (void *cls, | |||
272 | 285 | ||
273 | 286 | ||
274 | int | 287 | int |
275 | main (int argc, char *argv[]) | 288 | main (int argc, |
289 | char *argv[]) | ||
276 | { | 290 | { |
277 | const char *plugin_name; | 291 | const char *plugin_name; |
278 | char *cfg_name; | 292 | char *cfg_name; |
@@ -282,6 +296,8 @@ main (int argc, char *argv[]) | |||
282 | "test_namestore_api_%s.conf", | 296 | "test_namestore_api_%s.conf", |
283 | plugin_name); | 297 | plugin_name); |
284 | res = 1; | 298 | res = 1; |
299 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
300 | "GNUNET_TEST_HOME"); | ||
285 | if (0 != | 301 | if (0 != |
286 | GNUNET_TESTING_peer_run ("test-namestore-api-store-update", | 302 | GNUNET_TESTING_peer_run ("test-namestore-api-store-update", |
287 | cfg_name, | 303 | cfg_name, |
@@ -290,14 +306,11 @@ main (int argc, char *argv[]) | |||
290 | { | 306 | { |
291 | res = 1; | 307 | res = 1; |
292 | } | 308 | } |
309 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
310 | "GNUNET_TEST_HOME"); | ||
293 | GNUNET_free (cfg_name); | 311 | GNUNET_free (cfg_name); |
294 | if (NULL != directory) | ||
295 | { | ||
296 | GNUNET_DISK_directory_remove (directory); | ||
297 | GNUNET_free (directory); | ||
298 | } | ||
299 | return res; | 312 | return res; |
300 | } | 313 | } |
301 | 314 | ||
302 | 315 | ||
303 | /* end of test_namestore_api_store_update.c*/ | 316 | /* end of test_namestore_api_store_update.c */ |
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index 806605d94..68c3de9b8 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013, 2018 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -56,8 +56,6 @@ static char * s_name_3; | |||
56 | 56 | ||
57 | static struct GNUNET_GNSRECORD_Data *s_rd_3; | 57 | static struct GNUNET_GNSRECORD_Data *s_rd_3; |
58 | 58 | ||
59 | static char *directory; | ||
60 | |||
61 | 59 | ||
62 | /** | 60 | /** |
63 | * Re-establish the connection to the service. | 61 | * Re-establish the connection to the service. |
@@ -68,43 +66,8 @@ static char *directory; | |||
68 | static void | 66 | static void |
69 | endbadly (void *cls) | 67 | endbadly (void *cls) |
70 | { | 68 | { |
71 | if (NULL != zi) | 69 | endbadly_task = NULL; |
72 | { | 70 | GNUNET_SCHEDULER_shutdown (); |
73 | GNUNET_NAMESTORE_zone_iteration_stop (zi); | ||
74 | zi = NULL; | ||
75 | } | ||
76 | if (nsh != NULL) | ||
77 | { | ||
78 | GNUNET_NAMESTORE_disconnect (nsh); | ||
79 | nsh = NULL; | ||
80 | } | ||
81 | GNUNET_free_non_null(s_name_1); | ||
82 | GNUNET_free_non_null(s_name_2); | ||
83 | GNUNET_free_non_null(s_name_3); | ||
84 | |||
85 | if (s_rd_1 != NULL) | ||
86 | { | ||
87 | GNUNET_free ((void *)s_rd_1->data); | ||
88 | GNUNET_free (s_rd_1); | ||
89 | } | ||
90 | if (s_rd_2 != NULL) | ||
91 | { | ||
92 | GNUNET_free ((void *)s_rd_2->data); | ||
93 | GNUNET_free (s_rd_2); | ||
94 | } | ||
95 | if (s_rd_3 != NULL) | ||
96 | { | ||
97 | GNUNET_free ((void *)s_rd_3->data); | ||
98 | GNUNET_free (s_rd_3); | ||
99 | } | ||
100 | |||
101 | if (privkey != NULL) | ||
102 | GNUNET_free (privkey); | ||
103 | privkey = NULL; | ||
104 | |||
105 | if (privkey2 != NULL) | ||
106 | GNUNET_free (privkey2); | ||
107 | privkey2 = NULL; | ||
108 | res = 1; | 71 | res = 1; |
109 | } | 72 | } |
110 | 73 | ||
@@ -117,41 +80,44 @@ end (void *cls) | |||
117 | GNUNET_NAMESTORE_zone_iteration_stop (zi); | 80 | GNUNET_NAMESTORE_zone_iteration_stop (zi); |
118 | zi = NULL; | 81 | zi = NULL; |
119 | } | 82 | } |
120 | if (endbadly_task != NULL) | 83 | if (NULL != endbadly_task) |
121 | { | 84 | { |
122 | GNUNET_SCHEDULER_cancel (endbadly_task); | 85 | GNUNET_SCHEDULER_cancel (endbadly_task); |
123 | endbadly_task = NULL; | 86 | endbadly_task = NULL; |
124 | } | 87 | } |
125 | 88 | if (NULL != privkey) | |
126 | if (privkey != NULL) | 89 | { |
127 | GNUNET_free (privkey); | 90 | GNUNET_free (privkey); |
128 | privkey = NULL; | 91 | privkey = NULL; |
129 | 92 | } | |
130 | if (privkey2 != NULL) | 93 | if (NULL != privkey2) |
94 | { | ||
131 | GNUNET_free (privkey2); | 95 | GNUNET_free (privkey2); |
132 | privkey2 = NULL; | 96 | privkey2 = NULL; |
133 | 97 | } | |
134 | GNUNET_free (s_name_1); | 98 | GNUNET_free (s_name_1); |
135 | GNUNET_free (s_name_2); | 99 | GNUNET_free (s_name_2); |
136 | GNUNET_free (s_name_3); | 100 | GNUNET_free (s_name_3); |
137 | if (s_rd_1 != NULL) | 101 | if (NULL != s_rd_1) |
138 | { | 102 | { |
139 | GNUNET_free ((void *)s_rd_1->data); | 103 | GNUNET_free ((void *)s_rd_1->data); |
140 | GNUNET_free (s_rd_1); | 104 | GNUNET_free (s_rd_1); |
141 | } | 105 | } |
142 | if (s_rd_2 != NULL) | 106 | if (NULL != s_rd_2) |
143 | { | 107 | { |
144 | GNUNET_free ((void *)s_rd_2->data); | 108 | GNUNET_free ((void *)s_rd_2->data); |
145 | GNUNET_free (s_rd_2); | 109 | GNUNET_free (s_rd_2); |
146 | } | 110 | } |
147 | if (s_rd_3 != NULL) | 111 | if (NULL != s_rd_3) |
148 | { | 112 | { |
149 | GNUNET_free ((void *)s_rd_3->data); | 113 | GNUNET_free ((void *)s_rd_3->data); |
150 | GNUNET_free (s_rd_3); | 114 | GNUNET_free (s_rd_3); |
151 | } | 115 | } |
152 | if (nsh != NULL) | 116 | if (NULL != nsh) |
117 | { | ||
153 | GNUNET_NAMESTORE_disconnect (nsh); | 118 | GNUNET_NAMESTORE_disconnect (nsh); |
154 | nsh = NULL; | 119 | nsh = NULL; |
120 | } | ||
155 | } | 121 | } |
156 | 122 | ||
157 | 123 | ||
@@ -170,7 +136,7 @@ zone_end (void *cls) | |||
170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
171 | "Received last result, iteration done after receing %u results\n", | 137 | "Received last result, iteration done after receing %u results\n", |
172 | returned_records); | 138 | returned_records); |
173 | GNUNET_SCHEDULER_add_now (&end, NULL); | 139 | GNUNET_SCHEDULER_shutdown (); |
174 | } | 140 | } |
175 | 141 | ||
176 | 142 | ||
@@ -191,7 +157,9 @@ zone_proc (void *cls, | |||
191 | int failed = GNUNET_NO; | 157 | int failed = GNUNET_NO; |
192 | 158 | ||
193 | GNUNET_assert (NULL != zone); | 159 | GNUNET_assert (NULL != zone); |
194 | if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | 160 | if (0 == memcmp (zone, |
161 | privkey, | ||
162 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | ||
195 | { | 163 | { |
196 | if (0 == strcmp (label, s_name_1)) | 164 | if (0 == strcmp (label, s_name_1)) |
197 | { | 165 | { |
@@ -230,12 +198,15 @@ zone_proc (void *cls, | |||
230 | else | 198 | else |
231 | { | 199 | { |
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
233 | "Comparing result failed: got name `%s' for first zone\n", label); | 201 | "Comparing result failed: got name `%s' for first zone\n", |
202 | label); | ||
234 | failed = GNUNET_YES; | 203 | failed = GNUNET_YES; |
235 | GNUNET_break (0); | 204 | GNUNET_break (0); |
236 | } | 205 | } |
237 | } | 206 | } |
238 | else if (0 == memcmp (zone, privkey2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | 207 | else if (0 == memcmp (zone, |
208 | privkey2, | ||
209 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | ||
239 | { | 210 | { |
240 | if (0 == strcmp (label, s_name_3)) | 211 | if (0 == strcmp (label, s_name_3)) |
241 | { | 212 | { |
@@ -258,7 +229,8 @@ zone_proc (void *cls, | |||
258 | else | 229 | else |
259 | { | 230 | { |
260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
261 | "Comparing result failed: got name `%s' for first zone\n", label); | 232 | "Comparing result failed: got name `%s' for first zone\n", |
233 | label); | ||
262 | failed = GNUNET_YES; | 234 | failed = GNUNET_YES; |
263 | GNUNET_break (0); | 235 | GNUNET_break (0); |
264 | } | 236 | } |
@@ -282,29 +254,34 @@ zone_proc (void *cls, | |||
282 | else | 254 | else |
283 | { | 255 | { |
284 | GNUNET_break (0); | 256 | GNUNET_break (0); |
285 | GNUNET_SCHEDULER_add_now (&end, NULL); | 257 | GNUNET_SCHEDULER_shutdown (); |
258 | res = 1; | ||
286 | } | 259 | } |
287 | } | 260 | } |
288 | 261 | ||
289 | 262 | ||
290 | static void | 263 | static void |
291 | put_cont (void *cls, int32_t success, const char *emsg) | 264 | put_cont (void *cls, |
265 | int32_t success, | ||
266 | const char *emsg) | ||
292 | { | 267 | { |
293 | static int c = 0; | 268 | static int c = 0; |
294 | 269 | ||
295 | if (success == GNUNET_OK) | 270 | if (success == GNUNET_OK) |
296 | { | 271 | { |
297 | c++; | 272 | c++; |
298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); | 273 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
274 | "Created record %u \n", | ||
275 | c); | ||
299 | } | 276 | } |
300 | else | 277 | else |
301 | { | 278 | { |
302 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", | 279 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
280 | "Failed to created records: `%s'\n", | ||
303 | emsg); | 281 | emsg); |
304 | GNUNET_break (0); | 282 | GNUNET_break (0); |
305 | if (NULL != endbadly_task) | 283 | GNUNET_SCHEDULER_shutdown (); |
306 | GNUNET_SCHEDULER_cancel (endbadly_task); | 284 | res = 1; |
307 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
308 | return; | 285 | return; |
309 | } | 286 | } |
310 | 287 | ||
@@ -312,7 +289,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
312 | { | 289 | { |
313 | res = 1; | 290 | res = 1; |
314 | returned_records = 0; | 291 | returned_records = 0; |
315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
293 | "All records created, starting iteration over all zones \n"); | ||
316 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, | 294 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, |
317 | NULL, | 295 | NULL, |
318 | &fail_cb, | 296 | &fail_cb, |
@@ -323,11 +301,11 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
323 | NULL); | 301 | NULL); |
324 | if (zi == NULL) | 302 | if (zi == NULL) |
325 | { | 303 | { |
326 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); | 304 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
305 | "Failed to create zone iterator\n"); | ||
327 | GNUNET_break (0); | 306 | GNUNET_break (0); |
328 | if (NULL != endbadly_task) | 307 | GNUNET_SCHEDULER_shutdown (); |
329 | GNUNET_SCHEDULER_cancel (endbadly_task); | 308 | res = 1; |
330 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
331 | return; | 309 | return; |
332 | } | 310 | } |
333 | } | 311 | } |
@@ -337,11 +315,11 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
337 | static struct GNUNET_GNSRECORD_Data * | 315 | static struct GNUNET_GNSRECORD_Data * |
338 | create_record (unsigned int count) | 316 | create_record (unsigned int count) |
339 | { | 317 | { |
340 | unsigned int c; | ||
341 | struct GNUNET_GNSRECORD_Data * rd; | 318 | struct GNUNET_GNSRECORD_Data * rd; |
342 | 319 | ||
343 | rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); | 320 | rd = GNUNET_new_array (count, |
344 | for (c = 0; c < count; c++) | 321 | struct GNUNET_GNSRECORD_Data); |
322 | for (unsigned int c = 0; c < count; c++) | ||
345 | { | 323 | { |
346 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; | 324 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; |
347 | rd[c].record_type = 1111; | 325 | rd[c].record_type = 1111; |
@@ -372,9 +350,8 @@ empty_zone_proc (void *cls, | |||
372 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 350 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
373 | _("Expected empty zone but received zone private key\n")); | 351 | _("Expected empty zone but received zone private key\n")); |
374 | GNUNET_break (0); | 352 | GNUNET_break (0); |
375 | if (endbadly_task != NULL) | 353 | GNUNET_SCHEDULER_shutdown (); |
376 | GNUNET_SCHEDULER_cancel (endbadly_task); | 354 | res = 1; |
377 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
378 | return; | 355 | return; |
379 | } | 356 | } |
380 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) | 357 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) |
@@ -382,9 +359,8 @@ empty_zone_proc (void *cls, | |||
382 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 359 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
383 | _("Expected no zone content but received data\n")); | 360 | _("Expected no zone content but received data\n")); |
384 | GNUNET_break (0); | 361 | GNUNET_break (0); |
385 | if (endbadly_task != NULL) | 362 | GNUNET_SCHEDULER_shutdown (); |
386 | GNUNET_SCHEDULER_cancel (endbadly_task); | 363 | res = 1; |
387 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
388 | return; | 364 | return; |
389 | } | 365 | } |
390 | GNUNET_assert (0); | 366 | GNUNET_assert (0); |
@@ -412,7 +388,9 @@ empty_zone_end (void *cls) | |||
412 | "zonefiles%s%s", | 388 | "zonefiles%s%s", |
413 | DIR_SEPARATOR_STR, | 389 | DIR_SEPARATOR_STR, |
414 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); | 390 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); |
415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | 391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
392 | "Using zonekey file `%s' \n", | ||
393 | hostkey_file); | ||
416 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | 394 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); |
417 | GNUNET_free (hostkey_file); | 395 | GNUNET_free (hostkey_file); |
418 | GNUNET_assert (privkey2 != NULL); | 396 | GNUNET_assert (privkey2 != NULL); |
@@ -425,8 +403,8 @@ empty_zone_end (void *cls) | |||
425 | privkey, | 403 | privkey, |
426 | s_name_1, | 404 | s_name_1, |
427 | 1, s_rd_1, | 405 | 1, s_rd_1, |
428 | &put_cont, NULL); | 406 | &put_cont, |
429 | 407 | NULL); | |
430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
431 | "Created record 2 \n"); | 409 | "Created record 2 \n"); |
432 | GNUNET_asprintf(&s_name_2, "dummy2"); | 410 | GNUNET_asprintf(&s_name_2, "dummy2"); |
@@ -437,16 +415,18 @@ empty_zone_end (void *cls) | |||
437 | 1, s_rd_2, | 415 | 1, s_rd_2, |
438 | &put_cont, | 416 | &put_cont, |
439 | NULL); | 417 | NULL); |
440 | |||
441 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
442 | "Created record 3\n"); | 419 | "Created record 3\n"); |
443 | |||
444 | /* name in different zone */ | 420 | /* name in different zone */ |
445 | GNUNET_asprintf(&s_name_3, "dummy3"); | 421 | GNUNET_asprintf(&s_name_3, "dummy3"); |
446 | s_rd_3 = create_record(1); | 422 | s_rd_3 = create_record(1); |
447 | GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, | 423 | GNUNET_NAMESTORE_records_store (nsh, |
448 | 1, s_rd_3, | 424 | privkey2, |
449 | &put_cont, NULL); | 425 | s_name_3, |
426 | 1, | ||
427 | s_rd_3, | ||
428 | &put_cont, | ||
429 | NULL); | ||
450 | } | 430 | } |
451 | 431 | ||
452 | 432 | ||
@@ -455,31 +435,30 @@ run (void *cls, | |||
455 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 435 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
456 | struct GNUNET_TESTING_Peer *peer) | 436 | struct GNUNET_TESTING_Peer *peer) |
457 | { | 437 | { |
458 | directory = NULL; | 438 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
459 | GNUNET_assert (GNUNET_OK == | 439 | &endbadly, |
460 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", | 440 | NULL); |
461 | "GNUNET_TEST_HOME", | 441 | GNUNET_SCHEDULER_add_shutdown (&end, |
462 | &directory)); | 442 | NULL); |
463 | GNUNET_DISK_directory_remove (directory); | 443 | |
464 | |||
465 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); | ||
466 | nsh = GNUNET_NAMESTORE_connect (cfg); | 444 | nsh = GNUNET_NAMESTORE_connect (cfg); |
467 | GNUNET_break (NULL != nsh); | 445 | GNUNET_break (NULL != nsh); |
468 | /* first, iterate over empty namestore */ | 446 | /* first, iterate over empty namestore */ |
469 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | 447 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, |
470 | NULL, | 448 | NULL, |
471 | &fail_cb, | 449 | &fail_cb, |
472 | NULL, | 450 | NULL, |
473 | &empty_zone_proc, | 451 | &empty_zone_proc, |
474 | nsh, | 452 | nsh, |
475 | &empty_zone_end, | 453 | &empty_zone_end, |
476 | NULL); | 454 | NULL); |
477 | if (NULL == zi) | 455 | if (NULL == zi) |
478 | { | 456 | { |
479 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); | 457 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
458 | "Failed to create zone iterator\n"); | ||
480 | GNUNET_break (0); | 459 | GNUNET_break (0); |
481 | GNUNET_SCHEDULER_cancel (endbadly_task); | 460 | res = 1; |
482 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | 461 | GNUNET_SCHEDULER_shutdown (); |
483 | } | 462 | } |
484 | } | 463 | } |
485 | 464 | ||
@@ -494,6 +473,8 @@ main (int argc, char *argv[]) | |||
494 | GNUNET_asprintf (&cfg_name, | 473 | GNUNET_asprintf (&cfg_name, |
495 | "test_namestore_api_%s.conf", | 474 | "test_namestore_api_%s.conf", |
496 | plugin_name); | 475 | plugin_name); |
476 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
477 | "GNUNET_TEST_HOME"); | ||
497 | res = 1; | 478 | res = 1; |
498 | if (0 != | 479 | if (0 != |
499 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration", | 480 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration", |
@@ -503,12 +484,9 @@ main (int argc, char *argv[]) | |||
503 | { | 484 | { |
504 | res = 1; | 485 | res = 1; |
505 | } | 486 | } |
487 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
488 | "GNUNET_TEST_HOME"); | ||
506 | GNUNET_free (cfg_name); | 489 | GNUNET_free (cfg_name); |
507 | if (NULL != directory) | ||
508 | { | ||
509 | GNUNET_DISK_directory_remove (directory); | ||
510 | GNUNET_free (directory); | ||
511 | } | ||
512 | return res; | 490 | return res; |
513 | } | 491 | } |
514 | 492 | ||
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c index a88646864..d950b7e69 100644 --- a/src/namestore/test_namestore_api_zone_iteration_nick.c +++ b/src/namestore/test_namestore_api_zone_iteration_nick.c | |||
@@ -60,7 +60,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3; | |||
60 | 60 | ||
61 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | 61 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; |
62 | 62 | ||
63 | static char *directory; | ||
64 | 63 | ||
65 | /** | 64 | /** |
66 | * Re-establish the connection to the service. | 65 | * Re-establish the connection to the service. |
@@ -265,7 +264,9 @@ fail_cb (void *cls) | |||
265 | 264 | ||
266 | 265 | ||
267 | static void | 266 | static void |
268 | put_cont (void *cls, int32_t success, const char *emsg) | 267 | put_cont (void *cls, |
268 | int32_t success, | ||
269 | const char *emsg) | ||
269 | { | 270 | { |
270 | static int c = 0; | 271 | static int c = 0; |
271 | 272 | ||
@@ -314,11 +315,11 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
314 | static struct GNUNET_GNSRECORD_Data * | 315 | static struct GNUNET_GNSRECORD_Data * |
315 | create_record (unsigned int count) | 316 | create_record (unsigned int count) |
316 | { | 317 | { |
317 | unsigned int c; | ||
318 | struct GNUNET_GNSRECORD_Data * rd; | 318 | struct GNUNET_GNSRECORD_Data * rd; |
319 | 319 | ||
320 | rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); | 320 | rd = GNUNET_new_array (count, |
321 | for (c = 0; c < count; c++) | 321 | struct GNUNET_GNSRECORD_Data); |
322 | for (unsigned int c = 0; c < count; c++) | ||
322 | { | 323 | { |
323 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; | 324 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; |
324 | rd[c].record_type = 1111; | 325 | rd[c].record_type = 1111; |
@@ -332,7 +333,9 @@ create_record (unsigned int count) | |||
332 | 333 | ||
333 | 334 | ||
334 | static void | 335 | static void |
335 | nick_2_cont (void *cls, int32_t success, const char *emsg) | 336 | nick_2_cont (void *cls, |
337 | int32_t success, | ||
338 | const char *emsg) | ||
336 | { | 339 | { |
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
338 | "Nick added : %s\n", | 341 | "Nick added : %s\n", |
@@ -422,25 +425,18 @@ empty_zone_proc (void *cls, | |||
422 | static void | 425 | static void |
423 | empty_zone_end (void *cls) | 426 | empty_zone_end (void *cls) |
424 | { | 427 | { |
425 | char *hostkey_file; | ||
426 | GNUNET_assert (nsh == cls); | 428 | GNUNET_assert (nsh == cls); |
427 | |||
428 | zi = NULL; | 429 | zi = NULL; |
429 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, | 430 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
430 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
431 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
432 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | ||
433 | GNUNET_free (hostkey_file); | ||
434 | GNUNET_assert (privkey != NULL); | 431 | GNUNET_assert (privkey != NULL); |
435 | 432 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); | |
436 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, | ||
437 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); | ||
438 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
439 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | ||
440 | GNUNET_free (hostkey_file); | ||
441 | GNUNET_assert (privkey2 != NULL); | 433 | GNUNET_assert (privkey2 != NULL); |
442 | 434 | ||
443 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, ZONE_NICK_1, &nick_1_cont, &privkey); | 435 | nsqe = GNUNET_NAMESTORE_set_nick (nsh, |
436 | privkey, | ||
437 | ZONE_NICK_1, | ||
438 | &nick_1_cont, | ||
439 | &privkey); | ||
444 | if (NULL == nsqe) | 440 | if (NULL == nsqe) |
445 | { | 441 | { |
446 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 442 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -455,15 +451,9 @@ run (void *cls, | |||
455 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 451 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
456 | struct GNUNET_TESTING_Peer *peer) | 452 | struct GNUNET_TESTING_Peer *peer) |
457 | { | 453 | { |
458 | directory = NULL; | 454 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
459 | GNUNET_assert (GNUNET_OK == | 455 | &endbadly, |
460 | GNUNET_CONFIGURATION_get_value_string (cfg, | 456 | NULL); |
461 | "PATHS", | ||
462 | "GNUNET_TEST_HOME", | ||
463 | &directory)); | ||
464 | GNUNET_DISK_directory_remove (directory); | ||
465 | |||
466 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); | ||
467 | nsh = GNUNET_NAMESTORE_connect (cfg); | 457 | nsh = GNUNET_NAMESTORE_connect (cfg); |
468 | GNUNET_break (NULL != nsh); | 458 | GNUNET_break (NULL != nsh); |
469 | 459 | ||
@@ -498,6 +488,8 @@ main (int argc, char *argv[]) | |||
498 | "test_namestore_api_%s.conf", | 488 | "test_namestore_api_%s.conf", |
499 | plugin_name); | 489 | plugin_name); |
500 | res = 1; | 490 | res = 1; |
491 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
492 | "GNUNET_TEST_HOME"); | ||
501 | if (0 != | 493 | if (0 != |
502 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick", | 494 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick", |
503 | cfg_name, | 495 | cfg_name, |
@@ -506,12 +498,9 @@ main (int argc, char *argv[]) | |||
506 | { | 498 | { |
507 | res = 1; | 499 | res = 1; |
508 | } | 500 | } |
501 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
502 | "GNUNET_TEST_HOME"); | ||
509 | GNUNET_free (cfg_name); | 503 | GNUNET_free (cfg_name); |
510 | if (NULL != directory) | ||
511 | { | ||
512 | GNUNET_DISK_directory_remove (directory); | ||
513 | GNUNET_free (directory); | ||
514 | } | ||
515 | return res; | 504 | return res; |
516 | } | 505 | } |
517 | 506 | ||
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c index a4fb320e9..0b137cc62 100644 --- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c +++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c | |||
@@ -57,53 +57,17 @@ static char * s_name_3; | |||
57 | 57 | ||
58 | static struct GNUNET_GNSRECORD_Data *s_rd_3; | 58 | static struct GNUNET_GNSRECORD_Data *s_rd_3; |
59 | 59 | ||
60 | static char *directory; | ||
61 | 60 | ||
62 | /** | 61 | /** |
63 | * Re-establish the connection to the service. | 62 | * Handle timeout. |
64 | * | 63 | * |
65 | * @param cls handle to use to re-connect. | 64 | * @param cls handle to use to re-connect. |
66 | * @param tc scheduler context | ||
67 | */ | 65 | */ |
68 | static void | 66 | static void |
69 | endbadly (void *cls) | 67 | endbadly (void *cls) |
70 | { | 68 | { |
71 | if (NULL != zi) | 69 | endbadly_task = NULL; |
72 | { | 70 | GNUNET_SCHEDULER_shutdown (); |
73 | GNUNET_NAMESTORE_zone_iteration_stop (zi); | ||
74 | zi = NULL; | ||
75 | } | ||
76 | if (nsh != NULL) | ||
77 | GNUNET_NAMESTORE_disconnect (nsh); | ||
78 | nsh = NULL; | ||
79 | |||
80 | GNUNET_free_non_null(s_name_1); | ||
81 | GNUNET_free_non_null(s_name_2); | ||
82 | GNUNET_free_non_null(s_name_3); | ||
83 | |||
84 | if (s_rd_1 != NULL) | ||
85 | { | ||
86 | GNUNET_free ((void *)s_rd_1->data); | ||
87 | GNUNET_free (s_rd_1); | ||
88 | } | ||
89 | if (s_rd_2 != NULL) | ||
90 | { | ||
91 | GNUNET_free ((void *)s_rd_2->data); | ||
92 | GNUNET_free (s_rd_2); | ||
93 | } | ||
94 | if (s_rd_3 != NULL) | ||
95 | { | ||
96 | GNUNET_free ((void *)s_rd_3->data); | ||
97 | GNUNET_free (s_rd_3); | ||
98 | } | ||
99 | |||
100 | if (privkey != NULL) | ||
101 | GNUNET_free (privkey); | ||
102 | privkey = NULL; | ||
103 | |||
104 | if (privkey2 != NULL) | ||
105 | GNUNET_free (privkey2); | ||
106 | privkey2 = NULL; | ||
107 | res = 1; | 71 | res = 1; |
108 | } | 72 | } |
109 | 73 | ||
@@ -116,21 +80,21 @@ end (void *cls) | |||
116 | GNUNET_NAMESTORE_zone_iteration_stop (zi); | 80 | GNUNET_NAMESTORE_zone_iteration_stop (zi); |
117 | zi = NULL; | 81 | zi = NULL; |
118 | } | 82 | } |
119 | 83 | if (NULL != endbadly_task) | |
120 | if (endbadly_task != NULL) | ||
121 | { | 84 | { |
122 | GNUNET_SCHEDULER_cancel (endbadly_task); | 85 | GNUNET_SCHEDULER_cancel (endbadly_task); |
123 | endbadly_task = NULL; | 86 | endbadly_task = NULL; |
124 | } | 87 | } |
125 | 88 | if (NULL != privkey) | |
126 | if (privkey != NULL) | 89 | { |
127 | GNUNET_free (privkey); | 90 | GNUNET_free (privkey); |
128 | privkey = NULL; | 91 | privkey = NULL; |
129 | 92 | } | |
130 | if (privkey2 != NULL) | 93 | if (NULL != privkey2) |
94 | { | ||
131 | GNUNET_free (privkey2); | 95 | GNUNET_free (privkey2); |
132 | privkey2 = NULL; | 96 | privkey2 = NULL; |
133 | 97 | } | |
134 | GNUNET_free (s_name_1); | 98 | GNUNET_free (s_name_1); |
135 | GNUNET_free (s_name_2); | 99 | GNUNET_free (s_name_2); |
136 | GNUNET_free (s_name_3); | 100 | GNUNET_free (s_name_3); |
@@ -150,8 +114,10 @@ end (void *cls) | |||
150 | GNUNET_free (s_rd_3); | 114 | GNUNET_free (s_rd_3); |
151 | } | 115 | } |
152 | if (nsh != NULL) | 116 | if (nsh != NULL) |
117 | { | ||
153 | GNUNET_NAMESTORE_disconnect (nsh); | 118 | GNUNET_NAMESTORE_disconnect (nsh); |
154 | nsh = NULL; | 119 | nsh = NULL; |
120 | } | ||
155 | } | 121 | } |
156 | 122 | ||
157 | 123 | ||
@@ -159,6 +125,7 @@ static void | |||
159 | fail_cb (void *cls) | 125 | fail_cb (void *cls) |
160 | { | 126 | { |
161 | GNUNET_assert (0); | 127 | GNUNET_assert (0); |
128 | zi = NULL; | ||
162 | } | 129 | } |
163 | 130 | ||
164 | 131 | ||
@@ -244,7 +211,8 @@ zone_proc (void *cls, | |||
244 | else | 211 | else |
245 | { | 212 | { |
246 | GNUNET_break (0); | 213 | GNUNET_break (0); |
247 | GNUNET_SCHEDULER_add_now (&end, NULL); | 214 | res = 2; |
215 | GNUNET_SCHEDULER_shutdown (); | ||
248 | } | 216 | } |
249 | } | 217 | } |
250 | 218 | ||
@@ -252,24 +220,28 @@ zone_proc (void *cls, | |||
252 | static void | 220 | static void |
253 | zone_proc_end (void *cls) | 221 | zone_proc_end (void *cls) |
254 | { | 222 | { |
223 | zi = NULL; | ||
255 | GNUNET_break (2 == returned_records); | 224 | GNUNET_break (2 == returned_records); |
256 | if (2 == returned_records) | 225 | if (2 == returned_records) |
257 | { | 226 | { |
258 | res = 0; /* Last iteraterator callback, we are done */ | 227 | res = 0; /* Last iteraterator callback, we are done */ |
259 | zi = NULL; | ||
260 | } | 228 | } |
261 | else | 229 | else |
230 | { | ||
262 | res = 1; | 231 | res = 1; |
232 | } | ||
263 | 233 | ||
264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
265 | "Received last result, iteration done after receing %u results\n", | 235 | "Received last result, iteration done after receing %u results\n", |
266 | returned_records); | 236 | returned_records); |
267 | GNUNET_SCHEDULER_add_now (&end, NULL); | 237 | GNUNET_SCHEDULER_shutdown (); |
268 | } | 238 | } |
269 | 239 | ||
270 | 240 | ||
271 | static void | 241 | static void |
272 | put_cont (void *cls, int32_t success, const char *emsg) | 242 | put_cont (void *cls, |
243 | int32_t success, | ||
244 | const char *emsg) | ||
273 | { | 245 | { |
274 | static int c = 0; | 246 | static int c = 0; |
275 | 247 | ||
@@ -285,9 +257,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
285 | "Failed to created records: `%s'\n", | 257 | "Failed to created records: `%s'\n", |
286 | emsg); | 258 | emsg); |
287 | GNUNET_break (0); | 259 | GNUNET_break (0); |
288 | if (NULL != endbadly_task) | 260 | res = 2; |
289 | GNUNET_SCHEDULER_cancel (endbadly_task); | 261 | GNUNET_SCHEDULER_shutdown (); |
290 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
291 | return; | 262 | return; |
292 | } | 263 | } |
293 | 264 | ||
@@ -310,9 +281,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
310 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 281 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
311 | "Failed to create zone iterator\n"); | 282 | "Failed to create zone iterator\n"); |
312 | GNUNET_break (0); | 283 | GNUNET_break (0); |
313 | if (NULL != endbadly_task) | 284 | res = 2; |
314 | GNUNET_SCHEDULER_cancel (endbadly_task); | 285 | GNUNET_SCHEDULER_shutdown (); |
315 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
316 | return; | 286 | return; |
317 | } | 287 | } |
318 | } | 288 | } |
@@ -322,11 +292,11 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
322 | static struct GNUNET_GNSRECORD_Data * | 292 | static struct GNUNET_GNSRECORD_Data * |
323 | create_record (unsigned int count) | 293 | create_record (unsigned int count) |
324 | { | 294 | { |
325 | unsigned int c; | 295 | struct GNUNET_GNSRECORD_Data *rd; |
326 | struct GNUNET_GNSRECORD_Data * rd; | ||
327 | 296 | ||
328 | rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); | 297 | rd = GNUNET_new_array (count, |
329 | for (c = 0; c < count; c++) | 298 | struct GNUNET_GNSRECORD_Data); |
299 | for (unsigned int c = 0; c < count; c++) | ||
330 | { | 300 | { |
331 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; | 301 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; |
332 | rd[c].record_type = 1111; | 302 | rd[c].record_type = 1111; |
@@ -357,9 +327,8 @@ empty_zone_proc (void *cls, | |||
357 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 327 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
358 | _("Expected empty zone but received zone private key\n")); | 328 | _("Expected empty zone but received zone private key\n")); |
359 | GNUNET_break (0); | 329 | GNUNET_break (0); |
360 | if (endbadly_task != NULL) | 330 | res = 2; |
361 | GNUNET_SCHEDULER_cancel (endbadly_task); | 331 | GNUNET_SCHEDULER_shutdown (); |
362 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
363 | return; | 332 | return; |
364 | } | 333 | } |
365 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) | 334 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) |
@@ -367,9 +336,8 @@ empty_zone_proc (void *cls, | |||
367 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 336 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
368 | _("Expected no zone content but received data\n")); | 337 | _("Expected no zone content but received data\n")); |
369 | GNUNET_break (0); | 338 | GNUNET_break (0); |
370 | if (endbadly_task != NULL) | 339 | res = 2; |
371 | GNUNET_SCHEDULER_cancel (endbadly_task); | 340 | GNUNET_SCHEDULER_shutdown (); |
372 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
373 | return; | 341 | return; |
374 | } | 342 | } |
375 | GNUNET_assert (0); | 343 | GNUNET_assert (0); |
@@ -379,35 +347,16 @@ empty_zone_proc (void *cls, | |||
379 | static void | 347 | static void |
380 | empty_zone_proc_end (void *cls) | 348 | empty_zone_proc_end (void *cls) |
381 | { | 349 | { |
382 | char *hostkey_file; | ||
383 | |||
384 | zi = NULL; | 350 | zi = NULL; |
385 | GNUNET_asprintf (&hostkey_file, | 351 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
386 | "zonefiles%s%s", | ||
387 | DIR_SEPARATOR_STR, | ||
388 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
389 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
390 | "Using zonekey file `%s'\n", | ||
391 | hostkey_file); | ||
392 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
393 | GNUNET_free (hostkey_file); | ||
394 | GNUNET_assert (privkey != NULL); | 352 | GNUNET_assert (privkey != NULL); |
395 | 353 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); | |
396 | GNUNET_asprintf(&hostkey_file, | ||
397 | "zonefiles%s%s", | ||
398 | DIR_SEPARATOR_STR, | ||
399 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); | ||
400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
401 | "Using zonekey file `%s' \n", | ||
402 | hostkey_file); | ||
403 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | ||
404 | GNUNET_free (hostkey_file); | ||
405 | GNUNET_assert (privkey2 != NULL); | 354 | GNUNET_assert (privkey2 != NULL); |
406 | 355 | ||
407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
408 | "Created record 1\n"); | 357 | "Created record 1\n"); |
409 | 358 | GNUNET_asprintf (&s_name_1, | |
410 | GNUNET_asprintf(&s_name_1, "dummy1"); | 359 | "dummy1"); |
411 | s_rd_1 = create_record (1); | 360 | s_rd_1 = create_record (1); |
412 | GNUNET_NAMESTORE_records_store (nsh, | 361 | GNUNET_NAMESTORE_records_store (nsh, |
413 | privkey, | 362 | privkey, |
@@ -419,7 +368,8 @@ empty_zone_proc_end (void *cls) | |||
419 | 368 | ||
420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
421 | "Created record 2 \n"); | 370 | "Created record 2 \n"); |
422 | GNUNET_asprintf(&s_name_2, "dummy2"); | 371 | GNUNET_asprintf (&s_name_2, |
372 | "dummy2"); | ||
423 | s_rd_2 = create_record (1); | 373 | s_rd_2 = create_record (1); |
424 | GNUNET_NAMESTORE_records_store (nsh, | 374 | GNUNET_NAMESTORE_records_store (nsh, |
425 | privkey, | 375 | privkey, |
@@ -433,7 +383,8 @@ empty_zone_proc_end (void *cls) | |||
433 | "Created record 3\n"); | 383 | "Created record 3\n"); |
434 | 384 | ||
435 | /* name in different zone */ | 385 | /* name in different zone */ |
436 | GNUNET_asprintf(&s_name_3, "dummy3"); | 386 | GNUNET_asprintf (&s_name_3, |
387 | "dummy3"); | ||
437 | s_rd_3 = create_record (1); | 388 | s_rd_3 = create_record (1); |
438 | GNUNET_NAMESTORE_records_store (nsh, | 389 | GNUNET_NAMESTORE_records_store (nsh, |
439 | privkey2, | 390 | privkey2, |
@@ -449,14 +400,8 @@ run (void *cls, | |||
449 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 400 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
450 | struct GNUNET_TESTING_Peer *peer) | 401 | struct GNUNET_TESTING_Peer *peer) |
451 | { | 402 | { |
452 | directory = NULL; | 403 | GNUNET_SCHEDULER_add_shutdown (&end, |
453 | GNUNET_assert (GNUNET_OK == | 404 | NULL); |
454 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
455 | "PATHS", | ||
456 | "GNUNET_TEST_HOME", | ||
457 | &directory)); | ||
458 | GNUNET_DISK_directory_remove (directory); | ||
459 | |||
460 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 405 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
461 | &endbadly, | 406 | &endbadly, |
462 | NULL); | 407 | NULL); |
@@ -476,8 +421,7 @@ run (void *cls, | |||
476 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 421 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
477 | "Failed to create zone iterator\n"); | 422 | "Failed to create zone iterator\n"); |
478 | GNUNET_break (0); | 423 | GNUNET_break (0); |
479 | GNUNET_SCHEDULER_cancel (endbadly_task); | 424 | GNUNET_SCHEDULER_shutdown (); |
480 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
481 | } | 425 | } |
482 | } | 426 | } |
483 | 427 | ||
@@ -493,6 +437,8 @@ main (int argc, char *argv[]) | |||
493 | "test_namestore_api_%s.conf", | 437 | "test_namestore_api_%s.conf", |
494 | plugin_name); | 438 | plugin_name); |
495 | res = 1; | 439 | res = 1; |
440 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
441 | "GNUNET_TEST_HOME"); | ||
496 | if (0 != | 442 | if (0 != |
497 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone", | 443 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone", |
498 | cfg_name, | 444 | cfg_name, |
@@ -501,12 +447,9 @@ main (int argc, char *argv[]) | |||
501 | { | 447 | { |
502 | res = 1; | 448 | res = 1; |
503 | } | 449 | } |
450 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
451 | "GNUNET_TEST_HOME"); | ||
504 | GNUNET_free (cfg_name); | 452 | GNUNET_free (cfg_name); |
505 | if (NULL != directory) | ||
506 | { | ||
507 | GNUNET_DISK_directory_remove (directory); | ||
508 | GNUNET_free (directory); | ||
509 | } | ||
510 | return res; | 453 | return res; |
511 | } | 454 | } |
512 | 455 | ||
diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c index c7be5fead..c7358fc6e 100644 --- a/src/namestore/test_namestore_api_zone_iteration_stop.c +++ b/src/namestore/test_namestore_api_zone_iteration_stop.c | |||
@@ -56,7 +56,6 @@ static char * s_name_3; | |||
56 | 56 | ||
57 | static struct GNUNET_GNSRECORD_Data *s_rd_3; | 57 | static struct GNUNET_GNSRECORD_Data *s_rd_3; |
58 | 58 | ||
59 | static char *directory; | ||
60 | 59 | ||
61 | 60 | ||
62 | /** | 61 | /** |
@@ -475,14 +474,9 @@ run (void *cls, | |||
475 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 474 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
476 | struct GNUNET_TESTING_Peer *peer) | 475 | struct GNUNET_TESTING_Peer *peer) |
477 | { | 476 | { |
478 | GNUNET_assert (GNUNET_OK == | 477 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
479 | GNUNET_CONFIGURATION_get_value_string (cfg, | 478 | &endbadly, |
480 | "PATHS", | 479 | NULL); |
481 | "GNUNET_TEST_HOME", | ||
482 | &directory)); | ||
483 | GNUNET_DISK_directory_remove (directory); | ||
484 | |||
485 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); | ||
486 | nsh = GNUNET_NAMESTORE_connect (cfg); | 480 | nsh = GNUNET_NAMESTORE_connect (cfg); |
487 | GNUNET_break (NULL != nsh); | 481 | GNUNET_break (NULL != nsh); |
488 | /* first, iterate over empty namestore */ | 482 | /* first, iterate over empty namestore */ |
@@ -515,6 +509,8 @@ main (int argc, char *argv[]) | |||
515 | GNUNET_asprintf (&cfg_name, | 509 | GNUNET_asprintf (&cfg_name, |
516 | "test_namestore_api_%s.conf", | 510 | "test_namestore_api_%s.conf", |
517 | plugin_name); | 511 | plugin_name); |
512 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
513 | "GNUNET_TEST_HOME"); | ||
518 | res = 1; | 514 | res = 1; |
519 | if (0 != | 515 | if (0 != |
520 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-stop", | 516 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-stop", |
@@ -524,12 +520,10 @@ main (int argc, char *argv[]) | |||
524 | { | 520 | { |
525 | res = 1; | 521 | res = 1; |
526 | } | 522 | } |
523 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
524 | "GNUNET_TEST_HOME"); | ||
527 | GNUNET_free (cfg_name); | 525 | GNUNET_free (cfg_name); |
528 | if (NULL != directory) | 526 | |
529 | { | ||
530 | GNUNET_DISK_directory_remove (directory); | ||
531 | GNUNET_free (directory); | ||
532 | } | ||
533 | return res; | 527 | return res; |
534 | } | 528 | } |
535 | 529 | ||
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c index 5b088d90b..292d8f701 100644 --- a/src/namestore/test_namestore_api_zone_to_name.c +++ b/src/namestore/test_namestore_api_zone_to_name.c | |||
@@ -51,8 +51,6 @@ static char * s_name; | |||
51 | 51 | ||
52 | static int res; | 52 | static int res; |
53 | 53 | ||
54 | static char *directory; | ||
55 | |||
56 | static struct GNUNET_NAMESTORE_QueueEntry *qe; | 54 | static struct GNUNET_NAMESTORE_QueueEntry *qe; |
57 | 55 | ||
58 | 56 | ||
@@ -204,34 +202,13 @@ run (void *cls, | |||
204 | { | 202 | { |
205 | (void) cls; | 203 | (void) cls; |
206 | (void) peer; | 204 | (void) peer; |
207 | directory = NULL; | ||
208 | GNUNET_assert (GNUNET_OK == | ||
209 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
210 | "PATHS", | ||
211 | "GNUNET_TEST_HOME", | ||
212 | &directory)); | ||
213 | GNUNET_DISK_directory_remove (directory); | ||
214 | |||
215 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 205 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
216 | &endbadly, | 206 | &endbadly, |
217 | NULL); | 207 | NULL); |
218 | GNUNET_SCHEDULER_add_shutdown (&end, | 208 | GNUNET_SCHEDULER_add_shutdown (&end, |
219 | NULL); | 209 | NULL); |
220 | GNUNET_asprintf (&s_name, "dummy"); | 210 | GNUNET_asprintf (&s_name, "dummy"); |
221 | /* load privat key */ | 211 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
222 | { | ||
223 | char *zonekey_file; | ||
224 | |||
225 | GNUNET_asprintf (&zonekey_file, | ||
226 | "zonefiles%s%s", | ||
227 | DIR_SEPARATOR_STR, | ||
228 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
230 | "Using zonekey file `%s'\n", | ||
231 | zonekey_file); | ||
232 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (zonekey_file); | ||
233 | GNUNET_free (zonekey_file); | ||
234 | } | ||
235 | GNUNET_assert (NULL != privkey); | 212 | GNUNET_assert (NULL != privkey); |
236 | /* get public key */ | 213 | /* get public key */ |
237 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, | 214 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
@@ -274,6 +251,8 @@ main (int argc, | |||
274 | GNUNET_asprintf (&cfg_name, | 251 | GNUNET_asprintf (&cfg_name, |
275 | "test_namestore_api_%s.conf", | 252 | "test_namestore_api_%s.conf", |
276 | plugin_name); | 253 | plugin_name); |
254 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
255 | "GNUNET_TEST_HOME"); | ||
277 | res = 1; | 256 | res = 1; |
278 | if (0 != | 257 | if (0 != |
279 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name", | 258 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name", |
@@ -283,12 +262,9 @@ main (int argc, | |||
283 | { | 262 | { |
284 | res = 1; | 263 | res = 1; |
285 | } | 264 | } |
265 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
266 | "GNUNET_TEST_HOME"); | ||
286 | GNUNET_free (cfg_name); | 267 | GNUNET_free (cfg_name); |
287 | if (NULL != directory) | ||
288 | { | ||
289 | GNUNET_DISK_directory_remove (directory); | ||
290 | GNUNET_free (directory); | ||
291 | } | ||
292 | return res; | 268 | return res; |
293 | } | 269 | } |
294 | 270 | ||
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c index 6bccd1706..8732acbcb 100644 --- a/src/namestore/test_plugin_namestore.c +++ b/src/namestore/test_plugin_namestore.c | |||
@@ -215,6 +215,8 @@ main (int argc, | |||
215 | sizeof (cfg_name), | 215 | sizeof (cfg_name), |
216 | "test_plugin_namestore_%s.conf", | 216 | "test_plugin_namestore_%s.conf", |
217 | plugin_name); | 217 | plugin_name); |
218 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
219 | "GNUNET_TMP"); | ||
218 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, | 220 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, |
219 | xargv, | 221 | xargv, |
220 | "test-plugin-namestore", | 222 | "test-plugin-namestore", |
@@ -222,6 +224,8 @@ main (int argc, | |||
222 | options, | 224 | options, |
223 | &run, | 225 | &run, |
224 | NULL); | 226 | NULL); |
227 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
228 | "GNUNET_TMP"); | ||
225 | if (ok != 0) | 229 | if (ok != 0) |
226 | FPRINTF (stderr, | 230 | FPRINTF (stderr, |
227 | "Missed some testcases: %d\n", | 231 | "Missed some testcases: %d\n", |
diff --git a/src/namestore/test_plugin_namestore_flat.conf b/src/namestore/test_plugin_namestore_flat.conf index 6a5491df7..5c632f0d1 100644 --- a/src/namestore/test_plugin_namestore_flat.conf +++ b/src/namestore/test_plugin_namestore_flat.conf | |||
@@ -1,5 +1,2 @@ | |||
1 | [namestore-flat] | 1 | [namestore-flat] |
2 | FILENAME = $GNUNET_TMP/gnunet-test-plugin-namestore-sqlite/flatdb | 2 | FILENAME = $GNUNET_TMP/gnunet-test-plugin-namestore-flat/flatdb |
3 | |||
4 | [namestore] | ||
5 | # PREFIX = valgrind --log-file=/home/schanzen/dev/gnunet/src/namestore/vg_log | ||