aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/Makefile.am25
-rw-r--r--src/namestore/gnunet-namestore-fcfsd.c580
-rw-r--r--src/namestore/gnunet-namestore.c194
-rw-r--r--src/namestore/gnunet-service-namestore.c825
-rw-r--r--src/namestore/gnunet-zoneimport.c134
-rw-r--r--src/namestore/namestore.conf.in6
-rw-r--r--src/namestore/namestore.h18
-rw-r--r--src/namestore/namestore_api.c87
-rw-r--r--src/namestore/namestore_api_monitor.c25
-rw-r--r--src/namestore/perf_namestore_api_flat.conf3
-rw-r--r--src/namestore/perf_namestore_api_postgres.conf4
-rw-r--r--src/namestore/perf_namestore_api_sqlite.conf3
-rw-r--r--src/namestore/perf_namestore_api_zone_iteration.c41
-rw-r--r--src/namestore/plugin_namestore_flat.c191
-rw-r--r--src/namestore/plugin_namestore_postgres.c27
-rw-r--r--src/namestore/plugin_namestore_sqlite.c285
-rw-r--r--src/namestore/plugin_rest_namestore.c1231
-rw-r--r--src/namestore/test_namestore_api.conf19
-rw-r--r--src/namestore/test_namestore_api_flat.conf3
-rw-r--r--src/namestore/test_namestore_api_lookup_nick.c58
-rw-r--r--src/namestore/test_namestore_api_lookup_private.c73
-rw-r--r--src/namestore/test_namestore_api_lookup_public.c52
-rw-r--r--src/namestore/test_namestore_api_lookup_shadow.c61
-rw-r--r--src/namestore/test_namestore_api_lookup_shadow_filter.c56
-rw-r--r--src/namestore/test_namestore_api_monitoring.c102
-rw-r--r--src/namestore/test_namestore_api_monitoring_existing.c210
-rw-r--r--src/namestore/test_namestore_api_postgres.conf5
-rw-r--r--src/namestore/test_namestore_api_remove.c63
-rw-r--r--src/namestore/test_namestore_api_remove_not_existing_record.c55
-rw-r--r--src/namestore/test_namestore_api_sqlite.conf4
-rw-r--r--src/namestore/test_namestore_api_store.c54
-rw-r--r--src/namestore/test_namestore_api_store_update.c202
-rw-r--r--src/namestore/test_namestore_api_zone_iteration.c223
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_nick.c80
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_specific_zone.c184
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_stop.c52
-rw-r--r--src/namestore/test_namestore_api_zone_to_name.c57
-rw-r--r--src/namestore/test_plugin_namestore.c28
-rw-r--r--src/namestore/test_plugin_namestore_flat.conf5
-rw-r--r--src/namestore/test_plugin_namestore_sqlite.conf2
40 files changed, 2208 insertions, 3119 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index fa85cc060..a349921d7 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -97,12 +97,6 @@ check_PROGRAMS = \
97 $(FLAT_TESTS) 97 $(FLAT_TESTS)
98endif 98endif
99 99
100if HAVE_MHD
101if HAVE_JSON
102REST_PLUGIN=libgnunet_plugin_rest_namestore.la
103endif
104endif
105
106if ENABLE_TEST_RUN 100if ENABLE_TEST_RUN
107AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 101AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
108TESTS = \ 102TESTS = \
@@ -147,8 +141,6 @@ gnunet_zoneimport_LDADD = \
147 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 141 $(top_builddir)/src/statistics/libgnunetstatistics.la \
148 $(top_builddir)/src/identity/libgnunetidentity.la \ 142 $(top_builddir)/src/identity/libgnunetidentity.la \
149 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 143 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
150 $(top_builddir)/src/dns/libgnunetdnsparser.la \
151 $(top_builddir)/src/dns/libgnunetdnsstub.la \
152 $(top_builddir)/src/util/libgnunetutil.la \ 144 $(top_builddir)/src/util/libgnunetutil.la \
153 $(GN_LIBINTL) 145 $(GN_LIBINTL)
154 146
@@ -188,8 +180,7 @@ gnunet_service_namestore_LDADD = \
188plugin_LTLIBRARIES = \ 180plugin_LTLIBRARIES = \
189 $(SQLITE_PLUGIN) \ 181 $(SQLITE_PLUGIN) \
190 $(POSTGRES_PLUGIN) \ 182 $(POSTGRES_PLUGIN) \
191 $(FLAT_PLUGIN) \ 183 $(FLAT_PLUGIN)
192 $(REST_PLUGIN)
193 184
194 185
195 186
@@ -226,20 +217,6 @@ libgnunet_plugin_namestore_postgres_la_LIBADD = \
226libgnunet_plugin_namestore_postgres_la_LDFLAGS = \ 217libgnunet_plugin_namestore_postgres_la_LDFLAGS = \
227 $(GN_PLUGIN_LDFLAGS) $(POSTGRESQL_LDFLAGS) 218 $(GN_PLUGIN_LDFLAGS) $(POSTGRESQL_LDFLAGS)
228 219
229libgnunet_plugin_rest_namestore_la_SOURCES = \
230 plugin_rest_namestore.c
231libgnunet_plugin_rest_namestore_la_LIBADD = \
232 libgnunetnamestore.la \
233 $(top_builddir)/src/rest/libgnunetrest.la \
234 $(top_builddir)/src/identity/libgnunetidentity.la \
235 $(top_builddir)/src/jsonapi/libgnunetjsonapi.la \
236 $(top_builddir)/src/jsonapi/libgnunetjsonapiutils.la \
237 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
238 $(LTLIBINTL) -ljansson -lmicrohttpd
239libgnunet_plugin_rest_namestore_la_LDFLAGS = \
240 $(GN_PLUGIN_LDFLAGS)
241
242
243test_namestore_api_store_flat_SOURCES = \ 220test_namestore_api_store_flat_SOURCES = \
244 test_namestore_api_store.c 221 test_namestore_api_store.c
245test_namestore_api_store_flat_LDADD = \ 222test_namestore_api_store_flat_LDADD = \
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c
index 903253b1a..0853ff4d7 100644
--- a/src/namestore/gnunet-namestore-fcfsd.c
+++ b/src/namestore/gnunet-namestore-fcfsd.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012-2014 GNUnet e.V. 3 Copyright (C) 2012-2014 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gnunet-namestore-fcfsd.c 19 * @file gnunet-namestore-fcfsd.c
@@ -119,7 +117,11 @@ struct Request
119 * a POST request). 117 * a POST request).
120 */ 118 */
121 struct MHD_PostProcessor *pp; 119 struct MHD_PostProcessor *pp;
122 120
121 /**
122 * MHD Connection
123 */
124 struct MHD_Connection *con;
123 /** 125 /**
124 * URL to serve in response to this POST (if this request 126 * URL to serve in response to this POST (if this request
125 * was a 'POST') 127 * was a 'POST')
@@ -132,6 +134,11 @@ struct Request
132 struct GNUNET_NAMESTORE_QueueEntry *qe; 134 struct GNUNET_NAMESTORE_QueueEntry *qe;
133 135
134 /** 136 /**
137 * Active lookup iterator
138 * TODO: deprecate or fix lookup by label and use above member
139 */
140 struct GNUNET_NAMESTORE_ZoneIterator *lookup_it;
141 /**
135 * Active iteration with the namestore. 142 * Active iteration with the namestore.
136 */ 143 */
137 struct GNUNET_NAMESTORE_ZoneIterator *zi; 144 struct GNUNET_NAMESTORE_ZoneIterator *zi;
@@ -161,11 +168,6 @@ struct Request
161struct ZoneinfoRequest 168struct ZoneinfoRequest
162{ 169{
163 /** 170 /**
164 * Connection
165 */
166 struct MHD_Connection *connection;
167
168 /**
169 * List iterator 171 * List iterator
170 */ 172 */
171 struct GNUNET_NAMESTORE_ZoneIterator *list_it; 173 struct GNUNET_NAMESTORE_ZoneIterator *list_it;
@@ -212,6 +214,16 @@ static struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey;
212static struct GNUNET_IDENTITY_Handle *identity; 214static struct GNUNET_IDENTITY_Handle *identity;
213 215
214/** 216/**
217 * Zoneinfo page we currently use.
218 */
219static struct MHD_Response *info_page;
220
221/**
222 * Task that runs #update_zoneinfo_page peridicially.
223 */
224static struct GNUNET_SCHEDULER_Task *uzp_task;
225
226/**
215 * Request for our ego. 227 * Request for our ego.
216 */ 228 */
217static struct GNUNET_IDENTITY_Operation *id_op; 229static struct GNUNET_IDENTITY_Operation *id_op;
@@ -221,6 +233,11 @@ static struct GNUNET_IDENTITY_Operation *id_op;
221 */ 233 */
222static unsigned long long port; 234static unsigned long long port;
223 235
236/**
237 * Name of the zone we manage.
238 */
239static char *zone;
240
224 241
225/** 242/**
226 * Task run whenever HTTP server operations are pending. 243 * Task run whenever HTTP server operations are pending.
@@ -247,25 +264,25 @@ run_httpd_now ()
247 264
248 265
249/** 266/**
267 * Create fresh version of zone information.
268 */
269static void
270update_zoneinfo_page (void *cls);
271
272
273/**
250 * Function called on error in zone iteration. 274 * Function called on error in zone iteration.
251 */ 275 */
252static void 276static void
253zone_iteration_error (void *cls) 277zone_iteration_error (void *cls)
254{ 278{
255 struct ZoneinfoRequest *zr = cls; 279 struct ZoneinfoRequest *zr = cls;
256 struct MHD_Response *response;
257 280
258 zr->list_it = NULL; 281 zr->list_it = NULL;
259 response = MHD_create_response_from_buffer (strlen ("internal error"),
260 (void *) "internal error",
261 MHD_RESPMEM_PERSISTENT);
262 MHD_queue_response (zr->connection,
263 MHD_HTTP_INTERNAL_SERVER_ERROR,
264 response);
265 MHD_destroy_response (response);
266 GNUNET_free (zr->zoneinfo); 282 GNUNET_free (zr->zoneinfo);
267 GNUNET_free (zr); 283 GNUNET_SCHEDULER_cancel (uzp_task);
268 run_httpd_now (); 284 uzp_task = GNUNET_SCHEDULER_add_now (&update_zoneinfo_page,
285 NULL);
269} 286}
270 287
271 288
@@ -292,13 +309,9 @@ zone_iteration_end (void *cls)
292 MHD_add_response_header (response, 309 MHD_add_response_header (response,
293 MHD_HTTP_HEADER_CONTENT_TYPE, 310 MHD_HTTP_HEADER_CONTENT_TYPE,
294 MIME_HTML); 311 MIME_HTML);
295 MHD_queue_response (zr->connection, 312 MHD_destroy_response (info_page);
296 MHD_HTTP_OK, 313 info_page = response;
297 response);
298 MHD_destroy_response (response);
299 GNUNET_free (zr->zoneinfo); 314 GNUNET_free (zr->zoneinfo);
300 GNUNET_free (zr);
301 run_httpd_now ();
302} 315}
303 316
304 317
@@ -373,27 +386,41 @@ iterate_cb (void *cls,
373 * Handler that returns FCFS zoneinfo page. 386 * Handler that returns FCFS zoneinfo page.
374 * 387 *
375 * @param connection connection to use 388 * @param connection connection to use
376 * @return MHD_YES on success
377 */ 389 */
378static int 390static int
379serve_zoneinfo_page (struct MHD_Connection *connection) 391serve_zoneinfo_page (struct MHD_Connection *connection)
380{ 392{
381 struct ZoneinfoRequest *zr; 393 return MHD_queue_response (connection,
382 394 MHD_HTTP_OK,
383 zr = GNUNET_new (struct ZoneinfoRequest); 395 info_page);
384 zr->zoneinfo = GNUNET_malloc (DEFAULT_ZONEINFO_BUFSIZE); 396}
385 zr->buf_len = DEFAULT_ZONEINFO_BUFSIZE; 397
386 zr->connection = connection; 398
387 zr->write_offset = 0; 399/**
388 zr->list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, 400 * Create fresh version of zone information.
389 &fcfs_zone_pkey, 401 */
390 &zone_iteration_error, 402static void
391 zr, 403update_zoneinfo_page (void *cls)
392 &iterate_cb, 404{
393 zr, 405 static struct ZoneinfoRequest zr;
394 &zone_iteration_end, 406
395 zr); 407 (void) cls;
396 return MHD_YES; 408 uzp_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
409 &update_zoneinfo_page,
410 NULL);
411 if (NULL != zr.list_it)
412 return;
413 zr.zoneinfo = GNUNET_malloc (DEFAULT_ZONEINFO_BUFSIZE);
414 zr.buf_len = DEFAULT_ZONEINFO_BUFSIZE;
415 zr.write_offset = 0;
416 zr.list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
417 &fcfs_zone_pkey,
418 &zone_iteration_error,
419 &zr,
420 &iterate_cb,
421 &zr,
422 &zone_iteration_end,
423 &zr);
397} 424}
398 425
399 426
@@ -401,7 +428,7 @@ serve_zoneinfo_page (struct MHD_Connection *connection)
401 * Handler that returns a simple static HTTP page. 428 * Handler that returns a simple static HTTP page.
402 * 429 *
403 * @param connection connection to use 430 * @param connection connection to use
404 * @return MHD_YES on success 431 * @return #MHD_YES on success
405 */ 432 */
406static int 433static int
407serve_main_page (struct MHD_Connection *connection) 434serve_main_page (struct MHD_Connection *connection)
@@ -551,6 +578,7 @@ put_continuation (void *cls,
551 } 578 }
552 else 579 else
553 request->phase = RP_SUCCESS; 580 request->phase = RP_SUCCESS;
581 MHD_resume_connection (request->con);
554 run_httpd_now (); 582 run_httpd_now ();
555} 583}
556 584
@@ -566,6 +594,7 @@ zone_to_name_error (void *cls)
566 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 594 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
567 _("Error when mapping zone to name\n")); 595 _("Error when mapping zone to name\n"));
568 request->phase = RP_FAIL; 596 request->phase = RP_FAIL;
597 MHD_resume_connection (request->con);
569 run_httpd_now (); 598 run_httpd_now ();
570} 599}
571 600
@@ -598,6 +627,7 @@ zone_to_name_cb (void *cls,
598 _("Found existing name `%s' for the given key\n"), 627 _("Found existing name `%s' for the given key\n"),
599 name); 628 name);
600 request->phase = RP_FAIL; 629 request->phase = RP_FAIL;
630 MHD_resume_connection (request->con);
601 run_httpd_now (); 631 run_httpd_now ();
602 return; 632 return;
603 } 633 }
@@ -619,10 +649,10 @@ zone_to_name_cb (void *cls,
619 * We encountered an error in the name lookup. 649 * We encountered an error in the name lookup.
620 */ 650 */
621static void 651static void
622lookup_block_error (void *cls) 652lookup_it_error (void *cls)
623{ 653{
624 struct Request *request = cls; 654 struct Request *request = cls;
625 655 MHD_resume_connection (request->con);
626 request->qe = NULL; 656 request->qe = NULL;
627 request->phase = RP_FAIL; 657 request->phase = RP_FAIL;
628 run_httpd_now (); 658 run_httpd_now ();
@@ -634,14 +664,14 @@ lookup_block_error (void *cls)
634 * and continue to process the result. 664 * and continue to process the result.
635 * 665 *
636 * @param cls the 'struct Request' we are processing 666 * @param cls the 'struct Request' we are processing
637 * @param zone private key of the zone; NULL on disconnect 667 * @param zonekey private key of the zone; NULL on disconnect
638 * @param label label of the records; NULL on disconnect 668 * @param label label of the records; NULL on disconnect
639 * @param rd_count number of entries in @a rd array, 0 if label was deleted 669 * @param rd_count number of entries in @a rd array, 0 if label was deleted
640 * @param rd array of records with data to store 670 * @param rd array of records with data to store
641 */ 671 */
642static void 672static void
643lookup_block_processor (void *cls, 673lookup_it_processor (void *cls,
644 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 674 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey,
645 const char *label, 675 const char *label,
646 unsigned int rd_count, 676 unsigned int rd_count,
647 const struct GNUNET_GNSRECORD_Data *rd) 677 const struct GNUNET_GNSRECORD_Data *rd)
@@ -650,40 +680,49 @@ lookup_block_processor (void *cls,
650 680
651 (void) label; 681 (void) label;
652 (void) rd; 682 (void) rd;
653 (void) zone; 683 (void) zonekey;
654 request->qe = NULL; 684 if (0 == strcmp (label, request->domain_name)) {
655 if (0 == rd_count) 685 GNUNET_break (0 != rd_count);
686 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
687 _("Found %u existing records for domain `%s'\n"),
688 rd_count,
689 request->domain_name);
690 request->phase = RP_FAIL;
691 }
692 GNUNET_NAMESTORE_zone_iterator_next (request->lookup_it, 1);
693}
694
695static void
696lookup_it_finished (void *cls)
697{
698 struct Request *request = cls;
699
700 if (RP_FAIL == request->phase)
656 { 701 {
657 if (GNUNET_OK != 702 MHD_resume_connection (request->con);
658 GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, 703 run_httpd_now ();
659 strlen (request->public_key),
660 &request->pub))
661 {
662 GNUNET_break (0);
663 request->phase = RP_FAIL;
664 run_httpd_now ();
665 return;
666 }
667 request->qe = GNUNET_NAMESTORE_zone_to_name (ns,
668 &fcfs_zone_pkey,
669 &request->pub,
670 &zone_to_name_error,
671 request,
672 &zone_to_name_cb,
673 request);
674 return; 704 return;
675 } 705 }
676 GNUNET_break (0 != rd_count); 706 if (GNUNET_OK !=
677 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 707 GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key,
678 _("Found %u existing records for domain `%s'\n"), 708 strlen (request->public_key),
679 rd_count, 709 &request->pub))
680 request->domain_name); 710 {
681 request->phase = RP_FAIL; 711 GNUNET_break (0);
682 run_httpd_now (); 712 request->phase = RP_FAIL;
683 return; 713 MHD_resume_connection (request->con);
714 run_httpd_now ();
715 return;
716 }
717 request->qe = GNUNET_NAMESTORE_zone_to_name (ns,
718 &fcfs_zone_pkey,
719 &request->pub,
720 &zone_to_name_error,
721 request,
722 &zone_to_name_cb,
723 request);
684} 724}
685 725
686
687/** 726/**
688 * Main MHD callback for handling requests. 727 * Main MHD callback for handling requests.
689 * 728 *
@@ -703,19 +742,19 @@ lookup_block_processor (void *cls,
703 * @a upload_data provided; the method must update this 742 * @a upload_data provided; the method must update this
704 * value to the number of bytes NOT processed; 743 * value to the number of bytes NOT processed;
705 * @param ptr pointer to location where we store the 'struct Request' 744 * @param ptr pointer to location where we store the 'struct Request'
706 * @return MHD_YES if the connection was handled successfully, 745 * @return #MHD_YES if the connection was handled successfully,
707 * MHD_NO if the socket must be closed due to a serious 746 * #MHD_NO if the socket must be closed due to a serious
708 * error while handling the request 747 * error while handling the request
709 */ 748 */
710static int 749static int
711create_response (void *cls, 750create_response (void *cls,
712 struct MHD_Connection *connection, 751 struct MHD_Connection *connection,
713 const char *url, 752 const char *url,
714 const char *method, 753 const char *method,
715 const char *version, 754 const char *version,
716 const char *upload_data, 755 const char *upload_data,
717 size_t *upload_data_size, 756 size_t *upload_data_size,
718 void **ptr) 757 void **ptr)
719{ 758{
720 struct MHD_Response *response; 759 struct MHD_Response *response;
721 struct Request *request; 760 struct Request *request;
@@ -726,114 +765,117 @@ create_response (void *cls,
726 (void) version; 765 (void) version;
727 if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) || 766 if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) ||
728 (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) ) 767 (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) )
729 { 768 {
730 if (0 == strcmp (url, FCFS_ZONEINFO_URL)) 769 if (0 == strcmp (url, FCFS_ZONEINFO_URL))
731 ret = serve_zoneinfo_page (connection); 770 ret = serve_zoneinfo_page (connection);
732 else 771 else
733 ret = serve_main_page (connection); 772 ret = serve_main_page (connection);
734 if (ret != MHD_YES) 773 if (ret != MHD_YES)
735 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 774 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
736 _("Failed to create page for `%s'\n"), 775 _("Failed to create page for `%s'\n"),
737 url); 776 url);
738 return ret; 777 return ret;
739 } 778 }
740 if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) 779 if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
780 {
781 request = *ptr;
782 if (NULL == request)
741 { 783 {
742 request = *ptr; 784 request = GNUNET_new (struct Request);
743 if (NULL == request) 785 request->con = connection;
786 *ptr = request;
787 request->pp = MHD_create_post_processor (connection,
788 1024,
789 &post_iterator,
790 request);
791 if (NULL == request->pp)
744 { 792 {
745 request = GNUNET_new (struct Request); 793 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
746 *ptr = request; 794 _("Failed to setup post processor for `%s'\n"),
747 request->pp = MHD_create_post_processor (connection, 795 url);
748 1024, 796 return MHD_NO; /* internal error */
749 &post_iterator,
750 request);
751 if (NULL == request->pp)
752 {
753 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
754 _("Failed to setup post processor for `%s'\n"),
755 url);
756 return MHD_NO; /* internal error */
757 }
758 return MHD_YES;
759 } 797 }
760 if (NULL != request->pp) 798 return MHD_YES;
761 { 799 }
762 /* evaluate POST data */ 800 if (NULL != request->pp)
763 MHD_post_process (request->pp, 801 {
764 upload_data, 802 /* evaluate POST data */
765 *upload_data_size); 803 MHD_post_process (request->pp,
766 if (0 != *upload_data_size) 804 upload_data,
767 { 805 *upload_data_size);
768 *upload_data_size = 0; 806 if (0 != *upload_data_size)
769 return MHD_YES;
770 }
771 /* done with POST data, serve response */
772 MHD_destroy_post_processor (request->pp);
773 request->pp = NULL;
774 }
775 if (GNUNET_OK !=
776 GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key,
777 strlen (request->public_key),
778 &pub))
779 { 807 {
780 /* parse error */ 808 *upload_data_size = 0;
781 return fill_s_reply ("Failed to parse given public key", 809 return MHD_YES;
782 request, connection);
783 } 810 }
784 switch (request->phase) 811 /* done with POST data, serve response */
785 { 812 MHD_destroy_post_processor (request->pp);
786 case RP_START: 813 request->pp = NULL;
787 if (NULL != strchr (request->domain_name, (int) '.'))
788 {
789 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
790 _("Domain name must not contain `.'\n"));
791 request->phase = RP_FAIL;
792 return fill_s_reply ("Domain name must not contain `.', sorry.",
793 request,
794 connection);
795 }
796 if (NULL != strchr (request->domain_name, (int) '+'))
797 {
798 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
799 _("Domain name must not contain `+'\n"));
800 request->phase = RP_FAIL;
801 return fill_s_reply ("Domain name must not contain `+', sorry.",
802 request, connection);
803 }
804 request->phase = RP_LOOKUP;
805 request->qe
806 = GNUNET_NAMESTORE_records_lookup (ns,
807 &fcfs_zone_pkey,
808 request->domain_name,
809 &lookup_block_error,
810 request,
811 &lookup_block_processor,
812 request);
813 break;
814 case RP_LOOKUP:
815 break;
816 case RP_PUT:
817 break;
818 case RP_FAIL:
819 return fill_s_reply ("Request failed, sorry.",
820 request, connection);
821 case RP_SUCCESS:
822 return fill_s_reply ("Success.",
823 request, connection);
824 default:
825 GNUNET_break (0);
826 return MHD_NO;
827 }
828 return MHD_YES; /* will have a reply later... */
829 } 814 }
815 if (GNUNET_OK !=
816 GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key,
817 strlen (request->public_key),
818 &pub))
819 {
820 /* parse error */
821 return fill_s_reply ("Failed to parse given public key",
822 request, connection);
823 }
824 switch (request->phase)
825 {
826 case RP_START:
827 if (NULL != strchr (request->domain_name, (int) '.'))
828 {
829 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
830 _("Domain name must not contain `.'\n"));
831 request->phase = RP_FAIL;
832 return fill_s_reply ("Domain name must not contain `.', sorry.",
833 request,
834 connection);
835 }
836 if (NULL != strchr (request->domain_name, (int) '+'))
837 {
838 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
839 _("Domain name must not contain `+'\n"));
840 request->phase = RP_FAIL;
841 return fill_s_reply ("Domain name must not contain `+', sorry.",
842 request, connection);
843 }
844 request->phase = RP_LOOKUP;
845 MHD_suspend_connection (request->con);
846 request->lookup_it
847 = GNUNET_NAMESTORE_zone_iteration_start (ns,
848 &fcfs_zone_pkey,
849 &lookup_it_error,
850 request,
851 &lookup_it_processor,
852 request,
853 &lookup_it_finished,
854 request);
855 break;
856 case RP_LOOKUP:
857 break;
858 case RP_PUT:
859 break;
860 case RP_FAIL:
861 return fill_s_reply ("Request failed, sorry.",
862 request, connection);
863 case RP_SUCCESS:
864 return fill_s_reply ("Success.",
865 request, connection);
866 default:
867 GNUNET_break (0);
868 return MHD_NO;
869 }
870 return MHD_YES; /* will have a reply later... */
871 }
830 /* unsupported HTTP method */ 872 /* unsupported HTTP method */
831 response = MHD_create_response_from_buffer (strlen (METHOD_ERROR), 873 response = MHD_create_response_from_buffer (strlen (METHOD_ERROR),
832 (void *) METHOD_ERROR, 874 (void *) METHOD_ERROR,
833 MHD_RESPMEM_PERSISTENT); 875 MHD_RESPMEM_PERSISTENT);
834 ret = MHD_queue_response (connection, 876 ret = MHD_queue_response (connection,
835 MHD_HTTP_NOT_ACCEPTABLE, 877 MHD_HTTP_NOT_ACCEPTABLE,
836 response); 878 response);
837 MHD_destroy_response (response); 879 MHD_destroy_response (response);
838 return ret; 880 return ret;
839} 881}
@@ -850,9 +892,9 @@ create_response (void *cls,
850 */ 892 */
851static void 893static void
852request_completed_callback (void *cls, 894request_completed_callback (void *cls,
853 struct MHD_Connection *connection, 895 struct MHD_Connection *connection,
854 void **con_cls, 896 void **con_cls,
855 enum MHD_RequestTerminationCode toe) 897 enum MHD_RequestTerminationCode toe)
856{ 898{
857 struct Request *request = *con_cls; 899 struct Request *request = *con_cls;
858 900
@@ -897,33 +939,33 @@ run_httpd ()
897 wws = GNUNET_NETWORK_fdset_create (); 939 wws = GNUNET_NETWORK_fdset_create ();
898 max = -1; 940 max = -1;
899 GNUNET_assert (MHD_YES == 941 GNUNET_assert (MHD_YES ==
900 MHD_get_fdset (httpd, 942 MHD_get_fdset (httpd,
901 &rs, 943 &rs,
902 &ws, 944 &ws,
903 &es, 945 &es,
904 &max)); 946 &max));
905 haveto = MHD_get_timeout (httpd, 947 haveto = MHD_get_timeout (httpd,
906 &timeout); 948 &timeout);
907 if (haveto == MHD_YES) 949 if (haveto == MHD_YES)
908 tv.rel_value_us = (uint64_t) timeout * 1000LL; 950 tv.rel_value_us = (uint64_t) timeout * 1000LL;
909 else 951 else
910 tv = GNUNET_TIME_UNIT_FOREVER_REL; 952 tv = GNUNET_TIME_UNIT_FOREVER_REL;
911 GNUNET_NETWORK_fdset_copy_native (wrs, 953 GNUNET_NETWORK_fdset_copy_native (wrs,
912 &rs, 954 &rs,
913 max + 1); 955 max + 1);
914 GNUNET_NETWORK_fdset_copy_native (wws, 956 GNUNET_NETWORK_fdset_copy_native (wws,
915 &ws, 957 &ws,
916 max + 1); 958 max + 1);
917 GNUNET_NETWORK_fdset_copy_native (wes, 959 GNUNET_NETWORK_fdset_copy_native (wes,
918 &es, 960 &es,
919 max + 1); 961 max + 1);
920 httpd_task = 962 httpd_task =
921 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, 963 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
922 tv, 964 tv,
923 wrs, 965 wrs,
924 wws, 966 wws,
925 &do_httpd, 967 &do_httpd,
926 NULL); 968 NULL);
927 GNUNET_NETWORK_fdset_destroy (wrs); 969 GNUNET_NETWORK_fdset_destroy (wrs);
928 GNUNET_NETWORK_fdset_destroy (wws); 970 GNUNET_NETWORK_fdset_destroy (wws);
929 GNUNET_NETWORK_fdset_destroy (wes); 971 GNUNET_NETWORK_fdset_destroy (wes);
@@ -959,6 +1001,11 @@ do_shutdown (void *cls)
959 GNUNET_SCHEDULER_cancel (httpd_task); 1001 GNUNET_SCHEDULER_cancel (httpd_task);
960 httpd_task = NULL; 1002 httpd_task = NULL;
961 } 1003 }
1004 if (NULL != uzp_task)
1005 {
1006 GNUNET_SCHEDULER_cancel (uzp_task);
1007 uzp_task = NULL;
1008 }
962 if (NULL != ns) 1009 if (NULL != ns)
963 { 1010 {
964 GNUNET_NAMESTORE_disconnect (ns); 1011 GNUNET_NAMESTORE_disconnect (ns);
@@ -1003,46 +1050,51 @@ do_shutdown (void *cls)
1003 */ 1050 */
1004static void 1051static void
1005identity_cb (void *cls, 1052identity_cb (void *cls,
1006 struct GNUNET_IDENTITY_Ego *ego, 1053 struct GNUNET_IDENTITY_Ego *ego,
1007 void **ctx, 1054 void **ctx,
1008 const char *name) 1055 const char *name)
1009{ 1056{
1010 int options; 1057 int options;
1011 1058
1012 (void) cls; 1059 (void) cls;
1013 (void) ctx; 1060 (void) ctx;
1014 (void) name; 1061 if (NULL == name)
1015 id_op = NULL; 1062 return;
1063 if (0 != strcmp (name,
1064 zone))
1065 return;
1016 if (NULL == ego) 1066 if (NULL == ego)
1017 { 1067 {
1018 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1068 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1019 _("No ego configured for `fcfsd` subsystem\n")); 1069 _("No ego configured for `fcfsd` subsystem\n"));
1070 GNUNET_SCHEDULER_shutdown ();
1020 return; 1071 return;
1021 } 1072 }
1022 fcfs_zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); 1073 fcfs_zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
1023 1074
1024 options = MHD_USE_DUAL_STACK | MHD_USE_DEBUG; 1075 options = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME;
1025 do 1076 do
1026 { 1077 {
1027 httpd = MHD_start_daemon (options, 1078 httpd = MHD_start_daemon (options,
1028 (uint16_t) port, 1079 (uint16_t) port,
1029 NULL, NULL, 1080 NULL, NULL,
1030 &create_response, NULL, 1081 &create_response, NULL,
1031 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128, 1082 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128,
1032 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, 1083 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1,
1033 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, 1084 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16,
1034 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (4 * 1024), 1085 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (4 * 1024),
1035 MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL, 1086 MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL,
1036 MHD_OPTION_END); 1087 MHD_OPTION_END);
1037 if (MHD_USE_DEBUG == options) 1088 if (MHD_USE_DEBUG == options)
1038 break; 1089 break;
1039 options = MHD_USE_DEBUG; 1090 options = MHD_USE_DEBUG;
1040 } 1091 }
1041 while (NULL == httpd); 1092 while (NULL == httpd);
1042 if (NULL == httpd) 1093 if (NULL == httpd)
1043 { 1094 {
1095
1044 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1096 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1045 _("Failed to start HTTP server\n")); 1097 _("Failed to start HTTP server\n"));
1046 GNUNET_SCHEDULER_shutdown (); 1098 GNUNET_SCHEDULER_shutdown ();
1047 return; 1099 return;
1048 } 1100 }
@@ -1069,32 +1121,34 @@ run (void *cls,
1069 (void) cfgfile; 1121 (void) cfgfile;
1070 if (GNUNET_OK != 1122 if (GNUNET_OK !=
1071 GNUNET_CONFIGURATION_get_value_number (cfg, 1123 GNUNET_CONFIGURATION_get_value_number (cfg,
1072 "fcfsd", 1124 "fcfsd",
1073 "HTTPPORT", 1125 "HTTPPORT",
1074 &port)) 1126 &port))
1075 { 1127 {
1076 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 1128 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1077 "fcfsd", "HTTPPORT"); 1129 "fcfsd", "HTTPPORT");
1078 return; 1130 return;
1079 } 1131 }
1080 ns = GNUNET_NAMESTORE_connect (cfg); 1132 ns = GNUNET_NAMESTORE_connect (cfg);
1081 if (NULL == ns) 1133 if (NULL == ns)
1082 { 1134 {
1083 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1135 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1084 _("Failed to connect to namestore\n")); 1136 _("Failed to connect to namestore\n"));
1085 return; 1137 return;
1086 } 1138 }
1087 identity = GNUNET_IDENTITY_connect (cfg, 1139 identity = GNUNET_IDENTITY_connect (cfg,
1088 NULL, NULL); 1140 &identity_cb,
1141 NULL);
1089 if (NULL == identity) 1142 if (NULL == identity)
1090 { 1143 {
1091 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1144 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1092 _("Failed to connect to identity\n")); 1145 _("Failed to connect to identity\n"));
1093 return; 1146 return;
1094 } 1147 }
1095 id_op = GNUNET_IDENTITY_get (identity, "fcfsd", 1148 uzp_task = GNUNET_SCHEDULER_add_now (&update_zoneinfo_page,
1096 &identity_cb, NULL); 1149 NULL);
1097 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 1150 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
1151 NULL);
1098} 1152}
1099 1153
1100 1154
@@ -1109,27 +1163,33 @@ int
1109main (int argc, 1163main (int argc,
1110 char *const *argv) 1164 char *const *argv)
1111{ 1165{
1112 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 1166 struct GNUNET_GETOPT_CommandLineOption options[] = {
1167 GNUNET_GETOPT_option_mandatory
1168 (GNUNET_GETOPT_option_string ('z',
1169 "zone",
1170 "EGO",
1171 gettext_noop ("name of the zone that is to be managed by FCFSD"),
1172 &zone)),
1113 GNUNET_GETOPT_OPTION_END 1173 GNUNET_GETOPT_OPTION_END
1114 }; 1174 };
1115 int ret; 1175 int ret;
1116 1176
1117 if (GNUNET_OK != 1177 if (GNUNET_OK !=
1118 GNUNET_STRINGS_get_utf8_args (argc, argv, 1178 GNUNET_STRINGS_get_utf8_args (argc, argv,
1119 &argc, &argv)) 1179 &argc, &argv))
1120 return 2; 1180 return 2;
1121 1181
1122 GNUNET_log_setup ("fcfsd", 1182 GNUNET_log_setup ("fcfsd",
1123 "WARNING", 1183 "WARNING",
1124 NULL); 1184 NULL);
1125 ret = 1185 ret =
1126 (GNUNET_OK == 1186 (GNUNET_OK ==
1127 GNUNET_PROGRAM_run (argc, 1187 GNUNET_PROGRAM_run (argc,
1128 argv, 1188 argv,
1129 "gnunet-namestore-fcfsd", 1189 "gnunet-namestore-fcfsd",
1130 _("GNU Name System First Come First Serve name registration service"), 1190 _("GNU Name System First Come First Serve name registration service"),
1131 options, 1191 options,
1132 &run, NULL)) ? 0 : 1; 1192 &run, NULL)) ? 0 : 1;
1133 GNUNET_free ((void*) argv); 1193 GNUNET_free ((void*) argv);
1134 GNUNET_CRYPTO_ecdsa_key_clear (&fcfs_zone_pkey); 1194 GNUNET_CRYPTO_ecdsa_key_clear (&fcfs_zone_pkey);
1135 return ret; 1195 return ret;
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index d329dcb3b..c5f48848e 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gnunet-namestore.c 19 * @file gnunet-namestore.c
@@ -80,6 +78,11 @@ static struct GNUNET_NAMESTORE_QueueEntry *add_qe_uri;
80static struct GNUNET_NAMESTORE_QueueEntry *add_qe; 78static struct GNUNET_NAMESTORE_QueueEntry *add_qe;
81 79
82/** 80/**
81 * Queue entry for the 'lookup' operation.
82 */
83static struct GNUNET_NAMESTORE_QueueEntry *get_qe;
84
85/**
83 * Queue entry for the 'reverse lookup' operation (in combination with a name). 86 * Queue entry for the 'reverse lookup' operation (in combination with a name).
84 */ 87 */
85static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; 88static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe;
@@ -234,6 +237,11 @@ do_shutdown (void *cls)
234 GNUNET_NAMESTORE_cancel (add_qe_uri); 237 GNUNET_NAMESTORE_cancel (add_qe_uri);
235 add_qe_uri = NULL; 238 add_qe_uri = NULL;
236 } 239 }
240 if (NULL != get_qe)
241 {
242 GNUNET_NAMESTORE_cancel (get_qe);
243 get_qe = NULL;
244 }
237 if (NULL != del_qe) 245 if (NULL != del_qe)
238 { 246 {
239 GNUNET_NAMESTORE_cancel (del_qe); 247 GNUNET_NAMESTORE_cancel (del_qe);
@@ -271,6 +279,7 @@ test_finished ()
271{ 279{
272 if ( (NULL == add_qe) && 280 if ( (NULL == add_qe) &&
273 (NULL == add_qe_uri) && 281 (NULL == add_qe_uri) &&
282 (NULL == get_qe) &&
274 (NULL == del_qe) && 283 (NULL == del_qe) &&
275 (NULL == reverse_qe) && 284 (NULL == reverse_qe) &&
276 (NULL == list_it) ) 285 (NULL == list_it) )
@@ -374,16 +383,12 @@ zone_iteration_error_cb (void *cls)
374/** 383/**
375 * Process a record that was stored in the namestore. 384 * Process a record that was stored in the namestore.
376 * 385 *
377 * @param cls closure
378 * @param zone_key private key of the zone
379 * @param rname name that is being mapped (at most 255 characters long) 386 * @param rname name that is being mapped (at most 255 characters long)
380 * @param rd_len number of entries in @a rd array 387 * @param rd_len number of entries in @a rd array
381 * @param rd array of records with data to store 388 * @param rd array of records with data to store
382 */ 389 */
383static void 390static void
384display_record (void *cls, 391display_record (const char *rname,
385 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
386 const char *rname,
387 unsigned int rd_len, 392 unsigned int rd_len,
388 const struct GNUNET_GNSRECORD_Data *rd) 393 const struct GNUNET_GNSRECORD_Data *rd)
389{ 394{
@@ -393,8 +398,6 @@ display_record (void *cls,
393 struct GNUNET_TIME_Absolute at; 398 struct GNUNET_TIME_Absolute at;
394 struct GNUNET_TIME_Relative rt; 399 struct GNUNET_TIME_Relative rt;
395 400
396 (void) cls;
397 (void) zone_key;
398 if ( (NULL != name) && 401 if ( (NULL != name) &&
399 (0 != strcmp (name, rname)) ) 402 (0 != strcmp (name, rname)) )
400 { 403 {
@@ -442,12 +445,86 @@ display_record (void *cls,
442 GNUNET_free (s); 445 GNUNET_free (s);
443 } 446 }
444 FPRINTF (stdout, "%s", "\n"); 447 FPRINTF (stdout, "%s", "\n");
448}
449
450
451/**
452 * Process a record that was stored in the namestore.
453 *
454 * @param cls closure
455 * @param zone_key private key of the zone
456 * @param rname name that is being mapped (at most 255 characters long)
457 * @param rd_len number of entries in @a rd array
458 * @param rd array of records with data to store
459 */
460static void
461display_record_iterator (void *cls,
462 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
463 const char *rname,
464 unsigned int rd_len,
465 const struct GNUNET_GNSRECORD_Data *rd)
466{
467 (void) cls;
468 (void) zone_key;
469 display_record (rname,
470 rd_len,
471 rd);
445 GNUNET_NAMESTORE_zone_iterator_next (list_it, 472 GNUNET_NAMESTORE_zone_iterator_next (list_it,
446 1); 473 1);
447} 474}
448 475
449 476
450/** 477/**
478 * Process a record that was stored in the namestore.
479 *
480 * @param cls closure
481 * @param zone_key private key of the zone
482 * @param rname name that is being mapped (at most 255 characters long)
483 * @param rd_len number of entries in @a rd array
484 * @param rd array of records with data to store
485 */
486static void
487display_record_monitor (void *cls,
488 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
489 const char *rname,
490 unsigned int rd_len,
491 const struct GNUNET_GNSRECORD_Data *rd)
492{
493 (void) cls;
494 (void) zone_key;
495 display_record (rname,
496 rd_len,
497 rd);
498 GNUNET_NAMESTORE_zone_monitor_next (zm,
499 1);
500}
501
502
503/**
504 * Process a record that was stored in the namestore.
505 *
506 * @param cls closure
507 * @param zone_key private key of the zone
508 * @param rname name that is being mapped (at most 255 characters long)
509 * @param rd_len number of entries in @a rd array
510 * @param rd array of records with data to store
511 */
512static void
513display_record_lookup (void *cls,
514 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
515 const char *rname,
516 unsigned int rd_len,
517 const struct GNUNET_GNSRECORD_Data *rd)
518{
519 get_qe = NULL;
520 display_record (rname,
521 rd_len,
522 rd);
523 test_finished ();
524}
525
526
527/**
451 * Function called once we are in sync in monitor mode. 528 * Function called once we are in sync in monitor mode.
452 * 529 *
453 * @param cls NULL 530 * @param cls NULL
@@ -478,12 +555,29 @@ monitor_error_cb (void *cls)
478 555
479 556
480/** 557/**
481 * Function called if lookup fails. 558 * Function called on errors while monitoring.
559 *
560 * @param cls NULL
482 */ 561 */
483static void 562static void
484lookup_error_cb (void *cls) 563lookup_error_cb (void *cls)
485{ 564{
486 (void) cls; 565 (void) cls;
566 get_qe = NULL;
567 FPRINTF (stderr,
568 "%s",
569 "Failed to lookup record.\n");
570 test_finished ();
571}
572
573
574/**
575 * Function called if lookup fails.
576 */
577static void
578add_error_cb (void *cls)
579{
580 (void) cls;
487 add_qe = NULL; 581 add_qe = NULL;
488 GNUNET_break (0); 582 GNUNET_break (0);
489 ret = 1; 583 ret = 1;
@@ -545,14 +639,6 @@ get_existing_record (void *cls,
545 ret = 1; 639 ret = 1;
546 test_finished (); 640 test_finished ();
547 return; 641 return;
548 case GNUNET_GNSRECORD_TYPE_GNS2DNS:
549 fprintf (stderr,
550 _("A %s record exists already under `%s', no other records can be added.\n"),
551 "GNS2DNS",
552 rec_name);
553 ret = 1;
554 test_finished ();
555 return;
556 } 642 }
557 } 643 }
558 switch (type) 644 switch (type)
@@ -582,16 +668,16 @@ get_existing_record (void *cls,
582 } 668 }
583 break; 669 break;
584 case GNUNET_GNSRECORD_TYPE_GNS2DNS: 670 case GNUNET_GNSRECORD_TYPE_GNS2DNS:
585 if (0 != rd_count) 671 for (unsigned int i=0;i<rd_count;i++)
586 { 672 if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type)
587 fprintf (stderr, 673 {
588 _("Records already exist under `%s', cannot add `%s' record.\n"), 674 fprintf (stderr,
589 rec_name, 675 _("Non-GNS2DNS records already exist under `%s', cannot add GNS2DNS record.\n"),
590 "GNS2DNS"); 676 rec_name);
591 ret = 1; 677 ret = 1;
592 test_finished (); 678 test_finished ();
593 return; 679 return;
594 } 680 }
595 break; 681 break;
596 } 682 }
597 memset (rdn, 683 memset (rdn,
@@ -666,12 +752,13 @@ handle_reverse_lookup (void *cls,
666 reverse_qe = NULL; 752 reverse_qe = NULL;
667 if (NULL == label) 753 if (NULL == label)
668 FPRINTF (stdout, 754 FPRINTF (stdout,
669 "%s.zkey\n", 755 "%s\n",
670 reverse_pkey); 756 reverse_pkey);
671 else 757 else
672 FPRINTF (stdout, 758 FPRINTF (stdout,
673 "%s.gnu\n", 759 "%s.%s\n",
674 label); 760 label,
761 ego_name);
675 test_finished (); 762 test_finished ();
676} 763}
677 764
@@ -926,7 +1013,7 @@ identity_cb (void *cls,
926 add_qe = GNUNET_NAMESTORE_records_lookup (ns, 1013 add_qe = GNUNET_NAMESTORE_records_lookup (ns,
927 &zone_pkey, 1014 &zone_pkey,
928 name, 1015 name,
929 &lookup_error_cb, 1016 &add_error_cb,
930 NULL, 1017 NULL,
931 &get_existing_record, 1018 &get_existing_record,
932 NULL); 1019 NULL);
@@ -952,14 +1039,23 @@ identity_cb (void *cls,
952 } 1039 }
953 if (list) 1040 if (list)
954 { 1041 {
955 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, 1042 if (NULL != name)
956 &zone_pkey, 1043 get_qe = GNUNET_NAMESTORE_records_lookup (ns,
957 &zone_iteration_error_cb, 1044 &zone_pkey,
958 NULL, 1045 name,
959 &display_record, 1046 &lookup_error_cb,
960 NULL, 1047 NULL,
961 &zone_iteration_finished, 1048 &display_record_lookup,
962 NULL); 1049 NULL);
1050 else
1051 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
1052 &zone_pkey,
1053 &zone_iteration_error_cb,
1054 NULL,
1055 &display_record_iterator,
1056 NULL,
1057 &zone_iteration_finished,
1058 NULL);
963 } 1059 }
964 if (NULL != reverse_pkey) 1060 if (NULL != reverse_pkey)
965 { 1061 {
@@ -1054,7 +1150,7 @@ identity_cb (void *cls,
1054 GNUNET_YES, 1150 GNUNET_YES,
1055 &monitor_error_cb, 1151 &monitor_error_cb,
1056 NULL, 1152 NULL,
1057 &display_record, 1153 &display_record_monitor,
1058 NULL, 1154 NULL,
1059 &sync_cb, 1155 &sync_cb,
1060 NULL); 1156 NULL);
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index f47c8776b..2d6020552 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1,21 +1,19 @@
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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
@@ -23,6 +21,9 @@
23 * @brief namestore for the GNUnet naming system 21 * @brief namestore for the GNUnet naming system
24 * @author Matthias Wachs 22 * @author Matthias Wachs
25 * @author Christian Grothoff 23 * @author Christian Grothoff
24 *
25 * TODO:
26 * - run testcases, make sure everything works!
26 */ 27 */
27#include "platform.h" 28#include "platform.h"
28#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
@@ -37,6 +38,11 @@
37 38
38#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) 39#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
39 40
41/**
42 * If a monitor takes more than 1 minute to process an event, print a warning.
43 */
44#define MONITOR_STALL_WARN_DELAY GNUNET_TIME_UNIT_MINUTES
45
40 46
41/** 47/**
42 * A namestore client 48 * A namestore client
@@ -161,6 +167,16 @@ struct ZoneMonitor
161 struct GNUNET_SCHEDULER_Task *task; 167 struct GNUNET_SCHEDULER_Task *task;
162 168
163 /** 169 /**
170 * Task to warn about slow monitors.
171 */
172 struct GNUNET_SCHEDULER_Task *sa_wait_warning;
173
174 /**
175 * Since when are we blocked on this monitor?
176 */
177 struct GNUNET_TIME_Absolute sa_waiting_start;
178
179 /**
164 * Last sequence number in the zone iteration used to address next 180 * Last sequence number in the zone iteration used to address next
165 * result of the zone iteration in the store 181 * result of the zone iteration in the store
166 * 182 *
@@ -175,6 +191,27 @@ struct ZoneMonitor
175 */ 191 */
176 uint64_t limit; 192 uint64_t limit;
177 193
194 /**
195 * How many more requests may we receive from the iterator
196 * before it is at the limit we gave it? Will be below or
197 * equal to @e limit. The effective limit for monitor
198 * events is thus @e iteration_cnt - @e limit!
199 */
200 uint64_t iteration_cnt;
201
202 /**
203 * Are we (still) in the initial iteration pass?
204 */
205 int in_first_iteration;
206
207 /**
208 * Is there a store activity waiting for this monitor? We only raise the
209 * flag when it happens and search the DLL for the store activity when we
210 * had a limit increase. If we cannot find any waiting store activity at
211 * that time, we clear the flag again.
212 */
213 int sa_waiting;
214
178}; 215};
179 216
180 217
@@ -212,6 +249,46 @@ struct CacheOperation
212 249
213 250
214/** 251/**
252 * Information for an ongoing #handle_record_store() operation.
253 * Needed as we may wait for monitors to be ready for the notification.
254 */
255struct StoreActivity
256{
257 /**
258 * Kept in a DLL.
259 */
260 struct StoreActivity *next;
261
262 /**
263 * Kept in a DLL.
264 */
265 struct StoreActivity *prev;
266
267 /**
268 * Which client triggered the store activity?
269 */
270 struct NamestoreClient *nc;
271
272 /**
273 * Copy of the original store message (as data fields in @e rd will
274 * point into it!).
275 */
276 const struct RecordStoreMessage *rsm;
277
278 /**
279 * Next zone monitor that still needs to be notified about this PUT.
280 */
281 struct ZoneMonitor *zm_pos;
282
283 /**
284 * Label nicely canonicalized (lower case).
285 */
286 char *conv_name;
287
288};
289
290
291/**
215 * Public key of all zeros. 292 * Public key of all zeros.
216 */ 293 */
217static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero; 294static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero;
@@ -262,6 +339,16 @@ static struct ZoneMonitor *monitor_head;
262static struct ZoneMonitor *monitor_tail; 339static struct ZoneMonitor *monitor_tail;
263 340
264/** 341/**
342 * Head of DLL of monitor-blocked store activities.
343 */
344static struct StoreActivity *sa_head;
345
346/**
347 * Tail of DLL of monitor-blocked store activities.
348 */
349static struct StoreActivity *sa_tail;
350
351/**
265 * Notification context shared by all monitors. 352 * Notification context shared by all monitors.
266 */ 353 */
267static struct GNUNET_NotificationContext *monitor_nc; 354static struct GNUNET_NotificationContext *monitor_nc;
@@ -326,80 +413,18 @@ cleanup_task (void *cls)
326 413
327 414
328/** 415/**
329 * Called whenever a client is disconnected. 416 * Release memory used by @a sa.
330 * Frees our resources associated with that client.
331 * 417 *
332 * @param cls closure 418 * @param sa activity to free
333 * @param client identification of the client
334 * @param app_ctx the `struct NamestoreClient` of @a client
335 */ 419 */
336static void 420static void
337client_disconnect_cb (void *cls, 421free_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 */
388static void *
389client_connect_cb (void *cls,
390 struct GNUNET_SERVICE_Client *client,
391 struct GNUNET_MQ_Handle *mq)
392{ 422{
393 struct NamestoreClient *nc; 423 GNUNET_CONTAINER_DLL_remove (sa_head,
394 424 sa_tail,
395 (void) cls; 425 sa);
396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 426 GNUNET_free (sa->conv_name);
397 "Client %p connected\n", 427 GNUNET_free (sa);
398 client);
399 nc = GNUNET_new (struct NamestoreClient);
400 nc->client = client;
401 nc->mq = mq;
402 return nc;
403} 428}
404 429
405 430
@@ -509,51 +534,63 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
509 uint64_t latest_expiration; 534 uint64_t latest_expiration;
510 size_t req; 535 size_t req;
511 char *data; 536 char *data;
512 int record_offset;
513 size_t data_offset; 537 size_t data_offset;
538 struct GNUNET_GNSRECORD_Data *target;
514 539
515 (*rdc_res) = 1 + rd2_length; 540 (*rdc_res) = 1 + rd2_length;
516 if (0 == 1 + rd2_length) 541 if (0 == 1 + rd2_length)
517 { 542 {
543 GNUNET_break (0);
518 (*rd_res) = NULL; 544 (*rd_res) = NULL;
519 return; 545 return;
520 } 546 }
521 req = 0; 547 req = sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd->data_size;
522 for (unsigned int c=0; c< 1; c++) 548 for (unsigned int i=0; i<rd2_length; i++)
523 req += sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd[c].data_size; 549 {
524 for (unsigned int c=0; c< rd2_length; c++) 550 const struct GNUNET_GNSRECORD_Data *orig = &rd2[i];
525 req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size; 551
526 (*rd_res) = GNUNET_malloc (req); 552 if (req + sizeof (struct GNUNET_GNSRECORD_Data) + orig->data_size < req)
527 data = (char *) &(*rd_res)[1 + rd2_length]; 553 {
554 GNUNET_break (0);
555 (*rd_res) = NULL;
556 return;
557 }
558 req += sizeof (struct GNUNET_GNSRECORD_Data) + orig->data_size;
559 }
560 target = GNUNET_malloc (req);
561 (*rd_res) = target;
562 data = (char *) &target[1 + rd2_length];
528 data_offset = 0; 563 data_offset = 0;
529 latest_expiration = 0; 564 latest_expiration = 0;
530 for (unsigned int c=0; c< rd2_length; c++) 565 for (unsigned int i=0;i<rd2_length;i++)
531 { 566 {
532 if (0 != (rd2[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) 567 const struct GNUNET_GNSRECORD_Data *orig = &rd2[i];
568
569 if (0 != (orig->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
533 { 570 {
534 if ((GNUNET_TIME_absolute_get().abs_value_us + rd2[c].expiration_time) > 571 if ((GNUNET_TIME_absolute_get().abs_value_us + orig->expiration_time) >
535 latest_expiration) 572 latest_expiration)
536 latest_expiration = rd2[c].expiration_time; 573 latest_expiration = orig->expiration_time;
537 } 574 }
538 else if (rd2[c].expiration_time > latest_expiration) 575 else if (orig->expiration_time > latest_expiration)
539 latest_expiration = rd2[c].expiration_time; 576 latest_expiration = orig->expiration_time;
540 (*rd_res)[c] = rd2[c]; 577 target[i] = *orig;
541 (*rd_res)[c].data = (void *) &data[data_offset]; 578 target[i].data = (void *) &data[data_offset];
542 GNUNET_memcpy ((void *) (*rd_res)[c].data, 579 GNUNET_memcpy (&data[data_offset],
543 rd2[c].data, 580 orig->data,
544 rd2[c].data_size); 581 orig->data_size);
545 data_offset += (*rd_res)[c].data_size; 582 data_offset += orig->data_size;
546 } 583 }
547 /* append nick */ 584 /* append nick */
548 record_offset = rd2_length; 585 target[rd2_length] = *nick_rd;
549 (*rd_res)[record_offset] = *nick_rd; 586 target[rd2_length].expiration_time = latest_expiration;
550 (*rd_res)[record_offset].expiration_time = latest_expiration; 587 target[rd2_length].data = (void *) &data[data_offset];
551 (*rd_res)[record_offset].data = (void *) &data[data_offset]; 588 GNUNET_memcpy (&data[data_offset],
552 GNUNET_memcpy ((void *) (*rd_res)[record_offset].data,
553 nick_rd->data, 589 nick_rd->data,
554 nick_rd->data_size); 590 nick_rd->data_size);
555 data_offset += (*rd_res)[record_offset].data_size; 591 data_offset += nick_rd->data_size;
556 GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset); 592 GNUNET_assert (req ==
593 (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset);
557} 594}
558 595
559 596
@@ -582,11 +619,16 @@ send_lookup_response (struct NamestoreClient *nc,
582 struct GNUNET_GNSRECORD_Data *res; 619 struct GNUNET_GNSRECORD_Data *res;
583 unsigned int res_count; 620 unsigned int res_count;
584 size_t name_len; 621 size_t name_len;
585 size_t rd_ser_len; 622 ssize_t rd_ser_len;
586 char *name_tmp; 623 char *name_tmp;
587 char *rd_ser; 624 char *rd_ser;
588 625
589 nick = get_nick_record (zone_key); 626 nick = get_nick_record (zone_key);
627
628 GNUNET_assert (-1 !=
629 GNUNET_GNSRECORD_records_get_size (rd_count,
630 rd));
631
590 if ( (NULL != nick) && 632 if ( (NULL != nick) &&
591 (0 != strcmp (name, 633 (0 != strcmp (name,
592 GNUNET_GNS_EMPTY_LABEL_AT))) 634 GNUNET_GNS_EMPTY_LABEL_AT)))
@@ -605,25 +647,44 @@ send_lookup_response (struct NamestoreClient *nc,
605 res = (struct GNUNET_GNSRECORD_Data *) rd; 647 res = (struct GNUNET_GNSRECORD_Data *) rd;
606 } 648 }
607 649
650 GNUNET_assert (-1 !=
651 GNUNET_GNSRECORD_records_get_size (res_count,
652 res));
653
654
608 name_len = strlen (name) + 1; 655 name_len = strlen (name) + 1;
609 rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res); 656 rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count,
657 res);
658 if (rd_ser_len < 0)
659 {
660 GNUNET_break (0);
661 GNUNET_SERVICE_client_drop (nc->client);
662 return;
663 }
664 if (rd_ser_len >= UINT16_MAX - name_len - sizeof (*zir_msg))
665 {
666 GNUNET_break (0);
667 GNUNET_SERVICE_client_drop (nc->client);
668 return;
669 }
610 env = GNUNET_MQ_msg_extra (zir_msg, 670 env = GNUNET_MQ_msg_extra (zir_msg,
611 name_len + rd_ser_len, 671 name_len + rd_ser_len,
612 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); 672 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
613 zir_msg->gns_header.r_id = htonl (request_id); 673 zir_msg->gns_header.r_id = htonl (request_id);
614 zir_msg->name_len = htons (name_len); 674 zir_msg->name_len = htons (name_len);
615 zir_msg->rd_count = htons (res_count); 675 zir_msg->rd_count = htons (res_count);
616 zir_msg->rd_len = htons (rd_ser_len); 676 zir_msg->rd_len = htons ((uint16_t) rd_ser_len);
617 zir_msg->private_key = *zone_key; 677 zir_msg->private_key = *zone_key;
618 name_tmp = (char *) &zir_msg[1]; 678 name_tmp = (char *) &zir_msg[1];
619 GNUNET_memcpy (name_tmp, 679 GNUNET_memcpy (name_tmp,
620 name, 680 name,
621 name_len); 681 name_len);
622 rd_ser = &name_tmp[name_len]; 682 rd_ser = &name_tmp[name_len];
623 GNUNET_GNSRECORD_records_serialize (res_count, 683 GNUNET_assert (rd_ser_len ==
624 res, 684 GNUNET_GNSRECORD_records_serialize (res_count,
625 rd_ser_len, 685 res,
626 rd_ser); 686 rd_ser_len,
687 rd_ser));
627 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
628 "Sending RECORD_RESULT message with %u records\n", 689 "Sending RECORD_RESULT message with %u records\n",
629 res_count); 690 res_count);
@@ -655,6 +716,10 @@ send_store_response (struct NamestoreClient *nc,
655 716
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 "Sending RECORD_STORE_RESPONSE message\n"); 718 "Sending RECORD_STORE_RESPONSE message\n");
719 GNUNET_STATISTICS_update (statistics,
720 "Store requests completed",
721 1,
722 GNUNET_NO);
658 env = GNUNET_MQ_msg (rcr_msg, 723 env = GNUNET_MQ_msg (rcr_msg,
659 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); 724 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE);
660 rcr_msg->gns_header.r_id = htonl (rid); 725 rcr_msg->gns_header.r_id = htonl (rid);
@@ -795,6 +860,206 @@ refresh_block (struct NamestoreClient *nc,
795 860
796 861
797/** 862/**
863 * Print a warning that one of our monitors is no longer reacting.
864 *
865 * @param cls a `struct ZoneMonitor` to warn about
866 */
867static void
868warn_monitor_slow (void *cls)
869{
870 struct ZoneMonitor *zm = cls;
871
872 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
873 "No response from monitor since %s\n",
874 GNUNET_STRINGS_absolute_time_to_string (zm->sa_waiting_start));
875 zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
876 &warn_monitor_slow,
877 zm);
878}
879
880
881/**
882 * Continue processing the @a sa.
883 *
884 * @param sa store activity to process
885 */
886static void
887continue_store_activity (struct StoreActivity *sa)
888{
889 const struct RecordStoreMessage *rp_msg = sa->rsm;
890 unsigned int rd_count;
891 size_t name_len;
892 size_t rd_ser_len;
893 uint32_t rid;
894 const char *name_tmp;
895 const char *rd_ser;
896
897 rid = ntohl (rp_msg->gns_header.r_id);
898 name_len = ntohs (rp_msg->name_len);
899 rd_count = ntohs (rp_msg->rd_count);
900 rd_ser_len = ntohs (rp_msg->rd_len);
901 name_tmp = (const char *) &rp_msg[1];
902 rd_ser = &name_tmp[name_len];
903 {
904 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
905
906 /* We did this before, must succeed again */
907 GNUNET_assert (GNUNET_OK ==
908 GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
909 rd_ser,
910 rd_count,
911 rd));
912
913 for (struct ZoneMonitor *zm = sa->zm_pos;
914 NULL != zm;
915 zm = sa->zm_pos)
916 {
917 if ( (0 != memcmp (&rp_msg->private_key,
918 &zm->zone,
919 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) &&
920 (0 != memcmp (&zm->zone,
921 &zero,
922 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
923 sa->zm_pos = zm->next; /* not interesting to this monitor */
924 if (zm->limit == zm->iteration_cnt)
925 {
926 zm->sa_waiting = GNUNET_YES;
927 zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
928 if (NULL != zm->sa_wait_warning)
929 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
930 zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
931 &warn_monitor_slow,
932 zm);
933 return; /* blocked on zone monitor */
934 }
935 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
936 "Notifying monitor about changes under label `%s'\n",
937 sa->conv_name);
938 zm->limit--;
939 send_lookup_response (zm->nc,
940 0,
941 &rp_msg->private_key,
942 sa->conv_name,
943 rd_count,
944 rd);
945 sa->zm_pos = zm->next;
946 }
947 /* great, done with the monitors, unpack (again) for refresh_block operation */
948 refresh_block (sa->nc,
949 rid,
950 &rp_msg->private_key,
951 sa->conv_name,
952 rd_count,
953 rd);
954 }
955 GNUNET_SERVICE_client_continue (sa->nc->client);
956 free_store_activity (sa);
957}
958
959
960/**
961 * Called whenever a client is disconnected.
962 * Frees our resources associated with that client.
963 *
964 * @param cls closure
965 * @param client identification of the client
966 * @param app_ctx the `struct NamestoreClient` of @a client
967 */
968static void
969client_disconnect_cb (void *cls,
970 struct GNUNET_SERVICE_Client *client,
971 void *app_ctx)
972{
973 struct NamestoreClient *nc = app_ctx;
974 struct ZoneIteration *no;
975 struct CacheOperation *cop;
976
977 (void) cls;
978 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
979 "Client %p disconnected\n",
980 client);
981 for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next)
982 {
983 struct StoreActivity *san;
984
985 if (nc != zm->nc)
986 continue;
987 GNUNET_CONTAINER_DLL_remove (monitor_head,
988 monitor_tail,
989 zm);
990 if (NULL != zm->task)
991 {
992 GNUNET_SCHEDULER_cancel (zm->task);
993 zm->task = NULL;
994 }
995 if (NULL != zm->sa_wait_warning)
996 {
997 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
998 zm->sa_wait_warning = NULL;
999 }
1000 for (struct StoreActivity *sa = sa_head; NULL != sa; sa = san)
1001 {
1002 san = sa->next;
1003 if (zm == sa->zm_pos)
1004 {
1005 sa->zm_pos = zm->next;
1006 /* this may free sa */
1007 continue_store_activity (sa);
1008 }
1009 }
1010 GNUNET_free (zm);
1011 break;
1012 }
1013 for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
1014 {
1015 if (sa->nc == nc)
1016 {
1017 /* this may free sa */
1018 free_store_activity (sa);
1019 break; /* there can only be one per nc */
1020 }
1021 }
1022 while (NULL != (no = nc->op_head))
1023 {
1024 GNUNET_CONTAINER_DLL_remove (nc->op_head,
1025 nc->op_tail,
1026 no);
1027 GNUNET_free (no);
1028 }
1029 for (cop = cop_head; NULL != cop; cop = cop->next)
1030 if (nc == cop->nc)
1031 cop->nc = NULL;
1032 GNUNET_free (nc);
1033}
1034
1035
1036/**
1037 * Add a client to our list of active clients.
1038 *
1039 * @param cls NULL
1040 * @param client client to add
1041 * @param mq message queue for @a client
1042 * @return internal namestore client structure for this client
1043 */
1044static void *
1045client_connect_cb (void *cls,
1046 struct GNUNET_SERVICE_Client *client,
1047 struct GNUNET_MQ_Handle *mq)
1048{
1049 struct NamestoreClient *nc;
1050
1051 (void) cls;
1052 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1053 "Client %p connected\n",
1054 client);
1055 nc = GNUNET_new (struct NamestoreClient);
1056 nc->client = client;
1057 nc->mq = mq;
1058 return nc;
1059}
1060
1061
1062/**
798 * Closure for #lookup_it(). 1063 * Closure for #lookup_it().
799 */ 1064 */
800struct RecordLookupContext 1065struct RecordLookupContext
@@ -828,12 +1093,13 @@ struct RecordLookupContext
828 /** 1093 /**
829 * FIXME. 1094 * FIXME.
830 */ 1095 */
831 size_t rd_ser_len; 1096 ssize_t rd_ser_len;
832}; 1097};
833 1098
834 1099
835/** 1100/**
836 * FIXME. 1101 * FIXME.
1102 *
837 * @param seq sequence number of the record 1103 * @param seq sequence number of the record
838 */ 1104 */
839static void 1105static void
@@ -845,60 +1111,93 @@ lookup_it (void *cls,
845 const struct GNUNET_GNSRECORD_Data *rd) 1111 const struct GNUNET_GNSRECORD_Data *rd)
846{ 1112{
847 struct RecordLookupContext *rlc = cls; 1113 struct RecordLookupContext *rlc = cls;
848 struct GNUNET_GNSRECORD_Data *rd_res;
849 unsigned int rdc_res;
850 1114
851 (void) private_key; 1115 (void) private_key;
852 (void) seq; 1116 (void) seq;
853 if (0 == strcmp (label, 1117 if (0 != strcmp (label,
854 rlc->label)) 1118 rlc->label))
1119 return;
1120 rlc->found = GNUNET_YES;
1121 if (0 == rd_count)
855 { 1122 {
856 rlc->found = GNUNET_YES; 1123 rlc->rd_ser_len = 0;
857 if (0 != rd_count) 1124 rlc->res_rd_count = 0;
1125 rlc->res_rd = NULL;
1126 return;
1127 }
1128 if ( (NULL != rlc->nick) &&
1129 (0 != strcmp (label,
1130 GNUNET_GNS_EMPTY_LABEL_AT)) )
1131 {
1132 /* Merge */
1133 struct GNUNET_GNSRECORD_Data *rd_res;
1134 unsigned int rdc_res;
1135
1136 rd_res = NULL;
1137 rdc_res = 0;
1138 rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
1139 merge_with_nick_records (rlc->nick,
1140 rd_count,
1141 rd,
1142 &rdc_res,
1143 &rd_res);
1144 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res,
1145 rd_res);
1146 if (rlc->rd_ser_len < 0)
858 { 1147 {
859 if ( (NULL != rlc->nick) && 1148 GNUNET_break (0);
860 (0 != strcmp (label, 1149 GNUNET_free (rd_res);
861 GNUNET_GNS_EMPTY_LABEL_AT)) ) 1150 rlc->found = GNUNET_NO;
862 { 1151 rlc->rd_ser_len = 0;
863 /* Merge */ 1152 return;
864 rd_res = NULL; 1153 }
865 rdc_res = 0; 1154 rlc->res_rd_count = rdc_res;
866 rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; 1155 rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len);
867 merge_with_nick_records (rlc->nick, 1156 if (rlc->rd_ser_len !=
868 rd_count,
869 rd,
870 &rdc_res,
871 &rd_res);
872 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res,
873 rd_res);
874 rlc->res_rd_count = rdc_res;
875 rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len);
876 GNUNET_GNSRECORD_records_serialize (rdc_res, 1157 GNUNET_GNSRECORD_records_serialize (rdc_res,
877 rd_res, 1158 rd_res,
878 rlc->rd_ser_len, 1159 rlc->rd_ser_len,
879 rlc->res_rd); 1160 rlc->res_rd))
880 1161 {
881 GNUNET_free (rd_res); 1162 GNUNET_break (0);
882 GNUNET_free (rlc->nick); 1163 GNUNET_free (rlc->res_rd);
883 rlc->nick = NULL; 1164 rlc->res_rd = NULL;
884 } 1165 rlc->res_rd_count = 0;
885 else 1166 rlc->rd_ser_len = 0;
886 { 1167 GNUNET_free (rd_res);
887 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, 1168 rlc->found = GNUNET_NO;
888 rd); 1169 return;
889 rlc->res_rd_count = rd_count; 1170 }
890 rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); 1171 GNUNET_free (rd_res);
1172 GNUNET_free (rlc->nick);
1173 rlc->nick = NULL;
1174 }
1175 else
1176 {
1177 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count,
1178 rd);
1179 if (rlc->rd_ser_len < 0)
1180 {
1181 GNUNET_break (0);
1182 rlc->found = GNUNET_NO;
1183 rlc->rd_ser_len = 0;
1184 return;
1185 }
1186 rlc->res_rd_count = rd_count;
1187 rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len);
1188 if (rlc->rd_ser_len !=
891 GNUNET_GNSRECORD_records_serialize (rd_count, 1189 GNUNET_GNSRECORD_records_serialize (rd_count,
892 rd, 1190 rd,
893 rlc->rd_ser_len, 1191 rlc->rd_ser_len,
894 rlc->res_rd); 1192 rlc->res_rd))
895 }
896 }
897 else
898 { 1193 {
899 rlc->rd_ser_len = 0; 1194 GNUNET_break (0);
900 rlc->res_rd_count = 0; 1195 GNUNET_free (rlc->res_rd);
901 rlc->res_rd = NULL; 1196 rlc->res_rd = NULL;
1197 rlc->res_rd_count = 0;
1198 rlc->rd_ser_len = 0;
1199 rlc->found = GNUNET_NO;
1200 return;
902 } 1201 }
903 } 1202 }
904} 1203}
@@ -1073,7 +1372,7 @@ handle_record_store (void *cls,
1073 const char *rd_ser; 1372 const char *rd_ser;
1074 unsigned int rd_count; 1373 unsigned int rd_count;
1075 int res; 1374 int res;
1076 struct ZoneMonitor *zm; 1375 struct StoreActivity *sa;
1077 1376
1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1079 "Received NAMESTORE_RECORD_STORE message\n"); 1378 "Received NAMESTORE_RECORD_STORE message\n");
@@ -1085,7 +1384,7 @@ handle_record_store (void *cls,
1085 name_tmp = (const char *) &rp_msg[1]; 1384 name_tmp = (const char *) &rp_msg[1];
1086 rd_ser = &name_tmp[name_len]; 1385 rd_ser = &name_tmp[name_len];
1087 { 1386 {
1088 struct GNUNET_GNSRECORD_Data rd[rd_count]; 1387 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
1089 1388
1090 if (GNUNET_OK != 1389 if (GNUNET_OK !=
1091 GNUNET_GNSRECORD_records_deserialize (rd_ser_len, 1390 GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
@@ -1108,6 +1407,10 @@ handle_record_store (void *cls,
1108 GNUNET_SERVICE_client_drop (nc->client); 1407 GNUNET_SERVICE_client_drop (nc->client);
1109 return; 1408 return;
1110 } 1409 }
1410 GNUNET_STATISTICS_update (statistics,
1411 "Well-formed store requests received",
1412 1,
1413 GNUNET_NO);
1111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1112 "Creating %u records for name `%s'\n", 1415 "Creating %u records for name `%s'\n",
1113 (unsigned int) rd_count, 1416 (unsigned int) rd_count,
@@ -1128,11 +1431,11 @@ handle_record_store (void *cls,
1128 } 1431 }
1129 else 1432 else
1130 { 1433 {
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 1434 /* remove "NICK" records, unless this is for the
1135 #GNUNET_GNS_EMPTY_LABEL_AT label */ 1435 #GNUNET_GNS_EMPTY_LABEL_AT label */
1436 struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
1437 unsigned int rd_clean_off;
1438
1136 rd_clean_off = 0; 1439 rd_clean_off = 0;
1137 for (unsigned int i=0;i<rd_count;i++) 1440 for (unsigned int i=0;i<rd_count;i++)
1138 { 1441 {
@@ -1147,59 +1450,33 @@ handle_record_store (void *cls,
1147 conv_name, 1450 conv_name,
1148 rd_clean_off, 1451 rd_clean_off,
1149 rd_clean); 1452 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 } 1453 }
1185 if (GNUNET_OK == res) 1454
1455 if (GNUNET_OK != res)
1186 { 1456 {
1187 refresh_block (nc, 1457 /* store not successful, not need to tell monitors */
1188 rid, 1458 send_store_response (nc,
1189 &rp_msg->private_key, 1459 res,
1190 conv_name, 1460 rid);
1191 rd_count,
1192 rd);
1193 GNUNET_SERVICE_client_continue (nc->client); 1461 GNUNET_SERVICE_client_continue (nc->client);
1194 GNUNET_free (conv_name); 1462 GNUNET_free (conv_name);
1195 return; 1463 return;
1196 } 1464 }
1197 GNUNET_free (conv_name); 1465
1466 sa = GNUNET_malloc (sizeof (struct StoreActivity) +
1467 ntohs (rp_msg->gns_header.header.size));
1468 GNUNET_CONTAINER_DLL_insert (sa_head,
1469 sa_tail,
1470 sa);
1471 sa->nc = nc;
1472 sa->rsm = (const struct RecordStoreMessage *) &sa[1];
1473 GNUNET_memcpy (&sa[1],
1474 rp_msg,
1475 ntohs (rp_msg->gns_header.header.size));
1476 sa->zm_pos = monitor_head;
1477 sa->conv_name = conv_name;
1478 continue_store_activity (sa);
1198 } 1479 }
1199 send_store_response (nc,
1200 res,
1201 rid);
1202 GNUNET_SERVICE_client_continue (nc->client);
1203} 1480}
1204 1481
1205 1482
@@ -1251,7 +1528,7 @@ handle_zone_to_name_it (void *cls,
1251 struct ZoneToNameResponseMessage *ztnr_msg; 1528 struct ZoneToNameResponseMessage *ztnr_msg;
1252 int16_t res; 1529 int16_t res;
1253 size_t name_len; 1530 size_t name_len;
1254 size_t rd_ser_len; 1531 ssize_t rd_ser_len;
1255 size_t msg_size; 1532 size_t msg_size;
1256 char *name_tmp; 1533 char *name_tmp;
1257 char *rd_tmp; 1534 char *rd_tmp;
@@ -1262,7 +1539,14 @@ handle_zone_to_name_it (void *cls,
1262 name); 1539 name);
1263 res = GNUNET_YES; 1540 res = GNUNET_YES;
1264 name_len = (NULL == name) ? 0 : strlen (name) + 1; 1541 name_len = (NULL == name) ? 0 : strlen (name) + 1;
1265 rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); 1542 rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count,
1543 rd);
1544 if (rd_ser_len < 0)
1545 {
1546 GNUNET_break (0);
1547 ztn_ctx->success = GNUNET_SYSERR;
1548 return;
1549 }
1266 msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len; 1550 msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len;
1267 if (msg_size >= GNUNET_MAX_MESSAGE_SIZE) 1551 if (msg_size >= GNUNET_MAX_MESSAGE_SIZE)
1268 { 1552 {
@@ -1285,10 +1569,11 @@ handle_zone_to_name_it (void *cls,
1285 name, 1569 name,
1286 name_len); 1570 name_len);
1287 rd_tmp = &name_tmp[name_len]; 1571 rd_tmp = &name_tmp[name_len];
1288 GNUNET_GNSRECORD_records_serialize (rd_count, 1572 GNUNET_assert (rd_ser_len ==
1289 rd, 1573 GNUNET_GNSRECORD_records_serialize (rd_count,
1290 rd_ser_len, 1574 rd,
1291 rd_tmp); 1575 rd_ser_len,
1576 rd_tmp));
1292 ztn_ctx->success = GNUNET_OK; 1577 ztn_ctx->success = GNUNET_OK;
1293 GNUNET_MQ_send (ztn_ctx->nc->mq, 1578 GNUNET_MQ_send (ztn_ctx->nc->mq,
1294 env); 1579 env);
@@ -1311,8 +1596,7 @@ handle_zone_to_name (void *cls,
1311 struct ZoneToNameResponseMessage *ztnr_msg; 1596 struct ZoneToNameResponseMessage *ztnr_msg;
1312 1597
1313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1314 "Received `%s' message\n", 1599 "Received ZONE_TO_NAME message\n");
1315 "ZONE_TO_NAME");
1316 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); 1600 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
1317 ztn_ctx.nc = nc; 1601 ztn_ctx.nc = nc;
1318 ztn_ctx.success = GNUNET_NO; 1602 ztn_ctx.success = GNUNET_NO;
@@ -1601,6 +1885,46 @@ handle_iteration_next (void *cls,
1601 1885
1602 1886
1603/** 1887/**
1888 * Function called when the monitor is ready for more data, and we
1889 * should thus unblock PUT operations that were blocked on the
1890 * monitor not being ready.
1891 */
1892static void
1893monitor_unblock (struct ZoneMonitor *zm)
1894{
1895 struct StoreActivity *sa = sa_head;
1896
1897 while ( (NULL != sa) &&
1898 (zm->limit > zm->iteration_cnt) )
1899 {
1900 struct StoreActivity *sn = sa->next;
1901
1902 if (sa->zm_pos == zm)
1903 continue_store_activity (sa);
1904 sa = sn;
1905 }
1906 if (zm->limit > zm->iteration_cnt)
1907 {
1908 zm->sa_waiting = GNUNET_NO;
1909 if (NULL != zm->sa_wait_warning)
1910 {
1911 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
1912 zm->sa_wait_warning = NULL;
1913 }
1914 }
1915 else if (GNUNET_YES == zm->sa_waiting)
1916 {
1917 zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
1918 if (NULL != zm->sa_wait_warning)
1919 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
1920 zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
1921 &warn_monitor_slow,
1922 zm);
1923 }
1924}
1925
1926
1927/**
1604 * Send 'sync' message to zone monitor, we're now in sync. 1928 * Send 'sync' message to zone monitor, we're now in sync.
1605 * 1929 *
1606 * @param zm monitor that is now in sync 1930 * @param zm monitor that is now in sync
@@ -1615,16 +1939,22 @@ monitor_sync (struct ZoneMonitor *zm)
1615 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC); 1939 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC);
1616 GNUNET_MQ_send (zm->nc->mq, 1940 GNUNET_MQ_send (zm->nc->mq,
1617 env); 1941 env);
1942 /* mark iteration done */
1943 zm->in_first_iteration = GNUNET_NO;
1944 zm->iteration_cnt = 0;
1945 if ( (zm->limit > 0) &&
1946 (zm->sa_waiting) )
1947 monitor_unblock (zm);
1618} 1948}
1619 1949
1620 1950
1621/** 1951/**
1622 * Obtain the next datum during the zone monitor's zone intiial iteration. 1952 * Obtain the next datum during the zone monitor's zone initial iteration.
1623 * 1953 *
1624 * @param cls zone monitor that does its initial iteration 1954 * @param cls zone monitor that does its initial iteration
1625 */ 1955 */
1626static void 1956static void
1627monitor_next (void *cls); 1957monitor_iteration_next (void *cls);
1628 1958
1629 1959
1630/** 1960/**
@@ -1658,14 +1988,23 @@ monitor_iterate_cb (void *cls,
1658 "Monitor notifications sent", 1988 "Monitor notifications sent",
1659 1, 1989 1,
1660 GNUNET_NO); 1990 GNUNET_NO);
1991 zm->limit--;
1992 zm->iteration_cnt--;
1661 send_lookup_response (zm->nc, 1993 send_lookup_response (zm->nc,
1662 0, 1994 0,
1663 zone_key, 1995 zone_key,
1664 name, 1996 name,
1665 rd_count, 1997 rd_count,
1666 rd); 1998 rd);
1667 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, 1999 if ( (0 == zm->iteration_cnt) &&
1668 zm); 2000 (0 != zm->limit) )
2001 {
2002 /* We are done with the current iteration batch, AND the
2003 client would right now accept more, so go again! */
2004 GNUNET_assert (NULL == zm->task);
2005 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
2006 zm);
2007 }
1669} 2008}
1670 2009
1671 2010
@@ -1687,6 +2026,8 @@ handle_monitor_start (void *cls,
1687 zm = GNUNET_new (struct ZoneMonitor); 2026 zm = GNUNET_new (struct ZoneMonitor);
1688 zm->nc = nc; 2027 zm->nc = nc;
1689 zm->zone = zis_msg->zone; 2028 zm->zone = zis_msg->zone;
2029 zm->limit = 1;
2030 zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first));
1690 GNUNET_CONTAINER_DLL_insert (monitor_head, 2031 GNUNET_CONTAINER_DLL_insert (monitor_head,
1691 monitor_tail, 2032 monitor_tail,
1692 zm); 2033 zm);
@@ -1694,8 +2035,8 @@ handle_monitor_start (void *cls,
1694 GNUNET_SERVICE_client_continue (nc->client); 2035 GNUNET_SERVICE_client_continue (nc->client);
1695 GNUNET_notification_context_add (monitor_nc, 2036 GNUNET_notification_context_add (monitor_nc,
1696 nc->mq); 2037 nc->mq);
1697 if (GNUNET_YES == ntohl (zis_msg->iterate_first)) 2038 if (zm->in_first_iteration)
1698 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, 2039 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
1699 zm); 2040 zm);
1700 else 2041 else
1701 monitor_sync (zm); 2042 monitor_sync (zm);
@@ -1708,12 +2049,17 @@ handle_monitor_start (void *cls,
1708 * @param cls zone monitor that does its initial iteration 2049 * @param cls zone monitor that does its initial iteration
1709 */ 2050 */
1710static void 2051static void
1711monitor_next (void *cls) 2052monitor_iteration_next (void *cls)
1712{ 2053{
1713 struct ZoneMonitor *zm = cls; 2054 struct ZoneMonitor *zm = cls;
1714 int ret; 2055 int ret;
1715 2056
1716 zm->task = NULL; 2057 zm->task = NULL;
2058 GNUNET_assert (0 == zm->iteration_cnt);
2059 if (zm->limit > 16)
2060 zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */
2061 else
2062 zm->iteration_cnt = zm->limit; /* use it all */
1717 ret = GSN_database->iterate_records (GSN_database->cls, 2063 ret = GSN_database->iterate_records (GSN_database->cls,
1718 (0 == memcmp (&zm->zone, 2064 (0 == memcmp (&zm->zone,
1719 &zero, 2065 &zero,
@@ -1721,7 +2067,7 @@ monitor_next (void *cls)
1721 ? NULL 2067 ? NULL
1722 : &zm->zone, 2068 : &zm->zone,
1723 zm->seq, 2069 zm->seq,
1724 1, 2070 zm->iteration_cnt,
1725 &monitor_iterate_cb, 2071 &monitor_iterate_cb,
1726 zm); 2072 zm);
1727 if (GNUNET_SYSERR == ret) 2073 if (GNUNET_SYSERR == ret)
@@ -1773,13 +2119,30 @@ handle_monitor_next (void *cls,
1773 return; 2119 return;
1774 } 2120 }
1775 zm->limit += inc; 2121 zm->limit += inc;
1776#if 0 2122 if ( (zm->in_first_iteration) &&
1777 if (GNUNET_YES == ntohl (zis_msg->iterate_first)) 2123 (zm->limit == inc) )
1778 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, 2124 {
1779 zm); 2125 /* We are still iterating, and the previous iteration must
1780 else 2126 have stopped due to the client's limit, so continue it! */
1781 monitor_sync (zm); 2127 GNUNET_assert (NULL == zm->task);
1782#endif 2128 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
2129 zm);
2130 }
2131 GNUNET_assert (zm->iteration_cnt <= zm->limit);
2132 if ( (zm->limit > zm->iteration_cnt) &&
2133 (zm->sa_waiting) )
2134 {
2135 monitor_unblock (zm);
2136 }
2137 else if (GNUNET_YES == zm->sa_waiting)
2138 {
2139 if (NULL != zm->sa_wait_warning)
2140 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
2141 zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
2142 zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
2143 &warn_monitor_slow,
2144 zm);
2145 }
1783} 2146}
1784 2147
1785 2148
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c
index 0fd0a4ab8..ddc8b483a 100644
--- a/src/namestore/gnunet-zoneimport.c
+++ b/src/namestore/gnunet-zoneimport.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2018 GNUnet e.V. 3 Copyright (C) 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file src/namestore/gnunet-zoneimport.c 19 * @file src/namestore/gnunet-zoneimport.c
@@ -59,6 +57,11 @@
59#define SERIES_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10) 57#define SERIES_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10)
60 58
61/** 59/**
60 * How long do DNS records have to last at least after being imported?
61 */
62static struct GNUNET_TIME_Relative minimum_expiration_time;
63
64/**
62 * How many requests do we request from NAMESTORE in one batch 65 * How many requests do we request from NAMESTORE in one batch
63 * during our initial iteration? 66 * during our initial iteration?
64 */ 67 */
@@ -429,9 +432,9 @@ get_label (struct Request *req)
429 GNUNET_break (0); 432 GNUNET_break (0);
430 return NULL; 433 return NULL;
431 } 434 }
432 memcpy (label, 435 GNUNET_memcpy (label,
433 req->hostname, 436 req->hostname,
434 dot - req->hostname); 437 dot - req->hostname);
435 label[dot - req->hostname] = '\0'; 438 label[dot - req->hostname] = '\0';
436 return label; 439 return label;
437} 440}
@@ -453,6 +456,7 @@ build_dns_query (struct Request *req,
453 char *rawp; 456 char *rawp;
454 struct GNUNET_DNSPARSER_Packet p; 457 struct GNUNET_DNSPARSER_Packet p;
455 struct GNUNET_DNSPARSER_Query q; 458 struct GNUNET_DNSPARSER_Query q;
459 int ret;
456 460
457 q.name = (char *) req->hostname; 461 q.name = (char *) req->hostname;
458 q.type = GNUNET_DNSPARSER_TYPE_NS; 462 q.type = GNUNET_DNSPARSER_TYPE_NS;
@@ -464,12 +468,14 @@ build_dns_query (struct Request *req,
464 p.num_queries = 1; 468 p.num_queries = 1;
465 p.queries = &q; 469 p.queries = &q;
466 p.id = req->id; 470 p.id = req->id;
467 if (GNUNET_OK != 471 ret = GNUNET_DNSPARSER_pack (&p,
468 GNUNET_DNSPARSER_pack (&p, 472 UINT16_MAX,
469 UINT16_MAX, 473 &rawp,
470 &rawp, 474 raw_size);
471 raw_size)) 475 if (GNUNET_OK != ret)
472 { 476 {
477 if (GNUNET_NO == ret)
478 GNUNET_free (rawp);
473 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 479 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
474 "Failed to pack query for hostname `%s'\n", 480 "Failed to pack query for hostname `%s'\n",
475 req->hostname); 481 req->hostname);
@@ -486,9 +492,9 @@ build_dns_query (struct Request *req,
486 GNUNET_free (rawp); 492 GNUNET_free (rawp);
487 return NULL; 493 return NULL;
488 } 494 }
489 memcpy (raw, 495 GNUNET_memcpy (raw,
490 rawp, 496 rawp,
491 *raw_size); 497 *raw_size);
492 GNUNET_free (rawp); 498 GNUNET_free (rawp);
493 return raw; 499 return raw;
494} 500}
@@ -632,10 +638,19 @@ check_for_glue (void *cls,
632 size_t off; 638 size_t off;
633 char ip[INET6_ADDRSTRLEN+1]; 639 char ip[INET6_ADDRSTRLEN+1];
634 socklen_t ip_size = (socklen_t) sizeof (ip); 640 socklen_t ip_size = (socklen_t) sizeof (ip);
641 struct GNUNET_TIME_Absolute expiration_time;
642 struct GNUNET_TIME_Relative left;
635 643
636 if (0 != strcasecmp (rec->name, 644 if (0 != strcasecmp (rec->name,
637 gc->ns)) 645 gc->ns))
638 return; 646 return;
647 expiration_time = rec->expiration_time;
648 left = GNUNET_TIME_absolute_get_remaining (expiration_time);
649 if (0 == left.rel_value_us)
650 return; /* ignore expired glue records */
651 /* if expiration window is too short, bump it to configured minimum */
652 if (left.rel_value_us < minimum_expiration_time.rel_value_us)
653 expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
639 dst_len = sizeof (dst); 654 dst_len = sizeof (dst);
640 off = 0; 655 off = 0;
641 switch (rec->type) 656 switch (rec->type)
@@ -668,7 +683,7 @@ check_for_glue (void *cls,
668 { 683 {
669 add_record (gc->req, 684 add_record (gc->req,
670 GNUNET_GNSRECORD_TYPE_GNS2DNS, 685 GNUNET_GNSRECORD_TYPE_GNS2DNS,
671 rec->expiration_time, 686 expiration_time,
672 dst, 687 dst,
673 off); 688 off);
674 gc->found = GNUNET_YES; 689 gc->found = GNUNET_YES;
@@ -702,7 +717,7 @@ check_for_glue (void *cls,
702 { 717 {
703 add_record (gc->req, 718 add_record (gc->req,
704 GNUNET_GNSRECORD_TYPE_GNS2DNS, 719 GNUNET_GNSRECORD_TYPE_GNS2DNS,
705 rec->expiration_time, 720 expiration_time,
706 dst, 721 dst,
707 off); 722 off);
708 gc->found = GNUNET_YES; 723 gc->found = GNUNET_YES;
@@ -722,7 +737,7 @@ check_for_glue (void *cls,
722 { 737 {
723 add_record (gc->req, 738 add_record (gc->req,
724 GNUNET_GNSRECORD_TYPE_GNS2DNS, 739 GNUNET_GNSRECORD_TYPE_GNS2DNS,
725 rec->expiration_time, 740 expiration_time,
726 dst, 741 dst,
727 off); 742 off);
728 gc->found = GNUNET_YES; 743 gc->found = GNUNET_YES;
@@ -768,6 +783,8 @@ process_record (void *cls,
768 char dst[65536]; 783 char dst[65536];
769 size_t dst_len; 784 size_t dst_len;
770 size_t off; 785 size_t off;
786 struct GNUNET_TIME_Absolute expiration_time;
787 struct GNUNET_TIME_Relative left;
771 788
772 dst_len = sizeof (dst); 789 dst_len = sizeof (dst);
773 off = 0; 790 off = 0;
@@ -783,18 +800,27 @@ process_record (void *cls,
783 return; /* does not match hostname, might be glue, but 800 return; /* does not match hostname, might be glue, but
784 not useful for this pass! */ 801 not useful for this pass! */
785 } 802 }
786 if (0 == 803 expiration_time = rec->expiration_time;
787 GNUNET_TIME_absolute_get_remaining (rec->expiration_time).rel_value_us) 804 left = GNUNET_TIME_absolute_get_remaining (expiration_time);
805 if (0 == left.rel_value_us)
788 { 806 {
789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
790 "DNS returned expired record for `%s'\n", 808 "DNS returned expired record for `%s'\n",
791 req->hostname); 809 req->hostname);
810 GNUNET_STATISTICS_update (stats,
811 "# expired records obtained from DNS",
812 1,
813 GNUNET_NO);
792 return; /* record expired */ 814 return; /* record expired */
793 } 815 }
816
794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
795 "DNS returned record that expires at %s for `%s'\n", 818 "DNS returned record that expires at %s for `%s'\n",
796 GNUNET_STRINGS_absolute_time_to_string (rec->expiration_time), 819 GNUNET_STRINGS_absolute_time_to_string (expiration_time),
797 req->hostname); 820 req->hostname);
821 /* if expiration window is too short, bump it to configured minimum */
822 if (left.rel_value_us < minimum_expiration_time.rel_value_us)
823 expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
798 switch (rec->type) 824 switch (rec->type)
799 { 825 {
800 case GNUNET_DNSPARSER_TYPE_NS: 826 case GNUNET_DNSPARSER_TYPE_NS:
@@ -828,7 +854,7 @@ process_record (void *cls,
828 rec->name); 854 rec->name);
829 add_record (req, 855 add_record (req,
830 GNUNET_GNSRECORD_TYPE_GNS2DNS, 856 GNUNET_GNSRECORD_TYPE_GNS2DNS,
831 rec->expiration_time, 857 expiration_time,
832 dst, 858 dst,
833 off); 859 off);
834 } 860 }
@@ -853,7 +879,7 @@ process_record (void *cls,
853 rec->name); 879 rec->name);
854 add_record (req, 880 add_record (req,
855 rec->type, 881 rec->type,
856 rec->expiration_time, 882 expiration_time,
857 dst, 883 dst,
858 off); 884 off);
859 } 885 }
@@ -878,7 +904,7 @@ process_record (void *cls,
878 rec->name); 904 rec->name);
879 add_record (req, 905 add_record (req,
880 rec->type, 906 rec->type,
881 rec->expiration_time, 907 expiration_time,
882 dst, 908 dst,
883 off); 909 off);
884 } 910 }
@@ -896,7 +922,7 @@ process_record (void *cls,
896 rec->name); 922 rec->name);
897 add_record (req, 923 add_record (req,
898 rec->type, 924 rec->type,
899 rec->expiration_time, 925 expiration_time,
900 dst, 926 dst,
901 off); 927 off);
902 } 928 }
@@ -913,7 +939,7 @@ process_record (void *cls,
913 rec->name); 939 rec->name);
914 add_record (req, 940 add_record (req,
915 rec->type, 941 rec->type,
916 rec->expiration_time, 942 expiration_time,
917 dst, 943 dst,
918 off); 944 off);
919 } 945 }
@@ -931,7 +957,7 @@ process_record (void *cls,
931 rec->name); 957 rec->name);
932 add_record (req, 958 add_record (req,
933 rec->type, 959 rec->type,
934 rec->expiration_time, 960 expiration_time,
935 dst, 961 dst,
936 off); 962 off);
937 } 963 }
@@ -948,7 +974,7 @@ process_record (void *cls,
948 rec->name); 974 rec->name);
949 add_record (req, 975 add_record (req,
950 rec->type, 976 rec->type,
951 rec->expiration_time, 977 expiration_time,
952 dst, 978 dst,
953 off); 979 off);
954 } 980 }
@@ -966,7 +992,7 @@ process_record (void *cls,
966 rec->name); 992 rec->name);
967 add_record (req, 993 add_record (req,
968 rec->type, 994 rec->type,
969 rec->expiration_time, 995 expiration_time,
970 rec->data.raw.data, 996 rec->data.raw.data,
971 rec->data.raw.data_len); 997 rec->data.raw.data_len);
972 break; 998 break;
@@ -1469,6 +1495,16 @@ do_shutdown (void *cls)
1469 1495
1470 1496
1471/** 1497/**
1498 * Iterate over all of the zones we care about and see which records
1499 * we may need to re-fetch when.
1500 *
1501 * @param cls NULL
1502 */
1503static void
1504iterate_zones (void *cls);
1505
1506
1507/**
1472 * Function called if #GNUNET_NAMESTORE_records_lookup() failed. 1508 * Function called if #GNUNET_NAMESTORE_records_lookup() failed.
1473 * Just logs an error. 1509 * Just logs an error.
1474 * 1510 *
@@ -1482,6 +1518,9 @@ ns_lookup_error_cb (void *cls)
1482 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1518 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1483 "Failed to load data from namestore for zone `%s'\n", 1519 "Failed to load data from namestore for zone `%s'\n",
1484 zone->domain); 1520 zone->domain);
1521 zone_it = NULL;
1522 ns_iterator_trigger_next = 0;
1523 iterate_zones (NULL);
1485} 1524}
1486 1525
1487 1526
@@ -1551,7 +1590,17 @@ ns_lookup_result_cb (void *cls,
1551 { 1590 {
1552 struct GNUNET_TIME_Absolute at; 1591 struct GNUNET_TIME_Absolute at;
1553 1592
1554 at.abs_value_us = rd->expiration_time; 1593 if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
1594 {
1595 struct GNUNET_TIME_Relative rel;
1596
1597 rel.rel_value_us = rd->expiration_time;
1598 at = GNUNET_TIME_relative_to_absolute (rel);
1599 }
1600 else
1601 {
1602 at.abs_value_us = rd->expiration_time;
1603 }
1555 add_record (req, 1604 add_record (req,
1556 rd->record_type, 1605 rd->record_type,
1557 at, 1606 at,
@@ -1648,9 +1697,9 @@ queue (const char *hostname)
1648 req = GNUNET_malloc (sizeof (struct Request) + hlen); 1697 req = GNUNET_malloc (sizeof (struct Request) + hlen);
1649 req->zone = zone; 1698 req->zone = zone;
1650 req->hostname = (char *) &req[1]; 1699 req->hostname = (char *) &req[1];
1651 memcpy (req->hostname, 1700 GNUNET_memcpy (req->hostname,
1652 hostname, 1701 hostname,
1653 hlen); 1702 hlen);
1654 req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1703 req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
1655 UINT16_MAX); 1704 UINT16_MAX);
1656 GNUNET_CRYPTO_hash (req->hostname, 1705 GNUNET_CRYPTO_hash (req->hostname,
@@ -1800,14 +1849,14 @@ process_stdin (void *cls)
1800 if (0 == idot) 1849 if (0 == idot)
1801 last = GNUNET_TIME_absolute_get (); 1850 last = GNUNET_TIME_absolute_get ();
1802 idot++; 1851 idot++;
1803 if (0 == idot % 10000) 1852 if (0 == idot % 100000)
1804 { 1853 {
1805 struct GNUNET_TIME_Relative delta; 1854 struct GNUNET_TIME_Relative delta;
1806 1855
1807 delta = GNUNET_TIME_absolute_get_duration (last); 1856 delta = GNUNET_TIME_absolute_get_duration (last);
1808 last = GNUNET_TIME_absolute_get (); 1857 last = GNUNET_TIME_absolute_get ();
1809 fprintf (stderr, 1858 fprintf (stderr,
1810 "Imported 10000 records in %s\n", 1859 "Read 100000 domain names in %s\n",
1811 GNUNET_STRINGS_relative_time_to_string (delta, 1860 GNUNET_STRINGS_relative_time_to_string (delta,
1812 GNUNET_YES)); 1861 GNUNET_YES));
1813 GNUNET_STATISTICS_set (stats, 1862 GNUNET_STATISTICS_set (stats,
@@ -1986,6 +2035,11 @@ main (int argc,
1986 "MAPSIZE", 2035 "MAPSIZE",
1987 gettext_noop ("size to use for the main hash map"), 2036 gettext_noop ("size to use for the main hash map"),
1988 &map_size), 2037 &map_size),
2038 GNUNET_GETOPT_option_relative_time ('m',
2039 "minimum-expiration",
2040 "RELATIVETIME",
2041 gettext_noop ("minimum expiration time we assume for imported records"),
2042 &minimum_expiration_time),
1989 GNUNET_GETOPT_OPTION_END 2043 GNUNET_GETOPT_OPTION_END
1990 }; 2044 };
1991 2045
diff --git a/src/namestore/namestore.conf.in b/src/namestore/namestore.conf.in
index 8b5e440b8..eb95f95be 100644
--- a/src/namestore/namestore.conf.in
+++ b/src/namestore/namestore.conf.in
@@ -1,6 +1,6 @@
1[namestore] 1[namestore]
2AUTOSTART = @AUTOSTART@ 2START_ON_DEMAND = @START_ON_DEMAND@
3USER_SERVICE = YES 3RUN_PER_USER = YES
4UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-namestore.sock 4UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-namestore.sock
5UNIX_MATCH_UID = NO 5UNIX_MATCH_UID = NO
6UNIX_MATCH_GID = YES 6UNIX_MATCH_GID = YES
@@ -42,7 +42,7 @@ gns = gnunet-namestore
42[fcfsd] 42[fcfsd]
43# Name of the fcfs registration service binary (for ARM) 43# Name of the fcfs registration service binary (for ARM)
44BINARY = gnunet-namestore-fcfsd 44BINARY = gnunet-namestore-fcfsd
45AUTOSTART = NO 45START_ON_DEMAND = NO
46UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-fcfsd.sock 46UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-fcfsd.sock
47 47
48# On what port does the FCFS daemon listen for HTTP clients? 48# On what port does the FCFS daemon listen for HTTP clients?
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index 679ca3d3d..e6f5ae848 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011-2013 GNUnet e.V. 3 Copyright (C) 2011-2013 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index ab356838b..55745d83d 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010-2013, 2016 GNUnet e.V. 3 Copyright (C) 2010-2013, 2016 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
@@ -40,6 +38,11 @@
40 38
41#define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__) 39#define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__)
42 40
41/**
42 * We grant the namestore up to 1 minute of latency, if it is slower than
43 * that, store queries will fail.
44 */
45#define NAMESTORE_DELAY_TOLERANCE GNUNET_TIME_UNIT_MINUTES
43 46
44/** 47/**
45 * An QueueEntry used to store information for a pending 48 * An QueueEntry used to store information for a pending
@@ -100,6 +103,11 @@ struct GNUNET_NAMESTORE_QueueEntry
100 struct GNUNET_MQ_Envelope *env; 103 struct GNUNET_MQ_Envelope *env;
101 104
102 /** 105 /**
106 * Task scheduled to warn us if the namestore is way too slow.
107 */
108 struct GNUNET_SCHEDULER_Task *timeout_task;
109
110 /**
103 * The operation id this zone iteration operation has 111 * The operation id this zone iteration operation has
104 */ 112 */
105 uint32_t op_id; 113 uint32_t op_id;
@@ -300,6 +308,8 @@ free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe)
300 qe); 308 qe);
301 if (NULL != qe->env) 309 if (NULL != qe->env)
302 GNUNET_MQ_discard (qe->env); 310 GNUNET_MQ_discard (qe->env);
311 if (NULL != qe->timeout_task)
312 GNUNET_SCHEDULER_cancel (qe->timeout_task);
303 GNUNET_free (qe); 313 GNUNET_free (qe);
304} 314}
305 315
@@ -968,6 +978,33 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h)
968 978
969 979
970/** 980/**
981 * Task launched to warn the user that the namestore is
982 * excessively slow and that a query was thus dropped.
983 *
984 * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *`
985 */
986static void
987warn_delay (void *cls)
988{
989 struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
990
991 qe->timeout_task = NULL;
992 LOG (GNUNET_ERROR_TYPE_WARNING,
993 "Did not receive response from namestore after %s!\n",
994 GNUNET_STRINGS_relative_time_to_string (NAMESTORE_DELAY_TOLERANCE,
995 GNUNET_YES));
996 if (NULL != qe->cont)
997 {
998 qe->cont (qe->cont_cls,
999 GNUNET_SYSERR,
1000 "timeout");
1001 qe->cont = NULL;
1002 }
1003 GNUNET_NAMESTORE_cancel (qe);
1004}
1005
1006
1007/**
971 * Store an item in the namestore. If the item is already present, 1008 * 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 1009 * it is replaced with the new record. Use an empty array to
973 * remove all records under the given name. 1010 * remove all records under the given name.
@@ -994,7 +1031,7 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
994 struct GNUNET_MQ_Envelope *env; 1031 struct GNUNET_MQ_Envelope *env;
995 char *name_tmp; 1032 char *name_tmp;
996 char *rd_ser; 1033 char *rd_ser;
997 size_t rd_ser_len; 1034 ssize_t rd_ser_len;
998 size_t name_len; 1035 size_t name_len;
999 uint32_t rid; 1036 uint32_t rid;
1000 struct RecordStoreMessage *msg; 1037 struct RecordStoreMessage *msg;
@@ -1006,6 +1043,18 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
1006 GNUNET_break (0); 1043 GNUNET_break (0);
1007 return NULL; 1044 return NULL;
1008 } 1045 }
1046 rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count,
1047 rd);
1048 if (rd_ser_len < 0)
1049 {
1050 GNUNET_break (0);
1051 return NULL;
1052 }
1053 if (rd_ser_len > UINT16_MAX)
1054 {
1055 GNUNET_break (0);
1056 return NULL;
1057 }
1009 rid = get_op_id (h); 1058 rid = get_op_id (h);
1010 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1059 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
1011 qe->h = h; 1060 qe->h = h;
@@ -1017,8 +1066,6 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
1017 qe); 1066 qe);
1018 1067
1019 /* setup msg */ 1068 /* setup msg */
1020 rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count,
1021 rd);
1022 env = GNUNET_MQ_msg_extra (msg, 1069 env = GNUNET_MQ_msg_extra (msg,
1023 name_len + rd_ser_len, 1070 name_len + rd_ser_len,
1024 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); 1071 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE);
@@ -1038,8 +1085,10 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
1038 rd, 1085 rd,
1039 rd_ser_len, 1086 rd_ser_len,
1040 rd_ser); 1087 rd_ser);
1041 if (0 > sret) 1088 if ( (0 > sret) ||
1089 (sret != rd_ser_len) )
1042 { 1090 {
1091 GNUNET_break (0);
1043 GNUNET_free (env); 1092 GNUNET_free (env);
1044 return NULL; 1093 return NULL;
1045 } 1094 }
@@ -1048,12 +1097,20 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
1048 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", 1097 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n",
1049 label, 1098 label,
1050 rd_count); 1099 rd_count);
1051 1100 qe->timeout_task = GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE,
1101 &warn_delay,
1102 qe);
1052 if (NULL == h->mq) 1103 if (NULL == h->mq)
1104 {
1053 qe->env = env; 1105 qe->env = env;
1106 LOG (GNUNET_ERROR_TYPE_WARNING,
1107 "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n");
1108 }
1054 else 1109 else
1110 {
1055 GNUNET_MQ_send (h->mq, 1111 GNUNET_MQ_send (h->mq,
1056 env); 1112 env);
1113 }
1057 return qe; 1114 return qe;
1058} 1115}
1059 1116
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c
index 9ba90833b..6c441d786 100644
--- a/src/namestore/namestore_api_monitor.c
+++ b/src/namestore/namestore_api_monitor.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013, 2016, 2018 GNUnet e.V. 3 Copyright (C) 2013, 2016, 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/namestore_api_monitor.c 19 * @file namestore/namestore_api_monitor.c
@@ -144,6 +142,11 @@ check_result (void *cls,
144 rd_len = ntohs (lrm->rd_len); 142 rd_len = ntohs (lrm->rd_len);
145 rd_count = ntohs (lrm->rd_count); 143 rd_count = ntohs (lrm->rd_count);
146 name_len = ntohs (lrm->name_len); 144 name_len = ntohs (lrm->name_len);
145 if (name_len > MAX_NAME_LEN)
146 {
147 GNUNET_break (0);
148 return GNUNET_SYSERR;
149 }
147 exp_lrm_len = sizeof (struct RecordResultMessage) + name_len + rd_len; 150 exp_lrm_len = sizeof (struct RecordResultMessage) + name_len + rd_len;
148 if (lrm_len != exp_lrm_len) 151 if (lrm_len != exp_lrm_len)
149 { 152 {
@@ -156,7 +159,7 @@ check_result (void *cls,
156 return GNUNET_SYSERR; 159 return GNUNET_SYSERR;
157 } 160 }
158 name_tmp = (const char *) &lrm[1]; 161 name_tmp = (const char *) &lrm[1];
159 if ((name_tmp[name_len -1] != '\0') || (name_len > MAX_NAME_LEN)) 162 if (name_tmp[name_len -1] != '\0')
160 { 163 {
161 GNUNET_break (0); 164 GNUNET_break (0);
162 return GNUNET_SYSERR; 165 return GNUNET_SYSERR;
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]
7DISABLE = YES 7DISABLE = YES
8
9[namestore-flat]
10FILENAME = $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]
7DISABLE = YES 7DISABLE = YES
8
9[namestore-postgres]
10CONFIG = connect_timeout=10; dbname=gnunetcheck
11TEMPORARY_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]
4DISABLE = YES 4DISABLE = YES
5
6[namestore-sqlite]
7FILENAME = $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..03f53e63b 100644
--- a/src/namestore/perf_namestore_api_zone_iteration.c
+++ b/src/namestore/perf_namestore_api_zone_iteration.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013, 2018 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/perf_namestore_api_zone_iteration.c 19 * @file namestore/perf_namestore_api_zone_iteration.c
@@ -26,6 +24,9 @@
26#include "gnunet_namestore_service.h" 24#include "gnunet_namestore_service.h"
27#include "gnunet_testing_lib.h" 25#include "gnunet_testing_lib.h"
28#include "namestore.h" 26#include "namestore.h"
27#include "gnunet_dnsparser_lib.h"
28
29#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
29 30
30/** 31/**
31 * A #BENCHMARK_SIZE of 1000 takes less than a minute on a reasonably 32 * A #BENCHMARK_SIZE of 1000 takes less than a minute on a reasonably
@@ -69,8 +70,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *qe;
69 70
70static int res; 71static int res;
71 72
72static char *directory;
73
74static unsigned int off; 73static unsigned int off;
75 74
76static unsigned int left_until_next; 75static unsigned int left_until_next;
@@ -143,7 +142,7 @@ create_record (unsigned int count)
143 142
144 rd = GNUNET_malloc (count + sizeof (struct GNUNET_GNSRECORD_Data)); 143 rd = GNUNET_malloc (count + sizeof (struct GNUNET_GNSRECORD_Data));
145 rd->expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 144 rd->expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
146 rd->record_type = count; 145 rd->record_type = TEST_RECORD_TYPE;
147 rd->data_size = count; 146 rd->data_size = count;
148 rd->data = (void *) &rd[1]; 147 rd->data = (void *) &rd[1];
149 rd->flags = 0; 148 rd->flags = 0;
@@ -333,13 +332,6 @@ run (void *cls,
333 const struct GNUNET_CONFIGURATION_Handle *cfg, 332 const struct GNUNET_CONFIGURATION_Handle *cfg,
334 struct GNUNET_TESTING_Peer *peer) 333 struct GNUNET_TESTING_Peer *peer)
335{ 334{
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, 335 GNUNET_SCHEDULER_add_shutdown (&end,
344 NULL); 336 NULL);
345 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 337 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
@@ -367,6 +359,8 @@ main (int argc,
367 "perf_namestore_api_%s.conf", 359 "perf_namestore_api_%s.conf",
368 plugin_name); 360 plugin_name);
369 res = 1; 361 res = 1;
362 GNUNET_DISK_purge_cfg_dir (cfg_name,
363 "GNUNET_TEST_HOME");
370 if (0 != 364 if (0 !=
371 GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration", 365 GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration",
372 cfg_name, 366 cfg_name,
@@ -375,12 +369,9 @@ main (int argc,
375 { 369 {
376 res = 1; 370 res = 1;
377 } 371 }
372 GNUNET_DISK_purge_cfg_dir (cfg_name,
373 "GNUNET_TEST_HOME");
378 GNUNET_free (cfg_name); 374 GNUNET_free (cfg_name);
379 if (NULL != directory)
380 {
381 GNUNET_DISK_directory_remove (directory);
382 GNUNET_free (directory);
383 }
384 return res; 375 return res;
385} 376}
386 377
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c
index bbb9e3c62..e16fe91b7 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -2,20 +2,18 @@
2 * This file is part of GNUnet 2 * This file is part of GNUnet
3 * Copyright (C) 2009-2015, 2018 GNUnet e.V. 3 * Copyright (C) 2009-2015, 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 it
6 * it under the terms of the GNU General Public License as published 6 * under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your 7 * by the Free Software Foundation, either version 3 of the License,
8 * option) any later version. 8 * or (at your option) any later version.
9 * 9 *
10 * GNUnet is distributed in the hope that it will be useful, but 10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details. 13 * Affero General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU Affero General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */ 17 */
20 18
21/** 19/**
@@ -49,41 +47,6 @@ struct Plugin
49 */ 47 */
50 struct GNUNET_CONTAINER_MultiHashMap *hm; 48 struct GNUNET_CONTAINER_MultiHashMap *hm;
51 49
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}; 50};
88 51
89 52
@@ -92,7 +55,7 @@ struct FlatFileEntry
92 /** 55 /**
93 * Entry zone 56 * Entry zone
94 */ 57 */
95 struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key; 58 struct GNUNET_CRYPTO_EcdsaPrivateKey private_key;
96 59
97 /** 60 /**
98 * Record cound 61 * Record cound
@@ -130,7 +93,6 @@ static int
130database_setup (struct Plugin *plugin) 93database_setup (struct Plugin *plugin)
131{ 94{
132 char *afsdir; 95 char *afsdir;
133 char *key;
134 char *record_data; 96 char *record_data;
135 char *zone_private_key; 97 char *zone_private_key;
136 char *record_data_b64; 98 char *record_data_b64;
@@ -141,7 +103,6 @@ database_setup (struct Plugin *plugin)
141 char *record_count; 103 char *record_count;
142 size_t record_data_size; 104 size_t record_data_size;
143 uint64_t size; 105 uint64_t size;
144 size_t key_len;
145 struct GNUNET_HashCode hkey; 106 struct GNUNET_HashCode hkey;
146 struct GNUNET_DISK_FileHandle *fh; 107 struct GNUNET_DISK_FileHandle *fh;
147 struct FlatFileEntry *entry; 108 struct FlatFileEntry *entry;
@@ -269,7 +230,7 @@ database_setup (struct Plugin *plugin)
269 record_data_size 230 record_data_size
270 = GNUNET_STRINGS_base64_decode (record_data_b64, 231 = GNUNET_STRINGS_base64_decode (record_data_b64,
271 strlen (record_data_b64), 232 strlen (record_data_b64),
272 &record_data); 233 (void **) &record_data);
273 entry->record_data = 234 entry->record_data =
274 GNUNET_new_array (entry->record_count, 235 GNUNET_new_array (entry->record_count,
275 struct GNUNET_GNSRECORD_Data); 236 struct GNUNET_GNSRECORD_Data);
@@ -288,21 +249,34 @@ database_setup (struct Plugin *plugin)
288 break; 249 break;
289 } 250 }
290 GNUNET_free (record_data); 251 GNUNET_free (record_data);
291 GNUNET_STRINGS_base64_decode (zone_private_key, 252
292 strlen (zone_private_key), 253 {
293 (char**)&entry->private_key); 254 struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key;
294 key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); 255
295 key = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 256 GNUNET_STRINGS_base64_decode (zone_private_key,
296 GNUNET_memcpy (key, 257 strlen (zone_private_key),
297 label, 258 (void**)&private_key);
298 strlen (label)); 259 entry->private_key = *private_key;
299 GNUNET_memcpy (key+strlen(label), 260 GNUNET_free (private_key);
300 entry->private_key, 261 }
301 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 262
302 GNUNET_CRYPTO_hash (key, 263 {
303 key_len, 264 char *key;
304 &hkey); 265 size_t key_len;
305 GNUNET_free (key); 266
267 key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
268 key = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
269 GNUNET_memcpy (key,
270 label,
271 strlen (label));
272 GNUNET_memcpy (key+strlen(label),
273 &entry->private_key,
274 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
275 GNUNET_CRYPTO_hash (key,
276 key_len,
277 &hkey);
278 GNUNET_free (key);
279 }
306 if (GNUNET_OK != 280 if (GNUNET_OK !=
307 GNUNET_CONTAINER_multihashmap_put (plugin->hm, 281 GNUNET_CONTAINER_multihashmap_put (plugin->hm,
308 &hkey, 282 &hkey,
@@ -336,14 +310,26 @@ store_and_free_entries (void *cls,
336 char *line; 310 char *line;
337 char *zone_private_key; 311 char *zone_private_key;
338 char *record_data_b64; 312 char *record_data_b64;
339 size_t data_size; 313 ssize_t data_size;
340 314
341 (void) key; 315 (void) key;
342 GNUNET_STRINGS_base64_encode ((char*)entry->private_key, 316 GNUNET_STRINGS_base64_encode (&entry->private_key,
343 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 317 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
344 &zone_private_key); 318 &zone_private_key);
345 data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count, 319 data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count,
346 entry->record_data); 320 entry->record_data);
321 if (data_size < 0)
322 {
323 GNUNET_break (0);
324 GNUNET_free (zone_private_key);
325 return GNUNET_SYSERR;
326 }
327 if (data_size >= UINT16_MAX)
328 {
329 GNUNET_break (0);
330 GNUNET_free (zone_private_key);
331 return GNUNET_SYSERR;
332 }
347 { 333 {
348 char data[data_size]; 334 char data[data_size];
349 ssize_t ret; 335 ssize_t ret;
@@ -353,7 +339,7 @@ store_and_free_entries (void *cls,
353 data_size, 339 data_size,
354 data); 340 data);
355 if ( (ret < 0) || 341 if ( (ret < 0) ||
356 (data_size != (size_t) ret) ) 342 (data_size != ret) )
357 { 343 {
358 GNUNET_break (0); 344 GNUNET_break (0);
359 GNUNET_free (zone_private_key); 345 GNUNET_free (zone_private_key);
@@ -364,10 +350,10 @@ store_and_free_entries (void *cls,
364 &record_data_b64); 350 &record_data_b64);
365 } 351 }
366 GNUNET_asprintf (&line, 352 GNUNET_asprintf (&line,
367 "%s,%lu,%u,%s,%s\n", 353 "%s,%llu,%u,%s,%s\n",
368 zone_private_key, 354 zone_private_key,
369 entry->rvalue, 355 (unsigned long long) entry->rvalue,
370 entry->record_count, 356 (unsigned int) entry->record_count,
371 record_data_b64, 357 record_data_b64,
372 entry->label); 358 entry->label);
373 GNUNET_free (record_data_b64); 359 GNUNET_free (record_data_b64);
@@ -378,7 +364,6 @@ store_and_free_entries (void *cls,
378 strlen (line)); 364 strlen (line));
379 365
380 GNUNET_free (line); 366 GNUNET_free (line);
381 GNUNET_free (entry->private_key);
382 GNUNET_free (entry->label); 367 GNUNET_free (entry->label);
383 GNUNET_free (entry->record_data); 368 GNUNET_free (entry->record_data);
384 GNUNET_free (entry); 369 GNUNET_free (entry);
@@ -466,11 +451,10 @@ namestore_flat_store_records (void *cls,
466 return GNUNET_OK; 451 return GNUNET_OK;
467 } 452 }
468 entry = GNUNET_new (struct FlatFileEntry); 453 entry = GNUNET_new (struct FlatFileEntry);
469 entry->private_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
470 GNUNET_asprintf (&entry->label, 454 GNUNET_asprintf (&entry->label,
471 label, 455 label,
472 strlen (label)); 456 strlen (label));
473 GNUNET_memcpy (entry->private_key, 457 GNUNET_memcpy (&entry->private_key,
474 zone_key, 458 zone_key,
475 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 459 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
476 entry->rvalue = rvalue; 460 entry->rvalue = rvalue;
@@ -544,7 +528,7 @@ namestore_flat_lookup_records (void *cls,
544 if (NULL != iter) 528 if (NULL != iter)
545 iter (iter_cls, 529 iter (iter_cls,
546 0, 530 0,
547 entry->private_key, 531 &entry->private_key,
548 entry->label, 532 entry->label,
549 entry->record_count, 533 entry->record_count,
550 entry->record_data); 534 entry->record_data);
@@ -608,14 +592,14 @@ iterate_zones (void *cls,
608 struct FlatFileEntry *entry = value; 592 struct FlatFileEntry *entry = value;
609 593
610 (void) key; 594 (void) key;
611 ic->pos++;
612 if (0 == ic->limit) 595 if (0 == ic->limit)
613 return GNUNET_NO; 596 return GNUNET_NO;
614 if ( (NULL != ic->zone) && 597 if ( (NULL != ic->zone) &&
615 (0 != memcmp (entry->private_key, 598 (0 != memcmp (&entry->private_key,
616 ic->zone, 599 ic->zone,
617 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ) 600 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
618 return GNUNET_YES; 601 return GNUNET_YES;
602 ic->pos++;
619 if (ic->offset > 0) 603 if (ic->offset > 0)
620 { 604 {
621 ic->offset--; 605 ic->offset--;
@@ -623,7 +607,7 @@ iterate_zones (void *cls,
623 } 607 }
624 ic->iter (ic->iter_cls, 608 ic->iter (ic->iter_cls,
625 ic->pos, 609 ic->pos,
626 entry->private_key, 610 &entry->private_key,
627 entry->label, 611 entry->label,
628 entry->record_count, 612 entry->record_count,
629 entry->record_data); 613 entry->record_data);
@@ -670,17 +654,31 @@ namestore_flat_iterate_records (void *cls,
670} 654}
671 655
672 656
657/**
658 * Closure for #zone_to_name.
659 */
660struct ZoneToNameContext
661{
662 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone;
663 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone;
664 GNUNET_NAMESTORE_RecordIterator iter;
665 void *iter_cls;
666
667 int result_found;
668};
669
670
673static int 671static int
674zone_to_name (void *cls, 672zone_to_name (void *cls,
675 const struct GNUNET_HashCode *key, 673 const struct GNUNET_HashCode *key,
676 void *value) 674 void *value)
677{ 675{
678 struct Plugin *plugin = cls; 676 struct ZoneToNameContext *ztn = cls;
679 struct FlatFileEntry *entry = value; 677 struct FlatFileEntry *entry = value;
680 678
681 (void) key; 679 (void) key;
682 if (0 != memcmp (entry->private_key, 680 if (0 != memcmp (&entry->private_key,
683 plugin->iter_zone, 681 ztn->zone,
684 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 682 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
685 return GNUNET_YES; 683 return GNUNET_YES;
686 684
@@ -688,18 +686,17 @@ zone_to_name (void *cls,
688 { 686 {
689 if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type) 687 if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type)
690 continue; 688 continue;
691 if (0 == memcmp (plugin->iter_pkey, 689 if (0 == memcmp (ztn->value_zone,
692 entry->record_data[i].data, 690 entry->record_data[i].data,
693 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 691 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
694 { 692 {
695 plugin->iter (plugin->iter_cls, 693 ztn->iter (ztn->iter_cls,
696 0, 694 0,
697 entry->private_key, 695 &entry->private_key,
698 entry->label, 696 entry->label,
699 entry->record_count, 697 entry->record_count,
700 entry->record_data); 698 entry->record_data);
701 plugin->iter_result_found = GNUNET_YES; 699 ztn->result_found = GNUNET_YES;
702
703 } 700 }
704 } 701 }
705 return GNUNET_YES; 702 return GNUNET_YES;
@@ -725,21 +722,21 @@ namestore_flat_zone_to_name (void *cls,
725 void *iter_cls) 722 void *iter_cls)
726{ 723{
727 struct Plugin *plugin = cls; 724 struct Plugin *plugin = cls;
725 struct ZoneToNameContext ztn = {
726 .iter = iter,
727 .iter_cls = iter_cls,
728 .zone = zone,
729 .value_zone = value_zone,
730 .result_found = GNUNET_NO
731 };
728 732
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, 733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "Performing reverse lookup for `%s'\n", 734 "Performing reverse lookup for `%s'\n",
738 GNUNET_GNSRECORD_z2s (value_zone)); 735 GNUNET_GNSRECORD_z2s (value_zone));
739 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, 736 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm,
740 &zone_to_name, 737 &zone_to_name,
741 plugin); 738 &ztn);
742 return plugin->iter_result_found; 739 return ztn.result_found;
743} 740}
744 741
745 742
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c
index d7907b1a6..7c6acc91b 100644
--- a/src/namestore/plugin_namestore_postgres.c
+++ b/src/namestore/plugin_namestore_postgres.c
@@ -2,20 +2,18 @@
2 * This file is part of GNUnet 2 * This file is part of GNUnet
3 * Copyright (C) 2009-2013, 2016-2018 GNUnet e.V. 3 * Copyright (C) 2009-2013, 2016-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 it
6 * it under the terms of the GNU General Public License as published 6 * under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your 7 * by the Free Software Foundation, either version 3 of the License,
8 * option) any later version. 8 * or (at your option) any later version.
9 * 9 *
10 * GNUnet is distributed in the hope that it will be useful, but 10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details. 13 * Affero General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU Affero General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */ 17 */
20 18
21/** 19/**
@@ -220,7 +218,7 @@ namestore_postgres_store_records (void *cls,
220 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 218 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
221 uint64_t rvalue; 219 uint64_t rvalue;
222 uint32_t rd_count32 = (uint32_t) rd_count; 220 uint32_t rd_count32 = (uint32_t) rd_count;
223 size_t data_size; 221 ssize_t data_size;
224 222
225 memset (&pkey, 223 memset (&pkey,
226 0, 224 0,
@@ -238,7 +236,12 @@ namestore_postgres_store_records (void *cls,
238 UINT64_MAX); 236 UINT64_MAX);
239 data_size = GNUNET_GNSRECORD_records_get_size (rd_count, 237 data_size = GNUNET_GNSRECORD_records_get_size (rd_count,
240 rd); 238 rd);
241 if (data_size > 64 * 65536) 239 if (data_size < 0)
240 {
241 GNUNET_break (0);
242 return GNUNET_SYSERR;
243 }
244 if (data_size >= UINT16_MAX)
242 { 245 {
243 GNUNET_break (0); 246 GNUNET_break (0);
244 return GNUNET_SYSERR; 247 return GNUNET_SYSERR;
@@ -287,7 +290,7 @@ namestore_postgres_store_records (void *cls,
287 data_size, 290 data_size,
288 data); 291 data);
289 if ( (ret < 0) || 292 if ( (ret < 0) ||
290 (data_size != (size_t) ret) ) 293 (data_size != ret) )
291 { 294 {
292 GNUNET_break (0); 295 GNUNET_break (0);
293 return GNUNET_SYSERR; 296 return GNUNET_SYSERR;
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index f62be1e18..6960e5d12 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -2,20 +2,18 @@
2 * This file is part of GNUnet 2 * This file is part of GNUnet
3 * Copyright (C) 2009-2017 GNUnet e.V. 3 * Copyright (C) 2009-2017 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 it
6 * it under the terms of the GNU General Public License as published 6 * under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your 7 * by the Free Software Foundation, either version 3 of the License,
8 * option) any later version. 8 * or (at your option) any later version.
9 * 9 *
10 * GNUnet is distributed in the hope that it will be useful, but 10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details. 13 * Affero General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU Affero General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */ 17 */
20 18
21/** 19/**
@@ -106,72 +104,6 @@ struct Plugin
106 104
107 105
108/** 106/**
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 */
116static int
117sq_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 */
144static void
145create_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 107 * Initialize the database connections and associated
176 * data structures (create tables and indices 108 * data structures (create tables and indices
177 * as needed as well). 109 * as needed as well).
@@ -182,17 +114,66 @@ create_indices (sqlite3 * dbh)
182static int 114static int
183database_setup (struct Plugin *plugin) 115database_setup (struct Plugin *plugin)
184{ 116{
185 sqlite3_stmt *stmt; 117 char *sqlite_filename;
186 char *afsdir; 118 struct GNUNET_SQ_ExecuteStatement es[] = {
187#if ENULL_DEFINED 119 GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
188 char *e; 120 GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
189#endif 121 GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
122 GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
123 GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
124 GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=EXCLUSIVE"),
125 GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
126 GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records ("
127 " uid INTEGER PRIMARY KEY,"
128 " zone_private_key BLOB NOT NULL,"
129 " pkey BLOB,"
130 " rvalue INT8 NOT NULL,"
131 " record_count INT NOT NULL,"
132 " record_data BLOB NOT NULL,"
133 " label TEXT NOT NULL"
134 ")"),
135 GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
136 "ON ns098records (zone_private_key,pkey)"),
137 GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter "
138 "ON ns098records (zone_private_key,uid)"),
139 GNUNET_SQ_EXECUTE_STATEMENT_END
140 };
141 struct GNUNET_SQ_PrepareStatement ps[] = {
142 GNUNET_SQ_make_prepare ("INSERT INTO ns098records "
143 "(zone_private_key,pkey,rvalue,record_count,record_data,label)"
144 " VALUES (?, ?, ?, ?, ?, ?)",
145 &plugin->store_records),
146 GNUNET_SQ_make_prepare ("DELETE FROM ns098records "
147 "WHERE zone_private_key=? AND label=?",
148 &plugin->delete_records),
149 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
150 " FROM ns098records"
151 " WHERE zone_private_key=? AND pkey=?",
152 &plugin->zone_to_name),
153 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
154 " FROM ns098records"
155 " WHERE zone_private_key=? AND _rowid_ >= ?"
156 " ORDER BY _rowid_ ASC"
157 " LIMIT ?",
158 &plugin->iterate_zone),
159 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key"
160 " FROM ns098records"
161 " WHERE _rowid_ >= ?"
162 " ORDER BY _rowid_ ASC"
163 " LIMIT ?",
164 &plugin->iterate_all_zones),
165 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key"
166 " FROM ns098records"
167 " WHERE zone_private_key=? AND label=?",
168 &plugin->lookup_label),
169 GNUNET_SQ_PREPARE_END
170 };
190 171
191 if (GNUNET_OK != 172 if (GNUNET_OK !=
192 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, 173 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg,
193 "namestore-sqlite", 174 "namestore-sqlite",
194 "FILENAME", 175 "FILENAME",
195 &afsdir)) 176 &sqlite_filename))
196 { 177 {
197 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 178 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
198 "namestore-sqlite", 179 "namestore-sqlite",
@@ -200,132 +181,51 @@ database_setup (struct Plugin *plugin)
200 return GNUNET_SYSERR; 181 return GNUNET_SYSERR;
201 } 182 }
202 if (GNUNET_OK != 183 if (GNUNET_OK !=
203 GNUNET_DISK_file_test (afsdir)) 184 GNUNET_DISK_file_test (sqlite_filename))
204 { 185 {
205 if (GNUNET_OK != 186 if (GNUNET_OK !=
206 GNUNET_DISK_directory_create_for_file (afsdir)) 187 GNUNET_DISK_directory_create_for_file (sqlite_filename))
207 { 188 {
208 GNUNET_break (0); 189 GNUNET_break (0);
209 GNUNET_free (afsdir); 190 GNUNET_free (sqlite_filename);
210 return GNUNET_SYSERR; 191 return GNUNET_SYSERR;
211 } 192 }
212 } 193 }
213 /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ 194 /* sqlite_filename should be UTF-8-encoded. If it isn't, it's a bug */
214 plugin->fn = afsdir; 195 plugin->fn = sqlite_filename;
215 196
216 /* Open database and precompile statements */ 197 /* Open database and precompile statements */
217 if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK) 198 if (SQLITE_OK !=
199 sqlite3_open (plugin->fn,
200 &plugin->dbh))
218 { 201 {
219 LOG (GNUNET_ERROR_TYPE_ERROR, 202 LOG (GNUNET_ERROR_TYPE_ERROR,
220 _("Unable to initialize SQLite: %s.\n"), 203 _("Unable to initialize SQLite: %s.\n"),
221 sqlite3_errmsg (plugin->dbh)); 204 sqlite3_errmsg (plugin->dbh));
222 return GNUNET_SYSERR; 205 return GNUNET_SYSERR;
223 } 206 }
224 CHECK (SQLITE_OK == 207 GNUNET_break (SQLITE_OK ==
225 sqlite3_exec (plugin->dbh, 208 sqlite3_busy_timeout (plugin->dbh,
226 "PRAGMA temp_store=MEMORY", NULL, NULL, 209 BUSY_TIMEOUT_MS));
227 ENULL)); 210 if (GNUNET_OK !=
228 CHECK (SQLITE_OK == 211 GNUNET_SQ_exec_statements (plugin->dbh,
229 sqlite3_exec (plugin->dbh, 212 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 { 213 {
277 LOG_SQLITE (plugin, 214 GNUNET_break (0);
278 GNUNET_ERROR_TYPE_ERROR, 215 LOG (GNUNET_ERROR_TYPE_ERROR,
279 "sqlite3_exec"); 216 _("Failed to setup database at `%s'\n"),
280 sqlite3_finalize (stmt); 217 plugin->fn);
281 return GNUNET_SYSERR; 218 return GNUNET_SYSERR;
282 } 219 }
283 sqlite3_finalize (stmt); 220
284 221 if (GNUNET_OK !=
285 create_indices (plugin->dbh); 222 GNUNET_SQ_prepare (plugin->dbh,
286 223 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 { 224 {
326 LOG_SQLITE (plugin, 225 GNUNET_break (0);
327 GNUNET_ERROR_TYPE_ERROR, 226 LOG (GNUNET_ERROR_TYPE_ERROR,
328 "precompiling"); 227 _("Failed to setup database at `%s'\n"),
228 plugin->fn);
329 return GNUNET_SYSERR; 229 return GNUNET_SYSERR;
330 } 230 }
331 return GNUNET_OK; 231 return GNUNET_OK;
@@ -411,7 +311,7 @@ namestore_sqlite_store_records (void *cls,
411 int n; 311 int n;
412 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 312 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
413 uint64_t rvalue; 313 uint64_t rvalue;
414 size_t data_size; 314 ssize_t data_size;
415 315
416 memset (&pkey, 316 memset (&pkey,
417 0, 317 0,
@@ -430,6 +330,11 @@ namestore_sqlite_store_records (void *cls,
430 UINT64_MAX); 330 UINT64_MAX);
431 data_size = GNUNET_GNSRECORD_records_get_size (rd_count, 331 data_size = GNUNET_GNSRECORD_records_get_size (rd_count,
432 rd); 332 rd);
333 if (data_size < 0)
334 {
335 GNUNET_break (0);
336 return GNUNET_SYSERR;
337 }
433 if (data_size > 64 * 65536) 338 if (data_size > 64 * 65536)
434 { 339 {
435 GNUNET_break (0); 340 GNUNET_break (0);
@@ -450,7 +355,7 @@ namestore_sqlite_store_records (void *cls,
450 data_size, 355 data_size,
451 data); 356 data);
452 if ( (ret < 0) || 357 if ( (ret < 0) ||
453 (data_size != (size_t) ret) ) 358 (data_size != ret) )
454 { 359 {
455 GNUNET_break (0); 360 GNUNET_break (0);
456 return GNUNET_SYSERR; 361 return GNUNET_SYSERR;
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
deleted file mode 100644
index fd1528a1d..000000000
--- a/src/namestore/plugin_rest_namestore.c
+++ /dev/null
@@ -1,1231 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V.
4
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19 */
20/**
21 * @author Martin Schanzenbach
22 * @file namestore/plugin_rest_namestore.c
23 * @brief GNUnet Namestore REST plugin
24 *
25 */
26
27#include "platform.h"
28#include "gnunet_rest_plugin.h"
29#include "gnunet_gns_service.h"
30#include "gnunet_namestore_service.h"
31#include "gnunet_identity_service.h"
32#include "gnunet_rest_lib.h"
33#include "gnunet_jsonapi_lib.h"
34#include "gnunet_jsonapi_util.h"
35#include "microhttpd.h"
36#include <jansson.h>
37
38#define GNUNET_REST_API_NS_NAMESTORE "/names"
39
40#define GNUNET_REST_API_NS_NAMESTORE_ZKEY "/names/zkey"
41
42#define GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO "record"
43
44#define GNUNET_REST_JSONAPI_NAMESTORE_NAME "name"
45
46#define GNUNET_REST_JSONAPI_NAMESTORE_REVINFO "revinfo"
47
48#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO
49
50#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE "record_type"
51
52#define GNUNET_REST_JSONAPI_NAMESTORE_VALUE "value"
53
54#define GNUNET_REST_JSONAPI_NAMESTORE_PUBLIC "public"
55
56#define GNUNET_REST_JSONAPI_NAMESTORE_SHADOW "shadow"
57
58#define GNUNET_REST_JSONAPI_NAMESTORE_PKEY "pkey"
59
60#define GNUNET_REST_JSONAPI_NAMESTORE_ZKEY "zkey"
61
62#define GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION "expiration"
63
64#define GNUNET_REST_JSONAPI_NAMESTORE_EGO "ego"
65
66/**
67 * @brief struct returned by the initialization function of the plugin
68 */
69struct Plugin
70{
71 const struct GNUNET_CONFIGURATION_Handle *cfg;
72};
73
74
75/**
76 * HTTP methods allows for this plugin
77 */
78static char* allow_methods;
79
80const struct GNUNET_CONFIGURATION_Handle *cfg;
81
82struct RecordEntry
83{
84 /**
85 * DLL
86 */
87 struct RecordEntry *next;
88
89 /**
90 * DLL
91 */
92 struct RecordEntry *prev;
93
94};
95
96struct RequestHandle
97{
98 /**
99 * Ego list
100 */
101 struct RecordEntry *record_head;
102
103 /**
104 * Ego list
105 */
106 struct record_entry *record_tail;
107
108 /**
109 * JSON response object
110 */
111 struct GNUNET_JSONAPI_Document *resp_object;
112
113 /**
114 * Rest connection
115 */
116 struct GNUNET_REST_RequestHandle *rest_handle;
117
118 /**
119 * Handle to GNS service.
120 */
121 struct GNUNET_IDENTITY_Handle *identity_handle;
122
123 /**
124 * Handle to NAMESTORE
125 */
126 struct GNUNET_NAMESTORE_Handle *ns_handle;
127
128 /**
129 * Handle to NAMESTORE it
130 */
131 struct GNUNET_NAMESTORE_ZoneIterator *list_it;
132
133 /**
134 * Private key for the zone
135 */
136 struct GNUNET_CRYPTO_EcdsaPrivateKey zone_pkey;
137
138 /**
139 * Handle to identity lookup
140 */
141 struct GNUNET_IDENTITY_EgoLookup *ego_lookup;
142
143 /**
144 * Default Ego operation
145 */
146 struct GNUNET_IDENTITY_Operation *get_default;
147
148 /**
149 * Name of the ego
150 */
151 char *ego_name;
152
153 /**
154 * Record is public
155 */
156 int is_public;
157
158 /**
159 * Shadow record
160 */
161 int is_shadow;
162
163 /**
164 * Name of the record to modify
165 */
166 char *name;
167
168 /**
169 * Value of the record
170 */
171 char *value;
172
173 /**
174 * Zkey string
175 */
176 const char* zkey_str;
177
178 /**
179 * record type
180 */
181 uint32_t type;
182
183 /**
184 * Records to store
185 */
186 struct GNUNET_GNSRECORD_Data *rd;
187
188 /**
189 * record count
190 */
191 unsigned int rd_count;
192
193 /**
194 * NAMESTORE Operation
195 */
196 struct GNUNET_NAMESTORE_QueueEntry *add_qe;
197
198 /**
199 * NAMESTORE Operation
200 */
201 struct GNUNET_NAMESTORE_QueueEntry *reverse_qe;
202
203 /**
204 * Desired timeout for the lookup (default is no timeout).
205 */
206 struct GNUNET_TIME_Relative timeout;
207
208 /**
209 * ID of a task associated with the resolution process.
210 */
211 struct GNUNET_SCHEDULER_Task * timeout_task;
212
213 /**
214 * The plugin result processor
215 */
216 GNUNET_REST_ResultProcessor proc;
217
218 /**
219 * The closure of the result processor
220 */
221 void *proc_cls;
222
223 /**
224 * The url
225 */
226 char *url;
227
228 /**
229 * Cfg
230 */
231 const struct GNUNET_CONFIGURATION_Handle *cfg;
232
233 /**
234 * HTTP response code
235 */
236 int response_code;
237
238};
239
240
241/**
242 * Cleanup lookup handle
243 *
244 * @param handle Handle to clean up
245 */
246static void
247cleanup_handle (struct RequestHandle *handle)
248{
249 struct RecordEntry *record_entry;
250 struct RecordEntry *record_tmp;
251
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 "Cleaning up\n");
254 if (NULL != handle->resp_object)
255 GNUNET_JSONAPI_document_delete (handle->resp_object);
256 if (NULL != handle->name)
257 GNUNET_free (handle->name);
258 if (NULL != handle->timeout_task)
259 GNUNET_SCHEDULER_cancel (handle->timeout_task);
260 if (NULL != handle->ego_lookup)
261 GNUNET_IDENTITY_ego_lookup_cancel (handle->ego_lookup);
262 if (NULL != handle->get_default)
263 GNUNET_IDENTITY_cancel (handle->get_default);
264 if (NULL != handle->list_it)
265 GNUNET_NAMESTORE_zone_iteration_stop (handle->list_it);
266 if (NULL != handle->add_qe)
267 GNUNET_NAMESTORE_cancel (handle->add_qe);
268 if (NULL != handle->identity_handle)
269 GNUNET_IDENTITY_disconnect (handle->identity_handle);
270 if (NULL != handle->ns_handle)
271 GNUNET_NAMESTORE_disconnect (handle->ns_handle);
272 if (NULL != handle->url)
273 GNUNET_free (handle->url);
274 if (NULL != handle->value)
275 GNUNET_free (handle->value);
276 if (NULL != handle->rd)
277 {
278 for (unsigned int i = 0; i < handle->rd_count; i++)
279 {
280 if (NULL != handle->rd[i].data)
281 GNUNET_free ((void*)handle->rd[i].data);
282 }
283 GNUNET_free (handle->rd);
284 }
285 if (NULL != handle->ego_name)
286 GNUNET_free (handle->ego_name);
287 for (record_entry = handle->record_head;
288 NULL != record_entry;)
289 {
290 record_tmp = record_entry;
291 record_entry = record_entry->next;
292 GNUNET_free (record_tmp);
293 }
294 GNUNET_free (handle);
295}
296
297
298/**
299 * Create json representation of a GNSRECORD
300 *
301 * @param rd the GNSRECORD_Data
302 */
303static json_t *
304gnsrecord_to_json (const struct GNUNET_GNSRECORD_Data *rd)
305{
306 const char *typename;
307 char *string_val;
308 const char *exp_str;
309 json_t *record_obj;
310
311 typename = GNUNET_GNSRECORD_number_to_typename (rd->record_type);
312 string_val = GNUNET_GNSRECORD_value_to_string (rd->record_type,
313 rd->data,
314 rd->data_size);
315
316 if (NULL == string_val)
317 {
318 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
319 "Record of type %d malformed, skipping\n",
320 (int) rd->record_type);
321 return NULL;
322 }
323 record_obj = json_object();
324 json_object_set_new (record_obj,
325 GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE,
326 json_string (typename));
327 json_object_set_new (record_obj,
328 GNUNET_REST_JSONAPI_NAMESTORE_VALUE,
329 json_string (string_val));
330 GNUNET_free (string_val);
331
332 if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd->flags)
333 {
334 struct GNUNET_TIME_Relative time_rel;
335 time_rel.rel_value_us = rd->expiration_time;
336 exp_str = GNUNET_STRINGS_relative_time_to_string (time_rel, 1);
337 }
338 else
339 {
340 struct GNUNET_TIME_Absolute time_abs;
341 time_abs.abs_value_us = rd->expiration_time;
342 exp_str = GNUNET_STRINGS_absolute_time_to_string (time_abs);
343 }
344 json_object_set_new (record_obj, GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION, json_string (exp_str));
345
346 json_object_set_new (record_obj, "expired",
347 json_boolean (GNUNET_YES == GNUNET_GNSRECORD_is_expired (rd)));
348 return record_obj;
349}
350
351
352/**
353 * Task run on error. Generates error response and cleans up.
354 *
355 * @param cls the request to generate an error response for
356 */
357static void
358do_error (void *cls)
359{
360 struct RequestHandle *handle = cls;
361 struct MHD_Response *resp = GNUNET_REST_create_response (NULL);
362
363 handle->proc (handle->proc_cls, resp, handle->response_code);
364 cleanup_handle (handle);
365}
366
367
368/**
369 * Task run on timeout.
370 *
371 * @param cls the request to time out
372 */
373static void
374do_timeout (void *cls)
375{
376 struct RequestHandle *handle = cls;
377
378 handle->timeout_task = NULL;
379 do_error (handle);
380}
381
382
383static void
384cleanup_handle_delayed (void *cls)
385{
386 cleanup_handle (cls);
387}
388
389
390/**
391 * Iteration over all results finished, build final
392 * response.
393 *
394 * @param cls the `struct RequestHandle`
395 */
396static void
397namestore_list_finished (void *cls)
398{
399 struct RequestHandle *handle = cls;
400 char *result;
401 struct MHD_Response *resp;
402
403 handle->list_it = NULL;
404 if (NULL == handle->resp_object)
405 handle->resp_object = GNUNET_JSONAPI_document_new ();
406
407 if (GNUNET_SYSERR ==
408 GNUNET_JSONAPI_document_serialize (handle->resp_object,
409 &result))
410 {
411 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
412 GNUNET_SCHEDULER_add_now (&do_error,
413 handle);
414 return;
415 }
416 resp = GNUNET_REST_create_response (result);
417 handle->proc (handle->proc_cls,
418 resp,
419 MHD_HTTP_OK);
420 GNUNET_free_non_null (result);
421 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed,
422 handle);
423}
424
425
426
427/**
428 * Create a response with requested records
429 *
430 * @param handle the RequestHandle
431 */
432static void
433namestore_list_response (void *cls,
434 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
435 const char *rname,
436 unsigned int rd_len,
437 const struct GNUNET_GNSRECORD_Data *rd)
438{
439 struct RequestHandle *handle = cls;
440 struct GNUNET_JSONAPI_Resource *json_resource;
441 json_t *result_array;
442 json_t *record_obj;
443
444 if (NULL == handle->resp_object)
445 handle->resp_object = GNUNET_JSONAPI_document_new ();
446
447 if ( (NULL != handle->name) &&
448 (0 != strcmp (handle->name,
449 rname)) )
450 {
451 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
452 "%s does not match %s\n",
453 rname,
454 handle->name);
455 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it,
456 1);
457 return;
458 }
459
460 result_array = json_array ();
461 for (unsigned int i=0; i<rd_len; i++)
462 {
463 if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
464 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)) )
465 continue;
466
467 if ( (rd[i].record_type != handle->type) &&
468 (GNUNET_GNSRECORD_TYPE_ANY != handle->type) )
469 continue;
470 record_obj = gnsrecord_to_json (&rd[i]);
471 json_array_append (result_array,
472 record_obj);
473 json_decref (record_obj);
474 }
475
476 if (0 < json_array_size(result_array))
477 {
478 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO,
479 rname);
480 GNUNET_JSONAPI_resource_add_attr (json_resource,
481 GNUNET_REST_JSONAPI_NAMESTORE_RECORD,
482 result_array);
483 GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource);
484 }
485
486 json_decref (result_array);
487 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it,
488 1);
489}
490
491
492static void
493create_finished (void *cls, int32_t success, const char *emsg)
494{
495 struct RequestHandle *handle = cls;
496 struct MHD_Response *resp;
497
498 handle->add_qe = NULL;
499 if (GNUNET_YES != success)
500 {
501 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
502 "Error storing records%s%s\n",
503 (NULL == emsg) ? "" : ": ",
504 (NULL == emsg) ? "" : emsg);
505 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
506 return;
507 }
508 resp = GNUNET_REST_create_response (NULL);
509 handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
510 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
511}
512
513
514/**
515 * We're storing a new record; this requires
516 * that no record already exists
517 *
518 * @param cls closure, unused
519 * @param zone_key private key of the zone
520 * @param rec_name name that is being mapped (at most 255 characters long)
521 * @param rd_count number of entries in @a rd array
522 * @param rd array of records with data to store
523 */
524static void
525create_new_record_cont (void *cls,
526 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
527 const char *rec_name,
528 unsigned int rd_count,
529 const struct GNUNET_GNSRECORD_Data *rd)
530{
531 struct RequestHandle *handle = cls;
532
533 handle->add_qe = NULL;
534 if (0 != strcmp (rec_name, handle->name))
535 {
536 GNUNET_break (0);
537 do_error (handle);
538 return;
539 }
540
541 if (0 != rd_count)
542 {
543 handle->proc (handle->proc_cls,
544 GNUNET_REST_create_response (NULL),
545 MHD_HTTP_CONFLICT);
546 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
547 return;
548 }
549
550 GNUNET_assert (NULL != handle->name);
551 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
552 &handle->zone_pkey,
553 handle->name,
554 handle->rd_count,
555 handle->rd,
556 &create_finished,
557 handle);
558}
559
560
561static void
562del_finished (void *cls,
563 int32_t success,
564 const char *emsg)
565{
566 struct RequestHandle *handle = cls;
567
568 handle->add_qe = NULL;
569 if (GNUNET_NO == success)
570 {
571 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
572 _("Deleting record failed, record does not exist%s%s\n"),
573 (NULL != emsg) ? ": " : "",
574 (NULL != emsg) ? emsg : "");
575 GNUNET_SCHEDULER_add_now (&do_error, handle); //do_not_found TODO
576 return;
577 }
578 if (GNUNET_SYSERR == success)
579 {
580 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
581 _("Deleting record failed%s%s\n"),
582 (NULL != emsg) ? ": " : "",
583 (NULL != emsg) ? emsg : "");
584 GNUNET_SCHEDULER_add_now (&do_error, handle);
585 return;
586 }
587 handle->proc (handle->proc_cls,
588 GNUNET_REST_create_response (NULL),
589 MHD_HTTP_NO_CONTENT);
590 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
591}
592
593
594static void
595del_cont (void *cls,
596 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
597 const char *label,
598 unsigned int rd_count,
599 const struct GNUNET_GNSRECORD_Data *rd)
600{
601 struct RequestHandle *handle = cls;
602
603 handle->add_qe = NULL;
604 if (0 == rd_count)
605 {
606 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
607 _("There are no records under label `%s' that could be deleted.\n"),
608 label);
609 do_error (handle);
610 return;
611 }
612
613 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
614 &handle->zone_pkey,
615 handle->name,
616 0, NULL,
617 &del_finished,
618 handle);
619}
620
621
622static void
623namestore_delete_cont (struct GNUNET_REST_RequestHandle *con,
624 const char *url,
625 void *cls)
626{
627 struct RequestHandle *handle = cls;
628
629 if (NULL == handle->name)
630 {
631 GNUNET_SCHEDULER_add_now (&do_error, handle);
632 return;
633 }
634
635 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
636 &handle->zone_pkey,
637 handle->name,
638 &do_error,
639 handle,
640 &del_cont,
641 handle);
642}
643
644
645static int
646json_to_gnsrecord (const json_t *records_json,
647 struct GNUNET_GNSRECORD_Data **rd,
648 unsigned int *rd_count)
649{
650 struct GNUNET_TIME_Relative etime_rel;
651 struct GNUNET_TIME_Absolute etime_abs;
652 char *value;
653 void *rdata;
654 size_t rdata_size;
655 const char *typestring;
656 const char *expirationstring;
657 json_t *type_json;
658 json_t *value_json;
659 json_t *record_json;
660 json_t *exp_json;
661
662 *rd_count = json_array_size (records_json);
663 *rd = GNUNET_new_array (*rd_count,
664 struct GNUNET_GNSRECORD_Data);
665 for (unsigned int i = 0; i < *rd_count; i++)
666 {
667 memset (&(*rd)[i],
668 0,
669 sizeof (struct GNUNET_GNSRECORD_Data));
670 record_json = json_array_get (records_json,
671 i);
672 type_json = json_object_get (record_json,
673 GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE);
674 if (! json_is_string (type_json))
675 {
676 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
677 "Type property is no string\n");
678 return GNUNET_SYSERR;
679 }
680 typestring = json_string_value (type_json);
681 (*rd)[i].record_type = GNUNET_GNSRECORD_typename_to_number (typestring);
682 if (UINT32_MAX == (*rd)[i].record_type)
683 {
684 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Unsupported type `%s'\n"),
685 json_string_value (type_json));
686 return GNUNET_SYSERR;
687 }
688 value_json = json_object_get (record_json,
689 GNUNET_REST_JSONAPI_NAMESTORE_VALUE);
690 if (! json_is_string (value_json))
691 {
692 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
693 "Value property is no string\n");
694 return GNUNET_SYSERR;
695 }
696 value = GNUNET_strdup (json_string_value (value_json));
697 if (GNUNET_OK !=
698 GNUNET_GNSRECORD_string_to_value ((*rd)[i].record_type,
699 value,
700 &rdata,
701 &rdata_size))
702 {
703 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
704 _("Value `%s' invalid for record type `%s'\n"),
705 value,
706 typestring);
707 return GNUNET_SYSERR;
708 }
709 (*rd)[i].data = rdata;
710 (*rd)[i].data_size = rdata_size;
711 /**TODO
712 * if (1 == handle->is_shadow)
713 rde->flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;
714 if (1 != handle->is_public)
715 rde->flags |= GNUNET_GNSRECORD_RF_PRIVATE;
716 */
717 exp_json = json_object_get (record_json,
718 GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION);
719 if (! json_is_string (exp_json))
720 {
721 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
722 "Expiration property is no string\n");
723 return GNUNET_SYSERR;
724 }
725 expirationstring = json_string_value (exp_json);
726 if (0 == strcmp (expirationstring, "never"))
727 {
728 (*rd)[i].expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
729 }
730 else if (GNUNET_OK ==
731 GNUNET_STRINGS_fancy_time_to_relative (expirationstring,
732 &etime_rel))
733 {
734 (*rd)[i].expiration_time = etime_rel.rel_value_us;
735 (*rd)[i].flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
736 }
737 else if (GNUNET_OK ==
738 GNUNET_STRINGS_fancy_time_to_absolute (expirationstring,
739 &etime_abs))
740 {
741 (*rd)[i].expiration_time = etime_abs.abs_value_us;
742 }
743 else
744 {
745 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
746 _("Value `%s' invalid for record type `%s'\n"),
747 value,
748 typestring);
749 return GNUNET_SYSERR;
750 }
751 }
752 return GNUNET_OK;
753}
754
755
756static void
757namestore_create_cont (struct GNUNET_REST_RequestHandle *con,
758 const char *url,
759 void *cls)
760{
761 struct RequestHandle *handle = cls;
762 struct MHD_Response *resp;
763 struct GNUNET_JSONAPI_Document *json_obj;
764 struct GNUNET_JSONAPI_Resource *json_res;
765 json_t *records_json;
766 json_t *data_js;
767 json_error_t err;
768 char term_data[handle->rest_handle->data_size+1];
769 struct GNUNET_JSON_Specification docspec[] = {
770 GNUNET_JSON_spec_jsonapi_document (&json_obj),
771 GNUNET_JSON_spec_end()
772 };
773
774 if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url))
775 {
776 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
777 "Cannot create under %s\n", handle->url);
778 GNUNET_SCHEDULER_add_now (&do_error, handle);
779 return;
780 }
781 if (0 >= handle->rest_handle->data_size)
782 {
783 GNUNET_SCHEDULER_add_now (&do_error, handle);
784 return;
785 }
786 term_data[handle->rest_handle->data_size] = '\0';
787 GNUNET_memcpy (term_data,
788 handle->rest_handle->data,
789 handle->rest_handle->data_size);
790 data_js = json_loads (term_data,
791 JSON_DECODE_ANY,
792 &err);
793 GNUNET_assert (GNUNET_OK ==
794 GNUNET_JSON_parse (data_js, docspec,
795 NULL, NULL));
796 json_decref (data_js);
797 if (NULL == json_obj)
798 {
799 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
800 "Unable to parse JSONAPI Object from %s\n",
801 term_data);
802 GNUNET_SCHEDULER_add_now (&do_error, handle);
803 return;
804 }
805 if (1 != GNUNET_JSONAPI_document_resource_count (json_obj))
806 {
807 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
808 "Cannot create more than 1 resource! (Got %d)\n",
809 GNUNET_JSONAPI_document_resource_count (json_obj));
810 GNUNET_JSONAPI_document_delete (json_obj);
811 GNUNET_SCHEDULER_add_now (&do_error, handle);
812 return;
813 }
814 json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0);
815 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res,
816 GNUNET_REST_JSONAPI_NAMESTORE_RECORD))
817 {
818 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
819 "Unsupported JSON data type\n");
820 GNUNET_JSONAPI_document_delete (json_obj);
821 resp = GNUNET_REST_create_response (NULL);
822 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
823 cleanup_handle (handle);
824 return;
825 }
826 handle->name = GNUNET_strdup (GNUNET_JSONAPI_resource_get_id (json_res));
827 records_json = GNUNET_JSONAPI_resource_read_attr (json_res,
828 GNUNET_REST_JSONAPI_NAMESTORE_RECORD);
829 if (NULL == records_json)
830 {
831 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
832 "No records given\n");
833 GNUNET_JSONAPI_document_delete (json_obj);
834 GNUNET_SCHEDULER_add_now (&do_error, handle);
835 return;
836 }
837 if (GNUNET_SYSERR == json_to_gnsrecord (records_json, &handle->rd, &handle->rd_count))
838 {
839 GNUNET_JSONAPI_document_delete (json_obj);
840 GNUNET_SCHEDULER_add_now (&do_error, handle);
841 return;
842 }
843 GNUNET_JSONAPI_document_delete (json_obj);
844
845 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
846 &handle->zone_pkey,
847 handle->name,
848 &do_error,
849 handle,
850 &create_new_record_cont,
851 handle);
852}
853
854
855static void
856namestore_zkey_response (void *cls,
857 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
858 const char *label,
859 unsigned int rd_count,
860 const struct GNUNET_GNSRECORD_Data *rd)
861{
862 struct RequestHandle *handle = cls;
863 struct MHD_Response *resp;
864 struct GNUNET_JSONAPI_Document *json_obj;
865 struct GNUNET_JSONAPI_Resource *json_res;
866 json_t *name_json;
867 char* result;
868
869 handle->reverse_qe = NULL;
870 json_obj = GNUNET_JSONAPI_document_new ();
871 if (NULL != label)
872 {
873 name_json = json_string (label);
874 json_res = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_NAMESTORE_REVINFO,
875 handle->zkey_str);
876 GNUNET_JSONAPI_resource_add_attr (json_res,
877 GNUNET_REST_JSONAPI_NAMESTORE_NAME,
878 name_json);
879 GNUNET_JSONAPI_document_resource_add (json_obj, json_res);
880 json_decref (name_json);
881 }
882 //Handle response
883 if (GNUNET_SYSERR == GNUNET_JSONAPI_document_serialize (json_obj, &result))
884 {
885 GNUNET_JSONAPI_document_delete (json_obj);
886 GNUNET_SCHEDULER_add_now (&do_error, handle);
887 return;
888 }
889 resp = GNUNET_REST_create_response (result);
890 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
891 GNUNET_JSONAPI_document_delete (json_obj);
892 GNUNET_free (result);
893 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
894}
895
896
897static void
898namestore_zkey_cont (struct GNUNET_REST_RequestHandle *con,
899 const char *url,
900 void *cls)
901{
902 struct RequestHandle *handle = cls;
903 struct GNUNET_HashCode key;
904 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
905
906 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_ZKEY,
907 strlen (GNUNET_REST_JSONAPI_NAMESTORE_ZKEY),
908 &key);
909 if ( GNUNET_NO ==
910 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map,
911 &key) )
912 {
913 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
914 "No zkey given %s\n", handle->url);
915 GNUNET_SCHEDULER_add_now (&do_error, handle);
916 return;
917 }
918 handle->zkey_str = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map,
919 &key);
920 if ((NULL == handle->zkey_str) ||
921 (GNUNET_OK !=
922 GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->zkey_str,
923 strlen (handle->zkey_str),
924 &pubkey)))
925 {
926 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
927 "Zkey invalid %s\n", handle->zkey_str);
928 GNUNET_SCHEDULER_add_now (&do_error, handle);
929 return;
930 }
931 handle->reverse_qe = GNUNET_NAMESTORE_zone_to_name (handle->ns_handle,
932 &handle->zone_pkey,
933 &pubkey,
934 &do_error,
935 handle,
936 &namestore_zkey_response,
937 handle);
938}
939
940
941static void
942namestore_info_cont (struct GNUNET_REST_RequestHandle *con,
943 const char *url,
944 void *cls)
945{
946 struct RequestHandle *handle = cls;
947
948 handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
949 &handle->zone_pkey,
950 &do_error,
951 handle,
952 &namestore_list_response,
953 handle,
954 &namestore_list_finished,
955 handle);
956}
957
958
959static char*
960get_name_from_url (const char* url)
961{
962 if (strlen (url) <= strlen (GNUNET_REST_API_NS_NAMESTORE))
963 return NULL;
964 return (char*)url + strlen (GNUNET_REST_API_NS_NAMESTORE) + 1;
965}
966
967/**
968 * Respond to OPTIONS request
969 *
970 * @param con_handle the connection handle
971 * @param url the url
972 * @param cls the RequestHandle
973 */
974static void
975options_cont (struct GNUNET_REST_RequestHandle *con_handle,
976 const char* url,
977 void *cls)
978{
979 struct MHD_Response *resp;
980 struct RequestHandle *handle = cls;
981
982 //For now, independent of path return all options
983 resp = GNUNET_REST_create_response (NULL);
984 MHD_add_response_header (resp,
985 "Access-Control-Allow-Methods",
986 allow_methods);
987 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
988 cleanup_handle (handle);
989}
990
991
992/**
993 * Callback invoked from identity service with ego information.
994 * An @a ego of NULL means the ego was not found.
995 *
996 * @param cls closure with the configuration
997 * @param ego an ego known to identity service, or NULL
998 */
999static void
1000identity_cb (void *cls,
1001 const struct GNUNET_IDENTITY_Ego *ego)
1002{
1003 struct RequestHandle *handle = cls;
1004 struct MHD_Response *resp;
1005 struct GNUNET_REST_RequestHandlerError err;
1006 static const struct GNUNET_REST_RequestHandler handlers[] = {
1007 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE_ZKEY, &namestore_zkey_cont}, //reverse
1008 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_info_cont}, //list
1009 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_create_cont}, //create
1010 // {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, &namestore_edit_cont}, //update. TODO this shoul be PATCH
1011 {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete_cont}, //delete
1012 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont},
1013 GNUNET_REST_HANDLER_END
1014 };
1015
1016 handle->ego_lookup = NULL;
1017 if (NULL == ego)
1018 {
1019 if (NULL != handle->ego_name)
1020 {
1021 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1022 _("Ego `%s' not known to identity service\n"),
1023 handle->ego_name);
1024 }
1025 resp = GNUNET_REST_create_response (NULL);
1026 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
1027 cleanup_handle (handle);
1028 return;
1029 }
1030 handle->zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
1031 handle->ns_handle = GNUNET_NAMESTORE_connect (cfg);
1032 if (NULL == handle->ns_handle)
1033 {
1034 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1035 _("Failed to connect to namestore\n"));
1036 GNUNET_SCHEDULER_add_now (&do_error, handle);
1037 return;
1038 }
1039
1040 if (GNUNET_OK !=
1041 GNUNET_JSONAPI_handle_request (handle->rest_handle,
1042 handlers,
1043 &err,
1044 handle))
1045 {
1046 handle->response_code = err.error_code;
1047 GNUNET_SCHEDULER_add_now (&do_error,
1048 (void *) handle);
1049 }
1050}
1051
1052
1053static void
1054default_ego_cb (void *cls,
1055 struct GNUNET_IDENTITY_Ego *ego,
1056 void **ctx,
1057 const char *name)
1058{
1059 struct RequestHandle *handle = cls;
1060 struct MHD_Response *resp;
1061 handle->get_default = NULL;
1062 if (NULL == ego)
1063 {
1064 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1065 _("No default ego configured in identity service\n"));
1066 resp = GNUNET_REST_create_response (NULL);
1067 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
1068 cleanup_handle (handle);
1069 return;
1070 }
1071 else
1072 {
1073 identity_cb (cls, ego);
1074 }
1075}
1076
1077static void
1078id_connect_cb (void *cls,
1079 struct GNUNET_IDENTITY_Ego *ego,
1080 void **ctx,
1081 const char *name)
1082{
1083 struct RequestHandle *handle = cls;
1084 if (NULL == ego)
1085 {
1086 handle->get_default = GNUNET_IDENTITY_get (handle->identity_handle,
1087 "namestore",
1088 &default_ego_cb, handle);
1089 }
1090}
1091
1092
1093/**
1094 * Function processing the REST call
1095 *
1096 * @param method HTTP method
1097 * @param url URL of the HTTP request
1098 * @param data body of the HTTP request (optional)
1099 * @param data_size length of the body
1100 * @param proc callback function for the result
1101 * @param proc_cls closure for callback function
1102 * @return #GNUNET_OK if request accepted
1103 */
1104static void
1105rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
1106 GNUNET_REST_ResultProcessor proc,
1107 void *proc_cls)
1108{
1109 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1110 struct MHD_Response *resp;
1111 struct GNUNET_HashCode key;
1112 char *ego;
1113 char *name;
1114 char *type;
1115
1116 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1117 handle->proc_cls = proc_cls;
1118 handle->proc = proc;
1119 handle->rest_handle = rest_handle;
1120 handle->url = GNUNET_strdup (rest_handle->url);
1121 if (handle->url[strlen (handle->url)-1] == '/')
1122 handle->url[strlen (handle->url)-1] = '\0';
1123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1124 "Connecting...\n");
1125 handle->cfg = cfg;
1126 ego = NULL;
1127 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_EGO,
1128 strlen (GNUNET_REST_JSONAPI_NAMESTORE_EGO),
1129 &key);
1130 if ( GNUNET_YES ==
1131 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map,
1132 &key) )
1133 {
1134 ego = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map,
1135 &key);
1136 }
1137
1138 handle->type = GNUNET_GNSRECORD_TYPE_ANY;
1139 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE,
1140 strlen (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE),
1141 &key);
1142 if ( GNUNET_YES ==
1143 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map,
1144 &key) )
1145 {
1146 type = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map,
1147 &key);
1148 if (NULL != type)
1149 handle->type = GNUNET_GNSRECORD_typename_to_number (type);
1150 }
1151 name = get_name_from_url (handle->url);
1152 if (NULL != ego)
1153 handle->ego_name = GNUNET_strdup (ego);
1154 if (NULL != name)
1155 handle->name = GNUNET_strdup (name);
1156 if (NULL == handle->ego_name)
1157 {
1158 handle->identity_handle = GNUNET_IDENTITY_connect (handle->cfg, &id_connect_cb, handle);
1159 if (NULL == handle->identity_handle)
1160 {
1161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Cannot connect to identity service\n"));
1162 resp = GNUNET_REST_create_response (NULL);
1163 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
1164 cleanup_handle (handle);
1165 }
1166 return;
1167 }
1168 handle->ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg,
1169 handle->ego_name,
1170 &identity_cb,
1171 handle);
1172 handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout,
1173 &do_timeout,
1174 handle);
1175}
1176
1177/**
1178 * Entry point for the plugin.
1179 *
1180 * @param cls Config info
1181 * @return NULL on error, otherwise the plugin context
1182 */
1183void *
1184libgnunet_plugin_rest_namestore_init (void *cls)
1185{
1186 static struct Plugin plugin;
1187 cfg = cls;
1188 struct GNUNET_REST_Plugin *api;
1189
1190 if (NULL != plugin.cfg)
1191 return NULL; /* can only initialize once! */
1192 memset (&plugin, 0, sizeof (struct Plugin));
1193 plugin.cfg = cfg;
1194 api = GNUNET_new (struct GNUNET_REST_Plugin);
1195 api->cls = &plugin;
1196 api->name = GNUNET_REST_API_NS_NAMESTORE;
1197 api->process_request = &rest_identity_process_request;
1198 GNUNET_asprintf (&allow_methods,
1199 "%s, %s, %s, %s, %s",
1200 MHD_HTTP_METHOD_GET,
1201 MHD_HTTP_METHOD_POST,
1202 MHD_HTTP_METHOD_PUT,
1203 MHD_HTTP_METHOD_DELETE,
1204 MHD_HTTP_METHOD_OPTIONS);
1205 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1206 _("Namestore REST API initialized\n"));
1207 return api;
1208}
1209
1210
1211/**
1212 * Exit point from the plugin.
1213 *
1214 * @param cls the plugin context (as returned by "init")
1215 * @return always NULL
1216 */
1217void *
1218libgnunet_plugin_rest_namestore_done (void *cls)
1219{
1220 struct GNUNET_REST_Plugin *api = cls;
1221 struct Plugin *plugin = api->cls;
1222
1223 plugin->cfg = NULL;
1224 GNUNET_free (api);
1225 GNUNET_free_non_null (allow_methods);
1226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1227 "Namestore REST plugin is finished\n");
1228 return NULL;
1229}
1230
1231/* end of plugin_rest_namestore.c */
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf
index 29ff90b5d..3e75c2ded 100644
--- a/src/namestore/test_namestore_api.conf
+++ b/src/namestore/test_namestore_api.conf
@@ -1,26 +1,19 @@
1@INLINE@ ../../contrib/no_forcestart.conf 1@INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf
2@INLINE@ ../../contrib/no_autostart_above_core.conf 2@INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf
3 3
4[PATHS] 4[PATHS]
5GNUNET_TEST_HOME = /tmp/test-gnunet-namestore/ 5GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-namestore/
6 6
7[namestore] 7[namestore]
8DATABASE = sqlite 8DATABASE = sqlite
9AUTOSTART = YES 9START_ON_DEMAND = YES
10 10
11[namecache] 11[namecache]
12DATABASE = sqlite 12DATABASE = sqlite
13AUTOSTART = YES 13START_ON_DEMAND = YES
14 14
15[identity] 15[identity]
16AUTOSTART = YES 16START_ON_DEMAND = YES
17
18[namestore-sqlite]
19FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
20
21[namestore-postgres]
22CONFIG = connect_timeout=10; dbname=gnunetcheck
23TEMPORARY_TABLE = YES
24 17
25[nse] 18[nse]
26WORKBITS = 0 19WORKBITS = 0
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]
4DATABASE = flat 4DATABASE = flat
5
6[namestore-flat]
7FILENAME = $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..1a5a09e47 100644
--- a/src/namestore/test_namestore_api_lookup_nick.c
+++ b/src/namestore/test_namestore_api_lookup_nick.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V. 3 Copyright (C) 2012 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_lookup_nick.c 19 * @file namestore/test_namestore_api_lookup_nick.c
@@ -24,8 +22,9 @@
24#include "platform.h" 22#include "platform.h"
25#include "gnunet_namestore_service.h" 23#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h" 24#include "gnunet_testing_lib.h"
25#include "gnunet_dnsparser_lib.h"
27 26
28#define TEST_RECORD_TYPE 1234 27#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
29 28
30#define TEST_RECORD_DATALEN 123 29#define TEST_RECORD_DATALEN 123
31 30
@@ -52,7 +51,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
52//static const char * name = "dummy.dummy.gnunet"; 51//static const char * name = "dummy.dummy.gnunet";
53static const char * name = "d"; 52static const char * name = "d";
54 53
55static char *directory;
56 54
57static void 55static void
58cleanup () 56cleanup ()
@@ -283,29 +281,22 @@ run (void *cls,
283 const struct GNUNET_CONFIGURATION_Handle *cfg, 281 const struct GNUNET_CONFIGURATION_Handle *cfg,
284 struct GNUNET_TESTING_Peer *peer) 282 struct GNUNET_TESTING_Peer *peer)
285{ 283{
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, 284 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
294 &endbadly, NULL); 285 &endbadly,
295 GNUNET_asprintf (&hostkey_file, 286 NULL);
296 "zonefiles%s%s", 287 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); 288 GNUNET_assert (privkey != NULL);
303 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 289 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
290 &pubkey);
304 291
305 nsh = GNUNET_NAMESTORE_connect (cfg); 292 nsh = GNUNET_NAMESTORE_connect (cfg);
306 GNUNET_break (NULL != nsh); 293 GNUNET_break (NULL != nsh);
307 294
308 nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, TEST_NICK, &nick_cont, (void *) name); 295 nsqe = GNUNET_NAMESTORE_set_nick (nsh,
296 privkey,
297 TEST_NICK,
298 &nick_cont,
299 (void *) name);
309 if (NULL == nsqe) 300 if (NULL == nsqe)
310 { 301 {
311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 302 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -324,6 +315,8 @@ main (int argc, char *argv[])
324 GNUNET_asprintf (&cfg_name, 315 GNUNET_asprintf (&cfg_name,
325 "test_namestore_api_%s.conf", 316 "test_namestore_api_%s.conf",
326 plugin_name); 317 plugin_name);
318 GNUNET_DISK_purge_cfg_dir (cfg_name,
319 "GNUNET_TEST_HOME");
327 res = 1; 320 res = 1;
328 if (0 != 321 if (0 !=
329 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick", 322 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick",
@@ -333,12 +326,9 @@ main (int argc, char *argv[])
333 { 326 {
334 res = 1; 327 res = 1;
335 } 328 }
329 GNUNET_DISK_purge_cfg_dir (cfg_name,
330 "GNUNET_TEST_HOME");
336 GNUNET_free (cfg_name); 331 GNUNET_free (cfg_name);
337 if (NULL != directory)
338 {
339 GNUNET_DISK_directory_remove (directory);
340 GNUNET_free (directory);
341 }
342 return res; 332 return res;
343} 333}
344 334
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c
index 7866749f1..024adaa43 100644
--- a/src/namestore/test_namestore_api_lookup_private.c
+++ b/src/namestore/test_namestore_api_lookup_private.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V. 3 Copyright (C) 2012 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_store.c 19 * @file namestore/test_namestore_api_store.c
@@ -24,8 +22,9 @@
24#include "platform.h" 22#include "platform.h"
25#include "gnunet_namestore_service.h" 23#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h" 24#include "gnunet_testing_lib.h"
25#include "gnunet_dnsparser_lib.h"
27 26
28#define TEST_RECORD_TYPE 1234 27#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
29 28
30#define TEST_RECORD_DATALEN 123 29#define TEST_RECORD_DATALEN 123
31 30
@@ -48,7 +47,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
48//static const char * name = "dummy.dummy.gnunet"; 47//static const char * name = "dummy.dummy.gnunet";
49static const char * name = "d"; 48static const char * name = "d";
50 49
51static char *directory;
52 50
53static void 51static void
54cleanup () 52cleanup ()
@@ -71,11 +69,11 @@ cleanup ()
71 * Re-establish the connection to the service. 69 * Re-establish the connection to the service.
72 * 70 *
73 * @param cls handle to use to re-connect. 71 * @param cls handle to use to re-connect.
74 * @param tc scheduler context
75 */ 72 */
76static void 73static void
77endbadly (void *cls) 74endbadly (void *cls)
78{ 75{
76 endbadly_task = NULL;
79 if (NULL != nsqe) 77 if (NULL != nsqe)
80 { 78 {
81 GNUNET_NAMESTORE_cancel (nsqe); 79 GNUNET_NAMESTORE_cancel (nsqe);
@@ -109,7 +107,7 @@ lookup_it (void *cls,
109 { 107 {
110 GNUNET_break(0); 108 GNUNET_break(0);
111 GNUNET_SCHEDULER_cancel (endbadly_task); 109 GNUNET_SCHEDULER_cancel (endbadly_task);
112 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 110 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
113 return; 111 return;
114 } 112 }
115 113
@@ -118,7 +116,7 @@ lookup_it (void *cls,
118 { 116 {
119 GNUNET_break(0); 117 GNUNET_break(0);
120 GNUNET_SCHEDULER_cancel (endbadly_task); 118 GNUNET_SCHEDULER_cancel (endbadly_task);
121 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 119 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
122 return; 120 return;
123 } 121 }
124 122
@@ -126,7 +124,7 @@ lookup_it (void *cls,
126 { 124 {
127 GNUNET_break(0); 125 GNUNET_break(0);
128 GNUNET_SCHEDULER_cancel (endbadly_task); 126 GNUNET_SCHEDULER_cancel (endbadly_task);
129 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 127 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
130 return; 128 return;
131 } 129 }
132 130
@@ -134,14 +132,14 @@ lookup_it (void *cls,
134 { 132 {
135 GNUNET_break(0); 133 GNUNET_break(0);
136 GNUNET_SCHEDULER_cancel (endbadly_task); 134 GNUNET_SCHEDULER_cancel (endbadly_task);
137 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 135 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
138 return; 136 return;
139 } 137 }
140 138
141 /* Done */ 139 /* Done */
142 GNUNET_SCHEDULER_cancel (endbadly_task); 140 GNUNET_SCHEDULER_cancel (endbadly_task);
143 endbadly_task = NULL; 141 endbadly_task = NULL;
144 GNUNET_SCHEDULER_add_now (&end, NULL ); 142 GNUNET_SCHEDULER_add_now (&end, NULL);
145} 143}
146 144
147 145
@@ -153,7 +151,9 @@ fail_cb (void *cls)
153 151
154 152
155static void 153static void
156put_cont (void *cls, int32_t success, const char *emsg) 154put_cont (void *cls,
155 int32_t success,
156 const char *emsg)
157{ 157{
158 const char *name = cls; 158 const char *name = cls;
159 159
@@ -187,22 +187,11 @@ run (void *cls,
187 struct GNUNET_TESTING_Peer *peer) 187 struct GNUNET_TESTING_Peer *peer)
188{ 188{
189 struct GNUNET_GNSRECORD_Data rd; 189 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 190
197 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 191 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
198 &endbadly, NULL); 192 &endbadly,
199 GNUNET_asprintf (&hostkey_file, 193 NULL);
200 "zonefiles%s%s", 194 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); 195 GNUNET_assert (privkey != NULL);
207 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 196 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
208 197
@@ -215,8 +204,13 @@ run (void *cls,
215 204
216 nsh = GNUNET_NAMESTORE_connect (cfg); 205 nsh = GNUNET_NAMESTORE_connect (cfg);
217 GNUNET_break (NULL != nsh); 206 GNUNET_break (NULL != nsh);
218 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 207 nsqe = GNUNET_NAMESTORE_records_store (nsh,
219 1, &rd, &put_cont, (void *) name); 208 privkey,
209 name,
210 1,
211 &rd,
212 &put_cont,
213 (void *) name);
220 if (NULL == nsqe) 214 if (NULL == nsqe)
221 { 215 {
222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 216 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -237,6 +231,8 @@ main (int argc, char *argv[])
237 GNUNET_asprintf (&cfg_name, 231 GNUNET_asprintf (&cfg_name,
238 "test_namestore_api_%s.conf", 232 "test_namestore_api_%s.conf",
239 plugin_name); 233 plugin_name);
234 GNUNET_DISK_purge_cfg_dir (cfg_name,
235 "GNUNET_TEST_HOME");
240 res = 1; 236 res = 1;
241 if (0 != 237 if (0 !=
242 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private", 238 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private",
@@ -246,12 +242,9 @@ main (int argc, char *argv[])
246 { 242 {
247 res = 1; 243 res = 1;
248 } 244 }
245 GNUNET_DISK_purge_cfg_dir (cfg_name,
246 "GNUNET_TEST_HOME");
249 GNUNET_free (cfg_name); 247 GNUNET_free (cfg_name);
250 if (NULL != directory)
251 {
252 GNUNET_DISK_directory_remove (directory);
253 GNUNET_free (directory);
254 }
255 return res; 248 return res;
256} 249}
257 250
diff --git a/src/namestore/test_namestore_api_lookup_public.c b/src/namestore/test_namestore_api_lookup_public.c
index 02ca16042..63cd7662e 100644
--- a/src/namestore/test_namestore_api_lookup_public.c
+++ b/src/namestore/test_namestore_api_lookup_public.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V. 3 Copyright (C) 2012 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api.c 19 * @file namestore/test_namestore_api.c
@@ -25,8 +23,9 @@
25#include "gnunet_namecache_service.h" 23#include "gnunet_namecache_service.h"
26#include "gnunet_namestore_service.h" 24#include "gnunet_namestore_service.h"
27#include "gnunet_testing_lib.h" 25#include "gnunet_testing_lib.h"
26#include "gnunet_dnsparser_lib.h"
28 27
29#define TEST_RECORD_TYPE 1234 28#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
30 29
31#define TEST_RECORD_DATALEN 123 30#define TEST_RECORD_DATALEN 123
32 31
@@ -51,7 +50,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
51 50
52static struct GNUNET_NAMECACHE_QueueEntry *ncqe; 51static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
53 52
54static char *directory;
55 53
56static void 54static void
57cleanup () 55cleanup ()
@@ -190,26 +188,15 @@ run (void *cls,
190 struct GNUNET_TESTING_Peer *peer) 188 struct GNUNET_TESTING_Peer *peer)
191{ 189{
192 struct GNUNET_GNSRECORD_Data rd; 190 struct GNUNET_GNSRECORD_Data rd;
193 char *hostkey_file;
194 const char * name = "dummy.dummy.gnunet"; 191 const char * name = "dummy.dummy.gnunet";
195 192
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, 193 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
202 &endbadly, NULL); 194 &endbadly,
203 GNUNET_asprintf (&hostkey_file, 195 NULL);
204 "zonefiles%s%s", 196 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); 197 GNUNET_assert (privkey != NULL);
211 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 198 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
212 199 &pubkey);
213 200
214 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 201 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
215 rd.record_type = TEST_RECORD_TYPE; 202 rd.record_type = TEST_RECORD_TYPE;
@@ -244,6 +231,8 @@ main (int argc, char *argv[])
244 GNUNET_asprintf (&cfg_name, 231 GNUNET_asprintf (&cfg_name,
245 "test_namestore_api_%s.conf", 232 "test_namestore_api_%s.conf",
246 plugin_name); 233 plugin_name);
234 GNUNET_DISK_purge_cfg_dir (cfg_name,
235 "GNUNET_TEST_HOME");
247 res = 1; 236 res = 1;
248 if (0 != 237 if (0 !=
249 GNUNET_TESTING_peer_run ("test-namestore-api", 238 GNUNET_TESTING_peer_run ("test-namestore-api",
@@ -253,12 +242,9 @@ main (int argc, char *argv[])
253 { 242 {
254 res = 1; 243 res = 1;
255 } 244 }
245 GNUNET_DISK_purge_cfg_dir (cfg_name,
246 "GNUNET_TEST_HOME");
256 GNUNET_free (cfg_name); 247 GNUNET_free (cfg_name);
257 if (NULL != directory)
258 {
259 GNUNET_DISK_directory_remove (directory);
260 GNUNET_free (directory);
261 }
262 return res; 248 return res;
263} 249}
264 250
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c b/src/namestore/test_namestore_api_lookup_shadow.c
index e80335796..08977712b 100644
--- a/src/namestore/test_namestore_api_lookup_shadow.c
+++ b/src/namestore/test_namestore_api_lookup_shadow.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V. 3 Copyright (C) 2012 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_lookup_shadow.c 19 * @file namestore/test_namestore_api_lookup_shadow.c
@@ -27,8 +25,9 @@
27#include "gnunet_namecache_service.h" 25#include "gnunet_namecache_service.h"
28#include "gnunet_namestore_service.h" 26#include "gnunet_namestore_service.h"
29#include "gnunet_testing_lib.h" 27#include "gnunet_testing_lib.h"
28#include "gnunet_dnsparser_lib.h"
30 29
31#define TEST_RECORD_TYPE 1234 30#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
32 31
33#define TEST_RECORD_DATALEN 123 32#define TEST_RECORD_DATALEN 123
34 33
@@ -53,7 +52,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
53 52
54static struct GNUNET_NAMECACHE_QueueEntry *ncqe; 53static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
55 54
56static char *directory;
57 55
58static void 56static void
59cleanup () 57cleanup ()
@@ -222,26 +220,15 @@ run (void *cls,
222 struct GNUNET_TESTING_Peer *peer) 220 struct GNUNET_TESTING_Peer *peer)
223{ 221{
224 struct GNUNET_GNSRECORD_Data rd; 222 struct GNUNET_GNSRECORD_Data rd;
225 char *hostkey_file;
226 const char * name = "dummy.dummy.gnunet"; 223 const char * name = "dummy.dummy.gnunet";
227 224
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, 225 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
234 &endbadly, NULL); 226 &endbadly,
235 GNUNET_asprintf (&hostkey_file, 227 NULL);
236 "zonefiles%s%s", 228 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); 229 GNUNET_assert (privkey != NULL);
243 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 230 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
244 231 &pubkey);
245 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 232 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
246 rd.record_type = TEST_RECORD_TYPE; 233 rd.record_type = TEST_RECORD_TYPE;
247 rd.data_size = TEST_RECORD_DATALEN; 234 rd.data_size = TEST_RECORD_DATALEN;
@@ -253,8 +240,13 @@ run (void *cls,
253 nch = GNUNET_NAMECACHE_connect (cfg); 240 nch = GNUNET_NAMECACHE_connect (cfg);
254 GNUNET_break (NULL != nsh); 241 GNUNET_break (NULL != nsh);
255 GNUNET_break (NULL != nch); 242 GNUNET_break (NULL != nch);
256 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 243 nsqe = GNUNET_NAMESTORE_records_store (nsh,
257 1, &rd, &put_cont, (void *) name); 244 privkey,
245 name,
246 1,
247 &rd,
248 &put_cont,
249 (void *) name);
258 if (NULL == nsqe) 250 if (NULL == nsqe)
259 { 251 {
260 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 252 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -274,6 +266,8 @@ main (int argc, char *argv[])
274 GNUNET_asprintf (&cfg_name, 266 GNUNET_asprintf (&cfg_name,
275 "test_namestore_api_%s.conf", 267 "test_namestore_api_%s.conf",
276 plugin_name); 268 plugin_name);
269 GNUNET_DISK_purge_cfg_dir (cfg_name,
270 "GNUNET_TEST_HOME");
277 res = 1; 271 res = 1;
278 if (0 != 272 if (0 !=
279 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow", 273 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow",
@@ -283,12 +277,9 @@ main (int argc, char *argv[])
283 { 277 {
284 res = 1; 278 res = 1;
285 } 279 }
280 GNUNET_DISK_purge_cfg_dir (cfg_name,
281 "GNUNET_TEST_HOME");
286 GNUNET_free (cfg_name); 282 GNUNET_free (cfg_name);
287 if (NULL != directory)
288 {
289 GNUNET_DISK_directory_remove (directory);
290 GNUNET_free (directory);
291 }
292 return res; 283 return res;
293} 284}
294 285
diff --git a/src/namestore/test_namestore_api_lookup_shadow_filter.c b/src/namestore/test_namestore_api_lookup_shadow_filter.c
index 5b8811a23..7555f51e7 100644
--- a/src/namestore/test_namestore_api_lookup_shadow_filter.c
+++ b/src/namestore/test_namestore_api_lookup_shadow_filter.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V. 3 Copyright (C) 2012 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_lookup_shadow_filter.c 19 * @file namestore/test_namestore_api_lookup_shadow_filter.c
@@ -28,9 +26,11 @@
28#include "gnunet_namecache_service.h" 26#include "gnunet_namecache_service.h"
29#include "gnunet_namestore_service.h" 27#include "gnunet_namestore_service.h"
30#include "gnunet_testing_lib.h" 28#include "gnunet_testing_lib.h"
29#include "gnunet_dnsparser_lib.h"
30
31#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
31 32
32#define TEST_NAME "dummy.dummy.gnunet" 33#define TEST_NAME "dummy.dummy.gnunet"
33#define TEST_RECORD_TYPE 1234
34#define TEST_RECORD_DATALEN 123 34#define TEST_RECORD_DATALEN 123
35#define TEST_RECORD_DATA 'a' 35#define TEST_RECORD_DATA 'a'
36#define TEST_SHADOW_RECORD_DATA 'b' 36#define TEST_SHADOW_RECORD_DATA 'b'
@@ -66,7 +66,6 @@ static struct GNUNET_HashCode derived_hash;
66 66
67static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; 67static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
68 68
69static char *directory;
70 69
71static void 70static void
72cleanup () 71cleanup ()
@@ -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",
@@ -361,12 +352,9 @@ main (int argc, char *argv[])
361 { 352 {
362 res = 1; 353 res = 1;
363 } 354 }
355 GNUNET_DISK_purge_cfg_dir (cfg_name,
356 "GNUNET_TEST_HOME");
364 GNUNET_free (cfg_name); 357 GNUNET_free (cfg_name);
365 if (NULL != directory)
366 {
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 f6d4fe226..1051e3248 100644
--- a/src/namestore/test_namestore_api_monitoring.c
+++ b/src/namestore/test_namestore_api_monitoring.c
@@ -1,21 +1,19 @@
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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_monitoring.c 19 * @file namestore/test_namestore_api_monitoring.c
@@ -25,6 +23,10 @@
25#include "gnunet_namestore_service.h" 23#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h" 24#include "gnunet_testing_lib.h"
27#include "namestore.h" 25#include "namestore.h"
26#include "gnunet_dnsparser_lib.h"
27
28#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
29
28 30
29 31
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
@@ -56,7 +58,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
56 58
57struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; 59struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
58 60
59static char *directory;
60 61
61static void 62static void
62do_shutdown () 63do_shutdown ()
@@ -66,7 +67,6 @@ do_shutdown ()
66 GNUNET_NAMESTORE_zone_monitor_stop (zm); 67 GNUNET_NAMESTORE_zone_monitor_stop (zm);
67 zm = NULL; 68 zm = NULL;
68 } 69 }
69
70 if (NULL != ns_ops[0]) 70 if (NULL != ns_ops[0])
71 { 71 {
72 GNUNET_NAMESTORE_cancel(ns_ops[0]); 72 GNUNET_NAMESTORE_cancel(ns_ops[0]);
@@ -82,13 +82,11 @@ do_shutdown ()
82 GNUNET_NAMESTORE_cancel(ns_ops[2]); 82 GNUNET_NAMESTORE_cancel(ns_ops[2]);
83 ns_ops[2] = NULL; 83 ns_ops[2] = NULL;
84 } 84 }
85
86 if (NULL != nsh) 85 if (NULL != nsh)
87 { 86 {
88 GNUNET_NAMESTORE_disconnect (nsh); 87 GNUNET_NAMESTORE_disconnect (nsh);
89 nsh = NULL; 88 nsh = NULL;
90 } 89 }
91
92 GNUNET_free_non_null(s_name_1); 90 GNUNET_free_non_null(s_name_1);
93 GNUNET_free_non_null(s_name_2); 91 GNUNET_free_non_null(s_name_2);
94 GNUNET_free_non_null(s_name_3); 92 GNUNET_free_non_null(s_name_3);
@@ -192,7 +190,8 @@ zone_proc (void *cls,
192 GNUNET_break (0); 190 GNUNET_break (0);
193 fail = GNUNET_YES; 191 fail = GNUNET_YES;
194 } 192 }
195 193 GNUNET_NAMESTORE_zone_monitor_next (zm,
194 1);
196 if (2 == ++returned_records) 195 if (2 == ++returned_records)
197 { 196 {
198 if (endbadly_task != NULL) 197 if (endbadly_task != NULL)
@@ -247,14 +246,14 @@ put_cont (void *cls,
247static struct GNUNET_GNSRECORD_Data * 246static struct GNUNET_GNSRECORD_Data *
248create_record (unsigned int count) 247create_record (unsigned int count)
249{ 248{
250 unsigned int c; 249 struct GNUNET_GNSRECORD_Data *rd;
251 struct GNUNET_GNSRECORD_Data * rd;
252 250
253 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 251 rd = GNUNET_new_array (count,
254 for (c = 0; c < count; c++) 252 struct GNUNET_GNSRECORD_Data);
253 for (unsigned int c = 0; c < count; c++)
255 { 254 {
256 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 255 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
257 rd[c].record_type = 1111; 256 rd[c].record_type = TEST_RECORD_TYPE;
258 rd[c].data_size = 50; 257 rd[c].data_size = 50;
259 rd[c].data = GNUNET_malloc(50); 258 rd[c].data = GNUNET_malloc(50);
260 rd[c].flags = 0; 259 rd[c].flags = 0;
@@ -283,23 +282,8 @@ 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 res = 1; 285 res = 1;
289 286 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
290 directory = NULL;
291 GNUNET_assert (GNUNET_OK ==
292 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
293 GNUNET_DISK_directory_remove (directory);
294
295 GNUNET_asprintf(&hostkey_file,
296 "zonefiles%s%s",
297 DIR_SEPARATOR_STR,
298 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
300 "Using zonekey file `%s' \n", hostkey_file);
301 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
302 GNUNET_free (hostkey_file);
303 GNUNET_assert (privkey != NULL); 287 GNUNET_assert (privkey != NULL);
304 288
305 /* Start monitoring */ 289 /* Start monitoring */
@@ -332,16 +316,12 @@ run (void *cls,
332 return; 316 return;
333 } 317 }
334 318
335 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s", 319 privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
336 DIR_SEPARATOR_STR,
337 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
339 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
340 GNUNET_free (hostkey_file);
341 GNUNET_assert (privkey2 != NULL); 320 GNUNET_assert (privkey2 != NULL);
342 321
343 322
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); 323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
324 "Created record 3\n");
345 /* name in different zone */ 325 /* name in different zone */
346 GNUNET_asprintf(&s_name_3, "dummy3"); 326 GNUNET_asprintf(&s_name_3, "dummy3");
347 s_rd_3 = create_record(1); 327 s_rd_3 = create_record(1);
@@ -357,22 +337,33 @@ run (void *cls,
357 "Created record 1\n"); 337 "Created record 1\n");
358 GNUNET_asprintf(&s_name_1, "dummy1"); 338 GNUNET_asprintf(&s_name_1, "dummy1");
359 s_rd_1 = create_record(1); 339 s_rd_1 = create_record(1);
360 GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, 340 GNUNET_assert (NULL != (ns_ops[0] =
361 1, s_rd_1, &put_cont, s_name_1))); 341 GNUNET_NAMESTORE_records_store (nsh,
342 privkey,
343 s_name_1,
344 1,
345 s_rd_1,
346 &put_cont,
347 s_name_1)));
362 348
363 349
364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); 350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
365 GNUNET_asprintf(&s_name_2, "dummy2"); 351 GNUNET_asprintf(&s_name_2, "dummy2");
366 s_rd_2 = create_record(1); 352 s_rd_2 = create_record(1);
367 GNUNET_assert (NULL != (ns_ops[1] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, 353 GNUNET_assert (NULL != (ns_ops[1] =
368 1, s_rd_2, &put_cont, s_name_2))); 354 GNUNET_NAMESTORE_records_store (nsh,
369 355 privkey,
370 356 s_name_2,
357 1,
358 s_rd_2,
359 &put_cont,
360 s_name_2)));
371} 361}
372 362
373 363
374int 364int
375main (int argc, char *argv[]) 365main (int argc,
366 char *argv[])
376{ 367{
377 const char *plugin_name; 368 const char *plugin_name;
378 char *cfg_name; 369 char *cfg_name;
@@ -381,6 +372,8 @@ main (int argc, char *argv[])
381 GNUNET_asprintf (&cfg_name, 372 GNUNET_asprintf (&cfg_name,
382 "test_namestore_api_%s.conf", 373 "test_namestore_api_%s.conf",
383 plugin_name); 374 plugin_name);
375 GNUNET_DISK_purge_cfg_dir (cfg_name,
376 "GNUNET_TEST_HOME");
384 res = 1; 377 res = 1;
385 if (0 != 378 if (0 !=
386 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring", 379 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring",
@@ -390,12 +383,9 @@ main (int argc, char *argv[])
390 { 383 {
391 res = 1; 384 res = 1;
392 } 385 }
386 GNUNET_DISK_purge_cfg_dir (cfg_name,
387 "GNUNET_TEST_HOME");
393 GNUNET_free (cfg_name); 388 GNUNET_free (cfg_name);
394 if (NULL != directory)
395 {
396 GNUNET_DISK_directory_remove (directory);
397 GNUNET_free (directory);
398 }
399 return res; 389 return res;
400} 390}
401 391
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c
index 17f726eb1..9c8ddf7ad 100644
--- a/src/namestore/test_namestore_api_monitoring_existing.c
+++ b/src/namestore/test_namestore_api_monitoring_existing.c
@@ -1,33 +1,34 @@
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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_monitoring.c 19 * @file namestore/test_namestore_api_monitoring_existing.c
22 * @brief testcase for zone monitoring functionality: add records first, then monitor 20 * @brief testcase for zone monitoring functionality: add records first, then monitor
23 */ 21 */
24#include "platform.h" 22#include "platform.h"
25#include "gnunet_namestore_service.h" 23#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h" 24#include "gnunet_testing_lib.h"
27#include "namestore.h" 25#include "namestore.h"
26#include "gnunet_dnsparser_lib.h"
27
28#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
28 29
29 30
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
31 32
32static const struct GNUNET_CONFIGURATION_Handle *cfg; 33static const struct GNUNET_CONFIGURATION_Handle *cfg;
33 34
@@ -57,18 +58,30 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
57 58
58struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; 59struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
59 60
60static char *directory; 61
62/**
63 * Re-establish the connection to the service.
64 *
65 * @param cls handle to use to re-connect.
66 */
67static void
68endbadly (void *cls)
69{
70 endbadly_task = NULL;
71 GNUNET_break (0);
72 GNUNET_SCHEDULER_shutdown ();
73 res = 1;
74}
61 75
62 76
63static void 77static void
64do_shutdown () 78end (void *cls)
65{ 79{
66 if (NULL != zm) 80 if (NULL != zm)
67 { 81 {
68 GNUNET_NAMESTORE_zone_monitor_stop (zm); 82 GNUNET_NAMESTORE_zone_monitor_stop (zm);
69 zm = NULL; 83 zm = NULL;
70 } 84 }
71
72 if (NULL != ns_ops[0]) 85 if (NULL != ns_ops[0])
73 { 86 {
74 GNUNET_NAMESTORE_cancel(ns_ops[0]); 87 GNUNET_NAMESTORE_cancel(ns_ops[0]);
@@ -84,7 +97,11 @@ do_shutdown ()
84 GNUNET_NAMESTORE_cancel(ns_ops[2]); 97 GNUNET_NAMESTORE_cancel(ns_ops[2]);
85 ns_ops[2] = NULL; 98 ns_ops[2] = NULL;
86 } 99 }
87 100 if (NULL != endbadly_task)
101 {
102 GNUNET_SCHEDULER_cancel (endbadly_task);
103 endbadly_task = NULL;
104 }
88 if (NULL != nsh) 105 if (NULL != nsh)
89 { 106 {
90 GNUNET_NAMESTORE_disconnect (nsh); 107 GNUNET_NAMESTORE_disconnect (nsh);
@@ -124,27 +141,6 @@ do_shutdown ()
124} 141}
125 142
126 143
127/**
128 * Re-establish the connection to the service.
129 *
130 * @param cls handle to use to re-connect.
131 */
132static void
133endbadly (void *cls)
134{
135 do_shutdown ();
136 res = 1;
137}
138
139
140static void
141end (void *cls)
142{
143 do_shutdown ();
144 res = 0;
145}
146
147
148static void 144static void
149zone_proc (void *cls, 145zone_proc (void *cls,
150 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 146 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
@@ -159,19 +155,22 @@ zone_proc (void *cls,
159 "Comparing results name %s\n", 155 "Comparing results name %s\n",
160 name); 156 name);
161 157
162 if (0 != memcmp (zone_key, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 158 if (0 != memcmp (zone_key,
159 privkey,
160 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
163 { 161 {
164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
165 "Monitoring returned wrong zone key\n"); 163 "Monitoring returned wrong zone key\n");
166 GNUNET_break (0); 164 GNUNET_break (0);
167 GNUNET_SCHEDULER_cancel (endbadly_task); 165 GNUNET_SCHEDULER_shutdown ();
168 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
169 return; 166 return;
170 } 167 }
171 168
172 if (0 == strcmp (name, s_name_1)) 169 if (0 == strcmp (name, s_name_1))
173 { 170 {
174 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1)) 171 if (GNUNET_YES !=
172 GNUNET_GNSRECORD_records_cmp (rd,
173 s_rd_1))
175 { 174 {
176 GNUNET_break (0); 175 GNUNET_break (0);
177 fail = GNUNET_YES; 176 fail = GNUNET_YES;
@@ -179,7 +178,9 @@ zone_proc (void *cls,
179 } 178 }
180 else if (0 == strcmp (name, s_name_2)) 179 else if (0 == strcmp (name, s_name_2))
181 { 180 {
182 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2)) 181 if (GNUNET_YES !=
182 GNUNET_GNSRECORD_records_cmp (rd,
183 s_rd_2))
183 { 184 {
184 GNUNET_break (0); 185 GNUNET_break (0);
185 fail = GNUNET_YES; 186 fail = GNUNET_YES;
@@ -192,18 +193,20 @@ zone_proc (void *cls,
192 GNUNET_break (0); 193 GNUNET_break (0);
193 fail = GNUNET_YES; 194 fail = GNUNET_YES;
194 } 195 }
195 196 GNUNET_NAMESTORE_zone_monitor_next (zm,
197 1);
196 if (2 == ++returned_records) 198 if (2 == ++returned_records)
197 { 199 {
198 if (endbadly_task != NULL) 200 GNUNET_SCHEDULER_shutdown ();
201 if (GNUNET_YES == fail)
199 { 202 {
200 GNUNET_SCHEDULER_cancel (endbadly_task); 203 GNUNET_break (0);
201 endbadly_task = NULL; 204 res = 1;
202 } 205 }
203 if (GNUNET_YES == fail)
204 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
205 else 206 else
206 GNUNET_SCHEDULER_add_now (&end, NULL); 207 {
208 res = 0;
209 }
207 } 210 }
208} 211}
209 212
@@ -223,7 +226,9 @@ sync_cb (void *cls)
223 226
224 227
225static void 228static void
226put_cont (void *cls, int32_t success, const char *emsg) 229put_cont (void *cls,
230 int32_t success,
231 const char *emsg)
227{ 232{
228 static int c = 0; 233 static int c = 0;
229 char *label = cls; 234 char *label = cls;
@@ -238,14 +243,19 @@ put_cont (void *cls, int32_t success, const char *emsg)
238 if (success == GNUNET_OK) 243 if (success == GNUNET_OK)
239 { 244 {
240 c++; 245 c++;
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u: `%s'\n", c, label); 246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
247 "Created record %u: `%s'\n",
248 c,
249 label);
242 } 250 }
243 else 251 else
244 { 252 {
245 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records\n"); 253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
254 "Failed to created records\n");
246 GNUNET_break (0); 255 GNUNET_break (0);
247 GNUNET_SCHEDULER_cancel (endbadly_task); 256 res = 1;
248 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 257 GNUNET_SCHEDULER_shutdown ();
258 return;
249 } 259 }
250 260
251 if (3 == c) 261 if (3 == c)
@@ -262,9 +272,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
262 NULL); 272 NULL);
263 if (NULL == zm) 273 if (NULL == zm)
264 { 274 {
265 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone monitor\n"); 275 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
276 "Failed to create zone monitor\n");
266 GNUNET_break (0); 277 GNUNET_break (0);
267 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 278 res = 1;
279 GNUNET_SCHEDULER_shutdown ();
268 return; 280 return;
269 } 281 }
270 } 282 }
@@ -281,7 +293,7 @@ create_record (unsigned int count)
281 for (unsigned int c = 0; c < count; c++) 293 for (unsigned int c = 0; c < count; c++)
282 { 294 {
283 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 295 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
284 rd[c].record_type = 1111; 296 rd[c].record_type = TEST_RECORD_TYPE;
285 rd[c].data_size = 50; 297 rd[c].data_size = 50;
286 rd[c].data = GNUNET_malloc(50); 298 rd[c].data = GNUNET_malloc(50);
287 rd[c].flags = 0; 299 rd[c].flags = 0;
@@ -298,30 +310,16 @@ run (void *cls,
298 const struct GNUNET_CONFIGURATION_Handle *mycfg, 310 const struct GNUNET_CONFIGURATION_Handle *mycfg,
299 struct GNUNET_TESTING_Peer *peer) 311 struct GNUNET_TESTING_Peer *peer)
300{ 312{
301 char *hostkey_file;
302
303 directory = NULL;
304 GNUNET_assert (GNUNET_OK ==
305 GNUNET_CONFIGURATION_get_value_string (mycfg,
306 "PATHS",
307 "GNUNET_TEST_HOME",
308 &directory));
309 GNUNET_DISK_directory_remove (directory);
310
311 res = 1; 313 res = 1;
312 314 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
313 GNUNET_asprintf(&hostkey_file,
314 "zonefiles%s%s",
315 DIR_SEPARATOR_STR,
316 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
318 "Using zonekey file `%s' \n", hostkey_file);
319 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
320 GNUNET_free (hostkey_file);
321 GNUNET_assert (privkey != NULL); 315 GNUNET_assert (privkey != NULL);
322 316
323 cfg = mycfg; 317 cfg = mycfg;
324 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); 318 GNUNET_SCHEDULER_add_shutdown (&end,
319 NULL);
320 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
321 &endbadly,
322 NULL);
325 /* Connect to namestore */ 323 /* Connect to namestore */
326 nsh = GNUNET_NAMESTORE_connect (cfg); 324 nsh = GNUNET_NAMESTORE_connect (cfg);
327 if (NULL == nsh) 325 if (NULL == nsh)
@@ -332,12 +330,7 @@ run (void *cls,
332 return; 330 return;
333 } 331 }
334 332
335 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s", 333 privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
336 DIR_SEPARATOR_STR,
337 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
339 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
340 GNUNET_free (hostkey_file);
341 GNUNET_assert (privkey2 != NULL); 334 GNUNET_assert (privkey2 != NULL);
342 335
343 336
@@ -345,23 +338,39 @@ run (void *cls,
345 /* name in different zone */ 338 /* name in different zone */
346 GNUNET_asprintf(&s_name_3, "dummy3"); 339 GNUNET_asprintf(&s_name_3, "dummy3");
347 s_rd_3 = create_record(1); 340 s_rd_3 = create_record(1);
348 GNUNET_assert (NULL != (ns_ops[2] = GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, 341 GNUNET_assert (NULL != (ns_ops[2] =
349 1, s_rd_3, &put_cont, s_name_3))); 342 GNUNET_NAMESTORE_records_store (nsh,
343 privkey2,
344 s_name_3,
345 1,
346 s_rd_3,
347 &put_cont,
348 s_name_3)));
350 349
351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); 350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
351 "Created record 1\n");
352 GNUNET_asprintf(&s_name_1, "dummy1"); 352 GNUNET_asprintf(&s_name_1, "dummy1");
353 s_rd_1 = create_record(1); 353 s_rd_1 = create_record(1);
354 GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, 354 GNUNET_assert (NULL != (ns_ops[0] =
355 1, s_rd_1, &put_cont, s_name_1))); 355 GNUNET_NAMESTORE_records_store(nsh,
356 356 privkey,
357 357 s_name_1,
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); 358 1,
359 s_rd_1,
360 &put_cont,
361 s_name_1)));
362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
363 "Created record 2 \n");
359 GNUNET_asprintf(&s_name_2, "dummy2"); 364 GNUNET_asprintf(&s_name_2, "dummy2");
360 s_rd_2 = create_record(1); 365 s_rd_2 = create_record(1);
361 GNUNET_assert (NULL != (ns_ops[1] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, 366 GNUNET_assert (NULL != (ns_ops[1] =
362 1, s_rd_2, &put_cont, s_name_2))); 367 GNUNET_NAMESTORE_records_store (nsh,
363 368 privkey,
364 369 s_name_2,
370 1,
371 s_rd_2,
372 &put_cont,
373 s_name_2)));
365} 374}
366 375
367 376
@@ -376,6 +385,8 @@ main (int argc, char *argv[])
376 "test_namestore_api_%s.conf", 385 "test_namestore_api_%s.conf",
377 plugin_name); 386 plugin_name);
378 res = 1; 387 res = 1;
388 GNUNET_DISK_purge_cfg_dir (cfg_name,
389 "GNUNET_TEST_HOME");
379 if (0 != 390 if (0 !=
380 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing", 391 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing",
381 cfg_name, 392 cfg_name,
@@ -384,12 +395,9 @@ main (int argc, char *argv[])
384 { 395 {
385 res = 1; 396 res = 1;
386 } 397 }
398 GNUNET_DISK_purge_cfg_dir (cfg_name,
399 "GNUNET_TEST_HOME");
387 GNUNET_free (cfg_name); 400 GNUNET_free (cfg_name);
388 if (NULL != directory)
389 {
390 GNUNET_DISK_directory_remove (directory);
391 GNUNET_free (directory);
392 }
393 return res; 401 return res;
394} 402}
395 403
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]
4DATABASE = postgres 4DATABASE = postgres
5
6
7[namestore-postgres]
8CONFIG = connect_timeout=10; dbname=gnunetcheck
9TEMPORARY_TABLE = YES
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c
index 532a751da..7d993d4d9 100644
--- a/src/namestore/test_namestore_api_remove.c
+++ b/src/namestore/test_namestore_api_remove.c
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api.c 19 * @file namestore/test_namestore_api.c
@@ -24,8 +22,9 @@
24#include "platform.h" 22#include "platform.h"
25#include "gnunet_namestore_service.h" 23#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h" 24#include "gnunet_testing_lib.h"
25#include "gnunet_dnsparser_lib.h"
27 26
28#define TEST_RECORD_TYPE 1234 27#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
29 28
30#define TEST_RECORD_DATALEN 123 29#define TEST_RECORD_DATALEN 123
31 30
@@ -48,7 +47,6 @@ static int removed;
48 47
49static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 48static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
50 49
51static char *directory;
52 50
53static void 51static void
54cleanup () 52cleanup ()
@@ -157,29 +155,12 @@ run (void *cls,
157 struct GNUNET_TESTING_Peer *peer) 155 struct GNUNET_TESTING_Peer *peer)
158{ 156{
159 struct GNUNET_GNSRECORD_Data rd; 157 struct GNUNET_GNSRECORD_Data rd;
160 char *hostkey_file;
161 const char * name = "dummy.dummy.gnunet"; 158 const char * name = "dummy.dummy.gnunet";
162 159
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, 160 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
172 &endbadly, 161 &endbadly,
173 NULL); 162 NULL);
174 GNUNET_asprintf (&hostkey_file, 163 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); 164 GNUNET_assert (privkey != NULL);
184 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 165 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
185 &pubkey); 166 &pubkey);
@@ -191,12 +172,19 @@ run (void *cls,
191 rd.data_size = TEST_RECORD_DATALEN; 172 rd.data_size = TEST_RECORD_DATALEN;
192 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 173 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
193 rd.flags = 0; 174 rd.flags = 0;
194 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); 175 memset ((char *) rd.data,
176 'a',
177 TEST_RECORD_DATALEN);
195 178
196 nsh = GNUNET_NAMESTORE_connect (cfg); 179 nsh = GNUNET_NAMESTORE_connect (cfg);
197 GNUNET_break (NULL != nsh); 180 GNUNET_break (NULL != nsh);
198 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 181 nsqe = GNUNET_NAMESTORE_records_store (nsh,
199 1, &rd, &put_cont, (void *) name); 182 privkey,
183 name,
184 1,
185 &rd,
186 &put_cont,
187 (void *) name);
200 if (NULL == nsqe) 188 if (NULL == nsqe)
201 { 189 {
202 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -216,6 +204,8 @@ main (int argc, char *argv[])
216 GNUNET_asprintf (&cfg_name, 204 GNUNET_asprintf (&cfg_name,
217 "test_namestore_api_%s.conf", 205 "test_namestore_api_%s.conf",
218 plugin_name); 206 plugin_name);
207 GNUNET_DISK_purge_cfg_dir (cfg_name,
208 "GNUNET_TEST_HOME");
219 res = 1; 209 res = 1;
220 if (0 != 210 if (0 !=
221 GNUNET_TESTING_peer_run ("test-namestore-api-remove", 211 GNUNET_TESTING_peer_run ("test-namestore-api-remove",
@@ -225,12 +215,9 @@ main (int argc, char *argv[])
225 { 215 {
226 res = 1; 216 res = 1;
227 } 217 }
218 GNUNET_DISK_purge_cfg_dir (cfg_name,
219 "GNUNET_TEST_HOME");
228 GNUNET_free (cfg_name); 220 GNUNET_free (cfg_name);
229 if (NULL != directory)
230 {
231 GNUNET_DISK_directory_remove (directory);
232 GNUNET_free (directory);
233 }
234 return res; 221 return res;
235} 222}
236 223
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..a5bd6c8c2 100644
--- a/src/namestore/test_namestore_api_remove_not_existing_record.c
+++ b/src/namestore/test_namestore_api_remove_not_existing_record.c
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_remove_not_existing_record.c 19 * @file namestore/test_namestore_api_remove_not_existing_record.c
@@ -46,7 +44,6 @@ static int res;
46 44
47static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 45static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
48 46
49static char *directory;
50 47
51static void 48static void
52cleanup () 49cleanup ()
@@ -92,7 +89,9 @@ end (void *cls)
92 89
93 90
94static void 91static void
95put_cont (void *cls, int32_t success, const char *emsg) 92put_cont (void *cls,
93 int32_t success,
94 const char *emsg)
96{ 95{
97 GNUNET_assert (NULL != cls); 96 GNUNET_assert (NULL != cls);
98 nsqe = NULL; 97 nsqe = NULL;
@@ -101,8 +100,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
101 GNUNET_SCHEDULER_cancel (endbadly_task); 100 GNUNET_SCHEDULER_cancel (endbadly_task);
102 endbadly_task = NULL; 101 endbadly_task = NULL;
103 } 102 }
104 103 switch (success)
105 switch (success) { 104 {
106 case GNUNET_NO: 105 case GNUNET_NO:
107 /* We expected GNUNET_NO, since record was not found */ 106 /* We expected GNUNET_NO, since record was not found */
108 GNUNET_SCHEDULER_add_now (&end, NULL); 107 GNUNET_SCHEDULER_add_now (&end, NULL);
@@ -129,25 +128,12 @@ run (void *cls,
129 const struct GNUNET_CONFIGURATION_Handle *cfg, 128 const struct GNUNET_CONFIGURATION_Handle *cfg,
130 struct GNUNET_TESTING_Peer *peer) 129 struct GNUNET_TESTING_Peer *peer)
131{ 130{
132 char *hostkey_file;
133 const char * name = "dummy.dummy.gnunet"; 131 const char * name = "dummy.dummy.gnunet";
134 132
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, 133 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
141 &endbadly, NULL); 134 &endbadly,
142 GNUNET_asprintf (&hostkey_file, 135 NULL);
143 "zonefiles%s%s", 136 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); 137 GNUNET_assert (privkey != NULL);
152 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 138 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
153 139
@@ -174,6 +160,8 @@ main (int argc, char *argv[])
174 GNUNET_asprintf (&cfg_name, 160 GNUNET_asprintf (&cfg_name,
175 "test_namestore_api_%s.conf", 161 "test_namestore_api_%s.conf",
176 plugin_name); 162 plugin_name);
163 GNUNET_DISK_purge_cfg_dir (cfg_name,
164 "GNUNET_TEST_HOME");
177 res = 1; 165 res = 1;
178 if (0 != 166 if (0 !=
179 GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record", 167 GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record",
@@ -183,12 +171,9 @@ main (int argc, char *argv[])
183 { 171 {
184 res = 1; 172 res = 1;
185 } 173 }
174 GNUNET_DISK_purge_cfg_dir (cfg_name,
175 "GNUNET_TEST_HOME");
186 GNUNET_free (cfg_name); 176 GNUNET_free (cfg_name);
187 if (NULL != directory)
188 {
189 GNUNET_DISK_directory_remove (directory);
190 GNUNET_free (directory);
191 }
192 return res; 177 return res;
193} 178}
194 179
diff --git a/src/namestore/test_namestore_api_sqlite.conf b/src/namestore/test_namestore_api_sqlite.conf
index 5416daec3..cd4822097 100644
--- a/src/namestore/test_namestore_api_sqlite.conf
+++ b/src/namestore/test_namestore_api_sqlite.conf
@@ -2,3 +2,7 @@
2 2
3[namestore] 3[namestore]
4DATABASE = sqlite 4DATABASE = sqlite
5# PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=/tmp/v_log
6
7[namestore-sqlite]
8FILENAME = $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..61b534781 100644
--- a/src/namestore/test_namestore_api_store.c
+++ b/src/namestore/test_namestore_api_store.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V. 3 Copyright (C) 2012 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_store.c 19 * @file namestore/test_namestore_api_store.c
@@ -24,8 +22,9 @@
24#include "platform.h" 22#include "platform.h"
25#include "gnunet_namestore_service.h" 23#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h" 24#include "gnunet_testing_lib.h"
25#include "gnunet_dnsparser_lib.h"
27 26
28#define TEST_RECORD_TYPE 1234 27#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
29 28
30#define TEST_RECORD_DATALEN 123 29#define TEST_RECORD_DATALEN 123
31 30
@@ -46,7 +45,6 @@ static int res;
46 45
47static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 46static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
48 47
49static char *directory;
50 48
51static void 49static void
52cleanup () 50cleanup ()
@@ -114,23 +112,11 @@ run (void *cls,
114 struct GNUNET_TESTING_Peer *peer) 112 struct GNUNET_TESTING_Peer *peer)
115{ 113{
116 struct GNUNET_GNSRECORD_Data rd; 114 struct GNUNET_GNSRECORD_Data rd;
117 char *hostkey_file;
118 const char * name = "dummy.dummy.gnunet"; 115 const char * name = "dummy.dummy.gnunet";
119 116
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, 117 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
126 &endbadly, NULL); 118 &endbadly, NULL);
127 GNUNET_asprintf (&hostkey_file, 119 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); 120 GNUNET_assert (privkey != NULL);
135 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 121 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
136 122
@@ -144,8 +130,13 @@ run (void *cls,
144 130
145 nsh = GNUNET_NAMESTORE_connect (cfg); 131 nsh = GNUNET_NAMESTORE_connect (cfg);
146 GNUNET_break (NULL != nsh); 132 GNUNET_break (NULL != nsh);
147 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 133 nsqe = GNUNET_NAMESTORE_records_store (nsh,
148 1, &rd, &put_cont, (void *) name); 134 privkey,
135 name,
136 1,
137 &rd,
138 &put_cont,
139 (void *) name);
149 if (NULL == nsqe) 140 if (NULL == nsqe)
150 { 141 {
151 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -167,6 +158,8 @@ main (int argc, char *argv[])
167 "test_namestore_api_%s.conf", 158 "test_namestore_api_%s.conf",
168 plugin_name); 159 plugin_name);
169 res = 1; 160 res = 1;
161 GNUNET_DISK_purge_cfg_dir (cfg_name,
162 "GNUNET_TEST_HOME");
170 if (0 != 163 if (0 !=
171 GNUNET_TESTING_peer_run ("test-namestore-api", 164 GNUNET_TESTING_peer_run ("test-namestore-api",
172 cfg_name, 165 cfg_name,
@@ -175,12 +168,9 @@ main (int argc, char *argv[])
175 { 168 {
176 res = 1; 169 res = 1;
177 } 170 }
171 GNUNET_DISK_purge_cfg_dir (cfg_name,
172 "GNUNET_TEST_HOME");
178 GNUNET_free (cfg_name); 173 GNUNET_free (cfg_name);
179 if (NULL != directory)
180 {
181 GNUNET_DISK_directory_remove (directory);
182 GNUNET_free (directory);
183 }
184 return res; 174 return res;
185} 175}
186 176
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c
index 0a4551f21..bd62fdd4c 100644
--- a/src/namestore/test_namestore_api_store_update.c
+++ b/src/namestore/test_namestore_api_store_update.c
@@ -1,41 +1,38 @@
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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_store_update.c 19 * @file namestore/test_namestore_api_store_update.c
22 * @brief testcase for namestore_api.c: store a record, update it and perform a lookup 20 * @brief testcase for namestore_api.c: store a record, update it and perform a lookup
23 * @author Matthias Wachs 21 * @author Matthias Wachs
22 * @author Christian Grothoff
24 */ 23 */
25#include "platform.h" 24#include "platform.h"
26#include "gnunet_namecache_service.h" 25#include "gnunet_namecache_service.h"
27#include "gnunet_namestore_service.h" 26#include "gnunet_namestore_service.h"
28#include "gnunet_testing_lib.h" 27#include "gnunet_testing_lib.h"
28#include "gnunet_dnsparser_lib.h"
29 29
30#define TEST_RECORD_TYPE 1234 30#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
31 31
32#define TEST_RECORD_DATALEN 123 32#define TEST_RECORD_DATALEN 123
33 33
34#define TEST_RECORD_DATA 'a' 34#define TEST_RECORD_DATA 'a'
35 35
36
37#define TEST_RECORD_TYPE2 4321
38
39#define TEST_RECORD_DATALEN2 234 36#define TEST_RECORD_DATALEN2 234
40 37
41#define TEST_RECORD_DATA2 'b' 38#define TEST_RECORD_DATA2 'b'
@@ -63,38 +60,30 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
63 60
64static const char *name = "dummy"; 61static const char *name = "dummy";
65 62
66static char *directory;
67 63
64/**
65 * Terminate test with error.
66 *
67 * @param cls handle to use to re-connect.
68 */
68static void 69static void
69cleanup () 70endbadly (void *cls)
70{ 71{
71 if (NULL != nsh) 72 GNUNET_break (0);
72 { 73 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 (); 74 GNUNET_SCHEDULER_shutdown ();
75 res = 1;
87} 76}
88 77
89 78
90/**
91 * Re-establish the connection to the service.
92 *
93 * @param cls handle to use to re-connect.
94 */
95static void 79static void
96endbadly (void *cls) 80end (void *cls)
97{ 81{
82 if (NULL != endbadly_task)
83 {
84 GNUNET_SCHEDULER_cancel (endbadly_task);
85 endbadly_task = NULL;
86 }
98 if (NULL != nsqe) 87 if (NULL != nsqe)
99 { 88 {
100 GNUNET_NAMESTORE_cancel (nsqe); 89 GNUNET_NAMESTORE_cancel (nsqe);
@@ -105,21 +94,28 @@ endbadly (void *cls)
105 GNUNET_NAMECACHE_cancel (ncqe); 94 GNUNET_NAMECACHE_cancel (ncqe);
106 ncqe = NULL; 95 ncqe = NULL;
107 } 96 }
108 cleanup (); 97 if (NULL != nsh)
109 res = 1; 98 {
110} 99 GNUNET_NAMESTORE_disconnect (nsh);
111 100 nsh = NULL;
112 101 }
113static void 102 if (NULL != nch)
114end (void *cls) 103 {
115{ 104 GNUNET_NAMECACHE_disconnect (nch);
116 cleanup (); 105 nch = NULL;
117 res = 0; 106 }
107 if (NULL != privkey)
108 {
109 GNUNET_free (privkey);
110 privkey = NULL;
111 }
118} 112}
119 113
120 114
121static void 115static void
122put_cont (void *cls, int32_t success, const char *emsg); 116put_cont (void *cls,
117 int32_t success,
118 const char *emsg);
123 119
124 120
125static void 121static void
@@ -135,38 +131,51 @@ rd_decrypt_cb (void *cls,
135 if (GNUNET_NO == update_performed) 131 if (GNUNET_NO == update_performed)
136 { 132 {
137 char rd_cmp_data[TEST_RECORD_DATALEN]; 133 char rd_cmp_data[TEST_RECORD_DATALEN];
138 memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
139 134
135 memset (rd_cmp_data,
136 TEST_RECORD_DATA,
137 TEST_RECORD_DATALEN);
140 GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); 138 GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type);
141 GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); 139 GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size);
142 GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)); 140 GNUNET_assert (0 == memcmp (&rd_cmp_data,
141 rd[0].data,
142 TEST_RECORD_DATALEN));
143 143
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "Block was decrypted successfully, updating record \n"); 145 "Block was decrypted successfully, updating record \n");
146 146
147 rd_new.flags = GNUNET_GNSRECORD_RF_NONE; 147 rd_new.flags = GNUNET_GNSRECORD_RF_NONE;
148 rd_new.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 148 rd_new.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
149 rd_new.record_type = TEST_RECORD_TYPE2; 149 rd_new.record_type = TEST_RECORD_TYPE;
150 rd_new.data_size = TEST_RECORD_DATALEN2; 150 rd_new.data_size = TEST_RECORD_DATALEN2;
151 rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); 151 rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2);
152 memset ((char *) rd_new.data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2); 152 memset ((char *) rd_new.data,
153 TEST_RECORD_DATA2,
154 TEST_RECORD_DATALEN2);
153 155
154 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 156 nsqe = GNUNET_NAMESTORE_records_store (nsh,
155 1, &rd_new, &put_cont, (void *) name); 157 privkey,
158 name,
159 1,
160 &rd_new,
161 &put_cont,
162 (void *) name);
156 update_performed = GNUNET_YES; 163 update_performed = GNUNET_YES;
157 } 164 }
158 else 165 else
159 { 166 {
160 char rd_cmp_data[TEST_RECORD_DATALEN2]; 167 char rd_cmp_data[TEST_RECORD_DATALEN2];
161 memset (rd_cmp_data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2);
162 168
163 GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type); 169 memset (rd_cmp_data,
170 TEST_RECORD_DATA2,
171 TEST_RECORD_DATALEN2);
172 GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type);
164 GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); 173 GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size);
165 GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN2)); 174 GNUNET_assert (0 == memcmp (&rd_cmp_data,
166 175 rd[0].data,
167 GNUNET_SCHEDULER_cancel (endbadly_task); 176 TEST_RECORD_DATALEN2));
168 endbadly_task = NULL; 177 GNUNET_SCHEDULER_shutdown ();
169 GNUNET_SCHEDULER_add_now (&end, NULL); 178 res = 0;
170 } 179 }
171} 180}
172 181
@@ -184,21 +193,25 @@ name_lookup_proc (void *cls,
184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
185 _("Namecache returned no block for `%s'\n"), 194 _("Namecache returned no block for `%s'\n"),
186 name); 195 name);
187 if (endbadly_task != NULL) 196 GNUNET_SCHEDULER_shutdown ();
188 GNUNET_SCHEDULER_cancel (endbadly_task);
189 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
190 return; 197 return;
191 } 198 }
192 199
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Namecache returned block, decrypting \n"); 201 "Namecache returned block, decrypting \n");
195 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, 202 GNUNET_assert (GNUNET_OK ==
196 &pubkey, name, &rd_decrypt_cb, (void *) name)); 203 GNUNET_GNSRECORD_block_decrypt (block,
204 &pubkey,
205 name,
206 &rd_decrypt_cb,
207 (void *) name));
197} 208}
198 209
199 210
200static void 211static void
201put_cont (void *cls, int32_t success, const char *emsg) 212put_cont (void *cls,
213 int32_t success,
214 const char *emsg)
202{ 215{
203 const char *name = cls; 216 const char *name = cls;
204 struct GNUNET_HashCode derived_hash; 217 struct GNUNET_HashCode derived_hash;
@@ -216,7 +229,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
217 "Looking in namecache for `%s'\n", 230 "Looking in namecache for `%s'\n",
218 GNUNET_h2s (&derived_hash)); 231 GNUNET_h2s (&derived_hash));
219 ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, 232 ncqe = GNUNET_NAMECACHE_lookup_block (nch,
233 &derived_hash,
220 &name_lookup_proc, (void *) name); 234 &name_lookup_proc, (void *) name);
221} 235}
222 236
@@ -227,41 +241,37 @@ run (void *cls,
227 struct GNUNET_TESTING_Peer *peer) 241 struct GNUNET_TESTING_Peer *peer)
228{ 242{
229 struct GNUNET_GNSRECORD_Data rd; 243 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 244
237 update_performed = GNUNET_NO; 245 update_performed = GNUNET_NO;
246 GNUNET_SCHEDULER_add_shutdown (&end,
247 NULL);
238 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 248 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
239 &endbadly, NULL); 249 &endbadly,
240 GNUNET_asprintf (&hostkey_file, 250 NULL);
241 "zonefiles%s%s", 251 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); 252 GNUNET_assert (privkey != NULL);
248 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 253 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
249 254 &pubkey);
250 rd.flags = GNUNET_GNSRECORD_RF_NONE; 255 rd.flags = GNUNET_GNSRECORD_RF_NONE;
251 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 256 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
252 rd.record_type = TEST_RECORD_TYPE; 257 rd.record_type = TEST_RECORD_TYPE;
253 rd.data_size = TEST_RECORD_DATALEN; 258 rd.data_size = TEST_RECORD_DATALEN;
254 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 259 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
255 memset ((char *) rd.data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); 260 memset ((char *) rd.data,
261 TEST_RECORD_DATA,
262 TEST_RECORD_DATALEN);
256 263
257 nsh = GNUNET_NAMESTORE_connect (cfg); 264 nsh = GNUNET_NAMESTORE_connect (cfg);
258 GNUNET_break (NULL != nsh); 265 GNUNET_break (NULL != nsh);
259 nch = GNUNET_NAMECACHE_connect (cfg); 266 nch = GNUNET_NAMECACHE_connect (cfg);
260 GNUNET_break (NULL != nch); 267 GNUNET_break (NULL != nch);
261 nsqe = GNUNET_NAMESTORE_records_store (nsh, 268 nsqe = GNUNET_NAMESTORE_records_store (nsh,
262 privkey, name, 269 privkey,
263 1, &rd, 270 name,
264 &put_cont, (void *) name); 271 1,
272 &rd,
273 &put_cont,
274 (void *) name);
265 if (NULL == nsqe) 275 if (NULL == nsqe)
266 { 276 {
267 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 277 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -272,7 +282,8 @@ run (void *cls,
272 282
273 283
274int 284int
275main (int argc, char *argv[]) 285main (int argc,
286 char *argv[])
276{ 287{
277 const char *plugin_name; 288 const char *plugin_name;
278 char *cfg_name; 289 char *cfg_name;
@@ -282,6 +293,8 @@ main (int argc, char *argv[])
282 "test_namestore_api_%s.conf", 293 "test_namestore_api_%s.conf",
283 plugin_name); 294 plugin_name);
284 res = 1; 295 res = 1;
296 GNUNET_DISK_purge_cfg_dir (cfg_name,
297 "GNUNET_TEST_HOME");
285 if (0 != 298 if (0 !=
286 GNUNET_TESTING_peer_run ("test-namestore-api-store-update", 299 GNUNET_TESTING_peer_run ("test-namestore-api-store-update",
287 cfg_name, 300 cfg_name,
@@ -290,14 +303,11 @@ main (int argc, char *argv[])
290 { 303 {
291 res = 1; 304 res = 1;
292 } 305 }
306 GNUNET_DISK_purge_cfg_dir (cfg_name,
307 "GNUNET_TEST_HOME");
293 GNUNET_free (cfg_name); 308 GNUNET_free (cfg_name);
294 if (NULL != directory)
295 {
296 GNUNET_DISK_directory_remove (directory);
297 GNUNET_free (directory);
298 }
299 return res; 309 return res;
300} 310}
301 311
302 312
303/* end of test_namestore_api_store_update.c*/ 313/* 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..af263c816 100644
--- a/src/namestore/test_namestore_api_zone_iteration.c
+++ b/src/namestore/test_namestore_api_zone_iteration.c
@@ -1,21 +1,19 @@
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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_zone_iteration.c 19 * @file namestore/test_namestore_api_zone_iteration.c
@@ -25,6 +23,9 @@
25#include "gnunet_namestore_service.h" 23#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h" 24#include "gnunet_testing_lib.h"
27#include "namestore.h" 25#include "namestore.h"
26#include "gnunet_dnsparser_lib.h"
27
28#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
28 29
29 30
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
@@ -56,8 +57,6 @@ static char * s_name_3;
56 57
57static struct GNUNET_GNSRECORD_Data *s_rd_3; 58static struct GNUNET_GNSRECORD_Data *s_rd_3;
58 59
59static char *directory;
60
61 60
62/** 61/**
63 * Re-establish the connection to the service. 62 * Re-establish the connection to the service.
@@ -68,43 +67,8 @@ static char *directory;
68static void 67static void
69endbadly (void *cls) 68endbadly (void *cls)
70{ 69{
71 if (NULL != zi) 70 endbadly_task = NULL;
72 { 71 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; 72 res = 1;
109} 73}
110 74
@@ -117,41 +81,44 @@ end (void *cls)
117 GNUNET_NAMESTORE_zone_iteration_stop (zi); 81 GNUNET_NAMESTORE_zone_iteration_stop (zi);
118 zi = NULL; 82 zi = NULL;
119 } 83 }
120 if (endbadly_task != NULL) 84 if (NULL != endbadly_task)
121 { 85 {
122 GNUNET_SCHEDULER_cancel (endbadly_task); 86 GNUNET_SCHEDULER_cancel (endbadly_task);
123 endbadly_task = NULL; 87 endbadly_task = NULL;
124 } 88 }
125 89 if (NULL != privkey)
126 if (privkey != NULL) 90 {
127 GNUNET_free (privkey); 91 GNUNET_free (privkey);
128 privkey = NULL; 92 privkey = NULL;
129 93 }
130 if (privkey2 != NULL) 94 if (NULL != privkey2)
95 {
131 GNUNET_free (privkey2); 96 GNUNET_free (privkey2);
132 privkey2 = NULL; 97 privkey2 = NULL;
133 98 }
134 GNUNET_free (s_name_1); 99 GNUNET_free (s_name_1);
135 GNUNET_free (s_name_2); 100 GNUNET_free (s_name_2);
136 GNUNET_free (s_name_3); 101 GNUNET_free (s_name_3);
137 if (s_rd_1 != NULL) 102 if (NULL != s_rd_1)
138 { 103 {
139 GNUNET_free ((void *)s_rd_1->data); 104 GNUNET_free ((void *)s_rd_1->data);
140 GNUNET_free (s_rd_1); 105 GNUNET_free (s_rd_1);
141 } 106 }
142 if (s_rd_2 != NULL) 107 if (NULL != s_rd_2)
143 { 108 {
144 GNUNET_free ((void *)s_rd_2->data); 109 GNUNET_free ((void *)s_rd_2->data);
145 GNUNET_free (s_rd_2); 110 GNUNET_free (s_rd_2);
146 } 111 }
147 if (s_rd_3 != NULL) 112 if (NULL != s_rd_3)
148 { 113 {
149 GNUNET_free ((void *)s_rd_3->data); 114 GNUNET_free ((void *)s_rd_3->data);
150 GNUNET_free (s_rd_3); 115 GNUNET_free (s_rd_3);
151 } 116 }
152 if (nsh != NULL) 117 if (NULL != nsh)
118 {
153 GNUNET_NAMESTORE_disconnect (nsh); 119 GNUNET_NAMESTORE_disconnect (nsh);
154 nsh = NULL; 120 nsh = NULL;
121 }
155} 122}
156 123
157 124
@@ -170,7 +137,7 @@ zone_end (void *cls)
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "Received last result, iteration done after receing %u results\n", 138 "Received last result, iteration done after receing %u results\n",
172 returned_records); 139 returned_records);
173 GNUNET_SCHEDULER_add_now (&end, NULL); 140 GNUNET_SCHEDULER_shutdown ();
174} 141}
175 142
176 143
@@ -191,7 +158,9 @@ zone_proc (void *cls,
191 int failed = GNUNET_NO; 158 int failed = GNUNET_NO;
192 159
193 GNUNET_assert (NULL != zone); 160 GNUNET_assert (NULL != zone);
194 if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 161 if (0 == memcmp (zone,
162 privkey,
163 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
195 { 164 {
196 if (0 == strcmp (label, s_name_1)) 165 if (0 == strcmp (label, s_name_1))
197 { 166 {
@@ -230,12 +199,15 @@ zone_proc (void *cls,
230 else 199 else
231 { 200 {
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 "Comparing result failed: got name `%s' for first zone\n", label); 202 "Comparing result failed: got name `%s' for first zone\n",
203 label);
234 failed = GNUNET_YES; 204 failed = GNUNET_YES;
235 GNUNET_break (0); 205 GNUNET_break (0);
236 } 206 }
237 } 207 }
238 else if (0 == memcmp (zone, privkey2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 208 else if (0 == memcmp (zone,
209 privkey2,
210 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
239 { 211 {
240 if (0 == strcmp (label, s_name_3)) 212 if (0 == strcmp (label, s_name_3))
241 { 213 {
@@ -258,7 +230,8 @@ zone_proc (void *cls,
258 else 230 else
259 { 231 {
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
261 "Comparing result failed: got name `%s' for first zone\n", label); 233 "Comparing result failed: got name `%s' for first zone\n",
234 label);
262 failed = GNUNET_YES; 235 failed = GNUNET_YES;
263 GNUNET_break (0); 236 GNUNET_break (0);
264 } 237 }
@@ -282,29 +255,34 @@ zone_proc (void *cls,
282 else 255 else
283 { 256 {
284 GNUNET_break (0); 257 GNUNET_break (0);
285 GNUNET_SCHEDULER_add_now (&end, NULL); 258 GNUNET_SCHEDULER_shutdown ();
259 res = 1;
286 } 260 }
287} 261}
288 262
289 263
290static void 264static void
291put_cont (void *cls, int32_t success, const char *emsg) 265put_cont (void *cls,
266 int32_t success,
267 const char *emsg)
292{ 268{
293 static int c = 0; 269 static int c = 0;
294 270
295 if (success == GNUNET_OK) 271 if (success == GNUNET_OK)
296 { 272 {
297 c++; 273 c++;
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); 274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
275 "Created record %u \n",
276 c);
299 } 277 }
300 else 278 else
301 { 279 {
302 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", 280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
281 "Failed to created records: `%s'\n",
303 emsg); 282 emsg);
304 GNUNET_break (0); 283 GNUNET_break (0);
305 if (NULL != endbadly_task) 284 GNUNET_SCHEDULER_shutdown ();
306 GNUNET_SCHEDULER_cancel (endbadly_task); 285 res = 1;
307 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
308 return; 286 return;
309 } 287 }
310 288
@@ -312,7 +290,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
312 { 290 {
313 res = 1; 291 res = 1;
314 returned_records = 0; 292 returned_records = 0;
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); 293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "All records created, starting iteration over all zones \n");
316 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, 295 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
317 NULL, 296 NULL,
318 &fail_cb, 297 &fail_cb,
@@ -323,11 +302,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
323 NULL); 302 NULL);
324 if (zi == NULL) 303 if (zi == NULL)
325 { 304 {
326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); 305 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
306 "Failed to create zone iterator\n");
327 GNUNET_break (0); 307 GNUNET_break (0);
328 if (NULL != endbadly_task) 308 GNUNET_SCHEDULER_shutdown ();
329 GNUNET_SCHEDULER_cancel (endbadly_task); 309 res = 1;
330 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
331 return; 310 return;
332 } 311 }
333 } 312 }
@@ -337,14 +316,14 @@ put_cont (void *cls, int32_t success, const char *emsg)
337static struct GNUNET_GNSRECORD_Data * 316static struct GNUNET_GNSRECORD_Data *
338create_record (unsigned int count) 317create_record (unsigned int count)
339{ 318{
340 unsigned int c;
341 struct GNUNET_GNSRECORD_Data * rd; 319 struct GNUNET_GNSRECORD_Data * rd;
342 320
343 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 321 rd = GNUNET_new_array (count,
344 for (c = 0; c < count; c++) 322 struct GNUNET_GNSRECORD_Data);
323 for (unsigned int c = 0; c < count; c++)
345 { 324 {
346 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 325 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
347 rd[c].record_type = 1111; 326 rd[c].record_type = TEST_RECORD_TYPE;
348 rd[c].data_size = 50; 327 rd[c].data_size = 50;
349 rd[c].data = GNUNET_malloc(50); 328 rd[c].data = GNUNET_malloc(50);
350 rd[c].flags = 0; 329 rd[c].flags = 0;
@@ -372,9 +351,8 @@ empty_zone_proc (void *cls,
372 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
373 _("Expected empty zone but received zone private key\n")); 352 _("Expected empty zone but received zone private key\n"));
374 GNUNET_break (0); 353 GNUNET_break (0);
375 if (endbadly_task != NULL) 354 GNUNET_SCHEDULER_shutdown ();
376 GNUNET_SCHEDULER_cancel (endbadly_task); 355 res = 1;
377 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
378 return; 356 return;
379 } 357 }
380 if ((NULL != label) || (NULL != rd) || (0 != rd_count)) 358 if ((NULL != label) || (NULL != rd) || (0 != rd_count))
@@ -382,9 +360,8 @@ empty_zone_proc (void *cls,
382 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 360 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
383 _("Expected no zone content but received data\n")); 361 _("Expected no zone content but received data\n"));
384 GNUNET_break (0); 362 GNUNET_break (0);
385 if (endbadly_task != NULL) 363 GNUNET_SCHEDULER_shutdown ();
386 GNUNET_SCHEDULER_cancel (endbadly_task); 364 res = 1;
387 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
388 return; 365 return;
389 } 366 }
390 GNUNET_assert (0); 367 GNUNET_assert (0);
@@ -412,7 +389,9 @@ empty_zone_end (void *cls)
412 "zonefiles%s%s", 389 "zonefiles%s%s",
413 DIR_SEPARATOR_STR, 390 DIR_SEPARATOR_STR,
414 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); 391 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
393 "Using zonekey file `%s' \n",
394 hostkey_file);
416 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 395 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
417 GNUNET_free (hostkey_file); 396 GNUNET_free (hostkey_file);
418 GNUNET_assert (privkey2 != NULL); 397 GNUNET_assert (privkey2 != NULL);
@@ -425,8 +404,8 @@ empty_zone_end (void *cls)
425 privkey, 404 privkey,
426 s_name_1, 405 s_name_1,
427 1, s_rd_1, 406 1, s_rd_1,
428 &put_cont, NULL); 407 &put_cont,
429 408 NULL);
430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
431 "Created record 2 \n"); 410 "Created record 2 \n");
432 GNUNET_asprintf(&s_name_2, "dummy2"); 411 GNUNET_asprintf(&s_name_2, "dummy2");
@@ -437,16 +416,18 @@ empty_zone_end (void *cls)
437 1, s_rd_2, 416 1, s_rd_2,
438 &put_cont, 417 &put_cont,
439 NULL); 418 NULL);
440
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
442 "Created record 3\n"); 420 "Created record 3\n");
443
444 /* name in different zone */ 421 /* name in different zone */
445 GNUNET_asprintf(&s_name_3, "dummy3"); 422 GNUNET_asprintf(&s_name_3, "dummy3");
446 s_rd_3 = create_record(1); 423 s_rd_3 = create_record(1);
447 GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, 424 GNUNET_NAMESTORE_records_store (nsh,
448 1, s_rd_3, 425 privkey2,
449 &put_cont, NULL); 426 s_name_3,
427 1,
428 s_rd_3,
429 &put_cont,
430 NULL);
450} 431}
451 432
452 433
@@ -455,31 +436,30 @@ run (void *cls,
455 const struct GNUNET_CONFIGURATION_Handle *cfg, 436 const struct GNUNET_CONFIGURATION_Handle *cfg,
456 struct GNUNET_TESTING_Peer *peer) 437 struct GNUNET_TESTING_Peer *peer)
457{ 438{
458 directory = NULL; 439 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
459 GNUNET_assert (GNUNET_OK == 440 &endbadly,
460 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", 441 NULL);
461 "GNUNET_TEST_HOME", 442 GNUNET_SCHEDULER_add_shutdown (&end,
462 &directory)); 443 NULL);
463 GNUNET_DISK_directory_remove (directory); 444
464
465 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
466 nsh = GNUNET_NAMESTORE_connect (cfg); 445 nsh = GNUNET_NAMESTORE_connect (cfg);
467 GNUNET_break (NULL != nsh); 446 GNUNET_break (NULL != nsh);
468 /* first, iterate over empty namestore */ 447 /* first, iterate over empty namestore */
469 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 448 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
470 NULL, 449 NULL,
471 &fail_cb, 450 &fail_cb,
472 NULL, 451 NULL,
473 &empty_zone_proc, 452 &empty_zone_proc,
474 nsh, 453 nsh,
475 &empty_zone_end, 454 &empty_zone_end,
476 NULL); 455 NULL);
477 if (NULL == zi) 456 if (NULL == zi)
478 { 457 {
479 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); 458 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
459 "Failed to create zone iterator\n");
480 GNUNET_break (0); 460 GNUNET_break (0);
481 GNUNET_SCHEDULER_cancel (endbadly_task); 461 res = 1;
482 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 462 GNUNET_SCHEDULER_shutdown ();
483 } 463 }
484} 464}
485 465
@@ -494,6 +474,8 @@ main (int argc, char *argv[])
494 GNUNET_asprintf (&cfg_name, 474 GNUNET_asprintf (&cfg_name,
495 "test_namestore_api_%s.conf", 475 "test_namestore_api_%s.conf",
496 plugin_name); 476 plugin_name);
477 GNUNET_DISK_purge_cfg_dir (cfg_name,
478 "GNUNET_TEST_HOME");
497 res = 1; 479 res = 1;
498 if (0 != 480 if (0 !=
499 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration", 481 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration",
@@ -503,12 +485,9 @@ main (int argc, char *argv[])
503 { 485 {
504 res = 1; 486 res = 1;
505 } 487 }
488 GNUNET_DISK_purge_cfg_dir (cfg_name,
489 "GNUNET_TEST_HOME");
506 GNUNET_free (cfg_name); 490 GNUNET_free (cfg_name);
507 if (NULL != directory)
508 {
509 GNUNET_DISK_directory_remove (directory);
510 GNUNET_free (directory);
511 }
512 return res; 491 return res;
513} 492}
514 493
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c
index a88646864..efaadff55 100644
--- a/src/namestore/test_namestore_api_zone_iteration_nick.c
+++ b/src/namestore/test_namestore_api_zone_iteration_nick.c
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_zone_iteration.c 19 * @file namestore/test_namestore_api_zone_iteration.c
@@ -25,6 +23,9 @@
25#include "gnunet_namestore_service.h" 23#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h" 24#include "gnunet_testing_lib.h"
27#include "namestore.h" 25#include "namestore.h"
26#include "gnunet_dnsparser_lib.h"
27
28#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
28 29
29#define ZONE_NICK_1 "nick1" 30#define ZONE_NICK_1 "nick1"
30#define ZONE_NICK_2 "nick2" 31#define ZONE_NICK_2 "nick2"
@@ -60,7 +61,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
60 61
61static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 62static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
62 63
63static char *directory;
64 64
65/** 65/**
66 * Re-establish the connection to the service. 66 * Re-establish the connection to the service.
@@ -265,7 +265,9 @@ fail_cb (void *cls)
265 265
266 266
267static void 267static void
268put_cont (void *cls, int32_t success, const char *emsg) 268put_cont (void *cls,
269 int32_t success,
270 const char *emsg)
269{ 271{
270 static int c = 0; 272 static int c = 0;
271 273
@@ -314,14 +316,14 @@ put_cont (void *cls, int32_t success, const char *emsg)
314static struct GNUNET_GNSRECORD_Data * 316static struct GNUNET_GNSRECORD_Data *
315create_record (unsigned int count) 317create_record (unsigned int count)
316{ 318{
317 unsigned int c;
318 struct GNUNET_GNSRECORD_Data * rd; 319 struct GNUNET_GNSRECORD_Data * rd;
319 320
320 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 321 rd = GNUNET_new_array (count,
321 for (c = 0; c < count; c++) 322 struct GNUNET_GNSRECORD_Data);
323 for (unsigned int c = 0; c < count; c++)
322 { 324 {
323 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 325 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
324 rd[c].record_type = 1111; 326 rd[c].record_type = TEST_RECORD_TYPE;
325 rd[c].data_size = 50; 327 rd[c].data_size = 50;
326 rd[c].data = GNUNET_malloc(50); 328 rd[c].data = GNUNET_malloc(50);
327 rd[c].flags = 0; 329 rd[c].flags = 0;
@@ -332,7 +334,9 @@ create_record (unsigned int count)
332 334
333 335
334static void 336static void
335nick_2_cont (void *cls, int32_t success, const char *emsg) 337nick_2_cont (void *cls,
338 int32_t success,
339 const char *emsg)
336{ 340{
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
338 "Nick added : %s\n", 342 "Nick added : %s\n",
@@ -422,25 +426,18 @@ empty_zone_proc (void *cls,
422static void 426static void
423empty_zone_end (void *cls) 427empty_zone_end (void *cls)
424{ 428{
425 char *hostkey_file;
426 GNUNET_assert (nsh == cls); 429 GNUNET_assert (nsh == cls);
427
428 zi = NULL; 430 zi = NULL;
429 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 431 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); 432 GNUNET_assert (privkey != NULL);
435 433 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); 434 GNUNET_assert (privkey2 != NULL);
442 435
443 nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, ZONE_NICK_1, &nick_1_cont, &privkey); 436 nsqe = GNUNET_NAMESTORE_set_nick (nsh,
437 privkey,
438 ZONE_NICK_1,
439 &nick_1_cont,
440 &privkey);
444 if (NULL == nsqe) 441 if (NULL == nsqe)
445 { 442 {
446 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 443 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -455,15 +452,9 @@ run (void *cls,
455 const struct GNUNET_CONFIGURATION_Handle *cfg, 452 const struct GNUNET_CONFIGURATION_Handle *cfg,
456 struct GNUNET_TESTING_Peer *peer) 453 struct GNUNET_TESTING_Peer *peer)
457{ 454{
458 directory = NULL; 455 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
459 GNUNET_assert (GNUNET_OK == 456 &endbadly,
460 GNUNET_CONFIGURATION_get_value_string (cfg, 457 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); 458 nsh = GNUNET_NAMESTORE_connect (cfg);
468 GNUNET_break (NULL != nsh); 459 GNUNET_break (NULL != nsh);
469 460
@@ -498,6 +489,8 @@ main (int argc, char *argv[])
498 "test_namestore_api_%s.conf", 489 "test_namestore_api_%s.conf",
499 plugin_name); 490 plugin_name);
500 res = 1; 491 res = 1;
492 GNUNET_DISK_purge_cfg_dir (cfg_name,
493 "GNUNET_TEST_HOME");
501 if (0 != 494 if (0 !=
502 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick", 495 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick",
503 cfg_name, 496 cfg_name,
@@ -506,12 +499,9 @@ main (int argc, char *argv[])
506 { 499 {
507 res = 1; 500 res = 1;
508 } 501 }
502 GNUNET_DISK_purge_cfg_dir (cfg_name,
503 "GNUNET_TEST_HOME");
509 GNUNET_free (cfg_name); 504 GNUNET_free (cfg_name);
510 if (NULL != directory)
511 {
512 GNUNET_DISK_directory_remove (directory);
513 GNUNET_free (directory);
514 }
515 return res; 505 return res;
516} 506}
517 507
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..303a7648a 100644
--- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
+++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_zone_iteration_specific_zone.c 19 * @file namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -26,6 +24,9 @@
26#include "gnunet_namestore_service.h" 24#include "gnunet_namestore_service.h"
27#include "gnunet_testing_lib.h" 25#include "gnunet_testing_lib.h"
28#include "namestore.h" 26#include "namestore.h"
27#include "gnunet_dnsparser_lib.h"
28
29#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
29 30
30 31
31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
@@ -57,53 +58,17 @@ static char * s_name_3;
57 58
58static struct GNUNET_GNSRECORD_Data *s_rd_3; 59static struct GNUNET_GNSRECORD_Data *s_rd_3;
59 60
60static char *directory;
61 61
62/** 62/**
63 * Re-establish the connection to the service. 63 * Handle timeout.
64 * 64 *
65 * @param cls handle to use to re-connect. 65 * @param cls handle to use to re-connect.
66 * @param tc scheduler context
67 */ 66 */
68static void 67static void
69endbadly (void *cls) 68endbadly (void *cls)
70{ 69{
71 if (NULL != zi) 70 endbadly_task = NULL;
72 { 71 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; 72 res = 1;
108} 73}
109 74
@@ -116,21 +81,21 @@ end (void *cls)
116 GNUNET_NAMESTORE_zone_iteration_stop (zi); 81 GNUNET_NAMESTORE_zone_iteration_stop (zi);
117 zi = NULL; 82 zi = NULL;
118 } 83 }
119 84 if (NULL != endbadly_task)
120 if (endbadly_task != NULL)
121 { 85 {
122 GNUNET_SCHEDULER_cancel (endbadly_task); 86 GNUNET_SCHEDULER_cancel (endbadly_task);
123 endbadly_task = NULL; 87 endbadly_task = NULL;
124 } 88 }
125 89 if (NULL != privkey)
126 if (privkey != NULL) 90 {
127 GNUNET_free (privkey); 91 GNUNET_free (privkey);
128 privkey = NULL; 92 privkey = NULL;
129 93 }
130 if (privkey2 != NULL) 94 if (NULL != privkey2)
95 {
131 GNUNET_free (privkey2); 96 GNUNET_free (privkey2);
132 privkey2 = NULL; 97 privkey2 = NULL;
133 98 }
134 GNUNET_free (s_name_1); 99 GNUNET_free (s_name_1);
135 GNUNET_free (s_name_2); 100 GNUNET_free (s_name_2);
136 GNUNET_free (s_name_3); 101 GNUNET_free (s_name_3);
@@ -150,8 +115,10 @@ end (void *cls)
150 GNUNET_free (s_rd_3); 115 GNUNET_free (s_rd_3);
151 } 116 }
152 if (nsh != NULL) 117 if (nsh != NULL)
118 {
153 GNUNET_NAMESTORE_disconnect (nsh); 119 GNUNET_NAMESTORE_disconnect (nsh);
154 nsh = NULL; 120 nsh = NULL;
121 }
155} 122}
156 123
157 124
@@ -159,6 +126,7 @@ static void
159fail_cb (void *cls) 126fail_cb (void *cls)
160{ 127{
161 GNUNET_assert (0); 128 GNUNET_assert (0);
129 zi = NULL;
162} 130}
163 131
164 132
@@ -244,7 +212,8 @@ zone_proc (void *cls,
244 else 212 else
245 { 213 {
246 GNUNET_break (0); 214 GNUNET_break (0);
247 GNUNET_SCHEDULER_add_now (&end, NULL); 215 res = 2;
216 GNUNET_SCHEDULER_shutdown ();
248 } 217 }
249} 218}
250 219
@@ -252,24 +221,28 @@ zone_proc (void *cls,
252static void 221static void
253zone_proc_end (void *cls) 222zone_proc_end (void *cls)
254{ 223{
224 zi = NULL;
255 GNUNET_break (2 == returned_records); 225 GNUNET_break (2 == returned_records);
256 if (2 == returned_records) 226 if (2 == returned_records)
257 { 227 {
258 res = 0; /* Last iteraterator callback, we are done */ 228 res = 0; /* Last iteraterator callback, we are done */
259 zi = NULL;
260 } 229 }
261 else 230 else
231 {
262 res = 1; 232 res = 1;
233 }
263 234
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
265 "Received last result, iteration done after receing %u results\n", 236 "Received last result, iteration done after receing %u results\n",
266 returned_records); 237 returned_records);
267 GNUNET_SCHEDULER_add_now (&end, NULL); 238 GNUNET_SCHEDULER_shutdown ();
268} 239}
269 240
270 241
271static void 242static void
272put_cont (void *cls, int32_t success, const char *emsg) 243put_cont (void *cls,
244 int32_t success,
245 const char *emsg)
273{ 246{
274 static int c = 0; 247 static int c = 0;
275 248
@@ -285,9 +258,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
285 "Failed to created records: `%s'\n", 258 "Failed to created records: `%s'\n",
286 emsg); 259 emsg);
287 GNUNET_break (0); 260 GNUNET_break (0);
288 if (NULL != endbadly_task) 261 res = 2;
289 GNUNET_SCHEDULER_cancel (endbadly_task); 262 GNUNET_SCHEDULER_shutdown ();
290 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
291 return; 263 return;
292 } 264 }
293 265
@@ -310,9 +282,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
310 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 282 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
311 "Failed to create zone iterator\n"); 283 "Failed to create zone iterator\n");
312 GNUNET_break (0); 284 GNUNET_break (0);
313 if (NULL != endbadly_task) 285 res = 2;
314 GNUNET_SCHEDULER_cancel (endbadly_task); 286 GNUNET_SCHEDULER_shutdown ();
315 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
316 return; 287 return;
317 } 288 }
318 } 289 }
@@ -322,14 +293,14 @@ put_cont (void *cls, int32_t success, const char *emsg)
322static struct GNUNET_GNSRECORD_Data * 293static struct GNUNET_GNSRECORD_Data *
323create_record (unsigned int count) 294create_record (unsigned int count)
324{ 295{
325 unsigned int c; 296 struct GNUNET_GNSRECORD_Data *rd;
326 struct GNUNET_GNSRECORD_Data * rd;
327 297
328 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 298 rd = GNUNET_new_array (count,
329 for (c = 0; c < count; c++) 299 struct GNUNET_GNSRECORD_Data);
300 for (unsigned int c = 0; c < count; c++)
330 { 301 {
331 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 302 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
332 rd[c].record_type = 1111; 303 rd[c].record_type = TEST_RECORD_TYPE;
333 rd[c].data_size = 50; 304 rd[c].data_size = 50;
334 rd[c].data = GNUNET_malloc(50); 305 rd[c].data = GNUNET_malloc(50);
335 rd[c].flags = 0; 306 rd[c].flags = 0;
@@ -357,9 +328,8 @@ empty_zone_proc (void *cls,
357 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 328 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
358 _("Expected empty zone but received zone private key\n")); 329 _("Expected empty zone but received zone private key\n"));
359 GNUNET_break (0); 330 GNUNET_break (0);
360 if (endbadly_task != NULL) 331 res = 2;
361 GNUNET_SCHEDULER_cancel (endbadly_task); 332 GNUNET_SCHEDULER_shutdown ();
362 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
363 return; 333 return;
364 } 334 }
365 if ((NULL != label) || (NULL != rd) || (0 != rd_count)) 335 if ((NULL != label) || (NULL != rd) || (0 != rd_count))
@@ -367,9 +337,8 @@ empty_zone_proc (void *cls,
367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 337 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
368 _("Expected no zone content but received data\n")); 338 _("Expected no zone content but received data\n"));
369 GNUNET_break (0); 339 GNUNET_break (0);
370 if (endbadly_task != NULL) 340 res = 2;
371 GNUNET_SCHEDULER_cancel (endbadly_task); 341 GNUNET_SCHEDULER_shutdown ();
372 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
373 return; 342 return;
374 } 343 }
375 GNUNET_assert (0); 344 GNUNET_assert (0);
@@ -379,35 +348,16 @@ empty_zone_proc (void *cls,
379static void 348static void
380empty_zone_proc_end (void *cls) 349empty_zone_proc_end (void *cls)
381{ 350{
382 char *hostkey_file;
383
384 zi = NULL; 351 zi = NULL;
385 GNUNET_asprintf (&hostkey_file, 352 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); 353 GNUNET_assert (privkey != NULL);
395 354 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); 355 GNUNET_assert (privkey2 != NULL);
406 356
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
408 "Created record 1\n"); 358 "Created record 1\n");
409 359 GNUNET_asprintf (&s_name_1,
410 GNUNET_asprintf(&s_name_1, "dummy1"); 360 "dummy1");
411 s_rd_1 = create_record (1); 361 s_rd_1 = create_record (1);
412 GNUNET_NAMESTORE_records_store (nsh, 362 GNUNET_NAMESTORE_records_store (nsh,
413 privkey, 363 privkey,
@@ -419,7 +369,8 @@ empty_zone_proc_end (void *cls)
419 369
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
421 "Created record 2 \n"); 371 "Created record 2 \n");
422 GNUNET_asprintf(&s_name_2, "dummy2"); 372 GNUNET_asprintf (&s_name_2,
373 "dummy2");
423 s_rd_2 = create_record (1); 374 s_rd_2 = create_record (1);
424 GNUNET_NAMESTORE_records_store (nsh, 375 GNUNET_NAMESTORE_records_store (nsh,
425 privkey, 376 privkey,
@@ -433,7 +384,8 @@ empty_zone_proc_end (void *cls)
433 "Created record 3\n"); 384 "Created record 3\n");
434 385
435 /* name in different zone */ 386 /* name in different zone */
436 GNUNET_asprintf(&s_name_3, "dummy3"); 387 GNUNET_asprintf (&s_name_3,
388 "dummy3");
437 s_rd_3 = create_record (1); 389 s_rd_3 = create_record (1);
438 GNUNET_NAMESTORE_records_store (nsh, 390 GNUNET_NAMESTORE_records_store (nsh,
439 privkey2, 391 privkey2,
@@ -449,14 +401,8 @@ run (void *cls,
449 const struct GNUNET_CONFIGURATION_Handle *cfg, 401 const struct GNUNET_CONFIGURATION_Handle *cfg,
450 struct GNUNET_TESTING_Peer *peer) 402 struct GNUNET_TESTING_Peer *peer)
451{ 403{
452 directory = NULL; 404 GNUNET_SCHEDULER_add_shutdown (&end,
453 GNUNET_assert (GNUNET_OK == 405 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, 406 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
461 &endbadly, 407 &endbadly,
462 NULL); 408 NULL);
@@ -476,8 +422,7 @@ run (void *cls,
476 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 422 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
477 "Failed to create zone iterator\n"); 423 "Failed to create zone iterator\n");
478 GNUNET_break (0); 424 GNUNET_break (0);
479 GNUNET_SCHEDULER_cancel (endbadly_task); 425 GNUNET_SCHEDULER_shutdown ();
480 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
481 } 426 }
482} 427}
483 428
@@ -493,6 +438,8 @@ main (int argc, char *argv[])
493 "test_namestore_api_%s.conf", 438 "test_namestore_api_%s.conf",
494 plugin_name); 439 plugin_name);
495 res = 1; 440 res = 1;
441 GNUNET_DISK_purge_cfg_dir (cfg_name,
442 "GNUNET_TEST_HOME");
496 if (0 != 443 if (0 !=
497 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone", 444 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone",
498 cfg_name, 445 cfg_name,
@@ -501,12 +448,9 @@ main (int argc, char *argv[])
501 { 448 {
502 res = 1; 449 res = 1;
503 } 450 }
451 GNUNET_DISK_purge_cfg_dir (cfg_name,
452 "GNUNET_TEST_HOME");
504 GNUNET_free (cfg_name); 453 GNUNET_free (cfg_name);
505 if (NULL != directory)
506 {
507 GNUNET_DISK_directory_remove (directory);
508 GNUNET_free (directory);
509 }
510 return res; 454 return res;
511} 455}
512 456
diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c
index c7be5fead..eb7ad4305 100644
--- a/src/namestore/test_namestore_api_zone_iteration_stop.c
+++ b/src/namestore/test_namestore_api_zone_iteration_stop.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_zone_iteration.c 19 * @file namestore/test_namestore_api_zone_iteration.c
@@ -25,7 +23,9 @@
25#include "gnunet_namestore_service.h" 23#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h" 24#include "gnunet_testing_lib.h"
27#include "namestore.h" 25#include "namestore.h"
26#include "gnunet_dnsparser_lib.h"
28 27
28#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
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, 100)
31#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) 31#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
@@ -56,7 +56,6 @@ static char * s_name_3;
56 56
57static struct GNUNET_GNSRECORD_Data *s_rd_3; 57static struct GNUNET_GNSRECORD_Data *s_rd_3;
58 58
59static char *directory;
60 59
61 60
62/** 61/**
@@ -350,14 +349,14 @@ put_cont (void *cls, int32_t success, const char *emsg)
350static struct GNUNET_GNSRECORD_Data * 349static struct GNUNET_GNSRECORD_Data *
351create_record (unsigned int count) 350create_record (unsigned int count)
352{ 351{
353 unsigned int c; 352 struct GNUNET_GNSRECORD_Data *rd;
354 struct GNUNET_GNSRECORD_Data * rd;
355 353
356 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 354 rd = GNUNET_new_array (count,
357 for (c = 0; c < count; c++) 355 struct GNUNET_GNSRECORD_Data);
356 for (unsigned int c = 0; c < count; c++)
358 { 357 {
359 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 358 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
360 rd[c].record_type = 1111; 359 rd[c].record_type = TEST_RECORD_TYPE;
361 rd[c].data_size = 50; 360 rd[c].data_size = 50;
362 rd[c].data = GNUNET_malloc(50); 361 rd[c].data = GNUNET_malloc(50);
363 rd[c].flags = 0; 362 rd[c].flags = 0;
@@ -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..e689455b0 100644
--- a/src/namestore/test_namestore_api_zone_to_name.c
+++ b/src/namestore/test_namestore_api_zone_to_name.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file namestore/test_namestore_api_zone_to_name.c 19 * @file namestore/test_namestore_api_zone_to_name.c
@@ -25,10 +23,11 @@
25#include "gnunet_namestore_service.h" 23#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h" 24#include "gnunet_testing_lib.h"
27#include "namestore.h" 25#include "namestore.h"
26#include "gnunet_dnsparser_lib.h"
28 27
29#define RECORDS 5 28#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
30 29
31#define TEST_RECORD_TYPE 1234 30#define RECORDS 5
32 31
33#define TEST_RECORD_DATALEN 123 32#define TEST_RECORD_DATALEN 123
34 33
@@ -51,8 +50,6 @@ static char * s_name;
51 50
52static int res; 51static int res;
53 52
54static char *directory;
55
56static struct GNUNET_NAMESTORE_QueueEntry *qe; 53static struct GNUNET_NAMESTORE_QueueEntry *qe;
57 54
58 55
@@ -204,34 +201,13 @@ run (void *cls,
204{ 201{
205 (void) cls; 202 (void) cls;
206 (void) peer; 203 (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, 204 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
216 &endbadly, 205 &endbadly,
217 NULL); 206 NULL);
218 GNUNET_SCHEDULER_add_shutdown (&end, 207 GNUNET_SCHEDULER_add_shutdown (&end,
219 NULL); 208 NULL);
220 GNUNET_asprintf (&s_name, "dummy"); 209 GNUNET_asprintf (&s_name, "dummy");
221 /* load privat key */ 210 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); 211 GNUNET_assert (NULL != privkey);
236 /* get public key */ 212 /* get public key */
237 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 213 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
@@ -274,6 +250,8 @@ main (int argc,
274 GNUNET_asprintf (&cfg_name, 250 GNUNET_asprintf (&cfg_name,
275 "test_namestore_api_%s.conf", 251 "test_namestore_api_%s.conf",
276 plugin_name); 252 plugin_name);
253 GNUNET_DISK_purge_cfg_dir (cfg_name,
254 "GNUNET_TEST_HOME");
277 res = 1; 255 res = 1;
278 if (0 != 256 if (0 !=
279 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name", 257 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name",
@@ -283,12 +261,9 @@ main (int argc,
283 { 261 {
284 res = 1; 262 res = 1;
285 } 263 }
264 GNUNET_DISK_purge_cfg_dir (cfg_name,
265 "GNUNET_TEST_HOME");
286 GNUNET_free (cfg_name); 266 GNUNET_free (cfg_name);
287 if (NULL != directory)
288 {
289 GNUNET_DISK_directory_remove (directory);
290 GNUNET_free (directory);
291 }
292 return res; 267 return res;
293} 268}
294 269
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c
index 6bccd1706..9d21ad16a 100644
--- a/src/namestore/test_plugin_namestore.c
+++ b/src/namestore/test_plugin_namestore.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V. 3 Copyright (C) 2012 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/* 18/*
21 * @file namestore/test_plugin_namestore.c 19 * @file namestore/test_plugin_namestore.c
@@ -26,7 +24,9 @@
26#include "gnunet_util_lib.h" 24#include "gnunet_util_lib.h"
27#include "gnunet_namestore_plugin.h" 25#include "gnunet_namestore_plugin.h"
28#include "gnunet_testing_lib.h" 26#include "gnunet_testing_lib.h"
27#include "gnunet_dnsparser_lib.h"
29 28
29#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
30 30
31static int ok; 31static int ok;
32 32
@@ -110,7 +110,7 @@ test_record (void *cls,
110 { 110 {
111 GNUNET_assert (rd[i].data_size == id % 10); 111 GNUNET_assert (rd[i].data_size == id % 10);
112 GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10)); 112 GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10));
113 GNUNET_assert (rd[i].record_type == 1 + (id % 13)); 113 GNUNET_assert (rd[i].record_type == TEST_RECORD_TYPE);
114 GNUNET_assert (rd[i].flags == 0); 114 GNUNET_assert (rd[i].flags == 0);
115 } 115 }
116 memset (&tzone_private_key, 116 memset (&tzone_private_key,
@@ -154,7 +154,7 @@ put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
154 rd[i].data = "Hello World"; 154 rd[i].data = "Hello World";
155 rd[i].data_size = id % 10; 155 rd[i].data_size = id % 10;
156 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES).abs_value_us; 156 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES).abs_value_us;
157 rd[i].record_type = 1 + (id % 13); 157 rd[i].record_type = TEST_RECORD_TYPE;
158 rd[i].flags = 0; 158 rd[i].flags = 0;
159 } 159 }
160 memset (&zone_private_key, (id % 241), sizeof (zone_private_key)); 160 memset (&zone_private_key, (id % 241), sizeof (zone_private_key));
@@ -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 3639ce33e..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]
2FILENAME = /tmp/gnunet-test-plugin-namestore-sqlite/flatdb 2FILENAME = $GNUNET_TMP/gnunet-test-plugin-namestore-flat/flatdb
3
4[namestore]
5# PREFIX = valgrind --log-file=/home/schanzen/dev/gnunet/src/namestore/vg_log
diff --git a/src/namestore/test_plugin_namestore_sqlite.conf b/src/namestore/test_plugin_namestore_sqlite.conf
index 57b170f7a..24eecd286 100644
--- a/src/namestore/test_plugin_namestore_sqlite.conf
+++ b/src/namestore/test_plugin_namestore_sqlite.conf
@@ -1,2 +1,2 @@
1[namestore-sqlite] 1[namestore-sqlite]
2FILENAME = /tmp/gnunet-test-plugin-namestore-sqlite/sqlite.db 2FILENAME = $GNUNET_TMP/gnunet-test-plugin-namestore-sqlite/sqlite.db