- changes
authorMatthias Wachs <wachs@net.in.tum.de>
Mon, 5 Mar 2012 17:31:35 +0000 (17:31 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Mon, 5 Mar 2012 17:31:35 +0000 (17:31 +0000)
src/namestore/gnunet-service-namestore.c
src/namestore/namestore_api.c
src/namestore/test_namestore_api.conf
src/namestore/test_namestore_api_create_update.c
src/namestore/test_namestore_api_lookup_specific_type.c
src/namestore/test_namestore_api_zone_to_name.c

index a3f77dabb2629e9ae03b2ef2cf0aa73c619a0588..40f3c477a43969d35872facfbd2aeef2960a75eb 100644 (file)
@@ -1086,7 +1086,7 @@ handle_zone_to_name_it (void *cls,
   int32_t contains_sig = 0;
   size_t msg_size = 0;
 
-  char *rd_ser;
+  char *rd_ser = NULL;
   char *name_tmp;
   char *rd_tmp;
   char *sig_tmp;
@@ -1094,7 +1094,7 @@ handle_zone_to_name_it (void *cls,
   if ((zone_key != NULL) && (name != NULL))
   {
     /* found result */
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found results: name ist \n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found results: name is `%s', has %u records\n", name, rd_count);
     res = GNUNET_YES;
     name_len = strlen (name);
   }
@@ -1109,7 +1109,7 @@ handle_zone_to_name_it (void *cls,
   if (rd_count > 0)
   {
     rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
-    char rd_ser[rd_ser_len];
+    rd_ser = GNUNET_malloc (rd_ser_len);
     GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
   }
   else
@@ -1120,6 +1120,8 @@ handle_zone_to_name_it (void *cls,
   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);
 
@@ -1136,17 +1138,21 @@ handle_zone_to_name_it (void *cls,
   ztnr_msg->rd_count = htons (rd_count);
   ztnr_msg->name_len = htons (name_len);
   ztnr_msg->contains_sig = htons (contains_sig);
+  ztnr_msg->expire = GNUNET_TIME_absolute_hton(expire);
   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));
+  memcpy (name_tmp, name, name_len);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name is `%s', has %u records, rd ser len %u msg_size %u\n", name, rd_count, rd_ser_len, msg_size);
+  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);
+  GNUNET_free_non_null (rd_ser);
 }
 
 
@@ -1192,7 +1198,7 @@ static void handle_zone_to_name (void *cls,
   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",
+  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);
index 10c4132f6738e1e6e42cf73a245b51d42f5aa879..9634b6d4dda924da8af0beb5fa4d2b400ff180d6 100644 (file)
@@ -478,20 +478,54 @@ handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
   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:
+  struct GNUNET_TIME_Absolute expire;
+  size_t name_len;
+  size_t rd_ser_len;
+  unsigned int rd_count;
+  int have_signature;
+
+  char * name_tmp;
+  char * rd_tmp;
+  struct GNUNET_CRYPTO_RsaSignature* sig_tmp;
+
+  if (res == 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);
+  }
+  else if (res == 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;
   }
+  else if (res == GNUNET_YES)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore has result for zone to name mapping \n");
+
+    name_len = ntohs (msg->name_len);
+    rd_count = ntohs (msg->rd_count);
+    rd_ser_len = ntohs (msg->rd_len);
+    have_signature = ntohl (msg->contains_sig);
+    expire = GNUNET_TIME_absolute_ntoh(msg->expire);
+
+    name_tmp = (char *) &msg[1];
+    rd_tmp = &name_tmp[name_len];
+    if (have_signature == GNUNET_YES)
+      sig_tmp = (struct GNUNET_CRYPTO_RsaSignature *) &rd_tmp[rd_ser_len];
+    else
+      sig_tmp = NULL;
+
+    struct GNUNET_NAMESTORE_RecordData rd[rd_count];
+    GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_tmp, rd_count, rd);
+
+    if (qe->proc != NULL)
+      qe->proc (qe->proc_cls, &msg->zone_key, expire, name_tmp, rd_count, rd, sig_tmp);
+
+  }
+  else
+    GNUNET_break_op (0);
 
   /* Operation done, remove */
   GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe);
index c437b414a1ecb9a1328f885a9054d32ec3f5f8aa..f4cd32dbdc0292d498f10b6b4c78aeaac11a5c7c 100644 (file)
@@ -4,7 +4,7 @@ DEFAULTSERVICES = namestore
 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
