aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwachs <wachs@140774ce-b5e7-0310-ab8b-a85725594a96>2012-03-05 17:31:35 +0000
committerwachs <wachs@140774ce-b5e7-0310-ab8b-a85725594a96>2012-03-05 17:31:35 +0000
commit612046db2dacc0420e4d21da2e76854371c5388a (patch)
tree157328b1b4c3310b8ce2549565baf08a3ec973e8
parent715cf3d7297658ab380dc6e32f7fbd5e9253c789 (diff)
- changes
git-svn-id: https://gnunet.org/svn/gnunet@20284 140774ce-b5e7-0310-ab8b-a85725594a96
-rw-r--r--src/namestore/gnunet-service-namestore.c20
-rw-r--r--src/namestore/namestore_api.c54
-rw-r--r--src/namestore/test_namestore_api.conf2
-rw-r--r--src/namestore/test_namestore_api_create_update.c2
-rw-r--r--src/namestore/test_namestore_api_lookup_specific_type.c2
-rw-r--r--src/namestore/test_namestore_api_zone_to_name.c86
6 files changed, 136 insertions, 30 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index a3f77dabb2..40f3c477a4 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -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);
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 10c4132f67..9634b6d4dd 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -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);
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf
index c437b414a1..f4cd32dbdc 100644
--- a/src/namestore/test_namestore_api.conf
+++ b/src/namestore/test_namestore_api.conf
@@ -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
diff --git a/src/namestore/test_namestore_api_create_update.c b/src/namestore/test_namestore_api_create_update.c
index 737c64a3d9..ca2cde10c4 100644
--- a/src/namestore/test_namestore_api_create_update.c
+++ b/src/namestore/test_namestore_api_create_update.c
@@ -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)
{
diff --git a/src/namestore/test_namestore_api_lookup_specific_type.c b/src/namestore/test_namestore_api_lookup_specific_type.c
index 8ffa9ca2c5..3f20988583 100644
--- a/src/namestore/test_namestore_api_lookup_specific_type.c
+++ b/src/namestore/test_namestore_api_lookup_specific_type.c
@@ -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
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c
index 387d582720..bd03987d54 100644
--- a/src/namestore/test_namestore_api_zone_to_name.c
+++ b/src/namestore/test_namestore_api_zone_to_name.c
@@ -29,6 +29,11 @@
#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