[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r27691 - in gnunet/src: include namestore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r27691 - in gnunet/src: include namestore |
Date: |
Sun, 30 Jun 2013 21:21:05 +0200 |
Author: grothoff
Date: 2013-06-30 21:21:05 +0200 (Sun, 30 Jun 2013)
New Revision: 27691
Added:
gnunet/src/namestore/namestore_api_common.c
gnunet/src/namestore/namestore_api_monitor.c
Removed:
gnunet/src/namestore/namestore_common.c
Modified:
gnunet/src/include/gnunet_namestore_service.h
gnunet/src/include/gnunet_protocols.h
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/plugin_namestore_sqlite.c
gnunet/src/namestore/test_namestore_api_create.c
gnunet/src/namestore/test_namestore_api_create_update.c
gnunet/src/namestore/test_namestore_api_remove.c
gnunet/src/namestore/test_namestore_api_remove_not_existing_record.c
gnunet/src/namestore/test_namestore_api_zone_iteration.c
gnunet/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
gnunet/src/namestore/test_namestore_api_zone_iteration_stop.c
gnunet/src/namestore/test_namestore_api_zone_to_name.c
Log:
-towards implementing improved namestore API
Modified: gnunet/src/include/gnunet_namestore_service.h
===================================================================
--- gnunet/src/include/gnunet_namestore_service.h 2013-06-30 19:14:53 UTC
(rev 27690)
+++ gnunet/src/include/gnunet_namestore_service.h 2013-06-30 19:21:05 UTC
(rev 27691)
@@ -371,7 +371,18 @@
GNUNET_NAMESTORE_RecordProcessor proc, void
*proc_cls);
+/**
+ * Cancel a namestore operation. The final callback from the
+ * operation must not have been done yet. Must be called on any
+ * namestore operation that has not yet completed prior to calling
+ * 'GNUNET_NAMESTORE_disconnect'.
+ *
+ * @param qe operation to cancel
+ */
+void
+GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
+
/**
* Starts a new zone iteration (used to periodically PUT all of our
* records into our DHT). "proc" will be called once immediately, and
@@ -447,7 +458,13 @@
* Function called whenever the records for a given name changed.
*
* @param cls closure
- * @param was_removed GNUNET_NO if the record was added, GNUNET_YES if it was
removed
+ * @param was_removed GNUNET_NO if the record was added, GNUNET_YES if it was
removed,
+ * GNUNET_SYSERR if the communication with the namestore
broke down
+ * (and thus all entries should be 'cleared' until the
communication
+ * can be re-established, at which point the monitor will
+ * re-add all records that are (still) in the namestore
after
+ * the reconnect); if this value is SYSERR, all other
arguments
+ * will be 0/NULL.
* @param freshness when does the corresponding block in the DHT expire (until
* when should we never do a DHT lookup for the same name
again)?;
* GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type
in the namestore,
@@ -495,18 +512,6 @@
GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm);
-/**
- * Cancel a namestore operation. The final callback from the
- * operation must not have been done yet. Must be called on any
- * namestore operation that has not yet completed prior to calling
- * 'GNUNET_NAMESTORE_disconnect'.
- *
- * @param qe operation to cancel
- */
-void
-GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
-
-
/* convenience APIs for serializing / deserializing GNS records */
/**
@@ -620,6 +625,61 @@
GNUNET_NAMESTORE_is_expired (const struct GNUNET_NAMESTORE_RecordData *rd);
+/**
+ * Convert a UTF-8 string to UTF-8 lowercase
+ * @param src source string
+ * @return converted result
+ */
+char *
+GNUNET_NAMESTORE_normalize_string (const char *src);
+
+
+/**
+ * Convert a short hash to a string (for printing debug messages).
+ * This is one of the very few calls in the entire API that is
+ * NOT reentrant!
+ *
+ * @param hc the short hash code
+ * @return string form; will be overwritten by next call to GNUNET_h2s.
+ */
+const char *
+GNUNET_NAMESTORE_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc);
+
+
+/**
+ * Sign name and records
+ *
+ * @param key the private key
+ * @param expire block expiration
+ * @param name the name
+ * @param rd record data
+ * @param rd_count number of records
+ *
+ * @return the signature
+ */
+struct GNUNET_CRYPTO_EccSignature *
+GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_EccPrivateKey
*key,
+ struct GNUNET_TIME_Absolute expire,
+ const char *name,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ unsigned int rd_count);
+
+
+/**
+ * Compares if two records are equal
+ *
+ * @param a Record a
+ * @param b Record b
+ *
+ * @return GNUNET_YES or GNUNET_NO
+ */
+int
+GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a,
+ const struct GNUNET_NAMESTORE_RecordData *b);
+
+
+
+
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h 2013-06-30 19:14:53 UTC (rev
27690)
+++ gnunet/src/include/gnunet_protocols.h 2013-06-30 19:21:05 UTC (rev
27691)
@@ -1452,16 +1452,6 @@
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE 436
/**
- * Client to service: remove record(s)
- */
-#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE 437
-
-/**
- * Service to client: result of removal request.
- */
-#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE 438
-
-/**
* Client to service: "reverse" lookup for zone name based on zone key
*/
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME 439
Modified: gnunet/src/namestore/Makefile.am
===================================================================
--- gnunet/src/namestore/Makefile.am 2013-06-30 19:14:53 UTC (rev 27690)
+++ gnunet/src/namestore/Makefile.am 2013-06-30 19:21:05 UTC (rev 27691)
@@ -64,7 +64,10 @@
libgnunetnamestore.la
libgnunetnamestore_la_SOURCES = \
- namestore_api.c namestore_common.c namestore.h
+ namestore_api.c \
+ namestore_api_monitor.c \
+ namestore_api_common.c \
+ namestore.h
libgnunetnamestore_la_LIBADD = \
$(top_builddir)/src/statistics/libgnunetstatistics.la \
$(top_builddir)/src/util/libgnunetutil.la \
@@ -111,7 +114,7 @@
$(POSTGRES_PLUGIN)
libgnunet_plugin_namestore_sqlite_la_SOURCES = \
- plugin_namestore_sqlite.c namestore_common.c
+ plugin_namestore_sqlite.c
libgnunet_plugin_namestore_sqlite_la_LIBADD = \
$(top_builddir)/src/namestore/libgnunetnamestore.la \
$(top_builddir)/src/statistics/libgnunetstatistics.la \
@@ -126,7 +129,7 @@
libgnunet_plugin_namestore_postgres_la_SOURCES = \
- plugin_namestore_postgres.c namestore_common.c
+ plugin_namestore_postgres.c
libgnunet_plugin_namestore_postgres_la_LIBADD = \
$(top_builddir)/src/namestore/libgnunetnamestore.la \
$(top_builddir)/src/postgres/libgnunetpostgres.la \
Modified: gnunet/src/namestore/gnunet-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-namestore.c 2013-06-30 19:14:53 UTC (rev
27690)
+++ gnunet/src/namestore/gnunet-namestore.c 2013-06-30 19:21:05 UTC (rev
27691)
@@ -133,8 +133,38 @@
*/
static int ret;
+/**
+ * Type string converted to DNS type value.
+ */
+static uint32_t type;
/**
+ * Value in binary format.
+ */
+static void *data;
+
+/**
+ * Number of bytes in 'data'.
+ */
+static size_t data_size;
+
+/**
+ * Expirationstring converted to relative time.
+ */
+static struct GNUNET_TIME_Relative etime_rel;
+
+/**
+ * Expirationstring converted to absolute time.
+ */
+static struct GNUNET_TIME_Absolute etime_abs;
+
+/**
+ * Is expiration time relative or absolute time?
+ */
+static int etime_is_rel = GNUNET_SYSERR;
+
+
+/**
* Task run on shutdown. Cleans up everything.
*
* @param cls unused
@@ -328,6 +358,69 @@
/**
+ * We're storing a record; this function is given the existing record
+ * so that we can merge the information.
+ *
+ * @param cls closure, unused
+ * @param zone_key public key of the zone
+ * @param freshness when does the corresponding block in the DHT expire (until
+ * when should we never do a DHT lookup for the same name
again)?;
+ * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type
in the namestore,
+ * 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 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)
+ */
+static void
+get_existing_record (void *cls,
+ const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
*zone_key,
+ struct GNUNET_TIME_Absolute freshness,
+ const char *name,
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_EccSignature *signature)
+{
+ struct GNUNET_NAMESTORE_RecordData rdn[rd_count + 1];
+ struct GNUNET_NAMESTORE_RecordData *rde;
+
+ add_qe = NULL;
+ memset (rdn, 0, sizeof (struct GNUNET_NAMESTORE_RecordData));
+ memcpy (&rdn[1], rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
+ /* FIXME: should add some logic to overwrite records if there
+ can only be one record of a particular type, and to check
+ if the combination of records is valid to begin with... */
+ rde = &rdn[0];
+ rde->data = data;
+ rde->data_size = data_size;
+ rde->record_type = type;
+ if (GNUNET_YES == etime_is_rel)
+ {
+ rde->expiration_time = etime_rel.rel_value;
+ rde->flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
+ }
+ else if (GNUNET_NO == etime_is_rel)
+ {
+ rde->expiration_time = etime_abs.abs_value;
+ }
+ if (1 != nonauthority)
+ rde->flags |= GNUNET_NAMESTORE_RF_AUTHORITY;
+ if (1 != public)
+ rde->flags |= GNUNET_NAMESTORE_RF_PRIVATE;
+
+ add_qe = GNUNET_NAMESTORE_record_put_by_authority (ns,
+ zone_pkey,
+ name,
+ rd_count + 1,
+ rde,
+ &add_continuation,
+ &add_qe);
+}
+
+
+/**
* Function called with the result of the ECC key generation.
*
* @param cls our configuration
@@ -341,12 +434,6 @@
{
const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub;
- uint32_t type;
- void *data = NULL;
- size_t data_size = 0;
- struct GNUNET_TIME_Relative etime_rel;
- struct GNUNET_TIME_Absolute etime_abs;
- int etime_is_rel = GNUNET_SYSERR;
struct GNUNET_NAMESTORE_RecordData rd;
keygen = NULL;
@@ -385,138 +472,97 @@
}
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&do_shutdown, NULL);
- if (NULL == typestring)
- type = 0;
- else
- type = GNUNET_NAMESTORE_typename_to_number (typestring);
- if (UINT32_MAX == type)
+ if (add)
{
- fprintf (stderr, _("Unsupported type `%s'\n"), typestring);
- GNUNET_SCHEDULER_shutdown ();
- ret = 1;
- return;
- }
- if ((NULL == typestring) && (add | del))
- {
- fprintf (stderr,
- _("Missing option `%s' for operation `%s'\n"),
- "-t", _("add/del"));
- GNUNET_SCHEDULER_shutdown ();
- ret = 1;
- return;
- }
- if (NULL != value)
- {
- if (GNUNET_OK !=
- GNUNET_NAMESTORE_string_to_value (type,
- value,
- &data,
- &data_size))
- {
- fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"),
- value,
- typestring);
- GNUNET_SCHEDULER_shutdown ();
- ret = 1;
- return;
- }
- } else if (add | del)
- {
- fprintf (stderr,
- _("Missing option `%s' for operation `%s'\n"),
- "-V", _("add/del"));
- ret = 1;
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
- if (NULL != expirationstring)
- {
- if (0 == strcmp (expirationstring, "never"))
+ if (NULL == name)
{
- etime_abs = GNUNET_TIME_UNIT_FOREVER_ABS;
- etime_is_rel = GNUNET_NO;
+ fprintf (stderr,
+ _("Missing option `%s' for operation `%s'\n"),
+ "-n", _("add"));
+ GNUNET_SCHEDULER_shutdown ();
+ ret = 1;
+ return;
}
- else if (GNUNET_OK ==
- GNUNET_STRINGS_fancy_time_to_relative (expirationstring,
- &etime_rel))
+ if (NULL == typestring)
{
- etime_is_rel = GNUNET_YES;
+ fprintf (stderr,
+ _("Missing option `%s' for operation `%s'\n"),
+ "-t", _("add"));
+ GNUNET_SCHEDULER_shutdown ();
+ ret = 1;
+ return;
}
- else if (GNUNET_OK ==
- GNUNET_STRINGS_fancy_time_to_absolute (expirationstring,
- &etime_abs))
+ type = GNUNET_NAMESTORE_typename_to_number (typestring);
+ if (UINT32_MAX == type)
{
- etime_is_rel = GNUNET_NO;
+ fprintf (stderr, _("Unsupported type `%s'\n"), typestring);
+ GNUNET_SCHEDULER_shutdown ();
+ ret = 1;
+ return;
}
- else
+ if (NULL == value)
{
fprintf (stderr,
- _("Invalid time format `%s'\n"),
- expirationstring);
+ _("Missing option `%s' for operation `%s'\n"),
+ "-V", _("add"));
+ ret = 1;
GNUNET_SCHEDULER_shutdown ();
- ret = 1;
return;
}
- if (etime_is_rel && del)
+ if (GNUNET_OK !=
+ GNUNET_NAMESTORE_string_to_value (type,
+ value,
+ &data,
+ &data_size))
{
- fprintf (stderr,
- _("Deletion requires either absolute time, or no time at all.
Got relative time `%s' instead.\n"),
- expirationstring);
+ fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"),
+ value,
+ typestring);
GNUNET_SCHEDULER_shutdown ();
ret = 1;
return;
}
- }
- else if (add)
- {
- fprintf (stderr,
- _("Missing option `%s' for operation `%s'\n"),
- "-e", _("add"));
- GNUNET_SCHEDULER_shutdown ();
- ret = 1;
- return;
- }
- memset (&rd, 0, sizeof (rd));
- if (add)
- {
- if (NULL == name)
+ if (NULL == expirationstring)
{
fprintf (stderr,
- _("Missing option `%s' for operation `%s'\n"),
- "-n", _("add"));
+ _("Missing option `%s' for operation `%s'\n"),
+ "-e", _("add"));
GNUNET_SCHEDULER_shutdown ();
ret = 1;
return;
}
- rd.data = data;
- rd.data_size = data_size;
- rd.record_type = type;
- if (GNUNET_YES == etime_is_rel)
+ if (0 == strcmp (expirationstring, "never"))
{
- rd.expiration_time = etime_rel.rel_value;
- rd.flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
+ etime_abs = GNUNET_TIME_UNIT_FOREVER_ABS;
+ etime_is_rel = GNUNET_NO;
}
- else if (GNUNET_NO == etime_is_rel)
- rd.expiration_time = etime_abs.abs_value;
+ else if (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_time_to_relative (expirationstring,
+ &etime_rel))
+ {
+ etime_is_rel = GNUNET_YES;
+ }
+ else if (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_time_to_absolute (expirationstring,
+ &etime_abs))
+ {
+ etime_is_rel = GNUNET_NO;
+ }
else
{
fprintf (stderr,
- _("No valid expiration time for operation `%s'\n"),
- _("add"));
+ _("Invalid time format `%s'\n"),
+ expirationstring);
GNUNET_SCHEDULER_shutdown ();
ret = 1;
- return;
+ return;
}
- if (1 != nonauthority)
- rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY;
- if (1 != public)
- rd.flags |= GNUNET_NAMESTORE_RF_PRIVATE;
- add_qe = GNUNET_NAMESTORE_record_create (ns,
- zone_pkey,
- name,
- &rd,
- &add_continuation,
- &add_qe);
+ add_qe = GNUNET_NAMESTORE_lookup_record (ns,
+ &zone,
+ name,
+ 0,
+ &get_existing_record,
+ NULL);
}
if (del)
{
@@ -529,19 +575,12 @@
ret = 1;
return;
}
- rd.data = data;
- rd.data_size = data_size;
- rd.record_type = type;
- rd.expiration_time = 0;
- if (!etime_is_rel)
- rd.expiration_time = etime_abs.abs_value;
- rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
- del_qe = GNUNET_NAMESTORE_record_remove (ns,
- zone_pkey,
- name,
- &rd,
- &del_continuation,
- NULL);
+ del_qe = GNUNET_NAMESTORE_record_put_by_authority (ns,
+ zone_pkey,
+ name,
+ 0, NULL,
+ &del_continuation,
+ NULL);
}
if (list)
{
@@ -580,6 +619,7 @@
ret = 1;
return;
}
+ memset (&rd, 0, sizeof (rd));
rd.data = ≻
rd.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode);
rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
@@ -594,16 +634,15 @@
rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value;
if (1 != nonauthority)
rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY;
-
- add_qe_uri = GNUNET_NAMESTORE_record_create (ns,
- zone_pkey,
- name,
- &rd,
- &add_continuation,
- &add_qe_uri);
+ add_qe_uri = GNUNET_NAMESTORE_record_put_by_authority (ns,
+ zone_pkey,
+ name,
+ 1,
+ &rd,
+ &add_continuation,
+ &add_qe_uri);
}
GNUNET_free_non_null (data);
-
}
Modified: gnunet/src/namestore/gnunet-service-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-service-namestore.c 2013-06-30 19:14:53 UTC
(rev 27690)
+++ gnunet/src/namestore/gnunet-service-namestore.c 2013-06-30 19:21:05 UTC
(rev 27691)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2012 Christian Grothoff (and other contributing authors)
+ (C) 2012, 2013 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
@@ -22,6 +22,7 @@
* @file namestore/gnunet-service-namestore.c
* @brief namestore for the GNUnet naming system
* @author Matthias Wachs
+ * @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_util_lib.h"
@@ -250,7 +251,7 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"File zone `%s' containing this key already exists\n",
- GNUNET_short_h2s (&zone));
+ GNUNET_NAMESTORE_short_h2s (&zone));
return GNUNET_OK;
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -279,7 +280,7 @@
GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Stored zonekey for zone `%s' in file `%s'\n",
- GNUNET_short_h2s(&c->zone), c->filename);
+ GNUNET_NAMESTORE_short_h2s(&c->zone), c->filename);
return GNUNET_OK;
}
@@ -305,7 +306,7 @@
GNUNET_asprintf(&c->filename,
"%s/%s.zkey",
zonefile_directory,
- GNUNET_short_h2s (&c->zone));
+ GNUNET_NAMESTORE_short_h2s (&c->zone));
(void) write_key_to_file(c->filename, c);
GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (zonekeys,
key, value));
GNUNET_CRYPTO_ecc_key_free (c->privkey);
@@ -343,7 +344,7 @@
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received new private key for zone `%s'\n",
- GNUNET_short_h2s(&pubkey_hash));
+ GNUNET_NAMESTORE_short_h2s(&pubkey_hash));
cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer));
cc->privkey = pkey;
cc->zone = pubkey_hash;
@@ -611,7 +612,7 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Am authoritative for zone `%s'\n",
- GNUNET_short_h2s (&zone_key_hash));
+ GNUNET_NAMESTORE_short_h2s (&zone_key_hash));
authoritative = GNUNET_YES;
}
}
@@ -645,7 +646,7 @@
copied_elements,
lnc->record_type,
lnc->name,
- GNUNET_short_h2s(lnc->zone));
+ GNUNET_NAMESTORE_short_h2s(lnc->zone));
if (copied_elements > 0)
{
rd_selected = GNUNET_malloc (copied_elements * sizeof (struct
GNUNET_NAMESTORE_RecordData));
@@ -695,7 +696,7 @@
"Found %u matching records for name `%s' in zone `%s'\n",
copied_elements,
lnc->name,
- GNUNET_short_h2s (lnc->zone));
+ GNUNET_NAMESTORE_short_h2s (lnc->zone));
contains_signature = GNUNET_NO;
if (copied_elements > 0)
{
@@ -709,7 +710,7 @@
"Creating signature for name `%s' with %u records in zone
`%s'\n",
name,
copied_elements,
- GNUNET_short_h2s(&zone_key_hash));
+ GNUNET_NAMESTORE_short_h2s(&zone_key_hash));
}
else
{
@@ -828,12 +829,12 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Looking up all records for name `%s' in zone `%s'\n",
name,
- GNUNET_short_h2s(&ln_msg->zone));
+ GNUNET_NAMESTORE_short_h2s(&ln_msg->zone));
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Looking up records with type %u for name `%s' in zone `%s'\n",
type, name,
- GNUNET_short_h2s(&ln_msg->zone));
+ GNUNET_NAMESTORE_short_h2s(&ln_msg->zone));
conv_name = GNUNET_NAMESTORE_normalize_string (name);
if (NULL == conv_name)
@@ -964,7 +965,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Putting %u records under name `%s' in zone `%s'\n",
rd_count, conv_name,
- GNUNET_short_h2s (&zone_hash));
+ GNUNET_NAMESTORE_short_h2s (&zone_hash));
res = GSN_database->put_records(GSN_database->cls,
&rp_msg->public_key,
expire,
@@ -992,156 +993,6 @@
/**
- * Context for record create operations passed from 'handle_record_create' to
- * 'handle_create_record_it' as closure
- */
-struct CreateRecordContext
-{
- /**
- * Record data
- */
- const struct GNUNET_NAMESTORE_RecordData *rd;
-
- /**
- * Zone's public key
- */
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
-
- /**
- * Name for the record to create
- */
- const char *name;
-
- /**
- * Record expiration time
- */
- struct GNUNET_TIME_Absolute expire;
-
- /**
- * result returned from 'handle_create_record_it'
- * GNUNET_SYSERR: failed to create the record
- * GNUNET_NO: we updated an existing record or identical entry existed
- * GNUNET_YES : we created a new record
- */
- int res;
-};
-
-
-/**
- * A 'GNUNET_NAMESTORE_RecordIterator' for record create operations
- * in handle_record_create
- *
- * @param cls a 'struct CreateRecordContext *' with information about the
request
- * @param pubkey zone key of the zone
- * @param expire expiration time
- * @param name name
- * @param rd_count number of records
- * @param rd array of records
- * @param signature signature
- */
-static void
-handle_create_record_it (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
*pubkey,
- struct GNUNET_TIME_Absolute expire,
- const char *name,
- unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- const struct GNUNET_CRYPTO_EccSignature *signature)
-{
- static struct GNUNET_CRYPTO_EccSignature dummy_signature;
- struct CreateRecordContext *crc = cls;
- struct GNUNET_NAMESTORE_RecordData *rd_new;
- struct GNUNET_TIME_Absolute block_expiration;
- int exist;
- int update;
- unsigned int c;
- unsigned int rd_count_new;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found %u existing records for `%s'\n",
- rd_count, crc->name);
- exist = -1;
- update = GNUNET_NO;
- for (c = 0; c < rd_count; c++)
- {
- if ( (crc->rd->record_type != rd[c].record_type) ||
- ((crc->rd->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)
- != (rd[c].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) )
- continue; /* no match */
- if ( (GNUNET_NAMESTORE_TYPE_PKEY == crc->rd->record_type) ||
- (GNUNET_NAMESTORE_TYPE_PSEU == crc->rd->record_type) ||
- (GNUNET_DNSPARSER_TYPE_CNAME == crc->rd->record_type) )
- {
- /* Update unique PKEY, PSEU or CNAME record; for these
- record types, only one can be active at any time */
- exist = c;
- if ( (crc->rd->data_size != rd[c].data_size) ||
- (0 != memcmp (crc->rd->data, rd[c].data, rd[c].data_size)) ||
- (crc->rd->expiration_time != rd[c].expiration_time) )
- update = GNUNET_YES;
- break;
- }
- if ( (crc->rd->data_size == rd[c].data_size) &&
- (0 == memcmp (crc->rd->data, rd[c].data, rd[c].data_size)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found matching existing record for `%s'; only updating
expiration date!\n",
- crc->name);
- exist = c;
- if (crc->rd->expiration_time != rd[c].expiration_time)
- update = GNUNET_YES;
- break;
- }
- }
-
- if ( (-1 != exist) &&
- (GNUNET_NO == update) )
- {
- /* Exact same record already exists */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Matching record for %s' exists, no change required!\n",
- crc->name);
- crc->res = GNUNET_NO; /* identical record existed */
- return;
- }
- if (-1 == exist)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No existing record for name `%s'!\n",
- crc->name);
- rd_count_new = rd_count + 1;
- rd_new = GNUNET_malloc (rd_count_new * sizeof (struct
GNUNET_NAMESTORE_RecordData));
- memcpy (rd_new, rd, rd_count * sizeof (struct
GNUNET_NAMESTORE_RecordData));
- rd_new[rd_count] = *(crc->rd);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Updating existing records for `%s'!\n",
- crc->name);
- rd_count_new = rd_count;
- rd_new = GNUNET_malloc (rd_count_new * sizeof (struct
GNUNET_NAMESTORE_RecordData));
- memcpy (rd_new, rd, rd_count * sizeof (struct
GNUNET_NAMESTORE_RecordData));
- rd_new[exist] = *(crc->rd);
- }
- block_expiration = GNUNET_TIME_absolute_max (crc->expire, expire);
- if (GNUNET_OK !=
- GSN_database->put_records (GSN_database->cls,
- &crc->pubkey,
- block_expiration,
- crc->name,
- rd_count_new, rd_new,
- &dummy_signature))
- crc->res = GNUNET_SYSERR; /* error */
- else if (GNUNET_YES == update)
- crc->res = GNUNET_NO; /* update */
- else
- crc->res = GNUNET_YES; /* created new record */
- GNUNET_free (rd_new);
-}
-
-
-/**
* Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE' message
*
* @param cls unused
@@ -1153,9 +1004,9 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
+ static struct GNUNET_CRYPTO_EccSignature dummy_signature;
struct GNUNET_NAMESTORE_Client *nc;
const struct RecordCreateMessage *rp_msg;
- struct CreateRecordContext crc;
struct GNUNET_CRYPTO_EccPrivateKey *pkey;
struct RecordCreateResponseMessage rcr_msg;
size_t name_len;
@@ -1170,8 +1021,8 @@
const char *rd_ser;
unsigned int rd_count;
int res;
- struct GNUNET_NAMESTORE_RecordData rd;
struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
+ struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' message\n", "NAMESTORE_RECORD_CREATE");
@@ -1195,7 +1046,7 @@
rd_ser_len = ntohs (rp_msg->rd_len);
key_len = ntohs (rp_msg->pkey_len);
msg_size_exp = sizeof (struct RecordCreateMessage) + key_len + name_len +
rd_ser_len;
- if ( (msg_size != msg_size_exp) || (1 != rd_count) )
+ if (msg_size != msg_size_exp)
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -1223,56 +1074,59 @@
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- if (GNUNET_OK !=
- GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, &rd))
{
- GNUNET_break (0);
- GNUNET_CRYPTO_ecc_key_free (pkey);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ struct GNUNET_NAMESTORE_RecordData rd[rd_count];
- /* Extracting and converting private key */
- GNUNET_CRYPTO_ecc_key_get_public (pkey, &crc.pubkey);
- GNUNET_CRYPTO_short_hash (&crc.pubkey,
- sizeof (struct
GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
- &pubkey_hash);
- learn_private_key (pkey);
+ if (GNUNET_OK !=
+ GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, rd))
+ {
+ GNUNET_break (0);
+ GNUNET_CRYPTO_ecc_key_free (pkey);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
- conv_name = GNUNET_NAMESTORE_normalize_string(name_tmp);
- if (NULL == conv_name)
- {
+ /* Extracting and converting private key */
+ GNUNET_CRYPTO_ecc_key_get_public (pkey, &pubkey);
+ GNUNET_CRYPTO_short_hash (&pubkey,
+ sizeof (struct
GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+ &pubkey_hash);
+ learn_private_key (pkey);
+ conv_name = GNUNET_NAMESTORE_normalize_string (name_tmp);
+ if (NULL == conv_name)
+ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Error converting name `%s'\n", name_tmp);
+ GNUNET_CRYPTO_ecc_key_free (pkey);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating %u records for name `%s' in zone `%s'\n",
+ (unsigned int) rd_count,
+ conv_name,
+ GNUNET_NAMESTORE_short_h2s (&pubkey_hash));
+ if (0 == rd_count)
+ res = GSN_database->remove_records (GSN_database->cls,
+ &pubkey_hash,
+ conv_name);
+ else
+ res = GSN_database->put_records (GSN_database->cls,
+ &pubkey,
+
GNUNET_TIME_absolute_ntoh(rp_msg->expire),
+ conv_name,
+ rd_count, rd,
+ &dummy_signature);
+ GNUNET_free (conv_name);
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating record for name `%s' in zone `%s'\n",
- conv_name, GNUNET_short_h2s(&pubkey_hash));
- crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire);
- crc.res = GNUNET_SYSERR;
- crc.rd = &rd;
- crc.name = conv_name;
-
- /* Get existing records for name */
- res = GSN_database->iterate_records (GSN_database->cls, &pubkey_hash,
conv_name, 0,
- &handle_create_record_it, &crc);
- GNUNET_free (conv_name);
- if (res != GNUNET_SYSERR)
- res = GNUNET_OK;
-
+
/* Send response */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending `%s' message\n", "RECORD_CREATE_RESPONSE");
rcr_msg.gns_header.header.type = htons
(GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE);
rcr_msg.gns_header.header.size = htons (sizeof (struct
RecordCreateResponseMessage));
rcr_msg.gns_header.r_id = htonl (rid);
- if ((GNUNET_OK == res) && (crc.res == GNUNET_YES))
- rcr_msg.op_result = htonl (GNUNET_YES);
- else if ((GNUNET_OK == res) && (crc.res == GNUNET_NO))
- rcr_msg.op_result = htonl (GNUNET_NO);
- else
- rcr_msg.op_result = htonl (GNUNET_SYSERR);
+ rcr_msg.op_result = htonl (res);
GNUNET_SERVER_notification_context_unicast (snc, nc->client,
&rcr_msg.gns_header.header,
GNUNET_NO);
@@ -1281,305 +1135,6 @@
/**
- * Context for record remove operations passed from 'handle_record_remove' to
- * 'handle_record_remove_it' as closure
- */
-struct RemoveRecordContext
-{
- /**
- * Record to remove
- */
- const struct GNUNET_NAMESTORE_RecordData *rd;
-
- /**
- * See RECORD_REMOVE_RESULT_*-codes. Set by 'handle_record_remove_it'
- * to the result of the operation.
- */
- int32_t op_res;
-};
-
-
-/**
- * We are to remove a record (or all records for a given name). This function
- * will be called with the existing records (if there are any) and is to then
- * compute what to keep and trigger the necessary changes.
- *
- * @param cls the 'struct RecordRemoveContext' with information about what to
remove
- * @param zone_key public key of the zone
- * @param expire when does the corresponding block in the DHT expire (until
- * when should we never do a DHT lookup for the same name again)?
- * @param name name that is being mapped (at most 255 characters long)
- * @param rd_count 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)
- */
-static void
-handle_record_remove_it (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
*zone_key,
- struct GNUNET_TIME_Absolute expire,
- const char *name,
- unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- const struct GNUNET_CRYPTO_EccSignature *signature)
-{
- static struct GNUNET_CRYPTO_EccSignature dummy_signature;
- struct RemoveRecordContext *rrc = cls;
- unsigned int c;
- int found;
- struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Name `%s 'currently has %u records\n",
- name, rd_count);
- if (0 == rd_count)
- {
- /* Could not find record to remove */
- rrc->op_res = RECORD_REMOVE_RESULT_NO_RECORDS;
- return;
- }
- /* Find record to remove */
- found = -1;
- for (c = 0; c < rd_count; c++)
- {
- if (GNUNET_YES !=
- GNUNET_NAMESTORE_records_cmp (&rd[c],
- rrc->rd))
- continue;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found record to remove!\n",
rd_count);
- found = c;
- break;
- }
- if (-1 == found)
- {
- /* Could not find record to remove */
- rrc->op_res = RECORD_REMOVE_RESULT_RECORD_NOT_FOUND;
- return;
- }
- if (1 == rd_count)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No records left for name `%s', removing name\n",
- name);
- GNUNET_CRYPTO_short_hash (zone_key,
- sizeof (struct
GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
- &pubkey_hash);
- if (GNUNET_OK !=
- GSN_database->remove_records (GSN_database->cls,
- &pubkey_hash,
- name))
- {
- /* Could not remove records from database */
- rrc->op_res = RECORD_REMOVE_RESULT_FAILED_TO_REMOVE;
- return;
- }
- rrc->op_res = RECORD_REMOVE_RESULT_SUCCESS;
- return;
- }
-
- {
- struct GNUNET_NAMESTORE_RecordData rd_new[rd_count - 1];
- unsigned int c2 = 0;
-
- for (c = 0; c < rd_count; c++)
- {
- if (c == found)
- continue;
- rd_new[c2++] = rd[c];
- }
- if (GNUNET_OK !=
- GSN_database->put_records(GSN_database->cls,
- zone_key,
- expire,
- name,
- rd_count - 1, rd_new,
- &dummy_signature))
- {
- /* Could not put records into database */
- rrc->op_res = RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE;
- return;
- }
- }
- rrc->op_res = RECORD_REMOVE_RESULT_SUCCESS;
-}
-
-
-/**
- * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE' message
- *
- * @param cls unused
- * @param client GNUNET_SERVER_Client sending the message
- * @param message message of type 'struct RecordRemoveMessage'
- */
-static void
-handle_record_remove (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- struct GNUNET_NAMESTORE_Client *nc;
- const struct RecordRemoveMessage *rr_msg;
- struct RecordRemoveResponseMessage rrr_msg;
- struct GNUNET_CRYPTO_EccPrivateKey *pkey;
- struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub;
- struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
- struct GNUNET_NAMESTORE_RecordData rd;
- const char *pkey_tmp;
- const char *name_tmp;
- const char *rd_ser;
- char * conv_name;
- size_t key_len;
- size_t name_len;
- size_t rd_ser_len;
- size_t msg_size;
- size_t msg_size_exp;
- uint32_t rd_count;
- uint32_t rid;
- struct RemoveRecordContext rrc;
- int res;
- uint64_t off;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message\n",
- "NAMESTORE_RECORD_REMOVE");
- if (ntohs (message->size) < sizeof (struct RecordRemoveMessage))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- if (NULL == (nc = client_lookup(client)))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- rr_msg = (const struct RecordRemoveMessage *) message;
- rid = ntohl (rr_msg->gns_header.r_id);
- name_len = ntohs (rr_msg->name_len);
- rd_ser_len = ntohs (rr_msg->rd_len);
- rd_count = ntohs (rr_msg->rd_count);
- key_len = ntohs (rr_msg->pkey_len);
- msg_size = ntohs (message->size);
- if ((name_len >= MAX_NAME_LEN) || (0 == name_len) || (1 < rd_count) )
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- msg_size_exp = sizeof (struct RecordRemoveMessage) + key_len + name_len +
rd_ser_len;
- if (msg_size != msg_size_exp)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- pkey_tmp = (const char *) &rr_msg[1];
- name_tmp = &pkey_tmp[key_len];
- rd_ser = &name_tmp[name_len];
- if ('\0' != name_tmp[name_len -1])
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- if (NULL == (pkey = GNUNET_CRYPTO_ecc_decode_key (pkey_tmp, key_len,
- GNUNET_NO)))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- GNUNET_CRYPTO_ecc_key_get_public (pkey, &pub);
- GNUNET_CRYPTO_short_hash (&pub,
- sizeof (struct
GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
- &pubkey_hash);
- learn_private_key (pkey);
- if (GNUNET_OK !=
- GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, &rd))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
-
- conv_name = GNUNET_NAMESTORE_normalize_string(name_tmp);
- if (NULL == conv_name)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Error converting name `%s'\n", name_tmp);
- return;
- }
-
- if (0 == rd_count)
- {
- /* remove the whole name and all records */
- res = GSN_database->remove_records (GSN_database->cls,
- &pubkey_hash,
- conv_name);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removing name `%s': %s\n",
- conv_name, (GNUNET_OK == res) ? "OK" : "FAILED");
- if (GNUNET_OK != res)
- /* Could not remove entry from database */
- res = RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE;
- else
- res = RECORD_REMOVE_RESULT_SUCCESS;
- }
- else
- {
- /* remove a single record */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removing record for name `%s' in zone `%s'\n", conv_name,
- GNUNET_short_h2s (&pubkey_hash));
- rrc.rd = &rd;
- rrc.op_res = RECORD_REMOVE_RESULT_RECORD_NOT_FOUND;
- off = 0;
- res = GNUNET_OK;
- while ( (RECORD_REMOVE_RESULT_RECORD_NOT_FOUND == rrc.op_res) &&
- (GNUNET_OK == res) )
- {
- res = GSN_database->iterate_records (GSN_database->cls,
- &pubkey_hash,
- conv_name,
- off++,
- &handle_record_remove_it, &rrc);
- }
- switch (res)
- {
- case GNUNET_OK:
- res = rrc.op_res;
- break;
- case GNUNET_NO:
- GNUNET_break (RECORD_REMOVE_RESULT_NO_RECORDS == rrc.op_res);
- res = RECORD_REMOVE_RESULT_NO_RECORDS;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to find record to remove\n"));
- break;
- case GNUNET_SYSERR:
- res = RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE;
- break;
- default:
- GNUNET_break (0);
- res = RECORD_REMOVE_RESULT_FAILED_INTERNAL_ERROR;
- break;
- }
- }
- GNUNET_free (conv_name);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending `%s' message\n",
- "RECORD_REMOVE_RESPONSE");
- rrr_msg.gns_header.header.type = htons
(GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE);
- rrr_msg.gns_header.header.size = htons (sizeof (struct
RecordRemoveResponseMessage));
- rrr_msg.gns_header.r_id = htonl (rid);
- rrr_msg.op_result = htonl (res);
- GNUNET_SERVER_notification_context_unicast (snc, nc->client,
- &rrr_msg.gns_header.header,
- GNUNET_NO);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
-}
-
-
-/**
* Context for record remove operations passed from 'handle_zone_to_name' to
* 'handle_zone_to_name_it' as closure
*/
@@ -1891,7 +1446,7 @@
expire = get_block_expiration_time (rd_count_filtered, rd_filtered);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Creating signature for `%s' in zone `%s' with %u records and
expiration %llu\n",
- name, GNUNET_short_h2s(&zone_hash),
+ name, GNUNET_NAMESTORE_short_h2s(&zone_hash),
rd_count_filtered,
(unsigned long long) expire.abs_value);
new_signature = GNUNET_NAMESTORE_create_signature (cc->privkey, expire,
name,
@@ -1905,7 +1460,7 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Using provided signature for `%s' in zone `%s' with %u
records and expiration %llu\n",
- name, GNUNET_short_h2s (&zone_hash), rd_count_filtered,
+ name, GNUNET_NAMESTORE_short_h2s (&zone_hash),
rd_count_filtered,
(unsigned long long) expire.abs_value);
return;
}
@@ -1922,7 +1477,7 @@
if (GNUNET_YES == proc->zi->has_zone)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending name `%s' for iteration over zone `%s'\n",
- name, GNUNET_short_h2s(&proc->zi->zone));
+ name, GNUNET_NAMESTORE_short_h2s(&proc->zi->zone));
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending name `%s' for iteration over all zones\n",
@@ -2000,7 +1555,7 @@
if (GNUNET_YES == zi->has_zone)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"No more results for zone `%s'\n",
- GNUNET_short_h2s(&zi->zone));
+ GNUNET_NAMESTORE_short_h2s(&zi->zone));
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"No more results for all zones\n");
@@ -2058,7 +1613,7 @@
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting to iterate over zone `%s'\n", GNUNET_short_h2s
(&zis_msg->zone));
+ "Starting to iterate over zone `%s'\n",
GNUNET_NAMESTORE_short_h2s (&zis_msg->zone));
zi->zone = zis_msg->zone;
zi->has_zone = GNUNET_YES;
}
@@ -2109,7 +1664,7 @@
if (GNUNET_YES == zi->has_zone)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Stopped zone iteration for zone `%s'\n",
- GNUNET_short_h2s (&zi->zone));
+ GNUNET_NAMESTORE_short_h2s (&zi->zone));
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Stopped zone iteration over all zones\n");
@@ -2233,8 +1788,6 @@
GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT, 0},
{&handle_record_create, NULL,
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, sizeof (struct
ZoneToNameMessage) },
{&handle_iteration_start, NULL,
Modified: gnunet/src/namestore/namestore.h
===================================================================
--- gnunet/src/namestore/namestore.h 2013-06-30 19:14:53 UTC (rev 27690)
+++ gnunet/src/namestore/namestore.h 2013-06-30 19:21:05 UTC (rev 27691)
@@ -31,60 +31,10 @@
*/
#define MAX_NAME_LEN 256
-/**
- * Convert a UTF-8 string to UTF-8 lowercase
- * @param src source string
- * @return converted result
- */
-char *
-GNUNET_NAMESTORE_normalize_string (const char *src);
+GNUNET_NETWORK_STRUCT_BEGIN
-/**
- * Convert a short hash to a string (for printing debug messages).
- * This is one of the very few calls in the entire API that is
- * NOT reentrant!
- *
- * @param hc the short hash code
- * @return string form; will be overwritten by next call to GNUNET_h2s.
- */
-const char *
-GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc);
-
/**
- * Sign name and records
- *
- * @param key the private key
- * @param expire block expiration
- * @param name the name
- * @param rd record data
- * @param rd_count number of records
- *
- * @return the signature
- */
-struct GNUNET_CRYPTO_EccSignature *
-GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_EccPrivateKey
*key,
- struct GNUNET_TIME_Absolute expire,
- const char *name,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- unsigned int rd_count);
-
-
-/**
- * Compares if two records are equal
- *
- * @param a Record a
- * @param b Record b
- *
- * @return GNUNET_YES or GNUNET_NO
- */
-int
-GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a,
- const struct GNUNET_NAMESTORE_RecordData *b);
-
-
-GNUNET_NETWORK_STRUCT_BEGIN
-/**
* A GNS record serialized for network transmission.
*
* Layout is [struct GNUNET_NAMESTORE_NetworkRecord][char[data_size] data]
@@ -352,105 +302,6 @@
/**
- * Remove a record from the namestore
- * Memory layout:
- */
-struct RecordRemoveMessage
-{
- /**
- * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE
- */
- struct GNUNET_NAMESTORE_Header gns_header;
-
- /**
- * Name length
- */
- uint16_t name_len;
-
- /**
- * Length of serialized rd data
- */
- uint16_t rd_len;
-
- /**
- * Number of records contained
- */
- uint16_t rd_count;
-
- /**
- * Length of private key
- */
- uint16_t pkey_len;
-
- /* followed by:
- * GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded private key with length pkey_len
- * name with length name_len
- * serialized record data with length rd_len
- * */
-};
-
-
-/**
- * Removal of the record succeeded.
- */
-#define RECORD_REMOVE_RESULT_SUCCESS 0
-
-/**
- * There are NO records for the given name.
- */
-#define RECORD_REMOVE_RESULT_NO_RECORDS 1
-
-/**
- * The specific record that was to be removed was
- * not found.
- */
-#define RECORD_REMOVE_RESULT_RECORD_NOT_FOUND 2
-
-/**
- * Internal error, failed to sign the remaining records.
- * (Note: not used?)
- */
-#define RECORD_REMOVE_RESULT_FAILED_TO_SIGN 3
-
-/**
- * Internal error, failed to store the updated record set
- */
-#define RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE 4
-
-/**
- * Internal error, failed to remove records from database
- */
-#define RECORD_REMOVE_RESULT_FAILED_TO_REMOVE 5
-
-/**
- * Internal error, failed to access database
- */
-#define RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE 6
-
-/**
- * Internal error, failed to access database
- */
-#define RECORD_REMOVE_RESULT_FAILED_INTERNAL_ERROR 7
-
-
-/**
- * Remove a record from the namestore response
- */
-struct RecordRemoveResponseMessage
-{
- /**
- * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE
- */
- struct GNUNET_NAMESTORE_Header gns_header;
-
- /**
- * Result code (see RECORD_REMOVE_RESULT_*). In network byte order.
- */
- int32_t op_result;
-};
-
-
-/**
* Lookup a name for a zone hash
*/
struct ZoneToNameMessage
Modified: gnunet/src/namestore/namestore_api.c
===================================================================
--- gnunet/src/namestore/namestore_api.c 2013-06-30 19:14:53 UTC (rev
27690)
+++ gnunet/src/namestore/namestore_api.c 2013-06-30 19:21:05 UTC (rev
27691)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
+ (C) 2010-2013 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
@@ -378,71 +378,6 @@
/**
- * Handle an incoming message of type
'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE'
- *
- * @param qe the respective entry in the message queue
- * @param msg the message we received
- * @param size the message size
- * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify
the client
- */
-static int
-handle_record_remove_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
- const struct RecordRemoveResponseMessage* msg,
- size_t size)
-{
- int ret;
- const char *emsg;
-
- /* Operation done, remove */
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n",
- "RECORD_REMOVE_RESPONSE");
- switch (ntohl (msg->op_result))
- {
- case RECORD_REMOVE_RESULT_SUCCESS:
- ret = GNUNET_OK;
- emsg = NULL;
- break;
- case RECORD_REMOVE_RESULT_NO_RECORDS:
- ret = GNUNET_NO;
- emsg = NULL;
- break;
- case RECORD_REMOVE_RESULT_RECORD_NOT_FOUND:
- ret = GNUNET_NO;
- emsg = NULL;
- break;
- case RECORD_REMOVE_RESULT_FAILED_TO_SIGN:
- ret = GNUNET_SYSERR;
- emsg = _("Failed to create new signature");
- break;
- case RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE:
- ret = GNUNET_SYSERR;
- emsg = _("Failed to put new set of records in database");
- break;
- case RECORD_REMOVE_RESULT_FAILED_TO_REMOVE:
- ret = GNUNET_SYSERR;
- emsg = _("Failed to remove records from database");
- break;
- case RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE:
- ret = GNUNET_SYSERR;
- emsg = _("Failed to access database");
- break;
- case RECORD_REMOVE_RESULT_FAILED_INTERNAL_ERROR:
- ret = GNUNET_SYSERR;
- emsg = _("unknown internal error in namestore");
- break;
- default:
- GNUNET_break (0);
- if (NULL != qe->cont)
- qe->cont (qe->cont_cls, GNUNET_SYSERR, _("Protocol error"));
- return GNUNET_NO;
- }
- if (NULL != qe->cont)
- qe->cont (qe->cont_cls, ret, emsg);
- return GNUNET_OK;
-}
-
-
-/**
* Handle an incoming message of type
'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE'
*
* @param qe the respective entry in the message queue
@@ -554,13 +489,6 @@
return GNUNET_SYSERR;
}
return handle_record_create_response (qe, (const struct
RecordCreateResponseMessage *) msg, size);
- case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE:
- if (size != sizeof (struct RecordRemoveResponseMessage))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- return handle_record_remove_response (qe, (const struct
RecordRemoveResponseMessage *) msg, size);
case GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE:
if (size < sizeof (struct ZoneToNameResponseMessage))
{
@@ -1142,18 +1070,20 @@
* @param h handle to the namestore
* @param pkey private key of the zone
* @param name name that is being mapped (at most 255 characters long)
+ * @param rd_count number of records in 'rd' array
* @param rd record data to store
* @param cont continuation to call when done
* @param cont_cls closure for cont
* @return handle to abort the request
*/
struct GNUNET_NAMESTORE_QueueEntry *
-GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
- const struct GNUNET_CRYPTO_EccPrivateKey *pkey,
- const char *name,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- GNUNET_NAMESTORE_ContinuationWithStatus cont,
- void *cont_cls)
+GNUNET_NAMESTORE_record_put_by_authority (struct GNUNET_NAMESTORE_Handle *h,
+ const struct
GNUNET_CRYPTO_EccPrivateKey *pkey,
+ const char *name,
+ unsigned int rd_count,
+ const struct
GNUNET_NAMESTORE_RecordData *rd,
+
GNUNET_NAMESTORE_ContinuationWithStatus cont,
+ void *cont_cls)
{
struct GNUNET_NAMESTORE_QueueEntry *qe;
struct PendingMessage *pe;
@@ -1171,19 +1101,14 @@
GNUNET_assert (NULL != h);
GNUNET_assert (NULL != pkey);
GNUNET_assert (NULL != name);
- GNUNET_assert (NULL != rd);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Creating record of type %u under name `%s'\n",
- rd->record_type,
- name);
name_len = strlen(name) + 1;
if (name_len > MAX_NAME_LEN)
{
GNUNET_break (0);
return NULL;
}
- rid = get_op_id(h);
- qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
+ rid = get_op_id (h);
+ qe = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_QueueEntry));
qe->nsh = h;
qe->cont = cont;
qe->cont_cls = cont_cls;
@@ -1195,9 +1120,9 @@
/* setup msg */
key_len = ntohs (pkey_enc->size);
- rd_ser_len = GNUNET_NAMESTORE_records_get_size(1, rd);
+ rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
msg_size = sizeof (struct RecordCreateMessage) + key_len + name_len +
rd_ser_len;
- pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
+ pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size);
pe->size = msg_size;
pe->is_init = GNUNET_NO;
msg = (struct RecordCreateMessage *) &pe[1];
@@ -1205,17 +1130,16 @@
msg->gns_header.header.size = htons (msg_size);
msg->gns_header.r_id = htonl (rid);
msg->name_len = htons (name_len);
- msg->rd_count = htons (1);
+ msg->rd_count = htons (rd_count);
msg->rd_len = htons (rd_ser_len);
msg->pkey_len = htons (key_len);
- msg->expire = GNUNET_TIME_absolute_hton(GNUNET_TIME_UNIT_FOREVER_ABS);
+ msg->expire = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS);
pkey_tmp = (char *) &msg[1];
memcpy (pkey_tmp, pkey_enc, key_len);
name_tmp = &pkey_tmp[key_len];
memcpy (name_tmp, name, name_len);
rd_ser = &name_tmp[name_len];
- GNUNET_NAMESTORE_records_serialize(1, rd, rd_ser_len, rd_ser);
-
+ GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
GNUNET_free (pkey_enc);
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1228,98 +1152,6 @@
/**
- * Explicitly remove some content from the database. The
- * "cont"inuation will be called with status "GNUNET_OK" if content
- * was removed, "GNUNET_NO" if no matching entry was found and
- * "GNUNET_SYSERR" on all other types of errors.
- * This API is used by the authority of a zone.
- *
- * @param h handle to the namestore
- * @param pkey private key of the zone
- * @param name name that is being mapped (at most 255 characters long)
- * @param rd record data, remove specific record, NULL to remove the name and
all records
- * @param cont continuation to call when done
- * @param cont_cls closure for cont
- * @return handle to abort the request
- */
-struct GNUNET_NAMESTORE_QueueEntry *
-GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
- const struct GNUNET_CRYPTO_EccPrivateKey *pkey,
- const char *name,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- GNUNET_NAMESTORE_ContinuationWithStatus cont,
- void *cont_cls)
-{
- struct GNUNET_NAMESTORE_QueueEntry *qe;
- struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *pkey_enc;
- struct PendingMessage *pe;
- struct RecordRemoveMessage * msg;
- char *pkey_tmp;
- char *rd_ser;
- char *name_tmp;
- size_t rd_ser_len;
- size_t msg_size;
- size_t name_len;
- size_t key_len;
- uint32_t rid;
- uint16_t rd_count;
-
- GNUNET_assert (NULL != h);
- if (NULL != rd)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Removing record of type %u under name `%s'\n",
- rd->record_type,
- name);
- else
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Removing all records under name `%s'\n",
- name);
- rid = get_op_id(h);
- qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
- qe->nsh = h;
- qe->cont = cont;
- qe->cont_cls = cont_cls;
- qe->op_id = rid;
- GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
-
- pkey_enc = GNUNET_CRYPTO_ecc_encode_key (pkey);
- GNUNET_assert (NULL != pkey_enc);
- key_len = ntohs (pkey_enc->size);
-
- rd_count = (NULL == rd) ? 0 : 1;
- rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
- name_len = strlen (name) + 1;
- msg_size = sizeof (struct RecordRemoveMessage) + key_len + name_len +
rd_ser_len;
- pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size);
- pe->size = msg_size;
- pe->is_init = GNUNET_NO;
- msg = (struct RecordRemoveMessage *) &pe[1];
- msg->gns_header.header.type = htons
(GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE);
- msg->gns_header.header.size = htons (msg_size);
- msg->gns_header.r_id = htonl (rid);
- msg->name_len = htons (name_len);
- msg->rd_len = htons (rd_ser_len);
- msg->rd_count = htons (rd_count);
- msg->pkey_len = htons (key_len);
- pkey_tmp = (char *) &msg[1];
- memcpy (pkey_tmp, pkey_enc, key_len);
- name_tmp = &pkey_tmp[key_len];
- memcpy (name_tmp, name, name_len);
- rd_ser = &name_tmp[name_len];
- GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
-
- GNUNET_free (pkey_enc);
-
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending `%s' message for name `%s' with size %u\n",
- "NAMESTORE_RECORD_REMOVE", name, msg_size);
- GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
- do_transmit(h);
- return qe;
-}
-
-
-/**
* Get a result for a particular key from the namestore. The processor
* will only be called once.
*
@@ -1507,7 +1339,7 @@
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Sending `%s' message for zone `%s'\n",
- "ZONE_ITERATION_START", GNUNET_short_h2s(zone));
+ "ZONE_ITERATION_START", GNUNET_NAMESTORE_short_h2s(zone));
msg->zone = *zone;
}
else
@@ -1582,7 +1414,7 @@
msg->gns_header.r_id = htonl (it->op_id);
if (GNUNET_YES == it->has_zone)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending `%s' message for zone `%s'\n", "ZONE_ITERATION_STOP",
GNUNET_short_h2s(&it->zone));
+ "Sending `%s' message for zone `%s'\n", "ZONE_ITERATION_STOP",
GNUNET_NAMESTORE_short_h2s(&it->zone));
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending `%s' message for all zones\n", "ZONE_ITERATION_STOP");
@@ -1608,4 +1440,5 @@
GNUNET_free(qe);
}
+
/* end of namestore_api.c */
Copied: gnunet/src/namestore/namestore_api_common.c (from rev 27689,
gnunet/src/namestore/namestore_common.c)
===================================================================
--- gnunet/src/namestore/namestore_api_common.c (rev 0)
+++ gnunet/src/namestore/namestore_api_common.c 2013-06-30 19:21:05 UTC (rev
27691)
@@ -0,0 +1,755 @@
+/*
+ This file is part of GNUnet.
+ (C) 2009, 2010, 2012 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/namestore_common.c
+ * @brief API to access the NAMESTORE service
+ * @author Martin Schanzenbach
+ * @author Matthias Wachs
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_constants.h"
+#include "gnunet_signatures.h"
+#include "gnunet_arm_service.h"
+#include "gnunet_namestore_service.h"
+#include "gnunet_dnsparser_lib.h"
+#include "gns_protocol.h"
+#include "namestore.h"
+
+
+#define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__)
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Internal format of a record in the serialized form.
+ */
+struct NetworkRecord
+{
+
+ /**
+ * Expiration time for the DNS record; relative or absolute depends
+ * on 'flags', network byte order.
+ */
+ uint64_t expiration_time GNUNET_PACKED;
+
+ /**
+ * Number of bytes in 'data', network byte order.
+ */
+ uint32_t data_size GNUNET_PACKED;
+
+ /**
+ * Type of the GNS/DNS record, network byte order.
+ */
+ uint32_t record_type GNUNET_PACKED;
+
+ /**
+ * Flags for the record, network byte order.
+ */
+ uint32_t flags GNUNET_PACKED;
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+/**
+ * Convert a UTF-8 string to UTF-8 lowercase
+ * @param src source string
+ * @return converted result
+ */
+char *
+GNUNET_NAMESTORE_normalize_string (const char *src)
+{
+ GNUNET_assert (NULL != src);
+ char *res = strdup (src);
+ /* normalize */
+ GNUNET_STRINGS_utf8_tolower(src, &res);
+ return res;
+}
+
+
+/**
+ * Convert a short hash to a string (for printing debug messages).
+ * This is one of the very few calls in the entire API that is
+ * NOT reentrant!
+ *
+ * @param hc the short hash code
+ * @return string form; will be overwritten by next call to GNUNET_h2s.
+ */
+const char *
+GNUNET_NAMESTORE_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc)
+{
+ static struct GNUNET_CRYPTO_ShortHashAsciiEncoded ret;
+
+ GNUNET_CRYPTO_short_hash_to_enc (hc, &ret);
+ return (const char *) &ret;
+}
+
+
+/**
+ * Calculate how many bytes we will need to serialize the given
+ * records.
+ *
+ * @param rd_count number of records in the rd array
+ * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
+ *
+ * @return the required size to serialize
+ *
+ */
+size_t
+GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd)
+{
+ unsigned int i;
+ size_t ret;
+
+ ret = sizeof (struct NetworkRecord) * rd_count;
+ for (i=0;i<rd_count;i++)
+ {
+ GNUNET_assert ((ret + rd[i].data_size) >= ret);
+ ret += rd[i].data_size;
+ }
+ return ret;
+}
+
+
+/**
+ * Serialize the given records to the given destination buffer.
+ *
+ * @param rd_count number of records in the rd array
+ * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
+ * @param dest_size size of the destination array
+ * @param dest where to write the result
+ *
+ * @return the size of serialized records, -1 if records do not fit
+ */
+ssize_t
+GNUNET_NAMESTORE_records_serialize (unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData
*rd,
+ size_t dest_size,
+ char *dest)
+{
+ struct NetworkRecord rec;
+ unsigned int i;
+ size_t off;
+
+ off = 0;
+ for (i=0;i<rd_count;i++)
+ {
+ rec.expiration_time = GNUNET_htonll (rd[i].expiration_time);
+ rec.data_size = htonl ((uint32_t) rd[i].data_size);
+ rec.record_type = htonl (rd[i].record_type);
+ rec.flags = htonl (rd[i].flags);
+ if (off + sizeof (rec) > dest_size)
+ return -1;
+ memcpy (&dest[off], &rec, sizeof (rec));
+ off += sizeof (rec);
+ if (off + rd[i].data_size > dest_size)
+ return -1;
+ memcpy (&dest[off], rd[i].data, rd[i].data_size);
+ off += rd[i].data_size;
+ }
+ return off;
+}
+
+
+/**
+ * Compares if two records are equal (ignoring flags such
+ * as authority, private and pending, but not relative vs.
+ * absolute expiration time).
+ *
+ * @param a record
+ * @param b record
+ * @return GNUNET_YES if the records are equal or GNUNET_NO if they are not
+ */
+int
+GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a,
+ const struct GNUNET_NAMESTORE_RecordData *b)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Comparing records\n");
+ if (a->record_type != b->record_type)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Record type %lu != %lu\n", a->record_type, b->record_type);
+ return GNUNET_NO;
+ }
+ if ((a->expiration_time != b->expiration_time) &&
+ ((a->expiration_time != 0) && (b->expiration_time != 0)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Expiration time %llu != %llu\n", a->expiration_time,
b->expiration_time);
+ return GNUNET_NO;
+ }
+ if ((a->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS)
+ != (b->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Flags %lu (%lu) != %lu (%lu)\n", a->flags,
+ a->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS, b->flags,
+ b->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS);
+ return GNUNET_NO;
+ }
+ if (a->data_size != b->data_size)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Data size %lu != %lu\n", a->data_size, b->data_size);
+ return GNUNET_NO;
+ }
+ if (0 != memcmp (a->data, b->data, a->data_size))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Data contents do not match\n");
+ return GNUNET_NO;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Records are equal\n");
+ return GNUNET_YES;
+}
+
+
+/**
+ * Deserialize the given records to the given destination.
+ *
+ * @param len size of the serialized record data
+ * @param src the serialized record data
+ * @param rd_count number of records in the rd array
+ * @param dest where to put the data
+ *
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_NAMESTORE_records_deserialize (size_t len,
+ const char *src,
+ unsigned int rd_count,
+ struct GNUNET_NAMESTORE_RecordData *dest)
+{
+ struct NetworkRecord rec;
+ unsigned int i;
+ size_t off;
+
+ off = 0;
+ for (i=0;i<rd_count;i++)
+ {
+ if (off + sizeof (rec) > len)
+ return GNUNET_SYSERR;
+ memcpy (&rec, &src[off], sizeof (rec));
+ dest[i].expiration_time = GNUNET_ntohll (rec.expiration_time);
+ dest[i].data_size = ntohl ((uint32_t) rec.data_size);
+ dest[i].record_type = ntohl (rec.record_type);
+ dest[i].flags = ntohl (rec.flags);
+ off += sizeof (rec);
+
+ if (off + dest[i].data_size > len)
+ return GNUNET_SYSERR;
+ dest[i].data = &src[off];
+ off += dest[i].data_size;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Sign name and records
+ *
+ * @param key the private key
+ * @param expire block expiration
+ * @param name the name
+ * @param rd record data
+ * @param rd_count number of records
+ *
+ * @return the signature
+ */
+struct GNUNET_CRYPTO_EccSignature *
+GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_EccPrivateKey
*key,
+ struct GNUNET_TIME_Absolute expire,
+ const char *name,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ unsigned int rd_count)
+{
+ struct GNUNET_CRYPTO_EccSignature *sig;
+ struct GNUNET_CRYPTO_EccSignaturePurpose *sig_purpose;
+ struct GNUNET_TIME_AbsoluteNBO expire_nbo;
+ size_t rd_ser_len;
+ size_t name_len;
+ struct GNUNET_TIME_AbsoluteNBO *expire_tmp;
+ char * name_tmp;
+ char * rd_tmp;
+ int res;
+ uint32_t sig_len;
+
+ if (NULL == name)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ sig = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EccSignature));
+ name_len = strlen (name) + 1;
+ expire_nbo = GNUNET_TIME_absolute_hton (expire);
+ rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
+ {
+ char rd_ser[rd_ser_len];
+
+ GNUNET_assert (rd_ser_len ==
+ GNUNET_NAMESTORE_records_serialize (rd_count, rd,
rd_ser_len, rd_ser));
+ sig_len = sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof
(struct GNUNET_TIME_AbsoluteNBO) + rd_ser_len + name_len;
+ sig_purpose = GNUNET_malloc (sig_len);
+ sig_purpose->size = htonl (sig_len);
+ sig_purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN);
+ expire_tmp = (struct GNUNET_TIME_AbsoluteNBO *) &sig_purpose[1];
+ memcpy (expire_tmp, &expire_nbo, sizeof (struct GNUNET_TIME_AbsoluteNBO));
+ name_tmp = (char *) &expire_tmp[1];
+ memcpy (name_tmp, name, name_len);
+ rd_tmp = &name_tmp[name_len];
+ memcpy (rd_tmp, rd_ser, rd_ser_len);
+ res = GNUNET_CRYPTO_ecc_sign (key, sig_purpose, sig);
+ GNUNET_free (sig_purpose);
+ }
+ if (GNUNET_OK != res)
+ {
+ GNUNET_break (0);
+ GNUNET_free (sig);
+ return NULL;
+ }
+ return sig;
+}
+
+
+/**
+ * Convert the 'value' of a record to a string.
+ *
+ * @param type type of the record
+ * @param data value in binary encoding
+ * @param data_size number of bytes in data
+ * @return NULL on error, otherwise human-readable representation of the value
+ */
+char *
+GNUNET_NAMESTORE_value_to_string (uint32_t type,
+ const void *data,
+ size_t data_size)
+{
+ uint16_t mx_pref;
+ const struct soa_data *soa;
+ const struct vpn_data *vpn;
+ const struct srv_data *srv;
+ const struct tlsa_data *tlsa;
+ struct GNUNET_CRYPTO_ShortHashAsciiEncoded enc;
+ struct GNUNET_CRYPTO_HashAsciiEncoded s_peer;
+ const char *cdata;
+ char* vpn_str;
+ char* srv_str;
+ char* tlsa_str;
+ char* result;
+ const char* soa_rname;
+ const char* soa_mname;
+ char tmp[INET6_ADDRSTRLEN];
+
+ switch (type)
+ {
+ case 0:
+ return NULL;
+ case GNUNET_DNSPARSER_TYPE_A:
+ if (data_size != sizeof (struct in_addr))
+ return NULL;
+ if (NULL == inet_ntop (AF_INET, data, tmp, sizeof (tmp)))
+ return NULL;
+ return GNUNET_strdup (tmp);
+ case GNUNET_DNSPARSER_TYPE_NS:
+ return GNUNET_strndup (data, data_size);
+ case GNUNET_DNSPARSER_TYPE_CNAME:
+ return GNUNET_strndup (data, data_size);
+ case GNUNET_DNSPARSER_TYPE_SOA:
+ if (data_size <= sizeof (struct soa_data))
+ return NULL;
+ soa = data;
+ soa_rname = (const char*) &soa[1];
+ soa_mname = memchr (soa_rname, 0, data_size - sizeof (struct soa_data) -
1);
+ if (NULL == soa_mname)
+ return NULL;
+ soa_mname++;
+ if (NULL == memchr (soa_mname, 0,
+ data_size - (sizeof (struct soa_data) + strlen
(soa_rname) + 1)))
+ return NULL;
+ GNUNET_asprintf (&result,
+ "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu",
+ soa_rname, soa_mname,
+ ntohl (soa->serial),
+ ntohl (soa->refresh),
+ ntohl (soa->retry),
+ ntohl (soa->expire),
+ ntohl (soa->minimum));
+ return result;
+ case GNUNET_DNSPARSER_TYPE_PTR:
+ return GNUNET_strndup (data, data_size);
+ case GNUNET_DNSPARSER_TYPE_MX:
+ mx_pref = ntohs(*((uint16_t*)data));
+ if (GNUNET_asprintf(&result, "%hu,%s", mx_pref, data+sizeof(uint16_t))
+ != 0)
+ return result;
+ else
+ {
+ GNUNET_free (result);
+ return NULL;
+ }
+ case GNUNET_DNSPARSER_TYPE_TXT:
+ return GNUNET_strndup (data, data_size);
+ case GNUNET_DNSPARSER_TYPE_AAAA:
+ if (data_size != sizeof (struct in6_addr))
+ return NULL;
+ if (NULL == inet_ntop (AF_INET6, data, tmp, sizeof (tmp)))
+ return NULL;
+ return GNUNET_strdup (tmp);
+ case GNUNET_NAMESTORE_TYPE_PKEY:
+ if (data_size != sizeof (struct GNUNET_CRYPTO_ShortHashCode))
+ return NULL;
+ GNUNET_CRYPTO_short_hash_to_enc (data,
+ &enc);
+ return GNUNET_strdup ((const char*) enc.short_encoding);
+ case GNUNET_NAMESTORE_TYPE_PSEU:
+ return GNUNET_strndup (data, data_size);
+ case GNUNET_NAMESTORE_TYPE_LEHO:
+ return GNUNET_strndup (data, data_size);
+ case GNUNET_NAMESTORE_TYPE_VPN:
+ cdata = data;
+ if ( (data_size <= sizeof (struct vpn_data)) ||
+ ('\0' != cdata[data_size - 1]) )
+ return NULL; /* malformed */
+ vpn = data;
+ GNUNET_CRYPTO_hash_to_enc (&vpn->peer, &s_peer);
+ if (0 == GNUNET_asprintf (&vpn_str, "%u %s %s",
+ (unsigned int) ntohs (vpn->proto),
+ (const char*) &s_peer,
+ (const char*) &vpn[1]))
+ {
+ GNUNET_free (vpn_str);
+ return NULL;
+ }
+ return vpn_str;
+ case GNUNET_DNSPARSER_TYPE_SRV:
+ cdata = data;
+ if ( (data_size <= sizeof (struct srv_data)) ||
+ ('\0' != cdata[data_size - 1]) )
+ return NULL; /* malformed */
+ srv = data;
+
+ if (0 == GNUNET_asprintf (&srv_str,
+ "%d %d %d %s",
+ ntohs (srv->prio),
+ ntohs (srv->weight),
+ ntohs (srv->port),
+ (const char *)&srv[1]))
+ {
+ GNUNET_free (srv_str);
+ return NULL;
+ }
+ return srv_str;
+ case GNUNET_DNSPARSER_TYPE_TLSA:
+ cdata = data;
+ if ( (data_size <= sizeof (struct tlsa_data)) ||
+ ('\0' != cdata[data_size - 1]) )
+ return NULL; /* malformed */
+ tlsa = data;
+ if (0 == GNUNET_asprintf (&tlsa_str,
+ "%c %c %c %s",
+ tlsa->usage,
+ tlsa->selector,
+ tlsa->matching_type,
+ (const char *) &tlsa[1]))
+ {
+ GNUNET_free (tlsa_str);
+ return NULL;
+ }
+ return tlsa_str;
+ default:
+ GNUNET_break (0);
+ }
+ GNUNET_break (0); // not implemented
+ return NULL;
+}
+
+
+/**
+ * Convert human-readable version of a 'value' of a record to the binary
+ * representation.
+ *
+ * @param type type of the record
+ * @param s human-readable string
+ * @param data set to value in binary encoding (will be allocated)
+ * @param data_size set to number of bytes in data
+ * @return GNUNET_OK on success
+ */
+int
+GNUNET_NAMESTORE_string_to_value (uint32_t type,
+ const char *s,
+ void **data,
+ size_t *data_size)
+{
+ struct in_addr value_a;
+ struct in6_addr value_aaaa;
+ struct GNUNET_CRYPTO_ShortHashCode pkey;
+ struct soa_data *soa;
+ struct vpn_data *vpn;
+ struct tlsa_data *tlsa;
+ char result[253 + 1];
+ char soa_rname[253 + 1];
+ char soa_mname[253 + 1];
+ char s_peer[103 + 1];
+ char s_serv[253 + 1];
+ unsigned int soa_serial;
+ unsigned int soa_refresh;
+ unsigned int soa_retry;
+ unsigned int soa_expire;
+ unsigned int soa_min;
+ uint16_t mx_pref;
+ uint16_t mx_pref_n;
+ unsigned int proto;
+
+ if (NULL == s)
+ return GNUNET_SYSERR;
+ switch (type)
+ {
+ case 0:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unsupported record type %d\n"),
+ (int) type);
+ return GNUNET_SYSERR;
+ case GNUNET_DNSPARSER_TYPE_A:
+ if (1 != inet_pton (AF_INET, s, &value_a))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to parse IPv4 address `%s'\n"),
+ s);
+ return GNUNET_SYSERR;
+ }
+ *data = GNUNET_malloc (sizeof (struct in_addr));
+ memcpy (*data, &value_a, sizeof (value_a));
+ *data_size = sizeof (value_a);
+ return GNUNET_OK;
+ case GNUNET_DNSPARSER_TYPE_NS:
+ *data = GNUNET_strdup (s);
+ *data_size = strlen (s) + 1;
+ return GNUNET_OK;
+ case GNUNET_DNSPARSER_TYPE_CNAME:
+ *data = GNUNET_strdup (s);
+ *data_size = strlen (s) + 1;
+ return GNUNET_OK;
+ case GNUNET_DNSPARSER_TYPE_SOA:
+ if (7 != SSCANF (s,
+ "rname=%253s mname=%253s %u,%u,%u,%u,%u",
+ soa_rname, soa_mname,
+ &soa_serial, &soa_refresh, &soa_retry, &soa_expire,
&soa_min))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to parse SOA record `%s'\n"),
+ s);
+ return GNUNET_SYSERR;
+ }
+ *data_size = sizeof (struct
soa_data)+strlen(soa_rname)+strlen(soa_mname)+2;
+ *data = GNUNET_malloc (*data_size);
+ soa = (struct soa_data*)*data;
+ soa->serial = htonl(soa_serial);
+ soa->refresh = htonl(soa_refresh);
+ soa->retry = htonl(soa_retry);
+ soa->expire = htonl(soa_expire);
+ soa->minimum = htonl(soa_min);
+ strcpy((char*)&soa[1], soa_rname);
+ strcpy((char*)&soa[1]+strlen(*data)+1, soa_mname);
+ return GNUNET_OK;
+ case GNUNET_DNSPARSER_TYPE_PTR:
+ *data = GNUNET_strdup (s);
+ *data_size = strlen (s);
+ return GNUNET_OK;
+ case GNUNET_DNSPARSER_TYPE_MX:
+ if (2 != SSCANF(s, "%hu,%253s", &mx_pref, result))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to parse MX record `%s'\n"),
+ s);
+ return GNUNET_SYSERR;
+ }
+ *data_size = sizeof (uint16_t)+strlen(result)+1;
+ *data = GNUNET_malloc (*data_size);
+ mx_pref_n = htons(mx_pref);
+ memcpy(*data, &mx_pref_n, sizeof (uint16_t));
+ strcpy((*data)+sizeof (uint16_t), result);
+ return GNUNET_OK;
+ case GNUNET_DNSPARSER_TYPE_TXT:
+ *data = GNUNET_strdup (s);
+ *data_size = strlen (s);
+ return GNUNET_OK;
+ case GNUNET_DNSPARSER_TYPE_AAAA:
+ if (1 != inet_pton (AF_INET6, s, &value_aaaa))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to parse IPv6 address `%s'\n"),
+ s);
+ return GNUNET_SYSERR;
+ }
+ *data = GNUNET_malloc (sizeof (struct in6_addr));
+ *data_size = sizeof (struct in6_addr);
+ memcpy (*data, &value_aaaa, sizeof (value_aaaa));
+ return GNUNET_OK;
+ case GNUNET_NAMESTORE_TYPE_PKEY:
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_short_hash_from_string (s, &pkey))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to parse PKEY record `%s'\n"),
+ s);
+ return GNUNET_SYSERR;
+ }
+ *data = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
+ memcpy (*data, &pkey, sizeof (pkey));
+ *data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode);
+ return GNUNET_OK;
+ case GNUNET_NAMESTORE_TYPE_PSEU:
+ *data = GNUNET_strdup (s);
+ *data_size = strlen (s);
+ return GNUNET_OK;
+ case GNUNET_NAMESTORE_TYPE_LEHO:
+ *data = GNUNET_strdup (s);
+ *data_size = strlen (s);
+ return GNUNET_OK;
+ case GNUNET_NAMESTORE_TYPE_VPN:
+ if (3 != SSCANF (s,"%u %103s %253s",
+ &proto, s_peer, s_serv))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to parse VPN record string `%s'\n"),
+ s);
+ return GNUNET_SYSERR;
+ }
+ *data_size = sizeof (struct vpn_data) + strlen (s_serv) + 1;
+ *data = vpn = GNUNET_malloc (*data_size);
+ if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_peer,
+ &vpn->peer))
+ {
+ GNUNET_free (vpn);
+ *data_size = 0;
+ return GNUNET_SYSERR;
+ }
+ vpn->proto = htons ((uint16_t) proto);
+ strcpy ((char*)&vpn[1], s_serv);
+ return GNUNET_OK;
+ case GNUNET_DNSPARSER_TYPE_TLSA:
+ *data_size = sizeof (struct tlsa_data) + strlen (s) - 6;
+ *data = tlsa = GNUNET_malloc (*data_size);
+ if (4 != SSCANF (s, "%c %c %c %s",
+ &tlsa->usage,
+ &tlsa->selector,
+ &tlsa->matching_type,
+ (char*)&tlsa[1]))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to parse TLSA record string `%s'\n"),
+ s);
+ *data_size = 0;
+ GNUNET_free (tlsa);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unsupported record type %d\n"),
+ (int) type);
+ return GNUNET_SYSERR;
+ }
+}
+
+
+static struct {
+ const char *name;
+ uint32_t number;
+} name_map[] = {
+ { "A", GNUNET_DNSPARSER_TYPE_A },
+ { "NS", GNUNET_DNSPARSER_TYPE_NS },
+ { "CNAME", GNUNET_DNSPARSER_TYPE_CNAME },
+ { "SOA", GNUNET_DNSPARSER_TYPE_SOA },
+ { "PTR", GNUNET_DNSPARSER_TYPE_PTR },
+ { "MX", GNUNET_DNSPARSER_TYPE_MX },
+ { "TXT", GNUNET_DNSPARSER_TYPE_TXT },
+ { "AAAA", GNUNET_DNSPARSER_TYPE_AAAA },
+ { "PKEY", GNUNET_NAMESTORE_TYPE_PKEY },
+ { "PSEU", GNUNET_NAMESTORE_TYPE_PSEU },
+ { "LEHO", GNUNET_NAMESTORE_TYPE_LEHO },
+ { "VPN", GNUNET_NAMESTORE_TYPE_VPN },
+ { "TLSA", GNUNET_DNSPARSER_TYPE_TLSA },
+ { NULL, UINT32_MAX }
+};
+
+
+/**
+ * Convert a type name (i.e. "AAAA") to the corresponding number.
+ *
+ * @param typename name to convert
+ * @return corresponding number, UINT32_MAX on error
+ */
+uint32_t
+GNUNET_NAMESTORE_typename_to_number (const char *typename)
+{
+ unsigned int i;
+
+ i=0;
+ while ( (name_map[i].name != NULL) &&
+ (0 != strcasecmp (typename, name_map[i].name)) )
+ i++;
+ return name_map[i].number;
+}
+
+
+/**
+ * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
+ *
+ * @param type number of a type to convert
+ * @return corresponding typestring, NULL on error
+ */
+const char *
+GNUNET_NAMESTORE_number_to_typename (uint32_t type)
+{
+ unsigned int i;
+
+ i=0;
+ while ( (name_map[i].name != NULL) &&
+ (type != name_map[i].number) )
+ i++;
+ return name_map[i].name;
+}
+
+/**
+ * Test if a given record is expired.
+ *
+ * @return GNUNET_YES if the record is expired,
+ * GNUNET_NO if not
+ */
+int
+GNUNET_NAMESTORE_is_expired (const struct GNUNET_NAMESTORE_RecordData *rd)
+{
+ struct GNUNET_TIME_Absolute at;
+
+ if (0 != (rd->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION))
+ return GNUNET_NO;
+ at.abs_value = rd->expiration_time;
+ return (0 == GNUNET_TIME_absolute_get_remaining (at).rel_value) ? GNUNET_YES
: GNUNET_NO;
+}
+
+
+/* end of namestore_common.c */
Added: gnunet/src/namestore/namestore_api_monitor.c
===================================================================
--- gnunet/src/namestore/namestore_api_monitor.c
(rev 0)
+++ gnunet/src/namestore/namestore_api_monitor.c 2013-06-30 19:21:05 UTC
(rev 27691)
@@ -0,0 +1,79 @@
+/*
+ This file is part of GNUnet.
+ (C) 2013 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/namestore_api_monitor.c
+ * @brief API to monitor changes in the NAMESTORE
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_crypto_lib.h"
+#include "gnunet_constants.h"
+#include "gnunet_dnsparser_lib.h"
+#include "gnunet_arm_service.h"
+#include "gnunet_signatures.h"
+#include "gnunet_namestore_service.h"
+#include "namestore.h"
+
+
+
+/**
+ * Handle for a monitoring activity.
+ */
+struct GNUNET_NAMESTORE_ZoneMonitor
+{
+};
+
+
+/**
+ * Begin monitoring a zone for changes. Will first call the 'monitor' function
+ * on all existing records in the selected zone(s) and then call it whenever
+ * a record changes.
+ *
+ * @param cfg configuration to use to connect to namestore
+ * @param zone zone to monitor, NULL for all zones
+ * @param monitor function to call on zone changes
+ * @param monitor_cls closure for 'monitor'
+ * @return handle to stop monitoring
+ */
+struct GNUNET_NAMESTORE_ZoneMonitor *
+GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle
*cfg,
+ const struct GNUNET_CRYPTO_ShortHashCode
*zone,
+ GNUNET_NAMESTORE_RecordMonitor monitor,
+ void *monitor_cls)
+{
+ GNUNET_break (0);
+ return NULL;
+}
+
+
+/**
+ * Stop monitoring a zone for changes.
+ *
+ * @param zm handle to the monitor activity to stop
+ */
+void
+GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
+{
+}
+
+/* end of namestore_api_monitor.c */
Deleted: gnunet/src/namestore/namestore_common.c
===================================================================
--- gnunet/src/namestore/namestore_common.c 2013-06-30 19:14:53 UTC (rev
27690)
+++ gnunet/src/namestore/namestore_common.c 2013-06-30 19:21:05 UTC (rev
27691)
@@ -1,755 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2009, 2010, 2012 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/namestore_common.c
- * @brief API to access the NAMESTORE service
- * @author Martin Schanzenbach
- * @author Matthias Wachs
- */
-
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_constants.h"
-#include "gnunet_signatures.h"
-#include "gnunet_arm_service.h"
-#include "gnunet_namestore_service.h"
-#include "gnunet_dnsparser_lib.h"
-#include "gns_protocol.h"
-#include "namestore.h"
-
-
-#define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__)
-
-GNUNET_NETWORK_STRUCT_BEGIN
-
-/**
- * Internal format of a record in the serialized form.
- */
-struct NetworkRecord
-{
-
- /**
- * Expiration time for the DNS record; relative or absolute depends
- * on 'flags', network byte order.
- */
- uint64_t expiration_time GNUNET_PACKED;
-
- /**
- * Number of bytes in 'data', network byte order.
- */
- uint32_t data_size GNUNET_PACKED;
-
- /**
- * Type of the GNS/DNS record, network byte order.
- */
- uint32_t record_type GNUNET_PACKED;
-
- /**
- * Flags for the record, network byte order.
- */
- uint32_t flags GNUNET_PACKED;
-
-};
-
-GNUNET_NETWORK_STRUCT_END
-
-/**
- * Convert a UTF-8 string to UTF-8 lowercase
- * @param src source string
- * @return converted result
- */
-char *
-GNUNET_NAMESTORE_normalize_string (const char *src)
-{
- GNUNET_assert (NULL != src);
- char *res = strdup (src);
- /* normalize */
- GNUNET_STRINGS_utf8_tolower(src, &res);
- return res;
-}
-
-
-/**
- * Convert a short hash to a string (for printing debug messages).
- * This is one of the very few calls in the entire API that is
- * NOT reentrant!
- *
- * @param hc the short hash code
- * @return string form; will be overwritten by next call to GNUNET_h2s.
- */
-const char *
-GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc)
-{
- static struct GNUNET_CRYPTO_ShortHashAsciiEncoded ret;
-
- GNUNET_CRYPTO_short_hash_to_enc (hc, &ret);
- return (const char *) &ret;
-}
-
-
-/**
- * Calculate how many bytes we will need to serialize the given
- * records.
- *
- * @param rd_count number of records in the rd array
- * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
- *
- * @return the required size to serialize
- *
- */
-size_t
-GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd)
-{
- unsigned int i;
- size_t ret;
-
- ret = sizeof (struct NetworkRecord) * rd_count;
- for (i=0;i<rd_count;i++)
- {
- GNUNET_assert ((ret + rd[i].data_size) >= ret);
- ret += rd[i].data_size;
- }
- return ret;
-}
-
-
-/**
- * Serialize the given records to the given destination buffer.
- *
- * @param rd_count number of records in the rd array
- * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
- * @param dest_size size of the destination array
- * @param dest where to write the result
- *
- * @return the size of serialized records, -1 if records do not fit
- */
-ssize_t
-GNUNET_NAMESTORE_records_serialize (unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData
*rd,
- size_t dest_size,
- char *dest)
-{
- struct NetworkRecord rec;
- unsigned int i;
- size_t off;
-
- off = 0;
- for (i=0;i<rd_count;i++)
- {
- rec.expiration_time = GNUNET_htonll (rd[i].expiration_time);
- rec.data_size = htonl ((uint32_t) rd[i].data_size);
- rec.record_type = htonl (rd[i].record_type);
- rec.flags = htonl (rd[i].flags);
- if (off + sizeof (rec) > dest_size)
- return -1;
- memcpy (&dest[off], &rec, sizeof (rec));
- off += sizeof (rec);
- if (off + rd[i].data_size > dest_size)
- return -1;
- memcpy (&dest[off], rd[i].data, rd[i].data_size);
- off += rd[i].data_size;
- }
- return off;
-}
-
-
-/**
- * Compares if two records are equal (ignoring flags such
- * as authority, private and pending, but not relative vs.
- * absolute expiration time).
- *
- * @param a record
- * @param b record
- * @return GNUNET_YES if the records are equal or GNUNET_NO if they are not
- */
-int
-GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a,
- const struct GNUNET_NAMESTORE_RecordData *b)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Comparing records\n");
- if (a->record_type != b->record_type)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Record type %lu != %lu\n", a->record_type, b->record_type);
- return GNUNET_NO;
- }
- if ((a->expiration_time != b->expiration_time) &&
- ((a->expiration_time != 0) && (b->expiration_time != 0)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Expiration time %llu != %llu\n", a->expiration_time,
b->expiration_time);
- return GNUNET_NO;
- }
- if ((a->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS)
- != (b->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Flags %lu (%lu) != %lu (%lu)\n", a->flags,
- a->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS, b->flags,
- b->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS);
- return GNUNET_NO;
- }
- if (a->data_size != b->data_size)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Data size %lu != %lu\n", a->data_size, b->data_size);
- return GNUNET_NO;
- }
- if (0 != memcmp (a->data, b->data, a->data_size))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Data contents do not match\n");
- return GNUNET_NO;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Records are equal\n");
- return GNUNET_YES;
-}
-
-
-/**
- * Deserialize the given records to the given destination.
- *
- * @param len size of the serialized record data
- * @param src the serialized record data
- * @param rd_count number of records in the rd array
- * @param dest where to put the data
- *
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-int
-GNUNET_NAMESTORE_records_deserialize (size_t len,
- const char *src,
- unsigned int rd_count,
- struct GNUNET_NAMESTORE_RecordData *dest)
-{
- struct NetworkRecord rec;
- unsigned int i;
- size_t off;
-
- off = 0;
- for (i=0;i<rd_count;i++)
- {
- if (off + sizeof (rec) > len)
- return GNUNET_SYSERR;
- memcpy (&rec, &src[off], sizeof (rec));
- dest[i].expiration_time = GNUNET_ntohll (rec.expiration_time);
- dest[i].data_size = ntohl ((uint32_t) rec.data_size);
- dest[i].record_type = ntohl (rec.record_type);
- dest[i].flags = ntohl (rec.flags);
- off += sizeof (rec);
-
- if (off + dest[i].data_size > len)
- return GNUNET_SYSERR;
- dest[i].data = &src[off];
- off += dest[i].data_size;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Sign name and records
- *
- * @param key the private key
- * @param expire block expiration
- * @param name the name
- * @param rd record data
- * @param rd_count number of records
- *
- * @return the signature
- */
-struct GNUNET_CRYPTO_EccSignature *
-GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_EccPrivateKey
*key,
- struct GNUNET_TIME_Absolute expire,
- const char *name,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- unsigned int rd_count)
-{
- struct GNUNET_CRYPTO_EccSignature *sig;
- struct GNUNET_CRYPTO_EccSignaturePurpose *sig_purpose;
- struct GNUNET_TIME_AbsoluteNBO expire_nbo;
- size_t rd_ser_len;
- size_t name_len;
- struct GNUNET_TIME_AbsoluteNBO *expire_tmp;
- char * name_tmp;
- char * rd_tmp;
- int res;
- uint32_t sig_len;
-
- if (NULL == name)
- {
- GNUNET_break (0);
- return NULL;
- }
- sig = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EccSignature));
- name_len = strlen (name) + 1;
- expire_nbo = GNUNET_TIME_absolute_hton (expire);
- rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
- {
- char rd_ser[rd_ser_len];
-
- GNUNET_assert (rd_ser_len ==
- GNUNET_NAMESTORE_records_serialize (rd_count, rd,
rd_ser_len, rd_ser));
- sig_len = sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof
(struct GNUNET_TIME_AbsoluteNBO) + rd_ser_len + name_len;
- sig_purpose = GNUNET_malloc (sig_len);
- sig_purpose->size = htonl (sig_len);
- sig_purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN);
- expire_tmp = (struct GNUNET_TIME_AbsoluteNBO *) &sig_purpose[1];
- memcpy (expire_tmp, &expire_nbo, sizeof (struct GNUNET_TIME_AbsoluteNBO));
- name_tmp = (char *) &expire_tmp[1];
- memcpy (name_tmp, name, name_len);
- rd_tmp = &name_tmp[name_len];
- memcpy (rd_tmp, rd_ser, rd_ser_len);
- res = GNUNET_CRYPTO_ecc_sign (key, sig_purpose, sig);
- GNUNET_free (sig_purpose);
- }
- if (GNUNET_OK != res)
- {
- GNUNET_break (0);
- GNUNET_free (sig);
- return NULL;
- }
- return sig;
-}
-
-
-/**
- * Convert the 'value' of a record to a string.
- *
- * @param type type of the record
- * @param data value in binary encoding
- * @param data_size number of bytes in data
- * @return NULL on error, otherwise human-readable representation of the value
- */
-char *
-GNUNET_NAMESTORE_value_to_string (uint32_t type,
- const void *data,
- size_t data_size)
-{
- uint16_t mx_pref;
- const struct soa_data *soa;
- const struct vpn_data *vpn;
- const struct srv_data *srv;
- const struct tlsa_data *tlsa;
- struct GNUNET_CRYPTO_ShortHashAsciiEncoded enc;
- struct GNUNET_CRYPTO_HashAsciiEncoded s_peer;
- const char *cdata;
- char* vpn_str;
- char* srv_str;
- char* tlsa_str;
- char* result;
- const char* soa_rname;
- const char* soa_mname;
- char tmp[INET6_ADDRSTRLEN];
-
- switch (type)
- {
- case 0:
- return NULL;
- case GNUNET_DNSPARSER_TYPE_A:
- if (data_size != sizeof (struct in_addr))
- return NULL;
- if (NULL == inet_ntop (AF_INET, data, tmp, sizeof (tmp)))
- return NULL;
- return GNUNET_strdup (tmp);
- case GNUNET_DNSPARSER_TYPE_NS:
- return GNUNET_strndup (data, data_size);
- case GNUNET_DNSPARSER_TYPE_CNAME:
- return GNUNET_strndup (data, data_size);
- case GNUNET_DNSPARSER_TYPE_SOA:
- if (data_size <= sizeof (struct soa_data))
- return NULL;
- soa = data;
- soa_rname = (const char*) &soa[1];
- soa_mname = memchr (soa_rname, 0, data_size - sizeof (struct soa_data) -
1);
- if (NULL == soa_mname)
- return NULL;
- soa_mname++;
- if (NULL == memchr (soa_mname, 0,
- data_size - (sizeof (struct soa_data) + strlen
(soa_rname) + 1)))
- return NULL;
- GNUNET_asprintf (&result,
- "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu",
- soa_rname, soa_mname,
- ntohl (soa->serial),
- ntohl (soa->refresh),
- ntohl (soa->retry),
- ntohl (soa->expire),
- ntohl (soa->minimum));
- return result;
- case GNUNET_DNSPARSER_TYPE_PTR:
- return GNUNET_strndup (data, data_size);
- case GNUNET_DNSPARSER_TYPE_MX:
- mx_pref = ntohs(*((uint16_t*)data));
- if (GNUNET_asprintf(&result, "%hu,%s", mx_pref, data+sizeof(uint16_t))
- != 0)
- return result;
- else
- {
- GNUNET_free (result);
- return NULL;
- }
- case GNUNET_DNSPARSER_TYPE_TXT:
- return GNUNET_strndup (data, data_size);
- case GNUNET_DNSPARSER_TYPE_AAAA:
- if (data_size != sizeof (struct in6_addr))
- return NULL;
- if (NULL == inet_ntop (AF_INET6, data, tmp, sizeof (tmp)))
- return NULL;
- return GNUNET_strdup (tmp);
- case GNUNET_NAMESTORE_TYPE_PKEY:
- if (data_size != sizeof (struct GNUNET_CRYPTO_ShortHashCode))
- return NULL;
- GNUNET_CRYPTO_short_hash_to_enc (data,
- &enc);
- return GNUNET_strdup ((const char*) enc.short_encoding);
- case GNUNET_NAMESTORE_TYPE_PSEU:
- return GNUNET_strndup (data, data_size);
- case GNUNET_NAMESTORE_TYPE_LEHO:
- return GNUNET_strndup (data, data_size);
- case GNUNET_NAMESTORE_TYPE_VPN:
- cdata = data;
- if ( (data_size <= sizeof (struct vpn_data)) ||
- ('\0' != cdata[data_size - 1]) )
- return NULL; /* malformed */
- vpn = data;
- GNUNET_CRYPTO_hash_to_enc (&vpn->peer, &s_peer);
- if (0 == GNUNET_asprintf (&vpn_str, "%u %s %s",
- (unsigned int) ntohs (vpn->proto),
- (const char*) &s_peer,
- (const char*) &vpn[1]))
- {
- GNUNET_free (vpn_str);
- return NULL;
- }
- return vpn_str;
- case GNUNET_DNSPARSER_TYPE_SRV:
- cdata = data;
- if ( (data_size <= sizeof (struct srv_data)) ||
- ('\0' != cdata[data_size - 1]) )
- return NULL; /* malformed */
- srv = data;
-
- if (0 == GNUNET_asprintf (&srv_str,
- "%d %d %d %s",
- ntohs (srv->prio),
- ntohs (srv->weight),
- ntohs (srv->port),
- (const char *)&srv[1]))
- {
- GNUNET_free (srv_str);
- return NULL;
- }
- return srv_str;
- case GNUNET_DNSPARSER_TYPE_TLSA:
- cdata = data;
- if ( (data_size <= sizeof (struct tlsa_data)) ||
- ('\0' != cdata[data_size - 1]) )
- return NULL; /* malformed */
- tlsa = data;
- if (0 == GNUNET_asprintf (&tlsa_str,
- "%c %c %c %s",
- tlsa->usage,
- tlsa->selector,
- tlsa->matching_type,
- (const char *) &tlsa[1]))
- {
- GNUNET_free (tlsa_str);
- return NULL;
- }
- return tlsa_str;
- default:
- GNUNET_break (0);
- }
- GNUNET_break (0); // not implemented
- return NULL;
-}
-
-
-/**
- * Convert human-readable version of a 'value' of a record to the binary
- * representation.
- *
- * @param type type of the record
- * @param s human-readable string
- * @param data set to value in binary encoding (will be allocated)
- * @param data_size set to number of bytes in data
- * @return GNUNET_OK on success
- */
-int
-GNUNET_NAMESTORE_string_to_value (uint32_t type,
- const char *s,
- void **data,
- size_t *data_size)
-{
- struct in_addr value_a;
- struct in6_addr value_aaaa;
- struct GNUNET_CRYPTO_ShortHashCode pkey;
- struct soa_data *soa;
- struct vpn_data *vpn;
- struct tlsa_data *tlsa;
- char result[253 + 1];
- char soa_rname[253 + 1];
- char soa_mname[253 + 1];
- char s_peer[103 + 1];
- char s_serv[253 + 1];
- unsigned int soa_serial;
- unsigned int soa_refresh;
- unsigned int soa_retry;
- unsigned int soa_expire;
- unsigned int soa_min;
- uint16_t mx_pref;
- uint16_t mx_pref_n;
- unsigned int proto;
-
- if (NULL == s)
- return GNUNET_SYSERR;
- switch (type)
- {
- case 0:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unsupported record type %d\n"),
- (int) type);
- return GNUNET_SYSERR;
- case GNUNET_DNSPARSER_TYPE_A:
- if (1 != inet_pton (AF_INET, s, &value_a))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to parse IPv4 address `%s'\n"),
- s);
- return GNUNET_SYSERR;
- }
- *data = GNUNET_malloc (sizeof (struct in_addr));
- memcpy (*data, &value_a, sizeof (value_a));
- *data_size = sizeof (value_a);
- return GNUNET_OK;
- case GNUNET_DNSPARSER_TYPE_NS:
- *data = GNUNET_strdup (s);
- *data_size = strlen (s) + 1;
- return GNUNET_OK;
- case GNUNET_DNSPARSER_TYPE_CNAME:
- *data = GNUNET_strdup (s);
- *data_size = strlen (s) + 1;
- return GNUNET_OK;
- case GNUNET_DNSPARSER_TYPE_SOA:
- if (7 != SSCANF (s,
- "rname=%253s mname=%253s %u,%u,%u,%u,%u",
- soa_rname, soa_mname,
- &soa_serial, &soa_refresh, &soa_retry, &soa_expire,
&soa_min))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to parse SOA record `%s'\n"),
- s);
- return GNUNET_SYSERR;
- }
- *data_size = sizeof (struct
soa_data)+strlen(soa_rname)+strlen(soa_mname)+2;
- *data = GNUNET_malloc (*data_size);
- soa = (struct soa_data*)*data;
- soa->serial = htonl(soa_serial);
- soa->refresh = htonl(soa_refresh);
- soa->retry = htonl(soa_retry);
- soa->expire = htonl(soa_expire);
- soa->minimum = htonl(soa_min);
- strcpy((char*)&soa[1], soa_rname);
- strcpy((char*)&soa[1]+strlen(*data)+1, soa_mname);
- return GNUNET_OK;
- case GNUNET_DNSPARSER_TYPE_PTR:
- *data = GNUNET_strdup (s);
- *data_size = strlen (s);
- return GNUNET_OK;
- case GNUNET_DNSPARSER_TYPE_MX:
- if (2 != SSCANF(s, "%hu,%253s", &mx_pref, result))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to parse MX record `%s'\n"),
- s);
- return GNUNET_SYSERR;
- }
- *data_size = sizeof (uint16_t)+strlen(result)+1;
- *data = GNUNET_malloc (*data_size);
- mx_pref_n = htons(mx_pref);
- memcpy(*data, &mx_pref_n, sizeof (uint16_t));
- strcpy((*data)+sizeof (uint16_t), result);
- return GNUNET_OK;
- case GNUNET_DNSPARSER_TYPE_TXT:
- *data = GNUNET_strdup (s);
- *data_size = strlen (s);
- return GNUNET_OK;
- case GNUNET_DNSPARSER_TYPE_AAAA:
- if (1 != inet_pton (AF_INET6, s, &value_aaaa))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to parse IPv6 address `%s'\n"),
- s);
- return GNUNET_SYSERR;
- }
- *data = GNUNET_malloc (sizeof (struct in6_addr));
- *data_size = sizeof (struct in6_addr);
- memcpy (*data, &value_aaaa, sizeof (value_aaaa));
- return GNUNET_OK;
- case GNUNET_NAMESTORE_TYPE_PKEY:
- if (GNUNET_OK !=
- GNUNET_CRYPTO_short_hash_from_string (s, &pkey))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to parse PKEY record `%s'\n"),
- s);
- return GNUNET_SYSERR;
- }
- *data = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
- memcpy (*data, &pkey, sizeof (pkey));
- *data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode);
- return GNUNET_OK;
- case GNUNET_NAMESTORE_TYPE_PSEU:
- *data = GNUNET_strdup (s);
- *data_size = strlen (s);
- return GNUNET_OK;
- case GNUNET_NAMESTORE_TYPE_LEHO:
- *data = GNUNET_strdup (s);
- *data_size = strlen (s);
- return GNUNET_OK;
- case GNUNET_NAMESTORE_TYPE_VPN:
- if (3 != SSCANF (s,"%u %103s %253s",
- &proto, s_peer, s_serv))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to parse VPN record string `%s'\n"),
- s);
- return GNUNET_SYSERR;
- }
- *data_size = sizeof (struct vpn_data) + strlen (s_serv) + 1;
- *data = vpn = GNUNET_malloc (*data_size);
- if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_peer,
- &vpn->peer))
- {
- GNUNET_free (vpn);
- *data_size = 0;
- return GNUNET_SYSERR;
- }
- vpn->proto = htons ((uint16_t) proto);
- strcpy ((char*)&vpn[1], s_serv);
- return GNUNET_OK;
- case GNUNET_DNSPARSER_TYPE_TLSA:
- *data_size = sizeof (struct tlsa_data) + strlen (s) - 6;
- *data = tlsa = GNUNET_malloc (*data_size);
- if (4 != SSCANF (s, "%c %c %c %s",
- &tlsa->usage,
- &tlsa->selector,
- &tlsa->matching_type,
- (char*)&tlsa[1]))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to parse TLSA record string `%s'\n"),
- s);
- *data_size = 0;
- GNUNET_free (tlsa);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unsupported record type %d\n"),
- (int) type);
- return GNUNET_SYSERR;
- }
-}
-
-
-static struct {
- const char *name;
- uint32_t number;
-} name_map[] = {
- { "A", GNUNET_DNSPARSER_TYPE_A },
- { "NS", GNUNET_DNSPARSER_TYPE_NS },
- { "CNAME", GNUNET_DNSPARSER_TYPE_CNAME },
- { "SOA", GNUNET_DNSPARSER_TYPE_SOA },
- { "PTR", GNUNET_DNSPARSER_TYPE_PTR },
- { "MX", GNUNET_DNSPARSER_TYPE_MX },
- { "TXT", GNUNET_DNSPARSER_TYPE_TXT },
- { "AAAA", GNUNET_DNSPARSER_TYPE_AAAA },
- { "PKEY", GNUNET_NAMESTORE_TYPE_PKEY },
- { "PSEU", GNUNET_NAMESTORE_TYPE_PSEU },
- { "LEHO", GNUNET_NAMESTORE_TYPE_LEHO },
- { "VPN", GNUNET_NAMESTORE_TYPE_VPN },
- { "TLSA", GNUNET_DNSPARSER_TYPE_TLSA },
- { NULL, UINT32_MAX }
-};
-
-
-/**
- * Convert a type name (i.e. "AAAA") to the corresponding number.
- *
- * @param typename name to convert
- * @return corresponding number, UINT32_MAX on error
- */
-uint32_t
-GNUNET_NAMESTORE_typename_to_number (const char *typename)
-{
- unsigned int i;
-
- i=0;
- while ( (name_map[i].name != NULL) &&
- (0 != strcasecmp (typename, name_map[i].name)) )
- i++;
- return name_map[i].number;
-}
-
-
-/**
- * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
- *
- * @param type number of a type to convert
- * @return corresponding typestring, NULL on error
- */
-const char *
-GNUNET_NAMESTORE_number_to_typename (uint32_t type)
-{
- unsigned int i;
-
- i=0;
- while ( (name_map[i].name != NULL) &&
- (type != name_map[i].number) )
- i++;
- return name_map[i].name;
-}
-
-/**
- * Test if a given record is expired.
- *
- * @return GNUNET_YES if the record is expired,
- * GNUNET_NO if not
- */
-int
-GNUNET_NAMESTORE_is_expired (const struct GNUNET_NAMESTORE_RecordData *rd)
-{
- struct GNUNET_TIME_Absolute at;
-
- if (0 != (rd->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION))
- return GNUNET_NO;
- at.abs_value = rd->expiration_time;
- return (0 == GNUNET_TIME_absolute_get_remaining (at).rel_value) ? GNUNET_YES
: GNUNET_NO;
-}
-
-
-/* end of namestore_common.c */
Modified: gnunet/src/namestore/plugin_namestore_sqlite.c
===================================================================
--- gnunet/src/namestore/plugin_namestore_sqlite.c 2013-06-30 19:14:53 UTC
(rev 27690)
+++ gnunet/src/namestore/plugin_namestore_sqlite.c 2013-06-30 19:21:05 UTC
(rev 27691)
@@ -683,7 +683,7 @@
&name_hase, sizeof (struct
GNUNET_CRYPTO_ShortHashCode),
SQLITE_STATIC)) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ITERATE NAME HASH: `%8s'",
GNUNET_short_h2s(&name_hase));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ITERATE NAME HASH: `%8s'",
GNUNET_NAMESTORE_short_h2s(&name_hase));
LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind_XXXX");
if (SQLITE_OK != sqlite3_reset (stmt))
Modified: gnunet/src/namestore/test_namestore_api_create.c
===================================================================
--- gnunet/src/namestore/test_namestore_api_create.c 2013-06-30 19:14:53 UTC
(rev 27690)
+++ gnunet/src/namestore/test_namestore_api_create.c 2013-06-30 19:21:05 UTC
(rev 27691)
@@ -254,7 +254,7 @@
for (c = 0; c < RECORDS; c++)
{
- if (GNUNET_NO == GNUNET_NAMESTORE_records_cmp(&rd[c],
&s_first_record[c]))
+ if (GNUNET_NO == GNUNET_NAMESTORE_records_cmp (&rd[c],
&s_first_record[c]))
{
GNUNET_break (0);
failed = GNUNET_YES;
@@ -280,7 +280,7 @@
res = 1;
/* create a second record */
- s_second_record = GNUNET_malloc(sizeof (struct
GNUNET_NAMESTORE_RecordData) + TEST_CREATE_RECORD_DATALEN);
+ s_second_record = GNUNET_malloc (sizeof (struct
GNUNET_NAMESTORE_RecordData) + TEST_CREATE_RECORD_DATALEN);
s_second_record->expiration_time = UINT64_MAX;
s_second_record->record_type = TEST_CREATE_RECORD_TYPE;
s_second_record->flags = GNUNET_NAMESTORE_RF_AUTHORITY;
@@ -288,7 +288,9 @@
s_second_record->data_size = TEST_CREATE_RECORD_DATALEN;
memset ((char *) s_second_record->data, TEST_CREATE_RECORD_DATA,
TEST_CREATE_RECORD_DATALEN);
- GNUNET_NAMESTORE_record_create (nsh, privkey, name, s_second_record,
&create_second_cont, name);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, name,
+ 1, s_second_record,
+ &create_second_cont, name);
}
else
@@ -375,7 +377,7 @@
/* create random zone hash */
GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct
GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), &s_zone);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name,
GNUNET_short_h2s (&s_zone));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name,
GNUNET_NAMESTORE_short_h2s (&s_zone));
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
@@ -383,7 +385,9 @@
GNUNET_break (s_name != NULL);
/* create initial record */
- GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record,
&create_first_cont, s_name);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name,
+ 1, s_first_record,
+ &create_first_cont, s_name);
}
Modified: gnunet/src/namestore/test_namestore_api_create_update.c
===================================================================
--- gnunet/src/namestore/test_namestore_api_create_update.c 2013-06-30
19:14:53 UTC (rev 27690)
+++ gnunet/src/namestore/test_namestore_api_create_update.c 2013-06-30
19:21:05 UTC (rev 27691)
@@ -141,7 +141,9 @@
{
res = 0;
s_first_record->expiration_time = GNUNET_TIME_absolute_get ().abs_value;
- GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record,
&create_updated_cont, s_name);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name,
+ 1, s_first_record,
+ &create_updated_cont, s_name);
}
else
{
@@ -162,7 +164,9 @@
{
res = 0;
/* check if record was created correct */
- GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record,
&create_identical_cont, s_name);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name,
+ 1, s_first_record,
+ &create_identical_cont, s_name);
}
else
{
@@ -228,7 +232,7 @@
/* create random zone hash */
GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct
GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), &s_zone);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name,
GNUNET_short_h2s (&s_zone));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name,
GNUNET_NAMESTORE_short_h2s (&s_zone));
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
@@ -236,7 +240,9 @@
GNUNET_break (s_name != NULL);
/* create initial record */
- GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record,
&create_first_cont, s_name);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name,
+ 1, s_first_record,
+ &create_first_cont, s_name);
}
Modified: gnunet/src/namestore/test_namestore_api_remove.c
===================================================================
--- gnunet/src/namestore/test_namestore_api_remove.c 2013-06-30 19:14:53 UTC
(rev 27690)
+++ gnunet/src/namestore/test_namestore_api_remove.c 2013-06-30 19:21:05 UTC
(rev 27691)
@@ -204,7 +204,9 @@
res = 0;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for `%s'\n", name);
- GNUNET_NAMESTORE_record_remove (nsh, privkey, name, &s_rd[0],
&remove_cont, name);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, name,
+ 0, NULL,
+ &remove_cont, name);
}
else
{
@@ -275,7 +277,7 @@
/* create random zone hash */
GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct
GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), &s_zone);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name,
GNUNET_short_h2s (&s_zone));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name,
GNUNET_NAMESTORE_short_h2s (&s_zone));
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
GNUNET_break (s_rd != NULL);
Modified: gnunet/src/namestore/test_namestore_api_remove_not_existing_record.c
===================================================================
--- gnunet/src/namestore/test_namestore_api_remove_not_existing_record.c
2013-06-30 19:14:53 UTC (rev 27690)
+++ gnunet/src/namestore/test_namestore_api_remove_not_existing_record.c
2013-06-30 19:21:05 UTC (rev 27691)
@@ -136,16 +136,9 @@
{
res = 0;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing non existing record for
`%s'\n", name);
-
- struct GNUNET_NAMESTORE_RecordData rd;
- char data[TEST_REMOVE_RECORD_DATALEN];
-
- rd.expiration_time = GNUNET_TIME_absolute_get().abs_value;
- rd.record_type = TEST_REMOVE_RECORD_TYPE;
- rd.data_size = TEST_REMOVE_RECORD_DATALEN;
- rd.data = &data;
-
- GNUNET_NAMESTORE_record_remove (nsh, privkey, name, &rd, &remove_cont,
name);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, name,
+ 0, NULL,
+ &remove_cont, name);
}
else
{
Modified: gnunet/src/namestore/test_namestore_api_zone_iteration.c
===================================================================
--- gnunet/src/namestore/test_namestore_api_zone_iteration.c 2013-06-30
19:14:53 UTC (rev 27690)
+++ gnunet/src/namestore/test_namestore_api_zone_iteration.c 2013-06-30
19:21:05 UTC (rev 27691)
@@ -410,7 +410,9 @@
s_rd_1 = create_record(1);
et.abs_value = s_rd_1->expiration_time;
sig_1 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_1, s_rd_1, 1);
- GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont,
NULL);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name_1,
+ 1, s_rd_1,
+ &put_cont, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
@@ -419,7 +421,9 @@
et.abs_value = s_rd_2->expiration_time;
sig_2 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_2, s_rd_2, 1);
- GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont,
NULL);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name_2,
+ 1, s_rd_2,
+ &put_cont, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
/* name in different zone */
Modified: gnunet/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
===================================================================
--- gnunet/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
2013-06-30 19:14:53 UTC (rev 27690)
+++ gnunet/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
2013-06-30 19:21:05 UTC (rev 27691)
@@ -182,7 +182,7 @@
const struct GNUNET_CRYPTO_EccSignature *signature)
{
int failed = GNUNET_NO;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n",
GNUNET_short_h2s (&zone));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n",
GNUNET_NAMESTORE_short_h2s (&zone));
if ((zone_key == NULL) && (name == NULL))
{
GNUNET_break (2 == returned_records);
@@ -285,7 +285,7 @@
res = 1;
returned_records = 0;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting
iteration over zone `%s'\n",
- GNUNET_short_h2s(&zone));
+ GNUNET_NAMESTORE_short_h2s(&zone));
zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
&zone,
GNUNET_NAMESTORE_RF_NONE,
@@ -356,14 +356,18 @@
s_rd_1 = create_record(1);
et.abs_value = s_rd_1[0].expiration_time;
sig_1 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_1, s_rd_1, 1);
- GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont,
NULL);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name_1,
+ 1, s_rd_1,
+ &put_cont, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
GNUNET_asprintf(&s_name_2, "dummy2");
s_rd_2 = create_record(1);
et.abs_value = s_rd_2[0].expiration_time;
sig_2 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_2, s_rd_2, 1);
- GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont,
NULL);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name_2,
+ 1, s_rd_2,
+ &put_cont, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
/* name in different zone */
@@ -371,7 +375,8 @@
s_rd_3 = create_record(1);
et.abs_value = s_rd_3[0].expiration_time;
sig_3 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_3, s_rd_3, 1);
- GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3,
GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3, &put_cont, NULL);
+ GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3,
+ GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3,
&put_cont, NULL);
}
Modified: gnunet/src/namestore/test_namestore_api_zone_iteration_stop.c
===================================================================
--- gnunet/src/namestore/test_namestore_api_zone_iteration_stop.c
2013-06-30 19:14:53 UTC (rev 27690)
+++ gnunet/src/namestore/test_namestore_api_zone_iteration_stop.c
2013-06-30 19:21:05 UTC (rev 27691)
@@ -407,7 +407,8 @@
s_rd_1 = create_record(1);
et.abs_value = s_rd_1[0].expiration_time;
sig_1 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_1, s_rd_1, 1);
- GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont,
NULL);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name_1,
+ 1, s_rd_1, &put_cont, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
@@ -416,7 +417,8 @@
et.abs_value = s_rd_2[0].expiration_time;
sig_2 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_2, s_rd_2, 1);
- GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont,
NULL);
+ GNUNET_NAMESTORE_record_put_by_authority (nsh, privkey, s_name_2,
+ 1, s_rd_2, &put_cont, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
/* name in different zone */
Modified: gnunet/src/namestore/test_namestore_api_zone_to_name.c
===================================================================
--- gnunet/src/namestore/test_namestore_api_zone_to_name.c 2013-06-30
19:14:53 UTC (rev 27690)
+++ gnunet/src/namestore/test_namestore_api_zone_to_name.c 2013-06-30
19:21:05 UTC (rev 27691)
@@ -184,7 +184,7 @@
/* zone hash */
GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct
GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), &s_zone);
GNUNET_CRYPTO_short_hash (s_name, strlen (s_name) + 1, &s_zone_value);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using PKEY `%s' \n", GNUNET_short_h2s
(&s_zone_value));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using PKEY `%s' \n",
GNUNET_NAMESTORE_short_h2s (&s_zone_value));
struct GNUNET_NAMESTORE_RecordData rd;
rd.expiration_time = GNUNET_TIME_absolute_get().abs_value;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r27691 - in gnunet/src: include namestore,
gnunet <=