2 This file is part of GNUnet.
3 Copyright (C) 2011-2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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_identity_service.h"
34 #include "gnunet_gns_service.h"
35 #include "gnunet_statistics_service.h"
37 #include "gnunet-service-gns_resolver.h"
38 #include "gnunet-service-gns_shorten.h"
39 #include "gnunet-service-gns_interceptor.h"
40 #include "gnunet_protocols.h"
43 * The initial interval in milliseconds btween puts in
46 #define INITIAL_PUT_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS
49 * The upper bound for the zone iteration interval in milliseconds
51 #define MINIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_SECONDS
54 * The default put interval for the zone iteration. In case
57 #define DEFAULT_ZONE_PUBLISH_TIME_WINDOW GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
60 * The factor the current zone iteration interval is divided by for each
61 * additional new record
63 #define LATE_ITERATION_SPEEDUP_FACTOR 2
66 * How long until a DHT PUT attempt should time out?
68 #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
71 * What replication level do we use for DHT PUT operations?
73 #define DHT_GNS_REPLICATION_LEVEL 5
77 * Handle to a lookup operation from api
79 struct ClientLookupHandle
83 * We keep these in a DLL.
85 struct ClientLookupHandle *next;
88 * We keep these in a DLL.
90 struct ClientLookupHandle *prev;
93 * Handle to the requesting client
95 struct GNUNET_SERVER_Client *client;
98 * Active handle for the lookup.
100 struct GNS_ResolverHandle *lookup;
111 * Handle for DHT PUT activity triggered from the namestore monitor.
113 struct MonitorActivity
118 struct MonitorActivity *next;
123 struct MonitorActivity *prev;
126 * Handle for the DHT PUT operation.
128 struct GNUNET_DHT_PutHandle *ph;
133 * Our handle to the DHT
135 static struct GNUNET_DHT_Handle *dht_handle;
138 * Active DHT put operation (or NULL)
140 static struct GNUNET_DHT_PutHandle *active_put;
143 * Our handle to the namestore service
145 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
148 * Our handle to the namecache service
150 static struct GNUNET_NAMECACHE_Handle *namecache_handle;
153 * Our handle to the identity service
155 static struct GNUNET_IDENTITY_Handle *identity_handle;
158 * Our handle to the identity operation to find the master zone
159 * for intercepted queries.
161 static struct GNUNET_IDENTITY_Operation *identity_op;
164 * Handle to iterate over our authoritative zone in namestore
166 static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
169 * Handle to monitor namestore changes to instant propagation.
171 static struct GNUNET_NAMESTORE_ZoneMonitor *zmon;
174 * Our notification context.
176 static struct GNUNET_SERVER_NotificationContext *nc;
181 static struct ClientLookupHandle *clh_head;
186 static struct ClientLookupHandle *clh_tail;
189 * Head of monitor activities; kept in a DLL.
191 static struct MonitorActivity *ma_head;
194 * Tail of monitor activities; kept in a DLL.
196 static struct MonitorActivity *ma_tail;
199 * Useful for zone update for DHT put
201 static unsigned long long num_public_records;
204 * Last seen record count
206 static unsigned long long last_num_public_records;
209 * Minimum relative expiration time of records seem during the current
212 static struct GNUNET_TIME_Relative min_relative_record_time;
215 * Zone iteration PUT interval.
217 static struct GNUNET_TIME_Relative put_interval;
220 * Default time window for zone iteration
222 static struct GNUNET_TIME_Relative zone_publish_time_window_default;
225 * Time window for zone iteration, adjusted based on relative record
226 * expiration times in our zone.
228 static struct GNUNET_TIME_Relative zone_publish_time_window;
233 static struct GNUNET_SCHEDULER_Task * zone_publish_task;
236 * #GNUNET_YES if zone has never been published before
238 static int first_zone_iteration;
241 * #GNUNET_YES if ipv6 is supported
243 static int v6_enabled;
246 * #GNUNET_YES if ipv4 is supported
248 static int v4_enabled;
251 * Handle to the statistics service
253 static struct GNUNET_STATISTICS_Handle *statistics;
257 * Task run during shutdown.
263 shutdown_task (void *cls)
265 struct ClientLookupHandle *clh;
266 struct MonitorActivity *ma;
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
272 GNUNET_SERVER_notification_context_destroy (nc);
275 while (NULL != (clh = clh_head))
277 GNUNET_SERVER_client_set_user_context (clh->client,
279 GNS_resolver_lookup_cancel (clh->lookup);
280 GNUNET_CONTAINER_DLL_remove (clh_head,
286 GNS_interceptor_done ();
287 if (NULL != identity_op)
289 GNUNET_IDENTITY_cancel (identity_op);
292 if (NULL != identity_handle)
294 GNUNET_IDENTITY_disconnect (identity_handle);
295 identity_handle = NULL;
297 GNS_resolver_done ();
299 while (NULL != (ma = ma_head))
301 GNUNET_DHT_put_cancel (ma->ph);
302 GNUNET_CONTAINER_DLL_remove (ma_head,
307 if (NULL != statistics)
309 GNUNET_STATISTICS_destroy (statistics,
313 if (NULL != zone_publish_task)
315 GNUNET_SCHEDULER_cancel (zone_publish_task);
316 zone_publish_task = NULL;
318 if (NULL != namestore_iter)
320 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
321 namestore_iter = NULL;
325 GNUNET_NAMESTORE_zone_monitor_stop (zmon);
328 if (NULL != namestore_handle)
330 GNUNET_NAMESTORE_disconnect (namestore_handle);
331 namestore_handle = NULL;
333 if (NULL != namecache_handle)
335 GNUNET_NAMECACHE_disconnect (namecache_handle);
336 namecache_handle = NULL;
338 if (NULL != active_put)
340 GNUNET_DHT_put_cancel (active_put);
343 if (NULL != dht_handle)
345 GNUNET_DHT_disconnect (dht_handle);
352 * Method called periodically that triggers iteration over authoritative records
357 publish_zone_dht_next (void *cls)
359 zone_publish_task = NULL;
360 GNUNET_assert (NULL != namestore_iter);
361 GNUNET_NAMESTORE_zone_iterator_next (namestore_iter);
366 * Periodically iterate over our zone and store everything in dht
371 publish_zone_dht_start (void *cls);
375 * Continuation called from DHT once the PUT operation is done.
377 * @param cls closure, NULL if called from regular iteration,
378 * `struct MonitorActivity` if called from #handle_monitor_event.
379 * @param success #GNUNET_OK on success
382 dht_put_continuation (void *cls,
385 struct MonitorActivity *ma = cls;
386 struct GNUNET_TIME_Relative next_put_interval;
388 num_public_records++;
392 if ( (num_public_records > last_num_public_records) &&
393 (GNUNET_NO == first_zone_iteration) )
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Last record count was lower than current record count. Reducing interval.\n");
397 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
399 next_put_interval = GNUNET_TIME_relative_divide (put_interval,
400 LATE_ITERATION_SPEEDUP_FACTOR);
403 next_put_interval = put_interval;
405 GNUNET_STATISTICS_set (statistics,
406 "Current zone iteration interval (ms)",
407 next_put_interval.rel_value_us / 1000LL,
409 GNUNET_assert (NULL == zone_publish_task);
410 zone_publish_task = GNUNET_SCHEDULER_add_delayed (next_put_interval,
411 &publish_zone_dht_next,
416 GNUNET_CONTAINER_DLL_remove (ma_head,
425 * Convert namestore records from the internal format to that
426 * suitable for publication (removes private records, converts
427 * to absolute expiration time).
429 * @param rd input records
430 * @param rd_count size of the @a rd and @a rd_public arrays
431 * @param rd_public where to write the converted records
432 * @return number of records written to @a rd_public
435 convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
436 unsigned int rd_count,
437 struct GNUNET_GNSRECORD_Data *rd_public)
439 struct GNUNET_TIME_Absolute now;
440 unsigned int rd_public_count;
444 now = GNUNET_TIME_absolute_get ();
445 for (i=0;i<rd_count;i++)
446 if (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
448 rd_public[rd_public_count] = rd[i];
449 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
451 /* GNUNET_GNSRECORD_block_create will convert to absolute time;
452 we just need to adjust our iteration frequency */
453 min_relative_record_time.rel_value_us =
454 GNUNET_MIN (rd_public[rd_public_count].expiration_time,
455 min_relative_record_time.rel_value_us);
457 else if (rd_public[rd_public_count].expiration_time < now.abs_value_us)
459 /* record already expired, skip it */
464 return rd_public_count;
469 * Store GNS records in the DHT.
471 * @param key key of the zone
472 * @param label label to store under
473 * @param rd_public public record data
474 * @param rd_public_count number of records in @a rd_public
475 * @param pc_arg closure argument to pass to the #dht_put_continuation
476 * @return DHT PUT handle, NULL on error
478 static struct GNUNET_DHT_PutHandle *
479 perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
481 const struct GNUNET_GNSRECORD_Data *rd_public,
482 unsigned int rd_public_count,
485 struct GNUNET_GNSRECORD_Block *block;
486 struct GNUNET_HashCode query;
487 struct GNUNET_TIME_Absolute expire;
489 struct GNUNET_DHT_PutHandle *ret;
491 expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count,
493 block = GNUNET_GNSRECORD_block_create (key,
499 return NULL; /* whoops */
500 block_size = ntohl (block->purpose.size)
501 + sizeof (struct GNUNET_CRYPTO_EcdsaSignature)
502 + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
503 GNUNET_GNSRECORD_query_from_private_key (key,
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
507 "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n",
510 GNUNET_STRINGS_absolute_time_to_string (expire),
511 GNUNET_h2s (&query));
512 ret = GNUNET_DHT_put (dht_handle, &query,
513 DHT_GNS_REPLICATION_LEVEL,
514 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
515 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
519 &dht_put_continuation,
527 * Function used to put all records successively into the DHT.
529 * @param cls the closure (NULL)
530 * @param key the private key of the authority (ours)
531 * @param label the name of the records, NULL once the iteration is done
532 * @param rd_count the number of records in @a rd
533 * @param rd the record data
536 put_gns_record (void *cls,
537 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
539 unsigned int rd_count,
540 const struct GNUNET_GNSRECORD_Data *rd)
542 struct GNUNET_GNSRECORD_Data rd_public[rd_count];
543 unsigned int rd_public_count;
547 /* we're done with one iteration, calculate when to do the next one */
548 namestore_iter = NULL;
549 last_num_public_records = num_public_records;
550 first_zone_iteration = GNUNET_NO;
551 if (0 == num_public_records)
554 * If no records are known (startup) or none present
555 * we can safely set the interval to the value for a single
558 put_interval = zone_publish_time_window;
559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
560 "No records in namestore database.\n");
564 /* If records are present, next publication is based on the minimum
565 * relative expiration time of the records published divided by 4
567 zone_publish_time_window = GNUNET_TIME_relative_min (
568 GNUNET_TIME_relative_divide (min_relative_record_time, 4),
569 zone_publish_time_window_default);
570 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
573 /* reset for next iteration */
574 min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL;
575 put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL,
578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
579 "Zone iteration finished. Adjusted zone iteration interval to %s\n",
580 GNUNET_STRINGS_relative_time_to_string (put_interval, GNUNET_YES));
581 GNUNET_STATISTICS_set (statistics,
582 "Current zone iteration interval (in ms)",
583 put_interval.rel_value_us / 1000LL,
585 GNUNET_STATISTICS_update (statistics,
586 "Number of zone iterations",
589 GNUNET_STATISTICS_set (statistics,
590 "Number of public records in DHT",
591 last_num_public_records,
593 GNUNET_assert (NULL == zone_publish_task);
594 if (0 == num_public_records)
595 zone_publish_task = GNUNET_SCHEDULER_add_delayed (put_interval,
596 &publish_zone_dht_start,
599 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
604 rd_public_count = convert_records_for_export (rd,
608 /* We got a set of records to publish */
609 if (0 == rd_public_count)
611 GNUNET_assert (NULL == zone_publish_task);
612 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next,
617 active_put = perform_dht_put (key,
622 if (NULL == active_put)
625 dht_put_continuation (NULL, GNUNET_NO);
631 * Periodically iterate over all zones and store everything in DHT
636 publish_zone_dht_start (void *cls)
638 zone_publish_task = NULL;
640 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
641 "Starting DHT zone update!\n");
642 /* start counting again */
643 num_public_records = 0;
644 GNUNET_assert (NULL == namestore_iter);
645 namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
646 NULL, /* All zones */
647 &put_gns_record, NULL );
652 * Process a record that was stored in the namestore
653 * (invoked by the monitor).
655 * @param cls closure, NULL
656 * @param zone private key of the zone; NULL on disconnect
657 * @param label label of the records; NULL on disconnect
658 * @param rd_count number of entries in @a rd array, 0 if label was deleted
659 * @param rd array of records with data to store
662 handle_monitor_event (void *cls,
663 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
665 unsigned int rd_count,
666 const struct GNUNET_GNSRECORD_Data *rd)
668 struct GNUNET_GNSRECORD_Data rd_public[rd_count];
669 unsigned int rd_public_count;
670 struct MonitorActivity *ma;
672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
673 "Received %u records for label `%s' via namestore monitor\n",
676 /* filter out records that are not public, and convert to
677 absolute expiration time. */
678 rd_public_count = convert_records_for_export (rd, rd_count,
680 if (0 == rd_public_count)
681 return; /* nothing to do */
682 ma = GNUNET_new (struct MonitorActivity);
683 ma->ph = perform_dht_put (zone, label,
688 /* PUT failed, do not remember operation */
692 GNUNET_CONTAINER_DLL_insert (ma_head,
698 /* END DHT ZONE PROPAGATION */
702 * Reply to client with the result from our lookup.
704 * @param cls the closure (our client lookup handle)
705 * @param rd_count the number of records in @a rd
706 * @param rd the record data
709 send_lookup_response (void* cls,
711 const struct GNUNET_GNSRECORD_Data *rd)
713 struct ClientLookupHandle *clh = cls;
714 struct GNUNET_GNS_ClientLookupResultMessage *rmsg;
717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
718 "Sending LOOKUP_RESULT message with %u results\n",
719 (unsigned int) rd_count);
721 len = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
722 rmsg = GNUNET_malloc (len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage));
723 rmsg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT);
724 rmsg->header.size = htons (len + sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
725 rmsg->id = clh->request_id;
726 rmsg->rd_count = htonl (rd_count);
727 GNUNET_GNSRECORD_records_serialize (rd_count, rd, len,
729 GNUNET_SERVER_notification_context_unicast (nc,
734 GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh);
735 GNUNET_SERVER_client_set_user_context (clh->client, NULL);
737 GNUNET_STATISTICS_update (statistics,
738 "Completed lookups", 1,
740 GNUNET_STATISTICS_update (statistics,
748 * Handle lookup requests from client
750 * @param cls the closure
751 * @param client the client
752 * @param message the message
755 handle_lookup (void *cls,
756 struct GNUNET_SERVER_Client *client,
757 const struct GNUNET_MessageHeader *message)
759 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH + 1];
760 struct ClientLookupHandle *clh;
761 char *nameptr = name;
763 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key;
765 const struct GNUNET_GNS_ClientLookupMessage *sh_msg;
767 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
768 "Received LOOKUP message\n");
769 msg_size = ntohs (message->size);
770 if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage))
773 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
776 sh_msg = (const struct GNUNET_GNS_ClientLookupMessage *) message;
777 GNUNET_SERVER_notification_context_add (nc, client);
778 if (GNUNET_YES == ntohs (sh_msg->have_key))
779 key = &sh_msg->shorten_key;
782 utf_in = (const char *) &sh_msg[1];
783 if ( ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientLookupMessage) - 1]) ||
784 (strlen (utf_in) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) )
787 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
790 GNUNET_STRINGS_utf8_tolower (utf_in, nameptr);
791 GNUNET_SERVER_receive_done (client, GNUNET_OK);
793 clh = GNUNET_new (struct ClientLookupHandle);
794 GNUNET_SERVER_client_set_user_context (client, clh);
795 GNUNET_CONTAINER_DLL_insert (clh_head, clh_tail, clh);
796 clh->client = client;
797 clh->request_id = sh_msg->id;
798 if ( (GNUNET_DNSPARSER_TYPE_A == ntohl (sh_msg->type)) &&
799 (GNUNET_OK != v4_enabled) )
801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
802 "LOOKUP: Query for A record but AF_INET not supported!");
803 send_lookup_response (clh, 0, NULL);
806 if ( (GNUNET_DNSPARSER_TYPE_AAAA == ntohl (sh_msg->type)) &&
807 (GNUNET_OK != v6_enabled) )
809 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
810 "LOOKUP: Query for AAAA record but AF_INET6 not supported!");
811 send_lookup_response (clh, 0, NULL);
814 clh->lookup = GNS_resolver_lookup (&sh_msg->zone,
815 ntohl (sh_msg->type),
818 (enum GNUNET_GNS_LocalOptions) ntohs (sh_msg->options),
819 &send_lookup_response, clh);
820 GNUNET_STATISTICS_update (statistics,
827 * One of our clients disconnected, clean up after it.
830 * @param client the client that disconnected
833 notify_client_disconnect (void *cls,
834 struct GNUNET_SERVER_Client *client)
836 struct ClientLookupHandle *clh;
840 clh = GNUNET_SERVER_client_get_user_context (client, struct ClientLookupHandle);
843 GNS_resolver_lookup_cancel (clh->lookup);
844 GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh);
850 * The zone monitor is now in SYNC with the current state of the
851 * name store. Start to perform periodic iterations.
856 monitor_sync_event (void *cls)
858 GNUNET_assert (NULL == zone_publish_task);
859 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
865 * Method called to inform about the ego to be used for the master zone
866 * for DNS interceptions.
868 * This function is only called ONCE, and 'NULL' being passed in
869 * @a ego does indicate that interception is not configured.
870 * If @a ego is non-NULL, we should start to intercept DNS queries
871 * and resolve ".gnu" queries using the given ego as the master zone.
873 * @param cls closure, our `const struct GNUNET_CONFIGURATION_Handle *c`
874 * @param ego ego handle
875 * @param ctx context for application to store data for this ego
876 * (during the lifetime of this process, initially NULL)
877 * @param name name assigned by the user for this ego,
878 * NULL if the user just deleted the ego and it
879 * must thus no longer be used
882 identity_intercept_cb (void *cls,
883 struct GNUNET_IDENTITY_Ego *ego,
887 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
888 struct GNUNET_CRYPTO_EcdsaPublicKey dns_root;
893 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
894 _("No ego configured for `%s`\n"),
898 GNUNET_IDENTITY_ego_get_public_key (ego,
901 GNS_interceptor_init (&dns_root, cfg))
904 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
911 * Process GNS requests.
914 * @param server the initialized server
915 * @param c configuration to use
919 struct GNUNET_SERVER_Handle *server,
920 const struct GNUNET_CONFIGURATION_Handle *c)
922 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
923 { &handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0},
926 unsigned long long max_parallel_bg_queries = 0;
928 v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6);
929 v4_enabled = GNUNET_NETWORK_test_pf (PF_INET);
930 min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL;
931 namestore_handle = GNUNET_NAMESTORE_connect (c);
932 if (NULL == namestore_handle)
934 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
935 _("Failed to connect to the namestore!\n"));
936 GNUNET_SCHEDULER_shutdown ();
939 namecache_handle = GNUNET_NAMECACHE_connect (c);
940 if (NULL == namecache_handle)
942 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
943 _("Failed to connect to the namecache!\n"));
944 GNUNET_SCHEDULER_shutdown ();
948 put_interval = INITIAL_PUT_INTERVAL;
949 zone_publish_time_window_default = DEFAULT_ZONE_PUBLISH_TIME_WINDOW;
951 GNUNET_CONFIGURATION_get_value_time (c, "gns",
952 "ZONE_PUBLISH_TIME_WINDOW",
953 &zone_publish_time_window_default))
955 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
956 "Time window for zone iteration: %s\n",
957 GNUNET_STRINGS_relative_time_to_string (zone_publish_time_window,
960 zone_publish_time_window = zone_publish_time_window_default;
962 GNUNET_CONFIGURATION_get_value_number (c, "gns",
963 "MAX_PARALLEL_BACKGROUND_QUERIES",
964 &max_parallel_bg_queries))
966 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
967 "Number of allowed parallel background queries: %llu\n",
968 max_parallel_bg_queries);
971 dht_handle = GNUNET_DHT_connect (c,
972 (unsigned int) max_parallel_bg_queries);
973 if (NULL == dht_handle)
975 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
976 _("Could not connect to DHT!\n"));
977 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
981 identity_handle = GNUNET_IDENTITY_connect (c,
984 if (NULL == identity_handle)
986 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
987 "Could not connect to identity service!\n");
991 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
992 "Looking for gns-intercept ego\n");
993 identity_op = GNUNET_IDENTITY_get (identity_handle,
995 &identity_intercept_cb,
998 GNS_resolver_init (namecache_handle,
1001 max_parallel_bg_queries);
1002 GNS_shorten_init (namestore_handle,
1005 GNUNET_SERVER_disconnect_notify (server,
1006 ¬ify_client_disconnect,
1008 /* Schedule periodic put for our records. */
1009 first_zone_iteration = GNUNET_YES;
1010 GNUNET_SERVER_add_handlers (server, handlers);
1011 statistics = GNUNET_STATISTICS_create ("gns", c);
1012 nc = GNUNET_SERVER_notification_context_create (server, 1);
1013 zmon = GNUNET_NAMESTORE_zone_monitor_start (c,
1016 &handle_monitor_event,
1017 &monitor_sync_event,
1019 GNUNET_break (NULL != zmon);
1020 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1025 * The main function for the GNS service.
1027 * @param argc number of arguments from the command line
1028 * @param argv command line arguments
1029 * @return 0 ok, 1 on error
1032 main (int argc, char *const *argv)
1038 GNUNET_SERVICE_run (argc, argv, "gns", GNUNET_SERVICE_OPTION_NONE, &run,
1043 /* end of gnunet-service-gns.c */