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 = 0;
146 * update interval in seconds
148 static unsigned long long int max_record_put_interval;
150 static unsigned long long int dht_max_update_interval;
152 /* dht update interval FIXME define? */
153 static struct GNUNET_TIME_Relative record_put_interval;
155 /* zone update task */
156 GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid = GNUNET_SCHEDULER_NO_TASK;
158 /* automatic pkey import for name shortening */
159 static int auto_import_pkey;
162 static struct GNUNET_TIME_Relative default_lookup_timeout;
168 on_resolver_cleanup(void)
170 GNUNET_NAMESTORE_disconnect(namestore_handle, 1);
171 GNUNET_DHT_disconnect(dht_handle);
175 * Task run during shutdown.
181 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
184 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
186 /* Kill zone task for it may make the scheduler hang */
187 if (zone_update_taskid)
188 GNUNET_SCHEDULER_cancel(zone_update_taskid);
190 GNUNET_SERVER_notification_context_destroy (nc);
192 gns_interceptor_stop();
193 gns_resolver_cleanup(&on_resolver_cleanup);
199 * Method called periodicattluy that triggers
200 * iteration over root zone
203 * @param tc task context
206 update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
208 GNUNET_NAMESTORE_zone_iterator_next(namestore_iter);
212 * Continuation for DHT put
215 * @param tc task context
218 record_dht_put(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
220 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "put request transmitted\n");
225 update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
228 * Function used to put all records successively into the DHT.
230 * @param cls the closure (NULL)
231 * @param key the public key of the authority (ours)
232 * @param expiration lifetime of the namestore entry
233 * @param name the name of the records
234 * @param rd_count the number of records in data
235 * @param rd the record data
236 * @param signature the signature for the record data
239 put_gns_record(void *cls,
240 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
241 struct GNUNET_TIME_Absolute expiration,
243 unsigned int rd_count,
244 const struct GNUNET_NAMESTORE_RecordData *rd,
245 const struct GNUNET_CRYPTO_RsaSignature *signature)
248 struct GNSNameRecordBlock *nrb;
249 struct GNUNET_CRYPTO_ShortHashCode name_hash;
250 GNUNET_HashCode xor_hash;
251 GNUNET_HashCode name_hash_double;
252 GNUNET_HashCode zone_hash_double;
253 struct GNUNET_CRYPTO_HashAsciiEncoded xor_hash_string;
254 uint32_t rd_payload_length;
255 char* nrb_data = NULL;
261 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
262 "Zone iteration finished. Rescheduling put in %ds\n",
263 dht_max_update_interval);
264 zone_update_taskid = GNUNET_SCHEDULER_add_delayed (
265 GNUNET_TIME_relative_multiply(
266 GNUNET_TIME_UNIT_SECONDS,
267 dht_max_update_interval
269 &update_zone_dht_start,
274 namelen = strlen(name) + 1;
276 if (signature == NULL)
278 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
279 "No signature for %s record data provided! Skipping...\n",
281 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next,
287 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
288 "Putting records for %s into the DHT\n", name);
290 rd_payload_length = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
292 nrb = GNUNET_malloc(rd_payload_length + namelen
293 + sizeof(struct GNSNameRecordBlock));
295 nrb->signature = *signature;
297 nrb->public_key = *key;
299 nrb->rd_count = htonl(rd_count);
301 memcpy(&nrb[1], name, namelen);
303 nrb_data = (char*)&nrb[1];
306 rd_payload_length += sizeof(struct GNSNameRecordBlock) + namelen;
308 if (-1 == GNUNET_NAMESTORE_records_serialize (rd_count,
313 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
314 "Record serialization failed! Skipping...\n");
316 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next,
323 * calculate DHT key: H(name) xor H(pubkey)
325 GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash);
326 GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double);
327 GNUNET_CRYPTO_short_hash_double (&zone_hash, &zone_hash_double);
328 GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash);
329 GNUNET_CRYPTO_hash_to_enc (&xor_hash, &xor_hash_string);
331 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
332 "putting records for %s under key: %s with size %d\n",
333 name, (char*)&xor_hash_string, rd_payload_length);
335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
336 "DHT req to %d\n", DHT_OPERATION_TIMEOUT.rel_value);
338 GNUNET_DHT_put (dht_handle, &xor_hash,
339 DHT_GNS_REPLICATION_LEVEL,
341 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
345 DHT_OPERATION_TIMEOUT,
347 NULL); //cls for cont
349 num_public_records++;
352 * Reschedule periodic put
354 zone_update_taskid = GNUNET_SCHEDULER_add_delayed (record_put_interval,
355 &update_zone_dht_next,
363 * Periodically iterate over our zone and store everything in dht
366 * @param tc task context
369 update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
371 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling DHT zone update!\n");
373 unsigned long long int interval = 0;
375 if (0 == num_public_records)
378 * If no records are known (startup) or none present
379 * we can safely set the interval to 1s
381 record_put_interval = GNUNET_TIME_relative_multiply(
382 GNUNET_TIME_UNIT_SECONDS,
384 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
385 "No records in db. Adjusted record put interval to 1s\n");
389 interval = max_record_put_interval/num_public_records;
392 record_put_interval = GNUNET_TIME_relative_multiply(
393 GNUNET_TIME_UNIT_SECONDS,
395 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
396 "Adjusted DHT update interval to %ds!\n",
400 /* start counting again */
401 num_public_records = 0;
402 namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
404 GNUNET_NAMESTORE_RF_AUTHORITY,
405 GNUNET_NAMESTORE_RF_PRIVATE,
411 /* END DHT ZONE PROPAGATION */
414 * Send shorten response back to client
416 * @param cls the closure containing a client shorten handle
417 * @param name the shortened name result or NULL if cannot be shortened
420 send_shorten_response(void* cls, const char* name)
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n",
423 "SHORTEN_RESULT", name);
424 struct GNUNET_GNS_ClientShortenResultMessage *rmsg;
425 struct ClientShortenHandle *csh = (struct ClientShortenHandle *)cls;
432 rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientShortenResultMessage)
435 rmsg->id = csh->unique_id;
436 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT);
438 htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) +
441 strcpy((char*)&rmsg[1], name);
443 GNUNET_SERVER_notification_context_unicast (nc, csh->client,
444 (const struct GNUNET_MessageHeader *) rmsg,
446 GNUNET_SERVER_receive_done (csh->client, GNUNET_OK);
449 GNUNET_free_non_null(csh->name);
455 * Handle a shorten message from the api
457 * @param cls the closure
458 * @param client the client
459 * @param message the message
461 static void handle_shorten(void *cls,
462 struct GNUNET_SERVER_Client * client,
463 const struct GNUNET_MessageHeader * message)
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN");
468 struct ClientShortenHandle *csh;
469 char name[MAX_DNS_NAME_LENGTH];
470 char* nameptr = name;
472 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage))
475 GNUNET_SERVER_receive_done (client, GNUNET_OK);
480 struct GNUNET_GNS_ClientShortenMessage *sh_msg =
481 (struct GNUNET_GNS_ClientShortenMessage *) message;
483 msg_size = ntohs(message->size);
485 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
488 GNUNET_SERVER_receive_done (client, GNUNET_OK);
492 csh = GNUNET_malloc(sizeof(struct ClientShortenHandle));
493 csh->client = client;
494 csh->unique_id = sh_msg->id;
496 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
498 if (strlen (name) < strlen(GNUNET_GNS_TLD)) {
499 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
500 "SHORTEN: %s is too short", name);
502 send_shorten_response(csh, name);
506 if (strlen (name) > MAX_DNS_NAME_LENGTH) {
507 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
508 "SHORTEN: %s is too long", name);
510 send_shorten_response(csh, name);
514 if (!is_gnunet_tld(name) && !is_zkey_tld(name))
516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
517 "%s is not our domain. Returning\n", name);
519 send_shorten_response(csh, name);
523 GNUNET_SERVER_notification_context_add (nc, client);
525 /* Start shortening */
526 if (GNUNET_YES == auto_import_pkey)
527 gns_resolver_shorten_name(zone_hash, name, zone_key,
528 &send_shorten_response, csh);
530 gns_resolver_shorten_name(zone_hash, name, NULL,
531 &send_shorten_response, csh);
536 * Send get authority response back to client
538 * @param cls the closure containing a client get auth handle
539 * @param name the shortened name result or NULL if cannot be shortened
542 send_get_auth_response(void *cls, const char* name)
544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n",
545 "GET_AUTH_RESULT", name);
546 struct GNUNET_GNS_ClientGetAuthResultMessage *rmsg;
547 struct ClientGetAuthHandle *cah = (struct ClientGetAuthHandle *)cls;
554 rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage)
557 rmsg->id = cah->unique_id;
558 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT);
560 htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) +
563 strcpy((char*)&rmsg[1], name);
565 GNUNET_SERVER_notification_context_unicast (nc, cah->client,
566 (const struct GNUNET_MessageHeader *) rmsg,
568 GNUNET_SERVER_receive_done (cah->client, GNUNET_OK);
570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up handles...\n");
573 GNUNET_free_non_null(cah->name);
576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "done.\n");
582 * Handle a get authority message from the api
584 * @param cls the closure
585 * @param client the client
586 * @param message the message
588 static void handle_get_authority(void *cls,
589 struct GNUNET_SERVER_Client * client,
590 const struct GNUNET_MessageHeader * message)
592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "GET_AUTH");
595 struct ClientGetAuthHandle *cah;
596 char name[MAX_DNS_NAME_LENGTH];
597 char* nameptr = name;
600 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientGetAuthMessage))
603 GNUNET_SERVER_receive_done (client, GNUNET_OK);
607 GNUNET_SERVER_notification_context_add (nc, client);
609 struct GNUNET_GNS_ClientGetAuthMessage *sh_msg =
610 (struct GNUNET_GNS_ClientGetAuthMessage *) message;
612 msg_size = ntohs(message->size);
614 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
617 GNUNET_SERVER_receive_done (client, GNUNET_OK);
621 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
624 cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle));
625 cah->client = client;
626 cah->unique_id = sh_msg->id;
628 if (strlen(name) < strlen(GNUNET_GNS_TLD))
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
631 "GET_AUTH: %s is too short. Returning\n", name);
633 send_get_auth_response(cah, name);
637 if (strlen (name) > MAX_DNS_NAME_LENGTH) {
638 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
639 "GET_AUTH: %s is too long", name);
641 send_get_auth_response(cah, name);
645 if (strcmp(name+strlen(name)-strlen(GNUNET_GNS_TLD),
646 GNUNET_GNS_TLD) != 0)
648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
649 "GET_AUTH: %s is not our domain. Returning\n", name);
651 send_get_auth_response(cah, name);
655 if (strcmp(name, GNUNET_GNS_TLD) == 0)
657 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
658 "GET_AUTH: %s is us. Returning\n", name);
660 send_get_auth_response(cah, name);
664 cah->name = GNUNET_malloc(strlen(name)
665 - strlen(GNUNET_GNS_TLD) + 1);
667 strlen(name)-strlen(GNUNET_GNS_TLD) + 1);
668 memcpy(cah->name, name,
669 strlen(name)-strlen(GNUNET_GNS_TLD));
671 /* Start delegation resolution in our namestore */
672 gns_resolver_get_authority(zone_hash, name, &send_get_auth_response, cah);
677 * Reply to client with the result from our lookup.
679 * @param cls the closure (our client lookup handle)
680 * @param rd_count the number of records
681 * @param rd the record data
684 send_lookup_response(void* cls,
686 const struct GNUNET_NAMESTORE_RecordData *rd)
688 struct ClientLookupHandle* clh = (struct ClientLookupHandle*)cls;
689 struct GNUNET_GNS_ClientLookupResultMessage *rmsg;
692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %d results\n",
693 "LOOKUP_RESULT", rd_count);
695 len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
696 rmsg = GNUNET_malloc(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
698 rmsg->id = clh->unique_id;
699 rmsg->rd_count = htonl(rd_count);
700 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT);
702 htons(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
704 GNUNET_NAMESTORE_records_serialize (rd_count, rd, len, (char*)&rmsg[1]);
706 GNUNET_SERVER_notification_context_unicast (nc, clh->client,
707 (const struct GNUNET_MessageHeader *) rmsg,
709 GNUNET_SERVER_receive_done (clh->client, GNUNET_OK);
712 GNUNET_free(clh->name);
719 * Handle lookup requests from client
721 * @param cls the closure
722 * @param client the client
723 * @param message the message
726 handle_lookup(void *cls,
727 struct GNUNET_SERVER_Client * client,
728 const struct GNUNET_MessageHeader * message)
730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP");
734 char name[MAX_DNS_NAME_LENGTH];
735 struct ClientLookupHandle *clh;
736 char* nameptr = name;
738 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
741 GNUNET_SERVER_receive_done (client, GNUNET_OK);
745 GNUNET_SERVER_notification_context_add (nc, client);
747 struct GNUNET_GNS_ClientLookupMessage *sh_msg =
748 (struct GNUNET_GNS_ClientLookupMessage *) message;
750 msg_size = ntohs(message->size);
752 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
755 GNUNET_SERVER_receive_done (client, GNUNET_OK);
759 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
760 namelen = strlen(name)+1;
761 clh = GNUNET_malloc(sizeof(struct ClientLookupHandle));
762 clh->client = client;
763 clh->name = GNUNET_malloc(namelen);
764 strcpy(clh->name, name);
765 clh->unique_id = sh_msg->id;
766 clh->type = ntohl(sh_msg->type);
768 if (strlen (name) > MAX_DNS_NAME_LENGTH) {
769 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
770 "LOOKUP: %s is too long", name);
772 send_lookup_response(clh, 0, NULL);
776 if (GNUNET_YES == auto_import_pkey)
778 gns_resolver_lookup_record(zone_hash, clh->type, name,
780 default_lookup_timeout,
781 &send_lookup_response, clh);
785 gns_resolver_lookup_record(zone_hash, clh->type, name,
787 default_lookup_timeout,
788 &send_lookup_response, clh);
795 * Process GNS requests.
797 * @param cls closure)
798 * @param server the initialized server
799 * @param c configuration to use
802 run (void *cls, struct GNUNET_SERVER_Handle *server,
803 const struct GNUNET_CONFIGURATION_Handle *c)
806 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initializing GNS\n");
809 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
810 unsigned long long max_parallel_bg_queries = 0;
811 unsigned long long default_lookup_timeout_secs = 0;
812 int ignore_pending = GNUNET_NO;
814 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
815 {&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0},
816 {&handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0},
817 {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0}
820 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns",
821 "ZONEKEY", &keyfile))
823 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
824 "No private key for root zone specified!\n");
825 GNUNET_SCHEDULER_shutdown(0);
829 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
830 "Using keyfile %s for root zone.\n", keyfile);
832 zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
833 GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey);
835 GNUNET_CRYPTO_short_hash(&pkey,
836 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
838 GNUNET_free(keyfile);
841 * handle to our local namestore
843 namestore_handle = GNUNET_NAMESTORE_connect(c);
845 if (NULL == namestore_handle)
847 //FIXME do error handling;
848 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
849 "Failed to connect to the namestore!\n");
850 GNUNET_SCHEDULER_shutdown(0);
856 auto_import_pkey = GNUNET_NO;
859 GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
862 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
863 "Automatic PKEY import is enabled.\n");
864 auto_import_pkey = GNUNET_YES;
868 dht_max_update_interval = GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL;
871 GNUNET_CONFIGURATION_get_value_number (c, "gns",
873 &dht_max_update_interval))
875 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
876 "DHT zone update interval: %d\n",
877 dht_max_update_interval);
880 max_record_put_interval = 1;
883 GNUNET_CONFIGURATION_get_value_number (c, "gns",
884 "RECORD_PUT_INTERVAL",
885 &max_record_put_interval))
887 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
888 "Record put interval: %d\n",
889 max_record_put_interval);
893 GNUNET_CONFIGURATION_get_value_number (c, "gns",
894 "MAX_PARALLEL_BACKGROUND_QUERIES",
895 &max_parallel_bg_queries))
897 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
898 "Number of allowed parallel background queries: %d\n",
899 max_parallel_bg_queries);
903 GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
904 "AUTO_IMPORT_CONFIRMATION_REQ"))
906 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
907 "Auto import requires user confirmation\n");
908 ignore_pending = GNUNET_YES;
912 GNUNET_CONFIGURATION_get_value_number(c, "gns",
913 "DEFAULT_LOOKUP_TIMEOUT",
914 &default_lookup_timeout_secs))
916 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
917 "Default lookup timeout: %ds\n", default_lookup_timeout_secs);
918 default_lookup_timeout = GNUNET_TIME_relative_multiply(
919 GNUNET_TIME_UNIT_SECONDS,
920 default_lookup_timeout_secs);
926 dht_handle = GNUNET_DHT_connect(c,
927 //max_parallel_bg_queries); //FIXME get ht_len from cfg
930 if (NULL == dht_handle)
932 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n");
935 if (gns_resolver_init(namestore_handle, dht_handle, zone_hash,
936 max_parallel_bg_queries,
940 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
941 "Unable to initialize resolver!\n");
942 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
947 GNUNET_CONFIGURATION_get_value_yesno (c, "gns", "HIJACK_DNS"))
949 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
950 "DNS hijacking enabled... connecting to service.\n");
952 if (gns_interceptor_init(zone_hash, zone_key, c) == GNUNET_SYSERR)
954 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
955 "Failed to enable the dns interceptor!\n");
960 * Schedule periodic put
962 * We have roughly an hour for all records;
964 record_put_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
966 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL);
968 GNUNET_SERVER_add_handlers (server, handlers);
971 //GNUNET_SERVER_disconnect_notify (server,
972 // &client_disconnect_notification,
975 nc = GNUNET_SERVER_notification_context_create (server, 1);
977 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
983 * The main function for the GNS service.
985 * @param argc number of arguments from the command line
986 * @param argv command line arguments
987 * @return 0 ok, 1 on error
990 main (int argc, char *const *argv)
996 GNUNET_SERVICE_run (argc, argv, "gns", GNUNET_SERVICE_OPTION_NONE, &run,
1001 /* end of gnunet-service-gns.c */