gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: NAMESTORE: Make bulk and transactional A


From: gnunet
Subject: [gnunet] branch master updated: NAMESTORE: Make bulk and transactional API consistent with monitoring
Date: Mon, 03 Oct 2022 13:51:00 +0200

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

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 4be1619e0 NAMESTORE: Make bulk and transactional API consistent with 
monitoring
4be1619e0 is described below

commit 4be1619e0826b061993257aea488f1f14ea888ae
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Mon Oct 3 20:50:53 2022 +0900

    NAMESTORE: Make bulk and transactional API consistent with monitoring
---
 src/namestore/gnunet-service-namestore.c | 194 ++++++++++++++++++-------------
 src/namestore/namestore_api.c            |   2 +-
 src/namestore/plugin_rest_namestore.c    | 165 ++++++++++++++++----------
 3 files changed, 214 insertions(+), 147 deletions(-)

diff --git a/src/namestore/gnunet-service-namestore.c 
b/src/namestore/gnunet-service-namestore.c
index bdc55cff0..fbe188122 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -317,6 +317,16 @@ struct StoreActivity
    */
   uint32_t rid;
 
+  /**
+   * The currently processed record
+   */
+  uint16_t rd_set_pos;
+
+  /**
+   * The number of records in this activity
+   */
+  uint16_t rd_set_count;
+
   /**
    * Wheather or not this store action is already commited.
    * The store activity will not be processed unless this field is GNUNET_YES
@@ -339,10 +349,6 @@ struct StoreActivity
    */
   struct ZoneMonitor *zm_pos;
 
-  /**
-   * Label nicely canonicalized (lower case).
-   */
-  char *conv_name;
 };
 
 
@@ -503,7 +509,6 @@ static void
 free_store_activity (struct StoreActivity *sa)
 {
   GNUNET_CONTAINER_DLL_remove (sa_head, sa_tail, sa);
-  GNUNET_free (sa->conv_name);
   GNUNET_free (sa);
 }
 
@@ -1133,6 +1138,8 @@ continue_store_activity (struct StoreActivity *sa)
   uint32_t rid;
   const char *name_tmp;
   const char *rd_ser;
+  const char *buf;
+  char *conv_name;
 
   // If we are in a transaction, do not notify monitors or update
   // cached. This will be done when we are commiting.
@@ -1144,63 +1151,75 @@ continue_store_activity (struct StoreActivity *sa)
     GNUNET_SERVICE_client_continue (sa->nc->client);
     return;
   }
