gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] 10/30: bugfixes; CLI improvements


From: gnunet
Subject: [gnunet] 10/30: bugfixes; CLI improvements
Date: Thu, 13 Feb 2020 22:31:10 +0100

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

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

commit b1b1aed7e18e206da30f0db3635363446103f67c
Author: Schanzenbach, Martin <address@hidden>
AuthorDate: Fri Feb 7 15:36:43 2020 +0100

    bugfixes; CLI improvements
---
 src/reclaim-attribute/reclaim_attribute.c    |  2 +
 src/reclaim/gnunet-reclaim.c                 | 57 +++++++++++++++++++++-------
 src/reclaim/gnunet-service-reclaim.c         |  8 +++-
 src/reclaim/gnunet-service-reclaim_tickets.c | 45 ++++++++++++++--------
 src/reclaim/gnunet-service-reclaim_tickets.h |  3 +-
 src/reclaim/reclaim_api.c                    |  7 +++-
 6 files changed, 89 insertions(+), 33 deletions(-)

diff --git a/src/reclaim-attribute/reclaim_attribute.c 
b/src/reclaim-attribute/reclaim_attribute.c
index 0e3fae849..12f124c15 100644
--- a/src/reclaim-attribute/reclaim_attribute.c
+++ b/src/reclaim-attribute/reclaim_attribute.c
@@ -470,6 +470,7 @@ GNUNET_RECLAIM_attribute_serialize (
   attr_ser->attribute_type = htons (attr->type);
   attr_ser->attribute_flag = htonl (attr->flag);
   attr_ser->attribute_id = attr->id;
+  attr_ser->attestation_id = attr->attestation;
   name_len = strlen (attr->name);
   attr_ser->name_len = htons (name_len);
   write_ptr = (char *) &attr_ser[1];
@@ -520,6 +521,7 @@ GNUNET_RECLAIM_attribute_deserialize (const char *data, 
size_t data_size)
   attr->type = ntohs (attr_ser->attribute_type);
   attr->flag = ntohl (attr_ser->attribute_flag);
   attr->id = attr_ser->attribute_id;
+  attr->attestation = attr_ser->attestation_id;
   attr->data_size = data_len;
 
   write_ptr = (char *) &attr[1];
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c
index 121f2b963..cb9a87e37 100644
--- a/src/reclaim/gnunet-reclaim.c
+++ b/src/reclaim/gnunet-reclaim.c
@@ -277,19 +277,43 @@ process_attrs (void *cls,
     ret = 1;
     return;
   }
-  value_str = GNUNET_RECLAIM_attribute_value_to_string (attr->type,
-                                                        attr->data,
-                                                        attr->data_size);
   attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type);
   id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id));
+  value_str = NULL;
+  if (NULL == attest)
+  {
+    value_str = GNUNET_RECLAIM_attribute_value_to_string (attr->type,
+                                                          attr->data,
+                                                          attr->data_size);
+  }
+  else
+  {
+    struct GNUNET_RECLAIM_AttributeListEntry *ale;
+    struct GNUNET_RECLAIM_AttributeList *al
+      = GNUNET_RECLAIM_attestation_get_attributes (attest);
+
+    for (ale = al->list_head; NULL != ale; ale = ale->next)
+    {
+      if (0 != strncmp (attr->data, ale->attribute->name, attr->data_size))
+        continue;
+      value_str
+        = GNUNET_RECLAIM_attribute_value_to_string (ale->attribute->type,
+                                                    ale->attribute->
+                                                    data,
+                                                    ale->attribute->
+                                                    data_size);
+      break;
+    }
+  }
   fprintf (stdout,
            "Name: %s; Value: %s (%s); Flag %u; ID: %s %s\n",
            attr->name,
-           value_str,
+           (NULL != value_str) ? value_str : "???",
            attr_type,
            attr->flag,
            id,
-           (NULL == attest) ? "" : "ATTESTED");
+           (NULL == attest) ? "" : "(ATTESTED)");
+  GNUNET_free_non_null (value_str);
   GNUNET_free (id);
 }
 
@@ -556,22 +580,25 @@ iter_cb (void *cls,
     if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attr->attestation))
     {
       fprintf (stdout,
-               "Name: %s; Value: %s (%s); Flag %u; ID: %s\n",
+               "%s: ``%s'' (%s); ID: %s\n",
                attr->name,
                attr_str,
                attr_type,
-               attr->flag,
                id);
     }
     else
     {
+      char *attest_id =
+        GNUNET_STRINGS_data_to_string_alloc (&attr->attestation,
+                                             sizeof(attr->attestation));
       fprintf (stdout,
-               "Name: %s; Value: %s (%s); Flag %u; ID: %s\n",
+               "%s: <``%s'' in attestation %s> (%s); ID: %s\n",
                attr->name,
                attr_str,
+               attest_id,
                attr_type,
-               attr->flag,
                id);
+      GNUNET_free (attest_id);
 
     }
     GNUNET_free (id);
