gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: NAMESTORE: Add records_lookup2 API for f


From: gnunet
Subject: [gnunet] branch master updated: NAMESTORE: Add records_lookup2 API for filtering and update REST API with filter functionality
Date: Wed, 19 Oct 2022 08:12:03 +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 1cb34e96b NAMESTORE: Add records_lookup2 API for filtering and update 
REST API with filter functionality
     new c0e8a01c7 Merge branch 'master' of git+ssh://git.gnunet.org/gnunet
1cb34e96b is described below

commit 1cb34e96bc939b77f1c2461c5ce85b5f138e9ae7
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Wed Oct 19 15:10:07 2022 +0900

    NAMESTORE: Add records_lookup2 API for filtering and update REST API with 
filter functionality
---
 src/include/gnunet_namestore_service.h   |  28 ++++++++
 src/namestore/gnunet-service-namestore.c |  41 +++++++++---
 src/namestore/namestore.h                |   5 ++
 src/namestore/namestore_api.c            |  26 +++++++-
 src/namestore/plugin_rest_namestore.c    | 107 ++++++++++++++++++++++---------
 5 files changed, 165 insertions(+), 42 deletions(-)

diff --git a/src/include/gnunet_namestore_service.h 
b/src/include/gnunet_namestore_service.h
index 998eb19d0..f08c4746b 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -290,6 +290,33 @@ GNUNET_NAMESTORE_records_lookup (struct 
GNUNET_NAMESTORE_Handle *h,
                                  GNUNET_NAMESTORE_RecordMonitor rm,
                                  void *rm_cls);
 
+/**
+ * Lookup an item in the namestore with GNSRECORD filter.
+ *
+ * @param h handle to the namestore
+ * @param pkey private key of the zone
+ * @param label name that is being mapped
+ * @param error_cb function to call on error (i.e. disconnect)
+ *        the handle is afterwards invalid
+ * @param error_cb_cls closure for @a error_cb
+ * @param rm function to call with the result (with 0 records if we don't have 
that label);
+ *        the handle is afterwards invalid
+ * @param rm_cls closure for @a rm
+ *  @param filter the record set filter to use
+ * @return handle to abort the request
+ */
+struct GNUNET_NAMESTORE_QueueEntry *
+GNUNET_NAMESTORE_records_lookup2 (struct GNUNET_NAMESTORE_Handle *h,
+                                  const struct
+                                  GNUNET_IDENTITY_PrivateKey *pkey,
+                                  const char *label,
+                                  GNUNET_SCHEDULER_TaskCallback error_cb,
+                                  void *error_cb_cls,
+                                  GNUNET_NAMESTORE_RecordMonitor rm,
+                                  void *rm_cls,
+                                  enum GNUNET_GNSRECORD_Filter filter);
+
+
 
 /**
  * Look for an existing PKEY delegation record for a given public key.
@@ -393,6 +420,7 @@ GNUNET_NAMESTORE_zone_iteration_start (struct 
GNUNET_NAMESTORE_Handle *h,
  * @param finish_cb function to call on completion
  *        the handle is afterwards invalid
  * @param finish_cb_cls closure for @a finish_cb
+ * @param filter the record set filter to use
  * @return an iterator handle to use for iteration
  */
 struct GNUNET_NAMESTORE_ZoneIterator *
