From 645b26ba88218c4a2f9a022968a8c03e9035082d Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 May 2018 23:18:00 +0200 Subject: update namestore monitor API users to use new _next call where needed --- src/namestore/gnunet-namestore.c | 62 ++++++++++++++++++---- src/namestore/test_namestore_api_monitoring.c | 5 +- .../test_namestore_api_monitoring_existing.c | 55 +++++++++++++------ 3 files changed, 94 insertions(+), 28 deletions(-) (limited to 'src/namestore') diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index d329dcb3b..32b1a39d0 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c @@ -374,16 +374,12 @@ zone_iteration_error_cb (void *cls) /** * Process a record that was stored in the namestore. * - * @param cls closure - * @param zone_key private key of the zone * @param rname name that is being mapped (at most 255 characters long) * @param rd_len number of entries in @a rd array * @param rd array of records with data to store */ static void -display_record (void *cls, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, - const char *rname, +display_record (const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd) { @@ -393,8 +389,6 @@ display_record (void *cls, struct GNUNET_TIME_Absolute at; struct GNUNET_TIME_Relative rt; - (void) cls; - (void) zone_key; if ( (NULL != name) && (0 != strcmp (name, rname)) ) { @@ -442,11 +436,61 @@ display_record (void *cls, GNUNET_free (s); } FPRINTF (stdout, "%s", "\n"); +} + + +/** + * Process a record that was stored in the namestore. + * + * @param cls closure + * @param zone_key private key of the zone + * @param rname name that is being mapped (at most 255 characters long) + * @param rd_len number of entries in @a rd array + * @param rd array of records with data to store + */ +static void +display_record_iterator (void *cls, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, + const char *rname, + unsigned int rd_len, + const struct GNUNET_GNSRECORD_Data *rd) +{ + (void) cls; + (void) zone_key; + display_record (rname, + rd_len, + rd); GNUNET_NAMESTORE_zone_iterator_next (list_it, 1); } +/** + * Process a record that was stored in the namestore. + * + * @param cls closure + * @param zone_key private key of the zone + * @param rname name that is being mapped (at most 255 characters long) + * @param rd_len number of entries in @a rd array + * @param rd array of records with data to store + */ +static void +display_record_monitor (void *cls, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, + const char *rname, + unsigned int rd_len, + const struct GNUNET_GNSRECORD_Data *rd) +{ + (void) cls; + (void) zone_key; + display_record (rname, + rd_len, + rd); + GNUNET_NAMESTORE_zone_monitor_next (zm, + 1); +} + + /** * Function called once we are in sync in monitor mode. * @@ -956,7 +1000,7 @@ identity_cb (void *cls, &zone_pkey, &zone_iteration_error_cb, NULL, - &display_record, + &display_record_iterator, NULL, &zone_iteration_finished, NULL); @@ -1054,7 +1098,7 @@ identity_cb (void *cls, GNUNET_YES, &monitor_error_cb, NULL, - &display_record, + &display_record_monitor, NULL, &sync_cb, NULL); diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c index f6d4fe226..cd38b2c80 100644 --- a/src/namestore/test_namestore_api_monitoring.c +++ b/src/namestore/test_namestore_api_monitoring.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2013 GNUnet e.V. + Copyright (C) 2013, 2018 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -192,7 +192,8 @@ zone_proc (void *cls, GNUNET_break (0); fail = GNUNET_YES; } - + GNUNET_NAMESTORE_zone_monitor_next (zm, + 1); if (2 == ++returned_records) { if (endbadly_task != NULL) diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c index 17f726eb1..f6a74609e 100644 --- a/src/namestore/test_namestore_api_monitoring_existing.c +++ b/src/namestore/test_namestore_api_monitoring_existing.c @@ -159,19 +159,24 @@ zone_proc (void *cls, "Comparing results name %s\n", name); - if (0 != memcmp (zone_key, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) + if (0 != memcmp (zone_key, + privkey, + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Monitoring returned wrong zone key\n"); GNUNET_break (0); GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, + NULL); return; } if (0 == strcmp (name, s_name_1)) { - if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1)) + if (GNUNET_YES != + GNUNET_GNSRECORD_records_cmp (rd, + s_rd_1)) { GNUNET_break (0); fail = GNUNET_YES; @@ -179,7 +184,9 @@ zone_proc (void *cls, } else if (0 == strcmp (name, s_name_2)) { - if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2)) + if (GNUNET_YES != + GNUNET_GNSRECORD_records_cmp (rd, + s_rd_2)) { GNUNET_break (0); fail = GNUNET_YES; @@ -192,7 +199,8 @@ zone_proc (void *cls, GNUNET_break (0); fail = GNUNET_YES; } - + GNUNET_NAMESTORE_zone_monitor_next (zm, + 1); if (2 == ++returned_records) { if (endbadly_task != NULL) @@ -201,9 +209,11 @@ zone_proc (void *cls, endbadly_task = NULL; } if (GNUNET_YES == fail) - GNUNET_SCHEDULER_add_now (&endbadly, NULL); + GNUNET_SCHEDULER_add_now (&endbadly, + NULL); else - GNUNET_SCHEDULER_add_now (&end, NULL); + GNUNET_SCHEDULER_add_now (&end, + NULL); } } @@ -223,7 +233,9 @@ sync_cb (void *cls) static void -put_cont (void *cls, int32_t success, const char *emsg) +put_cont (void *cls, + int32_t success, + const char *emsg) { static int c = 0; char *label = cls; @@ -238,11 +250,15 @@ put_cont (void *cls, int32_t success, const char *emsg) if (success == GNUNET_OK) { c++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u: `%s'\n", c, label); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created record %u: `%s'\n", + c, + label); } else { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to created records\n"); GNUNET_break (0); GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); @@ -262,9 +278,11 @@ put_cont (void *cls, int32_t success, const char *emsg) NULL); if (NULL == zm) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone monitor\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create zone monitor\n"); GNUNET_break (0); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, + NULL); return; } } @@ -354,14 +372,17 @@ run (void *cls, GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, 1, s_rd_1, &put_cont, s_name_1))); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); GNUNET_asprintf(&s_name_2, "dummy2"); s_rd_2 = create_record(1); - GNUNET_assert (NULL != (ns_ops[1] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, - 1, s_rd_2, &put_cont, s_name_2))); - - + GNUNET_assert (NULL != (ns_ops[1] = + GNUNET_NAMESTORE_records_store (nsh, + privkey, + s_name_2, + 1, + s_rd_2, + &put_cont, + s_name_2))); } -- cgit v1.2.3