aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r--src/gns/gnunet-service-gns.c161
1 files changed, 56 insertions, 105 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 69f1ca640..90cd47e1d 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011-2013 GNUnet e.V. 3 Copyright (C) 2011-2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -29,7 +29,7 @@
29#include "gnunet_dnsparser_lib.h" 29#include "gnunet_dnsparser_lib.h"
30#include "gnunet_dht_service.h" 30#include "gnunet_dht_service.h"
31#include "gnunet_namecache_service.h" 31#include "gnunet_namecache_service.h"
32#include "gnunet_identity_service.h" 32#include "gnunet_gnsrecord_lib.h"
33#include "gnunet_gns_service.h" 33#include "gnunet_gns_service.h"
34#include "gnunet_statistics_service.h" 34#include "gnunet_statistics_service.h"
35#include "gns.h" 35#include "gns.h"
@@ -44,7 +44,7 @@
44struct GnsClient; 44struct GnsClient;
45 45
46/** 46/**
47 * Handle to a lookup operation from api 47 * Handle to a lookup operation from client via API.
48 */ 48 */
49struct ClientLookupHandle 49struct ClientLookupHandle
50{ 50{
@@ -76,6 +76,10 @@ struct ClientLookupHandle
76 76
77}; 77};
78 78
79
80/**
81 * Information we track per connected client.
82 */
79struct GnsClient 83struct GnsClient
80{ 84{
81 /** 85 /**
@@ -122,7 +126,7 @@ struct GNS_TopLevelDomain
122 /** 126 /**
123 * Public key associated with the @a tld. 127 * Public key associated with the @a tld.
124 */ 128 */
125 struct GNUNET_CRYPTO_EddsaPublicKey pkey; 129 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
126 130
127 /** 131 /**
128 * Top-level domain as a string, including leading ".". 132 * Top-level domain as a string, including leading ".".
@@ -143,17 +147,6 @@ static struct GNUNET_DHT_Handle *dht_handle;
143static struct GNUNET_NAMECACHE_Handle *namecache_handle; 147static struct GNUNET_NAMECACHE_Handle *namecache_handle;
144 148
145/** 149/**
146 * Our handle to the identity service
147 */
148static struct GNUNET_IDENTITY_Handle *identity_handle;
149
150/**
151 * Our handle to the identity operation to find the master zone
152 * for intercepted queries.
153 */
154static struct GNUNET_IDENTITY_Operation *identity_op;
155
156/**
157 * #GNUNET_YES if ipv6 is supported 150 * #GNUNET_YES if ipv6 is supported
158 */ 151 */
159static int v6_enabled; 152static int v6_enabled;
@@ -188,7 +181,7 @@ static struct GNS_TopLevelDomain *tld_tail;
188 */ 181 */
189int 182int
190GNS_find_tld (const char *tld_str, 183GNS_find_tld (const char *tld_str,
191 struct GNUNET_CRYPTO_EddsaPublicKey *pkey) 184 struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
192{ 185{
193 if ('\0' == *tld_str) 186 if ('\0' == *tld_str)
194 return GNUNET_NO; 187 return GNUNET_NO;
@@ -204,16 +197,36 @@ GNS_find_tld (const char *tld_str,
204 } 197 }
205 } 198 }
206 if (GNUNET_OK == 199 if (GNUNET_OK ==
207 GNUNET_STRINGS_string_to_data (tld_str + 1, 200 GNUNET_GNSRECORD_zkey_to_pkey (tld_str + 1,
208 strlen (tld_str + 1), 201 pkey))
209 pkey,
210 sizeof (*pkey)))
211 return GNUNET_YES; /* TLD string *was* the public key */ 202 return GNUNET_YES; /* TLD string *was* the public key */
212 return GNUNET_NO; 203 return GNUNET_NO;
213} 204}
214 205
215 206
216/** 207/**
208 * Obtain the TLD of the given @a name.
209 *
210 * @param name a name
211 * @return the part of @a name after the last ".",
212 * or @a name if @a name does not contain a "."
213 */
214const char *
215GNS_get_tld (const char *name)
216{
217 const char *tld;
218
219 tld = strrchr (name,
220 (unsigned char) '.');
221 if (NULL == tld)
222 tld = name;
223 else
224 tld++; /* skip the '.' */
225 return tld;
226}
227
228
229/**
217 * Task run during shutdown. 230 * Task run during shutdown.
218 * 231 *
219 * @param cls unused 232 * @param cls unused
@@ -227,16 +240,6 @@ shutdown_task (void *cls)
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
228 "Shutting down!\n"); 241 "Shutting down!\n");
229 GNS_interceptor_done (); 242 GNS_interceptor_done ();
230 if (NULL != identity_op)
231 {
232 GNUNET_IDENTITY_cancel (identity_op);
233 identity_op = NULL;
234 }
235 if (NULL != identity_handle)
236 {
237 GNUNET_IDENTITY_disconnect (identity_handle);
238 identity_handle = NULL;
239 }
240 GNS_resolver_done (); 243 GNS_resolver_done ();
241 if (NULL != statistics) 244 if (NULL != statistics)
242 { 245 {
@@ -416,7 +419,8 @@ handle_lookup (void *cls,
416 419
417 GNUNET_SERVICE_client_continue (gc->client); 420 GNUNET_SERVICE_client_continue (gc->client);
418 utf_in = (const char *) &sh_msg[1]; 421 utf_in = (const char *) &sh_msg[1];
419 GNUNET_STRINGS_utf8_tolower (utf_in, nameptr); 422 GNUNET_STRINGS_utf8_tolower (utf_in,
423 nameptr);
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
421 "Received LOOKUP `%s' message\n", 425 "Received LOOKUP `%s' message\n",
422 name); 426 name);
@@ -432,7 +436,9 @@ handle_lookup (void *cls,
432 { 436 {
433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
434 "LOOKUP: Query for A record but AF_INET not supported!"); 438 "LOOKUP: Query for A record but AF_INET not supported!");
435 send_lookup_response (clh, 0, NULL); 439 send_lookup_response (clh,
440 0,
441 NULL);
436 return; 442 return;
437 } 443 }
438 if ( (GNUNET_DNSPARSER_TYPE_AAAA == ntohl (sh_msg->type)) && 444 if ( (GNUNET_DNSPARSER_TYPE_AAAA == ntohl (sh_msg->type)) &&
@@ -440,7 +446,9 @@ handle_lookup (void *cls,
440 { 446 {
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
442 "LOOKUP: Query for AAAA record but AF_INET6 not supported!"); 448 "LOOKUP: Query for AAAA record but AF_INET6 not supported!");
443 send_lookup_response (clh, 0, NULL); 449 send_lookup_response (clh,
450 0,
451 NULL);
444 return; 452 return;
445 } 453 }
446 clh->lookup = GNS_resolver_lookup (&sh_msg->zone, 454 clh->lookup = GNS_resolver_lookup (&sh_msg->zone,
@@ -455,57 +463,6 @@ handle_lookup (void *cls,
455 463
456 464
457/** 465/**
458 * Method called to inform about the ego to be used for the master zone
459 * for DNS interceptions.
460 *
461 * This function is only called ONCE, and 'NULL' being passed in
462 * @a ego does indicate that interception is not configured.
463 * If @a ego is non-NULL, we should start to intercept DNS queries
464 * and resolve ".gnu" queries using the given ego as the master zone.
465 *
466 * @param cls closure, our `const struct GNUNET_CONFIGURATION_Handle *c`
467 * @param ego ego handle
468 * @param ctx context for application to store data for this ego
469 * (during the lifetime of this process, initially NULL)
470 * @param name name assigned by the user for this ego,
471 * NULL if the user just deleted the ego and it
472 * must thus no longer be used
473 */
474static void
475identity_intercept_cb (void *cls,
476 struct GNUNET_IDENTITY_Ego *ego,
477 void **ctx,
478 const char *name)
479{
480 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
481 struct GNUNET_CRYPTO_EcdsaPublicKey dns_root;
482
483 identity_op = NULL;
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 "Looking for gns-intercept ego\n");
486 if (NULL == ego)
487 {
488 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
489 _("No ego configured for `%s`\n"),
490 "gns-intercept");
491
492 return;
493 }
494 GNUNET_IDENTITY_ego_get_public_key (ego,
495 &dns_root);
496 if (GNUNET_SYSERR ==
497 GNS_interceptor_init (&dns_root,
498 cfg))
499 {
500 GNUNET_break (0);
501 GNUNET_SCHEDULER_add_now (&shutdown_task,
502 NULL);
503 return;
504 }
505}
506
507
508/**
509 * Reads the configuration and populates TLDs 466 * Reads the configuration and populates TLDs
510 * 467 *
511 * @param cls unused 468 * @param cls unused
@@ -519,7 +476,7 @@ read_service_conf (void *cls,
519 const char *option, 476 const char *option,
520 const char *value) 477 const char *value)
521{ 478{
522 struct GNUNET_CRYPTO_EddsaPublicKey pk; 479 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
523 struct GNS_TopLevelDomain *tld; 480 struct GNS_TopLevelDomain *tld;
524 481
525 if (option[0] != '.') 482 if (option[0] != '.')
@@ -545,7 +502,6 @@ read_service_conf (void *cls,
545} 502}
546 503
547 504
548
549/** 505/**
550 * Process GNS requests. 506 * Process GNS requests.
551 * 507 *
@@ -594,29 +550,24 @@ run (void *cls,
594 NULL); 550 NULL);
595 return; 551 return;
596 } 552 }
597
598 identity_handle = GNUNET_IDENTITY_connect (c,
599 NULL,
600 NULL);
601 if (NULL == identity_handle)
602 {
603 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
604 "Could not connect to identity service!\n");
605 }
606 else
607 {
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
609 "Looking for gns-intercept ego\n");
610 identity_op = GNUNET_IDENTITY_get (identity_handle,
611 "gns-intercept",
612 &identity_intercept_cb,
613 (void *) c);
614 }
615 GNS_resolver_init (namecache_handle, 553 GNS_resolver_init (namecache_handle,
616 dht_handle, 554 dht_handle,
617 c, 555 c,
618 max_parallel_bg_queries); 556 max_parallel_bg_queries);
619 statistics = GNUNET_STATISTICS_create ("gns", c); 557 if ( (GNUNET_YES ==
558 GNUNET_CONFIGURATION_get_value_yesno (c,
559 "gns",
560 "INTERCEPT_DNS")) &&
561 (GNUNET_SYSERR ==
562 GNS_interceptor_init (c)) )
563 {
564 GNUNET_break (0);
565 GNUNET_SCHEDULER_add_now (&shutdown_task,
566 NULL);
567 return;
568 }
569 statistics = GNUNET_STATISTICS_create ("gns",
570 c);
620 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 571 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
621 NULL); 572 NULL);
622} 573}