index 737c64a3d976eb27bcf1973285d8e6c89de94d60..ca2cde10c4ac33776f8b566ab6a79453acb8181a 100644 (file)
@@ -325,7 +325,7 @@ create_updated_cont (void *cls, int32_t success, const char *emsg)
   if (success == GNUNET_NO)
   {
     res = 0;
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updated record for name `%s'\n", name);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updated record for name `%s'\n", name);
   }
   else if (success == GNUNET_OK)
   {
index 8ffa9ca2c5f4ac399a0b2060fd813f8a82012353..3f209885837757d4d629dcb851af3f4934d66fc7 100644 (file)
@@ -258,7 +258,7 @@ put_cont (void *cls, int32_t success, const char *emsg)
   if (success == GNUNET_OK)
   {
     res = 0;
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Looking up non-existing record type %u for name `%s'\n", TEST_RECORD_LOOKUP_TYPE_NOT_EXISTING, name);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up non-existing record type %u for name `%s'\n", TEST_RECORD_LOOKUP_TYPE_NOT_EXISTING, name);
     GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, TEST_RECORD_LOOKUP_TYPE_NOT_EXISTING, &name_lookup_non_existing_record_type, NULL);
   }
   else
index 387d582720f87e7f8bb17a5648c335570d16a306..bd03987d541a3cef1cb7487c595846dd8535b4a0 100644 (file)
 
 #define VERBOSE GNUNET_NO
 
+#define RECORDS 5
+#define TEST_RECORD_TYPE 1234
+#define TEST_RECORD_DATALEN 123
+#define TEST_RECORD_DATA 'a'
+
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
 
 static struct GNUNET_NAMESTORE_Handle * nsh;
@@ -39,9 +44,16 @@ static struct GNUNET_OS_Process *arm;
 static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
 
+struct GNUNET_TIME_Absolute expire;
+
 static GNUNET_HashCode s_zone;
 static GNUNET_HashCode s_zone_value;
 
+char * s_name;
+
+struct GNUNET_NAMESTORE_RecordData *s_rd;
+struct GNUNET_CRYPTO_RsaSignature *s_signature;
+
 static int res;
 
 static void
@@ -123,17 +135,37 @@ void zone_to_name_proc (void *cls,
                             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))
+  int fail = GNUNET_NO;
+
+  if ((zone_key == NULL) && (n == NULL) && (rd_count == 0) && (rd == NULL) && (signature == NULL))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No result found\n");
+    res = 1;
+  }
+  else
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result found: `%s'\n", n);
+    if (0 != strcmp(n, s_name))
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No result found\n");
-      res = 0;
+      fail = GNUNET_YES;
+      GNUNET_break (0);
     }
-    else
+    if (rd_count != 1)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result found\n");
-      res = 0;
+      fail = GNUNET_YES;
+      GNUNET_break (0);
     }
-    GNUNET_SCHEDULER_add_now(&end, NULL);
+    if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
+    {
+      fail = GNUNET_YES;
+      GNUNET_break (0);
+    }
+    if (fail == GNUNET_NO)
+      res = 0;
+    else
+      res = 1;
+  }
+  GNUNET_SCHEDULER_add_now(&end, NULL);
 }
 
 
@@ -155,6 +187,28 @@ delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
 
 }
 
+
+void
+put_cont (void *cls, int32_t success, const char *emsg)
+{
+  char *name = cls;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
+  if (success == GNUNET_OK)
+  {
+    res = 0;
+
+    /* create initial record */
+    GNUNET_NAMESTORE_zone_to_name (nsh, &s_zone, &s_zone_value, zone_to_name_proc, NULL);
+
+  }
+  else
+  {
+    res = 1;
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name);
+    GNUNET_SCHEDULER_add_now(&end, NULL);
+  }
+}
+
 static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -162,6 +216,8 @@ run (void *cls, char *const *args, const char *cfgfile,
   delete_existing_db(cfg);
 
   endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
+  GNUNET_asprintf(&s_name, "dummy.dummy.gnunet");
+
 
   /* load privat key */
   privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
@@ -171,7 +227,14 @@ run (void *cls, char *const *args, const char *cfgfile,
 
   /* 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);
+  GNUNET_CRYPTO_hash (s_name, strlen (s_name) + 1, &s_zone_value);
+
+  struct GNUNET_NAMESTORE_RecordData rd;
+  rd.expiration = GNUNET_TIME_absolute_get();
+  rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
+  rd.data_size = sizeof (GNUNET_HashCode);
+  rd.data = GNUNET_malloc(sizeof (GNUNET_HashCode));
+  memcpy ((char *) rd.data, &s_zone_value, sizeof (GNUNET_HashCode));
 
   start_arm (cfgfile);
   GNUNET_assert (arm != NULL);
@@ -179,8 +242,11 @@ run (void *cls, char *const *args, const char *cfgfile,
   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);
+  expire = GNUNET_TIME_absolute_get ();
+  s_signature = GNUNET_NAMESTORE_create_signature(privkey, s_name, &rd, 1);
+  GNUNET_NAMESTORE_record_put(nsh, &pubkey, s_name, expire, 1, &rd, s_signature, put_cont, NULL);
+
+  GNUNET_free ((void *) rd.data);
 }
 
 static int