gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] branch master updated (66a629d3b -> 47a9a3c95)


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated (66a629d3b -> 47a9a3c95)
Date: Sun, 15 Apr 2018 20:45:54 +0200

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

grothoff pushed a change to branch master
in repository gnunet.

    from 66a629d3b use heap instead of DLL
     new 284cfac7a modify zoneimport to deal with non-TLD zones due to 
difference in zone cuts between DNS and GNS
     new 47a9a3c95 add transactions to namestore plugin API

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:
 src/include/gnunet_namestore_plugin.h     |  31 ++++++-
 src/namestore/gnunet-zoneimport.c         | 129 ++++++++++++++++++++----------
 src/namestore/plugin_namestore_flat.c     |  93 +++++++++++++++------
 src/namestore/plugin_namestore_postgres.c |  79 +++++++++++++++++-
 src/namestore/plugin_namestore_sqlite.c   |  44 ++++++++++
 src/pq/pq_exec.c                          |   1 -
 6 files changed, 305 insertions(+), 72 deletions(-)

diff --git a/src/include/gnunet_namestore_plugin.h 
b/src/include/gnunet_namestore_plugin.h
index 11f16b97a..d1c68cd23 100644
--- a/src/include/gnunet_namestore_plugin.h
+++ b/src/include/gnunet_namestore_plugin.h
@@ -88,7 +88,7 @@ struct GNUNET_NAMESTORE_PluginFunctions
                    const char *label,
                    unsigned int rd_count,
                    const struct GNUNET_GNSRECORD_Data *rd);
-  
+
   /**
    * Lookup records in the datastore for which we are the authority.
    *
@@ -145,6 +145,35 @@ struct GNUNET_NAMESTORE_PluginFunctions
                   void *iter_cls);
 
 
+  /**
+   * Start a transaction.
+   *
+   * @param cls closure
+   * @return #GNUNET_OK on success, #GNUNET_NO if transactions are not 
supported,
+   *         #GNUNET_SYSERR on internal errors
+   */
+  int
+  (*begin_transaction) (void *cls);
+
+
+  /**
+   * Try to commit a transaction.
+   *
+   * @param cls closure
+   * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+   */
+  int
+  (*commit_transaction) (void *cls);
+
+
+  /**
+   * Rollback a transaction.
+   *
+   * @param cls closure
+   */
+  void
+  (*rollback_transaction) (void *cls);
+
 };
 
 
diff --git a/src/namestore/gnunet-zoneimport.c 
b/src/namestore/gnunet-zoneimport.c
index bac3d2603..e1d5b650d 100644
--- a/src/namestore/gnunet-zoneimport.c
+++ b/src/namestore/gnunet-zoneimport.c
@@ -32,6 +32,38 @@
 
 
 /**
+ * Some zones may include authoritative records for other
+ * zones, such as foo.com.uk or bar.com.fr.  As for GNS
+ * each dot represents a zone cut, we then need to create a
+ * zone on-the-fly to capture those records properly.
+ */
+struct Zone
+{
+
+  /**
+   * Kept in a DLL.
+   */
+  struct Zone *next;
+
+  /**
+   * Kept in a DLL.
+   */
+  struct Zone *prev;
+
+  /**
+   * Domain of the zone (i.e. "fr" or "com.fr")
+   */
+  char *domain;
+
+  /**
+   * Private key of the zone.
+   */
+  struct GNUNET_CRYPTO_EcdsaPrivateKey key;
+
+};
+
+
+/**
  * Record for the request to be stored by GNS.
  */
 struct Record
@@ -97,6 +129,11 @@ struct Request
   char *label;
 
   /**
+   * Zone responsible for this request.
+   */
+  const struct Zone *zone;
+
+  /**
    * Answer we got back and are currently parsing, or NULL
    * if not active.
    */
@@ -194,20 +231,14 @@ static char *dns_server;
 static char *db_lib_name;
 
 /**
- * Which zone are we importing into?
+ * Head of list of zones we are managing.
  */