diff --git a/src/namestore/gnunet-service-namestore.c 
b/src/namestore/gnunet-service-namestore.c
index b2cc826fd..c164fed3a 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1272,32 +1272,37 @@ client_connect_cb (void *cls,
 struct RecordLookupContext
 {
   /**
-   * FIXME.
+   * The label to look up.
    */
   const char *label;
 
   /**
-   * FIXME.
+   * The record result.
    */
   char *res_rd;
 
   /**
-   * FIXME.
+   * The nick for the zone.
    */
   struct GNUNET_GNSRECORD_Data *nick;
 
   /**
-   * FIXME.
+   * If a record set was found or not.
    */
   int found;
 
   /**
-   * FIXME.
+   * The record filter
+   */
+  enum GNUNET_GNSRECORD_Filter filter;
+
+  /**
+   * The number of found records.
    */
   unsigned int res_rd_count;
 
   /**
-   * FIXME.
+   * The length of the serialized records.
    */
   ssize_t rd_ser_len;
 };
@@ -1320,16 +1325,35 @@ lookup_it (void *cls,
            uint64_t seq,
            const struct GNUNET_IDENTITY_PrivateKey *private_key,
            const char *label,
-           unsigned int rd_count,
-           const struct GNUNET_GNSRECORD_Data *rd)
+           unsigned int rd_count_nf,
+           const struct GNUNET_GNSRECORD_Data *rd_nf)
 {
   struct RecordLookupContext *rlc = cls;
+  struct GNUNET_GNSRECORD_Data rd[rd_count_nf];
+  struct GNUNET_TIME_Absolute block_exp;
+  unsigned int rd_count = 0;
+  char *emsg;
 
   (void) private_key;
   GNUNET_assert (0 != seq);
   if (0 != strcmp (label, rlc->label))
     return;
   rlc->found = GNUNET_YES;
+
+  if (GNUNET_OK != GNUNET_GNSRECORD_normalize_record_set (rlc->label,
+                                                          rd_nf,
+                                                          rd_count_nf,
+                                                          rd,
+                                                          &rd_count,
+                                                          &block_exp,
+                                                          rlc->filter,
+                                                          &emsg))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg);
+    GNUNET_free (emsg);
+    GNUNET_assert (0);
+  }
+
   if (0 == rd_count)
   {
     rlc->rd_ser_len = 0;
@@ -1468,6 +1492,7 @@ handle_record_lookup (void *cls, const struct 
LabelLookupMessage *ll_msg)
   }
   name_len = strlen (conv_name) + 1;
   rlc.label = conv_name;
+  rlc.filter = ntohs (ll_msg->filter);
   rlc.found = GNUNET_NO;
   rlc.res_rd_count = 0;
   rlc.res_rd = NULL;
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index d7b6fd13e..ea35269a4 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -157,6 +157,11 @@ struct LabelLookupMessage
    */
   uint32_t is_edit_request GNUNET_PACKED;
 