@@ -643,11 +670,10 @@ attest_iter_cb (void *cls,
     attest_type = GNUNET_RECLAIM_attestation_number_to_typename (attest->type);
     id = GNUNET_STRINGS_data_to_string_alloc (&attest->id, sizeof(attest->id));
     fprintf (stdout,
-             "Name: %s; Value: %s (%s); Flag %u; ID: %s\n",
+             "%s: ``%s'' (%s); ID: %s\n",
              attest->name,
              attest_str,
              attest_type,
-             attest->flag,
              id);
     if (NULL != attrs)
     {
@@ -655,9 +681,12 @@ attest_iter_cb (void *cls,
                "\t Attributes:\n");
       for (ale = attrs->list_head; NULL != ale; ale = ale->next)
       {
-        attr_str = GNUNET_RECLAIM_attribute_value_to_string 
(ale->attribute->type,
-                                                             
ale->attribute->data,
-                                                             
ale->attribute->data_size);
+        attr_str = GNUNET_RECLAIM_attribute_value_to_string (
+          ale->attribute->type,
+          ale->attribute->
+          data,
+          ale->attribute->
+          data_size);
 
         fprintf (stdout,
                  "\t %s: %s\n", ale->attribute->name, attr_str);
diff --git a/src/reclaim/gnunet-service-reclaim.c 
b/src/reclaim/gnunet-service-reclaim.c
index eb8727f8f..4521e5c81 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -842,6 +842,7 @@ static void
 consume_result_cb (void *cls,
                    const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
                    const struct GNUNET_RECLAIM_AttributeList *attrs,
+                   const struct GNUNET_RECLAIM_AttestationList *attests,
                    int32_t success,
                    const char *emsg)
 {
@@ -850,23 +851,28 @@ consume_result_cb (void *cls,
   struct GNUNET_MQ_Envelope *env;
   char *data_tmp;
   size_t attrs_len;
+  size_t attests_len;
 
   if (GNUNET_OK != success)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error consuming ticket: %s\n", emsg);
   }
   attrs_len = GNUNET_RECLAIM_attribute_list_serialize_get_size (attrs);
+  attests_len = GNUNET_RECLAIM_attestation_list_serialize_get_size (attests);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Sending CONSUME_TICKET_RESULT message\n");
   env = GNUNET_MQ_msg_extra (crm,
-                             attrs_len,
+                             attrs_len + attests_len,
                              
GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT);
   crm->id = htonl (cop->r_id);
   crm->attrs_len = htons (attrs_len);
+  crm->attestations_len = htons (attests_len);
   crm->identity = *identity;
   crm->result = htonl (success);
   data_tmp = (char *) &crm[1];
   GNUNET_RECLAIM_attribute_list_serialize (attrs, data_tmp);
+  data_tmp += attrs_len;
+  GNUNET_RECLAIM_attestation_list_serialize (attests, data_tmp);
   GNUNET_MQ_send (cop->client->mq, env);
   GNUNET_CONTAINER_DLL_remove (cop->client->consume_op_head,
                                cop->client->consume_op_tail,
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c 
b/src/reclaim/gnunet-service-reclaim_tickets.c
index 019ce51b0..205886c78 100644
--- a/src/reclaim/gnunet-service-reclaim_tickets.c
+++ b/src/reclaim/gnunet-service-reclaim_tickets.c
@@ -1058,7 +1058,8 @@ process_parallel_lookup_result (void *cls,
   if (NULL != cth->parallel_lookups_head)
     return; // Wait for more
   /* Else we are done */
-  cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL);
+  cth->cb (cth->cb_cls, &cth->ticket.identity,
+           cth->attrs, cth->attests, GNUNET_OK, NULL);
   cleanup_cth (cth);
 }
 
@@ -1087,7 +1088,7 @@ abort_parallel_lookups (void *cls)
     GNUNET_free (lu);
     lu = tmp;
   }
-  cth->cb (cth->cb_cls, NULL, NULL, GNUNET_SYSERR, "Aborted");
+  cth->cb (cth->cb_cls, NULL, NULL, NULL, GNUNET_SYSERR, "Aborted");
 }
 
 
@@ -1124,10 +1125,11 @@ lookup_authz_cb (void *cls,
 
   for (int i = 0; i < rd_count; i++)
   {
-    if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type)
+    if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) &&
+        (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF != rd[i].record_type))
       continue;
     lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute ref found %s\n", lbl);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ticket reference found %s\n", lbl);
     parallel_lookup = GNUNET_new (struct ParallelLookup);
     parallel_lookup->handle = cth;
     parallel_lookup->label = lbl;
@@ -1159,7 +1161,8 @@ lookup_authz_cb (void *cls,
   /**
    * No references found, return empty attribute list
    */
-  cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL);
+  cth->cb (cth->cb_cls, &cth->ticket.identity,
+           cth->attrs, cth->attests, GNUNET_OK, NULL);
   cleanup_cth (cth);
 }
 
