From f38103524a5e65207ae029f7de0b880c6072e19f Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Fri, 18 Oct 2013 15:37:21 +0000 Subject: [PATCH] implementing api call --- src/include/gnunet_protocols.h | 4 +++ src/namestore/namestore.h | 27 +++++++++++++++++ src/namestore/namestore_api.c | 54 ++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index a3e40afd3..ff367e359 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -1433,6 +1433,10 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 448 +/** + * Client to service: lookup label + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_LABEL_LOOKUP 449 /******************************************************************************* * LOCKMANAGER message types diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h index 4350dbab4..761360c47 100644 --- a/src/namestore/namestore.h +++ b/src/namestore/namestore.h @@ -209,6 +209,33 @@ struct RecordStoreResponseMessage }; +/** + * Lookup a label + */ +struct LabelLookupMessage +{ + /** + * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_LABEL_LOOKUP + */ + struct GNUNET_NAMESTORE_Header gns_header; + + /** + * The private key of the zone to look up in + */ + struct GNUNET_CRYPTO_EcdsaPrivateKey zone; + + /** + * Length of the name + */ + uint16_t label_len GNUNET_PACKED; + + /* followed by: + * name with length name_len + */ +}; + + + /** * Lookup a name for a zone hash diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index efdc3005b..8d3ea16dd 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c @@ -981,6 +981,60 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, } +/** + * Lookup an item in the namestore. + * + * @param h handle to the namestore + * @param pkey private key of the zone + * @param label name that is being mapped (at most 255 characters long) + * @param rm function to call with the result (with 0 records if we don't have that label) + * @param rm_cls closure for @a rm + * @return handle to abort the request + */ +struct GNUNET_NAMESTORE_QueueEntry * +GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, + const char *label, + GNUNET_NAMESTORE_RecordMonitor rm, + void *rm_cls) +{ + struct GNUNET_NAMESTORE_QueueEntry *qe; + struct PendingMessage *pe; + struct LabelLookupMessage * msg; + size_t msg_size; + size_t label_len; + + GNUNET_assert (NULL != h); + GNUNET_assert (NULL != pkey); + GNUNET_assert (NULL != label); + + if (1 == (label_len = strlen (label) + 1)) + return NULL; + + qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); + qe->nsh = h; + qe->proc = rm; + qe->proc_cls = rm_cls; + qe->op_id = get_op_id(h); + GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); + + msg_size = sizeof (struct LabelLookupMessage) + label_len; + pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); + pe->size = msg_size; + msg = (struct LabelLookupMessage *) &pe[1]; + msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LABEL_LOOKUP); + msg->gns_header.header.size = htons (msg_size); + msg->gns_header.r_id = htonl (qe->op_id); + msg->zone = *pkey; + msg->label_len = htons(label_len); + + /* transmit message */ + GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); + do_transmit (h); + return qe; +} + + /** * Look for an existing PKEY delegation record for a given public key. * Returns at most one result to the processor. -- 2.25.1