aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-03-06 18:04:47 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-03-06 18:04:47 +0000
commit01d4c36af3ea8e777bbe1a6f98c88f5429b69519 (patch)
tree1c14cfc7ed1adfd0146b00fdb5f2514ebc10a540 /src
parent647b05ca4f4b069210709b65d943d18f570fe548 (diff)
downloadgnunet-01d4c36af3ea8e777bbe1a6f98c88f5429b69519.tar.gz
gnunet-01d4c36af3ea8e777bbe1a6f98c88f5429b69519.zip
- zone iteration stuff
Diffstat (limited to 'src')
-rw-r--r--src/namestore/Makefile.am7
-rw-r--r--src/namestore/gnunet-service-namestore.c132
-rw-r--r--src/namestore/namestore_api.c69
-rw-r--r--src/namestore/test_namestore_api.conf2
-rw-r--r--src/namestore/test_namestore_api_put.c1
-rw-r--r--src/namestore/test_namestore_api_zone_iteration.c200
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_specific_zone.c384
7 files changed, 704 insertions, 91 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 8bfa0389b..c52051082 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -36,6 +36,7 @@ check_PROGRAMS = \
36 test_namestore_api_remove_not_existing_record \ 36 test_namestore_api_remove_not_existing_record \
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_record_serialization 40 test_namestore_record_serialization
40 41
41if ENABLE_TEST_RUN 42if ENABLE_TEST_RUN
@@ -169,6 +170,12 @@ test_namestore_api_zone_iteration_SOURCES = \
169test_namestore_api_zone_iteration_LDADD = \ 170test_namestore_api_zone_iteration_LDADD = \
170 $(top_builddir)/src/util/libgnunetutil.la \ 171 $(top_builddir)/src/util/libgnunetutil.la \
171 $(top_builddir)/src/namestore/libgnunetnamestore.la 172 $(top_builddir)/src/namestore/libgnunetnamestore.la
173
174test_namestore_api_zone_iteration_specific_zone_SOURCES = \
175 test_namestore_api_zone_iteration_specific_zone.c
176test_namestore_api_zone_iteration_specific_zone_LDADD = \
177 $(top_builddir)/src/util/libgnunetutil.la \
178 $(top_builddir)/src/namestore/libgnunetnamestore.la
172 179
173test_namestore_record_serialization_SOURCES = \ 180test_namestore_record_serialization_SOURCES = \
174 test_namestore_record_serialization.c 181 test_namestore_record_serialization.c
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index af5f84979..59059d84e 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -614,6 +614,10 @@ handle_create_record_it (void *cls,
614 rd_count_new, rd_new, 614 rd_count_new, rd_new,
615 signature_new); 615 signature_new);
616 GNUNET_break (GNUNET_OK == res); 616 GNUNET_break (GNUNET_OK == res);
617 if (res == GNUNET_OK)
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully put record for `%s' in database \n", crc->name);
619 else
620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to put record for `%s' in database \n", crc->name);
617 res = GNUNET_YES; 621 res = GNUNET_YES;
618 622
619end: 623end:
@@ -1163,40 +1167,68 @@ void zone_iteration_proc (void *cls,
1163 const struct GNUNET_NAMESTORE_RecordData *rd, 1167 const struct GNUNET_NAMESTORE_RecordData *rd,
1164 const struct GNUNET_CRYPTO_RsaSignature *signature) 1168 const struct GNUNET_CRYPTO_RsaSignature *signature)
1165{ 1169{
1166 struct ZoneIterationProcResult *zipr = cls; 1170 struct GNUNET_NAMESTORE_ZoneIteration *zi = cls;
1167 size_t len; 1171 struct GNUNET_NAMESTORE_Client *nc = zi->client;
1168 if (zone_key != NULL) 1172 //size_t len;
1169 {
1170 zipr->zone_key = *zone_key;
1171 zipr->have_zone_key = GNUNET_YES;
1172 }
1173 else
1174 zipr->have_zone_key = GNUNET_NO;
1175
1176 zipr->expire = expire;
1177
1178 if (name != NULL)
1179 {
1180 memcpy (zipr->name, name, strlen(name) + 1);
1181 zipr->have_name = GNUNET_YES;
1182 }
1183 else
1184 zipr->have_name = GNUNET_NO;
1185 1173
1186 if (signature != NULL) 1174 if ((zone_key == NULL) && (name == NULL))
1187 { 1175 {
1188 zipr->signature = *signature; 1176 struct ZoneIterationResponseMessage zir_msg;
1189 zipr->have_signature = GNUNET_YES; 1177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for zone `%s'\n", GNUNET_h2s(&zi->zone));
1178 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);
1180 zir_msg.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage));
1181 zir_msg.gns_header.r_id = htonl(zi->request_id);
1182 zir_msg.expire = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_zero());
1183 zir_msg.name_len = htons (0);
1184 zir_msg.reserved = htons (0);
1185 zir_msg.rd_count = htons (0);
1186 zir_msg.rd_len = htons (0);
1187 memset (&zir_msg.public_key, '\0', sizeof (zir_msg.public_key));
1188 memset (&zir_msg.signature, '\0', sizeof (zir_msg.signature));
1189 GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO);
1190
1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing zone iterator\n");
1192 GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, zi);
1193 GNUNET_free (zi);
1194 return;
1190 } 1195 }
1191 else 1196 else
1192 zipr->have_signature = GNUNET_NO;
1193
1194 if ((rd_count > 0) && (rd != NULL))
1195 { 1197 {
1196 len = GNUNET_NAMESTORE_records_get_size(rd_count, rd); 1198 struct ZoneIterationResponseMessage *zir_msg;
1197 zipr->rd_ser = GNUNET_malloc (len); 1199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iterating zone `%s'\n", name, GNUNET_h2s(&zi->zone));
1198 GNUNET_NAMESTORE_records_serialize(rd_count, rd, len, zipr->rd_ser); 1200 size_t name_len;
1199 zipr->rd_ser_len = len; 1201 size_t rd_ser_len;
1202 size_t msg_size;
1203 char *name_tmp;
1204 char *rd_tmp;
1205 name_len = strlen (name) +1;
1206
1207 rd_ser_len = GNUNET_NAMESTORE_records_get_size(rd_count, rd);
1208 char rd_ser[rd_ser_len];
1209 GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
1210 msg_size = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_ser_len;
1211 zir_msg = GNUNET_malloc(msg_size);
1212
1213 name_tmp = (char *) &zir_msg[1];
1214 rd_tmp = &name_tmp[name_len];
1215
1216 zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
1217 zir_msg->gns_header.header.size = htons (msg_size);
1218 zir_msg->gns_header.r_id = htonl(zi->request_id);
1219 zir_msg->expire = GNUNET_TIME_absolute_hton(expire);
1220 zir_msg->reserved = htons (0);
1221 zir_msg->name_len = htons (name_len);
1222 zir_msg->rd_count = htons (rd_count);
1223 zir_msg->rd_len = htons (rd_ser_len);
1224 zir_msg->signature = *signature;
1225 zir_msg->public_key = *zone_key;
1226 memcpy (name_tmp, name, name_len);
1227 memcpy (rd_tmp, rd_ser, rd_ser_len);
1228
1229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending empty `%s' message with size %u\n", "ZONE_ITERATION_RESPONSE", msg_size);
1230 GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) zir_msg, GNUNET_NO);
1231 GNUNET_free (zir_msg);
1200 } 1232 }
1201} 1233}
1202 1234
@@ -1209,8 +1241,6 @@ static void handle_iteration_start (void *cls,
1209 struct ZoneIterationStartMessage * zis_msg = (struct ZoneIterationStartMessage *) message; 1241 struct ZoneIterationStartMessage * zis_msg = (struct ZoneIterationStartMessage *) message;
1210 struct GNUNET_NAMESTORE_Client *nc; 1242 struct GNUNET_NAMESTORE_Client *nc;
1211 struct GNUNET_NAMESTORE_ZoneIteration *zi; 1243 struct GNUNET_NAMESTORE_ZoneIteration *zi;
1212 struct ZoneIterationResponseMessage zir_msg;
1213 struct ZoneIterationProcResult zipr;
1214 int res; 1244 int res;
1215 1245
1216 nc = client_lookup(client); 1246 nc = client_lookup(client);
@@ -1227,33 +1257,24 @@ static void handle_iteration_start (void *cls,
1227 zi->client = nc; 1257 zi->client = nc;
1228 zi->zone = zis_msg->zone; 1258 zi->zone = zis_msg->zone;
1229 1259
1230 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); 1260 GNUNET_HashCode dummy;
1231 1261 GNUNET_HashCode *zone_tmp;
1232 res = GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, &zipr); 1262 memset (&dummy, '\0', sizeof (dummy));
1233 switch (res) { 1263 if (0 == memcmp (&dummy, &zis_msg->zone, sizeof (dummy)))
1234 case GNUNET_OK: 1264 {
1235 /* GNUNET_OK on success */ 1265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over all zones\n");
1236 1266 zone_tmp = NULL;
1237 break; 1267 }
1238 case GNUNET_SYSERR: 1268 else
1239 /* GNUNET_SYSERR on error */ 1269 {
1240 break; 1270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over zone `%s'\n", GNUNET_h2s (&zis_msg->zone));
1241 case GNUNET_NO: 1271 zone_tmp = &zis_msg->zone;
1242 /* GNUNET_NO if there were no results, */
1243 break;
1244 default:
1245 break;
1246 } 1272 }
1247 1273
1274 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
1248 1275
1249 1276
1250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_ITERATION_RESPONSE"); 1277 res = GSN_database->iterate_records (GSN_database->cls, zone_tmp , NULL, zi->offset , &zone_iteration_proc, zi);
1251 zir_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
1252 zir_msg.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage));
1253 zir_msg.gns_header.r_id = htonl(zi->request_id);
1254
1255 GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO);
1256
1257 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1278 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1258} 1279}
1259 1280
@@ -1327,9 +1348,10 @@ static void handle_iteration_next (void *cls,
1327 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1348 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1328 return; 1349 return;
1329 } 1350 }
1330
1331 zi->offset++; 1351 zi->offset++;
1352
1332 GSN_database->iterate_records (GSN_database->cls, &zi->zone, NULL, zi->offset , &zone_iteration_proc, zi); 1353 GSN_database->iterate_records (GSN_database->cls, &zi->zone, NULL, zi->offset , &zone_iteration_proc, zi);
1354 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1333} 1355}
1334 1356
1335 1357
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 31de00c81..ae9ed1a27 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -365,8 +365,6 @@ handle_record_create_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
365 struct GNUNET_NAMESTORE_Handle *h = qe->nsh; 365 struct GNUNET_NAMESTORE_Handle *h = qe->nsh;
366 int res = ntohl (msg->op_result); 366 int res = ntohl (msg->op_result);
367 367
368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' %i\n",
369 "RECORD_CREATE_RESPONSE", ntohs (msg->op_result));
370 if (res == GNUNET_YES) 368 if (res == GNUNET_YES)
371 { 369 {
372 if (qe->cont != NULL) 370 if (qe->cont != NULL)
@@ -582,12 +580,66 @@ handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze,
582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n", 580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n",
583 "ZONE_ITERATION_RESPONSE"); 581 "ZONE_ITERATION_RESPONSE");
584 582
583 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubdummy;
584 size_t msg_len = 0;
585 size_t exp_msg_len = 0;
586 size_t name_len = 0;
587 size_t rd_len = 0;
588 unsigned rd_count = 0;
585 589
586 if (ze->proc != NULL) 590 char *name_tmp;
591 char *rd_ser_tmp;
592 struct GNUNET_TIME_Absolute expire;
593
594 msg_len = ntohs (msg->gns_header.header.size);
595 rd_len = ntohs (msg->rd_len);
596 rd_count = ntohs (msg->rd_count);
597 name_len = ntohs (msg->name_len);
598 expire = GNUNET_TIME_absolute_ntoh (msg->expire);
599
600 exp_msg_len = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_len;
601 if (msg_len != exp_msg_len)
602 {
603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message size describes with `%u' bytes but calculated size is %u bytes \n",
604 msg_len, exp_msg_len);
605 GNUNET_break_op (0);
606 return;
607 }
608 if (0 != ntohs (msg->reserved))
609 {
610 GNUNET_break_op (0);
611 return;
612 }
613
614 memset (&pubdummy, '\0', sizeof (pubdummy));
615 if ((0 == name_len) && (0 == (memcmp (&msg->public_key, &pubdummy, sizeof (pubdummy)))))
616 {
617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration is completed!\n");
618
619 if (ze->proc != NULL)
620 ze->proc(ze->proc_cls, NULL, GNUNET_TIME_absolute_get_zero (), NULL , 0, NULL, NULL);
621
622 GNUNET_CONTAINER_DLL_remove(ze->h->z_head, ze->h->z_tail, ze);
623 GNUNET_free (ze);
624 return;
625 }
626
627 name_tmp = (char *) &msg[1];
628 if ((name_tmp[name_len -1] != '\0') || (name_len > 256))
629 {
630 GNUNET_break_op (0);
631 return;
632 }
633 rd_ser_tmp = (char *) &name_tmp[name_len];
634 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
635 if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd))
587 { 636 {
588 // FIXME 637 GNUNET_break_op (0);
589 ze->proc(ze->proc_cls, NULL, GNUNET_TIME_absolute_get_forever(), "dummy", 0, NULL, NULL); 638 return;
590 } 639 }
640
641 if (ze->proc != NULL)
642 ze->proc(ze->proc_cls, &msg->public_key, expire, name_tmp, rd_count, rd, &msg->signature);
591} 643}
592 644
593 645
@@ -1425,7 +1477,7 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
1425 uint32_t rid = 0; 1477 uint32_t rid = 0;
1426 1478
1427 GNUNET_assert (NULL != h); 1479 GNUNET_assert (NULL != h);
1428 GNUNET_assert (NULL != zone); 1480
1429 1481
1430 rid = get_op_id(h); 1482 rid = get_op_id(h);
1431 it = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_ZoneIterator)); 1483 it = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_ZoneIterator));
@@ -1448,7 +1500,10 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
1448 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START); 1500 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START);
1449 msg->gns_header.header.size = htons (msg_size); 1501 msg->gns_header.header.size = htons (msg_size);
1450 msg->gns_header.r_id = htonl (rid); 1502 msg->gns_header.r_id = htonl (rid);
1451 msg->zone = *zone; 1503 if (NULL == zone)
1504 msg->zone = *zone;
1505 else
1506 memset (&msg->zone, '\0', sizeof (msg->zone));
1452 msg->must_have_flags = ntohs (must_have_flags); 1507 msg->must_have_flags = ntohs (must_have_flags);
1453 msg->must_not_have_flags = ntohs (must_not_have_flags); 1508 msg->must_not_have_flags = ntohs (must_not_have_flags);
1454 1509
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf
index c437b414a..f4cd32dbd 100644
--- a/src/namestore/test_namestore_api.conf
+++ b/src/namestore/test_namestore_api.conf
@@ -4,7 +4,7 @@ DEFAULTSERVICES = namestore
4UNIXPATH = /tmp/gnunet-p1-service-arm.sock 4UNIXPATH = /tmp/gnunet-p1-service-arm.sock
5 5
6[namestore] 6[namestore]
7PREFIX = valgrind --leak-check=full 7#PREFIX = valgrind --leak-check=full
8AUTOSTART = YES 8AUTOSTART = YES
9UNIXPATH = /tmp/gnunet-service-namestore.sock 9UNIXPATH = /tmp/gnunet-service-namestore.sock
10UNIX_MATCH_UID = YES 10UNIX_MATCH_UID = YES
diff --git a/src/namestore/test_namestore_api_put.c b/src/namestore/test_namestore_api_put.c
index 8aa149ad9..2b01391ae 100644
--- a/src/namestore/test_namestore_api_put.c
+++ b/src/namestore/test_namestore_api_put.c
@@ -146,7 +146,6 @@ create_record (int count)
146 rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); 146 rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
147 memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); 147 memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
148 } 148 }
149
150 return rd; 149 return rd;
151} 150}
152 151
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c
index 95755ceee..e70a3baf0 100644
--- a/src/namestore/test_namestore_api_zone_iteration.c
+++ b/src/namestore/test_namestore_api_zone_iteration.c
@@ -24,6 +24,7 @@
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_common.h" 25#include "gnunet_common.h"
26#include "gnunet_namestore_service.h" 26#include "gnunet_namestore_service.h"
27#include "namestore.h"
27 28
28#define VERBOSE GNUNET_NO 29#define VERBOSE GNUNET_NO
29 30
@@ -42,6 +43,14 @@ static GNUNET_HashCode zone;
42static struct GNUNET_NAMESTORE_ZoneIterator *zi; 43static struct GNUNET_NAMESTORE_ZoneIterator *zi;
43static int res; 44static int res;
44 45
46struct GNUNET_CRYPTO_RsaSignature *sig_1;
47char * s_name_1;
48struct GNUNET_NAMESTORE_RecordData *s_rd_1;
49
50struct GNUNET_CRYPTO_RsaSignature *sig_2;
51char * s_name_2;
52struct GNUNET_NAMESTORE_RecordData *s_rd_2;
53
45static void 54static void
46start_arm (const char *cfgname) 55start_arm (const char *cfgname)
47{ 56{
@@ -87,6 +96,21 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
87 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 96 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
88 nsh = NULL; 97 nsh = NULL;
89 98
99 GNUNET_free_non_null(sig_1);
100 GNUNET_free_non_null(sig_2);
101 GNUNET_free_non_null(s_name_1);
102 GNUNET_free_non_null(s_name_2);
103 if (s_rd_1 != NULL)
104 {
105 GNUNET_free ((void *)s_rd_1->data);
106 GNUNET_free (s_rd_1);
107 }
108 if (s_rd_2 != NULL)
109 {
110 GNUNET_free ((void *)s_rd_2->data);
111 GNUNET_free (s_rd_2);
112 }
113
90 if (privkey != NULL) 114 if (privkey != NULL)
91 GNUNET_CRYPTO_rsa_key_free (privkey); 115 GNUNET_CRYPTO_rsa_key_free (privkey);
92 privkey = NULL; 116 privkey = NULL;
@@ -118,6 +142,21 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118 GNUNET_CRYPTO_rsa_key_free (privkey); 142 GNUNET_CRYPTO_rsa_key_free (privkey);
119 privkey = NULL; 143 privkey = NULL;
120 144
145 GNUNET_free_non_null(sig_1);
146 GNUNET_free_non_null(sig_2);
147 GNUNET_free_non_null(s_name_1);
148 GNUNET_free_non_null(s_name_2);
149 if (s_rd_1 != NULL)
150 {
151 GNUNET_free ((void *)s_rd_1->data);
152 GNUNET_free (s_rd_1);
153 }
154 if (s_rd_2 != NULL)
155 {
156 GNUNET_free ((void *)s_rd_2->data);
157 GNUNET_free (s_rd_2);
158 }
159
121 if (nsh != NULL) 160 if (nsh != NULL)
122 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 161 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
123 nsh = NULL; 162 nsh = NULL;
@@ -129,17 +168,6 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
129 res = 0; 168 res = 0;
130} 169}
131 170
132static void
133stop_iteration (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
134{
135 stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
136
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping iteration for zone `%s'\n", GNUNET_h2s (&zone));
138 GNUNET_NAMESTORE_zone_iteration_stop (zi);
139
140 GNUNET_SCHEDULER_add_now (&end, NULL);
141}
142
143void zone_proc (void *cls, 171void zone_proc (void *cls,
144 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, 172 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
145 struct GNUNET_TIME_Absolute expire, 173 struct GNUNET_TIME_Absolute expire,
@@ -148,9 +176,77 @@ void zone_proc (void *cls,
148 const struct GNUNET_NAMESTORE_RecordData *rd, 176 const struct GNUNET_NAMESTORE_RecordData *rd,
149 const struct GNUNET_CRYPTO_RsaSignature *signature) 177 const struct GNUNET_CRYPTO_RsaSignature *signature)
150{ 178{
179 int failed = GNUNET_NO;
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone)); 180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone));
152 181 if ((zone_key == NULL) && (name == NULL))
153 stopiteration_task = GNUNET_SCHEDULER_add_now (&stop_iteration, NULL); 182 {
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done\n");
184 GNUNET_SCHEDULER_add_now (&end, NULL);
185 }
186 else
187 {
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing results name %s \n", name);
189 if (0 == strcmp (name, s_name_1))
190 {
191 if (rd_count == 1)
192 {
193 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_1))
194 {
195 failed = GNUNET_YES;
196 GNUNET_break (0);
197 }
198 }
199 else
200 {
201 failed = GNUNET_YES;
202 GNUNET_break (0);
203 }
204 if (0 != memcmp (signature, sig_1, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
205 {
206 failed = GNUNET_YES;
207 GNUNET_break (0);
208 }
209 }
210 else if (0 == strcmp (name, s_name_2))
211 {
212 if (rd_count == 1)
213 {
214 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_2))
215 {
216 failed = GNUNET_YES;
217 GNUNET_break (0);
218 }
219 }
220 else
221 {
222 failed = GNUNET_YES;
223 GNUNET_break (0);
224 }
225 if (0 != memcmp (signature, sig_2, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
226 {
227 failed = GNUNET_YES;
228 GNUNET_break (0);
229 }
230
231 }
232 else
233 {
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing result `%s'\n", name);
235 GNUNET_break (0);
236 GNUNET_SCHEDULER_add_now (&end, NULL);
237 }
238
239 if (failed == GNUNET_NO)
240 {
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Telling namestore to send the next result\n");
242 GNUNET_NAMESTORE_zone_iterator_next (zi);
243 }
244 else
245 {
246 GNUNET_break (0);
247 GNUNET_SCHEDULER_add_now (&end, NULL);
248 }
249 }
154} 250}
155 251
156void 252void
@@ -171,6 +267,53 @@ delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
171 267
172} 268}
173 269
270void
271put_cont (void *cls, int32_t success, const char *emsg)
272{
273 static int c = 0;
274
275 if (success == GNUNET_OK)
276 {
277 c++;
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
279
280 }
281
282 if (c == 2)
283 {
284 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
285 NULL,
286 GNUNET_NAMESTORE_RF_NONE,
287 GNUNET_NAMESTORE_RF_NONE,
288 zone_proc,
289 &zone);
290 if (zi == NULL)
291 {
292 GNUNET_break (0);
293 GNUNET_SCHEDULER_cancel (endbadly_task);
294 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
295 }
296 }
297}
298
299static struct GNUNET_NAMESTORE_RecordData *
300create_record (int count)
301{
302 int c;
303 struct GNUNET_NAMESTORE_RecordData * rd;
304 rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));
305
306 for (c = 0; c < count; c++)
307 {
308 rd[c].expiration = GNUNET_TIME_absolute_get();
309 rd[c].record_type = 1111;
310 rd[c].data_size = 50;
311 rd[c].data = GNUNET_malloc(50);
312 memset ((char *) rd[c].data, 'a', 50);
313 }
314 return rd;
315}
316
174static void 317static void
175run (void *cls, char *const *args, const char *cfgfile, 318run (void *cls, char *const *args, const char *cfgfile,
176 const struct GNUNET_CONFIGURATION_Handle *cfg) 319 const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -181,8 +324,7 @@ run (void *cls, char *const *args, const char *cfgfile,
181 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey"); 324 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
182 GNUNET_assert (privkey != NULL); 325 GNUNET_assert (privkey != NULL);
183 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); 326 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
184 327 GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone);
185 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &zone);
186 328
187 start_arm (cfgfile); 329 start_arm (cfgfile);
188 GNUNET_assert (arm != NULL); 330 GNUNET_assert (arm != NULL);
@@ -190,18 +332,22 @@ run (void *cls, char *const *args, const char *cfgfile,
190 nsh = GNUNET_NAMESTORE_connect (cfg); 332 nsh = GNUNET_NAMESTORE_connect (cfg);
191 GNUNET_break (NULL != nsh); 333 GNUNET_break (NULL != nsh);
192 334
193 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
194 &zone, 336
195 GNUNET_NAMESTORE_RF_NONE, 337
196 GNUNET_NAMESTORE_RF_NONE, 338
197 zone_proc, 339 GNUNET_asprintf(&s_name_1, "dummy1");
198 &zone); 340 s_rd_1 = create_record(1);
199 if (zi == NULL) 341 sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1);
200 { 342 GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL);
201 GNUNET_break (0); 343
202 GNUNET_SCHEDULER_cancel (endbadly_task); 344
203 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
204 } 346 GNUNET_asprintf(&s_name_2, "dummy2");
347 s_rd_2 = create_record(1);
348
349 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);
205} 351}
206 352
207static int 353static 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
new file mode 100644
index 000000000..007010228
--- /dev/null
+++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -0,0 +1,384 @@
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 namestore_api.c zone iteration functionality
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, 10)
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_NAMESTORE_ZoneIterator *zi;
44static int res;
45
46struct GNUNET_CRYPTO_RsaSignature *sig_1;
47char * s_name_1;
48struct GNUNET_NAMESTORE_RecordData *s_rd_1;
49
50struct GNUNET_CRYPTO_RsaSignature *sig_2;
51char * s_name_2;
52struct GNUNET_NAMESTORE_RecordData *s_rd_2;
53
54static void
55start_arm (const char *cfgname)
56{
57 arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
58 "gnunet-service-arm", "-c", cfgname,
59#if VERBOSE_PEERS
60 "-L", "DEBUG",
61#else
62 "-L", "ERROR",
63#endif
64 NULL);
65}
66
67static void
68stop_arm ()
69{
70 if (NULL != arm)
71 {
72 if (0 != GNUNET_OS_process_kill (arm, SIGTERM))
73 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
74 GNUNET_OS_process_wait (arm);
75 GNUNET_OS_process_close (arm);
76 arm = NULL;
77 }
78}
79
80/**
81 * Re-establish the connection to the service.
82 *
83 * @param cls handle to use to re-connect.
84 * @param tc scheduler context
85 */
86static void
87endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
88{
89 if (stopiteration_task != GNUNET_SCHEDULER_NO_TASK)
90 {
91 GNUNET_SCHEDULER_cancel (stopiteration_task);
92 stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
93 }
94
95 if (nsh != NULL)
96 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
97 nsh = NULL;
98
99 GNUNET_free_non_null(sig_1);
100 GNUNET_free_non_null(sig_2);
101 GNUNET_free_non_null(s_name_1);
102 GNUNET_free_non_null(s_name_2);
103 if (s_rd_1 != NULL)
104 {
105 GNUNET_free ((void *)s_rd_1->data);
106 GNUNET_free (s_rd_1);
107 }
108 if (s_rd_2 != NULL)
109 {
110 GNUNET_free ((void *)s_rd_2->data);
111 GNUNET_free (s_rd_2);
112 }
113
114 if (privkey != NULL)
115 GNUNET_CRYPTO_rsa_key_free (privkey);
116 privkey = NULL;
117
118 if (NULL != arm)
119 stop_arm();
120
121 res = 1;
122}
123
124
125static void
126end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
127{
128 if (stopiteration_task != GNUNET_SCHEDULER_NO_TASK)
129 {
130 GNUNET_SCHEDULER_cancel (stopiteration_task);
131 stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
132 }
133
134 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
135 {
136 GNUNET_SCHEDULER_cancel (endbadly_task);
137 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
138 }
139
140
141 if (privkey != NULL)
142 GNUNET_CRYPTO_rsa_key_free (privkey);
143 privkey = NULL;
144
145 GNUNET_free_non_null(sig_1);
146 GNUNET_free_non_null(sig_2);
147 GNUNET_free_non_null(s_name_1);
148 GNUNET_free_non_null(s_name_2);
149 if (s_rd_1 != NULL)
150 {
151 GNUNET_free ((void *)s_rd_1->data);
152 GNUNET_free (s_rd_1);
153 }
154 if (s_rd_2 != NULL)
155 {
156 GNUNET_free ((void *)s_rd_2->data);
157 GNUNET_free (s_rd_2);
158 }
159
160 if (nsh != NULL)
161 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
162 nsh = NULL;
163
164
165 if (NULL != arm)
166 stop_arm();
167
168 res = 0;
169}
170
171void zone_proc (void *cls,
172 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
173 struct GNUNET_TIME_Absolute expire,
174 const char *name,
175 unsigned int rd_count,
176 const struct GNUNET_NAMESTORE_RecordData *rd,
177 const struct GNUNET_CRYPTO_RsaSignature *signature)
178{
179 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))
182 {
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done\n");
184 GNUNET_SCHEDULER_add_now (&end, NULL);
185 }
186 else
187 {
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing results name %s \n", name);
189 if (0 == strcmp (name, s_name_1))
190 {
191 if (rd_count == 1)
192 {
193 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_1))
194 {
195 failed = GNUNET_YES;
196 GNUNET_break (0);
197 }
198 }
199 else
200 {
201 failed = GNUNET_YES;
202 GNUNET_break (0);
203 }
204 if (0 != memcmp (signature, sig_1, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
205 {
206 failed = GNUNET_YES;
207 GNUNET_break (0);
208 }
209 }
210 else if (0 == strcmp (name, s_name_2))
211 {
212 if (rd_count == 1)
213 {
214 if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_2))
215 {
216 failed = GNUNET_YES;
217 GNUNET_break (0);
218 }
219 }
220 else
221 {
222 failed = GNUNET_YES;
223 GNUNET_break (0);
224 }
225 if (0 != memcmp (signature, sig_2, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
226 {
227 failed = GNUNET_YES;
228 GNUNET_break (0);
229 }
230
231 }
232 else
233 {
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing result `%s'\n", name);
235 GNUNET_break (0);
236 GNUNET_SCHEDULER_add_now (&end, NULL);
237 }
238
239 if (failed == GNUNET_NO)
240 {
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Telling namestore to send the next result\n");
242 GNUNET_NAMESTORE_zone_iterator_next (zi);
243 }
244 else
245 {
246 GNUNET_break (0);
247 GNUNET_SCHEDULER_add_now (&end, NULL);
248 }
249 }
250}
251
252void
253delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
254{
255 char *afsdir;
256
257 if (GNUNET_OK ==
258 GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite",
259 "FILENAME", &afsdir))
260 {
261 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
262 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
263 if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir))
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir);
265 GNUNET_free (afsdir);
266 }
267
268}
269
270void
271put_cont (void *cls, int32_t success, const char *emsg)
272{
273 static int c = 0;
274
275 if (success == GNUNET_OK)
276 {
277 c++;
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
279
280 }
281
282 if (c == 2)
283 {
284 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
285 &zone,
286 GNUNET_NAMESTORE_RF_NONE,
287 GNUNET_NAMESTORE_RF_NONE,
288 zone_proc,
289 &zone);
290 if (zi == NULL)
291 {
292 GNUNET_break (0);
293 GNUNET_SCHEDULER_cancel (endbadly_task);
294 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
295 }
296 }
297}
298
299static struct GNUNET_NAMESTORE_RecordData *
300create_record (int count)
301{
302 int c;
303 struct GNUNET_NAMESTORE_RecordData * rd;
304 rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));
305
306 for (c = 0; c < count; c++)
307 {
308 rd[c].expiration = GNUNET_TIME_absolute_get();
309 rd[c].record_type = 1111;
310 rd[c].data_size = 50;
311 rd[c].data = GNUNET_malloc(50);
312 memset ((char *) rd[c].data, 'a', 50);
313 }
314 return rd;
315}
316
317static void
318run (void *cls, char *const *args, const char *cfgfile,
319 const struct GNUNET_CONFIGURATION_Handle *cfg)
320{
321 delete_existing_db(cfg);
322 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL);
323
324 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
325 GNUNET_assert (privkey != NULL);
326 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
327 GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone);
328
329 start_arm (cfgfile);
330 GNUNET_assert (arm != NULL);
331
332 nsh = GNUNET_NAMESTORE_connect (cfg);
333 GNUNET_break (NULL != nsh);
334
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
336
337
338
339 GNUNET_asprintf(&s_name_1, "dummy1");
340 s_rd_1 = create_record(1);
341 sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1);
342 GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL);
343
344
345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
346 GNUNET_asprintf(&s_name_2, "dummy2");
347 s_rd_2 = create_record(1);
348
349 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);
351}
352
353static int
354check ()
355{
356 static char *const argv[] = { "test_namestore_api_zone_iteration",
357 "-c",
358 "test_namestore_api.conf",
359#if VERBOSE
360 "-L", "DEBUG",
361#endif
362 NULL
363 };
364 static struct GNUNET_GETOPT_CommandLineOption options[] = {
365 GNUNET_GETOPT_OPTION_END
366 };
367
368 res = 1;
369 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_api_zone_iteration",
370 "nohelp", options, &run, &res);
371 return res;
372}
373
374int
375main (int argc, char *argv[])
376{
377 int ret;
378
379 ret = check ();
380
381 return ret;
382}
383
384/* end of test_namestore_api_zone_iteration.c */