#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"
-#include "platform.h"
-#include <gcrypt.h>
-#include "gnunet_common.h"
-#include "gnunet_crypto_lib.h"
-#include "gnunet_disk_lib.h"
-
#define DEBUG_GNS_API GNUNET_EXTRA_LOGGING
#define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__)
*/
struct GNUNET_NAMESTORE_QueueEntry
{
+
+ /**
+ * Kept in a DLL.
+ */
struct GNUNET_NAMESTORE_QueueEntry *next;
+
+ /**
+ * Kept in a DLL.
+ */
struct GNUNET_NAMESTORE_QueueEntry *prev;
struct GNUNET_NAMESTORE_Handle *nsh;
*/
struct GNUNET_NAMESTORE_ZoneIterator
{
+
+ /**
+ * Kept in a DLL.
+ */
struct GNUNET_NAMESTORE_ZoneIterator *next;
+
+ /**
+ * Kept in a DLL.
+ */
struct GNUNET_NAMESTORE_ZoneIterator *prev;
uint32_t op_id;
};
+
+/**
+ * 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)
+{
+ static struct {
+ const char *name;
+ uint32_t number;
+ } 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_GNS_TYPE_PKEY },
+ { "PSEU", GNUNET_GNS_TYPE_PSEU },
+ { NULL, UINT32_MAX }
+ };
+ unsigned int i;
+
+ i=0;
+ while ( (map[i].name != NULL) &&
+ (0 != strcasecmp (typename, map[i].name)) )
+ i++;
+ return map[i].number;
+}
+
+
/**
* Disconnect from service and then reconnect.
*
"RECORD_CREATE_RESPONSE");
struct GNUNET_NAMESTORE_Handle *h = qe->nsh;
- int res = GNUNET_OK;
- if (ntohs (msg->op_result) == GNUNET_OK)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' %i\n",
+ "RECORD_CREATE_RESPONSE", ntohs (msg->op_result));
+ if (ntohs (msg->op_result) == GNUNET_YES)
{
- res = GNUNET_OK;
if (qe->cont != NULL)
{
- qe->cont (qe->cont_cls, res, _("Namestore added record successfully"));
+ qe->cont (qe->cont_cls, GNUNET_YES, _("Namestore added record successfully"));
}
}
else if (ntohs (msg->op_result) == GNUNET_NO)
{
- res = GNUNET_SYSERR;
if (qe->cont != NULL)
{
- qe->cont (qe->cont_cls, res, _("Namestore failed to add record"));
+ qe->cont (qe->cont_cls, GNUNET_NO, _("Namestore record already existed"));
}
}
else
{
- GNUNET_break_op (0);
- return;
+ if (qe->cont != NULL)
+ {
+ qe->cont (qe->cont_cls, GNUNET_SYSERR, _("Namestore failed to add record\n"));
+ }
}
/* Operation done, remove */
return h;
}
+struct DisconnectContext
+{
+ struct GNUNET_NAMESTORE_Handle *h;
+ int drop;
+};
-/**
- * Disconnect from the namestore service (and free associated
- * resources).
- *
- * @param h handle to the namestore
- * @param drop set to GNUNET_YES to delete all data in namestore (!)
- */
-void
-GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h, int drop)
+static void
+clean_up_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PendingMessage *p;
struct GNUNET_NAMESTORE_QueueEntry *q;
struct GNUNET_NAMESTORE_ZoneIterator *z;
-
+ struct GNUNET_NAMESTORE_Handle *h = cls;
GNUNET_assert (h != NULL);
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
while (NULL != (p = h->pending_head))
{
GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, p);
while (NULL != (q = h->op_head))
{
+ GNUNET_break (0);
GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, q);
GNUNET_free (q);
}
}
GNUNET_free(h);
h = NULL;
+};
+
+static size_t
+transmit_disconnect_to_namestore (void *cls, size_t size, void *buf)
+{
+ struct DisconnectContext * d_ctx = cls;
+ struct DisconnectMessage d_msg;
+ struct GNUNET_NAMESTORE_Handle *h = d_ctx->h;
+ int res;
+
+ d_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_DISCONNECT);
+ d_msg.header.size = htons (sizeof (struct DisconnectMessage));
+ d_msg.drop = htonl (d_ctx->drop);
+
+ h->th = NULL;
+ if ((size == 0) || (buf == NULL) || (size < sizeof (struct DisconnectMessage)))
+ {
+ GNUNET_break (0);
+ res = 0;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to service \n", "NAMESTORE_DISCONNECT");
+ memcpy (buf, &d_msg, sizeof (struct DisconnectMessage));
+ res = sizeof (struct DisconnectMessage);
+ }
+
+ GNUNET_SCHEDULER_add_now (&clean_up_task, h);
+ GNUNET_free (d_ctx);
+ return res;
+}
+
+/**
+ * Disconnect from the namestore service (and free associated
+ * resources).
+ *
+ * @param h handle to the namestore
+ * @param drop set to GNUNET_YES to delete all data in namestore (!)
+ */
+void
+GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h, int drop)
+{
+ if (h->th != NULL)
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel(h->th);
+ h->th = NULL;
+ }
+ if (h->client != NULL)
+ {
+ struct DisconnectContext *d_ctx = GNUNET_malloc (sizeof (struct DisconnectContext));
+ d_ctx->h = h;
+ d_ctx->drop = drop;
+
+ h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, sizeof (struct DisconnectMessage),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_NO, &transmit_disconnect_to_namestore,
+ d_ctx);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not send disconnect notification to namestore service, we are not connected!\n");
+ if (GNUNET_YES == drop)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "NAMESTORE will not drop content\n");
+ GNUNET_SCHEDULER_add_now (&clean_up_task, h);
+ }
}
const struct GNUNET_NAMESTORE_RecordData *rd,
const struct GNUNET_CRYPTO_RsaSignature *signature)
{
- return GNUNET_SYSERR;
+ int res = GNUNET_SYSERR;
+ size_t rd_ser_len = 0;
+ size_t name_len = 0;
+ char * name_tmp;
+ char * rd_tmp;
+ struct GNUNET_CRYPTO_RsaSignaturePurpose *sig_purpose;
+
+ GNUNET_assert (public_key != NULL);
+ GNUNET_assert (name != NULL);
+ GNUNET_assert (signature != NULL);
+
+ rd_ser_len = GNUNET_NAMESTORE_records_get_size(rd_count, rd);
+ char rd_ser[rd_ser_len];
+ GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
+
+ name_len = strlen (name) + 1;
+
+ sig_purpose = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + rd_ser_len + name_len);
+ sig_purpose->size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)+ rd_ser_len + name_len);
+ sig_purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN);
+ name_tmp = (char *) &sig_purpose[1];
+ rd_tmp = &name_tmp[name_len];
+ memcpy (name_tmp, name, name_len);
+ memcpy (rd_tmp, rd_ser, rd_ser_len);
+
+ res = GNUNET_CRYPTO_rsa_verify(GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, sig_purpose, signature, public_key);
+
+ GNUNET_free (sig_purpose);
+
+ return res;
}
/**
memcpy (name_tmp, name, name_len);
memcpy (rd_tmp, rd_ser, rd_ser_len);
+ GNUNET_free (pkey_enc);
+
GNUNET_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);