gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r20281 - gnunet/src/namestore


From: gnunet
Subject: [GNUnet-SVN] r20281 - gnunet/src/namestore
Date: Mon, 5 Mar 2012 16:20:49 +0100

Author: wachs
Date: 2012-03-05 16:20:49 +0100 (Mon, 05 Mar 2012)
New Revision: 20281

Added:
   gnunet/src/namestore/test_namestore_api_zone_to_name.c
Modified:
   gnunet/src/namestore/Makefile.am
   gnunet/src/namestore/gnunet-namestore.c
   gnunet/src/namestore/gnunet-service-namestore.c
   gnunet/src/namestore/namestore.h
   gnunet/src/namestore/namestore_api.c
   gnunet/src/namestore/test_namestore_api.conf
Log:
- changes


Modified: gnunet/src/namestore/Makefile.am
===================================================================
--- gnunet/src/namestore/Makefile.am    2012-03-05 15:06:44 UTC (rev 20280)
+++ gnunet/src/namestore/Makefile.am    2012-03-05 15:20:49 UTC (rev 20281)
@@ -34,6 +34,7 @@
  test_namestore_api_create_update \
  test_namestore_api_remove \
  test_namestore_api_remove_not_existing_record \
+ test_namestore_api_zone_to_name \
  test_namestore_api_zone_iteration \
  test_namestore_record_serialization
 
@@ -157,6 +158,12 @@
   $(top_builddir)/src/util/libgnunetutil.la \
   $(top_builddir)/src/namestore/libgnunetnamestore.la
 
+test_namestore_api_zone_to_name_SOURCES = \
+ test_namestore_api_zone_to_name.c
+test_namestore_api_zone_to_name_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la
+
 test_namestore_api_zone_iteration_SOURCES = \
  test_namestore_api_zone_iteration.c
 test_namestore_api_zone_iteration_LDADD = \

Modified: gnunet/src/namestore/gnunet-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-namestore.c     2012-03-05 15:06:44 UTC (rev 
20280)
+++ gnunet/src/namestore/gnunet-namestore.c     2012-03-05 15:20:49 UTC (rev 
20281)
@@ -191,7 +191,7 @@
  *               or the expiration time of the block in the namestore (even if 
there are zero
  *               records matching the desired record type)
  * @param name name that is being mapped (at most 255 characters long)
- * @param rd_count number of entries in 'rd' array
+ * @param rd_len number of entries in 'rd' array
  * @param rd array of records with data to store
  * @param signature signature of the record block, NULL if signature is 
unavailable (i.e. 
  *        because the user queried for a particular record type only)