-static struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
+static struct Zone *zone_head;
 
 /**
- * Which zone should records be imported into?
+ * Tail of list of zones we are managing.
  */
-static char *zone_name;
-
-/**
- * Did we find #zone_name and initialize #zone?
- */
-static int zone_found;
-
+static struct Zone *zone_tail;
 
 /**
  * Maximum number of queries pending at the same time.
@@ -789,7 +820,7 @@ process_result (void *cls,
       rd[off++] = rec->grd;
     if (GNUNET_OK !=
        ns->store_records (ns->cls,
-                          &zone,
+                          &req->zone->key,
                           req->label,
                           rd_count,
                           rd))
@@ -915,6 +946,7 @@ static void
 do_shutdown (void *cls)
 {
   struct Request *req;
+  struct Zone *zone;
 
   (void) cls;
   if (NULL != id)
@@ -952,6 +984,14 @@ do_shutdown (void *cls)
     GNUNET_CONTAINER_heap_destroy (req_heap);
     req_heap = NULL;
   }
+  while (NULL != (zone = zone_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (zone_head,
+                                 zone_tail,
+                                 zone);
+    GNUNET_free (zone->domain);
+    GNUNET_free (zone);
+  }
 }
 
 
@@ -974,8 +1014,8 @@ import_records (void *cls,
   struct Request *req = cls;
 
   GNUNET_break (0 == memcmp (private_key,
-                            &zone,
-                            sizeof (zone)));
+                            &req->zone->key,
+                            sizeof (*private_key)));
   GNUNET_break (0 == strcasecmp (label,
                                 req->label));
   for (unsigned int i=0;i<rd_count;i++)
@@ -1006,6 +1046,7 @@ queue (const char *hostname)
   char *raw;
   size_t raw_size;
   const char *dot;
+  struct Zone *zone;
 
   if (GNUNET_OK !=
       GNUNET_DNSPARSER_check_name (hostname))
@@ -1016,12 +1057,8 @@ queue (const char *hostname)
     rejects++;
     return;
   }
-  /* TODO: may later support importing zones that
-     are not TLD, for this we mostly need to change
-     the logic here to remove the zone's suffix
-     instead of just ".tld" */
-  dot = strrchr (hostname,
-                (unsigned char) '.');
+  dot = strchr (hostname,
+                (unsigned char) '.');
   if (NULL == dot)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1030,6 +1067,21 @@ queue (const char *hostname)
     rejects++;
     return;
   }
+  for (zone = zone_head; NULL != zone; zone = zone->next)
+    if ( (0 == strncmp (zone->domain,
+                        hostname,
+                        dot - hostname)) &&
+         (strlen (zone->domain) == dot - hostname) )
+      break;
+  if (NULL == zone)
+  {
+    rejects++;
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Domain name `%.*s' not in ego list!\n",
+                (int) (dot - hostname),
+                hostname);
+    return;
+  }
   q.name = (char *) hostname;
   q.type = GNUNET_DNSPARSER_TYPE_NS;
   q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
@@ -1056,27 +1108,16 @@ queue (const char *hostname)
   }
 
   req = GNUNET_new (struct Request);
+  req->zone = zone;
   req->hostname = GNUNET_strdup (hostname);
   req->raw = raw;
   req->raw_len = raw_size;
   req->id = p.id;
   req->label = GNUNET_strndup (hostname,
                               dot - hostname);
-  if (NULL != strchr (req->label,
-                     (unsigned char) '.'))
-  {
-    GNUNET_free (req->hostname);
-    GNUNET_free (req->label);
-    GNUNET_free (req);
-    rejects++;
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Label contained a `.', invalid hostname `%s'\n",
-                hostname);
-    return;
-  }
   if (GNUNET_OK !=
       ns->lookup_records (ns->cls,
-                         &zone,
+                         &req->zone->key,
                          req->label,
                          &import_records,
                          req))
