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;
146 * update interval in seconds
148 static unsigned long long int dht_max_update_interval;
150 /* dht update interval FIXME define? */
151 static struct GNUNET_TIME_Relative dht_update_interval;
153 /* zone update task */
154 GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid = GNUNET_SCHEDULER_NO_TASK;
156 /* automatic pkey import for name shortening */
157 static int auto_import_pkey;
160 static struct GNUNET_TIME_Relative default_lookup_timeout;
166 on_resolver_cleanup(void)
168 GNUNET_NAMESTORE_disconnect(namestore_handle, 1);
169 GNUNET_DHT_disconnect(dht_handle);
173 * Task run during shutdown.
179 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
182 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
184 /* Kill zone task for it may make the scheduler hang */
185 if (zone_update_taskid)
186 GNUNET_SCHEDULER_cancel(zone_update_taskid);
188 GNUNET_SERVER_notification_context_destroy (nc);
190 gns_interceptor_stop();
191 gns_resolver_cleanup(&on_resolver_cleanup);
197 * Method called periodicattluy that triggers
198 * iteration over root zone
201 * @param tc task context
204 update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
206 GNUNET_NAMESTORE_zone_iterator_next(namestore_iter);
210 * Continuation for DHT put
213 * @param tc task context
216 record_dht_put(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
218 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "put request transmitted\n");
223 update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
226 * Function used to put all records successively into the DHT.
228 * @param cls the closure (NULL)
229 * @param key the public key of the authority (ours)
230 * @param expiration lifetime of the namestore entry
231 * @param name the name of the records
232 * @param rd_count the number of records in data
233 * @param rd the record data
234 * @param signature the signature for the record data
237 put_gns_record(void *cls,
238 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
239 struct GNUNET_TIME_Absolute expiration,
241 unsigned int rd_count,
242 const struct GNUNET_NAMESTORE_RecordData *rd,
243 const struct GNUNET_CRYPTO_RsaSignature *signature)
246 struct GNSNameRecordBlock *nrb;
247 struct GNUNET_CRYPTO_ShortHashCode name_hash;
248 GNUNET_HashCode xor_hash;
249 GNUNET_HashCode name_hash_double;
250 GNUNET_HashCode zone_hash_double;
251 struct GNUNET_CRYPTO_HashAsciiEncoded xor_hash_string;
252 uint32_t rd_payload_length;
253 char* nrb_data = NULL;
259 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
260 "Zone iteration finished. Rescheduling put in %ds\n",
261 dht_max_update_interval);
262 zone_update_taskid = GNUNET_SCHEDULER_add_delayed (
263 GNUNET_TIME_relative_multiply(
264 GNUNET_TIME_UNIT_SECONDS,
265 dht_max_update_interval
267 &update_zone_dht_start,
272 namelen = strlen(name) + 1;
274 if (signature == NULL)
276 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
277 "No signature for %s record data provided! Skipping...\n",
279 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next,
285 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
286 "Putting records for %s into the DHT\n", name);
288 rd_payload_length = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
290 nrb = GNUNET_malloc(rd_payload_length + namelen
291 + sizeof(struct GNSNameRecordBlock));
293 nrb->signature = *signature;
295 nrb->public_key = *key;
297 nrb->rd_count = htonl(rd_count);
299 memcpy(&nrb[1], name, namelen);
301 nrb_data = (char*)&nrb[1];
304 rd_payload_length += sizeof(struct GNSNameRecordBlock) + namelen;
306 if (-1 == GNUNET_NAMESTORE_records_serialize (rd_count,
311 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
312 "Record serialization failed! Skipping...\n");
314 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next,
321 * calculate DHT key: H(name) xor H(pubkey)
323 GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash);
324 GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double);
325 GNUNET_CRYPTO_short_hash_double (&zone_hash, &zone_hash_double);
326 GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash);
327 GNUNET_CRYPTO_hash_to_enc (&xor_hash, &xor_hash_string);
329 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
330 "putting records for %s under key: %s with size %d\n",
331 name, (char*)&xor_hash_string, rd_payload_length);
333 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
334 "DHT req to %d\n", DHT_OPERATION_TIMEOUT.rel_value);
336 GNUNET_DHT_put (dht_handle, &xor_hash,
337 DHT_GNS_REPLICATION_LEVEL,
339 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
343 DHT_OPERATION_TIMEOUT,
345 NULL); //cls for cont
347 num_public_records++;
350 * Reschedule periodic put
352 zone_update_taskid = GNUNET_SCHEDULER_add_delayed (dht_update_interval,
353 &update_zone_dht_next,
361 * Periodically iterate over our zone and store everything in dht
364 * @param tc task context
367 update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
369 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling DHT zone update!\n");
370 if (0 == num_public_records)
372 dht_update_interval = GNUNET_TIME_relative_multiply(
373 GNUNET_TIME_UNIT_SECONDS,
374 dht_max_update_interval);
375 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
376 "No records in db. Adjusted DHT update interval to %ds\n",
377 dht_max_update_interval);
382 dht_update_interval = GNUNET_TIME_relative_multiply(
383 GNUNET_TIME_UNIT_SECONDS,
384 (dht_max_update_interval/num_public_records));
385 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
386 "Adjusted DHT update interval to %ds!\n",
387 (dht_max_update_interval/num_public_records));
390 /* start counting again */
391 num_public_records = 0;
392 namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
394 GNUNET_NAMESTORE_RF_AUTHORITY,
395 GNUNET_NAMESTORE_RF_PRIVATE,
401 /* END DHT ZONE PROPAGATION */
404 * Send shorten response back to client
406 * @param cls the closure containing a client shorten handle
407 * @param name the shortened name result or NULL if cannot be shortened
410 send_shorten_response(void* cls, const char* name)
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n",
413 "SHORTEN_RESULT", name);
414 struct GNUNET_GNS_ClientShortenResultMessage *rmsg;
415 struct ClientShortenHandle *csh = (struct ClientShortenHandle *)cls;
422 rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientShortenResultMessage)
425 rmsg->id = csh->unique_id;
426 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT);
428 htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) +
431 strcpy((char*)&rmsg[1], name);
433 GNUNET_SERVER_notification_context_unicast (nc, csh->client,
434 (const struct GNUNET_MessageHeader *) rmsg,
436 GNUNET_SERVER_receive_done (csh->client, GNUNET_OK);
439 GNUNET_free_non_null(csh->name);
445 * Handle a shorten message from the api
447 * @param cls the closure
448 * @param client the client
449 * @param message the message
451 static void handle_shorten(void *cls,
452 struct GNUNET_SERVER_Client * client,
453 const struct GNUNET_MessageHeader * message)
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN");
458 struct ClientShortenHandle *csh;
459 char name[MAX_DNS_NAME_LENGTH];
460 char* nameptr = name;
462 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage))
465 GNUNET_SERVER_receive_done (client, GNUNET_OK);
469 GNUNET_SERVER_notification_context_add (nc, client);
471 struct GNUNET_GNS_ClientShortenMessage *sh_msg =
472 (struct GNUNET_GNS_ClientShortenMessage *) message;
474 msg_size = ntohs(message->size);
476 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
479 GNUNET_SERVER_receive_done (client, GNUNET_OK);
483 csh = GNUNET_malloc(sizeof(struct ClientShortenHandle));
484 csh->client = client;
485 csh->unique_id = sh_msg->id;
487 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
489 if (strlen (name) < strlen(GNUNET_GNS_TLD)) {
491 send_shorten_response(csh, name);
495 if (!is_gnunet_tld(name) && !is_zkey_tld(name))
497 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
498 "%s is not our domain. Returning\n", name);
500 send_shorten_response(csh, name);
504 /* Start shortening */
505 if (GNUNET_YES == auto_import_pkey)
506 gns_resolver_shorten_name(zone_hash, name, zone_key,
507 &send_shorten_response, csh);
509 gns_resolver_shorten_name(zone_hash, name, NULL,
510 &send_shorten_response, csh);
515 * Send get authority response back to client
517 * @param cls the closure containing a client get auth handle
518 * @param name the shortened name result or NULL if cannot be shortened
521 send_get_auth_response(void *cls, const char* name)
523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n",
524 "GET_AUTH_RESULT", name);
525 struct GNUNET_GNS_ClientGetAuthResultMessage *rmsg;
526 struct ClientGetAuthHandle *cah = (struct ClientGetAuthHandle *)cls;
533 rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage)
536 rmsg->id = cah->unique_id;
537 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT);
539 htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) +
542 strcpy((char*)&rmsg[1], name);
544 GNUNET_SERVER_notification_context_unicast (nc, cah->client,
545 (const struct GNUNET_MessageHeader *) rmsg,
547 GNUNET_SERVER_receive_done (cah->client, GNUNET_OK);
549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up handles...\n");
552 GNUNET_free_non_null(cah->name);
555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "done.\n");
561 * Handle a get authority message from the api
563 * @param cls the closure
564 * @param client the client
565 * @param message the message
567 static void handle_get_authority(void *cls,
568 struct GNUNET_SERVER_Client * client,
569 const struct GNUNET_MessageHeader * message)
571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "GET_AUTH");
574 struct ClientGetAuthHandle *cah;
575 char name[MAX_DNS_NAME_LENGTH];
576 char* nameptr = name;
579 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientGetAuthMessage))
582 GNUNET_SERVER_receive_done (client, GNUNET_OK);
586 GNUNET_SERVER_notification_context_add (nc, client);
588 struct GNUNET_GNS_ClientGetAuthMessage *sh_msg =
589 (struct GNUNET_GNS_ClientGetAuthMessage *) message;
591 msg_size = ntohs(message->size);
593 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
596 GNUNET_SERVER_receive_done (client, GNUNET_OK);
600 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
603 cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle));
604 cah->client = client;
605 cah->unique_id = sh_msg->id;
607 if (strlen(name) < strlen(GNUNET_GNS_TLD))
609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
610 "%s is too short. Returning\n", name);
612 send_get_auth_response(cah, name);
616 if (strcmp(name+strlen(name)-strlen(GNUNET_GNS_TLD),
617 GNUNET_GNS_TLD) != 0)
619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
620 "%s is not our domain. Returning\n", name);
622 send_get_auth_response(cah, name);
626 if (strcmp(name, GNUNET_GNS_TLD) == 0)
628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
629 "%s is us. Returning\n", name);
631 send_get_auth_response(cah, name);
635 cah->name = GNUNET_malloc(strlen(name)
636 - strlen(GNUNET_GNS_TLD) + 1);
638 strlen(name)-strlen(GNUNET_GNS_TLD) + 1);
639 memcpy(cah->name, name,
640 strlen(name)-strlen(GNUNET_GNS_TLD));
642 /* Start delegation resolution in our namestore */
643 gns_resolver_get_authority(zone_hash, name, &send_get_auth_response, cah);
648 * Reply to client with the result from our lookup.
650 * @param cls the closure (our client lookup handle)
651 * @param rd_count the number of records
652 * @param rd the record data
655 send_lookup_response(void* cls,
657 const struct GNUNET_NAMESTORE_RecordData *rd)
659 struct ClientLookupHandle* clh = (struct ClientLookupHandle*)cls;
660 struct GNUNET_GNS_ClientLookupResultMessage *rmsg;
663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %d results\n",
664 "LOOKUP_RESULT", rd_count);
666 len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
667 rmsg = GNUNET_malloc(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
669 rmsg->id = clh->unique_id;
670 rmsg->rd_count = htonl(rd_count);
671 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT);
673 htons(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
675 GNUNET_NAMESTORE_records_serialize (rd_count, rd, len, (char*)&rmsg[1]);
677 GNUNET_SERVER_notification_context_unicast (nc, clh->client,
678 (const struct GNUNET_MessageHeader *) rmsg,
680 GNUNET_SERVER_receive_done (clh->client, GNUNET_OK);
683 GNUNET_free(clh->name);
690 * Handle lookup requests from client
692 * @param cls the closure
693 * @param client the client
694 * @param message the message
697 handle_lookup(void *cls,
698 struct GNUNET_SERVER_Client * client,
699 const struct GNUNET_MessageHeader * message)
701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP");
705 char name[MAX_DNS_NAME_LENGTH];
706 struct ClientLookupHandle *clh;
707 char* nameptr = name;
709 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
712 GNUNET_SERVER_receive_done (client, GNUNET_OK);
716 GNUNET_SERVER_notification_context_add (nc, client);
718 struct GNUNET_GNS_ClientLookupMessage *sh_msg =
719 (struct GNUNET_GNS_ClientLookupMessage *) message;
721 msg_size = ntohs(message->size);
723 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
726 GNUNET_SERVER_receive_done (client, GNUNET_OK);
730 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
731 namelen = strlen(name)+1;
732 clh = GNUNET_malloc(sizeof(struct ClientLookupHandle));
733 clh->client = client;
734 clh->name = GNUNET_malloc(namelen);
735 strcpy(clh->name, name);
736 clh->unique_id = sh_msg->id;
737 clh->type = ntohl(sh_msg->type);
739 if (GNUNET_YES == auto_import_pkey)
741 gns_resolver_lookup_record(zone_hash, clh->type, name,
743 default_lookup_timeout,
744 &send_lookup_response, clh);
748 gns_resolver_lookup_record(zone_hash, clh->type, name,
750 default_lookup_timeout,
751 &send_lookup_response, clh);
758 * Process GNS requests.
760 * @param cls closure)
761 * @param server the initialized server
762 * @param c configuration to use
765 run (void *cls, struct GNUNET_SERVER_Handle *server,
766 const struct GNUNET_CONFIGURATION_Handle *c)
769 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initializing GNS\n");
772 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
773 unsigned long long max_parallel_bg_queries = 0;
774 unsigned long long default_lookup_timeout_secs = 0;
775 int ignore_pending = GNUNET_NO;
777 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
778 {&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0},
779 {&handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0},
780 {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0}
783 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns",
784 "ZONEKEY", &keyfile))
786 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
787 "No private key for root zone specified!\n");
788 GNUNET_SCHEDULER_shutdown(0);
792 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
793 "Using keyfile %s for root zone.\n", keyfile);
795 zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
796 GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey);
798 GNUNET_CRYPTO_short_hash(&pkey,
799 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
801 GNUNET_free(keyfile);
804 * handle to our local namestore
806 namestore_handle = GNUNET_NAMESTORE_connect(c);
808 if (NULL == namestore_handle)
810 //FIXME do error handling;
811 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
812 "Failed to connect to the namestore!\n");
813 GNUNET_SCHEDULER_shutdown(0);
819 auto_import_pkey = GNUNET_NO;
822 GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
825 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
826 "Automatic PKEY import is enabled.\n");
827 auto_import_pkey = GNUNET_YES;
831 dht_max_update_interval = GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL;
834 GNUNET_CONFIGURATION_get_value_number (c, "gns",
835 "DHT_MAX_UPDATE_INTERVAL",
836 &dht_max_update_interval))
838 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
839 "DHT zone update interval: %d\n",
840 dht_max_update_interval);
844 GNUNET_CONFIGURATION_get_value_number (c, "gns",
845 "MAX_PARALLEL_BACKGROUND_QUERIES",
846 &max_parallel_bg_queries))
848 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
849 "Number of allowed parallel background queries: %d\n",
850 max_parallel_bg_queries);
854 GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
855 "AUTO_IMPORT_CONFIRMATION_REQ"))
857 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
858 "Auto import requires user confirmation\n");
859 ignore_pending = GNUNET_YES;
863 GNUNET_CONFIGURATION_get_value_number(c, "gns",
864 "DEFAULT_LOOKUP_TIMEOUT",
865 &default_lookup_timeout_secs))
867 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
868 "Default lookup timeout: %ds\n", default_lookup_timeout_secs);
869 default_lookup_timeout = GNUNET_TIME_relative_multiply(
870 GNUNET_TIME_UNIT_SECONDS,
871 default_lookup_timeout_secs);
877 dht_handle = GNUNET_DHT_connect(c,
878 //max_parallel_bg_queries); //FIXME get ht_len from cfg
881 if (NULL == dht_handle)
883 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n");
886 if (gns_resolver_init(namestore_handle, dht_handle, zone_hash,
887 max_parallel_bg_queries,
891 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
892 "Unable to initialize resolver!\n");
893 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
898 GNUNET_CONFIGURATION_get_value_yesno (c, "gns", "HIJACK_DNS"))
900 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
901 "DNS hijacking enabled... connecting to service.\n");
903 if (gns_interceptor_init(zone_hash, zone_key, c) == GNUNET_SYSERR)
905 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
906 "Failed to enable the dns interceptor!\n");
911 * Schedule periodic put
913 * We have roughly an hour for all records;
915 dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
917 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL);
919 GNUNET_SERVER_add_handlers (server, handlers);
922 //GNUNET_SERVER_disconnect_notify (server,
923 // &client_disconnect_notification,
926 nc = GNUNET_SERVER_notification_context_create (server, 1);
928 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
934 * The main function for the GNS service.
936 * @param argc number of arguments from the command line
937 * @param argv command line arguments
938 * @return 0 ok, 1 on error
941 main (int argc, char *const *argv)
947 GNUNET_SERVICE_run (argc, argv, "gns", GNUNET_SERVICE_OPTION_NONE, &run,
952 /* end of gnunet-service-gns.c */