-  name_len = ntohs (rd_set->name_len);
-  rd_count = ntohs (rd_set->rd_count);
-  rd_ser_len = ntohs (rd_set->rd_len);
-  name_tmp = (const char *) &rd_set[1];
-  rd_ser = &name_tmp[name_len];
-  {
-    struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)];
+  buf = (const char *) &sa[1];
+  for (int i = sa->rd_set_pos; i < sa->rd_set_count; i++)
+  {
+    rd_set = (struct RecordSet *) buf;
+    name_len = ntohs (rd_set->name_len);
+    rd_count = ntohs (rd_set->rd_count);
+    rd_ser_len = ntohs (rd_set->rd_len);
+    name_tmp = (const char *) &rd_set[1];
+    rd_ser = &name_tmp[name_len];
+    conv_name = GNUNET_GNSRECORD_string_normalize (name_tmp);
+    GNUNET_assert (NULL != conv_name);
+    {
+      struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (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));
+      /* We did this before, must succeed again */
+      GNUNET_assert (
+        GNUNET_OK ==
+        GNUNET_GNSRECORD_records_deserialize (rd_ser_len, rd_ser, rd_count,
+                                              rd));
 
-    for (struct ZoneMonitor *zm = sa->zm_pos; NULL != zm; zm = sa->zm_pos)
-    {
-      if ((0 != GNUNET_memcmp (&sa->private_key, &zm->zone)) &&
-          (0 != GNUNET_memcmp (&zm->zone, &zero)))
+      for (struct ZoneMonitor *zm = sa->zm_pos; NULL != zm; zm = sa->zm_pos)
       {
-        sa->zm_pos = zm->next;     /* not interesting to this monitor */
-        continue;
-      }
-      if (zm->limit == zm->iteration_cnt)
-      {
-        zm->sa_waiting = GNUNET_YES;
-        zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
-        if (NULL != zm->sa_wait_warning)
-          GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
-        zm->sa_wait_warning =
-          GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
-                                        &warn_monitor_slow,
-                                        zm);
-        return;     /* blocked on zone monitor */
+        if ((0 != GNUNET_memcmp (&sa->private_key, &zm->zone)) &&
+            (0 != GNUNET_memcmp (&zm->zone, &zero)))
+        {
+          sa->zm_pos = zm->next;   /* not interesting to this monitor */
+          continue;
+        }
+        if (zm->limit == zm->iteration_cnt)
+        {
+          zm->sa_waiting = GNUNET_YES;
+          zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
+          if (NULL != zm->sa_wait_warning)
+            GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
+          zm->sa_wait_warning =
+            GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
+                                          &warn_monitor_slow,
+                                          zm);
+          GNUNET_free (conv_name);
+          return;   /* blocked on zone monitor */
+        }
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "Notifying monitor about changes under label `%s'\n",
+                    conv_name);
+        zm->limit--;
+        send_lookup_response_with_filter (zm->nc,
+                                          0,
+                                          &sa->private_key,
+                                          conv_name,
+                                          rd_count,
+                                          rd,
+                                          zm->filter);
+        sa->zm_pos = zm->next;
       }
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Notifying monitor about changes under label `%s'\n",
-                  sa->conv_name);
-      zm->limit--;
-      send_lookup_response_with_filter (zm->nc,
-                                        0,
-                                        &sa->private_key,
-                                        sa->conv_name,
-                                        rd_count,
-                                        rd,
-                                        zm->filter);
-      sa->zm_pos = zm->next;
+      /* great, done with the monitors, unpack (again) for refresh_block 
operation */
+      sa->rd_set_pos++;
+      refresh_block ((sa->rd_set_pos == sa->rd_set_count) ? sa->nc : NULL,
+                     NULL,
+                     sa->rid,
+                     &sa->private_key,
+                     conv_name,
+                     rd_count,
+                     rd);
+      GNUNET_free (conv_name);
     }
-    /* great, done with the monitors, unpack (again) for refresh_block 
operation */
-    refresh_block (sa->nc,
-                   NULL,
-                   sa->rid,
-                   &sa->private_key,
-                   sa->conv_name,
-                   rd_count,
-                   rd);
   }
   GNUNET_SERVICE_client_continue (sa->nc->client);
   free_store_activity (sa);
+  return;
 }
 
 
@@ -1672,7 +1691,6 @@ static enum GNUNET_GenericReturnValue
 store_record_set (struct NamestoreClient *nc,
                   const struct GNUNET_IDENTITY_PrivateKey *private_key,
                   const struct RecordSet *rd_set,
-                  char **conv_name,
                   ssize_t *len,
                   char **emsg)
 {
@@ -1680,6 +1698,7 @@ store_record_set (struct NamestoreClient *nc,
   size_t rd_ser_len;
   const char *name_tmp;
   const char *rd_ser;
+  char *conv_name;
   unsigned int rd_count;
   int res;
   struct GNUNET_TIME_Absolute existing_block_exp;
@@ -1697,8 +1716,8 @@ store_record_set (struct NamestoreClient *nc,
     struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)];
 
     /* Extracting and converting private key */
-    *conv_name = GNUNET_GNSRECORD_string_normalize (name_tmp);
-    if (NULL == *conv_name)
+    conv_name = GNUNET_GNSRECORD_string_normalize (name_tmp);
+    if (NULL == conv_name)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Error normalizing name `%s'\n",
@@ -1708,12 +1727,12 @@ store_record_set (struct NamestoreClient *nc,
     }
 
     /* Check name for validity */