@@ -1188,9 +1229,11 @@ identity_cb (void *cls,
   (void) ctx;
   if (NULL == ego)
   {
-    if (zone_found)
+    if (NULL != zone_head)
+    {
       t = GNUNET_SCHEDULER_add_now (&process_stdin,
                                    NULL);
+    }
     else
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1199,12 +1242,16 @@ identity_cb (void *cls,
       return;
     }
   }
-  if ( (NULL != name) &&
-       (0 == strcasecmp (name,
-                        zone_name)) )
+  if (NULL != name)
   {
-    zone_found = GNUNET_YES;
-    zone = *GNUNET_IDENTITY_ego_get_private_key (ego);
+    struct Zone *zone;
+
+    zone = GNUNET_new (struct Zone);
+    zone->key = *GNUNET_IDENTITY_ego_get_private_key (ego);
+    zone->domain = GNUNET_strdup (name);
+    GNUNET_CONTAINER_DLL_insert (zone_head,
+                                 zone_tail,
+                                 zone);
   }
 }
 
@@ -1282,12 +1329,6 @@ main (int argc,
                                  "IP",
                                  "which DNS server should be used",
                                  &dns_server)),
-    GNUNET_GETOPT_option_mandatory
-    (GNUNET_GETOPT_option_string ('i',
-                                 "identity",
-                                 "ZONENAME",
-                                 "which GNS zone should we import data into",
-                                 &zone_name)),
     GNUNET_GETOPT_OPTION_END
   };
 
