From: Markus Voggenreiter Date: Thu, 31 Oct 2019 16:47:22 +0000 (+0100) Subject: Prepared Listing of References X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=32182e08d9bc27a836ab6a0a98547e86a9187e7e;p=oweals%2Fgnunet.git Prepared Listing of References --- diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 367f6fd80..8091fb367 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -3311,6 +3311,8 @@ extern "C" { */ #define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_DELETE 1500 +#define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT 1501 + /** * Type used to match 'all' message types. diff --git a/src/include/gnunet_reclaim_attribute_lib.h b/src/include/gnunet_reclaim_attribute_lib.h index cfdecae79..c761d20ed 100644 --- a/src/include/gnunet_reclaim_attribute_lib.h +++ b/src/include/gnunet_reclaim_attribute_lib.h @@ -76,9 +76,9 @@ struct GNUNET_RECLAIM_ATTRIBUTE_Claim uint32_t type; /** - * Version + * Flags */ - uint32_t version; + uint32_t flag; /** * The name of the attribute. Note "name" must never be individually * free'd diff --git a/src/include/gnunet_reclaim_service.h b/src/include/gnunet_reclaim_service.h index f839123e5..214cdba69 100644 --- a/src/include/gnunet_reclaim_service.h +++ b/src/include/gnunet_reclaim_service.h @@ -118,7 +118,8 @@ typedef void (*GNUNET_RECLAIM_ContinuationWithStatus) (void *cls, typedef void (*GNUNET_RECLAIM_AttributeResult) ( void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest); + const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, + const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference); /** diff --git a/src/reclaim-attribute/reclaim_attribute.c b/src/reclaim-attribute/reclaim_attribute.c index 0083ac53e..d958ba7f9 100644 --- a/src/reclaim-attribute/reclaim_attribute.c +++ b/src/reclaim-attribute/reclaim_attribute.c @@ -353,7 +353,7 @@ GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name, + strlen (attr_name_tmp) + 1 + data_size); attr->type = type; attr->data_size = data_size; - attr->version = 0; + attr->flag = 0; write_ptr = (char *) &attr[1]; GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1); attr->name = write_ptr; @@ -569,8 +569,8 @@ GNUNET_RECLAIM_ATTRIBUTE_list_dup ( le->claim->type, le->claim->data, le->claim->data_size); - result_le->claim->version = le->claim->version; result_le->claim->id = le->claim->id; + result_le->claim->flag = le->claim->flag; GNUNET_CONTAINER_DLL_insert (result->list_head, result->list_tail, result_le); @@ -635,7 +635,7 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize ( attr_ser = (struct Attribute *) result; attr_ser->attribute_type = htons (attr->type); - attr_ser->attribute_version = htonl (attr->version); + attr_ser->attribute_version = htonl (attr->flag); attr_ser->attribute_id = GNUNET_htonll (attr->id); name_len = strlen (attr->name); attr_ser->name_len = htons (name_len); @@ -685,7 +685,7 @@ GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size) attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + data_len + name_len + 1); attr->type = ntohs (attr_ser->attribute_type); - attr->version = ntohl (attr_ser->attribute_version); + attr->flag = ntohl (attr_ser->attribute_version); attr->id = GNUNET_ntohll (attr_ser->attribute_id); attr->data_size = data_len; diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c index ca77512d6..4d7a37c93 100644 --- a/src/reclaim/gnunet-reclaim.c +++ b/src/reclaim/gnunet-reclaim.c @@ -224,7 +224,8 @@ static void process_attrs (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest) + const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, + const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) { char *value_str; char *id; @@ -251,7 +252,7 @@ process_attrs (void *cls, attr->name, value_str, attr_type, - attr->version, + attr->flag, id); GNUNET_free (id); } @@ -437,7 +438,8 @@ static void iter_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest) + const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, + const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) { struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; char *attrs_tmp; @@ -472,7 +474,7 @@ iter_cb (void *cls, attr->type, attr->data, attr->data_size); - le->claim->version = attr->version; + le->claim->flag = attr->flag; le->claim->id = attr->id; GNUNET_CONTAINER_DLL_insert (attr_list->list_head, attr_list->list_tail, @@ -506,7 +508,7 @@ iter_cb (void *cls, attr->name, attr_str, attr_type, - attr->version, + attr->flag, id); GNUNET_free (id); } diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index fccb26a19..d552abb98 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c @@ -1452,26 +1452,19 @@ ticket_iter (void *cls, int has_changed = GNUNET_NO; for (int i = 0; i < rd_count; i++) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Next Zone Iteration %u and record type is %u\n", rd_count, - rd[i].record_type); if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE_REF != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_REF != rd[i].record_type)) continue; if (&adh->claim != NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Claim is existend: %u \n", adh->claim->id); if (0 != memcmp (rd[i].data, &adh->claim->id, sizeof(uint64_t))) continue; - } if (&adh->attest != NULL) if (0 != memcmp (rd[i].data, &adh->attest->id, sizeof(uint64_t))) continue; if (&adh->reference != NULL) if (0 != memcmp (rd[i].data, &adh->reference->id, sizeof(uint64_t))) continue; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Attribute or Attestation/Reference to delete found (%s)\n", adh->label); @@ -1490,7 +1483,6 @@ ticket_iter (void *cls, adh->tickets_to_update_tail, le); } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Next Zone Iteration \n"); GNUNET_NAMESTORE_zone_iterator_next (adh->ns_it, 1); } @@ -2026,7 +2018,7 @@ attr_iter_error (void *cls) /** - * Got record. Return if it is an attribute or attestation. + * Got record. Return if it is an attribute or attestation/reference. * * @param cls our attribute iterator * @param zone zone we are iterating @@ -2046,48 +2038,83 @@ attr_iter_cb (void *cls, struct GNUNET_MQ_Envelope *env; char *data_tmp; - if (rd_count != 1) + if (rd_count == 0) { GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); return; } - - if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd->record_type) && - (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd->record_type) ) + if (rd_count > 1) { - GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); - return; + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Non-Attestation record with multiple entries found\n"); + GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); + return; + } } - if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR == rd->record_type ) + for (int i = 0; idata_size, - GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT); - arm->id = htonl (ai->request_id); - arm->attr_len = htons (rd->data_size); - GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity); - data_tmp = (char *) &arm[1]; - GNUNET_memcpy (data_tmp, rd->data, rd->data_size); - GNUNET_MQ_send (ai->client->mq, env); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", label); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n"); - env = GNUNET_MQ_msg_extra (arm, - rd->data_size, - GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); - arm->id = htonl (ai->request_id); - arm->attr_len = htons (rd->data_size); - GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity); - data_tmp = (char *) &arm[1]; - GNUNET_memcpy (data_tmp, rd->data, rd->data_size); - GNUNET_MQ_send (ai->client->mq, env); + if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd[i].record_type) && + (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[i].record_type) && + (GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE != rd[i].record_type)) + { + GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); + return; + } + + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR == rd[i].record_type ) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", + label); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending ATTRIBUTE_RESULT message\n"); + env = GNUNET_MQ_msg_extra (arm, + rd[i].data_size, + GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); + arm->id = htonl (ai->request_id); + arm->attr_len = htons (rd[i].data_size); + GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity); + data_tmp = (char *) &arm[1]; + GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size); + GNUNET_MQ_send (ai->client->mq, env); + } + else + { + if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR == rd[i].record_type ) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attestation under: %s\n", + label); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending ATTESTATION_RESULT message\n"); + env = GNUNET_MQ_msg_extra (arm, + rd[i].data_size, + GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT); + arm->id = htonl (ai->request_id); + arm->attr_len = htons (rd[i].data_size); + GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity); + data_tmp = (char *) &arm[1]; + GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size); + GNUNET_MQ_send (ai->client->mq, env); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found reference under: %s\n", + label); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending REFERENCE_RESULT message\n"); + env = GNUNET_MQ_msg_extra (arm, + rd[i].data_size, + GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT); + arm->id = htonl (ai->request_id); + arm->attr_len = htons (rd[i].data_size); + GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity); + data_tmp = (char *) &arm[1]; + GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size); + GNUNET_MQ_send (ai->client->mq, env); + } + } } } diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c index 8e3c205cb..000e9ca99 100644 --- a/src/reclaim/plugin_rest_openid_connect.c +++ b/src/reclaim/plugin_rest_openid_connect.c @@ -973,7 +973,8 @@ static void oidc_attr_collect (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest) + const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, + const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) { struct RequestHandle *handle = cls; struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; @@ -1009,7 +1010,7 @@ oidc_attr_collect (void *cls, attr->data, attr->data_size); le->claim->id = attr->id; - le->claim->version = attr->version; + le->claim->flag = attr->flag; GNUNET_CONTAINER_DLL_insert (handle->attr_list->list_head, handle->attr_list->list_tail, le); @@ -1849,7 +1850,8 @@ static void consume_ticket (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest) + const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, + const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) { struct RequestHandle *handle = cls; char *tmp_value; diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 8bf757218..b8e48e55e 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c @@ -635,7 +635,8 @@ static void attest_collect (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest) + const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, + const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) { struct RequestHandle *handle = cls; json_t *attr_obj; @@ -1050,7 +1051,8 @@ static void attr_collect (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest) + const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, + const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) { struct RequestHandle *handle = cls; json_t *attr_obj; @@ -1288,7 +1290,8 @@ static void consume_cont (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest) + const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, + const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) { struct RequestHandle *handle = cls; char *val_str; diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c index 010f07bf5..5080cf935 100644 --- a/src/reclaim/reclaim_api.c +++ b/src/reclaim/reclaim_api.c @@ -503,16 +503,16 @@ handle_consume_ticket_result (void *cls, { if (NULL == attrs) { - op->ar_cb (op->cls, &msg->identity, NULL, NULL); + op->ar_cb (op->cls, &msg->identity, NULL, NULL, NULL); } else { for (le = attrs->list_head; NULL != le; le = le->next) - op->ar_cb (op->cls, &msg->identity, le->claim, NULL); + op->ar_cb (op->cls, &msg->identity, le->claim, NULL, NULL); GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); attrs = NULL; } - op->ar_cb (op->cls, NULL, NULL, NULL); + op->ar_cb (op->cls, NULL, NULL, NULL, NULL); } GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); free_op (op); @@ -596,7 +596,7 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) if (NULL != op) { if (NULL != op->ar_cb) - op->ar_cb (op->cls, NULL, NULL, NULL); + op->ar_cb (op->cls, NULL, NULL, NULL, NULL); GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); free_op (op); } @@ -609,12 +609,12 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) if (NULL != it) { if (NULL != it->proc) - it->proc (it->proc_cls, &msg->identity, attr, NULL); + it->proc (it->proc_cls, &msg->identity, attr, NULL, NULL); } else if (NULL != op) { if (NULL != op->ar_cb) - op->ar_cb (op->cls, &msg->identity, attr, NULL); + op->ar_cb (op->cls, &msg->identity, attr, NULL, NULL); } GNUNET_free (attr); return; @@ -695,7 +695,7 @@ handle_attestation_result (void *cls, const struct AttributeResultMessage *msg) if (NULL != op) { if (NULL != op->ar_cb) - op->ar_cb (op->cls, NULL, NULL, NULL); + op->ar_cb (op->cls, NULL, NULL, NULL, NULL); GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); free_op (op); } @@ -708,12 +708,111 @@ handle_attestation_result (void *cls, const struct AttributeResultMessage *msg) if (NULL != it) { if (NULL != it->proc) - it->proc (it->proc_cls, &msg->identity, NULL, attr); + it->proc (it->proc_cls, &msg->identity, NULL, attr, NULL); } else if (NULL != op) { if (NULL != op->ar_cb) - op->ar_cb (op->cls, &msg->identity, NULL, attr); + op->ar_cb (op->cls, &msg->identity, NULL, attr, NULL); + } + GNUNET_free (attr); + return; + } + GNUNET_assert (0); +} + +/** + * Handle an incoming message of type + * #GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT + * + * @param cls + * @param msg the message we received + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error + */ +static int +check_reference_result (void *cls, const struct AttributeResultMessage *msg) +{ + size_t msg_len; + size_t attr_len; + + msg_len = ntohs (msg->header.size); + attr_len = ntohs (msg->attr_len); + if (msg_len != sizeof(struct AttributeResultMessage) + attr_len) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + return GNUNET_OK; +} + +/** +* Handle an incoming message of type +* #GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT +* +* @param cls +* @param msg the message we received +*/ +static void +handle_reference_result (void *cls, const struct AttributeResultMessage *msg) +{ + static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; + struct GNUNET_RECLAIM_Handle *h = cls; + struct GNUNET_RECLAIM_AttributeIterator *it; + struct GNUNET_RECLAIM_Operation *op; + size_t attr_len; + uint32_t r_id = ntohl (msg->id); + + attr_len = ntohs (msg->attr_len); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing reference result.\n"); + + + for (it = h->it_head; NULL != it; it = it->next) + if (it->r_id == r_id) + break; + for (op = h->op_head; NULL != op; op = op->next) + if (op->r_id == r_id) + break; + if ((NULL == it) && (NULL == op)) + return; + + if ((0 == + (memcmp (&msg->identity, &identity_dummy, sizeof(identity_dummy))))) + { + if ((NULL == it) && (NULL == op)) + { + GNUNET_break (0); + force_reconnect (h); + return; + } + if (NULL != it) + { + if (NULL != it->finish_cb) + it->finish_cb (it->finish_cb_cls); + free_it (it); + } + if (NULL != op) + { + if (NULL != op->ar_cb) + op->ar_cb (op->cls, NULL, NULL, NULL, NULL); + GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); + free_op (op); + } + return; + } + + { + struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr; + attr = GNUNET_RECLAIM_ATTESTATION_REF_deserialize ((char *) &msg[1], + attr_len); + if (NULL != it) + { + if (NULL != it->proc) + it->proc (it->proc_cls, &msg->identity, NULL, NULL, attr); + } + else if (NULL != op) + { + if (NULL != op->ar_cb) + op->ar_cb (op->cls, &msg->identity, NULL, NULL, attr); } GNUNET_free (attr); return; @@ -843,6 +942,10 @@ reconnect (struct GNUNET_RECLAIM_Handle *h) GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT, struct AttributeResultMessage, h), + GNUNET_MQ_hd_var_size (reference_result, + GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT, + struct AttributeResultMessage, + h), GNUNET_MQ_hd_fixed_size (ticket_result, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT, struct TicketResultMessage,