From 2f5b9e1354967db31504cfcf2281e546aedaa248 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 28 Feb 2012 10:18:27 +0000 Subject: [PATCH] - more zone iteration --- src/namestore/gnunet-service-namestore.c | 42 +++++++++++++++++-- src/namestore/namestore_api.c | 7 ++++ .../test_namestore_api_zone_iteration.c | 27 +++++++++++- 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index e796fe530..f96146ec2 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -42,6 +42,8 @@ struct GNUNET_NAMESTORE_ZoneIteration struct GNUNET_NAMESTORE_Client * client; + GNUNET_HashCode zone; + uint64_t op_id; uint32_t offset; @@ -593,7 +595,6 @@ void zone_iteration_proc (void *cls, zir_msg.op_id = htonl(zi->op_id); zir_msg.header.size = htons (sizeof (struct ZoneIterationResponseMessage)); - GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO); } @@ -606,6 +607,7 @@ static void handle_iteration_start (void *cls, struct ZoneIterationStartMessage * zis_msg = (struct ZoneIterationStartMessage *) message; struct GNUNET_NAMESTORE_Client *nc; struct GNUNET_NAMESTORE_ZoneIteration *zi; + int res; nc = client_lookup(client); if (nc == NULL) @@ -619,10 +621,12 @@ static void handle_iteration_start (void *cls, zi->op_id = ntohl (zis_msg->op_id); zi->offset = 0; zi->client = nc; + zi->zone = zis_msg->zone; GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); - GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, zi); + res = GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, zi); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "iterate_records: %i\n", res); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -631,6 +635,38 @@ static void handle_iteration_stop (void *cls, const struct GNUNET_MessageHeader * message) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_STOP"); + + struct GNUNET_NAMESTORE_Client *nc; + struct GNUNET_NAMESTORE_ZoneIteration *zi; + struct ZoneIterationStopMessage * zis_msg = (struct ZoneIterationStopMessage *) message; + uint32_t id; + + nc = client_lookup(client); + if (nc == NULL) + { + GNUNET_break_op (0); + GNUNET_SERVER_receive_done (client, GNUNET_OK); + return; + } + + id = ntohl (zis_msg->op_id); + for (zi = nc->op_head; zi != NULL; zi = zi->next) + { + if (zi->op_id == id) + break; + } + if (zi == NULL) + { + GNUNET_break_op (0); + GNUNET_SERVER_receive_done (client, GNUNET_OK); + return; + } + + GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, zi); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration for zone `%s'\n", GNUNET_h2s (&zi->zone)); + GNUNET_free (zi); + + GNUNET_SERVER_receive_done (client, GNUNET_OK); } static void handle_iteration_next (void *cls, @@ -671,7 +707,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, {&handle_iteration_start, NULL, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage)}, {&handle_iteration_stop, NULL, - GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, 0}, + GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, sizeof (struct ZoneIterationStopMessage)}, {&handle_iteration_next, NULL, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, 0}, {NULL, NULL, 0, 0} diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 17c638050..ace9945da 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c @@ -380,6 +380,13 @@ handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze, { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n", "ZONE_ITERATION_RESPONSE"); + + + if (ze->proc != NULL) + { + // FIXME + ze->proc(ze->proc_cls, NULL, GNUNET_TIME_absolute_get_forever(), "dummy", 0, NULL, NULL); + } } diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index a53a2febc..c0ef8c809 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c @@ -32,6 +32,7 @@ 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; @@ -76,6 +77,12 @@ stop_arm () 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; @@ -94,12 +101,19 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 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; @@ -115,6 +129,16 @@ 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, @@ -125,7 +149,8 @@ void zone_proc (void *cls, const struct GNUNET_CRYPTO_RsaSignature *signature) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone)); - endbadly_task = GNUNET_SCHEDULER_add_now (&end, NULL); + + stopiteration_task = GNUNET_SCHEDULER_add_now (&stop_iteration, NULL); } static void -- 2.25.1