diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-02-25 23:21:34 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-02-25 23:21:34 +0100 |
commit | 56a9d4001b0844287ecc55b103549370676646a8 (patch) | |
tree | 15c386888d44654aee00e2bc14b8e6fda63407c6 | |
parent | ab31df30ad892ea81bf8ccea19f97bf2cbed5899 (diff) | |
download | gnunet-56a9d4001b0844287ecc55b103549370676646a8.tar.gz gnunet-56a9d4001b0844287ecc55b103549370676646a8.zip |
first preparations for GNS mapping arbitrary TLDs
-rw-r--r-- | contrib/gns-bcd.tex | 1 | ||||
-rw-r--r-- | src/exit/gnunet-daemon-exit.c | 4 | ||||
-rw-r--r-- | src/gns/Makefile.am | 2 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns.c | 133 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_interceptor.c | 4 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 7 |
6 files changed, 142 insertions, 9 deletions
diff --git a/contrib/gns-bcd.tex b/contrib/gns-bcd.tex index 5e33ffbc7..73a302985 100644 --- a/contrib/gns-bcd.tex +++ b/contrib/gns-bcd.tex | |||
@@ -18809,4 +18809,3 @@ | |||
18809 | % \card{english} | 18809 | % \card{english} |
18810 | % \end{center} | 18810 | % \end{center} |
18811 | %\end{figure} | 18811 | %\end{figure} |
18812 | |||
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c index d9a5dd684..c624e083e 100644 --- a/src/exit/gnunet-daemon-exit.c +++ b/src/exit/gnunet-daemon-exit.c | |||
@@ -3373,10 +3373,10 @@ add_services (int proto, | |||
3373 | 3373 | ||
3374 | 3374 | ||
3375 | /** | 3375 | /** |
3376 | * Reads the configuration servicecfg and populates udp_services | 3376 | * Reads the configuration and populates #udp_services and #tcp_services |
3377 | * | 3377 | * |
3378 | * @param cls unused | 3378 | * @param cls unused |
3379 | * @param section name of section in config, equal to hostname | 3379 | * @param section name of section in config |
3380 | */ | 3380 | */ |
3381 | static void | 3381 | static void |
3382 | read_service_conf (void *cls, | 3382 | read_service_conf (void *cls, |
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 977eb87e3..e89192414 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -185,7 +185,7 @@ w32nsp_resolve_SOURCES = \ | |||
185 | w32nsp_resolve_LDADD = -lws2_32 | 185 | w32nsp_resolve_LDADD = -lws2_32 |
186 | 186 | ||
187 | gnunet_service_gns_SOURCES = \ | 187 | gnunet_service_gns_SOURCES = \ |
188 | gnunet-service-gns.c \ | 188 | gnunet-service-gns.c gnunet-service-gns.h \ |
189 | gnunet-service-gns_resolver.c gnunet-service-gns_resolver.h \ | 189 | gnunet-service-gns_resolver.c gnunet-service-gns_resolver.h \ |
190 | gnunet-service-gns_interceptor.c gnunet-service-gns_interceptor.h | 190 | gnunet-service-gns_interceptor.c gnunet-service-gns_interceptor.h |
191 | gnunet_service_gns_LDADD = \ | 191 | gnunet_service_gns_LDADD = \ |
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 | */ | ||
107 | struct 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 | */ |
106 | static struct GNUNET_DHT_Handle *dht_handle; | 138 | static struct GNUNET_DHT_Handle *dht_handle; |
@@ -136,6 +168,50 @@ static int v4_enabled; | |||
136 | */ | 168 | */ |
137 | static struct GNUNET_STATISTICS_Handle *statistics; | 169 | static struct GNUNET_STATISTICS_Handle *statistics; |
138 | 170 | ||
171 | /** | ||
172 | * Head of DLL of TLDs we map to GNS zones. | ||
173 | */ | ||
174 | static struct GNS_TopLevelDomain *tld_head; | ||
175 | |||
176 | /** | ||
177 | * Tail of DLL of TLDs we map to GNS zones. | ||
178 | */ | ||
179 | static 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 | */ | ||
189 | int | ||
190 | GNS_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; | |||
146 | static void | 222 | static void |
147 | shutdown_task (void *cls) | 223 | shutdown_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 | */ | ||
515 | static void | ||
516 | read_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 | ||
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c index a9e207891..71aa08dc5 100644 --- a/src/gns/gnunet-service-gns_interceptor.c +++ b/src/gns/gnunet-service-gns_interceptor.c | |||
@@ -327,7 +327,9 @@ handle_dns_request (void *cls, | |||
327 | { | 327 | { |
328 | /* Start resolution in GNS */ | 328 | /* Start resolution in GNS */ |
329 | ilh = GNUNET_new (struct InterceptLookupHandle); | 329 | ilh = GNUNET_new (struct InterceptLookupHandle); |
330 | GNUNET_CONTAINER_DLL_insert (ilh_head, ilh_tail, ilh); | 330 | GNUNET_CONTAINER_DLL_insert (ilh_head, |
331 | ilh_tail, | ||
332 | ilh); | ||
331 | ilh->packet = p; | 333 | ilh->packet = p; |
332 | ilh->request_handle = rh; | 334 | ilh->request_handle = rh; |
333 | ilh->lookup = GNS_resolver_lookup (&zone, | 335 | ilh->lookup = GNS_resolver_lookup (&zone, |
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 5bf443267..533c0cada 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -2252,7 +2252,7 @@ recursive_resolution (void *cls) | |||
2252 | * Begin the resolution process from 'name', starting with | 2252 | * Begin the resolution process from 'name', starting with |
2253 | * the identification of the zone specified by 'name'. | 2253 | * the identification of the zone specified by 'name'. |
2254 | * | 2254 | * |
2255 | * @param cls the `struct GNS_ResolverHandle` | 2255 | * @param cls the `struct GNS_ResolverHandle` |
2256 | */ | 2256 | */ |
2257 | static void | 2257 | static void |
2258 | start_resolver_lookup (void *cls) | 2258 | start_resolver_lookup (void *cls) |
@@ -2595,10 +2595,11 @@ GNS_resolver_done () | |||
2595 | * | 2595 | * |
2596 | * @param name the name to check | 2596 | * @param name the name to check |
2597 | * @param tld the TLD to check for | 2597 | * @param tld the TLD to check for |
2598 | * @return GNUNET_YES or GNUNET_NO | 2598 | * @return #GNUNET_YES or #GNUNET_NO |
2599 | */ | 2599 | */ |
2600 | int | 2600 | int |
2601 | is_tld (const char* name, const char* tld) | 2601 | is_tld (const char* name, |
2602 | const char* tld) | ||
2602 | { | 2603 | { |
2603 | size_t offset = 0; | 2604 | size_t offset = 0; |
2604 | 2605 | ||