aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-02-25 23:21:34 +0100
committerChristian Grothoff <christian@grothoff.org>2018-02-25 23:21:34 +0100
commit56a9d4001b0844287ecc55b103549370676646a8 (patch)
tree15c386888d44654aee00e2bc14b8e6fda63407c6 /src/gns/gnunet-service-gns.c
parentab31df30ad892ea81bf8ccea19f97bf2cbed5899 (diff)
downloadgnunet-56a9d4001b0844287ecc55b103549370676646a8.tar.gz
gnunet-56a9d4001b0844287ecc55b103549370676646a8.zip
first preparations for GNS mapping arbitrary TLDs
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r--src/gns/gnunet-service-gns.c133
1 files changed, 132 insertions, 1 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 0ca25ac19..e13beb889 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -101,6 +101,38 @@ struct GnsClient
101 101
102 102
103/** 103/**
104 * Representation of a TLD, mapping the respective TLD string
105 * (i.e. ".gnu") to the respective public key of the zone.
106 */
107struct GNS_TopLevelDomain
108{
109
110 /**
111 * Kept in a DLL, as there are unlikely enough of these to
112 * warrant a hash map.
113 */
114 struct GNS_TopLevelDomain *next;
115
116 /**
117 * Kept in a DLL, as there are unlikely enough of these to
118 * warrant a hash map.
119 */
120 struct GNS_TopLevelDomain *prev;
121
122 /**
123 * Public key associated with the @a tld.
124 */
125 struct GNUNET_CRYPTO_EddsaPublicKey pkey;
126
127 /**
128 * Top-level domain as a string, including leading ".".
129 */
130 char *tld;
131
132};
133
134
135/**
104 * Our handle to the DHT 136 * Our handle to the DHT
105 */ 137 */
106static struct GNUNET_DHT_Handle *dht_handle; 138static struct GNUNET_DHT_Handle *dht_handle;
@@ -136,6 +168,50 @@ static int v4_enabled;
136 */ 168 */
137static struct GNUNET_STATISTICS_Handle *statistics; 169static struct GNUNET_STATISTICS_Handle *statistics;
138 170
171/**
172 * Head of DLL of TLDs we map to GNS zones.
173 */
174static struct GNS_TopLevelDomain *tld_head;
175
176/**
177 * Tail of DLL of TLDs we map to GNS zones.
178 */
179static struct GNS_TopLevelDomain *tld_tail;
180
181
182/**
183 * Find GNS zone belonging to TLD @a tld.
184 *
185 * @param tld_str top-level domain to look up
186 * @param[out] pkey public key to set
187 * @return #GNUNET_YES if @a tld was found #GNUNET_NO if not
188 */
189int
190GNS_find_tld (const char *tld_str,
191 struct GNUNET_CRYPTO_EddsaPublicKey *pkey)
192{
193 if ('\0' == *tld_str)
194 return GNUNET_NO;
195 for (struct GNS_TopLevelDomain *tld = tld_head;
196 NULL != tld;
197 tld = tld->next)
198 {
199 if (0 == strcasecmp (tld_str,
200 tld->tld))
201 {
202 *pkey = tld->pkey;
203 return GNUNET_YES;
204 }
205 }
206 if (GNUNET_OK ==
207 GNUNET_STRINGS_string_to_data (tld_str + 1,
208 strlen (tld_str + 1),
209 pkey,
210 sizeof (*pkey)))
211 return GNUNET_YES; /* TLD string *was* the public key */
212 return GNUNET_NO;
213}
214
139 215
140/** 216/**
141 * Task run during shutdown. 217 * Task run during shutdown.
@@ -146,6 +222,7 @@ static struct GNUNET_STATISTICS_Handle *statistics;
146static void 222static void
147shutdown_task (void *cls) 223shutdown_task (void *cls)
148{ 224{
225 struct GNS_TopLevelDomain *tld;
149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
150 "Shutting down!\n"); 227 "Shutting down!\n");
151 GNS_interceptor_done (); 228 GNS_interceptor_done ();
@@ -176,6 +253,14 @@ shutdown_task (void *cls)
176 GNUNET_DHT_disconnect (dht_handle); 253 GNUNET_DHT_disconnect (dht_handle);
177 dht_handle = NULL; 254 dht_handle = NULL;
178 } 255 }
256 while (NULL != (tld = tld_head))
257 {
258 GNUNET_CONTAINER_DLL_remove (tld_head,
259 tld_tail,
260 tld);
261 GNUNET_free (tld->tld);
262 GNUNET_free (tld);
263 }
179} 264}
180 265
181 266
@@ -420,6 +505,47 @@ identity_intercept_cb (void *cls,
420 505
421 506
422/** 507/**
508 * Reads the configuration and populates TLDs
509 *
510 * @param cls unused
511 * @param section name of section in config, always "gns"
512 * @param option name of the option, TLDs start with "."
513 * @param value value for the option, public key for TLDs
514 */
515static void
516read_service_conf (void *cls,
517 const char *section,
518 const char *option,
519 const char *value)
520{
521 struct GNUNET_CRYPTO_EddsaPublicKey pk;
522 struct GNS_TopLevelDomain *tld;
523
524 if (option[0] != '.')
525 return;
526 if (GNUNET_OK !=
527 GNUNET_STRINGS_string_to_data (value,
528 strlen (value),
529 &pk,
530 sizeof (pk)))
531 {
532 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
533 section,
534 option,
535 _("Properly base32-encoded public key required"));
536 return;
537 }
538 tld = GNUNET_new (struct GNS_TopLevelDomain);
539 tld->tld = GNUNET_strdup (option);
540 tld->pkey = pk;
541 GNUNET_CONTAINER_DLL_insert (tld_head,
542 tld_tail,
543 tld);
544}
545
546
547
548/**
423 * Process GNS requests. 549 * Process GNS requests.
424 * 550 *
425 * @param cls closure 551 * @param cls closure
@@ -433,6 +559,10 @@ run (void *cls,
433{ 559{
434 unsigned long long max_parallel_bg_queries = 16; 560 unsigned long long max_parallel_bg_queries = 16;
435 561
562 GNUNET_CONFIGURATION_iterate_section_values (c,
563 "gns",
564 &read_service_conf,
565 NULL);
436 v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6); 566 v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6);
437 v4_enabled = GNUNET_NETWORK_test_pf (PF_INET); 567 v4_enabled = GNUNET_NETWORK_test_pf (PF_INET);
438 namecache_handle = GNUNET_NAMECACHE_connect (c); 568 namecache_handle = GNUNET_NAMECACHE_connect (c);
@@ -459,7 +589,8 @@ run (void *cls,
459 { 589 {
460 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 590 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
461 _("Could not connect to DHT!\n")); 591 _("Could not connect to DHT!\n"));
462 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 592 GNUNET_SCHEDULER_add_now (&shutdown_task,
593 NULL);
463 return; 594 return;
464 } 595 }
465 596