Modified: gnunet/src/namestore/gnunet-service-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-service-namestore.c     2012-03-05 15:06:44 UTC 
(rev 20280)
+++ gnunet/src/namestore/gnunet-service-namestore.c     2012-03-05 15:20:49 UTC 
(rev 20281)
@@ -1062,6 +1062,146 @@
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
+
+struct ZoneToNameCtx
+{
+  struct GNUNET_NAMESTORE_Client *nc;
+  uint32_t rid;
+};
+
+static void
+handle_zone_to_name_it (void *cls,
+    const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+    struct GNUNET_TIME_Absolute expire,
+    const char *name,
+    unsigned int rd_count,
+    const struct GNUNET_NAMESTORE_RecordData *rd,
+    const struct GNUNET_CRYPTO_RsaSignature *signature)
+{
+  struct ZoneToNameCtx * ztn_ctx = cls;
+  struct ZoneToNameResponseMessage *ztnr_msg;
+  int16_t res = GNUNET_SYSERR;
+  uint16_t name_len = 0;
+  uint16_t rd_ser_len = 0 ;
+  int32_t contains_sig = 0;
+  size_t msg_size = 0;
+
+  char *rd_ser;
+  char *name_tmp;
+  char *rd_tmp;
+  char *sig_tmp;
+
+  if ((zone_key != NULL) && (name != NULL))
+  {
+    /* found result */
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found results: name ist \n");
+    res = GNUNET_YES;
+    name_len = strlen (name);
+  }
+  else
+  {
+    /* no result found */
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found no results\n");
+    res = GNUNET_NO;
+    name_len = 0;
+  }
+
+  if (rd_count > 0)
+  {
+    rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
+    char rd_ser[rd_ser_len];
+    GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
+  }
+  else
+    rd_ser_len = 0;
+
+  if (signature != NULL)
+    contains_sig = GNUNET_YES;
+  else
+    contains_sig = GNUNET_NO;
+
+  msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len 
+ contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature);
+  ztnr_msg = GNUNET_malloc (msg_size);
+
+  name_tmp = (char *) &ztnr_msg[1];
+  rd_tmp = &name_tmp[name_len];
+  sig_tmp = &rd_tmp[rd_ser_len];
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", 
"ZONE_TO_NAME_RESPONSE");
+  ztnr_msg->gns_header.header.type = htons 
(GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE);
+  ztnr_msg->gns_header.header.size = htons (msg_size);
+  ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid);
+  ztnr_msg->res = htons (res);
+  ztnr_msg->rd_len = htons (rd_ser_len);
+  ztnr_msg->rd_count = htons (rd_count);
+  ztnr_msg->name_len = htons (name_len);
+  ztnr_msg->contains_sig = htons (contains_sig);
+  if (zone_key != NULL)
+    ztnr_msg->zone_key = *zone_key;
+  else
+    memset (&ztnr_msg->zone_key, '\0', sizeof (struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+
+  memcpy (&name_tmp, name, name_len);
+  memcpy (&rd_tmp, &rd_ser, rd_ser_len);
+  memcpy (&sig_tmp, signature, contains_sig * sizeof (struct 
GNUNET_CRYPTO_RsaSignature));
+
+  GNUNET_SERVER_notification_context_unicast (snc, ztn_ctx->nc->client, (const 
struct GNUNET_MessageHeader *) ztnr_msg, GNUNET_NO);
+  GNUNET_free (ztnr_msg);
+}
+
+
+static void handle_zone_to_name (void *cls,
+                          struct GNUNET_SERVER_Client * client,
+                          const struct GNUNET_MessageHeader * message)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", 
"ZONE_TO_NAME");
+  struct GNUNET_NAMESTORE_Client *nc;
+  struct ZoneToNameCtx ztn_ctx;
+  size_t msg_size = 0;
+  uint32_t rid = 0;
+  int res;
+
+
+  if (ntohs (message->size) != sizeof (struct ZoneToNameMessage))
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  nc = client_lookup(client);
+  if (nc == NULL)
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  struct ZoneToNameMessage *ztn_msg = (struct ZoneToNameMessage *) message;
+
+  if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  rid = ntohl (ztn_msg->gns_header.r_id);
+
+  ztn_ctx.rid = rid;
+  ztn_ctx.nc = nc;
+
+  char * z_tmp = strdup (GNUNET_h2s (&ztn_msg->zone));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up name for zone `%s' in zone 
`%s''\n",
+      z_tmp,
+      GNUNET_h2s (&ztn_msg->value_zone));
+  GNUNET_free (z_tmp);
+
+  res = GSN_database->zone_to_name (GSN_database->cls, &ztn_msg->zone, 
&ztn_msg->value_zone, &handle_zone_to_name_it, &ztn_ctx);
+
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
 struct ZoneIterationProcResult
 {
   int have_zone_key;
@@ -1289,6 +1429,8 @@
      GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0},
     {&handle_record_remove, NULL,
      GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0},
+    {&handle_zone_to_name, NULL,
+      GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, 0},
     {&handle_iteration_start, NULL,
      GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct 
ZoneIterationStartMessage)},
     {&handle_iteration_stop, NULL,

Modified: gnunet/src/namestore/namestore.h
===================================================================
--- gnunet/src/namestore/namestore.h    2012-03-05 15:06:44 UTC (rev 20280)
+++ gnunet/src/namestore/namestore.h    2012-03-05 15:20:49 UTC (rev 20281)
@@ -37,14 +37,15 @@
 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE 436
 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE 437
 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE 438
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME 439
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE 440
 
-#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START 439
-#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE 440
-#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 441
-#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 442
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START 445
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE 446
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 447
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 448
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_DISCONNECT 449
 
-#define GNUNET_MESSAGE_TYPE_NAMESTORE_DISCONNECT 443
-
 /**
  * Sign name and records
  *
@@ -299,6 +300,7 @@
 
 };
 
+
 /**
  * Remove a record from the namestore
  * Memory layout:
@@ -325,13 +327,11 @@
   /* Length of pubkey */
   uint16_t key_len;
 };
