[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r36348 - gnunet/src/namestore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r36348 - gnunet/src/namestore |
Date: |
Thu, 10 Sep 2015 16:42:18 +0200 |
Author: schanzen
Date: 2015-09-10 16:42:18 +0200 (Thu, 10 Sep 2015)
New Revision: 36348
Modified:
gnunet/src/namestore/plugin_namestore_flat.c
gnunet/src/namestore/plugin_rest_namestore.c
gnunet/src/namestore/test_plugin_namestore_flat.conf
Log:
- update
Modified: gnunet/src/namestore/plugin_namestore_flat.c
===================================================================
--- gnunet/src/namestore/plugin_namestore_flat.c 2015-09-08 01:36:44 UTC
(rev 36347)
+++ gnunet/src/namestore/plugin_namestore_flat.c 2015-09-10 14:42:18 UTC
(rev 36348)
@@ -93,11 +93,6 @@
struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key;
/**
- * Entry zone pkey
- */
- struct GNUNET_CRYPTO_EcdsaPublicKey *pkey;
-
- /**
* Record cound
*/
uint32_t record_count;
@@ -113,6 +108,11 @@
struct GNUNET_GNSRECORD_Data *record_data;
/**
+ * Record data size
+ */
+ size_t data_size;
+
+ /**
* Label
*/
char *label;
@@ -136,7 +136,6 @@
char *key_str;
char *record_data;
char *zone_private_key;
- char *pkey;
char *record_data_b64;
char *buffer;
char *line;
@@ -210,53 +209,60 @@
}
GNUNET_DISK_file_close (fh);
-
- line = strtok ("\n", buffer);
- while (line != NULL) {
- zone_private_key = strtok (",", line);
- pkey = strtok (NULL, line);
- rvalue = strtok (NULL, line);
- record_count = strtok (NULL, line);
- record_data_b64 = strtok (NULL, line);
- label = strtok (NULL, line);
- line = strtok ("\n", buffer);
- entry = GNUNET_malloc (sizeof (struct FlatFileEntry));
- GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey,
- strlen (pkey),
- entry->pkey);
- sscanf (rvalue, "%lu", &entry->rvalue);
- sscanf (record_count, "%u", &entry->record_count);
- entry->label = GNUNET_strdup (label);
- record_data_size = GNUNET_STRINGS_base64_decode (record_data_b64,
- strlen (record_data_b64),
- &record_data);
- entry->record_data =
- GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Data) *
entry->record_count);
- GNUNET_GNSRECORD_records_deserialize (record_data_size,
- record_data,
- entry->record_count,
- entry->record_data);
- GNUNET_free (record_data);
- GNUNET_STRINGS_base64_decode (zone_private_key,
- strlen (zone_private_key),
- (char**)&entry->private_key);
- key_str = GNUNET_malloc (strlen (label) + sizeof (struct
GNUNET_CRYPTO_EcdsaPrivateKey));
- memcpy (key_str, label, strlen (label));
- memcpy (key_str+strlen(label),
- entry->private_key,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
- GNUNET_CRYPTO_hash (key_str,
- strlen (key_str),
- &hkey);
- GNUNET_free (key_str);
- if (GNUNET_OK !=
- GNUNET_CONTAINER_multihashmap_put (plugin->hm,
- &hkey,
- entry,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
- {
- GNUNET_free (entry);
- GNUNET_break (0);
+ if (0 < size) {
+ line = strtok (buffer, "\n");
+ while (line != NULL) {
+ zone_private_key = strtok (line, ",");
+ if (NULL == zone_private_key)
+ break;
+ rvalue = strtok (NULL, ",");
+ if (NULL == rvalue)
+ break;
+ record_count = strtok (NULL, ",");
+ if (NULL == record_count)
+ break;
+ record_data_b64 = strtok (NULL, ",");
+ if (NULL == record_data_b64)
+ break;
+ label = strtok (NULL, ",");
+ if (NULL == label)
+ break;
+ line = strtok (NULL, "\n");
+ entry = GNUNET_malloc (sizeof (struct FlatFileEntry));
+ sscanf (rvalue, "%lu", &entry->rvalue);
+ sscanf (record_count, "%u", &entry->record_count);
+ entry->label = GNUNET_strdup (label);
+ record_data_size = GNUNET_STRINGS_base64_decode (record_data_b64,
+ strlen
(record_data_b64),
+ &record_data);
+ entry->record_data =
+ GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Data) *
entry->record_count);
+ GNUNET_GNSRECORD_records_deserialize (record_data_size,
+ record_data,
+ entry->record_count,
+ entry->record_data);
+ GNUNET_free (record_data);
+ GNUNET_STRINGS_base64_decode (zone_private_key,
+ strlen (zone_private_key),
+ (char**)&entry->private_key);
+ key_str = GNUNET_malloc (strlen (label) + sizeof (struct
GNUNET_CRYPTO_EcdsaPrivateKey));
+ memcpy (key_str, label, strlen (label));
+ memcpy (key_str+strlen(label),
+ entry->private_key,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
+ GNUNET_CRYPTO_hash (key_str,
+ strlen (key_str),
+ &hkey);
+ GNUNET_free (key_str);
+ if (GNUNET_OK !=
+ GNUNET_CONTAINER_multihashmap_put (plugin->hm,
+ &hkey,
+ entry,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ {
+ GNUNET_free (entry);
+ GNUNET_break (0);
+ }
}
}
GNUNET_free (buffer);
@@ -278,37 +284,23 @@
struct FlatFileEntry *entry = value;
char *line;
char *zone_private_key;
- char *pkey;
char *rvalue;
char *record_count;
- char *record_data_buf;
char *record_data_b64;
- size_t record_data_len;
GNUNET_STRINGS_base64_encode ((char*)entry->private_key,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
&zone_private_key);
- pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (entry->pkey);
- GNUNET_asprintf (&rvalue, "%hhu", entry->rvalue);
+ GNUNET_asprintf (&rvalue, "%lu", entry->rvalue);
GNUNET_asprintf (&record_count, "%u", entry->record_count);
- record_data_len = GNUNET_GNSRECORD_records_get_size (entry->record_count,
- entry->record_data);
-
- record_data_buf = GNUNET_malloc (record_data_len);
- GNUNET_GNSRECORD_records_serialize (entry->record_count,
- entry->record_data,
- record_data_len,
- record_data_buf);
-
- GNUNET_STRINGS_base64_encode (record_data_buf,
- strlen (record_data_buf),
+ GNUNET_STRINGS_base64_encode ((char*)entry->record_data,
+ entry->data_size,
&record_data_b64);
GNUNET_asprintf (&line,
- "%s,%s,%s,%s,%s,%s\n",
+ "%s,%s,%s,%s,%s\n",
zone_private_key,
- pkey,
rvalue,
record_count,
record_data_b64,
@@ -316,7 +308,6 @@
GNUNET_free (rvalue);
GNUNET_free (record_count);
- GNUNET_free (record_data_buf);
GNUNET_free (record_data_b64);
GNUNET_DISK_file_write (fh,
@@ -324,7 +315,6 @@
strlen (line));
GNUNET_free (entry->private_key);
- GNUNET_free (entry->pkey);
GNUNET_free (entry->label);
GNUNET_free (entry->record_data);
GNUNET_free (entry);
@@ -349,8 +339,8 @@
if (NULL == fh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to initialize file: %s.\n"),
- plugin->fn);
+ _("Unable to initialize file: %s.\n"),
+ plugin->fn);
return;
}
@@ -381,24 +371,12 @@
const struct GNUNET_GNSRECORD_Data *rd)
{
struct Plugin *plugin = cls;
- struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
uint64_t rvalue;
size_t data_size;
- unsigned int i;
char *key_str;
struct GNUNET_HashCode hkey;
struct FlatFileEntry *entry;
- memset (&pkey, 0, sizeof (pkey));
- for (i=0;i<rd_count;i++)
- if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type)
- {
- GNUNET_break (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) ==
rd[i].data_size);
- memcpy (&pkey,
- rd[i].data,
- rd[i].data_size);
- break;
- }
rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
data_size = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
if (data_size > 64 * 65536)
@@ -430,17 +408,17 @@
{
entry = GNUNET_malloc (sizeof (struct FlatFileEntry));
entry->private_key = GNUNET_malloc (sizeof (struct
GNUNET_CRYPTO_EcdsaPrivateKey));
- memcpy (&entry->private_key,
+ GNUNET_asprintf (&entry->label,
+ label,
+ strlen (label));
+ memcpy (entry->private_key,
zone_key,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
- entry->pkey = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
- memcpy (entry->pkey,
- &pkey,
- sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
entry->rvalue = rvalue;
entry->record_count = rd_count;
+ entry->data_size = data_size;
entry->record_data = GNUNET_malloc (data_size);
- memcpy (&entry->record_data, data, data_size);
+ memcpy (entry->record_data, data, data_size);
return GNUNET_CONTAINER_multihashmap_put (plugin->hm,
&hkey,
entry,
@@ -606,8 +584,8 @@
struct Plugin *plugin = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Performing reverse lookup for `%s'\n",
- GNUNET_GNSRECORD_z2s (value_zone));
+ "Performing reverse lookup for `%s'\n",
+ GNUNET_GNSRECORD_z2s (value_zone));
GNUNET_CONTAINER_multihashmap_iterate (plugin->hm,
&zone_to_name,
@@ -647,7 +625,7 @@
api->zone_to_name = &namestore_zone_to_name;
api->lookup_records = &namestore_lookup_records;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("flat file database running\n"));
+ _("flat file database running\n"));
return api;
}
@@ -668,7 +646,7 @@
plugin->cfg = NULL;
GNUNET_free (api);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "flat file plugin is finished\n");
+ "flat file plugin is finished\n");
return NULL;
}
Modified: gnunet/src/namestore/plugin_rest_namestore.c
===================================================================
--- gnunet/src/namestore/plugin_rest_namestore.c 2015-09-08 01:36:44 UTC
(rev 36347)
+++ gnunet/src/namestore/plugin_rest_namestore.c 2015-09-10 14:42:18 UTC
(rev 36348)
@@ -371,6 +371,7 @@
if (NULL == rname)
{
+ handle->list_it = NULL;
//Handle response
if (GNUNET_SYSERR == GNUNET_REST_jsonapi_data_serialize
(handle->resp_object, &result))
{
@@ -379,7 +380,6 @@
}
GNUNET_REST_jsonapi_object_delete (handle->resp_object);
resp = GNUNET_REST_create_json_response (result);
- handle->list_it = NULL;
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
GNUNET_free (result);
GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
@@ -395,8 +395,6 @@
return;
}
- json_resource = GNUNET_REST_jsonapi_resource_new
(GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO,
- rname);
result_array = json_array ();
for (i=0; i<rd_len; i++)
{
@@ -411,10 +409,14 @@
json_array_append (result_array, record_obj);
json_decref (record_obj);
}
+
+ json_resource = GNUNET_REST_jsonapi_resource_new
(GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO,
+ rname);
GNUNET_REST_jsonapi_resource_add_attr (json_resource,
GNUNET_REST_JSONAPI_NAMESTORE_RECORD,
result_array);
GNUNET_REST_jsonapi_object_resource_add (handle->resp_object, json_resource);
+
json_decref (result_array);
GNUNET_NAMESTORE_zone_iterator_next (handle->list_it);
}
@@ -475,8 +477,8 @@
if (0 != rd_count)
{
handle->proc (handle->proc_cls,
- GNUNET_REST_create_json_response (NULL),
- MHD_HTTP_CONFLICT);
+ GNUNET_REST_create_json_response (NULL),
+ MHD_HTTP_CONFLICT);
GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
return;
}
@@ -525,10 +527,10 @@
static void
del_cont (void *cls,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
- const char *label,
- unsigned int rd_count,
- const struct GNUNET_GNSRECORD_Data *rd)
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+ const char *label,
+ unsigned int rd_count,
+ const struct GNUNET_GNSRECORD_Data *rd)
{
struct RequestHandle *handle = cls;
@@ -586,7 +588,7 @@
json_t *value_json;
json_t *record_json;
json_t *exp_json;
-
+
*rd_count = json_array_size (records_json);
*rd = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Data) * *rd_count);
for (i = 0; i < *rd_count; i++)
@@ -622,7 +624,7 @@
value,
&rdata,
&rdata_size))
- {
+ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Value `%s' invalid for record
type `%s'\n"),
value, typestring);
return GNUNET_SYSERR;
@@ -910,6 +912,7 @@
struct GNUNET_HashCode key;
char *ego;
char *name;
+ char *type;
if (result != GNUNET_YES)
{
@@ -931,6 +934,19 @@
ego = GNUNET_CONTAINER_multihashmap_get
(handle->conndata_handle->url_param_map,
&key);
}
+
+ type = GNUNET_GNSRECORD_TYPE_ANY;
+ GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE,
+ strlen (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE),
+ &key);
+ if ( GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_contains
(handle->conndata_handle->url_param_map,
+ &key) )
+ {
+ type = GNUNET_CONTAINER_multihashmap_get
(handle->conndata_handle->url_param_map,
+ &key);
+ }
+ handle->type = GNUNET_GNSRECORD_typename_to_number (type);
name = get_name_from_url (handle->url);
if (NULL != ego)
GNUNET_asprintf (&handle->ego_name, "%s", ego);
Modified: gnunet/src/namestore/test_plugin_namestore_flat.conf
===================================================================
--- gnunet/src/namestore/test_plugin_namestore_flat.conf 2015-09-08
01:36:44 UTC (rev 36347)
+++ gnunet/src/namestore/test_plugin_namestore_flat.conf 2015-09-10
14:42:18 UTC (rev 36348)
@@ -1,2 +1,5 @@
[namestore-flat]
FILENAME = /tmp/gnunet-test-plugin-namestore-sqlite/flatdb
+
+[namestore]
+PREFIX = valgrind --log-file=/home/schanzen/dev/gnunet/src/namestore/vg_log
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r36348 - gnunet/src/namestore,
gnunet <=