@@ -1189,6 +1192,7 @@ RECLAIM_TICKETS_consume (const struct 
GNUNET_CRYPTO_EcdsaPrivateKey *id,
   cth->identity = *id;
   GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, &cth->identity_pub);
   cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
+  cth->attests = GNUNET_new (struct GNUNET_RECLAIM_AttestationList);
   cth->ticket = *ticket;
   cth->cb = cb;
   cth->cb_cls = cb_cls;
@@ -1282,18 +1286,15 @@ issue_ticket (struct TicketIssueHandle *ih)
   struct GNUNET_RECLAIM_AttributeListEntry *le;
   struct GNUNET_GNSRECORD_Data *attrs_record;
   char *label;
-  size_t list_len = 1;
   int i;
+  int attrs_count = 0;
 
   for (le = ih->attrs->list_head; NULL != le; le = le->next)
-  {
-    list_len++;
-    if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation))
-      list_len++;
-  }
+    attrs_count++;
 
+  //Worst case we have one attestation per attribute
   attrs_record =
-    GNUNET_malloc (list_len * sizeof(struct GNUNET_GNSRECORD_Data));
+    GNUNET_malloc (2 * attrs_count * sizeof(struct GNUNET_GNSRECORD_Data));
   i = 0;
   for (le = ih->attrs->list_head; NULL != le; le = le->next)
   {
@@ -1302,17 +1303,30 @@ issue_ticket (struct TicketIssueHandle *ih)
     attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us;
     attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF;
     attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
+    i++;
     if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation))
     {
-      i++;
+      int j;
+      for (j = 0; j < i; j++)
+      {
+        if (attrs_record[j].record_type
+            != GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF)
+          continue;
+        if (0 == memcmp (attrs_record[j].data,
+                         &le->attribute->attestation,
+                         sizeof (le->attribute->attestation)))
+          break;
+      }
+      if (j < i)
+        continue; // Skip as we have already added this attestation.
       attrs_record[i].data = &le->attribute->attestation;
       attrs_record[i].data_size = sizeof(le->attribute->attestation);
       attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us;
       attrs_record[i].record_type =
         GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF;
       attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
+      i++;
     }
-    i++;
   }
   attrs_record[i].data = &ih->ticket;
   attrs_record[i].data_size = sizeof(struct GNUNET_RECLAIM_Ticket);
@@ -1320,6 +1334,7 @@ issue_ticket (struct TicketIssueHandle *ih)
   attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET;
   attrs_record[i].flags =
     GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION | GNUNET_GNSRECORD_RF_PRIVATE;
+  i++;
 
   label =
     GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd,
@@ -1328,7 +1343,7 @@ issue_ticket (struct TicketIssueHandle *ih)
   ih->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
                                               &ih->identity,
                                               label,
-                                              list_len,
+                                              i,
                                               attrs_record,
                                               &store_ticket_issue_cont,
                                               ih);
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.h 
b/src/reclaim/gnunet-service-reclaim_tickets.h
index e8299718c..d6bc4a70a 100644
--- a/src/reclaim/gnunet-service-reclaim_tickets.h
+++ b/src/reclaim/gnunet-service-reclaim_tickets.h
@@ -136,7 +136,8 @@ typedef void (*RECLAIM_TICKETS_TicketResult) (
 typedef void (*RECLAIM_TICKETS_ConsumeCallback) (
   void *cls,
   const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
-  const struct GNUNET_RECLAIM_AttributeList *l,
+  const struct GNUNET_RECLAIM_AttributeList *attributes,
+  const struct GNUNET_RECLAIM_AttestationList *attestations,
   int32_t success,
   const char *emsg);
 
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c
index 5f52aa57b..54288866d 100644
--- a/src/reclaim/reclaim_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -561,10 +561,13 @@ check_consume_ticket_result (void *cls,
 {
   size_t msg_len;
   size_t attrs_len;
+  size_t attests_len;
 
   msg_len = ntohs (msg->header.size);
   attrs_len = ntohs (msg->attrs_len);
-  if (msg_len != sizeof(struct ConsumeTicketResultMessage) + attrs_len)
+  attests_len = ntohs (msg->attestations_len);
+  if (msg_len !=
+      sizeof(struct ConsumeTicketResultMessage) + attrs_len + attests_len)
   {
     GNUNET_break (0);
     return GNUNET_SYSERR;
@@ -628,7 +631,7 @@ handle_consume_ticket_result (void *cls,
             for (ale = attests->list_head; NULL != ale; ale = ale->next)
             {
               if (GNUNET_YES ==
-                  GNUNET_RECLAIM_id_is_equal (&le->attribute->id,
+                  GNUNET_RECLAIM_id_is_equal (&le->attribute->attestation,
                                               &ale->attestation->id))
               {
                 op->atr_cb (op->cls, &msg->identity,

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



reply via email to

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