-GNUNET_NETWORK_STRUCT_END
 
 
 /**
  * Remove a record from the namestore response
  */
-GNUNET_NETWORK_STRUCT_BEGIN
 struct RecordRemoveResponseMessage
 {
   /**
@@ -351,13 +351,51 @@
    */
   uint16_t op_result;
 };
-GNUNET_NETWORK_STRUCT_END
 
 
 /**
+ * Connect to namestore service
+ */
+struct ZoneToNameMessage
+{
+  struct GNUNET_NAMESTORE_Header gns_header;
+
+  /* The hash of public key of the zone to look up in */
+  GNUNET_HashCode zone;
+
+  /* The  hash of the public key of the target zone  */
+  GNUNET_HashCode value_zone;
+};
+
+/**
+ * Connect to namestore service
+ */
+struct ZoneToNameResponseMessage
+{
+  struct GNUNET_NAMESTORE_Header gns_header;
+
+  struct GNUNET_TIME_AbsoluteNBO expire;
+
+  uint16_t name_len;
+
+  uint16_t rd_len;
+
+  uint16_t rd_count;
+
+  int32_t contains_sig;
+
+  /* result in NBO: GNUNET_OK on success, GNUNET_NO if there were no results, 
GNUNET_SYSERR on error */
+  int16_t res;
+
+  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
+
+};
+
+
+
+/**
  * Start a zone iteration for the given zone
  */
-GNUNET_NETWORK_STRUCT_BEGIN
 struct ZoneIterationStartMessage
 {
   /**
@@ -372,12 +410,11 @@
 
   GNUNET_HashCode zone;
 };
-GNUNET_NETWORK_STRUCT_END
 
+
 /**
  * Ask for next result of zone iteration for the given operation
  */
-GNUNET_NETWORK_STRUCT_BEGIN
 struct ZoneIterationNextMessage
 {
   /**
@@ -385,13 +422,11 @@
    */
   struct GNUNET_NAMESTORE_Header gns_header;
 };
-GNUNET_NETWORK_STRUCT_END
 
 
 /**
  * Stop zone iteration for the given operation
  */
-GNUNET_NETWORK_STRUCT_BEGIN
 struct ZoneIterationStopMessage
 {
   /**
@@ -399,12 +434,10 @@
    */
   struct GNUNET_NAMESTORE_Header gns_header;
 };
-GNUNET_NETWORK_STRUCT_END
 
 /**
  * Ask for next result of zone iteration for the given operation
  */
-GNUNET_NETWORK_STRUCT_BEGIN
 struct ZoneIterationResponseMessage
 {
   /**

Modified: gnunet/src/namestore/namestore_api.c
===================================================================
--- gnunet/src/namestore/namestore_api.c        2012-03-05 15:06:44 UTC (rev 
20280)
+++ gnunet/src/namestore/namestore_api.c        2012-03-05 15:20:49 UTC (rev 
20281)
@@ -467,7 +467,38 @@
   GNUNET_free (qe);
 }
 
+static void
+handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
+                             struct ZoneToNameResponseMessage* msg,
+                             size_t size)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n",
+              "ZONE_TO_NAME_RESPONSE");
 
+  struct GNUNET_NAMESTORE_Handle *h = qe->nsh;
+  int res = ntohs (msg->res);
+
+  switch (res) {
+    case GNUNET_SYSERR:
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "An error occured during zone to 
name operation\n");
+      if (qe->proc != NULL)
+        qe->proc (qe->proc_cls, NULL, GNUNET_TIME_absolute_get_zero(), NULL, 
0, NULL, NULL);
+      break;
+    case GNUNET_NO:
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore has no result for zone 
to name mapping \n");
+      if (qe->proc != NULL)
+        qe->proc (qe->proc_cls, NULL, GNUNET_TIME_absolute_get_zero(), NULL, 
0, NULL, NULL);
+      break;
+    default:
+      break;
+  }
+
+  /* Operation done, remove */
+  GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe);
+  GNUNET_free (qe);
+}
+
+
 static void
 manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe,
                           const struct GNUNET_MessageHeader *msg,