-    if (GNUNET_OK != GNUNET_GNSRECORD_label_check (*conv_name, emsg))
+    if (GNUNET_OK != GNUNET_GNSRECORD_label_check (conv_name, emsg))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Label invalid: `%s'\n",
                   *emsg);
-      GNUNET_free (*conv_name);
+      GNUNET_free (conv_name);
       return -1;
     }
 
@@ -1722,7 +1741,7 @@ store_record_set (struct NamestoreClient *nc,
                                               rd))
     {
       *emsg = GNUNET_strdup (_ ("Error deserializing records."));
-      GNUNET_free (*conv_name);
+      GNUNET_free (conv_name);
       return GNUNET_SYSERR;
     }
 
@@ -1733,10 +1752,10 @@ store_record_set (struct NamestoreClient *nc,
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Creating %u records for name `%s'\n",
                 (unsigned int) rd_count,
-                *conv_name);
+                conv_name);
     if ((GNUNET_NO == nc->GSN_database->lookup_records (nc->GSN_database->cls,
                                                         private_key,
-                                                        *conv_name,
+                                                        conv_name,
                                                         &
                                                         get_block_exp_existing,
                                                         &existing_block_exp))
@@ -1746,7 +1765,7 @@ store_record_set (struct NamestoreClient *nc,
       /* This name does not exist, so cannot be removed */
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Name `%s' does not exist, no deletion required\n",
-                  *conv_name);
+                  conv_name);
       res = GNUNET_NO;
     }
     else
@@ -1771,11 +1790,11 @@ store_record_set (struct NamestoreClient *nc,
       {
         rd_clean[rd_clean_off] = rd[i];
 
-        if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, *conv_name)) ||
+        if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) ||
             (GNUNET_GNSRECORD_TYPE_NICK != rd[i].record_type))
           rd_clean_off++;
 
-        if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, *conv_name)) &&
+        if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) &&
             (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type))
         {
           // FIXME: In case this is an uncommited transaction,
@@ -1785,7 +1804,7 @@ store_record_set (struct NamestoreClient *nc,
         }
       }
       if (GNUNET_OK !=
-          GNUNET_GNSRECORD_normalize_record_set (*conv_name,
+          GNUNET_GNSRECORD_normalize_record_set (conv_name,
                                                  rd_clean,
                                                  rd_clean_off,
                                                  rd_nf,
@@ -1794,7 +1813,7 @@ store_record_set (struct NamestoreClient *nc,
                                                  GNUNET_GNSRECORD_FILTER_NONE,
                                                  emsg))
       {
-        GNUNET_free (*conv_name);
+        GNUNET_free (conv_name);
         return GNUNET_SYSERR;
       }
       /*
@@ -1814,7 +1833,7 @@ store_record_set (struct NamestoreClient *nc,
         rd_nf[rd_nf_count].flags = GNUNET_GNSRECORD_RF_PRIVATE;
         rd_nf_count++;
       }
-      if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, *conv_name)) &&
+      if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) &&
           (GNUNET_NO == have_nick))
       {
         /* remove nick record from cache, in case we have one there */
@@ -1824,7 +1843,7 @@ store_record_set (struct NamestoreClient *nc,
       }
       res = nc->GSN_database->store_records (nc->GSN_database->cls,
                                              private_key,
-                                             *conv_name,
+                                             conv_name,
                                              rd_nf_count,
                                              rd_nf);
     }
@@ -1833,10 +1852,11 @@ store_record_set (struct NamestoreClient *nc,
     {
       /* store not successful, no need to tell monitors */
       *emsg = GNUNET_strdup (_ ("Store failed"));
-      GNUNET_free (*conv_name);
+      GNUNET_free (conv_name);
       return GNUNET_SYSERR;
     }
   }
+  GNUNET_free (conv_name);
   return res;
 }
 
@@ -1855,7 +1875,6 @@ handle_record_store (void *cls, const struct 
RecordStoreMessage *rp_msg)
   uint32_t rid;
   uint16_t rd_set_count;
   const char *name_tmp;
-  char *conv_name;
   char *emsg = NULL;
   const char *buf;
   const char *rd_ser;
@@ -1866,6 +1885,7 @@ handle_record_store (void *cls, const struct 
RecordStoreMessage *rp_msg)
   struct GNUNET_TIME_Absolute existing_block_exp;
   struct GNUNET_TIME_Absolute new_block_exp;
   enum GNUNET_GenericReturnValue res;
+  int blocked = GNUNET_NO;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received NAMESTORE_RECORD_STORE message\n");
@@ -1878,7 +1898,7 @@ handle_record_store (void *cls, const struct 
RecordStoreMessage *rp_msg)
   {
     rs = (struct RecordSet *) buf;
     res = store_record_set (nc, &rp_msg->private_key,
-                            rs, &conv_name, &read, &emsg);
+                            rs, &read, &emsg);
     if (GNUNET_OK != res)
     {
       send_store_response (nc, res, emsg,
@@ -1887,19 +1907,23 @@ handle_record_store (void *cls, const struct 
RecordStoreMessage *rp_msg)
       GNUNET_SERVICE_client_continue (nc->client);
       return;
     }
-    sa = GNUNET_malloc (sizeof(struct StoreActivity) + read);
-    GNUNET_CONTAINER_DLL_insert (sa_head, sa_tail, sa);
-    sa->nc = nc;
-    sa->rs = (const struct RecordSet *) &sa[1];
-    GNUNET_memcpy (&sa[1], rs, read);
-    sa->rid = rid;
-    sa->private_key = rp_msg->private_key;
-    sa->zm_pos = monitor_head;
-    sa->conv_name = conv_name;
-    sa->uncommited = nc->in_transaction;
-    continue_store_activity (sa);
     buf += read;
   }
+  sa = GNUNET_malloc (sizeof(struct StoreActivity)
+                      + ntohs (rp_msg->gns_header.header.size)
+                      - sizeof (*rp_msg));
+  GNUNET_CONTAINER_DLL_insert (sa_head, sa_tail, sa);
+  sa->nc = nc;
+  sa->rs = (struct RecordSet *) &sa[1];
+  sa->rd_set_count = rd_set_count;
+  GNUNET_memcpy (&sa[1], (char *) &rp_msg[1],
+                 ntohs (rp_msg->gns_header.header.size) - sizeof (*rp_msg));
+  sa->rid = rid;
+  sa->rd_set_pos = 0;
+  sa->private_key = rp_msg->private_key;
+  sa->zm_pos = monitor_head;
+  sa->uncommited = nc->in_transaction;
+  continue_store_activity (sa);
 }
 
 /**
@@ -1921,6 +1945,8 @@ handle_tx_control (void *cls, const struct 
TxControlMessage *tx_msg)
   char *err_tmp;
   size_t err_len;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TX_CONTROL message\n");
+
   switch (ntohs (tx_msg->control))
   {
   case GNUNET_NAMESTORE_TX_BEGIN:
@@ -1962,6 +1988,7 @@ handle_tx_control (void *cls, const struct 
TxControlMessage *tx_msg)
           sa = sa->next;
           continue;
         }
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Discarding uncommited 
StoreActivity\n");
         sn = sa->next;
         free_store_activity (sa);
         sa = sn;
@@ -2365,6 +2392,7 @@ static void
 monitor_unblock (struct ZoneMonitor *zm)
 {
   struct StoreActivity *sa = sa_head;
+  int blocked = GNUNET_NO;
 
   while ((NULL != sa) && (zm->limit > zm->iteration_cnt))
   {
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index f9ed2b620..fd348a057 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -1148,7 +1148,7 @@ GNUNET_NAMESTORE_records_store2 (
       GNUNET_break (0);
       return NULL;
     }
-    rd_set_len = sizeof (struct RecordSet) + name_len + rd_ser_len[i];
+    rd_set_len += sizeof (struct RecordSet) + name_len + rd_ser_len[i];
   }
   rid = get_op_id (h);
   qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
diff --git a/src/namestore/plugin_rest_namestore.c 
b/src/namestore/plugin_rest_namestore.c
index b9c32e087..0eef1aaeb 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -721,6 +721,38 @@ ns_lookup_cb (void *cls,
   }
 }
 
+/**
+ * Import callback
+ *
+ * @param cls the `struct RequestHandle`
+ * @param success the success indicating integer, GNUNET_OK on success
+ * @param emsg the error message (can be NULL)
+ */
+static void
+import_finished_cb (void *cls, int32_t success, const char *emsg)
+{
+  struct RequestHandle *handle = cls;
+  struct MHD_Response *resp;
+
+  handle->ns_qe = NULL;
+  if (GNUNET_YES != success)
+  {
+    if (NULL != emsg)
+    {
+      handle->emsg = GNUNET_strdup (emsg);
+      GNUNET_SCHEDULER_add_now (&do_error, handle);
+      return;
+    }
+    handle->emsg = GNUNET_strdup ("Error importing records");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  resp = GNUNET_REST_create_response (NULL);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
+  GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
+}
+
+
 /**
  * Handle namestore POST import
  *
@@ -728,19 +760,38 @@ ns_lookup_cb (void *cls,
  * @param url the url
  * @param cls the RequestHandle
  */
-/*void
+void
 namestore_import (struct GNUNET_REST_RequestHandle *con_handle,
-                         const char *url,
-                         void *cls)
+                  const char *url,
+                  void *cls)
 {
   struct RequestHandle *handle = cls;
   struct EgoEntry *ego_entry;
-  struct GNUNET_GNSRECORD_Data *rd_import;
   char *egoname;
   json_t *data_js;
   json_error_t err;
 
   char term_data[handle->rest_handle->data_size + 1];
+  // set zone to name if given
+  if (strlen (GNUNET_REST_API_NS_NAMESTORE) + 1 >= strlen (handle->url))
+  {
+    handle->response_code = MHD_HTTP_NOT_FOUND;
+    handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  ego_entry = NULL;
+
+  egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
+  ego_entry = get_egoentry_namestore (handle, egoname);
+
+  if (NULL == ego_entry)
+  {
+    handle->response_code = MHD_HTTP_NOT_FOUND;
+    handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
 
   if (0 >= handle->rest_handle->data_size)
   {
@@ -760,66 +811,50 @@ namestore_import (struct GNUNET_REST_RequestHandle 
*con_handle,
     GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
-  if (!json_is_array (data_js))
-  {
-    handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    json_decref (data_js);
-    return;
-  }
-  size_t num_records = json_array_size (data_js);
-  rd_import = GNUNET_malloc (sizeof (*rd_import) * json_array_size (data_js));
-  for (int i = 0; i < num_records)
-  struct GNUNET_JSON_Specification gnsspec[] =
-  { GNUNET_GNSRECORD_JSON_spec_gnsrecord (&handle->rd, &handle->rd_count,
-                                &handle->record_name),
-    GNUNET_JSON_spec_end () };
-  if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL))
-  {
-    handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    json_decref (data_js);
-    return;
-  }
-  GNUNET_JSON_parse_free (gnsspec);
-  if (0 >= strlen (handle->record_name))
+  if (! json_is_array (data_js))
   {
-    handle->response_code = MHD_HTTP_BAD_REQUEST;
     handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA);
     GNUNET_SCHEDULER_add_now (&do_error, handle);
     json_decref (data_js);
     return;
   }
-  json_decref (data_js);
-
-  egoname = NULL;
-  ego_entry = NULL;
-
-  // set zone to name if given
-  if (strlen (GNUNET_REST_API_NS_NAMESTORE) + 1 >= strlen (handle->url))
-  {
-    handle->response_code = MHD_HTTP_NOT_FOUND;
-    handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
+  size_t rd_set_count = json_array_size (data_js);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Got record set of size %d\n", rd_set_count);
+  const struct GNUNET_GNSRECORD_Data *a_rd[rd_set_count];
+  unsigned int a_rd_count[rd_set_count];
+  char *a_label[rd_set_count];
+  size_t index;
+  json_t *value;
+  json_array_foreach (data_js, index, value) {
+    {
+      struct GNUNET_GNSRECORD_Data *rd;
+      struct GNUNET_JSON_Specification gnsspec[] =
+      { GNUNET_GNSRECORD_JSON_spec_gnsrecord (&rd, &a_rd_count[index],
+                                              &a_label[index]),
+        GNUNET_JSON_spec_end () };
+      if (GNUNET_OK != GNUNET_JSON_parse (value, gnsspec, NULL, NULL))
+      {
+        handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA);
+        GNUNET_SCHEDULER_add_now (&do_error, handle);
+        json_decref (data_js);
+        return;
+      }
+      a_rd[index] = rd;
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Parsed record set for name %s\n", a_label[index]);
+    }
   }
-  egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
-  ego_entry = get_egoentry_namestore (handle, egoname);
+  //json_decref (data_js);
 
-  if (NULL == ego_entry)
-  {
-    handle->response_code = MHD_HTTP_NOT_FOUND;
-    handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
   handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
-  handle->ns_qe = GNUNET_NAMESTORE_records_lookup (ns_handle,
+  handle->ns_qe = GNUNET_NAMESTORE_records_store2 (ns_handle,
                                                    handle->zone_pkey,
-                                                   handle->record_name,
-                                                   &ns_lookup_error_cb,
-                                                   handle,
-                                                   &ns_lookup_cb,
+                                                   rd_set_count,
+                                                   (const char**) a_label,
+                                                   a_rd_count,
+                                                   a_rd,
+                                                   &import_finished_cb,
                                                    handle);
   if (NULL == handle->ns_qe)
   {
@@ -828,7 +863,6 @@ namestore_import (struct GNUNET_REST_RequestHandle 
*con_handle,
     return;
   }
 }
-*/
 
 /**
  * Handle namestore POST/PUT request
@@ -864,7 +898,7 @@ namestore_add_or_update (struct GNUNET_REST_RequestHandle 
*con_handle,
   data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
   struct GNUNET_JSON_Specification gnsspec[] =
   { GNUNET_GNSRECORD_JSON_spec_gnsrecord (&handle->rd, &handle->rd_count,
-                                &handle->record_name),
+                                          &handle->record_name),
     GNUNET_JSON_spec_end () };
   if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL))
   {
@@ -1040,7 +1074,8 @@ options_cont (struct GNUNET_REST_RequestHandle 
*con_handle,
 
   // independent of path return all options
   resp = GNUNET_REST_create_response (NULL);
-  MHD_add_response_header (resp, "Access-Control-Allow-Methods", 
allow_methods);
+  MHD_add_response_header (resp, "Access-Control-Allow-Methods",
+                           allow_methods);
   handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
   GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
   return;
@@ -1115,7 +1150,7 @@ list_ego (void *cls,
         break;
     }
     if (NULL == ego_entry)
-      return; /* Not found */
+      return;   /* Not found */
 
     GNUNET_CONTAINER_DLL_remove (ego_head,
                                  ego_tail,
@@ -1149,9 +1184,11 @@ rest_process_request (struct GNUNET_REST_RequestHandle 
*rest_handle,
   struct GNUNET_REST_RequestHandlerError err;
   static const struct GNUNET_REST_RequestHandler handlers[] =
   { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_get },
-    { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_add },
+    //{ MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_add },
+    { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_import },
     { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, &namestore_update },
-    { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete 
},
+    { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE,
+      &namestore_delete },
     { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont },
     GNUNET_REST_HANDLER_END };
 
@@ -1171,7 +1208,8 @@ rest_process_request (struct GNUNET_REST_RequestHandle 
*rest_handle,
                                handle);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
   if (GNUNET_NO ==
-      GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
+      GNUNET_REST_handle_request (handle->rest_handle, handlers, &err,
+                                  handle))
   {
     cleanup_handle (handle);
     return GNUNET_NO;
@@ -1196,7 +1234,7 @@ libgnunet_plugin_rest_namestore_init (void *cls)
 
   cfg = cls;
   if (NULL != plugin.cfg)
-    return NULL; /* can only initialize once! */
+    return NULL;   /* can only initialize once! */
   memset (&plugin, 0, sizeof(struct Plugin));
   plugin.cfg = cfg;
   api = GNUNET_new (struct GNUNET_REST_Plugin);
@@ -1214,7 +1252,8 @@ libgnunet_plugin_rest_namestore_init (void *cls)
   ns_handle = GNUNET_NAMESTORE_connect (cfg);
   identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Namestore REST API initialized\n"));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ (
+                "Namestore REST API initialized\n"));
   return api;
 }
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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