+ struct GNUNET_MQ_Envelope *env;
+ struct RecordStoreResponseMessage *rcr_msg;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending RECORD_STORE_RESPONSE message\n");
+ env = GNUNET_MQ_msg (rcr_msg,
+ GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE);
+ rcr_msg->gns_header.r_id = htonl (rid);
+ rcr_msg->op_result = htonl (res);
+ GNUNET_MQ_send (nc->mq,
+ env);
+}
+
+
+/**
+ * Cache operation complete, clean up.
+ *
+ * @param cls the `struct CacheOperation`
+ * @param success success
+ * @param emsg error messages
+ */
+static void
+finish_cache_operation (void *cls,
+ int32_t success,
+ const char *emsg)
+{
+ struct CacheOperation *cop = cls;
+
+ if (NULL != emsg)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to replicate block in namecache: %s\n"),
+ emsg);
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "CACHE operation completed\n");
+ GNUNET_CONTAINER_DLL_remove (cop_head,
+ cop_tail,
+ cop);
+ if (NULL != cop->nc)
+ send_store_response (cop->nc,
+ success,
+ cop->rid);
+ GNUNET_free (cop);
+}
+
+
+/**
+ * We just touched the plaintext information about a name in our zone;
+ * refresh the corresponding (encrypted) block in the namecache.
+ *
+ * @param nc client responsible for the request, can be NULL
+ * @param rid request ID of the client
+ * @param zone_key private key of the zone
+ * @param name label for the records
+ * @param rd_count number of records
+ * @param rd records stored under the given @a name
+ */
+static void
+refresh_block (struct NamestoreClient *nc,
+ uint32_t rid,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
+ const char *name,
+ unsigned int rd_count,
+ const struct GNUNET_GNSRECORD_Data *rd)
+{
+ struct GNUNET_GNSRECORD_Block *block;
+ struct CacheOperation *cop;
+ struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
+ struct GNUNET_GNSRECORD_Data *nick;
+ struct GNUNET_GNSRECORD_Data *res;
+ unsigned int res_count;
+
+ nick = get_nick_record (zone_key);
+ res_count = rd_count;
+ res = (struct GNUNET_GNSRECORD_Data *) rd; /* fixme: a bit unclean... */
+ if (NULL != nick)
+ {
+ nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
+ merge_with_nick_records (nick,
+ rd_count,rd,
+ &res_count,
+ &res);
+ GNUNET_free (nick);
+ }
+
+ if (0 == res_count)
+ block = GNUNET_GNSRECORD_block_create (zone_key,
+ GNUNET_TIME_UNIT_ZERO_ABS,
+ name,
+ res, rd_count);
+ else
+ block = GNUNET_GNSRECORD_block_create (zone_key,
+ GNUNET_GNSRECORD_record_get_expiration_time (res_count,
+ res),
+ name,
+ res, res_count);
+ GNUNET_assert (NULL != block);
+ GNUNET_CRYPTO_ecdsa_key_get_public (zone_key,
+ &pkey);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Caching block for label `%s' with %u records in zone `%s' in namecache\n",
+ name,
+ res_count,
+ GNUNET_GNSRECORD_z2s (&pkey));
+ cop = GNUNET_new (struct CacheOperation);
+ cop->nc = nc;
+ cop->rid = rid;
+ GNUNET_CONTAINER_DLL_insert (cop_head,
+ cop_tail,
+ cop);
+ cop->qe = GNUNET_NAMECACHE_block_cache (namecache,
+ block,
+ &finish_cache_operation,
+ cop);
+ GNUNET_free (block);
+}
+
+
+/**
+ * Closure for #lookup_it().
+ */
+struct RecordLookupContext
+{
+ const char *label;
+
+ int found;
+
+ unsigned int res_rd_count;
+