@@ -508,6 +539,14 @@
         }
         handle_record_remove_response (qe, (struct RecordRemoveResponseMessage 
*) msg, size);
       break;
+    case GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE:
+        if (size < sizeof (struct ZoneToNameResponseMessage))
+        {
+          GNUNET_break_op (0);
+          break;
+        }
+        handle_zone_to_name_response (qe, (struct ZoneToNameResponseMessage *) 
msg, size);
+      break;
     default:
       GNUNET_break_op (0);
       break;
@@ -1321,7 +1360,73 @@
 }
 
 
+/**
+ * Look for an existing PKEY delegation record for a given public key.
+ * Returns at most one result to the processor.
+ *
+ * @param h handle to the namestore
+ * @param zone hash of public key of the zone to look up in, never NULL
+ * @param value_zone hash of the public key of the target zone (value), never 
NULL
+ * @param proc function to call on the matching records, or with
+ *        NULL (rd_count == 0) if there are no matching records
+ * @param proc_cls closure for proc
+ * @return a handle that can be used to
+ *         cancel
+ */
+struct GNUNET_NAMESTORE_QueueEntry *
+GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
+                               const GNUNET_HashCode *zone,
+                               const GNUNET_HashCode *value_zone,
+                               GNUNET_NAMESTORE_RecordProcessor proc, void 
*proc_cls)
+{
+  struct GNUNET_NAMESTORE_QueueEntry *qe;
+  struct PendingMessage *pe;
+  size_t msg_size = 0;
+  uint32_t rid = 0;
 
+  GNUNET_assert (NULL != h);
+  GNUNET_assert (NULL != zone);
+  GNUNET_assert (NULL != value_zone);
+
+  rid = get_op_id(h);
+  qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
+  qe->nsh = h;
+  qe->proc = proc;
+  qe->proc_cls = proc_cls;
+  qe->op_id = rid;
+  GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe);
+
+  /* set msg_size*/
+  msg_size = sizeof (struct ZoneToNameMessage);
+  pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
+
+  /* create msg here */
+  struct ZoneToNameMessage * msg;
+  pe->size = msg_size;
+  pe->is_init = GNUNET_NO;
+  msg = (struct ZoneToNameMessage *) &pe[1];
+  msg->gns_header.header.type = htons 
(GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME);
+  msg->gns_header.header.size = htons (msg_size);
+  msg->gns_header.r_id = htonl (rid);
+  msg->zone = *zone;
+  msg->value_zone = *value_zone;
+
+  char * z_tmp = strdup (GNUNET_h2s (zone));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for zone `%s' in 
zone `%s'\n",
+      "NAMESTORE_ZONE_TO_NAME",
+      z_tmp,
+      GNUNET_h2s (value_zone));
+  GNUNET_free (z_tmp);
+
+  /* transmit message */
+  GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
+  do_transmit(h);
+
+  return qe;
+}
+
+
+
 /**
  * Starts a new zone iteration (used to periodically PUT all of our
  * records into our DHT). This MUST lock the GNUNET_NAMESTORE_Handle

Modified: gnunet/src/namestore/test_namestore_api.conf
===================================================================
--- gnunet/src/namestore/test_namestore_api.conf        2012-03-05 15:06:44 UTC 
(rev 20280)
+++ gnunet/src/namestore/test_namestore_api.conf        2012-03-05 15:20:49 UTC 
(rev 20281)
@@ -4,7 +4,7 @@
 UNIXPATH = /tmp/gnunet-p1-service-arm.sock
 
 [namestore]
-#PREFIX = valgrind --leak-check=full
+PREFIX = valgrind --leak-check=full
 AUTOSTART = YES
 UNIXPATH = /tmp/gnunet-service-namestore.sock
 UNIX_MATCH_UID = YES

Added: gnunet/src/namestore/test_namestore_api_zone_to_name.c
===================================================================
--- gnunet/src/namestore/test_namestore_api_zone_to_name.c                      
        (rev 0)
+++ gnunet/src/namestore/test_namestore_api_zone_to_name.c      2012-03-05 
15:20:49 UTC (rev 20281)
@@ -0,0 +1,216 @@
+/*
+     This file is part of GNUnet.
+     (C) 2009 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file namestore/test_namestore_api_zone_to_name.c
+ * @brief testcase for zone to name translation
+ */
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_namestore_service.h"
+#include "namestore.h"
+#include "gnunet_signatures.h"
+
+#define VERBOSE GNUNET_NO
+
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+
+static struct GNUNET_NAMESTORE_Handle * nsh;
+
+static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
+static struct GNUNET_OS_Process *arm;
+
+static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
+static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
+
+static GNUNET_HashCode s_zone;
+static GNUNET_HashCode s_zone_value;
+
+static int res;
+
+static void
+start_arm (const char *cfgname)
+{
+  arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
+                               "gnunet-service-arm", "-c", cfgname,
+#if VERBOSE_PEERS
+                               "-L", "DEBUG",
+#else
+                               "-L", "ERROR",
+#endif
+                               NULL);
+}
+
+static void
+stop_arm ()
+{
+  if (NULL != arm)
+  {
+    if (0 != GNUNET_OS_process_kill (arm, SIGTERM))
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+    GNUNET_OS_process_wait (arm);
+    GNUNET_OS_process_close (arm);
+    arm = NULL;
+  }
+}
+
+/**
+ * Re-establish the connection to the service.
+ *
+ * @param cls handle to use to re-connect.
+ * @param tc scheduler context
+ */
+static void
+endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if (nsh != NULL)
+    GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
+  nsh = NULL;
+
+  if (privkey != NULL)
+    GNUNET_CRYPTO_rsa_key_free (privkey);
+  privkey = NULL;
+
+  if (NULL != arm)
+    stop_arm();
+
+  res = 1;
+}
+
+
+static void
+end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
+  {
+    GNUNET_SCHEDULER_cancel (endbadly_task);
+    endbadly_task = GNUNET_SCHEDULER_NO_TASK;
+  }
+
+  if (privkey != NULL)
+    GNUNET_CRYPTO_rsa_key_free (privkey);
+  privkey = NULL;
+
+  if (nsh != NULL)
+    GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
+  nsh = NULL;
+
+  if (NULL != arm)
+    stop_arm();
+}
+
+void zone_to_name_proc (void *cls,
+                            const struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+                            struct GNUNET_TIME_Absolute expire,
+                            const char *n,
+                            unsigned int rd_count,
+                            const struct GNUNET_NAMESTORE_RecordData *rd,
+                            const struct GNUNET_CRYPTO_RsaSignature *signature)
+{
+    if ((zone_key == NULL) && (n == NULL) && (rd_count == 0) && (rd == NULL) 
&& (signature == NULL))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No result found\n");
+      res = 0;
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result found\n");
+      res = 0;
+    }
+    GNUNET_SCHEDULER_add_now(&end, NULL);
+}
+
+
+void
+delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  char *afsdir;
+
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite",
+                                               "FILENAME", &afsdir))
+  {
+    if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
+      if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
+        if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir))
+          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' 
\n", afsdir);
+   GNUNET_free (afsdir);
+  }
+
+}
+
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  delete_existing_db(cfg);
+
+  endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
+
+  /* load privat key */
+  privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
+  GNUNET_assert (privkey != NULL);
+  /* get public key */
+  GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
+
+  /* zone hash */
+  GNUNET_CRYPTO_hash (&pubkey, sizeof (struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone);
+  GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &s_zone_value);
+
+  start_arm (cfgfile);
+  GNUNET_assert (arm != NULL);
+
+  nsh = GNUNET_NAMESTORE_connect (cfg);
+  GNUNET_break (NULL != nsh);
+
+  /* create initial record */
+  GNUNET_NAMESTORE_zone_to_name (nsh, &s_zone, &s_zone_value, 
zone_to_name_proc, NULL);
+}
+
+static int
+check ()
+{
+  static char *const argv[] = { "test-namestore-api",
+    "-c",
+    "test_namestore_api.conf",
+#if VERBOSE
+    "-L", "DEBUG",
+#endif
+    NULL
+  };
+  static struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_OPTION_END
+  };
+
+  res = 1;
+  GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, 
"test-namestore-api",
+                      "nohelp", options, &run, &res);
+  return res;
+}
+
+int
+main (int argc, char *argv[])
+{
+  int ret;
+
+  ret = check ();
+  return ret;
+}
+
+/* end of test_namestore_api.c */




reply via email to

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