/*
This file is part of GNUnet.
- (C) 2011-2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2011-2013 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
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.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @file gns/gnunet-service-gns.c
#include "gnunet_dht_service.h"
#include "gnunet_namecache_service.h"
#include "gnunet_namestore_service.h"
+#include "gnunet_identity_service.h"
#include "gnunet_gns_service.h"
#include "gnunet_statistics_service.h"
#include "gns.h"
*/
static struct GNUNET_NAMECACHE_Handle *namecache_handle;
+/**
+ * Our handle to the identity service
+ */
+static struct GNUNET_IDENTITY_Handle *identity_handle;
+
+/**
+ * Our handle to the identity operation to find the master zone
+ * for intercepted queries.
+ */
+static struct GNUNET_IDENTITY_Operation *identity_op;
+
/**
* Handle to iterate over our authoritative zone in namestore
*/
/**
* zone publish task
*/
-static GNUNET_SCHEDULER_TaskIdentifier zone_publish_task;
+static struct GNUNET_SCHEDULER_Task * zone_publish_task;
/**
* #GNUNET_YES if zone has never been published before
* @param tc unused
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
{
struct ClientLookupHandle *clh;
struct MonitorActivity *ma;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Shutting down!\n");
- GNUNET_SERVER_notification_context_destroy (nc);
+ if (NULL != nc)
+ {
+ GNUNET_SERVER_notification_context_destroy (nc);
+ nc = NULL;
+ }
while (NULL != (clh = clh_head))
{
GNUNET_SERVER_client_set_user_context (clh->client, NULL);
}
GNS_interceptor_done ();
+ if (NULL != identity_op)
+ {
+ GNUNET_IDENTITY_cancel (identity_op);
+ identity_op = NULL;
+ }
+ if (NULL != identity_handle)
+ {
+ GNUNET_IDENTITY_disconnect (identity_handle);
+ identity_handle = NULL;
+ }
GNS_resolver_done ();
GNS_shorten_done ();
while (NULL != (ma = ma_head))
GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
statistics = NULL;
}
- if (GNUNET_SCHEDULER_NO_TASK != zone_publish_task)
+ if (NULL != zone_publish_task)
{
GNUNET_SCHEDULER_cancel (zone_publish_task);
- zone_publish_task = GNUNET_SCHEDULER_NO_TASK;
+ zone_publish_task = NULL;
}
if (NULL != namestore_iter)
{
* Method called periodically that triggers iteration over authoritative records
*
* @param cls closure
- * @param tc task context
*/
static void
-publish_zone_dht_next (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+publish_zone_dht_next (void *cls)
{
- zone_publish_task = GNUNET_SCHEDULER_NO_TASK;
+ zone_publish_task = NULL;
GNUNET_NAMESTORE_zone_iterator_next (namestore_iter);
}
* Periodically iterate over our zone and store everything in dht
*
* @param cls NULL
- * @param tc task context
*/
static void
-publish_zone_dht_start (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+publish_zone_dht_start (void *cls);
/**
block_size,
block,
expire,
- DHT_OPERATION_TIMEOUT,
&dht_put_continuation,
pc_arg);
GNUNET_free (block);
* Periodically iterate over all zones and store everything in DHT
*
* @param cls NULL
- * @param tc task context
*/
static void
-publish_zone_dht_start (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+publish_zone_dht_start (void *cls)
{
- zone_publish_task = GNUNET_SCHEDULER_NO_TASK;
+ zone_publish_task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting DHT zone update!\n");
size_t len;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending `%s' message with %d results\n",
- "LOOKUP_RESULT",
- rd_count);
+ "Sending LOOKUP_RESULT message with %u results\n",
+ (unsigned int) rd_count);
len = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
rmsg = GNUNET_malloc (len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage));
const struct GNUNET_GNS_ClientLookupMessage *sh_msg;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message\n",
- "LOOKUP");
+ "Received LOOKUP message\n");
msg_size = ntohs (message->size);
if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage))
{
}
+/**
+ * Method called to inform about the ego to be used for the master zone
+ * for DNS interceptions.
+ *
+ * This function is only called ONCE, and 'NULL' being passed in
+ * @a ego does indicate that interception is not configured.
+ * If @a ego is non-NULL, we should start to intercept DNS queries
+ * and resolve ".gnu" queries using the given ego as the master zone.
+ *
+ * @param cls closure, our `const struct GNUNET_CONFIGURATION_Handle *c`
+ * @param ego ego handle
+ * @param ctx context for application to store data for this ego
+ * (during the lifetime of this process, initially NULL)
+ * @param name name assigned by the user for this ego,
+ * NULL if the user just deleted the ego and it
+ * must thus no longer be used
+ */
+static void
+identity_intercept_cb (void *cls,
+ struct GNUNET_IDENTITY_Ego *ego,
+ void **ctx,
+ const char *name)
+{
+ const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ struct GNUNET_CRYPTO_EcdsaPublicKey dns_root;
+
+ identity_op = NULL;
+ if (NULL == ego)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("No ego configured for `%s`\n"),
+ "gns-intercept");
+ return;
+ }
+ GNUNET_IDENTITY_ego_get_public_key (ego,
+ &dns_root);
+ if (GNUNET_SYSERR ==
+ GNS_interceptor_init (&dns_root, cfg))
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ return;
+ }
+}
+
+
/**
* Process GNS requests.
*
* @param c configuration to use
*/
static void
-run (void *cls, struct GNUNET_SERVER_Handle *server,
+run (void *cls,
+ struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *c)
{
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
{ &handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0},
{NULL, NULL, 0, 0}
};
- struct GNUNET_CRYPTO_EcdsaPublicKey dns_root;
unsigned long long max_parallel_bg_queries = 0;
- char *dns_root_name;
v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6);
v4_enabled = GNUNET_NETWORK_test_pf (PF_INET);
return;
}
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (c, "gns", "DNS_ROOT",
- &dns_root_name))
+ identity_handle = GNUNET_IDENTITY_connect (c,
+ NULL,
+ NULL);
+ if (NULL == identity_handle)
{
- if (GNUNET_OK !=
- GNUNET_CRYPTO_ecdsa_public_key_from_string (dns_root_name,
- strlen (dns_root_name),
- &dns_root))
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "gns", "DNS_ROOT",
- _("valid public key required"));
- GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
- GNUNET_free (dns_root_name);
- return;
- }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "DNS hijacking with root `%s' enabled. Connecting to DNS service.\n",
- dns_root_name);
- GNUNET_free (dns_root_name);
- if (GNUNET_SYSERR ==
- GNS_interceptor_init (&dns_root, c))
- {
- GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
- return;
- }
+ "Could not connect to identity service!\n");
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Looking for gns-intercept ego\n");
+ identity_op = GNUNET_IDENTITY_get (identity_handle,
+ "gns-intercept",
+ &identity_intercept_cb,
+ (void *) c);
}
GNS_resolver_init (namecache_handle,
dht_handle,
&monitor_sync_event,
NULL);
GNUNET_break (NULL != zmon);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}