gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated (32b55237f -> 4353432b9)


From: gnunet
Subject: [gnunet] branch master updated (32b55237f -> 4353432b9)
Date: Fri, 17 Jan 2020 02:29:50 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a change to branch master
in repository gnunet.

    from 32b55237f Merge branch 'master' of ssh://git.gnunet.org/gnunet
     new 1126181ab include buffer in main util header
     new 4353432b9 DB load API change

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 contrib/build-common                     |  2 +-
 src/cadet/gnunet-service-cadet_channel.c |  2 +-
 src/cadet/gnunet-service-cadet_tunnels.c | 17 ++----
 src/curl/curl.c                          |  4 +-
 src/gnsrecord/gnsrecord_crypto.c         |  2 +-
 src/include/gnunet_disk_lib.h            |  1 -
 src/include/gnunet_os_lib.h              |  2 +-
 src/include/gnunet_pq_lib.h              | 22 +++++---
 src/include/gnunet_util_lib.h            |  1 +
 src/pq/pq.h                              |  5 ++
 src/pq/pq_connect.c                      | 92 ++++++++++++++++++++++++++++----
 src/util/os_priority.c                   |  2 +-
 12 files changed, 116 insertions(+), 36 deletions(-)

diff --git a/contrib/build-common b/contrib/build-common
index d81bbfabc..1915a74bb 160000
--- a/contrib/build-common
+++ b/contrib/build-common
@@ -1 +1 @@
-Subproject commit d81bbfabc2538932f631d3946bd6a9b95182b4f2
+Subproject commit 1915a74bbb4cd2ae9bc541a382dfebc37064a2fd
diff --git a/src/cadet/gnunet-service-cadet_channel.c 
b/src/cadet/gnunet-service-cadet_channel.c
index a2c710cbc..5c8103c5e 100644
--- a/src/cadet/gnunet-service-cadet_channel.c
+++ b/src/cadet/gnunet-service-cadet_channel.c
@@ -2026,4 +2026,4 @@ GCCH_debug (struct CadetChannel *ch, enum 
GNUNET_ErrorType level)
 }
 
 
-/* end of gnunet-service-cadet-new_channel.c */
+/* end of gnunet-service-cadet_channel.c */
diff --git a/src/cadet/gnunet-service-cadet_tunnels.c 
b/src/cadet/gnunet-service-cadet_tunnels.c
index a1098d757..ae201ed2d 100644
--- a/src/cadet/gnunet-service-cadet_tunnels.c
+++ b/src/cadet/gnunet-service-cadet_tunnels.c
@@ -544,29 +544,22 @@ estate2s (enum CadetTunnelEState es)
   {
   case CADET_TUNNEL_KEY_UNINITIALIZED:
     return "CADET_TUNNEL_KEY_UNINITIALIZED";
-
   case CADET_TUNNEL_KEY_AX_RECV:
     return "CADET_TUNNEL_KEY_AX_RECV";
-
   case CADET_TUNNEL_KEY_AX_SENT:
     return "CADET_TUNNEL_KEY_AX_SENT";
-
   case CADET_TUNNEL_KEY_AX_SENT_AND_RECV:
     return "CADET_TUNNEL_KEY_AX_SENT_AND_RECV";
-
   case CADET_TUNNEL_KEY_AX_AUTH_SENT:
     return "CADET_TUNNEL_KEY_AX_AUTH_SENT";
-
   case CADET_TUNNEL_KEY_OK:
     return "CADET_TUNNEL_KEY_OK";
-
-  default:
-    GNUNET_snprintf (buf,
-                     sizeof(buf),
-                     "%u (UNKNOWN STATE)",
-                     es);
-    return buf;
   }
+  GNUNET_snprintf (buf,
+                   sizeof(buf),
+                   "%u (UNKNOWN STATE)",
+                   es);
+  return buf;
 }
 
 
