2 This file is part of GNUnet.
3 (C) 2011-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file gns/gnunet-service-gns.c
22 * @brief GNU Name System (main service)
23 * @author Martin Schanzenbach
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_dns_service.h"
29 #include "gnunet_dnsparser_lib.h"
30 #include "gnunet_dht_service.h"
31 #include "gnunet_namecache_service.h"
32 #include "gnunet_namestore_service.h"
33 #include "gnunet_gns_service.h"
34 #include "gnunet_statistics_service.h"
36 #include "gnunet-service-gns_resolver.h"
37 #include "gnunet-service-gns_shorten.h"
38 #include "gnunet-service-gns_interceptor.h"
39 #include "gnunet_protocols.h"
42 * The initial interval in milliseconds btween puts in
45 #define INITIAL_PUT_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS
48 * The upper bound for the zone iteration interval in milliseconds
50 #define MINIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_SECONDS
53 * The default put interval for the zone iteration. In case
56 #define DEFAULT_ZONE_PUBLISH_TIME_WINDOW GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
59 * The factor the current zone iteration interval is divided by for each
60 * additional new record
62 #define LATE_ITERATION_SPEEDUP_FACTOR 2
65 * How long until a DHT PUT attempt should time out?
67 #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
70 * What replication level do we use for DHT PUT operations?
72 #define DHT_GNS_REPLICATION_LEVEL 5
76 * Handle to a lookup operation from api
78 struct ClientLookupHandle
82 * We keep these in a DLL.
84 struct ClientLookupHandle *next;
87 * We keep these in a DLL.
89 struct ClientLookupHandle *prev;
92 * Handle to the requesting client
94 struct GNUNET_SERVER_Client *client;
97 * Active handle for the lookup.
99 struct GNS_ResolverHandle *lookup;
110 * Handle for DHT PUT activity triggered from the namestore monitor.
112 struct MonitorActivity
117 struct MonitorActivity *next;
122 struct MonitorActivity *prev;
125 * Handle for the DHT PUT operation.
127 struct GNUNET_DHT_PutHandle *ph;
132 * Our handle to the DHT
134 static struct GNUNET_DHT_Handle *dht_handle;
137 * Active DHT put operation (or NULL)
139 static struct GNUNET_DHT_PutHandle *active_put;
142 * Our handle to the namestore service
144 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
147 * Our handle to the namecache service
149 static struct GNUNET_NAMECACHE_Handle *namecache_handle;
152 * Handle to iterate over our authoritative zone in namestore
154 static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
157 * Handle to monitor namestore changes to instant propagation.
159 static struct GNUNET_NAMESTORE_ZoneMonitor *zmon;
162 * Our notification context.
164 static struct GNUNET_SERVER_NotificationContext *nc;
169 static struct ClientLookupHandle *clh_head;
174 static struct ClientLookupHandle *clh_tail;
177 * Head of monitor activities; kept in a DLL.
179 static struct MonitorActivity *ma_head;
182 * Tail of monitor activities; kept in a DLL.
184 static struct MonitorActivity *ma_tail;
187 * Useful for zone update for DHT put
189 static unsigned long long num_public_records;
192 * Last seen record count
194 static unsigned long long last_num_public_records;
197 * Minimum relative expiration time of records seem during the current
200 static struct GNUNET_TIME_Relative min_relative_record_time;
203 * Zone iteration PUT interval.
205 static struct GNUNET_TIME_Relative put_interval;
208 * Default time window for zone iteration
210 static struct GNUNET_TIME_Relative zone_publish_time_window_default;
213 * Time window for zone iteration, adjusted based on relative record
214 * expiration times in our zone.
216 static struct GNUNET_TIME_Relative zone_publish_time_window;
221 static GNUNET_SCHEDULER_TaskIdentifier zone_publish_task;
224 * #GNUNET_YES if zone has never been published before
226 static int first_zone_iteration;
229 * #GNUNET_YES if ipv6 is supported
231 static int v6_enabled;
234 * #GNUNET_YES if ipv4 is supported
236 static int v4_enabled;
239 * Handle to the statistics service
241 static struct GNUNET_STATISTICS_Handle *statistics;
245 * Task run during shutdown.
251 shutdown_task (void *cls,
252 const struct GNUNET_SCHEDULER_TaskContext *tc)
254 struct ClientLookupHandle *clh;
255 struct MonitorActivity *ma;
257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
259 GNUNET_SERVER_notification_context_destroy (nc);
260 while (NULL != (clh = clh_head))
262 GNUNET_SERVER_client_set_user_context (clh->client, (void *)NULL);
263 GNS_resolver_lookup_cancel (clh->lookup);
264 GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh);
268 GNS_interceptor_done ();
269 GNS_resolver_done ();
271 while (NULL != (ma = ma_head))
273 GNUNET_DHT_put_cancel (ma->ph);
274 GNUNET_CONTAINER_DLL_remove (ma_head,
279 if (NULL != statistics)
281 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
284 if (GNUNET_SCHEDULER_NO_TASK != zone_publish_task)
286 GNUNET_SCHEDULER_cancel (zone_publish_task);
287 zone_publish_task = GNUNET_SCHEDULER_NO_TASK;
289 if (NULL != namestore_iter)
291 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
292 namestore_iter = NULL;
296 GNUNET_NAMESTORE_zone_monitor_stop (zmon);
299 if (NULL != namestore_handle)
301 GNUNET_NAMESTORE_disconnect (namestore_handle);
302 namestore_handle = NULL;
304 if (NULL != namecache_handle)
306 GNUNET_NAMECACHE_disconnect (namecache_handle);
307 namecache_handle = NULL;
309 if (NULL != active_put)
311 GNUNET_DHT_put_cancel (active_put);
314 if (NULL != dht_handle)
316 GNUNET_DHT_disconnect (dht_handle);
323 * Method called periodically that triggers iteration over authoritative records
326 * @param tc task context
329 publish_zone_dht_next (void *cls,
330 const struct GNUNET_SCHEDULER_TaskContext *tc)
332 zone_publish_task = GNUNET_SCHEDULER_NO_TASK;
333 GNUNET_NAMESTORE_zone_iterator_next (namestore_iter);
338 * Periodically iterate over our zone and store everything in dht
341 * @param tc task context
344 publish_zone_dht_start (void *cls,
345 const struct GNUNET_SCHEDULER_TaskContext *tc);
349 * Continuation called from DHT once the PUT operation is done.
351 * @param cls closure, NULL if called from regular iteration,
352 * `struct MonitorActivity` if called from #handle_monitor_event.
353 * @param success #GNUNET_OK on success
356 dht_put_continuation (void *cls,
359 struct MonitorActivity *ma = cls;
360 struct GNUNET_TIME_Relative next_put_interval;
362 num_public_records++;
366 if ( (num_public_records > last_num_public_records) &&
367 (GNUNET_NO == first_zone_iteration) )
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
370 "Last record count was lower than current record count. Reducing interval.\n");
371 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
373 next_put_interval = GNUNET_TIME_relative_divide (put_interval,
374 LATE_ITERATION_SPEEDUP_FACTOR);
377 next_put_interval = put_interval;
379 GNUNET_STATISTICS_set (statistics,
380 "Current zone iteration interval (ms)",
381 next_put_interval.rel_value_us / 1000LL,
383 zone_publish_task = GNUNET_SCHEDULER_add_delayed (next_put_interval,
384 &publish_zone_dht_next,
389 GNUNET_CONTAINER_DLL_remove (ma_head,
398 * Convert namestore records from the internal format to that
399 * suitable for publication (removes private records, converts
400 * to absolute expiration time).
402 * @param rd input records
403 * @param rd_count size of the @a rd and @a rd_public arrays
404 * @param rd_public where to write the converted records
405 * @return number of records written to @a rd_public
408 convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
409 unsigned int rd_count,
410 struct GNUNET_GNSRECORD_Data *rd_public)
412 struct GNUNET_TIME_Absolute now;
413 unsigned int rd_public_count;
417 now = GNUNET_TIME_absolute_get ();
418 for (i=0;i<rd_count;i++)
419 if (0 == (rd[i].flags & (GNUNET_GNSRECORD_RF_PRIVATE |
420 GNUNET_GNSRECORD_RF_PENDING)))
422 rd_public[rd_public_count] = rd[i];
423 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
425 /* GNUNET_GNSRECORD_block_create will convert to absolute time;
426 we just need to adjust our iteration frequency */
427 min_relative_record_time.rel_value_us =
428 GNUNET_MIN (rd_public[rd_public_count].expiration_time,
429 min_relative_record_time.rel_value_us);
431 else if (rd_public[rd_public_count].expiration_time < now.abs_value_us)
433 /* record already expired, skip it */
438 return rd_public_count;
443 * Store GNS records in the DHT.
445 * @param key key of the zone
446 * @param label label to store under
447 * @param rd_public public record data
448 * @param rd_public_count number of records in @a rd_public
449 * @param pc_arg closure argument to pass to the #dht_put_continuation
450 * @return DHT PUT handle, NULL on error
452 static struct GNUNET_DHT_PutHandle *
453 perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
455 const struct GNUNET_GNSRECORD_Data *rd_public,
456 unsigned int rd_public_count,
459 struct GNUNET_GNSRECORD_Block *block;
460 struct GNUNET_HashCode query;
461 struct GNUNET_TIME_Absolute expire;
463 struct GNUNET_DHT_PutHandle *ret;
465 expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count,
467 block = GNUNET_GNSRECORD_block_create (key,
472 block_size = ntohl (block->purpose.size)
473 + sizeof (struct GNUNET_CRYPTO_EcdsaSignature)
474 + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
475 GNUNET_GNSRECORD_query_from_private_key (key,
478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
479 "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n",
482 GNUNET_STRINGS_absolute_time_to_string (expire),
483 GNUNET_h2s (&query));
484 ret = GNUNET_DHT_put (dht_handle, &query,
485 DHT_GNS_REPLICATION_LEVEL,
486 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
487 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
491 DHT_OPERATION_TIMEOUT,
492 &dht_put_continuation,
500 * Function used to put all records successively into the DHT.
502 * @param cls the closure (NULL)
503 * @param key the private key of the authority (ours)
504 * @param name the name of the records, NULL once the iteration is done
505 * @param rd_count the number of records in @a rd
506 * @param rd the record data
509 put_gns_record (void *cls,
510 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
512 unsigned int rd_count,
513 const struct GNUNET_GNSRECORD_Data *rd)
515 struct GNUNET_GNSRECORD_Data rd_public[rd_count];
516 unsigned int rd_public_count;
520 /* we're done with one iteration, calculate when to do the next one */
521 namestore_iter = NULL;
522 last_num_public_records = num_public_records;
523 first_zone_iteration = GNUNET_NO;
524 if (0 == num_public_records)
527 * If no records are known (startup) or none present
528 * we can safely set the interval to the value for a single
531 put_interval = zone_publish_time_window;
532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
533 "No records in namestore database.\n");
537 zone_publish_time_window
538 = GNUNET_TIME_relative_min (GNUNET_TIME_relative_divide (min_relative_record_time,
540 zone_publish_time_window_default);
541 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
544 /* reset for next iteration */
545 min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL;
546 put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL,
549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
550 "Zone iteration finished. Adjusted zone iteration interval to %s\n",
551 GNUNET_STRINGS_relative_time_to_string (put_interval, GNUNET_YES));
552 GNUNET_STATISTICS_set (statistics,
553 "Current zone iteration interval (in ms)",
554 put_interval.rel_value_us / 1000LL,
556 GNUNET_STATISTICS_update (statistics,
557 "Number of zone iterations",
560 GNUNET_STATISTICS_set (statistics,
561 "Number of public records in DHT",
562 last_num_public_records,
564 if (0 == num_public_records)
565 zone_publish_task = GNUNET_SCHEDULER_add_delayed (put_interval,
566 &publish_zone_dht_start,
569 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
574 rd_public_count = convert_records_for_export (rd,
578 /* We got a set of records to publish */
579 if (0 == rd_public_count)
581 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next,
586 active_put = perform_dht_put (key,
591 if (NULL == active_put)
594 dht_put_continuation (NULL, GNUNET_NO);
600 * Periodically iterate over our zone and store everything in dht
603 * @param tc task context
606 publish_zone_dht_start (void *cls,
607 const struct GNUNET_SCHEDULER_TaskContext *tc)
609 zone_publish_task = GNUNET_SCHEDULER_NO_TASK;
611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
612 "Starting DHT zone update!\n");
613 /* start counting again */
614 num_public_records = 0;
615 namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
616 NULL, /* All zones */
623 * Process a record that was stored in the namestore
624 * (invoked by the monitor).
626 * @param cls closure, NULL
627 * @param zone private key of the zone; NULL on disconnect
628 * @param label label of the records; NULL on disconnect
629 * @param rd_count number of entries in @a rd array, 0 if label was deleted
630 * @param rd array of records with data to store
633 handle_monitor_event (void *cls,
634 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
636 unsigned int rd_count,
637 const struct GNUNET_GNSRECORD_Data *rd)
639 struct GNUNET_GNSRECORD_Data rd_public[rd_count];
640 unsigned int rd_public_count;
641 struct MonitorActivity *ma;
643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
644 "Received %u records for label `%s' via namestore monitor\n",
647 /* filter out records that are not public, and convert to
648 absolute expiration time. */
649 rd_public_count = convert_records_for_export (rd, rd_count,
651 if (0 == rd_public_count)
652 return; /* nothing to do */
653 ma = GNUNET_new (struct MonitorActivity);
654 ma->ph = perform_dht_put (zone, label,
659 /* PUT failed, do not remember operation */
663 GNUNET_CONTAINER_DLL_insert (ma_head,
669 /* END DHT ZONE PROPAGATION */
673 * Reply to client with the result from our lookup.
675 * @param cls the closure (our client lookup handle)
676 * @param rd_count the number of records in @a rd
677 * @param rd the record data
680 send_lookup_response (void* cls,
682 const struct GNUNET_GNSRECORD_Data *rd)
684 struct ClientLookupHandle *clh = cls;
685 struct GNUNET_GNS_ClientLookupResultMessage *rmsg;
688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
689 "Sending `%s' message with %d results\n",
693 len = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
694 rmsg = GNUNET_malloc (len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage));
695 rmsg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT);
696 rmsg->header.size = htons (len + sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
697 rmsg->id = clh->request_id;
698 rmsg->rd_count = htonl (rd_count);
699 GNUNET_GNSRECORD_records_serialize (rd_count, rd, len,
701 GNUNET_SERVER_notification_context_unicast (nc,
706 GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh);
707 GNUNET_SERVER_client_set_user_context (clh->client, (void *)NULL);
709 GNUNET_STATISTICS_update (statistics,
710 "Completed lookups", 1,
712 GNUNET_STATISTICS_update (statistics,
720 * Handle lookup requests from client
722 * @param cls the closure
723 * @param client the client
724 * @param message the message
727 handle_lookup (void *cls,
728 struct GNUNET_SERVER_Client *client,
729 const struct GNUNET_MessageHeader *message)
731 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH + 1];
732 struct ClientLookupHandle *clh;
733 char *nameptr = name;
735 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key;
737 const struct GNUNET_GNS_ClientLookupMessage *sh_msg;
739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
740 "Received `%s' message\n",
742 msg_size = ntohs (message->size);
743 if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage))
746 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
749 sh_msg = (const struct GNUNET_GNS_ClientLookupMessage *) message;
750 GNUNET_SERVER_notification_context_add (nc, client);
751 if (GNUNET_YES == ntohs (sh_msg->have_key))
752 key = &sh_msg->shorten_key;
755 utf_in = (const char *) &sh_msg[1];
756 if ( ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientLookupMessage) - 1]) ||
757 (strlen (utf_in) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) )
760 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
763 GNUNET_STRINGS_utf8_tolower (utf_in, nameptr);
764 GNUNET_SERVER_receive_done (client, GNUNET_OK);
766 clh = GNUNET_new (struct ClientLookupHandle);
767 GNUNET_SERVER_client_set_user_context (client, clh);
768 GNUNET_CONTAINER_DLL_insert (clh_head, clh_tail, clh);
769 clh->client = client;
770 clh->request_id = sh_msg->id;
771 if ( (GNUNET_DNSPARSER_TYPE_A == ntohl (sh_msg->type)) &&
772 (GNUNET_OK != v4_enabled) )
774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
775 "LOOKUP: Query for A record but AF_INET not supported!");
776 send_lookup_response (clh, 0, NULL);
779 if ( (GNUNET_DNSPARSER_TYPE_AAAA == ntohl (sh_msg->type)) &&
780 (GNUNET_OK != v6_enabled) )
782 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
783 "LOOKUP: Query for AAAA record but AF_INET6 not supported!");
784 send_lookup_response (clh, 0, NULL);
787 clh->lookup = GNS_resolver_lookup (&sh_msg->zone,
788 ntohl (sh_msg->type),
791 (enum GNUNET_GNS_LocalOptions) ntohs (sh_msg->options),
792 &send_lookup_response, clh);
793 GNUNET_STATISTICS_update (statistics,
800 * One of our clients disconnected, clean up after it.
803 * @param client the client that disconnected
806 notify_client_disconnect (void *cls,
807 struct GNUNET_SERVER_Client *client)
809 struct ClientLookupHandle *clh;
813 clh = GNUNET_SERVER_client_get_user_context (client, struct ClientLookupHandle);
816 GNS_resolver_lookup_cancel (clh->lookup);
817 GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh);
823 * The zone monitor is now in SYNC with the current state of the
824 * name store. Start to perform periodic iterations.
829 monitor_sync_event (void *cls)
831 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
837 * Process GNS requests.
840 * @param server the initialized server
841 * @param c configuration to use
844 run (void *cls, struct GNUNET_SERVER_Handle *server,
845 const struct GNUNET_CONFIGURATION_Handle *c)
847 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
848 { &handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0},
851 struct GNUNET_CRYPTO_EcdsaPublicKey dns_root;
852 unsigned long long max_parallel_bg_queries = 0;
855 v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6);
856 v4_enabled = GNUNET_NETWORK_test_pf (PF_INET);
857 min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL;
858 namestore_handle = GNUNET_NAMESTORE_connect (c);
859 if (NULL == namestore_handle)
861 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
862 _("Failed to connect to the namestore!\n"));
863 GNUNET_SCHEDULER_shutdown ();
866 namecache_handle = GNUNET_NAMECACHE_connect (c);
867 if (NULL == namecache_handle)
869 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
870 _("Failed to connect to the namecache!\n"));
871 GNUNET_SCHEDULER_shutdown ();
875 put_interval = INITIAL_PUT_INTERVAL;
876 zone_publish_time_window_default = DEFAULT_ZONE_PUBLISH_TIME_WINDOW;
878 GNUNET_CONFIGURATION_get_value_time (c, "gns",
879 "ZONE_PUBLISH_TIME_WINDOW",
880 &zone_publish_time_window_default))
882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
883 "Time window for zone iteration: %s\n",
884 GNUNET_STRINGS_relative_time_to_string (zone_publish_time_window,
887 zone_publish_time_window = zone_publish_time_window_default;
889 GNUNET_CONFIGURATION_get_value_number (c, "gns",
890 "MAX_PARALLEL_BACKGROUND_QUERIES",
891 &max_parallel_bg_queries))
893 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
894 "Number of allowed parallel background queries: %llu\n",
895 max_parallel_bg_queries);
898 dht_handle = GNUNET_DHT_connect (c,
899 (unsigned int) max_parallel_bg_queries);
900 if (NULL == dht_handle)
902 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
903 _("Could not connect to DHT!\n"));
904 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
909 GNUNET_CONFIGURATION_get_value_string (c, "gns", "DNS_ROOT",
913 GNUNET_CRYPTO_ecdsa_public_key_from_string (dns_root_name,
914 strlen (dns_root_name),
917 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
919 _("valid public key required"));
920 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
921 GNUNET_free (dns_root_name);
924 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
925 "DNS hijacking with root `%s' enabled. Connecting to DNS service.\n",
927 GNUNET_free (dns_root_name);
929 GNS_interceptor_init (&dns_root, c))
931 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
935 GNS_resolver_init (namecache_handle,
938 max_parallel_bg_queries);
939 GNS_shorten_init (namestore_handle,
942 GNUNET_SERVER_disconnect_notify (server,
943 ¬ify_client_disconnect,
945 /* Schedule periodic put for our records. */
946 first_zone_iteration = GNUNET_YES;
947 GNUNET_SERVER_add_handlers (server, handlers);
948 statistics = GNUNET_STATISTICS_create ("gns", c);
949 nc = GNUNET_SERVER_notification_context_create (server, 1);
950 zmon = GNUNET_NAMESTORE_zone_monitor_start (c,
953 &handle_monitor_event,
956 GNUNET_break (NULL != zmon);
957 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
958 &shutdown_task, NULL);
963 * The main function for the GNS service.
965 * @param argc number of arguments from the command line
966 * @param argv command line arguments
967 * @return 0 ok, 1 on error
970 main (int argc, char *const *argv)
976 GNUNET_SERVICE_run (argc, argv, "gns", GNUNET_SERVICE_OPTION_NONE, &run,
981 /* end of gnunet-service-gns.c */