From 8cd6146318d890c5cb18a2edb72090feee9729b2 Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Thu, 16 Aug 2018 22:08:54 +0200 Subject: [PATCH] store to ns --- src/include/gnunet_gnsrecord_lib.h | 5 ++++ src/zklaim/gnunet-service-zklaim.c | 46 +++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h index 693cc6cdb..b89588d1a 100644 --- a/src/include/gnunet_gnsrecord_lib.h +++ b/src/include/gnunet_gnsrecord_lib.h @@ -141,6 +141,11 @@ extern "C" */ #define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT 65553 +/** + * Record type for zklaim contexts + */ +#define GNUNET_GNSRECORD_TYPE_ZKLAIM_CTX 65554 + /** * Flags that can be set for a record. */ diff --git a/src/zklaim/gnunet-service-zklaim.c b/src/zklaim/gnunet-service-zklaim.c index ac8455364..91e70fc99 100644 --- a/src/zklaim/gnunet-service-zklaim.c +++ b/src/zklaim/gnunet-service-zklaim.c @@ -237,10 +237,14 @@ handle_create_context_message (void *cls, { struct CreateContextHandle *cch; struct ZkClient *zkc = cls; - size_t data_len; + struct GNUNET_GNSRECORD_Data ctx_record; + size_t str_len; char *tmp; char *pos; unsigned char *data; + char *rdata; + size_t data_len; + size_t rdata_len; int num_attrs; int num_pl; int i; @@ -249,13 +253,13 @@ handle_create_context_message (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE_REQUEST message\n"); - data_len = ntohs (crm->name_len); + str_len = ntohs (crm->name_len); cch = GNUNET_new (struct CreateContextHandle); - cch->name = GNUNET_strndup ((char*)&crm[1], data_len-1); - data_len = ntohs(crm->attrs_len); + cch->name = GNUNET_strndup ((char*)&crm[1], str_len-1); + str_len = ntohs(crm->attrs_len); cch->attrs = GNUNET_strndup (((char*)&crm[1]) + strlen (cch->name) + 1, - data_len-1); + str_len-1); cch->private_key = crm->private_key; GNUNET_CRYPTO_ecdsa_key_get_public (&crm->private_key, &cch->public_key); @@ -297,16 +301,30 @@ handle_create_context_message (void *cls, zklaim_ctx_free (ctx); return; } - if (0 != zklaim_ctx_serialize (ctx, &data)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Context serialization failed.\n"); - send_result(GNUNET_SYSERR, cch); - zklaim_ctx_free (ctx); - return; - } + data_len = zklaim_ctx_serialize (ctx, &data); + rdata_len = data_len + strlen (cch->attrs) + 1; zklaim_ctx_free (ctx); - // store ctx,attrs as GNS record + rdata = GNUNET_malloc (rdata_len); + memcpy (rdata, + cch->attrs, + strlen (cch->attrs) + 1); + memcpy (rdata + strlen (cch->attrs) + 1, + data, + data_len); + ctx_record.data_size = rdata_len; + ctx_record.data = rdata; + ctx_record.expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; //TODO config + ctx_record.record_type = GNUNET_GNSRECORD_TYPE_ZKLAIM_CTX; + ctx_record.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; + cch->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle, + &cch->private_key, + cch->name, + 1, + &ctx_record, + &context_store_cont, + cch); + GNUNET_free (rdata); + GNUNET_free (data); } -- 2.25.1