diff --git a/src/curl/curl.c b/src/curl/curl.c
index 82eb28ed9..01c7c5fca 100644
--- a/src/curl/curl.c
+++ b/src/curl/curl.c
@@ -556,7 +556,9 @@ GNUNET_CURL_download_get_result_ (struct 
GNUNET_CURL_DownloadBuffer *db,
     }
     if (0 != db->buf_size)
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  "Did NOT detect response as JSON\n");
+                  "Did NOT detect response `%.*s' as JSON\n",
+                  (int) db->buf_size,
+                  (const char *) db->buf);
     return NULL;
   }
   json = NULL;
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c
index b27688019..ea8baa77d 100644
--- a/src/gnsrecord/gnsrecord_crypto.c
+++ b/src/gnsrecord/gnsrecord_crypto.c
@@ -80,7 +80,7 @@ derive_block_aes_key (struct 
GNUNET_CRYPTO_SymmetricInitializationVector *iv,
  * @param rd_count number of records
  * @return NULL on error (block too large)
  */
-struct GNUNET_GNSRECORD_Block *
+static struct GNUNET_GNSRECORD_Block *
 block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
               const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey,
               struct GNUNET_TIME_Absolute expire,
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index 9376a1059..b79be5f70 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -413,7 +413,6 @@ GNUNET_DISK_pipe (int blocking_read,
  * @param blocking_read creates an asynchronous pipe for reading if set to 
#GNUNET_NO
  * @param blocking_write creates an asynchronous pipe for writing if set to 
#GNUNET_NO
  * @param fd an array of two fd values. One of them may be -1 for read-only or 
write-only pipes
- *
  * @return handle to the new pipe, NULL on error
  */
 struct GNUNET_DISK_PipeHandle *
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h
index 50e9a4c92..a6188c1ca 100644
--- a/src/include/gnunet_os_lib.h
+++ b/src/include/gnunet_os_lib.h
@@ -597,7 +597,7 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc,
 
 
 /**
- * Retrieve the status of a process, waiting on it if dead.
+ * Retrieve the status of a process.
  * Nonblocking version.
  *
  * @param proc pointer to process structure
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index 2aea77b7f..8b32a9265 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -708,15 +708,22 @@ GNUNET_PQ_exec_statements (struct GNUNET_PQ_Context *db,
 
 
 /**
- * Create a connection to the Postgres database using @a config_str
- * for the configuration.  Initialize logging via GNUnet's log
- * routines and disable Postgres's logger.  Also ensures that the
- * statements in @a es are executed whenever we (re)connect to the
- * database, and that the prepared statements in @a ps are "ready".
- * If statements in @es fail that were created with
- * #GNUNET_PQ_make_execute(), then the entire operation fails.
+ * Create a connection to the Postgres database using @a config_str for the
+ * configuration.  Initialize logging via GNUnet's log routines and disable
+ * Postgres's logger.  Also ensures that the statements in @a load_path and @a
+ * es are executed whenever we (re)connect to the database, and that the
+ * prepared statements in @a ps are "ready".  If statements in @es fail that
+ * were created with #GNUNET_PQ_make_execute(), then the entire operation
+ * fails.
+ *
+ * In @a load_path, a list of "$XXXX.sql" files is expected where $XXXX
+ * must be a sequence of contiguous integer values starting at 0000.
+ * These files are then loaded in sequence using "psql $config_str" before
+ * running statements from @e es.  The directory is inspected again on
+ * reconnect.
  *
  * @param config_str configuration to use
+ * @param load_path path to directory with SQL transactions to run, can be NULL
  * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated
  *            array of statements to execute upon EACH connection, can be NULL
  * @param ps array of prepared statements to prepare, can be NULL
@@ -724,6 +731,7 @@ GNUNET_PQ_exec_statements (struct GNUNET_PQ_Context *db,
  */
 struct GNUNET_PQ_Context *
 GNUNET_PQ_connect (const char *config_str,
+                   const char *load_path,
                    const struct GNUNET_PQ_ExecuteStatement *es,
                    const struct GNUNET_PQ_PreparedStatement *ps);
 
diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h
index 24ad4e4e5..5e790550f 100644
--- a/src/include/gnunet_util_lib.h
+++ b/src/include/gnunet_util_lib.h
@@ -64,6 +64,7 @@ extern "C"
 #include "gnunet_crypto_lib.h"
 #include "gnunet_bandwidth_lib.h"
 #include "gnunet_bio_lib.h"
+#include "gnunet_buffer_lib.h"
 #include "gnunet_client_lib.h"
 #include "gnunet_container_lib.h"
 #include "gnunet_getopt_lib.h"
diff --git a/src/pq/pq.h b/src/pq/pq.h
index b30f4f0d4..91a890bcb 100644
--- a/src/pq/pq.h
+++ b/src/pq/pq.h
@@ -52,6 +52,11 @@ struct GNUNET_PQ_Context
    * Configuration to use to connect to the DB.
    */
   char *config_str;
+
+  /**
+   * Path to load SQL files from.
+   */
+  char *load_path;
 };
 
 #endif
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c
index 7d9a524b3..5ade12a3e 100644
--- a/src/pq/pq_connect.c
+++ b/src/pq/pq_connect.c
@@ -64,19 +64,22 @@ pq_notice_processor_cb (void *arg,
 
 
 /**
- * Create a connection to the Postgres database using @a config_str
- * for the configuration.  Initialize logging via GNUnet's log
- * routines and disable Postgres's logger.  Also ensures that the
- * statements in @a es are executed whenever we (re)connect to the
- * database, and that the prepared statements in @a ps are "ready".
- * If statements in @es fail that were created with
- * #GNUNET_PQ_make_execute(), then the entire operation fails.
+ * Create a connection to the Postgres database using @a config_str for the
+ * configuration.  Initialize logging via GNUnet's log routines and disable
+ * Postgres's logger.  Also ensures that the statements in @a load_path and @a
+ * es are executed whenever we (re)connect to the database, and that the
+ * prepared statements in @a ps are "ready".  If statements in @es fail that
+ * were created with #GNUNET_PQ_make_execute(), then the entire operation
+ * fails.
  *
- * The caller MUST ensure that @a es and @a ps remain allocated and
- * initialized in memory until #GNUNET_PQ_disconnect() is called,
- * as they may be needed repeatedly and no copy will be made.
+ * In @a load_path, a list of "$XXXX.sql" files is expected where $XXXX
+ * must be a sequence of contiguous integer values starting at 0000.
+ * These files are then loaded in sequence using "psql $config_str" before
+ * running statements from @e es.  The directory is inspected again on
+ * reconnect.
  *
  * @param config_str configuration to use
+ * @param load_path path to directory with SQL transactions to run, can be NULL
  * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated
  *            array of statements to execute upon EACH connection, can be NULL
  * @param ps array of prepared statements to prepare, can be NULL
@@ -84,6 +87,7 @@ pq_notice_processor_cb (void *arg,
  */
 struct GNUNET_PQ_Context *
 GNUNET_PQ_connect (const char *config_str,
+                   const char *load_path,
                    const struct GNUNET_PQ_ExecuteStatement *es,
                    const struct GNUNET_PQ_PreparedStatement *ps)
 {
@@ -100,6 +104,8 @@ GNUNET_PQ_connect (const char *config_str,
 
   db = GNUNET_new (struct GNUNET_PQ_Context);
   db->config_str = GNUNET_strdup (config_str);
+  if (NULL != load_path)
+    db->load_path = GNUNET_strdup (load_path);
   if (0 != elen)
   {
     db->es = GNUNET_new_array (elen + 1,
@@ -175,6 +181,62 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
   PQsetNoticeProcessor (db->conn,
                         &pq_notice_processor_cb,
                         db);
+  if (NULL != db->load_path)
+  {
+    size_t slen = strlen (db->load_path) + 10;
+
+    for (unsigned int i = 0; i<10000; i++)
+    {
+      char buf[slen];
+      struct GNUNET_OS_Process *psql;
+      enum GNUNET_OS_ProcessStatusType type;
+      unsigned long code;
+
+      GNUNET_snprintf (buf,
+                       sizeof (buf),
+                       "%s/%u.sql",
+                       db->load_path,
+                       i);
+      if (GNUNET_YES !=
+          GNUNET_DISK_file_test (buf))
+        break; /* We are done */
+      psql = GNUNET_OS_start_process (GNUNET_NO,
+                                      GNUNET_OS_INHERIT_STD_ERR,
+                                      NULL,
+                                      NULL,
+                                      NULL,
+                                      "psql",
+                                      db->config_str,
+                                      "-f",
+                                      buf,
+                                      "-q",
+                                      NULL);
+      if (NULL == psql)
+      {
+        GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+                                  "exec",
+                                  "psql");
+        PQfinish (db->conn);
+        db->conn = NULL;
+        return;
+      }
+      GNUNET_assert (GNUNET_OK ==
+                     GNUNET_OS_process_wait_status (psql,
+                                                    &type,
+                                                    &code));
+      GNUNET_OS_process_destroy (psql);
+      if ( (GNUNET_OS_PROCESS_EXITED != type) ||
+           (0 != code) )
+      {
+        GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+                                  "psql",
+                                  buf);
+        PQfinish (db->conn);
+        db->conn = NULL;
+        return;
+      }
+    }
+  }
   if ( (NULL != db->es) &&
        (GNUNET_OK !=
         GNUNET_PQ_exec_statements (db,
@@ -221,6 +283,7 @@ GNUNET_PQ_connect_with_cfg (const struct 
GNUNET_CONFIGURATION_Handle *cfg,
 {
   struct GNUNET_PQ_Context *db;
   char *conninfo;
+  char *load_path;
 
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
@@ -228,9 +291,17 @@ GNUNET_PQ_connect_with_cfg (const struct 
GNUNET_CONFIGURATION_Handle *cfg,
                                              "CONFIG",
                                              &conninfo))
     conninfo = NULL;
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cfg,
+                                             section,
+                                             "SQL_PATH",
+                                             &load_path))
+    load_path = NULL;
   db = GNUNET_PQ_connect (conninfo == NULL ? "" : conninfo,
+                          load_path,
                           es,
                           ps);
+  GNUNET_free_non_null (load_path);
   GNUNET_free_non_null (conninfo);
   return db;
 }
@@ -247,6 +318,7 @@ GNUNET_PQ_disconnect (struct GNUNET_PQ_Context *db)
 {
   GNUNET_free_non_null (db->es);
   GNUNET_free_non_null (db->ps);
+  GNUNET_free_non_null (db->load_path);
   PQfinish (db->conn);
   GNUNET_free (db);
 }
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index d93e0d44f..722aac872 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -951,7 +951,7 @@ process_status (struct GNUNET_OS_Process *proc,
 
 
 /**
- * Retrieve the status of a process, waiting on it if dead.
+ * Retrieve the status of a process.
  * Nonblocking version.
  *
  * @param proc process ID

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]