aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-05-09 17:33:04 +0200
committerChristian Grothoff <christian@grothoff.org>2018-05-09 17:33:04 +0200
commit8bb475af99260f1d107dbc8908268ae93960aa83 (patch)
tree1a7a1fc03424df841a6f977b137482439b09bc9f /src/namestore
parent1f80a11e90ee982bffaae4685e281f75ee1c225d (diff)
downloadgnunet-8bb475af99260f1d107dbc8908268ae93960aa83.tar.gz
gnunet-8bb475af99260f1d107dbc8908268ae93960aa83.zip
implement new functions in libgnunetsq, clean up sqlite namestore plugin, implement flow control in namestore API and tests
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-service-namestore.c501
-rw-r--r--src/namestore/plugin_namestore_flat.c6
-rw-r--r--src/namestore/plugin_namestore_sqlite.c260
-rw-r--r--src/namestore/test_namestore_api_lookup_nick.c37
-rw-r--r--src/namestore/test_namestore_api_lookup_private.c52
-rw-r--r--src/namestore/test_namestore_api_lookup_public.c31
-rw-r--r--src/namestore/test_namestore_api_lookup_shadow.c40
-rw-r--r--src/namestore/test_namestore_api_lookup_shadow_filter.c34
-rw-r--r--src/namestore/test_namestore_api_monitoring.c65
-rw-r--r--src/namestore/test_namestore_api_monitoring_existing.c42
-rw-r--r--src/namestore/test_namestore_api_remove.c42
-rw-r--r--src/namestore/test_namestore_api_remove_not_existing_record.c37
-rw-r--r--src/namestore/test_namestore_api_store.c33
-rw-r--r--src/namestore/test_namestore_api_store_update.c175
-rw-r--r--src/namestore/test_namestore_api_zone_iteration.c200
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_nick.c57
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_specific_zone.c54
-rw-r--r--src/namestore/test_namestore_api_zone_to_name.c34
-rw-r--r--src/namestore/test_plugin_namestore.c4
19 files changed, 822 insertions, 882 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index f47c8776b..a92b8104a 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2014 GNUnet e.V. 3 Copyright (C) 2012, 2013, 2014, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -23,6 +23,9 @@
23 * @brief namestore for the GNUnet naming system 23 * @brief namestore for the GNUnet naming system
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 *
27 * TODO:
28 * - run testcases, make sure everything works!
26 */ 29 */
27#include "platform.h" 30#include "platform.h"
28#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
@@ -175,6 +178,27 @@ struct ZoneMonitor
175 */ 178 */
176 uint64_t limit; 179 uint64_t limit;
177 180
181 /**
182 * How many more requests may we receive from the iterator
183 * before it is at the limit we gave it? Will be below or
184 * equal to @e limit. The effective limit for monitor
185 * events is thus @e iteration_cnt - @e limit!
186 */
187 uint64_t iteration_cnt;
188
189 /**
190 * Are we (still) in the initial iteration pass?
191 */
192 int in_first_iteration;
193
194 /**
195 * Is there a store activity waiting for this monitor? We only raise the
196 * flag when it happens and search the DLL for the store activity when we
197 * had a limit increase. If we cannot find any waiting store activity at
198 * that time, we clear the flag again.
199 */
200 int sa_waiting;
201
178}; 202};
179 203
180 204
@@ -212,6 +236,57 @@ struct CacheOperation
212 236
213 237
214/** 238/**
239 * Information for an ongoing #handle_record_store() operation.
240 * Needed as we may wait for monitors to be ready for the notification.
241 */
242struct StoreActivity
243{
244 /**
245 * Kept in a DLL.
246 */
247 struct StoreActivity *next;
248
249 /**
250 * Kept in a DLL.
251 */
252 struct StoreActivity *prev;
253
254 /**
255 * Which client triggered the store activity?
256 */
257 struct NamestoreClient *nc;
258
259 /**
260 * Copy of the original store message (as data fields in @e rd will
261 * point into it!).
262 */
263 const struct RecordStoreMessage *rsm;
264
265 /**
266 * Array of record data to store (without NICK unless this is about
267 * #GNUNET_GNS_EMPTY_LABEL_AT). Length is in @e rd_count.
268 */
269 struct GNUNET_GNSRECORD_Data *rd;
270
271 /**
272 * Next zone monitor that still needs to be notified about this PUT.
273 */
274 struct ZoneMonitor *zm_pos;
275
276 /**
277 * Label nicely canonicalized (lower case).
278 */
279 char *conv_name;
280
281 /**
282 * How many records do we try to store?
283 */
284 unsigned int rd_count;
285
286};
287
288
289/**
215 * Public key of all zeros. 290 * Public key of all zeros.
216 */ 291 */
217static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero; 292static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero;
@@ -262,6 +337,16 @@ static struct ZoneMonitor *monitor_head;
262static struct ZoneMonitor *monitor_tail; 337static struct ZoneMonitor *monitor_tail;
263 338
264/** 339/**
340 * Head of DLL of monitor-blocked store activities.
341 */
342static struct StoreActivity *sa_head;
343
344/**
345 * Tail of DLL of monitor-blocked store activities.
346 */
347static struct StoreActivity *sa_tail;
348
349/**
265 * Notification context shared by all monitors. 350 * Notification context shared by all monitors.
266 */ 351 */
267static struct GNUNET_NotificationContext *monitor_nc; 352static struct GNUNET_NotificationContext *monitor_nc;
@@ -326,80 +411,21 @@ cleanup_task (void *cls)
326 411
327 412
328/** 413/**
329 * Called whenever a client is disconnected. 414 * Release memory used by @a sa.
330 * Frees our resources associated with that client.
331 * 415 *
332 * @param cls closure 416 * @param sa activity to free
333 * @param client identification of the client
334 * @param app_ctx the `struct NamestoreClient` of @a client
335 */ 417 */
336static void 418static void
337client_disconnect_cb (void *cls, 419free_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{ 420{
393 struct NamestoreClient *nc; 421 GNUNET_CONTAINER_DLL_remove (sa_head,
394 422 sa_tail,
395 (void) cls; 423 sa);
396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 424 GNUNET_array_grow (sa->rd,
397 "Client %p connected\n", 425 sa->rd_count,
398 client); 426 0);
399 nc = GNUNET_new (struct NamestoreClient); 427 GNUNET_free (sa->conv_name);
400 nc->client = client; 428 GNUNET_free (sa);
401 nc->mq = mq;
402 return nc;
403} 429}
404 430
405 431
@@ -795,6 +821,173 @@ refresh_block (struct NamestoreClient *nc,
795 821
796 822
797/** 823/**
824 * Continue processing the @a sa.
825 *
826 * @param sa store activity to process
827 */
828static void
829continue_store_activity (struct StoreActivity *sa)
830{
831 const struct RecordStoreMessage *rp_msg = sa->rsm;
832
833 for (struct ZoneMonitor *zm = sa->zm_pos;
834 NULL != zm;
835 zm = sa->zm_pos)
836 {
837 if ( (0 != memcmp (&rp_msg->private_key,
838 &zm->zone,
839 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) &&
840 (0 != memcmp (&zm->zone,
841 &zero,
842 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
843 sa->zm_pos = zm->next; /* not interesting to this monitor */
844 if (zm->limit == zm->iteration_cnt)
845 {
846 zm->sa_waiting = GNUNET_YES;
847 return; /* blocked on zone monitor */
848 }
849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
850 "Notifying monitor about changes under label `%s'\n",
851 sa->conv_name);
852 zm->limit--;
853 send_lookup_response (zm->nc,
854 0,
855 &rp_msg->private_key,
856 sa->conv_name,
857 sa->rd_count,
858 sa->rd);
859 sa->zm_pos = zm->next;
860 }
861 /* great, done with the monitors, unpack (again) for refresh_block operation */
862 {
863 size_t name_len;
864 size_t rd_ser_len;
865 uint32_t rid;
866 const char *name_tmp;
867 const char *rd_ser;
868 unsigned int rd_count;
869
870 rid = ntohl (rp_msg->gns_header.r_id);
871 name_len = ntohs (rp_msg->name_len);
872 rd_count = ntohs (rp_msg->rd_count);
873 rd_ser_len = ntohs (rp_msg->rd_len);
874 name_tmp = (const char *) &rp_msg[1];
875 rd_ser = &name_tmp[name_len];
876 {
877 struct GNUNET_GNSRECORD_Data rd[rd_count];
878
879 /* We did this before, must succeed again */
880 GNUNET_assert (GNUNET_OK ==
881 GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
882 rd_ser,
883 rd_count,
884 rd));
885 refresh_block (sa->nc,
886 rid,
887 &rp_msg->private_key,
888 sa->conv_name,
889 rd_count,
890 rd);
891 }
892 }
893 GNUNET_SERVICE_client_continue (sa->nc->client);
894 free_store_activity (sa);
895}
896
897
898/**
899 * Called whenever a client is disconnected.
900 * Frees our resources associated with that client.
901 *
902 * @param cls closure
903 * @param client identification of the client
904 * @param app_ctx the `struct NamestoreClient` of @a client
905 */
906static void
907client_disconnect_cb (void *cls,
908 struct GNUNET_SERVICE_Client *client,
909 void *app_ctx)
910{
911 struct NamestoreClient *nc = app_ctx;
912 struct ZoneIteration *no;
913 struct CacheOperation *cop;
914
915 (void) cls;
916 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
917 "Client %p disconnected\n",
918 client);
919 for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next)
920 {
921 if (nc != zm->nc)
922 continue;
923 GNUNET_CONTAINER_DLL_remove (monitor_head,
924 monitor_tail,
925 zm);
926 if (NULL != zm->task)
927 {
928 GNUNET_SCHEDULER_cancel (zm->task);
929 zm->task = NULL;
930 }
931 for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
932 {
933 if (zm == sa->zm_pos)
934 {
935 sa->zm_pos = zm->next;
936 continue_store_activity (sa);
937 }
938 }
939 GNUNET_free (zm);
940 break;
941 }
942 for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
943 {
944 if (sa->nc == nc)
945 {
946 free_store_activity (sa);
947 break; /* there can only be one per nc */
948 }
949 }
950 while (NULL != (no = nc->op_head))
951 {
952 GNUNET_CONTAINER_DLL_remove (nc->op_head,
953 nc->op_tail,
954 no);
955 GNUNET_free (no);
956 }
957 for (cop = cop_head; NULL != cop; cop = cop->next)
958 if (nc == cop->nc)
959 cop->nc = NULL;
960 GNUNET_free (nc);
961}
962
963
964/**
965 * Add a client to our list of active clients.
966 *
967 * @param cls NULL
968 * @param client client to add
969 * @param mq message queue for @a client
970 * @return internal namestore client structure for this client
971 */
972static void *
973client_connect_cb (void *cls,
974 struct GNUNET_SERVICE_Client *client,
975 struct GNUNET_MQ_Handle *mq)
976{
977 struct NamestoreClient *nc;
978
979 (void) cls;
980 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
981 "Client %p connected\n",
982 client);
983 nc = GNUNET_new (struct NamestoreClient);
984 nc->client = client;
985 nc->mq = mq;
986 return nc;
987}
988
989
990/**
798 * Closure for #lookup_it(). 991 * Closure for #lookup_it().
799 */ 992 */
800struct RecordLookupContext 993struct RecordLookupContext
@@ -1073,7 +1266,7 @@ handle_record_store (void *cls,
1073 const char *rd_ser; 1266 const char *rd_ser;
1074 unsigned int rd_count; 1267 unsigned int rd_count;
1075 int res; 1268 int res;
1076 struct ZoneMonitor *zm; 1269 struct StoreActivity *sa;
1077 1270
1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1079 "Received NAMESTORE_RECORD_STORE message\n"); 1272 "Received NAMESTORE_RECORD_STORE message\n");
@@ -1085,7 +1278,9 @@ handle_record_store (void *cls,
1085 name_tmp = (const char *) &rp_msg[1]; 1278 name_tmp = (const char *) &rp_msg[1];
1086 rd_ser = &name_tmp[name_len]; 1279 rd_ser = &name_tmp[name_len];
1087 { 1280 {
1088 struct GNUNET_GNSRECORD_Data rd[rd_count]; 1281 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
1282 struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
1283 unsigned int rd_clean_off;
1089 1284
1090 if (GNUNET_OK != 1285 if (GNUNET_OK !=
1091 GNUNET_GNSRECORD_records_deserialize (rd_ser_len, 1286 GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
@@ -1128,9 +1323,6 @@ handle_record_store (void *cls,
1128 } 1323 }
1129 else 1324 else
1130 { 1325 {
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 1326 /* remove "NICK" records, unless this is for the
1135 #GNUNET_GNS_EMPTY_LABEL_AT label */ 1327 #GNUNET_GNS_EMPTY_LABEL_AT label */
1136 rd_clean_off = 0; 1328 rd_clean_off = 0;
@@ -1147,59 +1339,39 @@ handle_record_store (void *cls,
1147 conv_name, 1339 conv_name,
1148 rd_clean_off, 1340 rd_clean_off,
1149 rd_clean); 1341 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 } 1342 }
1185 if (GNUNET_OK == res) 1343
1344 if (GNUNET_OK != res)
1186 { 1345 {
1187 refresh_block (nc, 1346 /* store not successful, not need to tell monitors */
1188 rid, 1347 send_store_response (nc,
1189 &rp_msg->private_key, 1348 res,
1190 conv_name, 1349 rid);
1191 rd_count,
1192 rd);
1193 GNUNET_SERVICE_client_continue (nc->client); 1350 GNUNET_SERVICE_client_continue (nc->client);
1194 GNUNET_free (conv_name); 1351 GNUNET_free (conv_name);
1195 return; 1352 return;
1196 } 1353 }
1197 GNUNET_free (conv_name); 1354
1355 sa = GNUNET_malloc (sizeof (struct StoreActivity) +
1356 ntohs (rp_msg->gns_header.header.size));
1357 GNUNET_CONTAINER_DLL_insert (sa_head,
1358 sa_tail,
1359 sa);
1360 sa->nc = nc;
1361 sa->rsm = (const struct RecordStoreMessage *) &sa[1];
1362 memcpy (&sa[1],
1363 rp_msg,
1364 ntohs (rp_msg->gns_header.header.size));
1365 sa->zm_pos = monitor_head;
1366 sa->conv_name = conv_name;
1367 GNUNET_array_grow (sa->rd,
1368 sa->rd_count,
1369 rd_clean_off);
1370 memcpy (sa->rd,
1371 rd_clean,
1372 sizeof (struct GNUNET_GNSRECORD_Data) * rd_clean_off);
1373 continue_store_activity (sa);
1198 } 1374 }
1199 send_store_response (nc,
1200 res,
1201 rid);
1202 GNUNET_SERVICE_client_continue (nc->client);
1203} 1375}
1204 1376
1205 1377
@@ -1311,8 +1483,7 @@ handle_zone_to_name (void *cls,
1311 struct ZoneToNameResponseMessage *ztnr_msg; 1483 struct ZoneToNameResponseMessage *ztnr_msg;
1312 1484
1313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1314 "Received `%s' message\n", 1486 "Received ZONE_TO_NAME message\n");
1315 "ZONE_TO_NAME");
1316 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); 1487 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
1317 ztn_ctx.nc = nc; 1488 ztn_ctx.nc = nc;
1318 ztn_ctx.success = GNUNET_NO; 1489 ztn_ctx.success = GNUNET_NO;
@@ -1601,6 +1772,30 @@ handle_iteration_next (void *cls,
1601 1772
1602 1773
1603/** 1774/**
1775 * Function called when the monitor is ready for more data, and we
1776 * should thus unblock PUT operations that were blocked on the
1777 * monitor not being ready.
1778 */
1779static void
1780monitor_unblock (struct ZoneMonitor *zm)
1781{
1782 struct StoreActivity *sa = sa_head;
1783
1784 while ( (NULL != sa) &&
1785 (zm->limit > zm->iteration_cnt) )
1786 {
1787 struct StoreActivity *sn = sa->next;
1788
1789 if (sa->zm_pos == zm)
1790 continue_store_activity (sa);
1791 sa = sn;
1792 }
1793 if (zm->limit > zm->iteration_cnt)
1794 zm->sa_waiting = GNUNET_NO;
1795}
1796
1797
1798/**
1604 * Send 'sync' message to zone monitor, we're now in sync. 1799 * Send 'sync' message to zone monitor, we're now in sync.
1605 * 1800 *
1606 * @param zm monitor that is now in sync 1801 * @param zm monitor that is now in sync
@@ -1615,16 +1810,22 @@ monitor_sync (struct ZoneMonitor *zm)
1615 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC); 1810 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC);
1616 GNUNET_MQ_send (zm->nc->mq, 1811 GNUNET_MQ_send (zm->nc->mq,
1617 env); 1812 env);
1813 /* mark iteration done */
1814 zm->in_first_iteration = GNUNET_NO;
1815 zm->iteration_cnt = 0;
1816 if ( (zm->limit > 0) &&
1817 (zm->sa_waiting) )
1818 monitor_unblock (zm);
1618} 1819}
1619 1820
1620 1821
1621/** 1822/**
1622 * Obtain the next datum during the zone monitor's zone intiial iteration. 1823 * Obtain the next datum during the zone monitor's zone initial iteration.
1623 * 1824 *
1624 * @param cls zone monitor that does its initial iteration 1825 * @param cls zone monitor that does its initial iteration
1625 */ 1826 */
1626static void 1827static void
1627monitor_next (void *cls); 1828monitor_iteration_next (void *cls);
1628 1829
1629 1830
1630/** 1831/**
@@ -1658,14 +1859,23 @@ monitor_iterate_cb (void *cls,
1658 "Monitor notifications sent", 1859 "Monitor notifications sent",
1659 1, 1860 1,
1660 GNUNET_NO); 1861 GNUNET_NO);
1862 zm->limit--;
1863 zm->iteration_cnt--;
1661 send_lookup_response (zm->nc, 1864 send_lookup_response (zm->nc,
1662 0, 1865 0,
1663 zone_key, 1866 zone_key,
1664 name, 1867 name,
1665 rd_count, 1868 rd_count,
1666 rd); 1869 rd);
1667 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, 1870 if ( (0 == zm->iteration_cnt) &&
1668 zm); 1871 (0 != zm->limit) )
1872 {
1873 /* We are done with the current iteration batch, AND the
1874 client would right now accept more, so go again! */
1875 GNUNET_assert (NULL == zm->task);
1876 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
1877 zm);
1878 }
1669} 1879}
1670 1880
1671 1881
@@ -1687,6 +1897,8 @@ handle_monitor_start (void *cls,
1687 zm = GNUNET_new (struct ZoneMonitor); 1897 zm = GNUNET_new (struct ZoneMonitor);
1688 zm->nc = nc; 1898 zm->nc = nc;
1689 zm->zone = zis_msg->zone; 1899 zm->zone = zis_msg->zone;
1900 zm->limit = 1;
1901 zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first));
1690 GNUNET_CONTAINER_DLL_insert (monitor_head, 1902 GNUNET_CONTAINER_DLL_insert (monitor_head,
1691 monitor_tail, 1903 monitor_tail,
1692 zm); 1904 zm);
@@ -1694,8 +1906,8 @@ handle_monitor_start (void *cls,
1694 GNUNET_SERVICE_client_continue (nc->client); 1906 GNUNET_SERVICE_client_continue (nc->client);
1695 GNUNET_notification_context_add (monitor_nc, 1907 GNUNET_notification_context_add (monitor_nc,
1696 nc->mq); 1908 nc->mq);
1697 if (GNUNET_YES == ntohl (zis_msg->iterate_first)) 1909 if (zm->in_first_iteration)
1698 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, 1910 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
1699 zm); 1911 zm);
1700 else 1912 else
1701 monitor_sync (zm); 1913 monitor_sync (zm);
@@ -1708,12 +1920,17 @@ handle_monitor_start (void *cls,
1708 * @param cls zone monitor that does its initial iteration 1920 * @param cls zone monitor that does its initial iteration
1709 */ 1921 */
1710static void 1922static void
1711monitor_next (void *cls) 1923monitor_iteration_next (void *cls)
1712{ 1924{
1713 struct ZoneMonitor *zm = cls; 1925 struct ZoneMonitor *zm = cls;
1714 int ret; 1926 int ret;
1715 1927
1716 zm->task = NULL; 1928 zm->task = NULL;
1929 GNUNET_assert (0 == zm->iteration_cnt);
1930 if (zm->limit > 16)
1931 zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */
1932 else
1933 zm->iteration_cnt = zm->limit; /* use it all */
1717 ret = GSN_database->iterate_records (GSN_database->cls, 1934 ret = GSN_database->iterate_records (GSN_database->cls,
1718 (0 == memcmp (&zm->zone, 1935 (0 == memcmp (&zm->zone,
1719 &zero, 1936 &zero,
@@ -1721,7 +1938,7 @@ monitor_next (void *cls)
1721 ? NULL 1938 ? NULL
1722 : &zm->zone, 1939 : &zm->zone,
1723 zm->seq, 1940 zm->seq,
1724 1, 1941 zm->iteration_cnt,
1725 &monitor_iterate_cb, 1942 &monitor_iterate_cb,
1726 zm); 1943 zm);
1727 if (GNUNET_SYSERR == ret) 1944 if (GNUNET_SYSERR == ret)
@@ -1773,13 +1990,19 @@ handle_monitor_next (void *cls,
1773 return; 1990 return;
1774 } 1991 }
1775 zm->limit += inc; 1992 zm->limit += inc;
1776#if 0 1993 if ( (zm->in_first_iteration) &&
1777 if (GNUNET_YES == ntohl (zis_msg->iterate_first)) 1994 (zm->limit == inc) )
1778 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, 1995 {
1779 zm); 1996 /* We are still iterating, and the previous iteration must
1780 else 1997 have stopped due to the client's limit, so continue it! */
1781 monitor_sync (zm); 1998 GNUNET_assert (NULL == zm->task);
1782#endif 1999 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
2000 zm);
2001 }
2002 GNUNET_assert (zm->iteration_cnt <= zm->limit);
2003 if ( (zm->limit > zm->iteration_cnt) &&
2004 (zm->sa_waiting) )
2005 monitor_unblock (zm);
1783} 2006}
1784 2007
1785 2008
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c
index bbb9e3c62..df9f424a6 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -364,10 +364,10 @@ store_and_free_entries (void *cls,
364 &record_data_b64); 364 &record_data_b64);
365 } 365 }
366 GNUNET_asprintf (&line, 366 GNUNET_asprintf (&line,
367 "%s,%lu,%u,%s,%s\n", 367 "%s,%llu,%u,%s,%s\n",
368 zone_private_key, 368 zone_private_key,
369 entry->rvalue, 369 (unsigned long long) entry->rvalue,
370 entry->record_count, 370 (unsigned int) entry->record_count,
371 record_data_b64, 371 record_data_b64,
372 entry->label); 372 entry->label);
373 GNUNET_free (record_data_b64); 373 GNUNET_free (record_data_b64);
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index f62be1e18..34e548613 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -106,72 +106,6 @@ struct Plugin
106 106
107 107
108/** 108/**
109 * @brief Prepare a SQL statement
110 *
111 * @param dbh handle to the database
112 * @param zSql SQL statement, UTF-8 encoded
113 * @param ppStmt set to the prepared statement
114 * @return 0 on success
115 */
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 109 * Initialize the database connections and associated
176 * data structures (create tables and indices 110 * data structures (create tables and indices
177 * as needed as well). 111 * as needed as well).
@@ -182,17 +116,66 @@ create_indices (sqlite3 * dbh)
182static int 116static int
183database_setup (struct Plugin *plugin) 117database_setup (struct Plugin *plugin)
184{ 118{
185 sqlite3_stmt *stmt; 119 char *sqlite_filename;
186 char *afsdir; 120 struct GNUNET_SQ_ExecuteStatement es[] = {
187#if ENULL_DEFINED 121 GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
188 char *e; 122 GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
189#endif 123 GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
124 GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
125 GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
126 GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=EXCLUSIVE"),
127 GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
128 GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records ("
129 " uid INTEGER PRIMARY KEY,"
130 " zone_private_key BLOB NOT NULL,"
131 " pkey BLOB,"
132 " rvalue INT8 NOT NULL,"
133 " record_count INT NOT NULL,"
134 " record_data BLOB NOT NULL,"
135 " label TEXT NOT NULL"
136 ")"),
137 GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
138 "ON ns098records (zone_private_key,pkey)"),
139 GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter "
140 "ON ns098records (zone_private_key,uid)"),
141 GNUNET_SQ_EXECUTE_STATEMENT_END
142 };
143 struct GNUNET_SQ_PrepareStatement ps[] = {
144 GNUNET_SQ_make_prepare ("INSERT INTO ns098records "
145 "(zone_private_key,pkey,rvalue,record_count,record_data,label)"
146 " VALUES (?, ?, ?, ?, ?, ?)",
147 &plugin->store_records),
148 GNUNET_SQ_make_prepare ("DELETE FROM ns098records "
149 "WHERE zone_private_key=? AND label=?",
150 &plugin->delete_records),
151 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
152 " FROM ns098records"
153 " WHERE zone_private_key=? AND pkey=?",
154 &plugin->zone_to_name),
155 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
156 " FROM ns098records"
157 " WHERE zone_private_key=? AND _rowid_ >= ?"
158 " ORDER BY _rowid_ ASC"
159 " LIMIT ?",
160 &plugin->iterate_zone),
161 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key"
162 " FROM ns098records"
163 " WHERE _rowid_ >= ?"
164 " ORDER BY _rowid_ ASC"
165 " LIMIT ?",
166 &plugin->iterate_all_zones),
167 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key"
168 " FROM ns098records"
169 " WHERE zone_private_key=? AND label=?",
170 &plugin->lookup_label),
171 GNUNET_SQ_PREPARE_END
172 };
190 173
191 if (GNUNET_OK != 174 if (GNUNET_OK !=
192 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, 175 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg,
193 "namestore-sqlite", 176 "namestore-sqlite",
194 "FILENAME", 177 "FILENAME",
195 &afsdir)) 178 &sqlite_filename))
196 { 179 {
197 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 180 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
198 "namestore-sqlite", 181 "namestore-sqlite",
@@ -200,132 +183,51 @@ database_setup (struct Plugin *plugin)
200 return GNUNET_SYSERR; 183 return GNUNET_SYSERR;
201 } 184 }
202 if (GNUNET_OK != 185 if (GNUNET_OK !=
203 GNUNET_DISK_file_test (afsdir)) 186 GNUNET_DISK_file_test (sqlite_filename))
204 { 187 {
205 if (GNUNET_OK != 188 if (GNUNET_OK !=
206 GNUNET_DISK_directory_create_for_file (afsdir)) 189 GNUNET_DISK_directory_create_for_file (sqlite_filename))
207 { 190 {
208 GNUNET_break (0); 191 GNUNET_break (0);
209 GNUNET_free (afsdir); 192 GNUNET_free (sqlite_filename);
210 return GNUNET_SYSERR; 193 return GNUNET_SYSERR;
211 } 194 }
212 } 195 }
213 /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ 196 /* sqlite_filename should be UTF-8-encoded. If it isn't, it's a bug */
214 plugin->fn = afsdir; 197 plugin->fn = sqlite_filename;
215 198
216 /* Open database and precompile statements */ 199 /* Open database and precompile statements */
217 if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK) 200 if (SQLITE_OK !=
201 sqlite3_open (plugin->fn,
202 &plugin->dbh))
218 { 203 {
219 LOG (GNUNET_ERROR_TYPE_ERROR, 204 LOG (GNUNET_ERROR_TYPE_ERROR,
220 _("Unable to initialize SQLite: %s.\n"), 205 _("Unable to initialize SQLite: %s.\n"),
221 sqlite3_errmsg (plugin->dbh)); 206 sqlite3_errmsg (plugin->dbh));
222 return GNUNET_SYSERR; 207 return GNUNET_SYSERR;
223 } 208 }
224 CHECK (SQLITE_OK == 209 GNUNET_break (SQLITE_OK ==
225 sqlite3_exec (plugin->dbh, 210 sqlite3_busy_timeout (plugin->dbh,
226 "PRAGMA temp_store=MEMORY", NULL, NULL, 211 BUSY_TIMEOUT_MS));
227 ENULL)); 212 if (GNUNET_OK !=
228 CHECK (SQLITE_OK == 213 GNUNET_SQ_exec_statements (plugin->dbh,
229 sqlite3_exec (plugin->dbh, 214 es))
230 "PRAGMA synchronous=NORMAL", NULL, NULL,
231 ENULL));
232 CHECK (SQLITE_OK ==
233 sqlite3_exec (plugin->dbh,
234 "PRAGMA legacy_file_format=OFF", NULL, NULL,
235 ENULL));
236 CHECK (SQLITE_OK ==
237 sqlite3_exec (plugin->dbh,
238 "PRAGMA auto_vacuum=INCREMENTAL", NULL,
239 NULL, ENULL));
240 CHECK (SQLITE_OK ==
241 sqlite3_exec (plugin->dbh,
242 "PRAGMA encoding=\"UTF-8\"", NULL,
243 NULL, ENULL));
244 CHECK (SQLITE_OK ==
245 sqlite3_exec (plugin->dbh,
246 "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
247 ENULL));
248 CHECK (SQLITE_OK ==
249 sqlite3_exec (plugin->dbh,
250 "PRAGMA page_size=4092", NULL, NULL,
251 ENULL));
252
253 CHECK (SQLITE_OK ==
254 sqlite3_busy_timeout (plugin->dbh,
255 BUSY_TIMEOUT_MS));
256
257
258 /* Create table */
259 CHECK (SQLITE_OK ==
260 sq_prepare (plugin->dbh,
261 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'ns098records'",
262 &stmt));
263 if ( (sqlite3_step (stmt) == SQLITE_DONE) &&
264 (SQLITE_OK !=
265 sqlite3_exec (plugin->dbh,
266 "CREATE TABLE ns098records ("
267 " uid INTEGER PRIMARY KEY,"
268 " zone_private_key BLOB NOT NULL,"
269 " pkey BLOB,"
270 " rvalue INT8 NOT NULL,"
271 " record_count INT NOT NULL,"
272 " record_data BLOB NOT NULL,"
273 " label TEXT NOT NULL"
274 ")",
275 NULL, NULL, NULL)) )
276 { 215 {
277 LOG_SQLITE (plugin, 216 GNUNET_break (0);
278 GNUNET_ERROR_TYPE_ERROR, 217 LOG (GNUNET_ERROR_TYPE_ERROR,
279 "sqlite3_exec"); 218 _("Failed to setup database at `%s'\n"),
280 sqlite3_finalize (stmt); 219 plugin->fn);
281 return GNUNET_SYSERR; 220 return GNUNET_SYSERR;
282 } 221 }
283 sqlite3_finalize (stmt); 222
284 223 if (GNUNET_OK !=
285 create_indices (plugin->dbh); 224 GNUNET_SQ_prepare (plugin->dbh,
286 225 ps))
287 if ( (SQLITE_OK !=
288 sq_prepare (plugin->dbh,
289 "INSERT INTO ns098records (zone_private_key, pkey, rvalue, record_count, record_data, label)"
290 " VALUES (?, ?, ?, ?, ?, ?)",
291 &plugin->store_records)) ||
292 (SQLITE_OK !=
293 sq_prepare (plugin->dbh,
294 "DELETE FROM ns098records WHERE zone_private_key=? AND label=?",
295 &plugin->delete_records)) ||
296 (SQLITE_OK !=
297 sq_prepare (plugin->dbh,
298 "SELECT uid,record_count,record_data,label"
299 " FROM ns098records"
300 " WHERE zone_private_key=? AND pkey=?",
301 &plugin->zone_to_name)) ||
302 (SQLITE_OK !=
303 sq_prepare (plugin->dbh,
304 "SELECT uid,record_count,record_data,label"
305 " FROM ns098records"
306 " WHERE zone_private_key=? AND _rowid_ >= ?"
307 " ORDER BY _rowid_ ASC"
308 " LIMIT ?",
309 &plugin->iterate_zone)) ||
310 (SQLITE_OK !=
311 sq_prepare (plugin->dbh,
312 "SELECT uid,record_count,record_data,label,zone_private_key"
313 " FROM ns098records"
314 " WHERE _rowid_ >= ?"
315 " ORDER BY _rowid_ ASC"
316 " LIMIT ?",
317 &plugin->iterate_all_zones)) ||
318 (SQLITE_OK !=
319 sq_prepare (plugin->dbh,
320 "SELECT uid,record_count,record_data,label,zone_private_key"
321 " FROM ns098records"
322 " WHERE zone_private_key=? AND label=?",
323 &plugin->lookup_label))
324 )
325 { 226 {
326 LOG_SQLITE (plugin, 227 GNUNET_break (0);
327 GNUNET_ERROR_TYPE_ERROR, 228 LOG (GNUNET_ERROR_TYPE_ERROR,
328 "precompiling"); 229 _("Failed to setup database at `%s'\n"),
230 plugin->fn);
329 return GNUNET_SYSERR; 231 return GNUNET_SYSERR;
330 } 232 }
331 return GNUNET_OK; 233 return GNUNET_OK;
diff --git a/src/namestore/test_namestore_api_lookup_nick.c b/src/namestore/test_namestore_api_lookup_nick.c
index 50d1fd9a9..b9ae93bf2 100644
--- a/src/namestore/test_namestore_api_lookup_nick.c
+++ b/src/namestore/test_namestore_api_lookup_nick.c
@@ -52,7 +52,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
52//static const char * name = "dummy.dummy.gnunet"; 52//static const char * name = "dummy.dummy.gnunet";
53static const char * name = "d"; 53static const char * name = "d";
54 54
55static char *directory;
56 55
57static void 56static void
58cleanup () 57cleanup ()
@@ -283,29 +282,22 @@ run (void *cls,
283 const struct GNUNET_CONFIGURATION_Handle *cfg, 282 const struct GNUNET_CONFIGURATION_Handle *cfg,
284 struct GNUNET_TESTING_Peer *peer) 283 struct GNUNET_TESTING_Peer *peer)
285{ 284{
286 char *hostkey_file;
287
288 directory = NULL;
289 GNUNET_assert (GNUNET_OK ==
290 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
291 GNUNET_DISK_directory_remove (directory);
292
293 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 285 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
294 &endbadly, NULL); 286 &endbadly,
295 GNUNET_asprintf (&hostkey_file, 287 NULL);
296 "zonefiles%s%s", 288 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
297 DIR_SEPARATOR_STR,
298 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
300 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
301 GNUNET_free (hostkey_file);
302 GNUNET_assert (privkey != NULL); 289 GNUNET_assert (privkey != NULL);
303 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 290 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
291 &pubkey);
304 292
305 nsh = GNUNET_NAMESTORE_connect (cfg); 293 nsh = GNUNET_NAMESTORE_connect (cfg);
306 GNUNET_break (NULL != nsh); 294 GNUNET_break (NULL != nsh);
307 295
308 nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, TEST_NICK, &nick_cont, (void *) name); 296 nsqe = GNUNET_NAMESTORE_set_nick (nsh,
297 privkey,
298 TEST_NICK,
299 &nick_cont,
300 (void *) name);
309 if (NULL == nsqe) 301 if (NULL == nsqe)
310 { 302 {
311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 303 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -324,6 +316,8 @@ main (int argc, char *argv[])
324 GNUNET_asprintf (&cfg_name, 316 GNUNET_asprintf (&cfg_name,
325 "test_namestore_api_%s.conf", 317 "test_namestore_api_%s.conf",
326 plugin_name); 318 plugin_name);
319 GNUNET_DISK_purge_cfg_dir (cfg_name,
320 "GNUNET_TEST_HOME");
327 res = 1; 321 res = 1;
328 if (0 != 322 if (0 !=
329 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick", 323 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick",
@@ -333,12 +327,9 @@ main (int argc, char *argv[])
333 { 327 {
334 res = 1; 328 res = 1;
335 } 329 }
330 GNUNET_DISK_purge_cfg_dir (cfg_name,
331 "GNUNET_TEST_HOME");
336 GNUNET_free (cfg_name); 332 GNUNET_free (cfg_name);
337 if (NULL != directory)
338 {
339 GNUNET_DISK_directory_remove (directory);
340 GNUNET_free (directory);
341 }
342 return res; 333 return res;
343} 334}
344 335
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c
index 7866749f1..689e73a2e 100644
--- a/src/namestore/test_namestore_api_lookup_private.c
+++ b/src/namestore/test_namestore_api_lookup_private.c
@@ -48,7 +48,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
48//static const char * name = "dummy.dummy.gnunet"; 48//static const char * name = "dummy.dummy.gnunet";
49static const char * name = "d"; 49static const char * name = "d";
50 50
51static char *directory;
52 51
53static void 52static void
54cleanup () 53cleanup ()
@@ -71,11 +70,11 @@ cleanup ()
71 * Re-establish the connection to the service. 70 * Re-establish the connection to the service.
72 * 71 *
73 * @param cls handle to use to re-connect. 72 * @param cls handle to use to re-connect.
74 * @param tc scheduler context
75 */ 73 */
76static void 74static void
77endbadly (void *cls) 75endbadly (void *cls)
78{ 76{
77 endbadly_task = NULL;
79 if (NULL != nsqe) 78 if (NULL != nsqe)
80 { 79 {
81 GNUNET_NAMESTORE_cancel (nsqe); 80 GNUNET_NAMESTORE_cancel (nsqe);
@@ -109,7 +108,7 @@ lookup_it (void *cls,
109 { 108 {
110 GNUNET_break(0); 109 GNUNET_break(0);
111 GNUNET_SCHEDULER_cancel (endbadly_task); 110 GNUNET_SCHEDULER_cancel (endbadly_task);
112 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 111 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
113 return; 112 return;
114 } 113 }
115 114
@@ -118,7 +117,7 @@ lookup_it (void *cls,
118 { 117 {
119 GNUNET_break(0); 118 GNUNET_break(0);
120 GNUNET_SCHEDULER_cancel (endbadly_task); 119 GNUNET_SCHEDULER_cancel (endbadly_task);
121 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 120 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
122 return; 121 return;
123 } 122 }
124 123
@@ -126,7 +125,7 @@ lookup_it (void *cls,
126 { 125 {
127 GNUNET_break(0); 126 GNUNET_break(0);
128 GNUNET_SCHEDULER_cancel (endbadly_task); 127 GNUNET_SCHEDULER_cancel (endbadly_task);
129 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 128 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
130 return; 129 return;
131 } 130 }
132 131
@@ -134,14 +133,14 @@ lookup_it (void *cls,
134 { 133 {
135 GNUNET_break(0); 134 GNUNET_break(0);
136 GNUNET_SCHEDULER_cancel (endbadly_task); 135 GNUNET_SCHEDULER_cancel (endbadly_task);
137 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 136 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
138 return; 137 return;
139 } 138 }
140 139
141 /* Done */ 140 /* Done */
142 GNUNET_SCHEDULER_cancel (endbadly_task); 141 GNUNET_SCHEDULER_cancel (endbadly_task);
143 endbadly_task = NULL; 142 endbadly_task = NULL;
144 GNUNET_SCHEDULER_add_now (&end, NULL ); 143 GNUNET_SCHEDULER_add_now (&end, NULL);
145} 144}
146 145
147 146
@@ -153,7 +152,9 @@ fail_cb (void *cls)
153 152
154 153
155static void 154static void
156put_cont (void *cls, int32_t success, const char *emsg) 155put_cont (void *cls,
156 int32_t success,
157 const char *emsg)
157{ 158{
158 const char *name = cls; 159 const char *name = cls;
159 160
@@ -187,22 +188,11 @@ run (void *cls,
187 struct GNUNET_TESTING_Peer *peer) 188 struct GNUNET_TESTING_Peer *peer)
188{ 189{
189 struct GNUNET_GNSRECORD_Data rd; 190 struct GNUNET_GNSRECORD_Data rd;
190 char *hostkey_file;
191
192 directory = NULL;
193 GNUNET_assert (GNUNET_OK ==
194 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
195 GNUNET_DISK_directory_remove (directory);
196 191
197 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 192 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
198 &endbadly, NULL); 193 &endbadly,
199 GNUNET_asprintf (&hostkey_file, 194 NULL);
200 "zonefiles%s%s", 195 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
201 DIR_SEPARATOR_STR,
202 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
204 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
205 GNUNET_free (hostkey_file);
206 GNUNET_assert (privkey != NULL); 196 GNUNET_assert (privkey != NULL);
207 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 197 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
208 198
@@ -215,8 +205,13 @@ run (void *cls,
215 205
216 nsh = GNUNET_NAMESTORE_connect (cfg); 206 nsh = GNUNET_NAMESTORE_connect (cfg);
217 GNUNET_break (NULL != nsh); 207 GNUNET_break (NULL != nsh);
218 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 208 nsqe = GNUNET_NAMESTORE_records_store (nsh,
219 1, &rd, &put_cont, (void *) name); 209 privkey,
210 name,
211 1,
212 &rd,
213 &put_cont,
214 (void *) name);
220 if (NULL == nsqe) 215 if (NULL == nsqe)
221 { 216 {
222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -237,6 +232,8 @@ main (int argc, char *argv[])
237 GNUNET_asprintf (&cfg_name, 232 GNUNET_asprintf (&cfg_name,
238 "test_namestore_api_%s.conf", 233 "test_namestore_api_%s.conf",
239 plugin_name); 234 plugin_name);
235 GNUNET_DISK_purge_cfg_dir (cfg_name,
236 "GNUNET_TEST_HOME");
240 res = 1; 237 res = 1;
241 if (0 != 238 if (0 !=
242 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private", 239 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private",
@@ -246,12 +243,9 @@ main (int argc, char *argv[])
246 { 243 {
247 res = 1; 244 res = 1;
248 } 245 }
246 GNUNET_DISK_purge_cfg_dir (cfg_name,
247 "GNUNET_TEST_HOME");
249 GNUNET_free (cfg_name); 248 GNUNET_free (cfg_name);
250 if (NULL != directory)
251 {
252 GNUNET_DISK_directory_remove (directory);
253 GNUNET_free (directory);
254 }
255 return res; 249 return res;
256} 250}
257 251
diff --git a/src/namestore/test_namestore_api_lookup_public.c b/src/namestore/test_namestore_api_lookup_public.c
index 02ca16042..28a68daf9 100644
--- a/src/namestore/test_namestore_api_lookup_public.c
+++ b/src/namestore/test_namestore_api_lookup_public.c
@@ -51,7 +51,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
51 51
52static struct GNUNET_NAMECACHE_QueueEntry *ncqe; 52static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
53 53
54static char *directory;
55 54
56static void 55static void
57cleanup () 56cleanup ()
@@ -190,26 +189,15 @@ run (void *cls,
190 struct GNUNET_TESTING_Peer *peer) 189 struct GNUNET_TESTING_Peer *peer)
191{ 190{
192 struct GNUNET_GNSRECORD_Data rd; 191 struct GNUNET_GNSRECORD_Data rd;
193 char *hostkey_file;
194 const char * name = "dummy.dummy.gnunet"; 192 const char * name = "dummy.dummy.gnunet";
195 193
196 directory = NULL;
197 GNUNET_assert (GNUNET_OK ==
198 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
199 GNUNET_DISK_directory_remove (directory);
200
201 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 194 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
202 &endbadly, NULL); 195 &endbadly,
203 GNUNET_asprintf (&hostkey_file, 196 NULL);
204 "zonefiles%s%s", 197 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
205 DIR_SEPARATOR_STR,
206 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
208 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
209 GNUNET_free (hostkey_file);
210 GNUNET_assert (privkey != NULL); 198 GNUNET_assert (privkey != NULL);
211 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 199 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
212 200 &pubkey);
213 201
214 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 202 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
215 rd.record_type = TEST_RECORD_TYPE; 203 rd.record_type = TEST_RECORD_TYPE;
@@ -244,6 +232,8 @@ main (int argc, char *argv[])
244 GNUNET_asprintf (&cfg_name, 232 GNUNET_asprintf (&cfg_name,
245 "test_namestore_api_%s.conf", 233 "test_namestore_api_%s.conf",
246 plugin_name); 234 plugin_name);
235 GNUNET_DISK_purge_cfg_dir (cfg_name,
236 "GNUNET_TEST_HOME");
247 res = 1; 237 res = 1;
248 if (0 != 238 if (0 !=
249 GNUNET_TESTING_peer_run ("test-namestore-api", 239 GNUNET_TESTING_peer_run ("test-namestore-api",
@@ -253,12 +243,9 @@ main (int argc, char *argv[])
253 { 243 {
254 res = 1; 244 res = 1;
255 } 245 }
246 GNUNET_DISK_purge_cfg_dir (cfg_name,
247 "GNUNET_TEST_HOME");
256 GNUNET_free (cfg_name); 248 GNUNET_free (cfg_name);
257 if (NULL != directory)
258 {
259 GNUNET_DISK_directory_remove (directory);
260 GNUNET_free (directory);
261 }
262 return res; 249 return res;
263} 250}
264 251
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c b/src/namestore/test_namestore_api_lookup_shadow.c
index e80335796..39ce4e564 100644
--- a/src/namestore/test_namestore_api_lookup_shadow.c
+++ b/src/namestore/test_namestore_api_lookup_shadow.c
@@ -53,7 +53,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
53 53
54static struct GNUNET_NAMECACHE_QueueEntry *ncqe; 54static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
55 55
56static char *directory;
57 56
58static void 57static void
59cleanup () 58cleanup ()
@@ -222,26 +221,15 @@ run (void *cls,
222 struct GNUNET_TESTING_Peer *peer) 221 struct GNUNET_TESTING_Peer *peer)
223{ 222{
224 struct GNUNET_GNSRECORD_Data rd; 223 struct GNUNET_GNSRECORD_Data rd;
225 char *hostkey_file;
226 const char * name = "dummy.dummy.gnunet"; 224 const char * name = "dummy.dummy.gnunet";
227 225
228 directory = NULL;
229 GNUNET_assert (GNUNET_OK ==
230 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
231 GNUNET_DISK_directory_remove (directory);
232
233 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 226 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
234 &endbadly, NULL); 227 &endbadly,
235 GNUNET_asprintf (&hostkey_file, 228 NULL);
236 "zonefiles%s%s", 229 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
237 DIR_SEPARATOR_STR,
238 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
240 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
241 GNUNET_free (hostkey_file);
242 GNUNET_assert (privkey != NULL); 230 GNUNET_assert (privkey != NULL);
243 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 231 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
244 232 &pubkey);
245 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 233 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
246 rd.record_type = TEST_RECORD_TYPE; 234 rd.record_type = TEST_RECORD_TYPE;
247 rd.data_size = TEST_RECORD_DATALEN; 235 rd.data_size = TEST_RECORD_DATALEN;
@@ -253,8 +241,13 @@ run (void *cls,
253 nch = GNUNET_NAMECACHE_connect (cfg); 241 nch = GNUNET_NAMECACHE_connect (cfg);
254 GNUNET_break (NULL != nsh); 242 GNUNET_break (NULL != nsh);
255 GNUNET_break (NULL != nch); 243 GNUNET_break (NULL != nch);
256 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 244 nsqe = GNUNET_NAMESTORE_records_store (nsh,
257 1, &rd, &put_cont, (void *) name); 245 privkey,
246 name,
247 1,
248 &rd,
249 &put_cont,
250 (void *) name);
258 if (NULL == nsqe) 251 if (NULL == nsqe)
259 { 252 {
260 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -274,6 +267,8 @@ main (int argc, char *argv[])
274 GNUNET_asprintf (&cfg_name, 267 GNUNET_asprintf (&cfg_name,
275 "test_namestore_api_%s.conf", 268 "test_namestore_api_%s.conf",
276 plugin_name); 269 plugin_name);
270 GNUNET_DISK_purge_cfg_dir (cfg_name,
271 "GNUNET_TEST_HOME");
277 res = 1; 272 res = 1;
278 if (0 != 273 if (0 !=
279 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow", 274 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow",
@@ -284,11 +279,8 @@ main (int argc, char *argv[])
284 res = 1; 279 res = 1;
285 } 280 }
286 GNUNET_free (cfg_name); 281 GNUNET_free (cfg_name);
287 if (NULL != directory) 282 GNUNET_DISK_purge_cfg_dir (cfg_name,
288 { 283 "GNUNET_TEST_HOME");
289 GNUNET_DISK_directory_remove (directory);
290 GNUNET_free (directory);
291 }
292 return res; 284 return res;
293} 285}
294 286
diff --git a/src/namestore/test_namestore_api_lookup_shadow_filter.c b/src/namestore/test_namestore_api_lookup_shadow_filter.c
index 5b8811a23..09fd8ce07 100644
--- a/src/namestore/test_namestore_api_lookup_shadow_filter.c
+++ b/src/namestore/test_namestore_api_lookup_shadow_filter.c
@@ -66,7 +66,6 @@ static struct GNUNET_HashCode derived_hash;
66 66
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",
@@ -362,11 +353,8 @@ main (int argc, char *argv[])
362 res = 1; 353 res = 1;
363 } 354 }
364 GNUNET_free (cfg_name); 355 GNUNET_free (cfg_name);
365 if (NULL != directory) 356 GNUNET_DISK_purge_cfg_dir (cfg_name,
366 { 357 "GNUNET_TEST_HOME");
367 GNUNET_DISK_directory_remove (directory);
368 GNUNET_free (directory);
369 }
370 return res; 358 return res;
371} 359}
372 360
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c
index cd38b2c80..de202d535 100644
--- a/src/namestore/test_namestore_api_monitoring.c
+++ b/src/namestore/test_namestore_api_monitoring.c
@@ -56,7 +56,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
56 56
57struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; 57struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
58 58
59static char *directory;
60 59
61static void 60static void
62do_shutdown () 61do_shutdown ()
@@ -66,7 +65,6 @@ do_shutdown ()
66 GNUNET_NAMESTORE_zone_monitor_stop (zm); 65 GNUNET_NAMESTORE_zone_monitor_stop (zm);
67 zm = NULL; 66 zm = NULL;
68 } 67 }
69
70 if (NULL != ns_ops[0]) 68 if (NULL != ns_ops[0])
71 { 69 {
72 GNUNET_NAMESTORE_cancel(ns_ops[0]); 70 GNUNET_NAMESTORE_cancel(ns_ops[0]);
@@ -82,13 +80,11 @@ do_shutdown ()
82 GNUNET_NAMESTORE_cancel(ns_ops[2]); 80 GNUNET_NAMESTORE_cancel(ns_ops[2]);
83 ns_ops[2] = NULL; 81 ns_ops[2] = NULL;
84 } 82 }
85
86 if (NULL != nsh) 83 if (NULL != nsh)
87 { 84 {
88 GNUNET_NAMESTORE_disconnect (nsh); 85 GNUNET_NAMESTORE_disconnect (nsh);
89 nsh = NULL; 86 nsh = NULL;
90 } 87 }
91
92 GNUNET_free_non_null(s_name_1); 88 GNUNET_free_non_null(s_name_1);
93 GNUNET_free_non_null(s_name_2); 89 GNUNET_free_non_null(s_name_2);
94 GNUNET_free_non_null(s_name_3); 90 GNUNET_free_non_null(s_name_3);
@@ -284,23 +280,8 @@ run (void *cls,
284 const struct GNUNET_CONFIGURATION_Handle *cfg, 280 const struct GNUNET_CONFIGURATION_Handle *cfg,
285 struct GNUNET_TESTING_Peer *peer) 281 struct GNUNET_TESTING_Peer *peer)
286{ 282{
287 char *hostkey_file;
288
289 res = 1; 283 res = 1;
290 284 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
291 directory = NULL;
292 GNUNET_assert (GNUNET_OK ==
293 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
294 GNUNET_DISK_directory_remove (directory);
295
296 GNUNET_asprintf(&hostkey_file,
297 "zonefiles%s%s",
298 DIR_SEPARATOR_STR,
299 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
301 "Using zonekey file `%s' \n", hostkey_file);
302 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
303 GNUNET_free (hostkey_file);
304 GNUNET_assert (privkey != NULL); 285 GNUNET_assert (privkey != NULL);
305 286
306 /* Start monitoring */ 287 /* Start monitoring */
@@ -333,16 +314,12 @@ run (void *cls,
333 return; 314 return;
334 } 315 }
335 316
336 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s", 317 privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
337 DIR_SEPARATOR_STR,
338 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
340 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
341 GNUNET_free (hostkey_file);
342 GNUNET_assert (privkey2 != NULL); 318 GNUNET_assert (privkey2 != NULL);
343 319
344 320
345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); 321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
322 "Created record 3\n");
346 /* name in different zone */ 323 /* name in different zone */
347 GNUNET_asprintf(&s_name_3, "dummy3"); 324 GNUNET_asprintf(&s_name_3, "dummy3");
348 s_rd_3 = create_record(1); 325 s_rd_3 = create_record(1);
@@ -358,22 +335,33 @@ run (void *cls,
358 "Created record 1\n"); 335 "Created record 1\n");
359 GNUNET_asprintf(&s_name_1, "dummy1"); 336 GNUNET_asprintf(&s_name_1, "dummy1");
360 s_rd_1 = create_record(1); 337 s_rd_1 = create_record(1);
361 GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, 338 GNUNET_assert (NULL != (ns_ops[0] =
362 1, s_rd_1, &put_cont, s_name_1))); 339 GNUNET_NAMESTORE_records_store (nsh,
340 privkey,
341 s_name_1,
342 1,
343 s_rd_1,
344 &put_cont,
345 s_name_1)));
363 346
364 347
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); 348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
366 GNUNET_asprintf(&s_name_2, "dummy2"); 349 GNUNET_asprintf(&s_name_2, "dummy2");
367 s_rd_2 = create_record(1); 350 s_rd_2 = create_record(1);
368 GNUNET_assert (NULL != (ns_ops[1] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, 351 GNUNET_assert (NULL != (ns_ops[1] =
369 1, s_rd_2, &put_cont, s_name_2))); 352 GNUNET_NAMESTORE_records_store (nsh,
370 353 privkey,
371 354 s_name_2,
355 1,
356 s_rd_2,
357 &put_cont,
358 s_name_2)));
372} 359}
373 360
374 361
375int 362int
376main (int argc, char *argv[]) 363main (int argc,
364 char *argv[])
377{ 365{
378 const char *plugin_name; 366 const char *plugin_name;
379 char *cfg_name; 367 char *cfg_name;
@@ -382,6 +370,8 @@ main (int argc, char *argv[])
382 GNUNET_asprintf (&cfg_name, 370 GNUNET_asprintf (&cfg_name,
383 "test_namestore_api_%s.conf", 371 "test_namestore_api_%s.conf",
384 plugin_name); 372 plugin_name);
373 GNUNET_DISK_purge_cfg_dir (cfg_name,
374 "GNUNET_TEST_HOME");
385 res = 1; 375 res = 1;
386 if (0 != 376 if (0 !=
387 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring", 377 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring",
@@ -391,12 +381,9 @@ main (int argc, char *argv[])
391 { 381 {
392 res = 1; 382 res = 1;
393 } 383 }
384 GNUNET_DISK_purge_cfg_dir (cfg_name,
385 "GNUNET_TEST_HOME");
394 GNUNET_free (cfg_name); 386 GNUNET_free (cfg_name);
395 if (NULL != directory)
396 {
397 GNUNET_DISK_directory_remove (directory);
398 GNUNET_free (directory);
399 }
400 return res; 387 return res;
401} 388}
402 389
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c
index f6a74609e..25c098fe3 100644
--- a/src/namestore/test_namestore_api_monitoring_existing.c
+++ b/src/namestore/test_namestore_api_monitoring_existing.c
@@ -57,8 +57,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
57 57
58struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; 58struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
59 59
60static char *directory;
61
62 60
63static void 61static void
64do_shutdown () 62do_shutdown ()
@@ -316,30 +314,14 @@ run (void *cls,
316 const struct GNUNET_CONFIGURATION_Handle *mycfg, 314 const struct GNUNET_CONFIGURATION_Handle *mycfg,
317 struct GNUNET_TESTING_Peer *peer) 315 struct GNUNET_TESTING_Peer *peer)
318{ 316{
319 char *hostkey_file;
320
321 directory = NULL;
322 GNUNET_assert (GNUNET_OK ==
323 GNUNET_CONFIGURATION_get_value_string (mycfg,
324 "PATHS",
325 "GNUNET_TEST_HOME",
326 &directory));
327 GNUNET_DISK_directory_remove (directory);
328
329 res = 1; 317 res = 1;
330 318 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
331 GNUNET_asprintf(&hostkey_file,
332 "zonefiles%s%s",
333 DIR_SEPARATOR_STR,
334 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "Using zonekey file `%s' \n", hostkey_file);
337 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
338 GNUNET_free (hostkey_file);
339 GNUNET_assert (privkey != NULL); 319 GNUNET_assert (privkey != NULL);
340 320
341 cfg = mycfg; 321 cfg = mycfg;
342 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); 322 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
323 &endbadly,
324 NULL);
343 /* Connect to namestore */ 325 /* Connect to namestore */
344 nsh = GNUNET_NAMESTORE_connect (cfg); 326 nsh = GNUNET_NAMESTORE_connect (cfg);
345 if (NULL == nsh) 327 if (NULL == nsh)
@@ -350,12 +332,7 @@ run (void *cls,
350 return; 332 return;
351 } 333 }
352 334
353 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s", 335 privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
354 DIR_SEPARATOR_STR,
355 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
357 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
358 GNUNET_free (hostkey_file);
359 GNUNET_assert (privkey2 != NULL); 336 GNUNET_assert (privkey2 != NULL);
360 337
361 338
@@ -397,6 +374,8 @@ main (int argc, char *argv[])
397 "test_namestore_api_%s.conf", 374 "test_namestore_api_%s.conf",
398 plugin_name); 375 plugin_name);
399 res = 1; 376 res = 1;
377 GNUNET_DISK_purge_cfg_dir (cfg_name,
378 "GNUNET_TEST_HOME");
400 if (0 != 379 if (0 !=
401 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing", 380 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing",
402 cfg_name, 381 cfg_name,
@@ -405,12 +384,9 @@ main (int argc, char *argv[])
405 { 384 {
406 res = 1; 385 res = 1;
407 } 386 }
387 GNUNET_DISK_purge_cfg_dir (cfg_name,
388 "GNUNET_TEST_HOME");
408 GNUNET_free (cfg_name); 389 GNUNET_free (cfg_name);
409 if (NULL != directory)
410 {
411 GNUNET_DISK_directory_remove (directory);
412 GNUNET_free (directory);
413 }
414 return res; 390 return res;
415} 391}
416 392
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c
index 532a751da..c9e2802bd 100644
--- a/src/namestore/test_namestore_api_remove.c
+++ b/src/namestore/test_namestore_api_remove.c
@@ -48,7 +48,6 @@ static int removed;
48 48
49static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 49static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
50 50
51static char *directory;
52 51
53static void 52static void
54cleanup () 53cleanup ()
@@ -157,29 +156,12 @@ run (void *cls,
157 struct GNUNET_TESTING_Peer *peer) 156 struct GNUNET_TESTING_Peer *peer)
158{ 157{
159 struct GNUNET_GNSRECORD_Data rd; 158 struct GNUNET_GNSRECORD_Data rd;
160 char *hostkey_file;
161 const char * name = "dummy.dummy.gnunet"; 159 const char * name = "dummy.dummy.gnunet";
162 160
163 directory = NULL;
164 GNUNET_assert (GNUNET_OK ==
165 GNUNET_CONFIGURATION_get_value_string(cfg,
166 "PATHS",
167 "GNUNET_TEST_HOME",
168 &directory));
169 GNUNET_DISK_directory_remove (directory);
170
171 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 161 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
172 &endbadly, 162 &endbadly,
173 NULL); 163 NULL);
174 GNUNET_asprintf (&hostkey_file, 164 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
175 "zonefiles%s%s",
176 DIR_SEPARATOR_STR,
177 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
179 "Using zonekey file `%s' \n",
180 hostkey_file);
181 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
182 GNUNET_free (hostkey_file);
183 GNUNET_assert (privkey != NULL); 165 GNUNET_assert (privkey != NULL);
184 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 166 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
185 &pubkey); 167 &pubkey);
@@ -191,12 +173,19 @@ run (void *cls,
191 rd.data_size = TEST_RECORD_DATALEN; 173 rd.data_size = TEST_RECORD_DATALEN;
192 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 174 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
193 rd.flags = 0; 175 rd.flags = 0;
194 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); 176 memset ((char *) rd.data,
177 'a',
178 TEST_RECORD_DATALEN);
195 179
196 nsh = GNUNET_NAMESTORE_connect (cfg); 180 nsh = GNUNET_NAMESTORE_connect (cfg);
197 GNUNET_break (NULL != nsh); 181 GNUNET_break (NULL != nsh);
198 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 182 nsqe = GNUNET_NAMESTORE_records_store (nsh,
199 1, &rd, &put_cont, (void *) name); 183 privkey,
184 name,
185 1,
186 &rd,
187 &put_cont,
188 (void *) name);
200 if (NULL == nsqe) 189 if (NULL == nsqe)
201 { 190 {
202 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -216,6 +205,8 @@ main (int argc, char *argv[])
216 GNUNET_asprintf (&cfg_name, 205 GNUNET_asprintf (&cfg_name,
217 "test_namestore_api_%s.conf", 206 "test_namestore_api_%s.conf",
218 plugin_name); 207 plugin_name);
208 GNUNET_DISK_purge_cfg_dir (cfg_name,
209 "GNUNET_TEST_HOME");
219 res = 1; 210 res = 1;
220 if (0 != 211 if (0 !=
221 GNUNET_TESTING_peer_run ("test-namestore-api-remove", 212 GNUNET_TESTING_peer_run ("test-namestore-api-remove",
@@ -225,12 +216,9 @@ main (int argc, char *argv[])
225 { 216 {
226 res = 1; 217 res = 1;
227 } 218 }
219 GNUNET_DISK_purge_cfg_dir (cfg_name,
220 "GNUNET_TEST_HOME");
228 GNUNET_free (cfg_name); 221 GNUNET_free (cfg_name);
229 if (NULL != directory)
230 {
231 GNUNET_DISK_directory_remove (directory);
232 GNUNET_free (directory);
233 }
234 return res; 222 return res;
235} 223}
236 224
diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c b/src/namestore/test_namestore_api_remove_not_existing_record.c
index 2f20c3636..d0438a7e1 100644
--- a/src/namestore/test_namestore_api_remove_not_existing_record.c
+++ b/src/namestore/test_namestore_api_remove_not_existing_record.c
@@ -46,7 +46,6 @@ static int res;
46 46
47static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 47static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
48 48
49static char *directory;
50 49
51static void 50static void
52cleanup () 51cleanup ()
@@ -92,7 +91,9 @@ end (void *cls)
92 91
93 92
94static void 93static void
95put_cont (void *cls, int32_t success, const char *emsg) 94put_cont (void *cls,
95 int32_t success,
96 const char *emsg)
96{ 97{
97 GNUNET_assert (NULL != cls); 98 GNUNET_assert (NULL != cls);
98 nsqe = NULL; 99 nsqe = NULL;
@@ -101,8 +102,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
101 GNUNET_SCHEDULER_cancel (endbadly_task); 102 GNUNET_SCHEDULER_cancel (endbadly_task);
102 endbadly_task = NULL; 103 endbadly_task = NULL;
103 } 104 }
104 105 switch (success)
105 switch (success) { 106 {
106 case GNUNET_NO: 107 case GNUNET_NO:
107 /* We expected GNUNET_NO, since record was not found */ 108 /* We expected GNUNET_NO, since record was not found */
108 GNUNET_SCHEDULER_add_now (&end, NULL); 109 GNUNET_SCHEDULER_add_now (&end, NULL);
@@ -129,25 +130,12 @@ run (void *cls,
129 const struct GNUNET_CONFIGURATION_Handle *cfg, 130 const struct GNUNET_CONFIGURATION_Handle *cfg,
130 struct GNUNET_TESTING_Peer *peer) 131 struct GNUNET_TESTING_Peer *peer)
131{ 132{
132 char *hostkey_file;
133 const char * name = "dummy.dummy.gnunet"; 133 const char * name = "dummy.dummy.gnunet";
134 134
135 directory = NULL;
136 GNUNET_assert (GNUNET_OK ==
137 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
138 GNUNET_DISK_directory_remove (directory);
139
140 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 135 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
141 &endbadly, NULL); 136 &endbadly,
142 GNUNET_asprintf (&hostkey_file, 137 NULL);
143 "zonefiles%s%s", 138 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
144 DIR_SEPARATOR_STR,
145 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "Using zonekey file `%s' \n",
148 hostkey_file);
149 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
150 GNUNET_free (hostkey_file);
151 GNUNET_assert (privkey != NULL); 139 GNUNET_assert (privkey != NULL);
152 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 140 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
153 141
@@ -174,6 +162,8 @@ main (int argc, char *argv[])
174 GNUNET_asprintf (&cfg_name, 162 GNUNET_asprintf (&cfg_name,
175 "test_namestore_api_%s.conf", 163 "test_namestore_api_%s.conf",
176 plugin_name); 164 plugin_name);
165 GNUNET_DISK_purge_cfg_dir (cfg_name,
166 "GNUNET_TEST_HOME");
177 res = 1; 167 res = 1;
178 if (0 != 168 if (0 !=
179 GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record", 169 GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record",
@@ -183,12 +173,9 @@ main (int argc, char *argv[])
183 { 173 {
184 res = 1; 174 res = 1;
185 } 175 }
176 GNUNET_DISK_purge_cfg_dir (cfg_name,
177 "GNUNET_TEST_HOME");
186 GNUNET_free (cfg_name); 178 GNUNET_free (cfg_name);
187 if (NULL != directory)
188 {
189 GNUNET_DISK_directory_remove (directory);
190 GNUNET_free (directory);
191 }
192 return res; 179 return res;
193} 180}
194 181
diff --git a/src/namestore/test_namestore_api_store.c b/src/namestore/test_namestore_api_store.c
index 4e51678a1..4abcfa4d3 100644
--- a/src/namestore/test_namestore_api_store.c
+++ b/src/namestore/test_namestore_api_store.c
@@ -46,7 +46,6 @@ static int res;
46 46
47static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 47static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
48 48
49static char *directory;
50 49
51static void 50static void
52cleanup () 51cleanup ()
@@ -114,23 +113,11 @@ run (void *cls,
114 struct GNUNET_TESTING_Peer *peer) 113 struct GNUNET_TESTING_Peer *peer)
115{ 114{
116 struct GNUNET_GNSRECORD_Data rd; 115 struct GNUNET_GNSRECORD_Data rd;
117 char *hostkey_file;
118 const char * name = "dummy.dummy.gnunet"; 116 const char * name = "dummy.dummy.gnunet";
119 117
120 directory = NULL;
121 GNUNET_assert (GNUNET_OK ==
122 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
123 GNUNET_DISK_directory_remove (directory);
124
125 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 118 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
126 &endbadly, NULL); 119 &endbadly, NULL);
127 GNUNET_asprintf (&hostkey_file, 120 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
128 "zonefiles%s%s",
129 DIR_SEPARATOR_STR,
130 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
132 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
133 GNUNET_free (hostkey_file);
134 GNUNET_assert (privkey != NULL); 121 GNUNET_assert (privkey != NULL);
135 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 122 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
136 123
@@ -144,8 +131,13 @@ run (void *cls,
144 131
145 nsh = GNUNET_NAMESTORE_connect (cfg); 132 nsh = GNUNET_NAMESTORE_connect (cfg);
146 GNUNET_break (NULL != nsh); 133 GNUNET_break (NULL != nsh);
147 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 134 nsqe = GNUNET_NAMESTORE_records_store (nsh,
148 1, &rd, &put_cont, (void *) name); 135 privkey,
136 name,
137 1,
138 &rd,
139 &put_cont,
140 (void *) name);
149 if (NULL == nsqe) 141 if (NULL == nsqe)
150 { 142 {
151 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 143 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -167,6 +159,8 @@ main (int argc, char *argv[])
167 "test_namestore_api_%s.conf", 159 "test_namestore_api_%s.conf",
168 plugin_name); 160 plugin_name);
169 res = 1; 161 res = 1;
162 GNUNET_DISK_purge_cfg_dir (cfg_name,
163 "GNUNET_TEST_HOME");
170 if (0 != 164 if (0 !=
171 GNUNET_TESTING_peer_run ("test-namestore-api", 165 GNUNET_TESTING_peer_run ("test-namestore-api",
172 cfg_name, 166 cfg_name,
@@ -175,12 +169,9 @@ main (int argc, char *argv[])
175 { 169 {
176 res = 1; 170 res = 1;
177 } 171 }
172 GNUNET_DISK_purge_cfg_dir (cfg_name,
173 "GNUNET_TEST_HOME");
178 GNUNET_free (cfg_name); 174 GNUNET_free (cfg_name);
179 if (NULL != directory)
180 {
181 GNUNET_DISK_directory_remove (directory);
182 GNUNET_free (directory);
183 }
184 return res; 175 return res;
185} 176}
186 177
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c
index 0a4551f21..7b13cd9c5 100644
--- a/src/namestore/test_namestore_api_store_update.c
+++ b/src/namestore/test_namestore_api_store_update.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013 GNUnet e.V. 3 Copyright (C) 2012, 2013, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -21,6 +21,7 @@
21 * @file namestore/test_namestore_api_store_update.c 21 * @file namestore/test_namestore_api_store_update.c
22 * @brief testcase for namestore_api.c: store a record, update it and perform a lookup 22 * @brief testcase for namestore_api.c: store a record, update it and perform a lookup
23 * @author Matthias Wachs 23 * @author Matthias Wachs
24 * @author Christian Grothoff
24 */ 25 */
25#include "platform.h" 26#include "platform.h"
26#include "gnunet_namecache_service.h" 27#include "gnunet_namecache_service.h"
@@ -33,7 +34,6 @@
33 34
34#define TEST_RECORD_DATA 'a' 35#define TEST_RECORD_DATA 'a'
35 36
36
37#define TEST_RECORD_TYPE2 4321 37#define TEST_RECORD_TYPE2 4321
38 38
39#define TEST_RECORD_DATALEN2 234 39#define TEST_RECORD_DATALEN2 234
@@ -63,38 +63,30 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
63 63
64static const char *name = "dummy"; 64static const char *name = "dummy";
65 65
66static char *directory;
67 66
67/**
68 * Terminate test with error.
69 *
70 * @param cls handle to use to re-connect.
71 */
68static void 72static void
69cleanup () 73endbadly (void *cls)
70{ 74{
71 if (NULL != nsh) 75 GNUNET_break (0);
72 { 76 endbadly_task = NULL;
73 GNUNET_NAMESTORE_disconnect (nsh);
74 nsh = NULL;
75 }
76 if (NULL != nch)
77 {
78 GNUNET_NAMECACHE_disconnect (nch);
79 nch = NULL;
80 }
81 if (NULL != privkey)
82 {
83 GNUNET_free (privkey);
84 privkey = NULL;
85 }
86 GNUNET_SCHEDULER_shutdown (); 77 GNUNET_SCHEDULER_shutdown ();
78 res = 1;
87} 79}
88 80
89 81
90/**
91 * Re-establish the connection to the service.
92 *
93 * @param cls handle to use to re-connect.
94 */
95static void 82static void
96endbadly (void *cls) 83end (void *cls)
97{ 84{
85 if (NULL != endbadly_task)
86 {
87 GNUNET_SCHEDULER_cancel (endbadly_task);
88 endbadly_task = NULL;
89 }
98 if (NULL != nsqe) 90 if (NULL != nsqe)
99 { 91 {
100 GNUNET_NAMESTORE_cancel (nsqe); 92 GNUNET_NAMESTORE_cancel (nsqe);
@@ -105,21 +97,28 @@ endbadly (void *cls)
105 GNUNET_NAMECACHE_cancel (ncqe); 97 GNUNET_NAMECACHE_cancel (ncqe);
106 ncqe = NULL; 98 ncqe = NULL;
107 } 99 }
108 cleanup (); 100 if (NULL != nsh)
109 res = 1; 101 {
110} 102 GNUNET_NAMESTORE_disconnect (nsh);
111 103 nsh = NULL;
112 104 }
113static void 105 if (NULL != nch)
114end (void *cls) 106 {
115{ 107 GNUNET_NAMECACHE_disconnect (nch);
116 cleanup (); 108 nch = NULL;
117 res = 0; 109 }
110 if (NULL != privkey)
111 {
112 GNUNET_free (privkey);
113 privkey = NULL;
114 }
118} 115}
119 116
120 117
121static void 118static void
122put_cont (void *cls, int32_t success, const char *emsg); 119put_cont (void *cls,
120 int32_t success,
121 const char *emsg);
123 122
124 123
125static void 124static void
@@ -135,11 +134,15 @@ rd_decrypt_cb (void *cls,
135 if (GNUNET_NO == update_performed) 134 if (GNUNET_NO == update_performed)
136 { 135 {
137 char rd_cmp_data[TEST_RECORD_DATALEN]; 136 char rd_cmp_data[TEST_RECORD_DATALEN];
138 memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
139 137
138 memset (rd_cmp_data,
139 TEST_RECORD_DATA,
140 TEST_RECORD_DATALEN);
140 GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); 141 GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type);
141 GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); 142 GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size);
142 GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)); 143 GNUNET_assert (0 == memcmp (&rd_cmp_data,
144 rd[0].data,
145 TEST_RECORD_DATALEN));
143 146
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "Block was decrypted successfully, updating record \n"); 148 "Block was decrypted successfully, updating record \n");
@@ -149,24 +152,33 @@ rd_decrypt_cb (void *cls,
149 rd_new.record_type = TEST_RECORD_TYPE2; 152 rd_new.record_type = TEST_RECORD_TYPE2;
150 rd_new.data_size = TEST_RECORD_DATALEN2; 153 rd_new.data_size = TEST_RECORD_DATALEN2;
151 rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); 154 rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2);
152 memset ((char *) rd_new.data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2); 155 memset ((char *) rd_new.data,
156 TEST_RECORD_DATA2,
157 TEST_RECORD_DATALEN2);
153 158
154 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 159 nsqe = GNUNET_NAMESTORE_records_store (nsh,
155 1, &rd_new, &put_cont, (void *) name); 160 privkey,
161 name,
162 1,
163 &rd_new,
164 &put_cont,
165 (void *) name);
156 update_performed = GNUNET_YES; 166 update_performed = GNUNET_YES;
157 } 167 }
158 else 168 else
159 { 169 {
160 char rd_cmp_data[TEST_RECORD_DATALEN2]; 170 char rd_cmp_data[TEST_RECORD_DATALEN2];
161 memset (rd_cmp_data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2);
162 171
172 memset (rd_cmp_data,
173 TEST_RECORD_DATA2,
174 TEST_RECORD_DATALEN2);
163 GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type); 175 GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type);
164 GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); 176 GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size);
165 GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN2)); 177 GNUNET_assert (0 == memcmp (&rd_cmp_data,
166 178 rd[0].data,
167 GNUNET_SCHEDULER_cancel (endbadly_task); 179 TEST_RECORD_DATALEN2));
168 endbadly_task = NULL; 180 GNUNET_SCHEDULER_shutdown ();
169 GNUNET_SCHEDULER_add_now (&end, NULL); 181 res = 0;
170 } 182 }
171} 183}
172 184
@@ -184,21 +196,25 @@ name_lookup_proc (void *cls,
184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
185 _("Namecache returned no block for `%s'\n"), 197 _("Namecache returned no block for `%s'\n"),
186 name); 198 name);
187 if (endbadly_task != NULL) 199 GNUNET_SCHEDULER_shutdown ();
188 GNUNET_SCHEDULER_cancel (endbadly_task);
189 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
190 return; 200 return;
191 } 201 }
192 202
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Namecache returned block, decrypting \n"); 204 "Namecache returned block, decrypting \n");
195 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, 205 GNUNET_assert (GNUNET_OK ==
196 &pubkey, name, &rd_decrypt_cb, (void *) name)); 206 GNUNET_GNSRECORD_block_decrypt (block,
207 &pubkey,
208 name,
209 &rd_decrypt_cb,
210 (void *) name));
197} 211}
198 212
199 213
200static void 214static void
201put_cont (void *cls, int32_t success, const char *emsg) 215put_cont (void *cls,
216 int32_t success,
217 const char *emsg)
202{ 218{
203 const char *name = cls; 219 const char *name = cls;
204 struct GNUNET_HashCode derived_hash; 220 struct GNUNET_HashCode derived_hash;
@@ -216,7 +232,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
217 "Looking in namecache for `%s'\n", 233 "Looking in namecache for `%s'\n",
218 GNUNET_h2s (&derived_hash)); 234 GNUNET_h2s (&derived_hash));
219 ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, 235 ncqe = GNUNET_NAMECACHE_lookup_block (nch,
236 &derived_hash,
220 &name_lookup_proc, (void *) name); 237 &name_lookup_proc, (void *) name);
221} 238}
222 239
@@ -227,41 +244,37 @@ run (void *cls,
227 struct GNUNET_TESTING_Peer *peer) 244 struct GNUNET_TESTING_Peer *peer)
228{ 245{
229 struct GNUNET_GNSRECORD_Data rd; 246 struct GNUNET_GNSRECORD_Data rd;
230 char *hostkey_file;
231
232 directory = NULL;
233 GNUNET_assert (GNUNET_OK ==
234 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
235 GNUNET_DISK_directory_remove (directory);
236 247
237 update_performed = GNUNET_NO; 248 update_performed = GNUNET_NO;
249 GNUNET_SCHEDULER_add_shutdown (&end,
250 NULL);
238 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 251 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
239 &endbadly, NULL); 252 &endbadly,
240 GNUNET_asprintf (&hostkey_file, 253 NULL);
241 "zonefiles%s%s", 254 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
242 DIR_SEPARATOR_STR,
243 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
245 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
246 GNUNET_free (hostkey_file);
247 GNUNET_assert (privkey != NULL); 255 GNUNET_assert (privkey != NULL);
248 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 256 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
249 257 &pubkey);
250 rd.flags = GNUNET_GNSRECORD_RF_NONE; 258 rd.flags = GNUNET_GNSRECORD_RF_NONE;
251 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 259 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
252 rd.record_type = TEST_RECORD_TYPE; 260 rd.record_type = TEST_RECORD_TYPE;
253 rd.data_size = TEST_RECORD_DATALEN; 261 rd.data_size = TEST_RECORD_DATALEN;
254 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 262 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
255 memset ((char *) rd.data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); 263 memset ((char *) rd.data,
264 TEST_RECORD_DATA,
265 TEST_RECORD_DATALEN);
256 266
257 nsh = GNUNET_NAMESTORE_connect (cfg); 267 nsh = GNUNET_NAMESTORE_connect (cfg);
258 GNUNET_break (NULL != nsh); 268 GNUNET_break (NULL != nsh);
259 nch = GNUNET_NAMECACHE_connect (cfg); 269 nch = GNUNET_NAMECACHE_connect (cfg);
260 GNUNET_break (NULL != nch); 270 GNUNET_break (NULL != nch);
261 nsqe = GNUNET_NAMESTORE_records_store (nsh, 271 nsqe = GNUNET_NAMESTORE_records_store (nsh,
262 privkey, name, 272 privkey,
263 1, &rd, 273 name,
264 &put_cont, (void *) name); 274 1,
275 &rd,
276 &put_cont,
277 (void *) name);
265 if (NULL == nsqe) 278 if (NULL == nsqe)
266 { 279 {
267 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -272,7 +285,8 @@ run (void *cls,
272 285
273 286
274int 287int
275main (int argc, char *argv[]) 288main (int argc,
289 char *argv[])
276{ 290{
277 const char *plugin_name; 291 const char *plugin_name;
278 char *cfg_name; 292 char *cfg_name;
@@ -282,6 +296,8 @@ main (int argc, char *argv[])
282 "test_namestore_api_%s.conf", 296 "test_namestore_api_%s.conf",
283 plugin_name); 297 plugin_name);
284 res = 1; 298 res = 1;
299 GNUNET_DISK_purge_cfg_dir (cfg_name,
300 "GNUNET_TEST_HOME");
285 if (0 != 301 if (0 !=
286 GNUNET_TESTING_peer_run ("test-namestore-api-store-update", 302 GNUNET_TESTING_peer_run ("test-namestore-api-store-update",
287 cfg_name, 303 cfg_name,
@@ -290,14 +306,11 @@ main (int argc, char *argv[])
290 { 306 {
291 res = 1; 307 res = 1;
292 } 308 }
309 GNUNET_DISK_purge_cfg_dir (cfg_name,
310 "GNUNET_TEST_HOME");
293 GNUNET_free (cfg_name); 311 GNUNET_free (cfg_name);
294 if (NULL != directory)
295 {
296 GNUNET_DISK_directory_remove (directory);
297 GNUNET_free (directory);
298 }
299 return res; 312 return res;
300} 313}
301 314
302 315
303/* end of test_namestore_api_store_update.c*/ 316/* end of test_namestore_api_store_update.c */
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c
index 806605d94..68c3de9b8 100644
--- a/src/namestore/test_namestore_api_zone_iteration.c
+++ b/src/namestore/test_namestore_api_zone_iteration.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V. 3 Copyright (C) 2013, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -56,8 +56,6 @@ static char * s_name_3;
56 56
57static struct GNUNET_GNSRECORD_Data *s_rd_3; 57static struct GNUNET_GNSRECORD_Data *s_rd_3;
58 58
59static char *directory;
60
61 59
62/** 60/**
63 * Re-establish the connection to the service. 61 * Re-establish the connection to the service.
@@ -68,43 +66,8 @@ static char *directory;
68static void 66static void
69endbadly (void *cls) 67endbadly (void *cls)
70{ 68{
71 if (NULL != zi) 69 endbadly_task = NULL;
72 { 70 GNUNET_SCHEDULER_shutdown ();
73 GNUNET_NAMESTORE_zone_iteration_stop (zi);
74 zi = NULL;
75 }
76 if (nsh != NULL)
77 {
78 GNUNET_NAMESTORE_disconnect (nsh);
79 nsh = NULL;
80 }
81 GNUNET_free_non_null(s_name_1);
82 GNUNET_free_non_null(s_name_2);
83 GNUNET_free_non_null(s_name_3);
84
85 if (s_rd_1 != NULL)
86 {
87 GNUNET_free ((void *)s_rd_1->data);
88 GNUNET_free (s_rd_1);
89 }
90 if (s_rd_2 != NULL)
91 {
92 GNUNET_free ((void *)s_rd_2->data);
93 GNUNET_free (s_rd_2);
94 }
95 if (s_rd_3 != NULL)
96 {
97 GNUNET_free ((void *)s_rd_3->data);
98 GNUNET_free (s_rd_3);
99 }
100
101 if (privkey != NULL)
102 GNUNET_free (privkey);
103 privkey = NULL;
104
105 if (privkey2 != NULL)
106 GNUNET_free (privkey2);
107 privkey2 = NULL;
108 res = 1; 71 res = 1;
109} 72}
110 73
@@ -117,41 +80,44 @@ end (void *cls)
117 GNUNET_NAMESTORE_zone_iteration_stop (zi); 80 GNUNET_NAMESTORE_zone_iteration_stop (zi);
118 zi = NULL; 81 zi = NULL;
119 } 82 }
120 if (endbadly_task != NULL) 83 if (NULL != endbadly_task)
121 { 84 {
122 GNUNET_SCHEDULER_cancel (endbadly_task); 85 GNUNET_SCHEDULER_cancel (endbadly_task);
123 endbadly_task = NULL; 86 endbadly_task = NULL;
124 } 87 }
125 88 if (NULL != privkey)
126 if (privkey != NULL) 89 {
127 GNUNET_free (privkey); 90 GNUNET_free (privkey);
128 privkey = NULL; 91 privkey = NULL;
129 92 }
130 if (privkey2 != NULL) 93 if (NULL != privkey2)
94 {
131 GNUNET_free (privkey2); 95 GNUNET_free (privkey2);
132 privkey2 = NULL; 96 privkey2 = NULL;
133 97 }
134 GNUNET_free (s_name_1); 98 GNUNET_free (s_name_1);
135 GNUNET_free (s_name_2); 99 GNUNET_free (s_name_2);
136 GNUNET_free (s_name_3); 100 GNUNET_free (s_name_3);
137 if (s_rd_1 != NULL) 101 if (NULL != s_rd_1)
138 { 102 {
139 GNUNET_free ((void *)s_rd_1->data); 103 GNUNET_free ((void *)s_rd_1->data);
140 GNUNET_free (s_rd_1); 104 GNUNET_free (s_rd_1);
141 } 105 }
142 if (s_rd_2 != NULL) 106 if (NULL != s_rd_2)
143 { 107 {
144 GNUNET_free ((void *)s_rd_2->data); 108 GNUNET_free ((void *)s_rd_2->data);
145 GNUNET_free (s_rd_2); 109 GNUNET_free (s_rd_2);
146 } 110 }
147 if (s_rd_3 != NULL) 111 if (NULL != s_rd_3)
148 { 112 {
149 GNUNET_free ((void *)s_rd_3->data); 113 GNUNET_free ((void *)s_rd_3->data);
150 GNUNET_free (s_rd_3); 114 GNUNET_free (s_rd_3);
151 } 115 }
152 if (nsh != NULL) 116 if (NULL != nsh)
117 {
153 GNUNET_NAMESTORE_disconnect (nsh); 118 GNUNET_NAMESTORE_disconnect (nsh);
154 nsh = NULL; 119 nsh = NULL;
120 }
155} 121}
156 122
157 123
@@ -170,7 +136,7 @@ zone_end (void *cls)
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "Received last result, iteration done after receing %u results\n", 137 "Received last result, iteration done after receing %u results\n",
172 returned_records); 138 returned_records);
173 GNUNET_SCHEDULER_add_now (&end, NULL); 139 GNUNET_SCHEDULER_shutdown ();
174} 140}
175 141
176 142
@@ -191,7 +157,9 @@ zone_proc (void *cls,
191 int failed = GNUNET_NO; 157 int failed = GNUNET_NO;
192 158
193 GNUNET_assert (NULL != zone); 159 GNUNET_assert (NULL != zone);
194 if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 160 if (0 == memcmp (zone,
161 privkey,
162 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
195 { 163 {
196 if (0 == strcmp (label, s_name_1)) 164 if (0 == strcmp (label, s_name_1))
197 { 165 {
@@ -230,12 +198,15 @@ zone_proc (void *cls,
230 else 198 else
231 { 199 {
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 "Comparing result failed: got name `%s' for first zone\n", label); 201 "Comparing result failed: got name `%s' for first zone\n",
202 label);
234 failed = GNUNET_YES; 203 failed = GNUNET_YES;
235 GNUNET_break (0); 204 GNUNET_break (0);
236 } 205 }
237 } 206 }
238 else if (0 == memcmp (zone, privkey2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 207 else if (0 == memcmp (zone,
208 privkey2,
209 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
239 { 210 {
240 if (0 == strcmp (label, s_name_3)) 211 if (0 == strcmp (label, s_name_3))
241 { 212 {
@@ -258,7 +229,8 @@ zone_proc (void *cls,
258 else 229 else
259 { 230 {
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
261 "Comparing result failed: got name `%s' for first zone\n", label); 232 "Comparing result failed: got name `%s' for first zone\n",
233 label);
262 failed = GNUNET_YES; 234 failed = GNUNET_YES;
263 GNUNET_break (0); 235 GNUNET_break (0);
264 } 236 }
@@ -282,29 +254,34 @@ zone_proc (void *cls,
282 else 254 else
283 { 255 {
284 GNUNET_break (0); 256 GNUNET_break (0);
285 GNUNET_SCHEDULER_add_now (&end, NULL); 257 GNUNET_SCHEDULER_shutdown ();
258 res = 1;
286 } 259 }
287} 260}
288 261
289 262
290static void 263static void
291put_cont (void *cls, int32_t success, const char *emsg) 264put_cont (void *cls,
265 int32_t success,
266 const char *emsg)
292{ 267{
293 static int c = 0; 268 static int c = 0;
294 269
295 if (success == GNUNET_OK) 270 if (success == GNUNET_OK)
296 { 271 {
297 c++; 272 c++;
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); 273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
274 "Created record %u \n",
275 c);
299 } 276 }
300 else 277 else
301 { 278 {
302 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", 279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
280 "Failed to created records: `%s'\n",
303 emsg); 281 emsg);
304 GNUNET_break (0); 282 GNUNET_break (0);
305 if (NULL != endbadly_task) 283 GNUNET_SCHEDULER_shutdown ();
306 GNUNET_SCHEDULER_cancel (endbadly_task); 284 res = 1;
307 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
308 return; 285 return;
309 } 286 }
310 287
@@ -312,7 +289,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
312 { 289 {
313 res = 1; 290 res = 1;
314 returned_records = 0; 291 returned_records = 0;
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); 292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "All records created, starting iteration over all zones \n");
316 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, 294 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
317 NULL, 295 NULL,
318 &fail_cb, 296 &fail_cb,
@@ -323,11 +301,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
323 NULL); 301 NULL);
324 if (zi == NULL) 302 if (zi == NULL)
325 { 303 {
326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); 304 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
305 "Failed to create zone iterator\n");
327 GNUNET_break (0); 306 GNUNET_break (0);
328 if (NULL != endbadly_task) 307 GNUNET_SCHEDULER_shutdown ();
329 GNUNET_SCHEDULER_cancel (endbadly_task); 308 res = 1;
330 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
331 return; 309 return;
332 } 310 }
333 } 311 }
@@ -337,11 +315,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
337static struct GNUNET_GNSRECORD_Data * 315static struct GNUNET_GNSRECORD_Data *
338create_record (unsigned int count) 316create_record (unsigned int count)
339{ 317{
340 unsigned int c;
341 struct GNUNET_GNSRECORD_Data * rd; 318 struct GNUNET_GNSRECORD_Data * rd;
342 319
343 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 320 rd = GNUNET_new_array (count,
344 for (c = 0; c < count; c++) 321 struct GNUNET_GNSRECORD_Data);
322 for (unsigned int c = 0; c < count; c++)
345 { 323 {
346 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 324 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
347 rd[c].record_type = 1111; 325 rd[c].record_type = 1111;
@@ -372,9 +350,8 @@ empty_zone_proc (void *cls,
372 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
373 _("Expected empty zone but received zone private key\n")); 351 _("Expected empty zone but received zone private key\n"));
374 GNUNET_break (0); 352 GNUNET_break (0);
375 if (endbadly_task != NULL) 353 GNUNET_SCHEDULER_shutdown ();
376 GNUNET_SCHEDULER_cancel (endbadly_task); 354 res = 1;
377 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
378 return; 355 return;
379 } 356 }
380 if ((NULL != label) || (NULL != rd) || (0 != rd_count)) 357 if ((NULL != label) || (NULL != rd) || (0 != rd_count))
@@ -382,9 +359,8 @@ empty_zone_proc (void *cls,
382 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
383 _("Expected no zone content but received data\n")); 360 _("Expected no zone content but received data\n"));
384 GNUNET_break (0); 361 GNUNET_break (0);
385 if (endbadly_task != NULL) 362 GNUNET_SCHEDULER_shutdown ();
386 GNUNET_SCHEDULER_cancel (endbadly_task); 363 res = 1;
387 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
388 return; 364 return;
389 } 365 }
390 GNUNET_assert (0); 366 GNUNET_assert (0);
@@ -412,7 +388,9 @@ empty_zone_end (void *cls)
412 "zonefiles%s%s", 388 "zonefiles%s%s",
413 DIR_SEPARATOR_STR, 389 DIR_SEPARATOR_STR,
414 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); 390 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "Using zonekey file `%s' \n",
393 hostkey_file);
416 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 394 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
417 GNUNET_free (hostkey_file); 395 GNUNET_free (hostkey_file);
418 GNUNET_assert (privkey2 != NULL); 396 GNUNET_assert (privkey2 != NULL);
@@ -425,8 +403,8 @@ empty_zone_end (void *cls)
425 privkey, 403 privkey,
426 s_name_1, 404 s_name_1,
427 1, s_rd_1, 405 1, s_rd_1,
428 &put_cont, NULL); 406 &put_cont,
429 407 NULL);
430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
431 "Created record 2 \n"); 409 "Created record 2 \n");
432 GNUNET_asprintf(&s_name_2, "dummy2"); 410 GNUNET_asprintf(&s_name_2, "dummy2");
@@ -437,16 +415,18 @@ empty_zone_end (void *cls)
437 1, s_rd_2, 415 1, s_rd_2,
438 &put_cont, 416 &put_cont,
439 NULL); 417 NULL);
440
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
442 "Created record 3\n"); 419 "Created record 3\n");
443
444 /* name in different zone */ 420 /* name in different zone */
445 GNUNET_asprintf(&s_name_3, "dummy3"); 421 GNUNET_asprintf(&s_name_3, "dummy3");
446 s_rd_3 = create_record(1); 422 s_rd_3 = create_record(1);
447 GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, 423 GNUNET_NAMESTORE_records_store (nsh,
448 1, s_rd_3, 424 privkey2,
449 &put_cont, NULL); 425 s_name_3,
426 1,
427 s_rd_3,
428 &put_cont,
429 NULL);
450} 430}
451 431
452 432
@@ -455,31 +435,30 @@ run (void *cls,
455 const struct GNUNET_CONFIGURATION_Handle *cfg, 435 const struct GNUNET_CONFIGURATION_Handle *cfg,
456 struct GNUNET_TESTING_Peer *peer) 436 struct GNUNET_TESTING_Peer *peer)
457{ 437{
458 directory = NULL; 438 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
459 GNUNET_assert (GNUNET_OK == 439 &endbadly,
460 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", 440 NULL);
461 "GNUNET_TEST_HOME", 441 GNUNET_SCHEDULER_add_shutdown (&end,
462 &directory)); 442 NULL);
463 GNUNET_DISK_directory_remove (directory); 443
464
465 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
466 nsh = GNUNET_NAMESTORE_connect (cfg); 444 nsh = GNUNET_NAMESTORE_connect (cfg);
467 GNUNET_break (NULL != nsh); 445 GNUNET_break (NULL != nsh);
468 /* first, iterate over empty namestore */ 446 /* first, iterate over empty namestore */
469 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 447 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
470 NULL, 448 NULL,
471 &fail_cb, 449 &fail_cb,
472 NULL, 450 NULL,
473 &empty_zone_proc, 451 &empty_zone_proc,
474 nsh, 452 nsh,
475 &empty_zone_end, 453 &empty_zone_end,
476 NULL); 454 NULL);
477 if (NULL == zi) 455 if (NULL == zi)
478 { 456 {
479 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); 457 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
458 "Failed to create zone iterator\n");
480 GNUNET_break (0); 459 GNUNET_break (0);
481 GNUNET_SCHEDULER_cancel (endbadly_task); 460 res = 1;
482 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 461 GNUNET_SCHEDULER_shutdown ();
483 } 462 }
484} 463}
485 464
@@ -494,6 +473,8 @@ main (int argc, char *argv[])
494 GNUNET_asprintf (&cfg_name, 473 GNUNET_asprintf (&cfg_name,
495 "test_namestore_api_%s.conf", 474 "test_namestore_api_%s.conf",
496 plugin_name); 475 plugin_name);
476 GNUNET_DISK_purge_cfg_dir (cfg_name,
477 "GNUNET_TEST_HOME");
497 res = 1; 478 res = 1;
498 if (0 != 479 if (0 !=
499 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration", 480 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration",
@@ -503,12 +484,9 @@ main (int argc, char *argv[])
503 { 484 {
504 res = 1; 485 res = 1;
505 } 486 }
487 GNUNET_DISK_purge_cfg_dir (cfg_name,
488 "GNUNET_TEST_HOME");
506 GNUNET_free (cfg_name); 489 GNUNET_free (cfg_name);
507 if (NULL != directory)
508 {
509 GNUNET_DISK_directory_remove (directory);
510 GNUNET_free (directory);
511 }
512 return res; 490 return res;
513} 491}
514 492
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c
index a88646864..d950b7e69 100644
--- a/src/namestore/test_namestore_api_zone_iteration_nick.c
+++ b/src/namestore/test_namestore_api_zone_iteration_nick.c
@@ -60,7 +60,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
60 60
61static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 61static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
62 62
63static char *directory;
64 63
65/** 64/**
66 * Re-establish the connection to the service. 65 * Re-establish the connection to the service.
@@ -265,7 +264,9 @@ fail_cb (void *cls)
265 264
266 265
267static void 266static void
268put_cont (void *cls, int32_t success, const char *emsg) 267put_cont (void *cls,
268 int32_t success,
269 const char *emsg)
269{ 270{
270 static int c = 0; 271 static int c = 0;
271 272
@@ -314,11 +315,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
314static struct GNUNET_GNSRECORD_Data * 315static struct GNUNET_GNSRECORD_Data *
315create_record (unsigned int count) 316create_record (unsigned int count)
316{ 317{
317 unsigned int c;
318 struct GNUNET_GNSRECORD_Data * rd; 318 struct GNUNET_GNSRECORD_Data * rd;
319 319
320 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 320 rd = GNUNET_new_array (count,
321 for (c = 0; c < count; c++) 321 struct GNUNET_GNSRECORD_Data);
322 for (unsigned int c = 0; c < count; c++)
322 { 323 {
323 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 324 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
324 rd[c].record_type = 1111; 325 rd[c].record_type = 1111;
@@ -332,7 +333,9 @@ create_record (unsigned int count)
332 333
333 334
334static void 335static void
335nick_2_cont (void *cls, int32_t success, const char *emsg) 336nick_2_cont (void *cls,
337 int32_t success,
338 const char *emsg)
336{ 339{
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
338 "Nick added : %s\n", 341 "Nick added : %s\n",
@@ -422,25 +425,18 @@ empty_zone_proc (void *cls,
422static void 425static void
423empty_zone_end (void *cls) 426empty_zone_end (void *cls)
424{ 427{
425 char *hostkey_file;
426 GNUNET_assert (nsh == cls); 428 GNUNET_assert (nsh == cls);
427
428 zi = NULL; 429 zi = NULL;
429 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 430 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
430 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
432 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
433 GNUNET_free (hostkey_file);
434 GNUNET_assert (privkey != NULL); 431 GNUNET_assert (privkey != NULL);
435 432 privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
436 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
437 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
439 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
440 GNUNET_free (hostkey_file);
441 GNUNET_assert (privkey2 != NULL); 433 GNUNET_assert (privkey2 != NULL);
442 434
443 nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, ZONE_NICK_1, &nick_1_cont, &privkey); 435 nsqe = GNUNET_NAMESTORE_set_nick (nsh,
436 privkey,
437 ZONE_NICK_1,
438 &nick_1_cont,
439 &privkey);
444 if (NULL == nsqe) 440 if (NULL == nsqe)
445 { 441 {
446 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 442 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -455,15 +451,9 @@ run (void *cls,
455 const struct GNUNET_CONFIGURATION_Handle *cfg, 451 const struct GNUNET_CONFIGURATION_Handle *cfg,
456 struct GNUNET_TESTING_Peer *peer) 452 struct GNUNET_TESTING_Peer *peer)
457{ 453{
458 directory = NULL; 454 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
459 GNUNET_assert (GNUNET_OK == 455 &endbadly,
460 GNUNET_CONFIGURATION_get_value_string (cfg, 456 NULL);
461 "PATHS",
462 "GNUNET_TEST_HOME",
463 &directory));
464 GNUNET_DISK_directory_remove (directory);
465
466 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
467 nsh = GNUNET_NAMESTORE_connect (cfg); 457 nsh = GNUNET_NAMESTORE_connect (cfg);
468 GNUNET_break (NULL != nsh); 458 GNUNET_break (NULL != nsh);
469 459
@@ -498,6 +488,8 @@ main (int argc, char *argv[])
498 "test_namestore_api_%s.conf", 488 "test_namestore_api_%s.conf",
499 plugin_name); 489 plugin_name);
500 res = 1; 490 res = 1;
491 GNUNET_DISK_purge_cfg_dir (cfg_name,
492 "GNUNET_TEST_HOME");
501 if (0 != 493 if (0 !=
502 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick", 494 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick",
503 cfg_name, 495 cfg_name,
@@ -506,12 +498,9 @@ main (int argc, char *argv[])
506 { 498 {
507 res = 1; 499 res = 1;
508 } 500 }
501 GNUNET_DISK_purge_cfg_dir (cfg_name,
502 "GNUNET_TEST_HOME");
509 GNUNET_free (cfg_name); 503 GNUNET_free (cfg_name);
510 if (NULL != directory)
511 {
512 GNUNET_DISK_directory_remove (directory);
513 GNUNET_free (directory);
514 }
515 return res; 504 return res;
516} 505}
517 506
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
index a4fb320e9..54cbe5472 100644
--- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
+++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -57,7 +57,6 @@ static char * s_name_3;
57 57
58static struct GNUNET_GNSRECORD_Data *s_rd_3; 58static struct GNUNET_GNSRECORD_Data *s_rd_3;
59 59
60static char *directory;
61 60
62/** 61/**
63 * Re-establish the connection to the service. 62 * Re-establish the connection to the service.
@@ -379,35 +378,16 @@ empty_zone_proc (void *cls,
379static void 378static void
380empty_zone_proc_end (void *cls) 379empty_zone_proc_end (void *cls)
381{ 380{
382 char *hostkey_file;
383
384 zi = NULL; 381 zi = NULL;
385 GNUNET_asprintf (&hostkey_file, 382 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); 383 GNUNET_assert (privkey != NULL);
395 384 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); 385 GNUNET_assert (privkey2 != NULL);
406 386
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
408 "Created record 1\n"); 388 "Created record 1\n");
409 389 GNUNET_asprintf (&s_name_1,
410 GNUNET_asprintf(&s_name_1, "dummy1"); 390 "dummy1");
411 s_rd_1 = create_record (1); 391 s_rd_1 = create_record (1);
412 GNUNET_NAMESTORE_records_store (nsh, 392 GNUNET_NAMESTORE_records_store (nsh,
413 privkey, 393 privkey,
@@ -419,7 +399,8 @@ empty_zone_proc_end (void *cls)
419 399
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
421 "Created record 2 \n"); 401 "Created record 2 \n");
422 GNUNET_asprintf(&s_name_2, "dummy2"); 402 GNUNET_asprintf (&s_name_2,
403 "dummy2");
423 s_rd_2 = create_record (1); 404 s_rd_2 = create_record (1);
424 GNUNET_NAMESTORE_records_store (nsh, 405 GNUNET_NAMESTORE_records_store (nsh,
425 privkey, 406 privkey,
@@ -433,7 +414,8 @@ empty_zone_proc_end (void *cls)
433 "Created record 3\n"); 414 "Created record 3\n");
434 415
435 /* name in different zone */ 416 /* name in different zone */
436 GNUNET_asprintf(&s_name_3, "dummy3"); 417 GNUNET_asprintf (&s_name_3,
418 "dummy3");
437 s_rd_3 = create_record (1); 419 s_rd_3 = create_record (1);
438 GNUNET_NAMESTORE_records_store (nsh, 420 GNUNET_NAMESTORE_records_store (nsh,
439 privkey2, 421 privkey2,
@@ -449,14 +431,6 @@ run (void *cls,
449 const struct GNUNET_CONFIGURATION_Handle *cfg, 431 const struct GNUNET_CONFIGURATION_Handle *cfg,
450 struct GNUNET_TESTING_Peer *peer) 432 struct GNUNET_TESTING_Peer *peer)
451{ 433{
452 directory = NULL;
453 GNUNET_assert (GNUNET_OK ==
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, 434 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
461 &endbadly, 435 &endbadly,
462 NULL); 436 NULL);
@@ -477,7 +451,8 @@ run (void *cls,
477 "Failed to create zone iterator\n"); 451 "Failed to create zone iterator\n");
478 GNUNET_break (0); 452 GNUNET_break (0);
479 GNUNET_SCHEDULER_cancel (endbadly_task); 453 GNUNET_SCHEDULER_cancel (endbadly_task);
480 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 454 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
455 NULL);
481 } 456 }
482} 457}
483 458
@@ -493,6 +468,8 @@ main (int argc, char *argv[])
493 "test_namestore_api_%s.conf", 468 "test_namestore_api_%s.conf",
494 plugin_name); 469 plugin_name);
495 res = 1; 470 res = 1;
471 GNUNET_DISK_purge_cfg_dir (cfg_name,
472 "GNUNET_TEST_HOME");
496 if (0 != 473 if (0 !=
497 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone", 474 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone",
498 cfg_name, 475 cfg_name,
@@ -501,12 +478,9 @@ main (int argc, char *argv[])
501 { 478 {
502 res = 1; 479 res = 1;
503 } 480 }
481 GNUNET_DISK_purge_cfg_dir (cfg_name,
482 "GNUNET_TEST_HOME");
504 GNUNET_free (cfg_name); 483 GNUNET_free (cfg_name);
505 if (NULL != directory)
506 {
507 GNUNET_DISK_directory_remove (directory);
508 GNUNET_free (directory);
509 }
510 return res; 484 return res;
511} 485}
512 486
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c
index 5b088d90b..292d8f701 100644
--- a/src/namestore/test_namestore_api_zone_to_name.c
+++ b/src/namestore/test_namestore_api_zone_to_name.c
@@ -51,8 +51,6 @@ static char * s_name;
51 51
52static int res; 52static int res;
53 53
54static char *directory;
55
56static struct GNUNET_NAMESTORE_QueueEntry *qe; 54static struct GNUNET_NAMESTORE_QueueEntry *qe;
57 55
58 56
@@ -204,34 +202,13 @@ run (void *cls,
204{ 202{
205 (void) cls; 203 (void) cls;
206 (void) peer; 204 (void) peer;
207 directory = NULL;
208 GNUNET_assert (GNUNET_OK ==
209 GNUNET_CONFIGURATION_get_value_string (cfg,
210 "PATHS",
211 "GNUNET_TEST_HOME",
212 &directory));
213 GNUNET_DISK_directory_remove (directory);
214
215 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 205 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
216 &endbadly, 206 &endbadly,
217 NULL); 207 NULL);
218 GNUNET_SCHEDULER_add_shutdown (&end, 208 GNUNET_SCHEDULER_add_shutdown (&end,
219 NULL); 209 NULL);
220 GNUNET_asprintf (&s_name, "dummy"); 210 GNUNET_asprintf (&s_name, "dummy");
221 /* load privat key */ 211 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
222 {
223 char *zonekey_file;
224
225 GNUNET_asprintf (&zonekey_file,
226 "zonefiles%s%s",
227 DIR_SEPARATOR_STR,
228 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
230 "Using zonekey file `%s'\n",
231 zonekey_file);
232 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (zonekey_file);
233 GNUNET_free (zonekey_file);
234 }
235 GNUNET_assert (NULL != privkey); 212 GNUNET_assert (NULL != privkey);
236 /* get public key */ 213 /* get public key */
237 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 214 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
@@ -274,6 +251,8 @@ main (int argc,
274 GNUNET_asprintf (&cfg_name, 251 GNUNET_asprintf (&cfg_name,
275 "test_namestore_api_%s.conf", 252 "test_namestore_api_%s.conf",
276 plugin_name); 253 plugin_name);
254 GNUNET_DISK_purge_cfg_dir (cfg_name,
255 "GNUNET_TEST_HOME");
277 res = 1; 256 res = 1;
278 if (0 != 257 if (0 !=
279 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name", 258 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name",
@@ -283,12 +262,9 @@ main (int argc,
283 { 262 {
284 res = 1; 263 res = 1;
285 } 264 }
265 GNUNET_DISK_purge_cfg_dir (cfg_name,
266 "GNUNET_TEST_HOME");
286 GNUNET_free (cfg_name); 267 GNUNET_free (cfg_name);
287 if (NULL != directory)
288 {
289 GNUNET_DISK_directory_remove (directory);
290 GNUNET_free (directory);
291 }
292 return res; 268 return res;
293} 269}
294 270
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c
index 6bccd1706..8732acbcb 100644
--- a/src/namestore/test_plugin_namestore.c
+++ b/src/namestore/test_plugin_namestore.c
@@ -215,6 +215,8 @@ main (int argc,
215 sizeof (cfg_name), 215 sizeof (cfg_name),
216 "test_plugin_namestore_%s.conf", 216 "test_plugin_namestore_%s.conf",
217 plugin_name); 217 plugin_name);
218 GNUNET_DISK_purge_cfg_dir (cfg_name,
219 "GNUNET_TMP");
218 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, 220 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
219 xargv, 221 xargv,
220 "test-plugin-namestore", 222 "test-plugin-namestore",
@@ -222,6 +224,8 @@ main (int argc,
222 options, 224 options,
223 &run, 225 &run,
224 NULL); 226 NULL);
227 GNUNET_DISK_purge_cfg_dir (cfg_name,
228 "GNUNET_TMP");
225 if (ok != 0) 229 if (ok != 0)
226 FPRINTF (stderr, 230 FPRINTF (stderr,
227 "Missed some testcases: %d\n", 231 "Missed some testcases: %d\n",