2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011 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.
23 * @file gns/gnunet-service-gns.c
24 * @brief GNUnet GNS service
25 * @author Martin Schanzenbach
28 #include "gnunet_util_lib.h"
29 #include "gnunet_transport_service.h"
30 #include "gnunet_dns_service.h"
31 #include "gnunet_dnsparser_lib.h"
32 #include "gnunet_dht_service.h"
33 #include "gnunet_namestore_service.h"
34 #include "gnunet_gns_service.h"
35 #include "block_gns.h"
37 #include "gnunet-service-gns_resolver.h"
38 #include "gnunet-service-gns_interceptor.h"
40 /* FIXME move to proper header in include */
41 #define GNUNET_MESSAGE_TYPE_GNS_LOOKUP 23
42 #define GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT 24
43 #define GNUNET_MESSAGE_TYPE_GNS_SHORTEN 25
44 #define GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT 26
45 #define GNUNET_MESSAGE_TYPE_GNS_GET_AUTH 27
46 #define GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT 28
50 * Handle to a shorten operation from api
52 struct ClientShortenHandle
54 /* the requesting client that */
55 struct GNUNET_SERVER_Client *client;
61 enum GNUNET_GNS_RecordType type;
70 * Handle to a get auhtority operation from api
72 struct ClientGetAuthHandle
74 /* the requesting client that */
75 struct GNUNET_SERVER_Client *client;
80 /* name to lookup authority */
87 * Handle to a lookup operation from api
89 struct ClientLookupHandle
91 /* the requesting client that */
92 struct GNUNET_SERVER_Client *client;
98 enum GNUNET_GNS_RecordType type;
100 /* the name to look up */
101 char* name; //Needed?
105 * Our handle to the DHT
107 static struct GNUNET_DHT_Handle *dht_handle;
110 * Our zone's private key
112 struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
115 * Our handle to the namestore service
116 * FIXME maybe need a second handle for iteration
118 struct GNUNET_NAMESTORE_Handle *namestore_handle;
121 * Handle to iterate over our authoritative zone in namestore
123 struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
126 * The configuration the GNS service is running with
128 const struct GNUNET_CONFIGURATION_Handle *GNS_cfg;
131 * Our notification context.
133 static struct GNUNET_SERVER_NotificationContext *nc;
138 struct GNUNET_CRYPTO_ShortHashCode zone_hash;
141 * Useful for zone update for DHT put
143 static int num_public_records = 3600;
145 /* dht update interval FIXME define? */
146 static struct GNUNET_TIME_Relative dht_update_interval;
148 /* zone update task */
149 GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid = GNUNET_SCHEDULER_NO_TASK;
151 /* automatic pkey import for name shortening */
152 static int auto_import_pkey;
155 static struct GNUNET_TIME_Relative default_lookup_timeout;
161 on_resolver_cleanup(void)
163 GNUNET_NAMESTORE_disconnect(namestore_handle, 1);
164 GNUNET_DHT_disconnect(dht_handle);
168 * Task run during shutdown.
174 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
177 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
179 /* Kill zone task for it may make the scheduler hang */
180 if (zone_update_taskid)
181 GNUNET_SCHEDULER_cancel(zone_update_taskid);
183 GNUNET_SERVER_notification_context_destroy (nc);
185 gns_interceptor_stop();
186 gns_resolver_cleanup(&on_resolver_cleanup);
192 * Method called periodicattluy that triggers
193 * iteration over root zone
196 * @param tc task context
199 update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
201 GNUNET_NAMESTORE_zone_iterator_next(namestore_iter);
205 * Continuation for DHT put
208 * @param tc task context
211 record_dht_put(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
213 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "put request transmitted\n");
218 update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
221 * Function used to put all records successively into the DHT.
223 * @param cls the closure (NULL)
224 * @param key the public key of the authority (ours)
225 * @param expiration lifetime of the namestore entry
226 * @param name the name of the records
227 * @param rd_count the number of records in data
228 * @param rd the record data
229 * @param signature the signature for the record data
232 put_gns_record(void *cls,
233 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
234 struct GNUNET_TIME_Absolute expiration,
236 unsigned int rd_count,
237 const struct GNUNET_NAMESTORE_RecordData *rd,
238 const struct GNUNET_CRYPTO_RsaSignature *signature)
241 struct GNSNameRecordBlock *nrb;
242 struct GNUNET_CRYPTO_ShortHashCode name_hash;
243 GNUNET_HashCode xor_hash;
244 GNUNET_HashCode name_hash_double;
245 GNUNET_HashCode zone_hash_double;
246 struct GNUNET_CRYPTO_HashAsciiEncoded xor_hash_string;
247 uint32_t rd_payload_length;
248 char* nrb_data = NULL;
254 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
255 "Zone iteration finished. Rescheduling put in %ds\n",
256 GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL);
257 zone_update_taskid = GNUNET_SCHEDULER_add_delayed (
258 GNUNET_TIME_relative_multiply(
259 GNUNET_TIME_UNIT_SECONDS,
260 GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL
262 &update_zone_dht_start,
267 namelen = strlen(name) + 1;
269 if (signature == NULL)
271 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
272 "No signature for %s record data provided! Skipping...\n",
274 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next,
280 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
281 "Putting records for %s into the DHT\n", name);
283 rd_payload_length = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
285 nrb = GNUNET_malloc(rd_payload_length + namelen
286 + sizeof(struct GNSNameRecordBlock));
288 nrb->signature = *signature;
290 nrb->public_key = *key;
292 nrb->rd_count = htonl(rd_count);
294 memcpy(&nrb[1], name, namelen);
296 nrb_data = (char*)&nrb[1];
299 rd_payload_length += sizeof(struct GNSNameRecordBlock) + namelen;
301 if (-1 == GNUNET_NAMESTORE_records_serialize (rd_count,
306 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
307 "Record serialization failed! Skipping...\n");
309 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next,
316 * calculate DHT key: H(name) xor H(pubkey)
318 GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash);
319 GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double);
320 GNUNET_CRYPTO_short_hash_double (&zone_hash, &zone_hash_double);
321 GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash);
322 GNUNET_CRYPTO_hash_to_enc (&xor_hash, &xor_hash_string);
324 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
325 "putting records for %s under key: %s with size %d\n",
326 name, (char*)&xor_hash_string, rd_payload_length);
328 GNUNET_DHT_put (dht_handle, &xor_hash,
329 DHT_GNS_REPLICATION_LEVEL,
331 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
335 DHT_OPERATION_TIMEOUT,
337 NULL); //cls for cont
339 num_public_records++;
342 * Reschedule periodic put
344 zone_update_taskid = GNUNET_SCHEDULER_add_delayed (dht_update_interval,
345 &update_zone_dht_next,
353 * Periodically iterate over our zone and store everything in dht
356 * @param tc task context
359 update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
361 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling DHT zone update!\n");
362 if (0 == num_public_records)
364 dht_update_interval = GNUNET_TIME_relative_multiply(
365 GNUNET_TIME_UNIT_SECONDS,
366 GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL);
367 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
368 "No records in db. Adjusted DHT update interval to %ds\n",
369 GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL);
374 dht_update_interval = GNUNET_TIME_relative_multiply(
375 GNUNET_TIME_UNIT_SECONDS,
376 (3600/num_public_records));
377 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
378 "Adjusted DHT update interval to %ds!\n",
379 (3600/num_public_records));
382 /* start counting again */
383 num_public_records = 0;
384 namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
386 GNUNET_NAMESTORE_RF_AUTHORITY,
387 GNUNET_NAMESTORE_RF_PRIVATE,
393 /* END DHT ZONE PROPAGATION */
396 * Send shorten response back to client
398 * @param cls the closure containing a client shorten handle
399 * @param name the shortened name result or NULL if cannot be shortened
402 send_shorten_response(void* cls, const char* name)
404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n",
405 "SHORTEN_RESULT", name);
406 struct GNUNET_GNS_ClientShortenResultMessage *rmsg;
407 struct ClientShortenHandle *csh = (struct ClientShortenHandle *)cls;
414 rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientShortenResultMessage)
417 rmsg->id = csh->unique_id;
418 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT);
420 htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) +
423 strcpy((char*)&rmsg[1], name);
425 GNUNET_SERVER_notification_context_unicast (nc, csh->client,
426 (const struct GNUNET_MessageHeader *) rmsg,
428 GNUNET_SERVER_receive_done (csh->client, GNUNET_OK);
431 GNUNET_free_non_null(csh->name);
437 * Handle a shorten message from the api
439 * @param cls the closure
440 * @param client the client
441 * @param message the message
443 static void handle_shorten(void *cls,
444 struct GNUNET_SERVER_Client * client,
445 const struct GNUNET_MessageHeader * message)
447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN");
450 struct ClientShortenHandle *csh;
451 char name[MAX_DNS_NAME_LENGTH];
452 char* nameptr = name;
454 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage))
457 GNUNET_SERVER_receive_done (client, GNUNET_OK);
461 GNUNET_SERVER_notification_context_add (nc, client);
463 struct GNUNET_GNS_ClientShortenMessage *sh_msg =
464 (struct GNUNET_GNS_ClientShortenMessage *) message;
466 msg_size = ntohs(message->size);
468 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
471 GNUNET_SERVER_receive_done (client, GNUNET_OK);
475 csh = GNUNET_malloc(sizeof(struct ClientShortenHandle));
476 csh->client = client;
477 csh->unique_id = sh_msg->id;
479 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
481 if (strlen (name) < strlen(GNUNET_GNS_TLD)) {
483 send_shorten_response(csh, name);
487 if (!is_gnunet_tld(name) && !is_zkey_tld(name))
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 "%s is not our domain. Returning\n", name);
492 send_shorten_response(csh, name);
496 /* Start shortening */
497 if (GNUNET_YES == auto_import_pkey)
498 gns_resolver_shorten_name(zone_hash, name, zone_key,
499 &send_shorten_response, csh);
501 gns_resolver_shorten_name(zone_hash, name, NULL,
502 &send_shorten_response, csh);
507 * Send get authority response back to client
509 * @param cls the closure containing a client get auth handle
510 * @param name the shortened name result or NULL if cannot be shortened
513 send_get_auth_response(void *cls, const char* name)
515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n",
516 "GET_AUTH_RESULT", name);
517 struct GNUNET_GNS_ClientGetAuthResultMessage *rmsg;
518 struct ClientGetAuthHandle *cah = (struct ClientGetAuthHandle *)cls;
525 rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage)
528 rmsg->id = cah->unique_id;
529 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT);
531 htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) +
534 strcpy((char*)&rmsg[1], name);
536 GNUNET_SERVER_notification_context_unicast (nc, cah->client,
537 (const struct GNUNET_MessageHeader *) rmsg,
539 GNUNET_SERVER_receive_done (cah->client, GNUNET_OK);
541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up handles...\n");
544 GNUNET_free_non_null(cah->name);
547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "done.\n");
553 * Handle a get authority message from the api
555 * @param cls the closure
556 * @param client the client
557 * @param message the message
559 static void handle_get_authority(void *cls,
560 struct GNUNET_SERVER_Client * client,
561 const struct GNUNET_MessageHeader * message)
563 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "GET_AUTH");
566 struct ClientGetAuthHandle *cah;
567 char name[MAX_DNS_NAME_LENGTH];
568 char* nameptr = name;
570 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientGetAuthMessage))
573 GNUNET_SERVER_receive_done (client, GNUNET_OK);
577 GNUNET_SERVER_notification_context_add (nc, client);
579 struct GNUNET_GNS_ClientGetAuthMessage *sh_msg =
580 (struct GNUNET_GNS_ClientGetAuthMessage *) message;
582 msg_size = ntohs(message->size);
584 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
587 GNUNET_SERVER_receive_done (client, GNUNET_OK);
591 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
594 cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle));
595 cah->client = client;
596 cah->unique_id = sh_msg->id;
598 if (strlen(name) < strlen(GNUNET_GNS_TLD))
600 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
601 "%s is too short. Returning\n", name);
603 send_get_auth_response(cah, name);
607 if (strcmp(name+strlen(name)-strlen(GNUNET_GNS_TLD),
608 GNUNET_GNS_TLD) != 0)
610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
611 "%s is not our domain. Returning\n", name);
613 send_get_auth_response(cah, name);
617 if (strcmp(name, GNUNET_GNS_TLD) == 0)
619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
620 "%s is us. Returning\n", name);
622 send_get_auth_response(cah, name);
626 cah->name = GNUNET_malloc(strlen(name)
627 - strlen(GNUNET_GNS_TLD) + 1);
629 strlen(name)-strlen(GNUNET_GNS_TLD) + 1);
630 memcpy(cah->name, name,
631 strlen(name)-strlen(GNUNET_GNS_TLD));
633 /* Start delegation resolution in our namestore */
634 gns_resolver_get_authority(zone_hash, name, &send_get_auth_response, cah);
639 * Reply to client with the result from our lookup.
641 * @param cls the closure (our client lookup handle)
642 * @param rd_count the number of records
643 * @param rd the record data
646 send_lookup_response(void* cls,
648 const struct GNUNET_NAMESTORE_RecordData *rd)
650 struct ClientLookupHandle* clh = (struct ClientLookupHandle*)cls;
651 struct GNUNET_GNS_ClientLookupResultMessage *rmsg;
654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %d results\n",
655 "LOOKUP_RESULT", rd_count);
657 len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
658 rmsg = GNUNET_malloc(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
660 rmsg->id = clh->unique_id;
661 rmsg->rd_count = htonl(rd_count);
662 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT);
664 htons(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
666 GNUNET_NAMESTORE_records_serialize (rd_count, rd, len, (char*)&rmsg[1]);
668 GNUNET_SERVER_notification_context_unicast (nc, clh->client,
669 (const struct GNUNET_MessageHeader *) rmsg,
671 GNUNET_SERVER_receive_done (clh->client, GNUNET_OK);
674 GNUNET_free(clh->name);
681 * Handle lookup requests from client
683 * @param cls the closure
684 * @param client the client
685 * @param message the message
688 handle_lookup(void *cls,
689 struct GNUNET_SERVER_Client * client,
690 const struct GNUNET_MessageHeader * message)
692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP");
696 char name[MAX_DNS_NAME_LENGTH];
697 struct ClientLookupHandle *clh;
698 char* nameptr = name;
700 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
703 GNUNET_SERVER_receive_done (client, GNUNET_OK);
707 GNUNET_SERVER_notification_context_add (nc, client);
709 struct GNUNET_GNS_ClientLookupMessage *sh_msg =
710 (struct GNUNET_GNS_ClientLookupMessage *) message;
712 msg_size = ntohs(message->size);
714 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
717 GNUNET_SERVER_receive_done (client, GNUNET_OK);
721 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
722 namelen = strlen(name)+1;
723 clh = GNUNET_malloc(sizeof(struct ClientLookupHandle));
724 clh->client = client;
725 clh->name = GNUNET_malloc(namelen);
726 strcpy(clh->name, name);
727 clh->unique_id = sh_msg->id;
728 clh->type = ntohl(sh_msg->type);
730 if (GNUNET_YES == auto_import_pkey)
732 gns_resolver_lookup_record(zone_hash, clh->type, name,
734 default_lookup_timeout,
735 &send_lookup_response, clh);
739 gns_resolver_lookup_record(zone_hash, clh->type, name,
741 default_lookup_timeout,
742 &send_lookup_response, clh);
749 * Process GNS requests.
751 * @param cls closure)
752 * @param server the initialized server
753 * @param c configuration to use
756 run (void *cls, struct GNUNET_SERVER_Handle *server,
757 const struct GNUNET_CONFIGURATION_Handle *c)
760 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initializing GNS\n");
763 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
764 unsigned long long max_parallel_bg_queries = 0;
765 unsigned long long default_lookup_timeout_secs = 0;
767 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
768 {&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0},
769 {&handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0},
770 {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0}
773 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns",
774 "ZONEKEY", &keyfile))
776 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
777 "No private key for root zone specified!\n");
778 GNUNET_SCHEDULER_shutdown(0);
782 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
783 "Using keyfile %s for root zone.\n", keyfile);
785 zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
786 GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey);
788 GNUNET_CRYPTO_short_hash(&pkey,
789 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
791 GNUNET_free(keyfile);
794 * handle to our local namestore
796 namestore_handle = GNUNET_NAMESTORE_connect(c);
798 if (NULL == namestore_handle)
800 //FIXME do error handling;
801 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
802 "Failed to connect to the namestore!\n");
803 GNUNET_SCHEDULER_shutdown(0);
810 dht_handle = GNUNET_DHT_connect(c, 1); //FIXME get ht_len from cfg
812 if (NULL == dht_handle)
814 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n");
817 auto_import_pkey = GNUNET_NO;
820 GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
823 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
824 "Automatic PKEY import is enabled.\n");
825 auto_import_pkey = GNUNET_YES;
830 GNUNET_CONFIGURATION_get_value_number(c, "gns",
831 "MAX_PARALLEL_BACKGROUND_QUERIES",
832 &max_parallel_bg_queries))
834 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
835 "Number of allowed parallel background queries: %d\n",
836 max_parallel_bg_queries);
840 GNUNET_CONFIGURATION_get_value_number(c, "gns",
841 "DEFAULT_LOOKUP_TIMEOUT",
842 &default_lookup_timeout_secs))
844 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
845 "Default lookup timeout: %ds\n", default_lookup_timeout_secs);
846 default_lookup_timeout = GNUNET_TIME_relative_multiply(
847 GNUNET_TIME_UNIT_SECONDS,
848 default_lookup_timeout_secs);
851 if (gns_resolver_init(namestore_handle, dht_handle, zone_hash,
852 max_parallel_bg_queries)
855 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
856 "Unable to initialize resolver!\n");
857 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
862 GNUNET_CONFIGURATION_get_value_yesno (c, "gns", "HIJACK_DNS"))
864 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
865 "DNS hijacking enabled... connecting to service.\n");
867 if (gns_interceptor_init(zone_hash, zone_key, c) == GNUNET_SYSERR)
869 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
870 "Failed to enable the dns interceptor!\n");
875 * Schedule periodic put
877 * We have roughly an hour for all records;
879 dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
881 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL);
883 GNUNET_SERVER_add_handlers (server, handlers);
886 //GNUNET_SERVER_disconnect_notify (server,
887 // &client_disconnect_notification,
890 nc = GNUNET_SERVER_notification_context_create (server, 1);
892 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
898 * The main function for the GNS service.
900 * @param argc number of arguments from the command line
901 * @param argv command line arguments
902 * @return 0 ok, 1 on error
905 main (int argc, char *const *argv)
911 GNUNET_SERVICE_run (argc, argv, "gns", GNUNET_SERVICE_OPTION_NONE, &run,
916 /* end of gnunet-service-gns.c */