[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] branch master updated: implement new functions in
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] branch master updated: implement new functions in libgnunetsq, clean up sqlite namestore plugin, implement flow control in namestore API and tests |
Date: |
Wed, 09 May 2018 17:33:09 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 8bb475af9 implement new functions in libgnunetsq, clean up sqlite
namestore plugin, implement flow control in namestore API and tests
8bb475af9 is described below
commit 8bb475af99260f1d107dbc8908268ae93960aa83
Author: Christian Grothoff <address@hidden>
AuthorDate: Wed May 9 17:33:04 2018 +0200
implement new functions in libgnunetsq, clean up sqlite namestore plugin,
implement flow control in namestore API and tests
---
src/gnsrecord/gnsrecord_serialization.c | 3 +-
src/include/gnunet_disk_lib.h | 12 +
src/include/gnunet_sq_lib.h | 119 +++++
src/namestore/gnunet-service-namestore.c | 501 +++++++++++++++------
src/namestore/plugin_namestore_flat.c | 6 +-
src/namestore/plugin_namestore_sqlite.c | 260 ++++-------
src/namestore/test_namestore_api_lookup_nick.c | 37 +-
src/namestore/test_namestore_api_lookup_private.c | 52 +--
src/namestore/test_namestore_api_lookup_public.c | 31 +-
src/namestore/test_namestore_api_lookup_shadow.c | 40 +-
.../test_namestore_api_lookup_shadow_filter.c | 34 +-
src/namestore/test_namestore_api_monitoring.c | 65 ++-
.../test_namestore_api_monitoring_existing.c | 42 +-
src/namestore/test_namestore_api_remove.c | 42 +-
...test_namestore_api_remove_not_existing_record.c | 37 +-
src/namestore/test_namestore_api_store.c | 33 +-
src/namestore/test_namestore_api_store_update.c | 175 +++----
src/namestore/test_namestore_api_zone_iteration.c | 200 ++++----
.../test_namestore_api_zone_iteration_nick.c | 57 +--
...st_namestore_api_zone_iteration_specific_zone.c | 54 +--
src/namestore/test_namestore_api_zone_to_name.c | 34 +-
src/namestore/test_plugin_namestore.c | 4 +
src/sq/Makefile.am | 4 +-
src/sq/sq_exec.c | 109 +++++
src/sq/sq_prepare.c | 81 ++++
src/util/disk.c | 53 ++-
26 files changed, 1199 insertions(+), 886 deletions(-)
diff --git a/src/gnsrecord/gnsrecord_serialization.c
b/src/gnsrecord/gnsrecord_serialization.c
index 190f62fc2..3da24d72a 100644
--- a/src/gnsrecord/gnsrecord_serialization.c
+++ b/src/gnsrecord/gnsrecord_serialization.c
@@ -161,11 +161,10 @@ GNUNET_GNSRECORD_records_deserialize (size_t len,
struct GNUNET_GNSRECORD_Data *dest)
{
struct NetworkRecord rec;
- unsigned int i;
size_t off;
off = 0;
- for (i=0;i<rd_count;i++)
+ for (unsigned int i=0;i<rd_count;i++)
{
if (off + sizeof (rec) > len)
return GNUNET_SYSERR;
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index be2885460..114a22052 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -709,6 +709,18 @@ GNUNET_DISK_directory_remove (const char *filename);
/**
+ * Remove the directory given under @a option in
+ * section [PATHS] in configuration under @a cfg_filename
+ *
+ * @param cfg_filename configuration file to parse
+ * @param option option with the dir name to purge
+ */
+void
+GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
+ const char *option);
+
+
+/**
* Implementation of "mkdir -p"
*
* @param dir the directory to create
diff --git a/src/include/gnunet_sq_lib.h b/src/include/gnunet_sq_lib.h
index f3adbc4c2..61fd5299a 100644
--- a/src/include/gnunet_sq_lib.h
+++ b/src/include/gnunet_sq_lib.h
@@ -446,6 +446,125 @@ void
GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs);
+
+/* ******************** sq_prepare.c functions ************** */
+
+
+/**
+ * Information needed to run a list of SQL statements using
+ * #GNUNET_SQ_exec_statements().
+ */
+struct GNUNET_SQ_PrepareStatement {
+
+ /**
+ * Actual SQL statement.
+ */
+ const char *sql;
+
+ /**
+ * Where to store handle?
+ */
+ sqlite3_stmt **pstmt;
+
+};
+
+
+/**
+ * Terminator for executable statement list.
+ */
+#define GNUNET_SQ_PREPARE_END { NULL, NULL }
+
+
+/**
+ * Create a `struct GNUNET_SQ_PrepareStatement`
+ *
+ * @param sql actual SQL statement
+ * @param pstmt where to store the handle
+ * @return initialized struct
+ */
+struct GNUNET_SQ_PrepareStatement
+GNUNET_SQ_make_prepare (const char *sql,
+ sqlite3_stmt **pstmt);
+
+
+
+/**
+ * Prepare all statements given in the (NULL,NULL)-terminated
+ * array at @a ps
+ *
+ * @param dbh database handle
+ * @param ps array of statements to prepare
+ * @return #GNUNET_OK on success
+ */
+int
+GNUNET_SQ_prepare (sqlite3 *dbh,
+ const struct GNUNET_SQ_PrepareStatement *ps);
+
+
+/* ******************** sq_exec.c functions ************** */
+
+
+/**
+ * Information needed to run a list of SQL statements using
+ * #GNUNET_SQ_exec_statements().
+ */
+struct GNUNET_SQ_ExecuteStatement {
+
+ /**
+ * Actual SQL statement.
+ */
+ const char *sql;
+
+ /**
+ * Should we ignore errors?
+ */
+ int ignore_errors;
+
+};
+
+
+/**
+ * Terminator for executable statement list.
+ */
+#define GNUNET_SQ_EXECUTE_STATEMENT_END { NULL, GNUNET_SYSERR }
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_execute (const char *sql);
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
+ * be tolerated.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_try_execute (const char *sql);
+
+
+/**
+ * Request execution of an array of statements @a es from Postgres.
+ *
+ * @param dbh database to execute the statements over
+ * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
+ * statements.
+ * @return #GNUNET_OK on success (modulo statements where errors can be
ignored)
+ * #GNUNET_SYSERR on error
+ */
+int
+GNUNET_SQ_exec_statements (sqlite3 *dbh,
+ const struct GNUNET_SQ_ExecuteStatement *es);
+
+
+
#endif /* GNUNET_SQ_LIB_H_ */
/* end of include/gnunet_sq_lib.h */
diff --git a/src/namestore/gnunet-service-namestore.c
b/src/namestore/gnunet-service-namestore.c
index f47c8776b..a92b8104a 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2012, 2013, 2014 GNUnet e.V.
+ Copyright (C) 2012, 2013, 2014, 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
@@ -23,6 +23,9 @@
* @brief namestore for the GNUnet naming system
* @author Matthias Wachs
* @author Christian Grothoff
+ *
+ * TODO:
+ * - run testcases, make sure everything works!
*/
#include "platform.h"
#include "gnunet_util_lib.h"
@@ -175,6 +178,27 @@ struct ZoneMonitor
*/
uint64_t limit;
+ /**
+ * How many more requests may we receive from the iterator
+ * before it is at the limit we gave it? Will be below or
+ * equal to @e limit. The effective limit for monitor
+ * events is thus @e iteration_cnt - @e limit!
+ */
+ uint64_t iteration_cnt;
+
+ /**
+ * Are we (still) in the initial iteration pass?
+ */
+ int in_first_iteration;
+
+ /**
+ * Is there a store activity waiting for this monitor? We only raise the
+ * flag when it happens and search the DLL for the store activity when we
+ * had a limit increase. If we cannot find any waiting store activity at
+ * that time, we clear the flag again.
+ */
+ int sa_waiting;
+
};
@@ -212,6 +236,57 @@ struct CacheOperation
/**
+ * Information for an ongoing #handle_record_store() operation.
+ * Needed as we may wait for monitors to be ready for the notification.
+ */
+struct StoreActivity
+{
+ /**
+ * Kept in a DLL.
+ */
+ struct StoreActivity *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct StoreActivity *prev;
+
+ /**
+ * Which client triggered the store activity?
+ */
+ struct NamestoreClient *nc;
+
+ /**
+ * Copy of the original store message (as data fields in @e rd will
+ * point into it!).
+ */
+ const struct RecordStoreMessage *rsm;
+
+ /**
+ * Array of record data to store (without NICK unless this is about
+ * #GNUNET_GNS_EMPTY_LABEL_AT). Length is in @e rd_count.
+ */
+ struct GNUNET_GNSRECORD_Data *rd;
+
+ /**
+ * Next zone monitor that still needs to be notified about this PUT.
+ */
+ struct ZoneMonitor *zm_pos;
+
+ /**
+ * Label nicely canonicalized (lower case).
+ */
+ char *conv_name;
+
+ /**
+ * How many records do we try to store?
+ */
+ unsigned int rd_count;
+
+};
+
+
+/**
* Public key of all zeros.
*/
static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero;
@@ -262,6 +337,16 @@ static struct ZoneMonitor *monitor_head;
static struct ZoneMonitor *monitor_tail;
/**
+ * Head of DLL of monitor-blocked store activities.
+ */
+static struct StoreActivity *sa_head;
+
+/**
+ * Tail of DLL of monitor-blocked store activities.
+ */
+static struct StoreActivity *sa_tail;
+
+/**
* Notification context shared by all monitors.
*/
static struct GNUNET_NotificationContext *monitor_nc;
@@ -326,80 +411,21 @@ cleanup_task (void *cls)
/**
- * Called whenever a client is disconnected.
- * Frees our resources associated with that client.
+ * Release memory used by @a sa.
*
- * @param cls closure
- * @param client identification of the client
- * @param app_ctx the `struct NamestoreClient` of @a client
+ * @param sa activity to free
*/
static void
-client_disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- void *app_ctx)
-{
- struct NamestoreClient *nc = app_ctx;
- struct ZoneIteration *no;
- struct ZoneMonitor *zm;
- struct CacheOperation *cop;
-
- (void) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p disconnected\n",
- client);
- for (zm = monitor_head; NULL != zm; zm = zm->next)
- {
- if (nc == zm->nc)
- {
- GNUNET_CONTAINER_DLL_remove (monitor_head,
- monitor_tail,
- zm);
- if (NULL != zm->task)
- {
- GNUNET_SCHEDULER_cancel (zm->task);
- zm->task = NULL;
- }
- GNUNET_free (zm);
- break;
- }
- }
- while (NULL != (no = nc->op_head))
- {
- GNUNET_CONTAINER_DLL_remove (nc->op_head,
- nc->op_tail,
- no);
- GNUNET_free (no);
- }
- for (cop = cop_head; NULL != cop; cop = cop->next)
- if (nc == cop->nc)
- cop->nc = NULL;
- GNUNET_free (nc);
-}
-
-
-/**
- * Add a client to our list of active clients.
- *
- * @param cls NULL
- * @param client client to add
- * @param mq message queue for @a client
- * @return internal namestore client structure for this client
- */
-static void *
-client_connect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- struct GNUNET_MQ_Handle *mq)
+free_store_activity (struct StoreActivity *sa)
{
- struct NamestoreClient *nc;
-
- (void) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p connected\n",
- client);
- nc = GNUNET_new (struct NamestoreClient);
- nc->client = client;
- nc->mq = mq;
- return nc;
+ GNUNET_CONTAINER_DLL_remove (sa_head,
+ sa_tail,
+ sa);
+ GNUNET_array_grow (sa->rd,
+ sa->rd_count,
+ 0);
+ GNUNET_free (sa->conv_name);
+ GNUNET_free (sa);
}
@@ -795,6 +821,173 @@ refresh_block (struct NamestoreClient *nc,
/**
+ * Continue processing the @a sa.
+ *
+ * @param sa store activity to process
+ */
+static void
+continue_store_activity (struct StoreActivity *sa)
+{
+ const struct RecordStoreMessage *rp_msg = sa->rsm;
+
+ for (struct ZoneMonitor *zm = sa->zm_pos;
+ NULL != zm;
+ zm = sa->zm_pos)
+ {
+ if ( (0 != memcmp (&rp_msg->private_key,
+ &zm->zone,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) &&
+ (0 != memcmp (&zm->zone,
+ &zero,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
+ sa->zm_pos = zm->next; /* not interesting to this monitor */
+ if (zm->limit == zm->iteration_cnt)
+ {
+ zm->sa_waiting = GNUNET_YES;
+ return; /* blocked on zone monitor */
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Notifying monitor about changes under label `%s'\n",
+ sa->conv_name);
+ zm->limit--;
+ send_lookup_response (zm->nc,
+ 0,
+ &rp_msg->private_key,
+ sa->conv_name,
+ sa->rd_count,
+ sa->rd);
+ sa->zm_pos = zm->next;
+ }
+ /* great, done with the monitors, unpack (again) for refresh_block operation
*/
+ {
+ size_t name_len;
+ size_t rd_ser_len;
+ uint32_t rid;
+ const char *name_tmp;
+ const char *rd_ser;
+ unsigned int rd_count;
+
+ rid = ntohl (rp_msg->gns_header.r_id);
+ name_len = ntohs (rp_msg->name_len);
+ rd_count = ntohs (rp_msg->rd_count);
+ rd_ser_len = ntohs (rp_msg->rd_len);
+ name_tmp = (const char *) &rp_msg[1];
+ rd_ser = &name_tmp[name_len];
+ {
+ struct GNUNET_GNSRECORD_Data rd[rd_count];
+
+ /* We did this before, must succeed again */
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
+ rd_ser,
+ rd_count,
+ rd));
+ refresh_block (sa->nc,
+ rid,
+ &rp_msg->private_key,
+ sa->conv_name,
+ rd_count,
+ rd);
+ }
+ }
+ GNUNET_SERVICE_client_continue (sa->nc->client);
+ free_store_activity (sa);
+}
+
+
+/**
+ * Called whenever a client is disconnected.
+ * Frees our resources associated with that client.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param app_ctx the `struct NamestoreClient` of @a client
+ */
+static void
+client_disconnect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *client,
+ void *app_ctx)
+{
+ struct NamestoreClient *nc = app_ctx;
+ struct ZoneIteration *no;
+ struct CacheOperation *cop;
+
+ (void) cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p disconnected\n",
+ client);
+ for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next)
+ {
+ if (nc != zm->nc)
+ continue;
+ GNUNET_CONTAINER_DLL_remove (monitor_head,
+ monitor_tail,
+ zm);
+ if (NULL != zm->task)
+ {
+ GNUNET_SCHEDULER_cancel (zm->task);
+ zm->task = NULL;
+ }
+ for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
+ {
+ if (zm == sa->zm_pos)
+ {
+ sa->zm_pos = zm->next;
+ continue_store_activity (sa);
+ }
+ }
+ GNUNET_free (zm);
+ break;
+ }
+ for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
+ {
+ if (sa->nc == nc)
+ {
+ free_store_activity (sa);
+ break; /* there can only be one per nc */
+ }
+ }
+ while (NULL != (no = nc->op_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (nc->op_head,
+ nc->op_tail,
+ no);
+ GNUNET_free (no);
+ }
+ for (cop = cop_head; NULL != cop; cop = cop->next)
+ if (nc == cop->nc)
+ cop->nc = NULL;
+ GNUNET_free (nc);
+}
+
+
+/**
+ * Add a client to our list of active clients.
+ *
+ * @param cls NULL
+ * @param client client to add
+ * @param mq message queue for @a client
+ * @return internal namestore client structure for this client
+ */
+static void *
+client_connect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *client,
+ struct GNUNET_MQ_Handle *mq)
+{
+ struct NamestoreClient *nc;
+
+ (void) cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p connected\n",
+ client);
+ nc = GNUNET_new (struct NamestoreClient);
+ nc->client = client;
+ nc->mq = mq;
+ return nc;
+}
+
+
+/**
* Closure for #lookup_it().
*/
struct RecordLookupContext
@@ -1073,7 +1266,7 @@ handle_record_store (void *cls,
const char *rd_ser;
unsigned int rd_count;
int res;
- struct ZoneMonitor *zm;
+ struct StoreActivity *sa;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received NAMESTORE_RECORD_STORE message\n");
@@ -1085,7 +1278,9 @@ handle_record_store (void *cls,
name_tmp = (const char *) &rp_msg[1];
rd_ser = &name_tmp[name_len];
{
- struct GNUNET_GNSRECORD_Data rd[rd_count];
+ struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
+ struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
+ unsigned int rd_clean_off;
if (GNUNET_OK !=
GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
@@ -1128,9 +1323,6 @@ handle_record_store (void *cls,
}
else
{
- struct GNUNET_GNSRECORD_Data rd_clean[rd_count];
- unsigned int rd_clean_off;
-
/* remove "NICK" records, unless this is for the
#GNUNET_GNS_EMPTY_LABEL_AT label */
rd_clean_off = 0;
@@ -1147,59 +1339,39 @@ handle_record_store (void *cls,
conv_name,
rd_clean_off,
rd_clean);
- if (GNUNET_OK == res)
- {
- for (zm = monitor_head; NULL != zm; zm = zm->next)
- {
- if ( (0 == memcmp (&rp_msg->private_key,
- &zm->zone,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ||
- (0 == memcmp (&zm->zone,
- &zero,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Notifying monitor about changes under label `%s'\n",
- conv_name);
- send_lookup_response (zm->nc,
- 0,
- &rp_msg->private_key,
- conv_name,
- rd_count, rd);
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Monitor is for another zone\n");
- }
- if (NULL == monitor_head)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No monitors active\n");
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error storing record: %d\n",
- res);
- }
}
- if (GNUNET_OK == res)
+
+ if (GNUNET_OK != res)
{
- refresh_block (nc,
- rid,
- &rp_msg->private_key,
- conv_name,
- rd_count,
- rd);
+ /* store not successful, not need to tell monitors */
+ send_store_response (nc,
+ res,
+ rid);
GNUNET_SERVICE_client_continue (nc->client);
GNUNET_free (conv_name);
return;
}
- GNUNET_free (conv_name);
+
+ sa = GNUNET_malloc (sizeof (struct StoreActivity) +
+ ntohs (rp_msg->gns_header.header.size));
+ GNUNET_CONTAINER_DLL_insert (sa_head,
+ sa_tail,
+ sa);
+ sa->nc = nc;
+ sa->rsm = (const struct RecordStoreMessage *) &sa[1];
+ memcpy (&sa[1],
+ rp_msg,
+ ntohs (rp_msg->gns_header.header.size));
+ sa->zm_pos = monitor_head;
+ sa->conv_name = conv_name;
+ GNUNET_array_grow (sa->rd,
+ sa->rd_count,
+ rd_clean_off);
+ memcpy (sa->rd,
+ rd_clean,
+ sizeof (struct GNUNET_GNSRECORD_Data) * rd_clean_off);
+ continue_store_activity (sa);
}
- send_store_response (nc,
- res,
- rid);
- GNUNET_SERVICE_client_continue (nc->client);
}
@@ -1311,8 +1483,7 @@ handle_zone_to_name (void *cls,
struct ZoneToNameResponseMessage *ztnr_msg;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message\n",
- "ZONE_TO_NAME");
+ "Received ZONE_TO_NAME message\n");
ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
ztn_ctx.nc = nc;
ztn_ctx.success = GNUNET_NO;
@@ -1601,6 +1772,30 @@ handle_iteration_next (void *cls,
/**
+ * Function called when the monitor is ready for more data, and we
+ * should thus unblock PUT operations that were blocked on the
+ * monitor not being ready.
+ */
+static void
+monitor_unblock (struct ZoneMonitor *zm)
+{
+ struct StoreActivity *sa = sa_head;
+
+ while ( (NULL != sa) &&
+ (zm->limit > zm->iteration_cnt) )
+ {
+ struct StoreActivity *sn = sa->next;
+
+ if (sa->zm_pos == zm)
+ continue_store_activity (sa);
+ sa = sn;
+ }
+ if (zm->limit > zm->iteration_cnt)
+ zm->sa_waiting = GNUNET_NO;
+}
+
+
+/**
* Send 'sync' message to zone monitor, we're now in sync.
*
* @param zm monitor that is now in sync
@@ -1615,16 +1810,22 @@ monitor_sync (struct ZoneMonitor *zm)
GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC);
GNUNET_MQ_send (zm->nc->mq,
env);
+ /* mark iteration done */
+ zm->in_first_iteration = GNUNET_NO;
+ zm->iteration_cnt = 0;
+ if ( (zm->limit > 0) &&
+ (zm->sa_waiting) )
+ monitor_unblock (zm);
}
/**
- * Obtain the next datum during the zone monitor's zone intiial iteration.
+ * Obtain the next datum during the zone monitor's zone initial iteration.
*
* @param cls zone monitor that does its initial iteration
*/
static void
-monitor_next (void *cls);
+monitor_iteration_next (void *cls);
/**
@@ -1658,14 +1859,23 @@ monitor_iterate_cb (void *cls,
"Monitor notifications sent",
1,
GNUNET_NO);
+ zm->limit--;
+ zm->iteration_cnt--;
send_lookup_response (zm->nc,
0,
zone_key,
name,
rd_count,
rd);
- zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
- zm);
+ if ( (0 == zm->iteration_cnt) &&
+ (0 != zm->limit) )
+ {
+ /* We are done with the current iteration batch, AND the
+ client would right now accept more, so go again! */
+ GNUNET_assert (NULL == zm->task);
+ zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
+ zm);
+ }
}
@@ -1687,6 +1897,8 @@ handle_monitor_start (void *cls,
zm = GNUNET_new (struct ZoneMonitor);
zm->nc = nc;
zm->zone = zis_msg->zone;
+ zm->limit = 1;
+ zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first));
GNUNET_CONTAINER_DLL_insert (monitor_head,
monitor_tail,
zm);
@@ -1694,8 +1906,8 @@ handle_monitor_start (void *cls,
GNUNET_SERVICE_client_continue (nc->client);
GNUNET_notification_context_add (monitor_nc,
nc->mq);
- if (GNUNET_YES == ntohl (zis_msg->iterate_first))
- zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
+ if (zm->in_first_iteration)
+ zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
zm);
else
monitor_sync (zm);
@@ -1708,12 +1920,17 @@ handle_monitor_start (void *cls,
* @param cls zone monitor that does its initial iteration
*/
static void
-monitor_next (void *cls)
+monitor_iteration_next (void *cls)
{
struct ZoneMonitor *zm = cls;
int ret;
zm->task = NULL;
+ GNUNET_assert (0 == zm->iteration_cnt);
+ if (zm->limit > 16)
+ zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */
+ else
+ zm->iteration_cnt = zm->limit; /* use it all */
ret = GSN_database->iterate_records (GSN_database->cls,
(0 == memcmp (&zm->zone,
&zero,
@@ -1721,7 +1938,7 @@ monitor_next (void *cls)
? NULL
: &zm->zone,
zm->seq,
- 1,
+ zm->iteration_cnt,
&monitor_iterate_cb,
zm);
if (GNUNET_SYSERR == ret)
@@ -1773,13 +1990,19 @@ handle_monitor_next (void *cls,
return;
}
zm->limit += inc;
-#if 0
- if (GNUNET_YES == ntohl (zis_msg->iterate_first))
- zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
- zm);
- else
- monitor_sync (zm);
-#endif
+ if ( (zm->in_first_iteration) &&
+ (zm->limit == inc) )
+ {
+ /* We are still iterating, and the previous iteration must
+ have stopped due to the client's limit, so continue it! */
+ GNUNET_assert (NULL == zm->task);
+ zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
+ zm);
+ }
+ GNUNET_assert (zm->iteration_cnt <= zm->limit);
+ if ( (zm->limit > zm->iteration_cnt) &&
+ (zm->sa_waiting) )
+ monitor_unblock (zm);
}
diff --git a/src/namestore/plugin_namestore_flat.c
b/src/namestore/plugin_namestore_flat.c
index bbb9e3c62..df9f424a6 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -364,10 +364,10 @@ store_and_free_entries (void *cls,
&record_data_b64);
}
GNUNET_asprintf (&line,
- "%s,%lu,%u,%s,%s\n",
+ "%s,%llu,%u,%s,%s\n",
zone_private_key,
- entry->rvalue,
- entry->record_count,
+ (unsigned long long) entry->rvalue,
+ (unsigned int) entry->record_count,
record_data_b64,
entry->label);
GNUNET_free (record_data_b64);
diff --git a/src/namestore/plugin_namestore_sqlite.c
b/src/namestore/plugin_namestore_sqlite.c
index f62be1e18..34e548613 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -106,72 +106,6 @@ struct Plugin
/**
- * @brief Prepare a SQL statement
- *
- * @param dbh handle to the database
- * @param zSql SQL statement, UTF-8 encoded
- * @param ppStmt set to the prepared statement
- * @return 0 on success
- */
-static int
-sq_prepare (sqlite3 *dbh,
- const char *zSql,
- sqlite3_stmt **ppStmt)
-{
- char *dummy;
- int result;
-
- result =
- sqlite3_prepare_v2 (dbh,
- zSql,
- strlen (zSql),
- ppStmt,
- (const char **) &dummy);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Prepared `%s' / %p: %d\n",
- zSql,
- *ppStmt,
- result);
- return result;
-}
-
-
-/**
- * Create our database indices.
- *
- * @param dbh handle to the database
- */
-static void
-create_indices (sqlite3 * dbh)
-{
- /* create indices */
- if ( (SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
- "ON ns098records (zone_private_key,pkey)",
- NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS ir_pkey_iter "
- "ON ns098records (zone_private_key,uid)",
- NULL, NULL, NULL)) )
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Failed to create indices: %s\n",
- sqlite3_errmsg (dbh));
-}
-
-
-#if 0
-#define CHECK(a) GNUNET_break(a)
-#define ENULL NULL
-#else
-#define ENULL &e
-#define ENULL_DEFINED 1
-#define CHECK(a) if (! (a)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e);
sqlite3_free(e); }
-#endif
-
-
-/**
* Initialize the database connections and associated
* data structures (create tables and indices
* as needed as well).
@@ -182,17 +116,66 @@ create_indices (sqlite3 * dbh)
static int
database_setup (struct Plugin *plugin)
{
- sqlite3_stmt *stmt;
- char *afsdir;
-#if ENULL_DEFINED
- char *e;
-#endif
+ char *sqlite_filename;
+ struct GNUNET_SQ_ExecuteStatement es[] = {
+ GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
+ GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
+ GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
+ GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
+ GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
+ GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=EXCLUSIVE"),
+ GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
+ GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records ("
+ " uid INTEGER PRIMARY KEY,"
+ " zone_private_key BLOB NOT NULL,"
+ " pkey BLOB,"
+ " rvalue INT8 NOT NULL,"
+ " record_count INT NOT NULL,"
+ " record_data BLOB NOT NULL,"
+ " label TEXT NOT NULL"
+ ")"),
+ GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
+ "ON ns098records (zone_private_key,pkey)"),
+ GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter "
+ "ON ns098records (zone_private_key,uid)"),
+ GNUNET_SQ_EXECUTE_STATEMENT_END
+ };
+ struct GNUNET_SQ_PrepareStatement ps[] = {
+ GNUNET_SQ_make_prepare ("INSERT INTO ns098records "
+
"(zone_private_key,pkey,rvalue,record_count,record_data,label)"
+ " VALUES (?, ?, ?, ?, ?, ?)",
+ &plugin->store_records),
+ GNUNET_SQ_make_prepare ("DELETE FROM ns098records "
+ "WHERE zone_private_key=? AND label=?",
+ &plugin->delete_records),
+ GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
+ " FROM ns098records"
+ " WHERE zone_private_key=? AND pkey=?",
+ &plugin->zone_to_name),
+ GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
+ " FROM ns098records"
+ " WHERE zone_private_key=? AND _rowid_ >= ?"
+ " ORDER BY _rowid_ ASC"
+ " LIMIT ?",
+ &plugin->iterate_zone),
+ GNUNET_SQ_make_prepare ("SELECT
uid,record_count,record_data,label,zone_private_key"
+ " FROM ns098records"
+ " WHERE _rowid_ >= ?"
+ " ORDER BY _rowid_ ASC"
+ " LIMIT ?",
+ &plugin->iterate_all_zones),
+ GNUNET_SQ_make_prepare ("SELECT
uid,record_count,record_data,label,zone_private_key"
+ " FROM ns098records"
+ " WHERE zone_private_key=? AND label=?",
+ &plugin->lookup_label),
+ GNUNET_SQ_PREPARE_END
+ };
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (plugin->cfg,
"namestore-sqlite",
"FILENAME",
- &afsdir))
+ &sqlite_filename))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"namestore-sqlite",
@@ -200,132 +183,51 @@ database_setup (struct Plugin *plugin)
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
- GNUNET_DISK_file_test (afsdir))
+ GNUNET_DISK_file_test (sqlite_filename))
{
if (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (afsdir))
+ GNUNET_DISK_directory_create_for_file (sqlite_filename))
{
GNUNET_break (0);
- GNUNET_free (afsdir);
+ GNUNET_free (sqlite_filename);
return GNUNET_SYSERR;
}
}
- /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
- plugin->fn = afsdir;
+ /* sqlite_filename should be UTF-8-encoded. If it isn't, it's a bug */
+ plugin->fn = sqlite_filename;
/* Open database and precompile statements */
- if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK)
+ if (SQLITE_OK !=
+ sqlite3_open (plugin->fn,
+ &plugin->dbh))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_("Unable to initialize SQLite: %s.\n"),
sqlite3_errmsg (plugin->dbh));
return GNUNET_SYSERR;
}
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA temp_store=MEMORY", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA synchronous=NORMAL", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA legacy_file_format=OFF", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA auto_vacuum=INCREMENTAL", NULL,
- NULL, ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA encoding=\"UTF-8\"", NULL,
- NULL, ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA page_size=4092", NULL, NULL,
- ENULL));
-
- CHECK (SQLITE_OK ==
- sqlite3_busy_timeout (plugin->dbh,
- BUSY_TIMEOUT_MS));
-
-
- /* Create table */
- CHECK (SQLITE_OK ==
- sq_prepare (plugin->dbh,
- "SELECT 1 FROM sqlite_master WHERE tbl_name =
'ns098records'",
- &stmt));
- if ( (sqlite3_step (stmt) == SQLITE_DONE) &&
- (SQLITE_OK !=
- sqlite3_exec (plugin->dbh,
- "CREATE TABLE ns098records ("
- " uid INTEGER PRIMARY KEY,"
- " zone_private_key BLOB NOT NULL,"
- " pkey BLOB,"
- " rvalue INT8 NOT NULL,"
- " record_count INT NOT NULL,"
- " record_data BLOB NOT NULL,"
- " label TEXT NOT NULL"
- ")",
- NULL, NULL, NULL)) )
+ GNUNET_break (SQLITE_OK ==
+ sqlite3_busy_timeout (plugin->dbh,
+ BUSY_TIMEOUT_MS));
+ if (GNUNET_OK !=
+ GNUNET_SQ_exec_statements (plugin->dbh,
+ es))
{
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_exec");
- sqlite3_finalize (stmt);
+ GNUNET_break (0);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to setup database at `%s'\n"),
+ plugin->fn);
return GNUNET_SYSERR;
}
- sqlite3_finalize (stmt);
-
- create_indices (plugin->dbh);
-
- if ( (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "INSERT INTO ns098records (zone_private_key, pkey, rvalue,
record_count, record_data, label)"
- " VALUES (?, ?, ?, ?, ?, ?)",
- &plugin->store_records)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "DELETE FROM ns098records WHERE zone_private_key=? AND
label=?",
- &plugin->delete_records)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT uid,record_count,record_data,label"
- " FROM ns098records"
- " WHERE zone_private_key=? AND pkey=?",
- &plugin->zone_to_name)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT uid,record_count,record_data,label"
- " FROM ns098records"
- " WHERE zone_private_key=? AND _rowid_ >= ?"
- " ORDER BY _rowid_ ASC"
- " LIMIT ?",
- &plugin->iterate_zone)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT
uid,record_count,record_data,label,zone_private_key"
- " FROM ns098records"
- " WHERE _rowid_ >= ?"
- " ORDER BY _rowid_ ASC"
- " LIMIT ?",
- &plugin->iterate_all_zones)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT
uid,record_count,record_data,label,zone_private_key"
- " FROM ns098records"
- " WHERE zone_private_key=? AND label=?",
- &plugin->lookup_label))
- )
+
+ if (GNUNET_OK !=
+ GNUNET_SQ_prepare (plugin->dbh,
+ ps))
{
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "precompiling");
+ GNUNET_break (0);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to setup database at `%s'\n"),
+ plugin->fn);
return GNUNET_SYSERR;
}
return GNUNET_OK;
diff --git a/src/namestore/test_namestore_api_lookup_nick.c
b/src/namestore/test_namestore_api_lookup_nick.c
index 50d1fd9a9..b9ae93bf2 100644
--- a/src/namestore/test_namestore_api_lookup_nick.c
+++ b/src/namestore/test_namestore_api_lookup_nick.c
@@ -52,7 +52,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
//static const char * name = "dummy.dummy.gnunet";
static const char * name = "d";
-static char *directory;
static void
cleanup ()
@@ -283,29 +282,22 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
"GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n",
hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, TEST_NICK, &nick_cont, (void
*) name);
+ nsqe = GNUNET_NAMESTORE_set_nick (nsh,
+ privkey,
+ TEST_NICK,
+ &nick_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -324,6 +316,8 @@ main (int argc, char *argv[])
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick",
@@ -333,12 +327,9 @@ main (int argc, char *argv[])
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
diff --git a/src/namestore/test_namestore_api_lookup_private.c
b/src/namestore/test_namestore_api_lookup_private.c
index 7866749f1..689e73a2e 100644
--- a/src/namestore/test_namestore_api_lookup_private.c
+++ b/src/namestore/test_namestore_api_lookup_private.c
@@ -48,7 +48,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
//static const char * name = "dummy.dummy.gnunet";
static const char * name = "d";
-static char *directory;
static void
cleanup ()
@@ -71,11 +70,11 @@ cleanup ()
* Re-establish the connection to the service.
*
* @param cls handle to use to re-connect.
- * @param tc scheduler context
*/
static void
endbadly (void *cls)
{
+ endbadly_task = NULL;
if (NULL != nsqe)
{
GNUNET_NAMESTORE_cancel (nsqe);
@@ -109,7 +108,7 @@ lookup_it (void *cls,
{
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;
}
@@ -118,7 +117,7 @@ lookup_it (void *cls,
{
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;
}
@@ -126,7 +125,7 @@ lookup_it (void *cls,
{
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;
}
@@ -134,14 +133,14 @@ lookup_it (void *cls,
{
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;
}
/* Done */
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
- GNUNET_SCHEDULER_add_now (&end, NULL );
+ GNUNET_SCHEDULER_add_now (&end, NULL);
}
@@ -153,7 +152,9 @@ fail_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)
{
const char *name = cls;
@@ -187,22 +188,11 @@ run (void *cls,
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
"GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n",
hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
@@ -215,8 +205,13 @@ run (void *cls,
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -237,6 +232,8 @@ main (int argc, char *argv[])
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private",
@@ -246,12 +243,9 @@ main (int argc, char *argv[])
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
diff --git a/src/namestore/test_namestore_api_lookup_public.c
b/src/namestore/test_namestore_api_lookup_public.c
index 02ca16042..28a68daf9 100644
--- a/src/namestore/test_namestore_api_lookup_public.c
+++ b/src/namestore/test_namestore_api_lookup_public.c
@@ -51,7 +51,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
-static char *directory;
static void
cleanup ()
@@ -190,26 +189,15 @@ run (void *cls,
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
"GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n",
hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
-
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
rd.record_type = TEST_RECORD_TYPE;
@@ -244,6 +232,8 @@ main (int argc, char *argv[])
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api",
@@ -253,12 +243,9 @@ main (int argc, char *argv[])
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c
b/src/namestore/test_namestore_api_lookup_shadow.c
index e80335796..39ce4e564 100644
--- a/src/namestore/test_namestore_api_lookup_shadow.c
+++ b/src/namestore/test_namestore_api_lookup_shadow.c
@@ -53,7 +53,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
-static char *directory;
static void
cleanup ()
@@ -222,26 +221,15 @@ run (void *cls,
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
"GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n",
hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
-
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
rd.record_type = TEST_RECORD_TYPE;
rd.data_size = TEST_RECORD_DATALEN;
@@ -253,8 +241,13 @@ run (void *cls,
nch = GNUNET_NAMECACHE_connect (cfg);
GNUNET_break (NULL != nsh);
GNUNET_break (NULL != nch);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -274,6 +267,8 @@ main (int argc, char *argv[])
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow",
@@ -284,11 +279,8 @@ main (int argc, char *argv[])
res = 1;
}
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
return res;
}
diff --git a/src/namestore/test_namestore_api_lookup_shadow_filter.c
b/src/namestore/test_namestore_api_lookup_shadow_filter.c
index 5b8811a23..09fd8ce07 100644
--- a/src/namestore/test_namestore_api_lookup_shadow_filter.c
+++ b/src/namestore/test_namestore_api_lookup_shadow_filter.c
@@ -66,7 +66,6 @@ static struct GNUNET_HashCode derived_hash;
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
-static char *directory;
static void
cleanup ()
@@ -291,26 +290,16 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
"GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n",
hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
- record_expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
EXPIRATION);
+ record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
+ EXPIRATION);
records[0].expiration_time = record_expiration.abs_value_us;
records[0].record_type = TEST_RECORD_TYPE;
records[0].data_size = TEST_RECORD_DATALEN;
@@ -352,6 +341,8 @@ main (int argc, char *argv[])
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter",
@@ -362,11 +353,8 @@ main (int argc, char *argv[])
res = 1;
}
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
return res;
}
diff --git a/src/namestore/test_namestore_api_monitoring.c
b/src/namestore/test_namestore_api_monitoring.c
index cd38b2c80..de202d535 100644
--- a/src/namestore/test_namestore_api_monitoring.c
+++ b/src/namestore/test_namestore_api_monitoring.c
@@ -56,7 +56,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
-static char *directory;
static void
do_shutdown ()
@@ -66,7 +65,6 @@ do_shutdown ()
GNUNET_NAMESTORE_zone_monitor_stop (zm);
zm = NULL;
}
-
if (NULL != ns_ops[0])
{
GNUNET_NAMESTORE_cancel(ns_ops[0]);
@@ -82,13 +80,11 @@ do_shutdown ()
GNUNET_NAMESTORE_cancel(ns_ops[2]);
ns_ops[2] = NULL;
}
-
if (NULL != nsh)
{
GNUNET_NAMESTORE_disconnect (nsh);
nsh = NULL;
}
-
GNUNET_free_non_null(s_name_1);
GNUNET_free_non_null(s_name_2);
GNUNET_free_non_null(s_name_3);
@@ -284,23 +280,8 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
-
res = 1;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
"GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
- GNUNET_asprintf(&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
/* Start monitoring */
@@ -333,16 +314,12 @@ run (void *cls,
return;
}
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n",
hostkey_file);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey2 != NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created record 3\n");
/* name in different zone */
GNUNET_asprintf(&s_name_3, "dummy3");
s_rd_3 = create_record(1);
@@ -358,22 +335,33 @@ run (void *cls,
"Created record 1\n");
GNUNET_asprintf(&s_name_1, "dummy1");
s_rd_1 = create_record(1);
- 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_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)));
}
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
const char *plugin_name;
char *cfg_name;
@@ -382,6 +370,8 @@ main (int argc, char *argv[])
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-monitoring",
@@ -391,12 +381,9 @@ main (int argc, char *argv[])
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c
b/src/namestore/test_namestore_api_monitoring_existing.c
index f6a74609e..25c098fe3 100644
--- a/src/namestore/test_namestore_api_monitoring_existing.c
+++ b/src/namestore/test_namestore_api_monitoring_existing.c
@@ -57,8 +57,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
-static char *directory;
-
static void
do_shutdown ()
@@ -316,30 +314,14 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *mycfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (mycfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
res = 1;
-
- GNUNET_asprintf(&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
cfg = mycfg;
- endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &endbadly,
+ NULL);
/* Connect to namestore */
nsh = GNUNET_NAMESTORE_connect (cfg);
if (NULL == nsh)
@@ -350,12 +332,7 @@ run (void *cls,
return;
}
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n",
hostkey_file);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey2 != NULL);
@@ -397,6 +374,8 @@ main (int argc, char *argv[])
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing",
cfg_name,
@@ -405,12 +384,9 @@ main (int argc, char *argv[])
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
diff --git a/src/namestore/test_namestore_api_remove.c
b/src/namestore/test_namestore_api_remove.c
index 532a751da..c9e2802bd 100644
--- a/src/namestore/test_namestore_api_remove.c
+++ b/src/namestore/test_namestore_api_remove.c
@@ -48,7 +48,6 @@ static int removed;
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
-static char *directory;
static void
cleanup ()
@@ -157,29 +156,12 @@ run (void *cls,
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n",
- hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
&pubkey);
@@ -191,12 +173,19 @@ run (void *cls,
rd.data_size = TEST_RECORD_DATALEN;
rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
rd.flags = 0;
- memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN);
+ memset ((char *) rd.data,
+ 'a',
+ TEST_RECORD_DATALEN);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -216,6 +205,8 @@ main (int argc, char *argv[])
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-remove",
@@ -225,12 +216,9 @@ main (int argc, char *argv[])
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c
b/src/namestore/test_namestore_api_remove_not_existing_record.c
index 2f20c3636..d0438a7e1 100644
--- a/src/namestore/test_namestore_api_remove_not_existing_record.c
+++ b/src/namestore/test_namestore_api_remove_not_existing_record.c
@@ -46,7 +46,6 @@ static int res;
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
-static char *directory;
static void
cleanup ()
@@ -92,7 +91,9 @@ end (void *cls)
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
GNUNET_assert (NULL != cls);
nsqe = NULL;
@@ -101,8 +102,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
}
-
- switch (success) {
+ switch (success)
+ {
case GNUNET_NO:
/* We expected GNUNET_NO, since record was not found */
GNUNET_SCHEDULER_add_now (&end, NULL);
@@ -129,25 +130,12 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
"GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n",
- hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
@@ -174,6 +162,8 @@ main (int argc, char *argv[])
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record",
@@ -183,12 +173,9 @@ main (int argc, char *argv[])
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
diff --git a/src/namestore/test_namestore_api_store.c
b/src/namestore/test_namestore_api_store.c
index 4e51678a1..4abcfa4d3 100644
--- a/src/namestore/test_namestore_api_store.c
+++ b/src/namestore/test_namestore_api_store.c
@@ -46,7 +46,6 @@ static int res;
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
-static char *directory;
static void
cleanup ()
@@ -114,23 +113,11 @@ run (void *cls,
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
"GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n",
hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
@@ -144,8 +131,13 @@ run (void *cls,
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -167,6 +159,8 @@ main (int argc, char *argv[])
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api",
cfg_name,
@@ -175,12 +169,9 @@ main (int argc, char *argv[])
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
diff --git a/src/namestore/test_namestore_api_store_update.c
b/src/namestore/test_namestore_api_store_update.c
index 0a4551f21..7b13cd9c5 100644
--- a/src/namestore/test_namestore_api_store_update.c
+++ b/src/namestore/test_namestore_api_store_update.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2012, 2013 GNUnet e.V.
+ Copyright (C) 2012, 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
@@ -21,6 +21,7 @@
* @file namestore/test_namestore_api_store_update.c
* @brief testcase for namestore_api.c: store a record, update it and perform
a lookup
* @author Matthias Wachs
+ * @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_namecache_service.h"
@@ -33,7 +34,6 @@
#define TEST_RECORD_DATA 'a'
-
#define TEST_RECORD_TYPE2 4321
#define TEST_RECORD_DATALEN2 234
@@ -63,38 +63,30 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
static const char *name = "dummy";
-static char *directory;
+/**
+ * Terminate test with error.
+ *
+ * @param cls handle to use to re-connect.
+ */
static void
-cleanup ()
+endbadly (void *cls)
{
- if (NULL != nsh)
- {
- GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
- }
- if (NULL != nch)
- {
- GNUNET_NAMECACHE_disconnect (nch);
- nch = NULL;
- }
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
+ GNUNET_break (0);
+ endbadly_task = NULL;
GNUNET_SCHEDULER_shutdown ();
+ res = 1;
}
-/**
- * Re-establish the connection to the service.
- *
- * @param cls handle to use to re-connect.
- */
static void
-endbadly (void *cls)
+end (void *cls)
{
+ if (NULL != endbadly_task)
+ {
+ GNUNET_SCHEDULER_cancel (endbadly_task);
+ endbadly_task = NULL;
+ }
if (NULL != nsqe)
{
GNUNET_NAMESTORE_cancel (nsqe);
@@ -105,21 +97,28 @@ endbadly (void *cls)
GNUNET_NAMECACHE_cancel (ncqe);
ncqe = NULL;
}
- cleanup ();
- res = 1;
-}
-
-
-static void
-end (void *cls)
-{
- cleanup ();
- res = 0;
+ if (NULL != nsh)
+ {
+ GNUNET_NAMESTORE_disconnect (nsh);
+ nsh = NULL;
+ }
+ if (NULL != nch)
+ {
+ GNUNET_NAMECACHE_disconnect (nch);
+ nch = NULL;
+ }
+ if (NULL != privkey)
+ {
+ GNUNET_free (privkey);
+ privkey = NULL;
+ }
}
static void
-put_cont (void *cls, int32_t success, const char *emsg);
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg);
static void
@@ -135,11 +134,15 @@ rd_decrypt_cb (void *cls,
if (GNUNET_NO == update_performed)
{
char rd_cmp_data[TEST_RECORD_DATALEN];
- memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
+ memset (rd_cmp_data,
+ TEST_RECORD_DATA,
+ TEST_RECORD_DATALEN);
GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type);
GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size);
- GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data,
TEST_RECORD_DATALEN));
+ GNUNET_assert (0 == memcmp (&rd_cmp_data,
+ rd[0].data,
+ TEST_RECORD_DATALEN));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Block was decrypted successfully, updating record \n");
@@ -149,24 +152,33 @@ rd_decrypt_cb (void *cls,
rd_new.record_type = TEST_RECORD_TYPE2;
rd_new.data_size = TEST_RECORD_DATALEN2;
rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2);
- memset ((char *) rd_new.data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2);
+ memset ((char *) rd_new.data,
+ TEST_RECORD_DATA2,
+ TEST_RECORD_DATALEN2);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd_new, &put_cont, (void *)
name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd_new,
+ &put_cont,
+ (void *) name);
update_performed = GNUNET_YES;
}
else
{
char rd_cmp_data[TEST_RECORD_DATALEN2];
- memset (rd_cmp_data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2);
+ memset (rd_cmp_data,
+ TEST_RECORD_DATA2,
+ TEST_RECORD_DATALEN2);
GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type);
GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size);
- GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data,
TEST_RECORD_DATALEN2));
-
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = NULL;
- GNUNET_SCHEDULER_add_now (&end, NULL);
+ GNUNET_assert (0 == memcmp (&rd_cmp_data,
+ rd[0].data,
+ TEST_RECORD_DATALEN2));
+ GNUNET_SCHEDULER_shutdown ();
+ res = 0;
}
}
@@ -184,21 +196,25 @@ name_lookup_proc (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Namecache returned no block for `%s'\n"),
name);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Namecache returned block, decrypting \n");
- GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block,
- &pubkey, name, &rd_decrypt_cb, (void *) name));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_GNSRECORD_block_decrypt (block,
+ &pubkey,
+ name,
+ &rd_decrypt_cb,
+ (void *) name));
}
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
const char *name = cls;
struct GNUNET_HashCode derived_hash;
@@ -216,7 +232,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Looking in namecache for `%s'\n",
GNUNET_h2s (&derived_hash));
- ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash,
+ ncqe = GNUNET_NAMECACHE_lookup_block (nch,
+ &derived_hash,
&name_lookup_proc, (void *) name);
}
@@ -227,41 +244,37 @@ run (void *cls,
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
"GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
update_performed = GNUNET_NO;
+ GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n",
hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
-
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
rd.flags = GNUNET_GNSRECORD_RF_NONE;
rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
rd.record_type = TEST_RECORD_TYPE;
rd.data_size = TEST_RECORD_DATALEN;
rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
- memset ((char *) rd.data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
+ memset ((char *) rd.data,
+ TEST_RECORD_DATA,
+ TEST_RECORD_DATALEN);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
nch = GNUNET_NAMECACHE_connect (cfg);
GNUNET_break (NULL != nch);
nsqe = GNUNET_NAMESTORE_records_store (nsh,
- privkey, name,
- 1, &rd,
- &put_cont, (void *) name);
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -272,7 +285,8 @@ run (void *cls,
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
const char *plugin_name;
char *cfg_name;
@@ -282,6 +296,8 @@ main (int argc, char *argv[])
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-store-update",
cfg_name,
@@ -290,14 +306,11 @@ main (int argc, char *argv[])
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
-/* end of test_namestore_api_store_update.c*/
+/* end of test_namestore_api_store_update.c */
diff --git a/src/namestore/test_namestore_api_zone_iteration.c
b/src/namestore/test_namestore_api_zone_iteration.c
index 806605d94..68c3de9b8 100644
--- a/src/namestore/test_namestore_api_zone_iteration.c
+++ b/src/namestore/test_namestore_api_zone_iteration.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
@@ -56,8 +56,6 @@ static char * s_name_3;
static struct GNUNET_GNSRECORD_Data *s_rd_3;
-static char *directory;
-
/**
* Re-establish the connection to the service.
@@ -68,43 +66,8 @@ static char *directory;
static void
endbadly (void *cls)
{
- if (NULL != zi)
- {
- GNUNET_NAMESTORE_zone_iteration_stop (zi);
- zi = NULL;
- }
- if (nsh != NULL)
- {
- GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
- }
- GNUNET_free_non_null(s_name_1);
- GNUNET_free_non_null(s_name_2);
- GNUNET_free_non_null(s_name_3);
-
- 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 (s_rd_3 != NULL)
- {
- GNUNET_free ((void *)s_rd_3->data);
- GNUNET_free (s_rd_3);
- }
-
- if (privkey != NULL)
- GNUNET_free (privkey);
- privkey = NULL;
-
- if (privkey2 != NULL)
- GNUNET_free (privkey2);
- privkey2 = NULL;
+ endbadly_task = NULL;
+ GNUNET_SCHEDULER_shutdown ();
res = 1;
}
@@ -117,41 +80,44 @@ end (void *cls)
GNUNET_NAMESTORE_zone_iteration_stop (zi);
zi = NULL;
}
- if (endbadly_task != NULL)
+ if (NULL != endbadly_task)
{
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
}
-
- if (privkey != NULL)
+ if (NULL != privkey)
+ {
GNUNET_free (privkey);
- privkey = NULL;
-
- if (privkey2 != NULL)
+ privkey = NULL;
+ }
+ if (NULL != privkey2)
+ {
GNUNET_free (privkey2);
- privkey2 = NULL;
-
+ privkey2 = NULL;
+ }
GNUNET_free (s_name_1);
GNUNET_free (s_name_2);
GNUNET_free (s_name_3);
- if (s_rd_1 != NULL)
+ if (NULL != s_rd_1)
{
GNUNET_free ((void *)s_rd_1->data);
GNUNET_free (s_rd_1);
}
- if (s_rd_2 != NULL)
+ if (NULL != s_rd_2)
{
GNUNET_free ((void *)s_rd_2->data);
GNUNET_free (s_rd_2);
}
- if (s_rd_3 != NULL)
+ if (NULL != s_rd_3)
{
GNUNET_free ((void *)s_rd_3->data);
GNUNET_free (s_rd_3);
}
- if (nsh != NULL)
+ if (NULL != nsh)
+ {
GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
+ nsh = NULL;
+ }
}
@@ -170,7 +136,7 @@ zone_end (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received last result, iteration done after receing %u
results\n",
returned_records);
- GNUNET_SCHEDULER_add_now (&end, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -191,7 +157,9 @@ zone_proc (void *cls,
int failed = GNUNET_NO;
GNUNET_assert (NULL != zone);
- if (0 == memcmp (zone, privkey, sizeof (struct
GNUNET_CRYPTO_EcdsaPrivateKey)))
+ if (0 == memcmp (zone,
+ privkey,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
{
if (0 == strcmp (label, s_name_1))
{
@@ -230,12 +198,15 @@ zone_proc (void *cls,
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Comparing result failed: got name `%s' for first zone\n",
label);
+ "Comparing result failed: got name `%s' for first zone\n",
+ label);
failed = GNUNET_YES;
GNUNET_break (0);
}
}
- else if (0 == memcmp (zone, privkey2, sizeof (struct
GNUNET_CRYPTO_EcdsaPrivateKey)))
+ else if (0 == memcmp (zone,
+ privkey2,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
{
if (0 == strcmp (label, s_name_3))
{
@@ -258,7 +229,8 @@ zone_proc (void *cls,
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Comparing result failed: got name `%s' for first zone\n",
label);
+ "Comparing result failed: got name `%s' for first zone\n",
+ label);
failed = GNUNET_YES;
GNUNET_break (0);
}
@@ -282,29 +254,34 @@ zone_proc (void *cls,
else
{
GNUNET_break (0);
- GNUNET_SCHEDULER_add_now (&end, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
}
}
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;
if (success == GNUNET_OK)
{
c++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created record %u \n",
+ c);
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to created records: `%s'\n",
emsg);
GNUNET_break (0);
- if (NULL != endbadly_task)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
return;
}
@@ -312,7 +289,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
{
res = 1;
returned_records = 0;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting
iteration over all zones \n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All records created, starting iteration over all zones \n");
zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
NULL,
&fail_cb,
@@ -323,11 +301,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
NULL);
if (zi == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to create zone iterator\n");
GNUNET_break (0);
- if (NULL != endbadly_task)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
return;
}
}
@@ -337,11 +315,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
static struct GNUNET_GNSRECORD_Data *
create_record (unsigned int count)
{
- unsigned int c;
struct GNUNET_GNSRECORD_Data * rd;
- rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
- for (c = 0; c < count; c++)
+ rd = GNUNET_new_array (count,
+ struct GNUNET_GNSRECORD_Data);
+ for (unsigned int c = 0; c < count; c++)
{
rd[c].expiration_time = GNUNET_TIME_relative_to_absolute
(GNUNET_TIME_UNIT_HOURS).abs_value_us;
rd[c].record_type = 1111;
@@ -372,9 +350,8 @@ empty_zone_proc (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Expected empty zone but received zone private key\n"));
GNUNET_break (0);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
return;
}
if ((NULL != label) || (NULL != rd) || (0 != rd_count))
@@ -382,9 +359,8 @@ empty_zone_proc (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Expected no zone content but received data\n"));
GNUNET_break (0);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
return;
}
GNUNET_assert (0);
@@ -412,7 +388,9 @@ empty_zone_end (void *cls)
"zonefiles%s%s",
DIR_SEPARATOR_STR,
"HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n",
hostkey_file);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Using zonekey file `%s' \n",
+ hostkey_file);
privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
GNUNET_free (hostkey_file);
GNUNET_assert (privkey2 != NULL);
@@ -425,8 +403,8 @@ empty_zone_end (void *cls)
privkey,
s_name_1,
1, s_rd_1,
- &put_cont, NULL);
-
+ &put_cont,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 2 \n");
GNUNET_asprintf(&s_name_2, "dummy2");
@@ -437,16 +415,18 @@ empty_zone_end (void *cls)
1, s_rd_2,
&put_cont,
NULL);
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 3\n");
-
/* name in different zone */
GNUNET_asprintf(&s_name_3, "dummy3");
s_rd_3 = create_record(1);
- GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3,
- 1, s_rd_3,
- &put_cont, NULL);
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey2,
+ s_name_3,
+ 1,
+ s_rd_3,
+ &put_cont,
+ NULL);
}
@@ -455,31 +435,30 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
- endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &endbadly,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
+
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
/* first, iterate over empty namestore */
- zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
- NULL,
- &fail_cb,
- NULL,
- &empty_zone_proc,
- nsh,
- &empty_zone_end,
- NULL);
+ zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
+ NULL,
+ &fail_cb,
+ NULL,
+ &empty_zone_proc,
+ nsh,
+ &empty_zone_end,
+ NULL);
if (NULL == zi)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to create zone iterator\n");
GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ res = 1;
+ GNUNET_SCHEDULER_shutdown ();
}
}
@@ -494,6 +473,8 @@ main (int argc, char *argv[])
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration",
@@ -503,12 +484,9 @@ main (int argc, char *argv[])
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c
b/src/namestore/test_namestore_api_zone_iteration_nick.c
index a88646864..d950b7e69 100644
--- a/src/namestore/test_namestore_api_zone_iteration_nick.c
+++ b/src/namestore/test_namestore_api_zone_iteration_nick.c
@@ -60,7 +60,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
-static char *directory;
/**
* Re-establish the connection to the service.
@@ -265,7 +264,9 @@ fail_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;
@@ -314,11 +315,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
static struct GNUNET_GNSRECORD_Data *
create_record (unsigned int count)
{
- unsigned int c;
struct GNUNET_GNSRECORD_Data * rd;
- rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
- for (c = 0; c < count; c++)
+ rd = GNUNET_new_array (count,
+ struct GNUNET_GNSRECORD_Data);
+ for (unsigned int c = 0; c < count; c++)
{
rd[c].expiration_time = GNUNET_TIME_relative_to_absolute
(GNUNET_TIME_UNIT_HOURS).abs_value_us;
rd[c].record_type = 1111;
@@ -332,7 +333,9 @@ create_record (unsigned int count)
static void
-nick_2_cont (void *cls, int32_t success, const char *emsg)
+nick_2_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Nick added : %s\n",
@@ -422,25 +425,18 @@ empty_zone_proc (void *cls,
static void
empty_zone_end (void *cls)
{
- char *hostkey_file;
GNUNET_assert (nsh == cls);
-
zi = NULL;
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n",
hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
-
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n",
hostkey_file);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey2 != NULL);
- nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, ZONE_NICK_1, &nick_1_cont,
&privkey);
+ nsqe = GNUNET_NAMESTORE_set_nick (nsh,
+ privkey,
+ ZONE_NICK_1,
+ &nick_1_cont,
+ &privkey);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -455,15 +451,9 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
- endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &endbadly,
+ NULL);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
@@ -498,6 +488,8 @@ main (int argc, char *argv[])
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick",
cfg_name,
@@ -506,12 +498,9 @@ main (int argc, char *argv[])
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
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 a4fb320e9..54cbe5472 100644
--- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
+++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -57,7 +57,6 @@ static char * s_name_3;
static struct GNUNET_GNSRECORD_Data *s_rd_3;
-static char *directory;
/**
* Re-establish the connection to the service.
@@ -379,35 +378,16 @@ empty_zone_proc (void *cls,
static void
empty_zone_proc_end (void *cls)
{
- char *hostkey_file;
-
zi = NULL;
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
-
"N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s'\n",
- hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
-
- GNUNET_asprintf(&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n",
- hostkey_file);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey2 != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 1\n");
-
- GNUNET_asprintf(&s_name_1, "dummy1");
+ GNUNET_asprintf (&s_name_1,
+ "dummy1");
s_rd_1 = create_record (1);
GNUNET_NAMESTORE_records_store (nsh,
privkey,
@@ -419,7 +399,8 @@ empty_zone_proc_end (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 2 \n");
- GNUNET_asprintf(&s_name_2, "dummy2");
+ GNUNET_asprintf (&s_name_2,
+ "dummy2");
s_rd_2 = create_record (1);
GNUNET_NAMESTORE_records_store (nsh,
privkey,
@@ -433,7 +414,8 @@ empty_zone_proc_end (void *cls)
"Created record 3\n");
/* name in different zone */
- GNUNET_asprintf(&s_name_3, "dummy3");
+ GNUNET_asprintf (&s_name_3,
+ "dummy3");
s_rd_3 = create_record (1);
GNUNET_NAMESTORE_records_store (nsh,
privkey2,
@@ -449,14 +431,6 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
@@ -477,7 +451,8 @@ run (void *cls,
"Failed to create zone iterator\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);
}
}
@@ -493,6 +468,8 @@ main (int argc, char *argv[])
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run
("test-namestore-api-zone-iteration-specific-zone",
cfg_name,
@@ -501,12 +478,9 @@ main (int argc, char *argv[])
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
diff --git a/src/namestore/test_namestore_api_zone_to_name.c
b/src/namestore/test_namestore_api_zone_to_name.c
index 5b088d90b..292d8f701 100644
--- a/src/namestore/test_namestore_api_zone_to_name.c
+++ b/src/namestore/test_namestore_api_zone_to_name.c
@@ -51,8 +51,6 @@ static char * s_name;
static int res;
-static char *directory;
-
static struct GNUNET_NAMESTORE_QueueEntry *qe;
@@ -204,34 +202,13 @@ run (void *cls,
{
(void) cls;
(void) peer;
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
GNUNET_SCHEDULER_add_shutdown (&end,
NULL);
GNUNET_asprintf (&s_name, "dummy");
- /* load privat key */
- {
- char *zonekey_file;
-
- GNUNET_asprintf (&zonekey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
-
"N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s'\n",
- zonekey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (zonekey_file);
- GNUNET_free (zonekey_file);
- }
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (NULL != privkey);
/* get public key */
GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
@@ -274,6 +251,8 @@ main (int argc,
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name",
@@ -283,12 +262,9 @@ main (int argc,
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
diff --git a/src/namestore/test_plugin_namestore.c
b/src/namestore/test_plugin_namestore.c
index 6bccd1706..8732acbcb 100644
--- a/src/namestore/test_plugin_namestore.c
+++ b/src/namestore/test_plugin_namestore.c
@@ -215,6 +215,8 @@ main (int argc,
sizeof (cfg_name),
"test_plugin_namestore_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TMP");
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
xargv,
"test-plugin-namestore",
@@ -222,6 +224,8 @@ main (int argc,
options,
&run,
NULL);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TMP");
if (ok != 0)
FPRINTF (stderr,
"Missed some testcases: %d\n",
diff --git a/src/sq/Makefile.am b/src/sq/Makefile.am
index 119a94734..fb9364005 100644
--- a/src/sq/Makefile.am
+++ b/src/sq/Makefile.am
@@ -1,5 +1,5 @@
# This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include
+AM_CPPFLAGS = -I$(top_srcdir)/src/include
if MINGW
WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
@@ -15,6 +15,8 @@ endif
libgnunetsq_la_SOURCES = \
sq.c \
+ sq_exec.c \
+ sq_prepare.c \
sq_query_helper.c \
sq_result_helper.c
libgnunetsq_la_LIBADD = -lsqlite3 \
diff --git a/src/sq/sq_exec.c b/src/sq/sq_exec.c
new file mode 100644
index 000000000..c40b1fb75
--- /dev/null
+++ b/src/sq/sq_exec.c
@@ -0,0 +1,109 @@
+/*
+ This file is part of GNUnet
+ Copyright (C) 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 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, If not, see
<http://www.gnu.org/licenses/>
+*/
+/**
+ * @file sq/sq_exec.c
+ * @brief helper functions for executing SQL statements
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_sq_lib.h"
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_execute (const char *sql)
+ {
+ struct GNUNET_SQ_ExecuteStatement es = {
+ .sql = sql,
+ .ignore_errors = GNUNET_NO
+ };
+
+ return es;
+}
+
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
+ * be tolerated.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_try_execute (const char *sql)
+{
+ struct GNUNET_SQ_ExecuteStatement es = {
+ .sql = sql,
+ .ignore_errors = GNUNET_YES
+ };
+
+ return es;
+}
+
+
+/**
+ * Request execution of an array of statements @a es from Postgres.
+ *
+ * @param dbh database to execute the statements over
+ * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
+ * statements.
+ * @return #GNUNET_OK on success (modulo statements where errors can be
ignored)
+ * #GNUNET_SYSERR on error
+ */
+int
+GNUNET_SQ_exec_statements (sqlite3 *dbh,
+ const struct GNUNET_SQ_ExecuteStatement *es)
+{
+ for (unsigned int i=0;NULL != es[i].sql;i++)
+ {
+ char *emsg = NULL;
+
+ if (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ es[i].sql,
+ NULL,
+ NULL,
+ &emsg))
+ {
+ if (es[i].ignore_errors)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to run SQL `%s': %s\n",
+ es[i].sql,
+ emsg);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to run SQL `%s': %s\n",
+ es[i].sql,
+ emsg);
+ sqlite3_free (emsg);
+ return GNUNET_SYSERR;
+ }
+ sqlite3_free (emsg);
+ }
+ }
+ return GNUNET_OK;
+}
+
+/* end of sq_exec */
diff --git a/src/sq/sq_prepare.c b/src/sq/sq_prepare.c
new file mode 100644
index 000000000..db1047c75
--- /dev/null
+++ b/src/sq/sq_prepare.c
@@ -0,0 +1,81 @@
+/*
+ This file is part of GNUnet
+ Copyright (C) 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 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, If not, see
<http://www.gnu.org/licenses/>
+*/
+/**
+ * @file sq/sq_prepare.c
+ * @brief helper functions for executing SQL statements
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_sq_lib.h"
+
+
+/**
+ * Create a `struct GNUNET_SQ_PrepareStatement`
+ *
+ * @param sql actual SQL statement
+ * @param pstmt where to store the handle
+ * @return initialized struct
+ */
+struct GNUNET_SQ_PrepareStatement
+GNUNET_SQ_make_prepare (const char *sql,
+ sqlite3_stmt **pstmt)
+{
+ struct GNUNET_SQ_PrepareStatement ps = {
+ .sql = sql,
+ .pstmt = pstmt
+ };
+
+ return ps;
+}
+
+
+
+/**
+ * Prepare all statements given in the (NULL,NULL)-terminated
+ * array at @a ps
+ *
+ * @param dbh database to use
+ * @param ps array of statements to prepare
+ * @return #GNUNET_OK on success
+ */
+int
+GNUNET_SQ_prepare (sqlite3 *dbh,
+ const struct GNUNET_SQ_PrepareStatement *ps)
+{
+ for (unsigned int i=0;NULL != ps[i].sql;i++)
+ {
+ const char *epos = NULL;
+ int ret;
+
+ if (SQLITE_OK !=
+ (ret = sqlite3_prepare_v2 (dbh,
+ ps[i].sql,
+ strlen (ps[i].sql),
+ ps[i].pstmt,
+ &epos)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to prepare SQL `%s': error %d at %s\n",
+ ps[i].sql,
+ ret,
+ epos);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
+
+/* end of sq_prepare.c */
diff --git a/src/util/disk.c b/src/util/disk.c
index 8fd689070..37d689576 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2001--2013, 2016 GNUnet e.V.
+ Copyright (C) 2001--2013, 2016, 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
@@ -2641,4 +2641,55 @@ GNUNET_DISK_internal_file_handle_ (const struct
GNUNET_DISK_FileHandle *fh,
return GNUNET_OK;
}
+
+/**
+ * Remove the directory given under @a option in
+ * section [PATHS] in configuration under @a cfg_filename
+ *
+ * @param cfg_filename configuration file to parse
+ * @param option option with the dir name to purge
+ */
+void
+GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
+ const char *option)
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ char *tmpname;
+
+ cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_load (cfg,
+ cfg_filename))
+ {
+ GNUNET_break (0);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "PATHS",
+ option,
+ &tmpname))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "PATHS",
+ option);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return;
+ }
+ GNUNET_CONFIGURATION_destroy (cfg);
+ if (GNUNET_SYSERR ==
+ GNUNET_DISK_directory_remove (tmpname))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "remove",
+ tmpname);
+ GNUNET_free (tmpname);
+ return;
+ }
+ GNUNET_free (tmpname);
+}
+
+
+
/* end of disk.c */
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [gnunet] branch master updated: implement new functions in libgnunetsq, clean up sqlite namestore plugin, implement flow control in namestore API and tests,
gnunet <=