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);
470 struct GNUNET_GNS_ClientShortenMessage *sh_msg =
471 (struct GNUNET_GNS_ClientShortenMessage *) message;
473 msg_size = ntohs(message->size);
475 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
478 GNUNET_SERVER_receive_done (client, GNUNET_OK);
482 csh = GNUNET_malloc(sizeof(struct ClientShortenHandle));
483 csh->client = client;
484 csh->unique_id = sh_msg->id;
486 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
488 if (strlen (name) < strlen(GNUNET_GNS_TLD)) {
489 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
490 "SHORTEN: %s is too short", name);
492 send_shorten_response(csh, name);
496 if (strlen (name) > MAX_DNS_NAME_LENGTH) {
497 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
498 "SHORTEN: %s is too long", name);
500 send_shorten_response(csh, name);
504 if (!is_gnunet_tld(name) && !is_zkey_tld(name))
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
507 "%s is not our domain. Returning\n", name);
509 send_shorten_response(csh, name);
513 GNUNET_SERVER_notification_context_add (nc, client);
515 /* Start shortening */
516 if (GNUNET_YES == auto_import_pkey)
517 gns_resolver_shorten_name(zone_hash, name, zone_key,
518 &send_shorten_response, csh);
520 gns_resolver_shorten_name(zone_hash, name, NULL,
521 &send_shorten_response, csh);
526 * Send get authority response back to client
528 * @param cls the closure containing a client get auth handle
529 * @param name the shortened name result or NULL if cannot be shortened
532 send_get_auth_response(void *cls, const char* name)
534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n",
535 "GET_AUTH_RESULT", name);
536 struct GNUNET_GNS_ClientGetAuthResultMessage *rmsg;
537 struct ClientGetAuthHandle *cah = (struct ClientGetAuthHandle *)cls;
544 rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage)
547 rmsg->id = cah->unique_id;
548 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT);
550 htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) +
553 strcpy((char*)&rmsg[1], name);
555 GNUNET_SERVER_notification_context_unicast (nc, cah->client,
556 (const struct GNUNET_MessageHeader *) rmsg,
558 GNUNET_SERVER_receive_done (cah->client, GNUNET_OK);
560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up handles...\n");
563 GNUNET_free_non_null(cah->name);
566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "done.\n");
572 * Handle a get authority message from the api
574 * @param cls the closure
575 * @param client the client
576 * @param message the message
578 static void handle_get_authority(void *cls,
579 struct GNUNET_SERVER_Client * client,
580 const struct GNUNET_MessageHeader * message)
582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "GET_AUTH");
585 struct ClientGetAuthHandle *cah;
586 char name[MAX_DNS_NAME_LENGTH];
587 char* nameptr = name;
590 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientGetAuthMessage))
593 GNUNET_SERVER_receive_done (client, GNUNET_OK);
597 GNUNET_SERVER_notification_context_add (nc, client);
599 struct GNUNET_GNS_ClientGetAuthMessage *sh_msg =
600 (struct GNUNET_GNS_ClientGetAuthMessage *) message;
602 msg_size = ntohs(message->size);
604 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
607 GNUNET_SERVER_receive_done (client, GNUNET_OK);
611 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
614 cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle));
615 cah->client = client;
616 cah->unique_id = sh_msg->id;
618 if (strlen(name) < strlen(GNUNET_GNS_TLD))
620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
621 "GET_AUTH: %s is too short. Returning\n", name);
623 send_get_auth_response(cah, name);
627 if (strlen (name) > MAX_DNS_NAME_LENGTH) {
628 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
629 "GET_AUTH: %s is too long", name);
631 send_get_auth_response(cah, name);
635 if (strcmp(name+strlen(name)-strlen(GNUNET_GNS_TLD),
636 GNUNET_GNS_TLD) != 0)
638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
639 "GET_AUTH: %s is not our domain. Returning\n", name);
641 send_get_auth_response(cah, name);
645 if (strcmp(name, GNUNET_GNS_TLD) == 0)
647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
648 "GET_AUTH: %s is us. Returning\n", name);
650 send_get_auth_response(cah, name);
654 cah->name = GNUNET_malloc(strlen(name)
655 - strlen(GNUNET_GNS_TLD) + 1);
657 strlen(name)-strlen(GNUNET_GNS_TLD) + 1);
658 memcpy(cah->name, name,
659 strlen(name)-strlen(GNUNET_GNS_TLD));
661 /* Start delegation resolution in our namestore */
662 gns_resolver_get_authority(zone_hash, name, &send_get_auth_response, cah);
667 * Reply to client with the result from our lookup.
669 * @param cls the closure (our client lookup handle)
670 * @param rd_count the number of records
671 * @param rd the record data
674 send_lookup_response(void* cls,
676 const struct GNUNET_NAMESTORE_RecordData *rd)
678 struct ClientLookupHandle* clh = (struct ClientLookupHandle*)cls;
679 struct GNUNET_GNS_ClientLookupResultMessage *rmsg;
682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %d results\n",
683 "LOOKUP_RESULT", rd_count);
685 len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
686 rmsg = GNUNET_malloc(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
688 rmsg->id = clh->unique_id;
689 rmsg->rd_count = htonl(rd_count);
690 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT);
692 htons(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
694 GNUNET_NAMESTORE_records_serialize (rd_count, rd, len, (char*)&rmsg[1]);
696 GNUNET_SERVER_notification_context_unicast (nc, clh->client,
697 (const struct GNUNET_MessageHeader *) rmsg,
699 GNUNET_SERVER_receive_done (clh->client, GNUNET_OK);
702 GNUNET_free(clh->name);
709 * Handle lookup requests from client
711 * @param cls the closure
712 * @param client the client
713 * @param message the message
716 handle_lookup(void *cls,
717 struct GNUNET_SERVER_Client * client,
718 const struct GNUNET_MessageHeader * message)
720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP");
724 char name[MAX_DNS_NAME_LENGTH];
725 struct ClientLookupHandle *clh;
726 char* nameptr = name;
728 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
731 GNUNET_SERVER_receive_done (client, GNUNET_OK);
735 GNUNET_SERVER_notification_context_add (nc, client);
737 struct GNUNET_GNS_ClientLookupMessage *sh_msg =
738 (struct GNUNET_GNS_ClientLookupMessage *) message;
740 msg_size = ntohs(message->size);
742 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
745 GNUNET_SERVER_receive_done (client, GNUNET_OK);
749 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
750 namelen = strlen(name)+1;
751 clh = GNUNET_malloc(sizeof(struct ClientLookupHandle));
752 clh->client = client;
753 clh->name = GNUNET_malloc(namelen);
754 strcpy(clh->name, name);
755 clh->unique_id = sh_msg->id;
756 clh->type = ntohl(sh_msg->type);
758 if (strlen (name) > MAX_DNS_NAME_LENGTH) {
759 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
760 "LOOKUP: %s is too long", name);
762 send_lookup_response(clh, 0, NULL);
766 if (GNUNET_YES == auto_import_pkey)
768 gns_resolver_lookup_record(zone_hash, clh->type, name,
770 default_lookup_timeout,
771 &send_lookup_response, clh);
775 gns_resolver_lookup_record(zone_hash, clh->type, name,
777 default_lookup_timeout,
778 &send_lookup_response, clh);
785 * Process GNS requests.
787 * @param cls closure)
788 * @param server the initialized server
789 * @param c configuration to use
792 run (void *cls, struct GNUNET_SERVER_Handle *server,
793 const struct GNUNET_CONFIGURATION_Handle *c)
796 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initializing GNS\n");
799 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
800 unsigned long long max_parallel_bg_queries = 0;
801 unsigned long long default_lookup_timeout_secs = 0;
802 int ignore_pending = GNUNET_NO;
804 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
805 {&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0},
806 {&handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0},
807 {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0}
810 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns",
811 "ZONEKEY", &keyfile))
813 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
814 "No private key for root zone specified!\n");
815 GNUNET_SCHEDULER_shutdown(0);
819 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
820 "Using keyfile %s for root zone.\n", keyfile);
822 zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
823 GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey);
825 GNUNET_CRYPTO_short_hash(&pkey,
826 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
828 GNUNET_free(keyfile);
831 * handle to our local namestore
833 namestore_handle = GNUNET_NAMESTORE_connect(c);
835 if (NULL == namestore_handle)
837 //FIXME do error handling;
838 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
839 "Failed to connect to the namestore!\n");
840 GNUNET_SCHEDULER_shutdown(0);
846 auto_import_pkey = GNUNET_NO;
849 GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
852 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
853 "Automatic PKEY import is enabled.\n");
854 auto_import_pkey = GNUNET_YES;
858 dht_max_update_interval = GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL;
861 GNUNET_CONFIGURATION_get_value_number (c, "gns",
862 "DHT_MAX_UPDATE_INTERVAL",
863 &dht_max_update_interval))
865 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
866 "DHT zone update interval: %d\n",
867 dht_max_update_interval);
871 GNUNET_CONFIGURATION_get_value_number (c, "gns",
872 "MAX_PARALLEL_BACKGROUND_QUERIES",
873 &max_parallel_bg_queries))
875 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
876 "Number of allowed parallel background queries: %d\n",
877 max_parallel_bg_queries);
881 GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
882 "AUTO_IMPORT_CONFIRMATION_REQ"))
884 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
885 "Auto import requires user confirmation\n");
886 ignore_pending = GNUNET_YES;
890 GNUNET_CONFIGURATION_get_value_number(c, "gns",
891 "DEFAULT_LOOKUP_TIMEOUT",
892 &default_lookup_timeout_secs))
894 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
895 "Default lookup timeout: %ds\n", default_lookup_timeout_secs);
896 default_lookup_timeout = GNUNET_TIME_relative_multiply(
897 GNUNET_TIME_UNIT_SECONDS,
898 default_lookup_timeout_secs);
904 dht_handle = GNUNET_DHT_connect(c,
905 //max_parallel_bg_queries); //FIXME get ht_len from cfg
908 if (NULL == dht_handle)
910 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n");
913 if (gns_resolver_init(namestore_handle, dht_handle, zone_hash,
914 max_parallel_bg_queries,
918 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
919 "Unable to initialize resolver!\n");
920 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
925 GNUNET_CONFIGURATION_get_value_yesno (c, "gns", "HIJACK_DNS"))
927 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
928 "DNS hijacking enabled... connecting to service.\n");
930 if (gns_interceptor_init(zone_hash, zone_key, c) == GNUNET_SYSERR)
932 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
933 "Failed to enable the dns interceptor!\n");
938 * Schedule periodic put
940 * We have roughly an hour for all records;
942 dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
944 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL);
946 GNUNET_SERVER_add_handlers (server, handlers);
949 //GNUNET_SERVER_disconnect_notify (server,
950 // &client_disconnect_notification,
953 nc = GNUNET_SERVER_notification_context_create (server, 1);
955 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
961 * The main function for the GNS service.
963 * @param argc number of arguments from the command line
964 * @param argv command line arguments
965 * @return 0 ok, 1 on error
968 main (int argc, char *const *argv)
974 GNUNET_SERVICE_run (argc, argv, "gns", GNUNET_SERVICE_OPTION_NONE, &run,
979 /* end of gnunet-service-gns.c */