+  /**
+   * The record filter
+   */
+  uint16_t filter;
+
   /**
    * The private key of the zone to look up in
    */
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index cf2247d18..f92e6ef41 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -1234,7 +1234,8 @@ records_lookup (
   void *error_cb_cls,
   GNUNET_NAMESTORE_RecordMonitor rm,
   void *rm_cls,
-  int is_edit_request)
+  int is_edit_request,
+  enum GNUNET_GNSRECORD_Filter filter)
 {
   struct GNUNET_NAMESTORE_QueueEntry *qe;
   struct GNUNET_MQ_Envelope *env;
@@ -1263,6 +1264,7 @@ records_lookup (
   msg->zone = *pkey;
   msg->is_edit_request = htonl (is_edit_request);
   msg->label_len = htonl (label_len);
+  msg->filter = htons (filter);
   GNUNET_memcpy (&msg[1], label, label_len);
   if (NULL == h->mq)
     qe->env = env;
@@ -1283,10 +1285,28 @@ GNUNET_NAMESTORE_records_lookup (
 {
   return records_lookup (h, pkey, label,
                          error_cb, error_cb_cls,
-                         rm, rm_cls, GNUNET_NO);
+                         rm, rm_cls, GNUNET_NO, GNUNET_GNSRECORD_FILTER_NONE);
 
 }
 
+struct GNUNET_NAMESTORE_QueueEntry *
+GNUNET_NAMESTORE_records_lookup2 (
+  struct GNUNET_NAMESTORE_Handle *h,
+  const struct GNUNET_IDENTITY_PrivateKey *pkey,
+  const char *label,
+  GNUNET_SCHEDULER_TaskCallback error_cb,
+  void *error_cb_cls,
+  GNUNET_NAMESTORE_RecordMonitor rm,
+  void *rm_cls,
+  enum GNUNET_GNSRECORD_Filter filter)
+{
+  return records_lookup (h, pkey, label,
+                         error_cb, error_cb_cls,
+                         rm, rm_cls, GNUNET_NO, filter);
+
+}
+
+
 struct GNUNET_NAMESTORE_QueueEntry *
 GNUNET_NAMESTORE_records_edit (
   struct GNUNET_NAMESTORE_Handle *h,
@@ -1299,7 +1319,7 @@ GNUNET_NAMESTORE_records_edit (
 {
   return records_lookup (h, pkey, label,
                          error_cb, error_cb_cls,
-                         rm, rm_cls, GNUNET_YES);
+                         rm, rm_cls, GNUNET_YES, GNUNET_GNSRECORD_FILTER_NONE);
 }
 
 struct GNUNET_NAMESTORE_QueueEntry *
diff --git a/src/namestore/plugin_rest_namestore.c 
b/src/namestore/plugin_rest_namestore.c
index 5a5fdb9a8..fcc6068e8 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -52,7 +52,12 @@
 /**
  * Error message No identity found
  */
-#define GNUNET_REST_IDENTITY_NOT_FOUND "No identity found"
+#define GNUNET_REST_IDENTITY_NOT_FOUND "Zone not found"
+
+/**
+ * Error message No record found
+ */
+#define GNUNET_REST_RECORD_NOT_FOUND "Record not found"
 
 
 /**
@@ -521,8 +526,12 @@ namestore_list_finished (void *cls)
   handle->list_it = NULL;
 
   if (NULL == handle->resp_object)
-    handle->resp_object = json_array ();
-
+  {
+    handle->response_code = MHD_HTTP_NOT_FOUND;
+    handle->emsg = GNUNET_strdup (GNUNET_REST_RECORD_NOT_FOUND);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
   result_str = json_dumps (handle->resp_object, 0);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
   resp = GNUNET_REST_create_response (result_str);
@@ -545,7 +554,8 @@ namestore_list_iteration (void *cls,
                           const struct GNUNET_IDENTITY_PrivateKey *zone_key,
                           const char *rname,
                           unsigned int rd_len,
-                          const struct GNUNET_GNSRECORD_Data *rd)
+                          const struct GNUNET_GNSRECORD_Data *rd,
+                          struct GNUNET_TIME_Absolute expiry)
 {
   struct RequestHandle *handle = cls;
   struct GNUNET_GNSRECORD_Data rd_filtered[rd_len];
@@ -553,8 +563,13 @@ namestore_list_iteration (void *cls,
   int i = 0;
   int j = 0;
 
-  if (NULL == handle->resp_object)
-    handle->resp_object = json_array ();
+  if (rd_len == 0)
+  {
+    /** skip **/
+    GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1);
+    return;
+  }
+
   for (i = 0; i < rd_len; i++)
   {
     if ((GNUNET_GNSRECORD_TYPE_ANY != handle->record_type) &&
@@ -567,6 +582,8 @@ namestore_list_iteration (void *cls,
   /** Only add if not empty **/
   if (j > 0)
   {
+    if (NULL == handle->resp_object)
+      handle->resp_object = json_array ();
     record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (rname,
                                                        rd_filtered,
                                                        j);
@@ -600,13 +617,10 @@ ns_get_lookup_cb (void *cls,
 {
   struct RequestHandle *handle = cls;
   struct GNUNET_GNSRECORD_Data rd_filtered[rd_len];
-  json_t *record_obj;
   int i = 0;
   int j = 0;
 
   handle->ns_qe = NULL;
-  if (NULL == handle->resp_object)
-    handle->resp_object = json_array ();
   for (i = 0; i < rd_len; i++)
   {
     if ((GNUNET_GNSRECORD_TYPE_ANY != handle->record_type) &&
@@ -616,14 +630,17 @@ ns_get_lookup_cb (void *cls,
     rd_filtered[j].data = rd[i].data;
     j++;
   }
-  /** Only add if not empty **/
-  if (j > 0)
+  /** Return 404 if no set was found **/
+  if (j == 0)
   {
-    record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (label,
-                                                       rd_filtered,
-                                                       j);
-    json_array_append_new (handle->resp_object, record_obj);
+    handle->response_code = MHD_HTTP_NOT_FOUND;
+    handle->emsg = GNUNET_strdup (GNUNET_REST_RECORD_NOT_FOUND);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
   }
+  handle->resp_object = GNUNET_GNSRECORD_JSON_from_gnsrecord (label,
+                                                              rd_filtered,
+                                                              j);
   GNUNET_SCHEDULER_add_now (&namestore_list_finished, handle);
 }
 
@@ -643,9 +660,11 @@ namestore_get (struct GNUNET_REST_RequestHandle 
*con_handle,
   struct RequestHandle *handle = cls;
   struct EgoEntry *ego_entry;
   struct GNUNET_HashCode key;
+  enum GNUNET_GNSRECORD_Filter filter_flags;
   char *egoname;
   char *labelname;
   char *typename;
+  char *boolstring;
 
   egoname = NULL;
   ego_entry = NULL;
@@ -679,19 +698,44 @@ namestore_get (struct GNUNET_REST_RequestHandle 
*con_handle,
     if (NULL != typename)
       handle->record_type = GNUNET_GNSRECORD_typename_to_number (typename);
   }
+  GNUNET_CRYPTO_hash ("omit_private", strlen ("omit_private"), &key);
+  filter_flags = GNUNET_GNSRECORD_FILTER_NONE;
+  if (GNUNET_YES ==
+      GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, &key))
+  {
+    boolstring = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
+                                                    &key);
+    if ((0 == strcmp (boolstring, "1")) ||
+        (0 == strcmp (boolstring, "yes")) ||
+        (0 == strcmp (boolstring, "true")))
+      filter_flags = GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE;
+  }
+  GNUNET_CRYPTO_hash ("include_maintenance", strlen ("include_maintenance"),
+                      &key);
+  if (GNUNET_YES ==
+      GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, &key))
+  {
+    boolstring = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
+                                                    &key);
+    if ((0 == strcmp (boolstring, "1")) ||
+        (0 == strcmp (boolstring, "yes")) ||
+        (0 == strcmp (boolstring, "true")))
+      filter_flags |= GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE;
+  }
   labelname = &egoname[strlen (ego_entry->identifier)];
-  // set zone to name if given
   if (1 >= strlen (labelname))
   {
+    /* Iterate over all records */
     handle->list_it =
-      GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
-                                             handle->zone_pkey,
-                                             &namestore_iteration_error,
-                                             handle,
-                                             &namestore_list_iteration,
-                                             handle,
-                                             &namestore_list_finished,
-                                             handle);
+      GNUNET_NAMESTORE_zone_iteration_start2 (ns_handle,
+                                              handle->zone_pkey,
+                                              &namestore_iteration_error,
+                                              handle,
+                                              &namestore_list_iteration,
+                                              handle,
+                                              &namestore_list_finished,
+                                              handle,
+                                              filter_flags);
     if (NULL == handle->list_it)
     {
       handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED);
@@ -701,13 +745,14 @@ namestore_get (struct GNUNET_REST_RequestHandle 
*con_handle,
     return;
   }
   handle->record_name = GNUNET_strdup (labelname + 1);
-  handle->ns_qe = GNUNET_NAMESTORE_records_lookup (ns_handle,
-                                                   handle->zone_pkey,
-                                                   handle->record_name,
-                                                   &ns_lookup_error_cb,
-                                                   handle,
-                                                   &ns_get_lookup_cb,
-                                                   handle);
+  handle->ns_qe = GNUNET_NAMESTORE_records_lookup2 (ns_handle,
+                                                    handle->zone_pkey,
+                                                    handle->record_name,
+                                                    &ns_lookup_error_cb,
+                                                    handle,
+                                                    &ns_get_lookup_cb,
+                                                    handle,
+                                                    filter_flags);
   if (NULL == handle->ns_qe)
   {
     handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED);

-- 
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]