aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-03-07 10:34:07 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-03-07 10:34:07 +0000
commit18d7b243b873410c7101d97bd8c9fabb36bdb404 (patch)
tree9feae8ee71f2a144938c0536afe9dd554bfd015e /src
parent55656c4720d237f883bff2d54ad7365d0ecb793d (diff)
downloadgnunet-18d7b243b873410c7101d97bd8c9fabb36bdb404.tar.gz
gnunet-18d7b243b873410c7101d97bd8c9fabb36bdb404.zip
- final zone iteration code
Diffstat (limited to 'src')
-rw-r--r--src/namestore/Makefile.am7
-rw-r--r--src/namestore/gnunet-service-namestore.c35
-rw-r--r--src/namestore/namestore_api.c15
-rw-r--r--src/namestore/test_namestore_api_zone_iteration.c119
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_specific_zone.c47
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_stop.c482
6 files changed, 668 insertions, 37 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index c52051082..3c91198f0 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -37,6 +37,7 @@ check_PROGRAMS = \
37 test_namestore_api_zone_to_name \ 37 test_namestore_api_zone_to_name \
38 test_namestore_api_zone_iteration \ 38 test_namestore_api_zone_iteration \
39 test_namestore_api_zone_iteration_specific_zone \ 39 test_namestore_api_zone_iteration_specific_zone \
40 test_namestore_api_zone_iteration_stop \
40 test_namestore_record_serialization 41 test_namestore_record_serialization
41 42
42if ENABLE_TEST_RUN 43if ENABLE_TEST_RUN
@@ -176,6 +177,12 @@ test_namestore_api_zone_iteration_specific_zone_SOURCES = \
176test_namestore_api_zone_iteration_specific_zone_LDADD = \ 177test_namestore_api_zone_iteration_specific_zone_LDADD = \
177 $(top_builddir)/src/util/libgnunetutil.la \ 178 $(top_builddir)/src/util/libgnunetutil.la \
178 $(top_builddir)/src/namestore/libgnunetnamestore.la 179 $(top_builddir)/src/namestore/libgnunetnamestore.la
180
181test_namestore_api_zone_iteration_stop_SOURCES = \
182 test_namestore_api_zone_iteration_stop.c
183test_namestore_api_zone_iteration_stop_LDADD = \
184 $(top_builddir)/src/util/libgnunetutil.la \
185 $(top_builddir)/src/namestore/libgnunetnamestore.la
179 186
180test_namestore_record_serialization_SOURCES = \ 187test_namestore_record_serialization_SOURCES = \
181 test_namestore_record_serialization.c 188 test_namestore_record_serialization.c
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 59059d84e..c92f39a59 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -43,11 +43,15 @@ struct GNUNET_NAMESTORE_ZoneIteration
43 43
44 struct GNUNET_NAMESTORE_Client * client; 44 struct GNUNET_NAMESTORE_Client * client;
45 45
46 int has_zone;
47
46 GNUNET_HashCode zone; 48 GNUNET_HashCode zone;
47 49
48 uint64_t request_id; 50 uint64_t request_id;
49 uint32_t offset; 51 uint32_t offset;
50 52
53
54
51}; 55};
52 56
53 57
@@ -1174,7 +1178,11 @@ void zone_iteration_proc (void *cls,
1174 if ((zone_key == NULL) && (name == NULL)) 1178 if ((zone_key == NULL) && (name == NULL))
1175 { 1179 {
1176 struct ZoneIterationResponseMessage zir_msg; 1180 struct ZoneIterationResponseMessage zir_msg;
1177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for zone `%s'\n", GNUNET_h2s(&zi->zone)); 1181 if (zi->has_zone == GNUNET_YES)
1182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for zone `%s'\n", GNUNET_h2s(&zi->zone));
1183 else
1184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for all zones\n");
1185
1178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending empty `%s' message\n", "ZONE_ITERATION_RESPONSE"); 1186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending empty `%s' message\n", "ZONE_ITERATION_RESPONSE");
1179 zir_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); 1187 zir_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
1180 zir_msg.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage)); 1188 zir_msg.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage));
@@ -1196,7 +1204,13 @@ void zone_iteration_proc (void *cls,
1196 else 1204 else
1197 { 1205 {
1198 struct ZoneIterationResponseMessage *zir_msg; 1206 struct ZoneIterationResponseMessage *zir_msg;
1199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iterating zone `%s'\n", name, GNUNET_h2s(&zi->zone)); 1207 if (zi->has_zone == GNUNET_YES)
1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over zone `%s'\n",
1209 name, GNUNET_h2s(&zi->zone));
1210 if (zi->has_zone == GNUNET_NO)
1211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over all zones\n",
1212 name);
1213
1200 size_t name_len; 1214 size_t name_len;
1201 size_t rd_ser_len; 1215 size_t rd_ser_len;
1202 size_t msg_size; 1216 size_t msg_size;
@@ -1263,11 +1277,13 @@ static void handle_iteration_start (void *cls,
1263 if (0 == memcmp (&dummy, &zis_msg->zone, sizeof (dummy))) 1277 if (0 == memcmp (&dummy, &zis_msg->zone, sizeof (dummy)))
1264 { 1278 {
1265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over all zones\n"); 1279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over all zones\n");
1280 zi->has_zone = GNUNET_NO;
1266 zone_tmp = NULL; 1281 zone_tmp = NULL;
1267 } 1282 }
1268 else 1283 else
1269 { 1284 {
1270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over zone `%s'\n", GNUNET_h2s (&zis_msg->zone)); 1285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over zone `%s'\n", GNUNET_h2s (&zis_msg->zone));
1286 zi->has_zone = GNUNET_YES;
1271 zone_tmp = &zis_msg->zone; 1287 zone_tmp = &zis_msg->zone;
1272 } 1288 }
1273 1289
@@ -1311,7 +1327,10 @@ static void handle_iteration_stop (void *cls,
1311 } 1327 }
1312 1328
1313 GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, zi); 1329 GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, zi);
1314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration for zone `%s'\n", GNUNET_h2s (&zi->zone)); 1330 if (GNUNET_YES == zi->has_zone)
1331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration for zone `%s'\n", GNUNET_h2s (&zi->zone));
1332 else
1333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration all zones\n");
1315 GNUNET_free (zi); 1334 GNUNET_free (zi);
1316 1335
1317 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1336 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1325,6 +1344,7 @@ static void handle_iteration_next (void *cls,
1325 1344
1326 struct GNUNET_NAMESTORE_Client *nc; 1345 struct GNUNET_NAMESTORE_Client *nc;
1327 struct GNUNET_NAMESTORE_ZoneIteration *zi; 1346 struct GNUNET_NAMESTORE_ZoneIteration *zi;
1347 GNUNET_HashCode *zone_tmp;
1328 struct ZoneIterationStopMessage * zis_msg = (struct ZoneIterationStopMessage *) message; 1348 struct ZoneIterationStopMessage * zis_msg = (struct ZoneIterationStopMessage *) message;
1329 uint32_t rid; 1349 uint32_t rid;
1330 1350
@@ -1348,9 +1368,14 @@ static void handle_iteration_next (void *cls,
1348 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1368 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1349 return; 1369 return;
1350 } 1370 }
1351 zi->offset++;
1352 1371
1353 GSN_database->iterate_records (GSN_database->cls, &zi->zone, NULL, zi->offset , &zone_iteration_proc, zi); 1372 if (GNUNET_YES == zi->has_zone)
1373 zone_tmp = &zi->zone;
1374 else
1375 zone_tmp = NULL;
1376
1377 zi->offset++;
1378 GSN_database->iterate_records (GSN_database->cls, zone_tmp, NULL, zi->offset , &zone_iteration_proc, zi);
1354 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1379 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1355} 1380}
1356 1381
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 64db49375..87894cee3 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -1477,13 +1477,19 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
1477 msg->gns_header.header.size = htons (msg_size); 1477 msg->gns_header.header.size = htons (msg_size);
1478 msg->gns_header.r_id = htonl (rid); 1478 msg->gns_header.r_id = htonl (rid);
1479 if (NULL != zone) 1479 if (NULL != zone)
1480 {
1481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for zone `%s'\n", "ZONE_ITERATION_START", GNUNET_h2s(zone));
1480 msg->zone = *zone; 1482 msg->zone = *zone;
1483 }
1481 else 1484 else
1485 {
1486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for all zones\n", "ZONE_ITERATION_START");
1482 memset (&msg->zone, '\0', sizeof (msg->zone)); 1487 memset (&msg->zone, '\0', sizeof (msg->zone));
1488 }
1483 msg->must_have_flags = ntohs (must_have_flags); 1489 msg->must_have_flags = ntohs (must_have_flags);
1484 msg->must_not_have_flags = ntohs (must_not_have_flags); 1490 msg->must_not_have_flags = ntohs (must_not_have_flags);
1485 1491
1486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for zone `%s'\n", "ZONE_ITERATION_START", GNUNET_h2s(zone)); 1492
1487 1493
1488 /* transmit message */ 1494 /* transmit message */
1489 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); 1495 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
@@ -1522,7 +1528,7 @@ GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it)
1522 msg->gns_header.header.size = htons (msg_size); 1528 msg->gns_header.header.size = htons (msg_size);
1523 msg->gns_header.r_id = htonl (it->op_id); 1529 msg->gns_header.r_id = htonl (it->op_id);
1524 1530
1525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for name `%s'\n", "ZONE_ITERATION_NEXT", GNUNET_h2s(&it->zone)); 1531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_ITERATION_NEXT");
1526 1532
1527 /* transmit message */ 1533 /* transmit message */
1528 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); 1534 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
@@ -1556,7 +1562,10 @@ GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it)
1556 msg->gns_header.header.size = htons (msg_size); 1562 msg->gns_header.header.size = htons (msg_size);
1557 msg->gns_header.r_id = htonl (it->op_id); 1563 msg->gns_header.r_id = htonl (it->op_id);
1558 1564
1559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for name `%s'\n", "ZONE_ITERATION_STOP", GNUNET_h2s(&it->zone)); 1565 if (GNUNET_YES == it->has_zone)
1566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for zone `%s'\n", "ZONE_ITERATION_STOP", GNUNET_h2s(&it->zone));
1567 else
1568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for all zones\n", "ZONE_ITERATION_STOP");
1560 1569
1561 /* transmit message */ 1570 /* transmit message */
1562 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); 1571 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c
index e70a3baf0..92e8e7988 100644
--- a/src/namestore/test_namestore_api_zone_iteration.c
+++ b/src/namestore/test_namestore_api_zone_iteration.c
@@ -19,7 +19,7 @@
19*/ 19*/
20/** 20/**
21 * @file namestore/test_namestore_api_zone_iteration.c 21 * @file namestore/test_namestore_api_zone_iteration.c
22 * @brief testcase for namestore_api.c zone iteration functionality 22 * @brief testcase for zone iteration functionality: iterate of a specific zone
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_common.h" 25#include "gnunet_common.h"
@@ -40,8 +40,13 @@ static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
40static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; 40static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
41static GNUNET_HashCode zone; 41static GNUNET_HashCode zone;
42 42
43static struct GNUNET_CRYPTO_RsaPrivateKey * privkey2;
44static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey2;
45static GNUNET_HashCode zone2;
46
43static struct GNUNET_NAMESTORE_ZoneIterator *zi; 47static struct GNUNET_NAMESTORE_ZoneIterator *zi;
44static int res; 48static int res;
49static int returned_records;
45 50
46struct GNUNET_CRYPTO_RsaSignature *sig_1; 51struct GNUNET_CRYPTO_RsaSignature *sig_1;
47char * s_name_1; 52char * s_name_1;
@@ -51,6 +56,10 @@ struct GNUNET_CRYPTO_RsaSignature *sig_2;
51char * s_name_2; 56char * s_name_2;
52struct GNUNET_NAMESTORE_RecordData *s_rd_2; 57struct GNUNET_NAMESTORE_RecordData *s_rd_2;
53 58
59struct GNUNET_CRYPTO_RsaSignature *sig_3;
60char * s_name_3;
61struct GNUNET_NAMESTORE_RecordData *s_rd_3;
62
54static void 63static void
55start_arm (const char *cfgname) 64start_arm (const char *cfgname)
56{ 65{
@@ -98,8 +107,11 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
98 107
99 GNUNET_free_non_null(sig_1); 108 GNUNET_free_non_null(sig_1);
100 GNUNET_free_non_null(sig_2); 109 GNUNET_free_non_null(sig_2);
110 GNUNET_free_non_null(sig_3);
101 GNUNET_free_non_null(s_name_1); 111 GNUNET_free_non_null(s_name_1);
102 GNUNET_free_non_null(s_name_2); 112 GNUNET_free_non_null(s_name_2);
113 GNUNET_free_non_null(s_name_3);
114
103 if (s_rd_1 != NULL) 115 if (s_rd_1 != NULL)
104 { 116 {
105 GNUNET_free ((void *)s_rd_1->data); 117 GNUNET_free ((void *)s_rd_1->data);
@@ -110,11 +122,20 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
110 GNUNET_free ((void *)s_rd_2->data); 122 GNUNET_free ((void *)s_rd_2->data);
111 GNUNET_free (s_rd_2); 123 GNUNET_free (s_rd_2);
112 } 124 }
125 if (s_rd_3 != NULL)
126 {
127 GNUNET_free ((void *)s_rd_3->data);
128 GNUNET_free (s_rd_3);
129 }
113 130
114 if (privkey != NULL) 131 if (privkey != NULL)
115 GNUNET_CRYPTO_rsa_key_free (privkey); 132 GNUNET_CRYPTO_rsa_key_free (privkey);
116 privkey = NULL; 133 privkey = NULL;
117 134
135 if (privkey2 != NULL)
136 GNUNET_CRYPTO_rsa_key_free (privkey2);
137 privkey2 = NULL;
138
118 if (NULL != arm) 139 if (NULL != arm)
119 stop_arm(); 140 stop_arm();
120 141
@@ -137,15 +158,20 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
137 endbadly_task = GNUNET_SCHEDULER_NO_TASK; 158 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
138 } 159 }
139 160
140
141 if (privkey != NULL) 161 if (privkey != NULL)
142 GNUNET_CRYPTO_rsa_key_free (privkey); 162 GNUNET_CRYPTO_rsa_key_free (privkey);
143 privkey = NULL; 163 privkey = NULL;
144 164
145 GNUNET_free_non_null(sig_1); 165 if (privkey2 != NULL)
146 GNUNET_free_non_null(sig_2); 166 GNUNET_CRYPTO_rsa_key_free (privkey2);
147 GNUNET_free_non_null(s_name_1); 167 privkey2 = NULL;
148 GNUNET_free_non_null(s_name_2); 168
169 GNUNET_free (sig_1);
170 GNUNET_free (sig_2);
171 GNUNET_free (sig_3);
172 GNUNET_free (s_name_1);
173 GNUNET_free (s_name_2);
174 GNUNET_free (s_name_3);
149 if (s_rd_1 != NULL) 175 if (s_rd_1 != NULL)
150 { 176 {
151 GNUNET_free ((void *)s_rd_1->data); 177 GNUNET_free ((void *)s_rd_1->data);
@@ -156,6 +182,11 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
156 GNUNET_free ((void *)s_rd_2->data); 182 GNUNET_free ((void *)s_rd_2->data);
157 GNUNET_free (s_rd_2); 183 GNUNET_free (s_rd_2);
158 } 184 }
185 if (s_rd_3 != NULL)
186 {
187 GNUNET_free ((void *)s_rd_3->data);
188 GNUNET_free (s_rd_3);
189 }
159 190
160 if (nsh != NULL) 191 if (nsh != NULL)
161 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 192 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
@@ -164,8 +195,6 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
164 195
165 if (NULL != arm) 196 if (NULL != arm)
166 stop_arm(); 197 stop_arm();
167
168 res = 0;
169} 198}
170 199
171void zone_proc (void *cls, 200void zone_proc (void *cls,
@@ -177,10 +206,15 @@ void zone_proc (void *cls,
177 const struct GNUNET_CRYPTO_RsaSignature *signature) 206 const struct GNUNET_CRYPTO_RsaSignature *signature)
178{ 207{
179 int failed = GNUNET_NO; 208 int failed = GNUNET_NO;
180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone));
181 if ((zone_key == NULL) && (name == NULL)) 209 if ((zone_key == NULL) && (name == NULL))
182 { 210 {
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done\n"); 211 GNUNET_break (3 == returned_records);
212 if (3 == returned_records)
213 res = 0;
214 else
215 res = 1;
216
217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done after receing %u results\n",returned_records );
184 GNUNET_SCHEDULER_add_now (&end, NULL); 218 GNUNET_SCHEDULER_add_now (&end, NULL);
185 } 219 }
186 else 220 else
@@ -227,17 +261,39 @@ void zone_proc (void *cls,
227 failed = GNUNET_YES; 261 failed = GNUNET_YES;
228 GNUNET_break (0); 262 GNUNET_break (0);
229 } 263 }
230 264 }
265 else if (0 == strcmp (name, s_name_3))
266 {
267 if (rd_count == 1)
268 {
269 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_3))
270 {
271 failed = GNUNET_YES;
272 GNUNET_break (0);
273 }
274 }
275 else
276 {
277 failed = GNUNET_YES;
278 GNUNET_break (0);
279 }
280 if (0 != memcmp (signature, sig_3, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
281 {
282 failed = GNUNET_YES;
283 GNUNET_break (0);
284 }
231 } 285 }
232 else 286 else
233 { 287 {
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing result `%s'\n", name); 288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing result failed: got name `%s'\n", name);
289 res = 1;
235 GNUNET_break (0); 290 GNUNET_break (0);
236 GNUNET_SCHEDULER_add_now (&end, NULL); 291 GNUNET_SCHEDULER_add_now (&end, NULL);
237 } 292 }
238 293
239 if (failed == GNUNET_NO) 294 if (failed == GNUNET_NO)
240 { 295 {
296 returned_records ++;
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Telling namestore to send the next result\n"); 297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Telling namestore to send the next result\n");
242 GNUNET_NAMESTORE_zone_iterator_next (zi); 298 GNUNET_NAMESTORE_zone_iterator_next (zi);
243 } 299 }
@@ -276,11 +332,20 @@ put_cont (void *cls, int32_t success, const char *emsg)
276 { 332 {
277 c++; 333 c++;
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); 334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
279 335 }
336 else
337 {
338 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records\n");
339 GNUNET_break (0);
340 GNUNET_SCHEDULER_cancel (endbadly_task);
341 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
280 } 342 }
281 343
282 if (c == 2) 344 if (c == 3)
283 { 345 {
346 res = 1;
347 returned_records = 0;
348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n");
284 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 349 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
285 NULL, 350 NULL,
286 GNUNET_NAMESTORE_RF_NONE, 351 GNUNET_NAMESTORE_RF_NONE,
@@ -289,6 +354,7 @@ put_cont (void *cls, int32_t success, const char *emsg)
289 &zone); 354 &zone);
290 if (zi == NULL) 355 if (zi == NULL)
291 { 356 {
357 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
292 GNUNET_break (0); 358 GNUNET_break (0);
293 GNUNET_SCHEDULER_cancel (endbadly_task); 359 GNUNET_SCHEDULER_cancel (endbadly_task);
294 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 360 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
@@ -305,11 +371,11 @@ create_record (int count)
305 371
306 for (c = 0; c < count; c++) 372 for (c = 0; c < count; c++)
307 { 373 {
308 rd[c].expiration = GNUNET_TIME_absolute_get(); 374 rd[c].expiration = GNUNET_TIME_absolute_get();
309 rd[c].record_type = 1111; 375 rd[c].record_type = 1111;
310 rd[c].data_size = 50; 376 rd[c].data_size = 50;
311 rd[c].data = GNUNET_malloc(50); 377 rd[c].data = GNUNET_malloc(50);
312 memset ((char *) rd[c].data, 'a', 50); 378 memset ((char *) rd[c].data, 'a', 50);
313 } 379 }
314 return rd; 380 return rd;
315} 381}
@@ -326,6 +392,12 @@ run (void *cls, char *const *args, const char *cfgfile,
326 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); 392 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
327 GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone); 393 GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone);
328 394
395 privkey2 = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey2");
396 GNUNET_assert (privkey2 != NULL);
397 GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2);
398 GNUNET_CRYPTO_hash(&pubkey2, sizeof (pubkey), &zone2);
399
400
329 start_arm (cfgfile); 401 start_arm (cfgfile);
330 GNUNET_assert (arm != NULL); 402 GNUNET_assert (arm != NULL);
331 403
@@ -334,8 +406,6 @@ run (void *cls, char *const *args, const char *cfgfile,
334 406
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); 407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
336 408
337
338
339 GNUNET_asprintf(&s_name_1, "dummy1"); 409 GNUNET_asprintf(&s_name_1, "dummy1");
340 s_rd_1 = create_record(1); 410 s_rd_1 = create_record(1);
341 sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1); 411 sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1);
@@ -348,6 +418,13 @@ run (void *cls, char *const *args, const char *cfgfile,
348 418
349 sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_name_2, s_rd_2, 1); 419 sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_name_2, s_rd_2, 1);
350 GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL); 420 GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL);
421
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
423 /* name in different zone */
424 GNUNET_asprintf(&s_name_3, "dummy3");
425 s_rd_3 = create_record(1);
426 sig_3 = GNUNET_NAMESTORE_create_signature(privkey, s_name_3, s_rd_3, 1);
427 GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_absolute_get_forever(), 1, s_rd_3, sig_3, &put_cont, NULL);
351} 428}
352 429
353static int 430static int
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 7d98eefb0..7cdcea42a 100644
--- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
+++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -18,8 +18,8 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/** 20/**
21 * @file namestore/test_namestore_api_zone_iteration.c 21 * @file namestore/test_namestore_api_zone_iteration_specific_zone.c
22 * @brief testcase for namestore_api.c zone iteration functionality 22 * @brief testcase for zone iteration functionality: iterate of a specific zone
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_common.h" 25#include "gnunet_common.h"
@@ -46,6 +46,7 @@ static GNUNET_HashCode zone2;
46 46
47static struct GNUNET_NAMESTORE_ZoneIterator *zi; 47static struct GNUNET_NAMESTORE_ZoneIterator *zi;
48static int res; 48static int res;
49static int returned_records;
49 50
50struct GNUNET_CRYPTO_RsaSignature *sig_1; 51struct GNUNET_CRYPTO_RsaSignature *sig_1;
51char * s_name_1; 52char * s_name_1;
@@ -106,8 +107,10 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
106 107
107 GNUNET_free_non_null(sig_1); 108 GNUNET_free_non_null(sig_1);
108 GNUNET_free_non_null(sig_2); 109 GNUNET_free_non_null(sig_2);
110 GNUNET_free_non_null(sig_3);
109 GNUNET_free_non_null(s_name_1); 111 GNUNET_free_non_null(s_name_1);
110 GNUNET_free_non_null(s_name_2); 112 GNUNET_free_non_null(s_name_2);
113 GNUNET_free_non_null(s_name_3);
111 114
112 if (s_rd_1 != NULL) 115 if (s_rd_1 != NULL)
113 { 116 {
@@ -119,11 +122,20 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
119 GNUNET_free ((void *)s_rd_2->data); 122 GNUNET_free ((void *)s_rd_2->data);
120 GNUNET_free (s_rd_2); 123 GNUNET_free (s_rd_2);
121 } 124 }
125 if (s_rd_3 != NULL)
126 {
127 GNUNET_free ((void *)s_rd_3->data);
128 GNUNET_free (s_rd_3);
129 }
122 130
123 if (privkey != NULL) 131 if (privkey != NULL)
124 GNUNET_CRYPTO_rsa_key_free (privkey); 132 GNUNET_CRYPTO_rsa_key_free (privkey);
125 privkey = NULL; 133 privkey = NULL;
126 134
135 if (privkey2 != NULL)
136 GNUNET_CRYPTO_rsa_key_free (privkey2);
137 privkey2 = NULL;
138
127 if (NULL != arm) 139 if (NULL != arm)
128 stop_arm(); 140 stop_arm();
129 141
@@ -150,10 +162,16 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
150 GNUNET_CRYPTO_rsa_key_free (privkey); 162 GNUNET_CRYPTO_rsa_key_free (privkey);
151 privkey = NULL; 163 privkey = NULL;
152 164
165 if (privkey2 != NULL)
166 GNUNET_CRYPTO_rsa_key_free (privkey2);
167 privkey2 = NULL;
168
153 GNUNET_free (sig_1); 169 GNUNET_free (sig_1);
154 GNUNET_free (sig_2); 170 GNUNET_free (sig_2);
171 GNUNET_free (sig_3);
155 GNUNET_free (s_name_1); 172 GNUNET_free (s_name_1);
156 GNUNET_free (s_name_2); 173 GNUNET_free (s_name_2);
174 GNUNET_free (s_name_3);
157 if (s_rd_1 != NULL) 175 if (s_rd_1 != NULL)
158 { 176 {
159 GNUNET_free ((void *)s_rd_1->data); 177 GNUNET_free ((void *)s_rd_1->data);
@@ -164,6 +182,11 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
164 GNUNET_free ((void *)s_rd_2->data); 182 GNUNET_free ((void *)s_rd_2->data);
165 GNUNET_free (s_rd_2); 183 GNUNET_free (s_rd_2);
166 } 184 }
185 if (s_rd_3 != NULL)
186 {
187 GNUNET_free ((void *)s_rd_3->data);
188 GNUNET_free (s_rd_3);
189 }
167 190
168 if (nsh != NULL) 191 if (nsh != NULL)
169 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 192 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
@@ -186,7 +209,13 @@ void zone_proc (void *cls,
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone)); 209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone));
187 if ((zone_key == NULL) && (name == NULL)) 210 if ((zone_key == NULL) && (name == NULL))
188 { 211 {
189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done\n"); 212 GNUNET_break (2 == returned_records);
213 if (2 == returned_records)
214 res = 0;
215 else
216 res = 1;
217
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done after %u records\n", returned_records);
190 GNUNET_SCHEDULER_add_now (&end, NULL); 219 GNUNET_SCHEDULER_add_now (&end, NULL);
191 } 220 }
192 else 221 else
@@ -236,14 +265,15 @@ void zone_proc (void *cls,
236 } 265 }
237 else 266 else
238 { 267 {
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing result `%s'\n", name); 268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing result failed: got name `%s'\n", name);
269 res = 1;
240 GNUNET_break (0); 270 GNUNET_break (0);
241 GNUNET_SCHEDULER_add_now (&end, NULL); 271 GNUNET_SCHEDULER_add_now (&end, NULL);
242 } 272 }
243 273
244 if (failed == GNUNET_NO) 274 if (failed == GNUNET_NO)
245 { 275 {
246 res --; 276 returned_records ++;
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Telling namestore to send the next result\n"); 277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Telling namestore to send the next result\n");
248 GNUNET_NAMESTORE_zone_iterator_next (zi); 278 GNUNET_NAMESTORE_zone_iterator_next (zi);
249 } 279 }
@@ -291,9 +321,10 @@ put_cont (void *cls, int32_t success, const char *emsg)
291 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 321 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
292 } 322 }
293 323
294 if (c == 2) 324 if (c == 3)
295 { 325 {
296 res = 2; 326 res = 1;
327 returned_records = 0;
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over zone `%s'\n", 328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over zone `%s'\n",
298 GNUNET_h2s(&zone)); 329 GNUNET_h2s(&zone));
299 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 330 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
@@ -408,4 +439,4 @@ main (int argc, char *argv[])
408 return ret; 439 return ret;
409} 440}
410 441
411/* end of test_namestore_api_zone_iteration.c */ 442/* end of test_namestore_api_zone_iteration_specific_zone.c */
diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c
new file mode 100644
index 000000000..36a08d7db
--- /dev/null
+++ b/src/namestore/test_namestore_api_zone_iteration_stop.c
@@ -0,0 +1,482 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file namestore/test_namestore_api_zone_iteration.c
22 * @brief testcase for zone iteration functionality: iterate of a specific zone
23 */
24#include "platform.h"
25#include "gnunet_common.h"
26#include "gnunet_namestore_service.h"
27#include "namestore.h"
28
29#define VERBOSE GNUNET_NO
30
31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
32
33static struct GNUNET_NAMESTORE_Handle * nsh;
34
35static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
36static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task;
37static struct GNUNET_OS_Process *arm;
38
39static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
40static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
41static GNUNET_HashCode zone;
42
43static struct GNUNET_CRYPTO_RsaPrivateKey * privkey2;
44static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey2;
45static GNUNET_HashCode zone2;
46
47static struct GNUNET_NAMESTORE_ZoneIterator *zi;
48static int res;
49static int returned_records;
50
51struct GNUNET_CRYPTO_RsaSignature *sig_1;
52char * s_name_1;
53struct GNUNET_NAMESTORE_RecordData *s_rd_1;
54
55struct GNUNET_CRYPTO_RsaSignature *sig_2;
56char * s_name_2;
57struct GNUNET_NAMESTORE_RecordData *s_rd_2;
58
59struct GNUNET_CRYPTO_RsaSignature *sig_3;
60char * s_name_3;
61struct GNUNET_NAMESTORE_RecordData *s_rd_3;
62
63static void
64start_arm (const char *cfgname)
65{
66 arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
67 "gnunet-service-arm", "-c", cfgname,
68#if VERBOSE_PEERS
69 "-L", "DEBUG",
70#else
71 "-L", "ERROR",
72#endif
73 NULL);
74}
75
76static void
77stop_arm ()
78{
79 if (NULL != arm)
80 {
81 if (0 != GNUNET_OS_process_kill (arm, SIGTERM))
82 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
83 GNUNET_OS_process_wait (arm);
84 GNUNET_OS_process_close (arm);
85 arm = NULL;
86 }
87}
88
89/**
90 * Re-establish the connection to the service.
91 *
92 * @param cls handle to use to re-connect.
93 * @param tc scheduler context
94 */
95static void
96endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
97{
98 if (stopiteration_task != GNUNET_SCHEDULER_NO_TASK)
99 {
100 GNUNET_SCHEDULER_cancel (stopiteration_task);
101 stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
102 }
103
104 if (nsh != NULL)
105 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
106 nsh = NULL;
107
108 GNUNET_free_non_null(sig_1);
109 GNUNET_free_non_null(sig_2);
110 GNUNET_free_non_null(sig_3);
111 GNUNET_free_non_null(s_name_1);
112 GNUNET_free_non_null(s_name_2);
113 GNUNET_free_non_null(s_name_3);
114
115 if (s_rd_1 != NULL)
116 {
117 GNUNET_free ((void *)s_rd_1->data);
118 GNUNET_free (s_rd_1);
119 }
120 if (s_rd_2 != NULL)
121 {
122 GNUNET_free ((void *)s_rd_2->data);
123 GNUNET_free (s_rd_2);
124 }
125 if (s_rd_3 != NULL)
126 {
127 GNUNET_free ((void *)s_rd_3->data);
128 GNUNET_free (s_rd_3);
129 }
130
131 if (privkey != NULL)
132 GNUNET_CRYPTO_rsa_key_free (privkey);
133 privkey = NULL;
134
135 if (privkey2 != NULL)
136 GNUNET_CRYPTO_rsa_key_free (privkey2);
137 privkey2 = NULL;
138
139 if (NULL != arm)
140 stop_arm();
141
142 res = 1;
143}
144
145
146static void
147end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
148{
149 if (stopiteration_task != GNUNET_SCHEDULER_NO_TASK)
150 {
151 GNUNET_SCHEDULER_cancel (stopiteration_task);
152 stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
153 }
154
155 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
156 {
157 GNUNET_SCHEDULER_cancel (endbadly_task);
158 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
159 }
160
161 if (privkey != NULL)
162 GNUNET_CRYPTO_rsa_key_free (privkey);
163 privkey = NULL;
164
165 if (privkey2 != NULL)
166 GNUNET_CRYPTO_rsa_key_free (privkey2);
167 privkey2 = NULL;
168
169 GNUNET_free (sig_1);
170 GNUNET_free (sig_2);
171 GNUNET_free (sig_3);
172 GNUNET_free (s_name_1);
173 GNUNET_free (s_name_2);
174 GNUNET_free (s_name_3);
175 if (s_rd_1 != NULL)
176 {
177 GNUNET_free ((void *)s_rd_1->data);
178 GNUNET_free (s_rd_1);
179 }
180 if (s_rd_2 != NULL)
181 {
182 GNUNET_free ((void *)s_rd_2->data);
183 GNUNET_free (s_rd_2);
184 }
185 if (s_rd_3 != NULL)
186 {
187 GNUNET_free ((void *)s_rd_3->data);
188 GNUNET_free (s_rd_3);
189 }
190
191 if (nsh != NULL)
192 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
193 nsh = NULL;
194
195 if (NULL != arm)
196 stop_arm();
197 if (returned_records == 1)
198 res = 0;
199 else
200 res = 1;
201
202}
203
204void zone_proc (void *cls,
205 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
206 struct GNUNET_TIME_Absolute expire,
207 const char *name,
208 unsigned int rd_count,
209 const struct GNUNET_NAMESTORE_RecordData *rd,
210 const struct GNUNET_CRYPTO_RsaSignature *signature)
211{
212 int failed = GNUNET_NO;
213
214 if ((zone_key == NULL) && (name == NULL))
215 {
216 GNUNET_break (3 == returned_records);
217 if (3 == returned_records)
218 res = 0;
219 else
220 res = 1;
221
222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done after receing %u results\n",returned_records );
223 GNUNET_SCHEDULER_add_now (&end, NULL);
224 }
225 else
226 {
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing results name %s \n", name);
228 if (0 == strcmp (name, s_name_1))
229 {
230 if (rd_count == 1)
231 {
232 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_1))
233 {
234 failed = GNUNET_YES;
235 GNUNET_break (0);
236 }
237 }
238 else
239 {
240 failed = GNUNET_YES;
241 GNUNET_break (0);
242 }
243 if (0 != memcmp (signature, sig_1, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
244 {
245 failed = GNUNET_YES;
246 GNUNET_break (0);
247 }
248 }
249 else if (0 == strcmp (name, s_name_2))
250 {
251 if (rd_count == 1)
252 {
253 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_2))
254 {
255 failed = GNUNET_YES;
256 GNUNET_break (0);
257 }
258 }
259 else
260 {
261 failed = GNUNET_YES;
262 GNUNET_break (0);
263 }
264 if (0 != memcmp (signature, sig_2, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
265 {
266 failed = GNUNET_YES;
267 GNUNET_break (0);
268 }
269 }
270 else if (0 == strcmp (name, s_name_3))
271 {
272 if (rd_count == 1)
273 {
274 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_3))
275 {
276 failed = GNUNET_YES;
277 GNUNET_break (0);
278 }
279 }
280 else
281 {
282 failed = GNUNET_YES;
283 GNUNET_break (0);
284 }
285 if (0 != memcmp (signature, sig_3, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
286 {
287 failed = GNUNET_YES;
288 GNUNET_break (0);
289 }
290 }
291 else
292 {
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing result failed: got name `%s'\n", name);
294 res = 1;
295 GNUNET_break (0);
296 GNUNET_SCHEDULER_add_now (&end, NULL);
297 }
298
299 if (failed == GNUNET_NO)
300 {
301 returned_records ++;
302
303 if (1 == returned_records)
304 {
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping zone iteration after %u received record \n",returned_records );
306 GNUNET_NAMESTORE_zone_iteration_stop (zi);
307 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
308 {
309 GNUNET_SCHEDULER_cancel (endbadly_task);
310 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
311 }
312 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3), &end , NULL);
313 return;
314 }
315 else
316 {
317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Telling namestore to send the next result\n");
318 GNUNET_NAMESTORE_zone_iterator_next (zi);
319 }
320 }
321 else
322 {
323 GNUNET_break (0);
324 GNUNET_SCHEDULER_add_now (&end, NULL);
325 }
326 }
327}
328
329void
330delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
331{
332 char *afsdir;
333
334 if (GNUNET_OK ==
335 GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite",
336 "FILENAME", &afsdir))
337 {
338 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
339 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
340 if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir))
341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir);
342 GNUNET_free (afsdir);
343 }
344
345}
346
347void
348put_cont (void *cls, int32_t success, const char *emsg)
349{
350 static int c = 0;
351
352 if (success == GNUNET_OK)
353 {
354 c++;
355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
356 }
357 else
358 {
359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records\n");
360 GNUNET_break (0);
361 GNUNET_SCHEDULER_cancel (endbadly_task);
362 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
363 }
364
365 if (c == 3)
366 {
367 res = 1;
368 returned_records = 0;
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n");
370 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
371 NULL,
372 GNUNET_NAMESTORE_RF_NONE,
373 GNUNET_NAMESTORE_RF_NONE,
374 zone_proc,
375 &zone);
376 if (zi == NULL)
377 {
378 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
379 GNUNET_break (0);
380 GNUNET_SCHEDULER_cancel (endbadly_task);
381 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
382 }
383 }
384}
385
386static struct GNUNET_NAMESTORE_RecordData *
387create_record (int count)
388{
389 int c;
390 struct GNUNET_NAMESTORE_RecordData * rd;
391 rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));
392
393 for (c = 0; c < count; c++)
394 {
395 rd[c].expiration = GNUNET_TIME_absolute_get();
396 rd[c].record_type = 1111;
397 rd[c].data_size = 50;
398 rd[c].data = GNUNET_malloc(50);
399 memset ((char *) rd[c].data, 'a', 50);
400 }
401 return rd;
402}
403
404static void
405run (void *cls, char *const *args, const char *cfgfile,
406 const struct GNUNET_CONFIGURATION_Handle *cfg)
407{
408 delete_existing_db(cfg);
409 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL);
410
411 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
412 GNUNET_assert (privkey != NULL);
413 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
414 GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone);
415
416 privkey2 = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey2");
417 GNUNET_assert (privkey2 != NULL);
418 GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2);
419 GNUNET_CRYPTO_hash(&pubkey2, sizeof (pubkey), &zone2);
420
421
422 start_arm (cfgfile);
423 GNUNET_assert (arm != NULL);
424
425 nsh = GNUNET_NAMESTORE_connect (cfg);
426 GNUNET_break (NULL != nsh);
427
428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
429
430 GNUNET_asprintf(&s_name_1, "dummy1");
431 s_rd_1 = create_record(1);
432 sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1);
433 GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL);
434
435
436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
437 GNUNET_asprintf(&s_name_2, "dummy2");
438 s_rd_2 = create_record(1);
439
440 sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_name_2, s_rd_2, 1);
441 GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL);
442
443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
444 /* name in different zone */
445 GNUNET_asprintf(&s_name_3, "dummy3");
446 s_rd_3 = create_record(1);
447 sig_3 = GNUNET_NAMESTORE_create_signature(privkey, s_name_3, s_rd_3, 1);
448 GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_absolute_get_forever(), 1, s_rd_3, sig_3, &put_cont, NULL);
449}
450
451static int
452check ()
453{
454 static char *const argv[] = { "test_namestore_api_zone_iteration",
455 "-c",
456 "test_namestore_api.conf",
457#if VERBOSE
458 "-L", "DEBUG",
459#endif
460 NULL
461 };
462 static struct GNUNET_GETOPT_CommandLineOption options[] = {
463 GNUNET_GETOPT_OPTION_END
464 };
465
466 res = 1;
467 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_api_zone_iteration",
468 "nohelp", options, &run, &res);
469 return res;
470}
471
472int
473main (int argc, char *argv[])
474{
475 int ret;
476
477 ret = check ();
478
479 return ret;
480}
481
482/* end of test_namestore_api_zone_iteration.c */