diff --git a/src/namestore/plugin_namestore_flat.c 
b/src/namestore/plugin_namestore_flat.c
index 024fc34f2..170adb49e 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -383,7 +383,7 @@ static void
 database_shutdown (struct Plugin *plugin)
 {
   struct GNUNET_DISK_FileHandle *fh;
-  
+
   fh = GNUNET_DISK_file_open (plugin->fn,
                               GNUNET_DISK_OPEN_CREATE |
                               GNUNET_DISK_OPEN_TRUNCATE |
@@ -418,11 +418,11 @@ database_shutdown (struct Plugin *plugin)
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
-namestore_store_records (void *cls,
-                         const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
-                         const char *label,
-                         unsigned int rd_count,
-                         const struct GNUNET_GNSRECORD_Data *rd)
+namestore_flat_store_records (void *cls,
+                              const struct GNUNET_CRYPTO_EcdsaPrivateKey 
*zone_key,
+                              const char *label,
+                              unsigned int rd_count,
+                              const struct GNUNET_GNSRECORD_Data *rd)
 {
   struct Plugin *plugin = cls;
   uint64_t rvalue;
@@ -488,11 +488,11 @@ namestore_store_records (void *cls,
  * @return #GNUNET_OK on success, else #GNUNET_SYSERR
  */
 static int
-namestore_lookup_records (void *cls,
-                          const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
-                          const char *label,
-                          GNUNET_NAMESTORE_RecordIterator iter,
-                          void *iter_cls)
+namestore_flat_lookup_records (void *cls,
+                               const struct GNUNET_CRYPTO_EcdsaPrivateKey 
*zone,
+                               const char *label,
+                               GNUNET_NAMESTORE_RecordIterator iter,
+                               void *iter_cls)
 {
   struct Plugin *plugin = cls;
   struct FlatFileEntry *entry;
@@ -571,11 +571,11 @@ iterate_zones (void *cls,
  * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, 
#GNUNET_SYSERR on error
  */
 static int
-namestore_iterate_records (void *cls,
-                           const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
-                           uint64_t offset,
-                           GNUNET_NAMESTORE_RecordIterator iter,
-                          void *iter_cls)
+namestore_flat_iterate_records (void *cls,
+                                const struct GNUNET_CRYPTO_EcdsaPrivateKey 
*zone,
+                                uint64_t offset,
+                                GNUNET_NAMESTORE_RecordIterator iter,
+                                void *iter_cls)
 {
   struct Plugin *plugin = cls;
 
@@ -641,11 +641,11 @@ zone_to_name (void *cls,
  * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, 
#GNUNET_SYSERR on error
  */
 static int
-namestore_zone_to_name (void *cls,
-                        const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
-                        const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
-                        GNUNET_NAMESTORE_RecordIterator iter,
-                       void *iter_cls)
+namestore_flat_zone_to_name (void *cls,
+                             const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+                             const struct GNUNET_CRYPTO_EcdsaPublicKey 
*value_zone,
+                             GNUNET_NAMESTORE_RecordIterator iter,
+                             void *iter_cls)
 {
   struct Plugin *plugin = cls;
 
@@ -667,6 +667,46 @@ namestore_zone_to_name (void *cls,
 
 
 /**
+ * Start a transaction.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success, #GNUNET_NO if transactions are not supported,
+ *         #GNUNET_SYSERR on internal errors
+ */
+static int
+namestore_flat_begin_transaction (void *cls)
+{
+  return GNUNET_NO;
+}
+
+
+/**
+ * Try to commit a transaction.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+ */
+static int
+namestore_flat_commit_transaction (void *cls)
+{
+  GNUNET_break (0);
+  return GNUNET_SYSERR;
+}
+
+
+/**
+ * Rollback a transaction.
+ *
+ * @param cls closure
+ */
+static void
+namestore_flat_rollback_transaction (void *cls)
+{
+  GNUNET_break (0);
+}
+
+
+/**
  * Entry point for the plugin.
  *
  * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
@@ -692,10 +732,13 @@ libgnunet_plugin_namestore_flat_init (void *cls)
   }
   api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions);
   api->cls = &plugin;
-  api->store_records = &namestore_store_records;
-  api->iterate_records = &namestore_iterate_records;
-  api->zone_to_name = &namestore_zone_to_name;
-  api->lookup_records = &namestore_lookup_records;
+  api->store_records = &namestore_flat_store_records;
+  api->iterate_records = &namestore_flat_iterate_records;
+  api->zone_to_name = &namestore_flat_zone_to_name;
+  api->lookup_records = &namestore_flat_lookup_records;
+  api->begin_transaction = &namestore_flat_begin_transaction;
+  api->commit_transaction = &namestore_flat_commit_transaction;
+  api->rollback_transaction = &namestore_flat_rollback_transaction;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               _("flat file database running\n"));
   return api;
diff --git a/src/namestore/plugin_namestore_postgres.c 
b/src/namestore/plugin_namestore_postgres.c
index 4828cb190..378a88f51 100644
--- a/src/namestore/plugin_namestore_postgres.c
+++ b/src/namestore/plugin_namestore_postgres.c
@@ -243,7 +243,7 @@ namestore_postgres_store_records (void *cls,
                                              data_size,
                                              data);
     if ( (ret < 0) ||
-        (data_size != (size_t) ret) )        
+        (data_size != (size_t) ret) )
     {
       GNUNET_break (0);
       return GNUNET_SYSERR;
@@ -518,6 +518,80 @@ database_shutdown (struct Plugin *plugin)
 
 
 /**
+ * Start a transaction.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success, #GNUNET_NO if transactions are not supported,
+ *         #GNUNET_SYSERR on internal errors
+ */
+static int
+namestore_postgres_begin_transaction (void *cls)
+{
+  struct Plugin *plugin = cls;
+  PGresult *result;
+  ExecStatusType ex;
+
+  result = PQexec (plugin->dbh,
+                   "START TRANSACTION ISOLATION LEVEL SERIALIZABLE");
+  if (PGRES_COMMAND_OK !=
+      (ex = PQresultStatus (result)))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to start transaction (%s): %s\n",
+                PQresStatus (ex),
+                PQerrorMessage (plugin->dbh));
+    GNUNET_break (0);
+    PQclear (result);
+    return GNUNET_SYSERR;
+  }
+  PQclear (result);
+  return GNUNET_OK;
+}
+
+
+/**
+ * Try to commit a transaction.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+ */
+static int
+namestore_postgres_commit_transaction (void *cls)
+{
+  struct Plugin *plugin = cls;
+  PGresult *result;
+  ExecStatusType status;
+  int ret;
+
+  result = PQexec (plugin->dbh,
+                   "COMMIT");
+  status = PQresultStatus (result);
+  ret = (PGRES_COMMAND_OK == status) ? GNUNET_OK : GNUNET_SYSERR;
+  PQclear (result);
+  return ret;
+}
+
+
+/**
+ * Rollback a transaction.
+ *
+ * @param cls closure
+ */
+static void
+namestore_postgres_rollback_transaction (void *cls)
+{
+  struct Plugin *plugin = cls;
+  PGresult *result;
+
+  result = PQexec (plugin->dbh,
+                   "ROLLBACK");
+  GNUNET_break (PGRES_COMMAND_OK ==
+                PQresultStatus (result));
+  PQclear (result);
+}
+
+
+/**
  * Entry point for the plugin.
  *
  * @param cls the `struct GNUNET_NAMESTORE_PluginEnvironment*`
@@ -545,6 +619,9 @@ libgnunet_plugin_namestore_postgres_init (void *cls)
   api->iterate_records = &namestore_postgres_iterate_records;
   api->zone_to_name = &namestore_postgres_zone_to_name;
   api->lookup_records = &namestore_postgres_lookup_records;
+  api->begin_transaction = &namestore_postgres_begin_transaction;
+  api->commit_transaction = &namestore_postgres_commit_transaction;
+  api->rollback_transaction = &namestore_postgres_rollback_transaction;
   LOG (GNUNET_ERROR_TYPE_INFO,
        "Postgres namestore plugin running\n");
   return api;
diff --git a/src/namestore/plugin_namestore_sqlite.c 
b/src/namestore/plugin_namestore_sqlite.c
index 5ad84688c..1ebb6bfc7 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -773,6 +773,47 @@ namestore_sqlite_zone_to_name (void *cls,
 
 
 /**
+ * Start a transaction.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success, #GNUNET_NO if transactions are not supported,
+ *         #GNUNET_SYSERR on internal errors
+ */
+static int
+namestore_sqlite_begin_transaction (void *cls)
+{
+  return GNUNET_NO;
+}
+
+
+/**
+ * Try to commit a transaction.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+ */
+static int
+namestore_sqlite_commit_transaction (void *cls)
+{
+  GNUNET_break (0);
+  return GNUNET_SYSERR;
+}
+
+
+/**
+ * Rollback a transaction.
+ *
+ * @param cls closure
+ */
+static void
+namestore_sqlite_rollback_transaction (void *cls)
+{
+  GNUNET_break (0);
+}
+
+
+
+/**
  * Entry point for the plugin.
  *
  * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
@@ -800,6 +841,9 @@ libgnunet_plugin_namestore_sqlite_init (void *cls)
   api->iterate_records = &namestore_sqlite_iterate_records;
   api->zone_to_name = &namestore_sqlite_zone_to_name;
   api->lookup_records = &namestore_sqlite_lookup_records;
+  api->begin_transaction = &namestore_sqlite_begin_transaction;
+  api->commit_transaction = &namestore_sqlite_commit_transaction;
+  api->rollback_transaction = &namestore_sqlite_rollback_transaction;
   LOG (GNUNET_ERROR_TYPE_INFO,
        _("Sqlite database running\n"));
   return api;
diff --git a/src/pq/pq_exec.c b/src/pq/pq_exec.c
index 1e5e4eb76..eacc1f2b3 100644
--- a/src/pq/pq_exec.c
+++ b/src/pq/pq_exec.c
@@ -79,7 +79,6 @@ GNUNET_PQ_exec_statements (PGconn *connection,
 
     result = PQexec (connection,
                      es[i].sql);
-
     if ( (GNUNET_NO == es[i].ignore_errors) &&
          (PGRES_COMMAND_OK != PQresultStatus (result)) )
     {

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



reply via email to

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