aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwachs <wachs@140774ce-b5e7-0310-ab8b-a85725594a96>2012-03-06 18:04:47 +0000
committerwachs <wachs@140774ce-b5e7-0310-ab8b-a85725594a96>2012-03-06 18:04:47 +0000
commitc64473d36dc6258583975cad700f72143623d7a2 (patch)
tree1c14cfc7ed1adfd0146b00fdb5f2514ebc10a540
parenta4a628d26b00720e885c990ad337bf8ab1a9431a (diff)
- zone iteration stuff
git-svn-id: https://gnunet.org/svn/gnunet@20318 140774ce-b5e7-0310-ab8b-a85725594a96
-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 8bfa0389bf..c52051082f 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -36,6 +36,7 @@ check_PROGRAMS = \
test_namestore_api_remove_not_existing_record \
test_namestore_api_zone_to_name \
test_namestore_api_zone_iteration \
+ test_namestore_api_zone_iteration_specific_zone \
test_namestore_record_serialization
if ENABLE_TEST_RUN
@@ -169,6 +170,12 @@ test_namestore_api_zone_iteration_SOURCES = \
test_namestore_api_zone_iteration_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/namestore/libgnunetnamestore.la
+
+test_namestore_api_zone_iteration_specific_zone_SOURCES = \
+ test_namestore_api_zone_iteration_specific_zone.c
+test_namestore_api_zone_iteration_specific_zone_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la
test_namestore_record_serialization_SOURCES = \
test_namestore_record_serialization.c
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index af5f84979e..59059d84ee 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,
rd_count_new, rd_new,
signature_new);
GNUNET_break (GNUNET_OK == res);
+ if (res == GNUNET_OK)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully put record for `%s' in database \n", crc->name);
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to put record for `%s' in database \n", crc->name);
res = GNUNET_YES;
end:
@@ -1163,40 +1167,68 @@ void zone_iteration_proc (void *cls,
const struct GNUNET_NAMESTORE_RecordData *rd,
const struct GNUNET_CRYPTO_RsaSignature *signature)
{
- struct ZoneIterationProcResult *zipr = cls;
- size_t len;
- if (zone_key != NULL)
- {
- zipr->zone_key = *zone_key;
- zipr->have_zone_key = GNUNET_YES;
- }
- else
- zipr->have_zone_key = GNUNET_NO;
-
- zipr->expire = expire;
-
- if (name != NULL)
- {
- memcpy (zipr->name, name, strlen(name) + 1);
- zipr->have_name = GNUNET_YES;
- }
- else
- zipr->have_name = GNUNET_NO;
+ struct GNUNET_NAMESTORE_ZoneIteration *zi = cls;
+ struct GNUNET_NAMESTORE_Client *nc = zi->client;
+ //size_t len;
- if (signature != NULL)
+ if ((zone_key == NULL) && (name == NULL))
{
- zipr->signature = *signature;
- zipr->have_signature = GNUNET_YES;
+ struct ZoneIterationResponseMessage zir_msg;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for zone `%s'\n", GNUNET_h2s(&zi->zone));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending empty `%s' message\n", "ZONE_ITERATION_RESPONSE");
+ zir_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
+ zir_msg.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage));
+ zir_msg.gns_header.r_id = htonl(zi->request_id);
+ zir_msg.expire = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_zero());
+ zir_msg.name_len = htons (0);
+ zir_msg.reserved = htons (0);
+ zir_msg.rd_count = htons (0);
+ zir_msg.rd_len = htons (0);
+ memset (&zir_msg.public_key, '\0', sizeof (zir_msg.public_key));
+ memset (&zir_msg.signature, '\0', sizeof (zir_msg.signature));
+ GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing zone iterator\n");
+ GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, zi);
+ GNUNET_free (zi);
+ return;
}
else
- zipr->have_signature = GNUNET_NO;
-
- if ((rd_count > 0) && (rd != NULL))
{
- len = GNUNET_NAMESTORE_records_get_size(rd_count, rd);
- zipr->rd_ser = GNUNET_malloc (len);
- GNUNET_NAMESTORE_records_serialize(rd_count, rd, len, zipr->rd_ser);
- zipr->rd_ser_len = len;
+ struct ZoneIterationResponseMessage *zir_msg;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iterating zone `%s'\n", name, GNUNET_h2s(&zi->zone));
+ size_t name_len;
+ size_t rd_ser_len;
+ size_t msg_size;
+ char *name_tmp;
+ char *rd_tmp;
+ name_len = strlen (name) +1;
+
+ rd_ser_len = GNUNET_NAMESTORE_records_get_size(rd_count, rd);
+ char rd_ser[rd_ser_len];
+ GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
+ msg_size = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_ser_len;
+ zir_msg = GNUNET_malloc(msg_size);
+
+ name_tmp = (char *) &zir_msg[1];
+ rd_tmp = &name_tmp[name_len];
+
+ zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
+ zir_msg->gns_header.header.size = htons (msg_size);
+ zir_msg->gns_header.r_id = htonl(zi->request_id);
+ zir_msg->expire = GNUNET_TIME_absolute_hton(expire);
+ zir_msg->reserved = htons (0);
+ zir_msg->name_len = htons (name_len);
+ zir_msg->rd_count = htons (rd_count);
+ zir_msg->rd_len = htons (rd_ser_len);
+ zir_msg->signature = *signature;
+ zir_msg->public_key = *zone_key;
+ memcpy (name_tmp, name, name_len);
+ memcpy (rd_tmp, rd_ser, rd_ser_len);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending empty `%s' message with size %u\n", "ZONE_ITERATION_RESPONSE", msg_size);
+ GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) zir_msg, GNUNET_NO);
+ GNUNET_free (zir_msg);
}
}
@@ -1209,8 +1241,6 @@ static void handle_iteration_start (void *cls,
struct ZoneIterationStartMessage * zis_msg = (struct ZoneIterationStartMessage *) message;
struct GNUNET_NAMESTORE_Client *nc;
struct GNUNET_NAMESTORE_ZoneIteration *zi;
- struct ZoneIterationResponseMessage zir_msg;
- struct ZoneIterationProcResult zipr;
int res;
nc = client_lookup(client);
@@ -1227,33 +1257,24 @@ static void handle_iteration_start (void *cls,
zi->client = nc;
zi->zone = zis_msg->zone;
- GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
-
- res = GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, &zipr);
- switch (res) {
- case GNUNET_OK:
- /* GNUNET_OK on success */
-
- break;
- case GNUNET_SYSERR:
- /* GNUNET_SYSERR on error */
- break;
- case GNUNET_NO:
- /* GNUNET_NO if there were no results, */
- break;
- default:
- break;
+ GNUNET_HashCode dummy;
+ GNUNET_HashCode *zone_tmp;
+ memset (&dummy, '\0', sizeof (dummy));
+ if (0 == memcmp (&dummy, &zis_msg->zone, sizeof (dummy)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over all zones\n");
+ zone_tmp = NULL;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over zone `%s'\n", GNUNET_h2s (&zis_msg->zone));
+ zone_tmp = &zis_msg->zone;
}
+ GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_ITERATION_RESPONSE");
- zir_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
- zir_msg.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage));
- zir_msg.gns_header.r_id = htonl(zi->request_id);
-
- GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO);
-
+ res = GSN_database->iterate_records (GSN_database->cls, zone_tmp , NULL, zi->offset , &zone_iteration_proc, zi);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -1327,9 +1348,10 @@ static void handle_iteration_next (void *cls,
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
-
zi->offset++;
+
GSN_database->iterate_records (GSN_database->cls, &zi->zone, NULL, zi->offset , &zone_iteration_proc, zi);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 31de00c81d..ae9ed1a271 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,
struct GNUNET_NAMESTORE_Handle *h = qe->nsh;
int res = ntohl (msg->op_result);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' %i\n",
- "RECORD_CREATE_RESPONSE", ntohs (msg->op_result));
if (res == GNUNET_YES)
{
if (qe->cont != NULL)
@@ -582,12 +580,66 @@ handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n",
"ZONE_ITERATION_RESPONSE");
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubdummy;
+ size_t msg_len = 0;
+ size_t exp_msg_len = 0;
+ size_t name_len = 0;
+ size_t rd_len = 0;
+ unsigned rd_count = 0;
- if (ze->proc != NULL)
+ char *name_tmp;
+ char *rd_ser_tmp;
+ struct GNUNET_TIME_Absolute expire;
+
+ msg_len = ntohs (msg->gns_header.header.size);
+ rd_len = ntohs (msg->rd_len);
+ rd_count = ntohs (msg->rd_count);
+ name_len = ntohs (msg->name_len);
+ expire = GNUNET_TIME_absolute_ntoh (msg->expire);
+
+ exp_msg_len = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_len;
+ if (msg_len != exp_msg_len)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message size describes with `%u' bytes but calculated size is %u bytes \n",
+ msg_len, exp_msg_len);
+ GNUNET_break_op (0);
+ return;
+ }
+ if (0 != ntohs (msg->reserved))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+
+ memset (&pubdummy, '\0', sizeof (pubdummy));
+ if ((0 == name_len) && (0 == (memcmp (&msg->public_key, &pubdummy, sizeof (pubdummy)))))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration is completed!\n");
+
+ if (ze->proc != NULL)
+ ze->proc(ze->proc_cls, NULL, GNUNET_TIME_absolute_get_zero (), NULL , 0, NULL, NULL);
+
+ GNUNET_CONTAINER_DLL_remove(ze->h->z_head, ze->h->z_tail, ze);
+ GNUNET_free (ze);
+ return;
+ }
+
+ name_tmp = (char *) &msg[1];
+ if ((name_tmp[name_len -1] != '\0') || (name_len > 256))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ rd_ser_tmp = (char *) &name_tmp[name_len];
+ struct GNUNET_NAMESTORE_RecordData rd[rd_count];
+ if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd))
{
- // FIXME
- ze->proc(ze->proc_cls, NULL, GNUNET_TIME_absolute_get_forever(), "dummy", 0, NULL, NULL);
+ GNUNET_break_op (0);
+ return;
}
+
+ if (ze->proc != NULL)
+ ze->proc(ze->proc_cls, &msg->public_key, expire, name_tmp, rd_count, rd, &msg->signature);
}
@@ -1425,7 +1477,7 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
uint32_t rid = 0;
GNUNET_assert (NULL != h);
- GNUNET_assert (NULL != zone);
+
rid = get_op_id(h);
it = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_ZoneIterator));
@@ -1448,7 +1500,10 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START);
msg->gns_header.header.size = htons (msg_size);
msg->gns_header.r_id = htonl (rid);
- msg->zone = *zone;
+ if (NULL == zone)
+ msg->zone = *zone;
+ else
+ memset (&msg->zone, '\0', sizeof (msg->zone));
msg->must_have_flags = ntohs (must_have_flags);
msg->must_not_have_flags = ntohs (must_not_have_flags);
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf
index c437b414a1..f4cd32dbdc 100644
--- a/src/namestore/test_namestore_api.conf
+++ b/src/namestore/test_namestore_api.conf
@@ -4,7 +4,7 @@ DEFAULTSERVICES = namestore
UNIXPATH = /tmp/gnunet-p1-service-arm.sock
[namestore]
-PREFIX = valgrind --leak-check=full
+#PREFIX = valgrind --leak-check=full
AUTOSTART = YES
UNIXPATH = /tmp/gnunet-service-namestore.sock
UNIX_MATCH_UID = YES
diff --git a/src/namestore/test_namestore_api_put.c b/src/namestore/test_namestore_api_put.c
index 8aa149ad9f..2b01391ae3 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)
rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
}
-
return rd;
}
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c
index 95755ceee3..e70a3baf0b 100644
--- a/src/namestore/test_namestore_api_zone_iteration.c
+++ b/src/namestore/test_namestore_api_zone_iteration.c
@@ -24,6 +24,7 @@
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_namestore_service.h"
+#include "namestore.h"
#define VERBOSE GNUNET_NO
@@ -42,6 +43,14 @@ static GNUNET_HashCode zone;
static struct GNUNET_NAMESTORE_ZoneIterator *zi;
static int res;
+struct GNUNET_CRYPTO_RsaSignature *sig_1;
+char * s_name_1;
+struct GNUNET_NAMESTORE_RecordData *s_rd_1;
+
+struct GNUNET_CRYPTO_RsaSignature *sig_2;
+char * s_name_2;
+struct GNUNET_NAMESTORE_RecordData *s_rd_2;
+
static void
start_arm (const char *cfgname)
{
@@ -87,6 +96,21 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
nsh = NULL;
+ GNUNET_free_non_null(sig_1);
+ GNUNET_free_non_null(sig_2);
+ GNUNET_free_non_null(s_name_1);
+ GNUNET_free_non_null(s_name_2);
+ if (s_rd_1 != NULL)
+ {
+ GNUNET_free ((void *)s_rd_1->data);
+ GNUNET_free (s_rd_1);
+ }
+ if (s_rd_2 != NULL)
+ {
+ GNUNET_free ((void *)s_rd_2->data);
+ GNUNET_free (s_rd_2);
+ }
+
if (privkey != NULL)
GNUNET_CRYPTO_rsa_key_free (privkey);
privkey = NULL;
@@ -118,6 +142,21 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
GNUNET_CRYPTO_rsa_key_free (privkey);
privkey = NULL;
+ GNUNET_free_non_null(sig_1);
+ GNUNET_free_non_null(sig_2);
+ GNUNET_free_non_null(s_name_1);
+ GNUNET_free_non_null(s_name_2);
+ if (s_rd_1 != NULL)
+ {
+ GNUNET_free ((void *)s_rd_1->data);
+ GNUNET_free (s_rd_1);
+ }
+ if (s_rd_2 != NULL)
+ {
+ GNUNET_free ((void *)s_rd_2->data);
+ GNUNET_free (s_rd_2);
+ }
+
if (nsh != NULL)
GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
nsh = NULL;
@@ -129,17 +168,6 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
res = 0;
}
-static void
-stop_iteration (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping iteration for zone `%s'\n", GNUNET_h2s (&zone));
- GNUNET_NAMESTORE_zone_iteration_stop (zi);
-
- GNUNET_SCHEDULER_add_now (&end, NULL);
-}
-
void zone_proc (void *cls,
const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
struct GNUNET_TIME_Absolute expire,
@@ -148,9 +176,77 @@ void zone_proc (void *cls,
const struct GNUNET_NAMESTORE_RecordData *rd,
const struct GNUNET_CRYPTO_RsaSignature *signature)
{
+ int failed = GNUNET_NO;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone));
-
- stopiteration_task = GNUNET_SCHEDULER_add_now (&stop_iteration, NULL);
+ if ((zone_key == NULL) && (name == NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done\n");
+ GNUNET_SCHEDULER_add_now (&end, NULL);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing results name %s \n", name);
+ if (0 == strcmp (name, s_name_1))
+ {
+ if (rd_count == 1)
+ {
+ if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_1))
+ {
+ failed = GNUNET_YES;
+ GNUNET_break (0);
+ }
+ }
+ else
+ {
+ failed = GNUNET_YES;
+ GNUNET_break (0);
+ }
+ if (0 != memcmp (signature, sig_1, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
+ {
+ failed = GNUNET_YES;
+ GNUNET_break (0);
+ }
+ }
+ else if (0 == strcmp (name, s_name_2))
+ {
+ if (rd_count == 1)
+ {
+ if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_2))
+ {
+ failed = GNUNET_YES;
+ GNUNET_break (0);
+ }
+ }
+ else
+ {
+ failed = GNUNET_YES;
+ GNUNET_break (0);
+ }
+ if (0 != memcmp (signature, sig_2, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
+ {
+ failed = GNUNET_YES;
+ GNUNET_break (0);
+ }
+
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing result `%s'\n", name);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_now (&end, NULL);
+ }
+
+ if (failed == GNUNET_NO)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Telling namestore to send the next result\n");
+ GNUNET_NAMESTORE_zone_iterator_next (zi);
+ }
+ else
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_now (&end, NULL);
+ }
+ }
}
void
@@ -171,6 +267,53 @@ delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
}
+void
+put_cont (void *cls, int32_t success, const char *emsg)
+{
+ static int c = 0;
+
+ if (success == GNUNET_OK)
+ {
+ c++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
+
+ }
+
+ if (c == 2)
+ {
+ zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
+ NULL,
+ GNUNET_NAMESTORE_RF_NONE,
+ GNUNET_NAMESTORE_RF_NONE,
+ zone_proc,
+ &zone);
+ if (zi == NULL)
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_cancel (endbadly_task);
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ }
+ }
+}
+
+static struct GNUNET_NAMESTORE_RecordData *
+create_record (int count)
+{
+ int c;
+ struct GNUNET_NAMESTORE_RecordData * rd;
+ rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));
+
+ for (c = 0; c < count; c++)
+ {
+ rd[c].expiration = GNUNET_TIME_absolute_get();
+ rd[c].record_type = 1111;
+ rd[c].data_size = 50;
+ rd[c].data = GNUNET_malloc(50);
+ memset ((char *) rd[c].data, 'a', 50);
+ }
+ return rd;
+}
+
static void
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -181,8 +324,7 @@ run (void *cls, char *const *args, const char *cfgfile,
privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
-
- GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &zone);
+ GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone);
start_arm (cfgfile);
GNUNET_assert (arm != NULL);
@@ -190,18 +332,22 @@ run (void *cls, char *const *args, const char *cfgfile,
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
- &zone,
- GNUNET_NAMESTORE_RF_NONE,
- GNUNET_NAMESTORE_RF_NONE,
- zone_proc,
- &zone);
- if (zi == NULL)
- {
- GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
+
+
+
+ GNUNET_asprintf(&s_name_1, "dummy1");
+ s_rd_1 = create_record(1);
+ sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1);
+ GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL);
+
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
+ GNUNET_asprintf(&s_name_2, "dummy2");
+ s_rd_2 = create_record(1);
+
+ sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_name_2, s_rd_2, 1);
+ GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL);
}
static 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 0000000000..0070102280
--- /dev/null
+++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -0,0 +1,384 @@
+/*
+ This file is part of GNUnet.
+ (C) 2009 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file namestore/test_namestore_api_zone_iteration.c
+ * @brief testcase for namestore_api.c zone iteration functionality
+ */
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_namestore_service.h"
+#include "namestore.h"
+
+#define VERBOSE GNUNET_NO
+
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+
+static struct GNUNET_NAMESTORE_Handle * nsh;
+
+static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
+static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task;
+static struct GNUNET_OS_Process *arm;
+
+static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
+static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
+static GNUNET_HashCode zone;
+
+static struct GNUNET_NAMESTORE_ZoneIterator *zi;
+static int res;
+
+struct GNUNET_CRYPTO_RsaSignature *sig_1;
+char * s_name_1;
+struct GNUNET_NAMESTORE_RecordData *s_rd_1;
+
+struct GNUNET_CRYPTO_RsaSignature *sig_2;
+char * s_name_2;
+struct GNUNET_NAMESTORE_RecordData *s_rd_2;
+
+static void
+start_arm (const char *cfgname)
+{
+ arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
+ "gnunet-service-arm", "-c", cfgname,
+#if VERBOSE_PEERS
+ "-L", "DEBUG",
+#else
+ "-L", "ERROR",
+#endif
+ NULL);
+}
+
+static void
+stop_arm ()
+{
+ if (NULL != arm)
+ {
+ if (0 != GNUNET_OS_process_kill (arm, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ GNUNET_OS_process_wait (arm);
+ GNUNET_OS_process_close (arm);
+ arm = NULL;
+ }
+}
+
+/**
+ * Re-establish the connection to the service.
+ *
+ * @param cls handle to use to re-connect.
+ * @param tc scheduler context
+ */
+static void
+endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (stopiteration_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (stopiteration_task);
+ stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+
+ if (nsh != NULL)
+ GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
+ nsh = NULL;
+
+ GNUNET_free_non_null(sig_1);
+ GNUNET_free_non_null(sig_2);
+ GNUNET_free_non_null(s_name_1);
+ GNUNET_free_non_null(s_name_2);
+ if (s_rd_1 != NULL)
+ {
+ GNUNET_free ((void *)s_rd_1->data);
+ GNUNET_free (s_rd_1);
+ }
+ if (s_rd_2 != NULL)
+ {
+ GNUNET_free ((void *)s_rd_2->data);
+ GNUNET_free (s_rd_2);
+ }
+
+ if (privkey != NULL)
+ GNUNET_CRYPTO_rsa_key_free (privkey);
+ privkey = NULL;
+
+ if (NULL != arm)
+ stop_arm();
+
+ res = 1;
+}
+
+
+static void
+end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (stopiteration_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (stopiteration_task);
+ stopiteration_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+
+ if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (endbadly_task);
+ endbadly_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+
+
+ if (privkey != NULL)
+ GNUNET_CRYPTO_rsa_key_free (privkey);
+ privkey = NULL;
+
+ GNUNET_free_non_null(sig_1);
+ GNUNET_free_non_null(sig_2);
+ GNUNET_free_non_null(s_name_1);
+ GNUNET_free_non_null(s_name_2);
+ if (s_rd_1 != NULL)
+ {
+ GNUNET_free ((void *)s_rd_1->data);
+ GNUNET_free (s_rd_1);
+ }
+ if (s_rd_2 != NULL)
+ {
+ GNUNET_free ((void *)s_rd_2->data);
+ GNUNET_free (s_rd_2);
+ }
+
+ if (nsh != NULL)
+ GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
+ nsh = NULL;
+
+
+ if (NULL != arm)
+ stop_arm();
+
+ res = 0;
+}
+
+void zone_proc (void *cls,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+ struct GNUNET_TIME_Absolute expire,
+ const char *name,
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_RsaSignature *signature)
+{
+ int failed = GNUNET_NO;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone));
+ if ((zone_key == NULL) && (name == NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done\n");
+ GNUNET_SCHEDULER_add_now (&end, NULL);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing results name %s \n", name);
+ if (0 == strcmp (name, s_name_1))
+ {
+ if (rd_count == 1)
+ {
+ if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_1))
+ {
+ failed = GNUNET_YES;
+ GNUNET_break (0);
+ }
+ }
+ else
+ {
+ failed = GNUNET_YES;
+ GNUNET_break (0);
+ }
+ if (0 != memcmp (signature, sig_1, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
+ {
+ failed = GNUNET_YES;
+ GNUNET_break (0);
+ }
+ }
+ else if (0 == strcmp (name, s_name_2))
+ {
+ if (rd_count == 1)
+ {
+ if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_2))
+ {
+ failed = GNUNET_YES;
+ GNUNET_break (0);
+ }
+ }
+ else
+ {
+ failed = GNUNET_YES;
+ GNUNET_break (0);
+ }
+ if (0 != memcmp (signature, sig_2, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
+ {
+ failed = GNUNET_YES;
+ GNUNET_break (0);
+ }
+
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing result `%s'\n", name);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_now (&end, NULL);
+ }
+
+ if (failed == GNUNET_NO)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Telling namestore to send the next result\n");
+ GNUNET_NAMESTORE_zone_iterator_next (zi);
+ }
+ else
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_now (&end, NULL);
+ }
+ }
+}
+
+void
+delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ char *afsdir;
+
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite",
+ "FILENAME", &afsdir))
+ {
+ if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
+ if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
+ if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir);
+ GNUNET_free (afsdir);
+ }
+
+}
+
+void
+put_cont (void *cls, int32_t success, const char *emsg)
+{
+ static int c = 0;
+
+ if (success == GNUNET_OK)
+ {
+ c++;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
+
+ }
+
+ if (c == 2)
+ {
+ zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
+ &zone,
+ GNUNET_NAMESTORE_RF_NONE,
+ GNUNET_NAMESTORE_RF_NONE,
+ zone_proc,
+ &zone);
+ if (zi == NULL)
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_cancel (endbadly_task);
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ }
+ }
+}
+
+static struct GNUNET_NAMESTORE_RecordData *
+create_record (int count)
+{
+ int c;
+ struct GNUNET_NAMESTORE_RecordData * rd;
+ rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));
+
+ for (c = 0; c < count; c++)
+ {
+ rd[c].expiration = GNUNET_TIME_absolute_get();
+ rd[c].record_type = 1111;
+ rd[c].data_size = 50;
+ rd[c].data = GNUNET_malloc(50);
+ memset ((char *) rd[c].data, 'a', 50);
+ }
+ return rd;
+}
+
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ delete_existing_db(cfg);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL);
+
+ privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
+ GNUNET_assert (privkey != NULL);
+ GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
+ GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone);
+
+ start_arm (cfgfile);
+ GNUNET_assert (arm != NULL);
+
+ nsh = GNUNET_NAMESTORE_connect (cfg);
+ GNUNET_break (NULL != nsh);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
+
+
+
+ GNUNET_asprintf(&s_name_1, "dummy1");
+ s_rd_1 = create_record(1);
+ sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1);
+ GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL);
+
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
+ GNUNET_asprintf(&s_name_2, "dummy2");
+ s_rd_2 = create_record(1);
+
+ sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_name_2, s_rd_2, 1);
+ GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL);
+}
+
+static int
+check ()
+{
+ static char *const argv[] = { "test_namestore_api_zone_iteration",
+ "-c",
+ "test_namestore_api.conf",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ NULL
+ };
+ static struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ res = 1;
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_api_zone_iteration",
+ "nohelp", options, &run, &res);
+ return res;
+}
+
+int
+main (int argc, char *argv[])
+{
+ int ret;
+
+ ret = check ();
+
+ return ret;
+}
+
+/* end of test_namestore_api_zone_iteration.c */