aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-22 21:42:42 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-22 21:42:42 +0100
commit945443b67fe95893ceb711e1bcd7049477f3cba7 (patch)
treef9f0c9fd3f1483facaa4e50dbbccd68520137f91 /src/gns
parentcd9531932c72478a3f7c17eb78238daa2302b2ef (diff)
downloadgnunet-945443b67fe95893ceb711e1bcd7049477f3cba7.tar.gz
gnunet-945443b67fe95893ceb711e1bcd7049477f3cba7.zip
remove dead code and dead linker dependencies
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/Makefile.am3
-rw-r--r--src/gns/gnunet-service-gns.c23
-rw-r--r--src/gns/gnunet-service-gns_resolver.c2
-rw-r--r--src/gns/gnunet-service-gns_reverser.c601
-rw-r--r--src/gns/gnunet-service-gns_reverser.h91
-rw-r--r--src/gns/gnunet-service-gns_shorten.c466
-rw-r--r--src/gns/gnunet-service-gns_shorten.h70
7 files changed, 1 insertions, 1255 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 3afad8ea7..8c952be04 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -113,7 +113,6 @@ gnunet_gns_SOURCES = \
113gnunet_gns_LDADD = \ 113gnunet_gns_LDADD = \
114 libgnunetgns.la \ 114 libgnunetgns.la \
115 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 115 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
116 $(top_builddir)/src/namestore/libgnunetnamestore.la \
117 $(top_builddir)/src/identity/libgnunetidentity.la \ 116 $(top_builddir)/src/identity/libgnunetidentity.la \
118 $(top_builddir)/src/util/libgnunetutil.la \ 117 $(top_builddir)/src/util/libgnunetutil.la \
119 $(GN_LIBINTL) 118 $(GN_LIBINTL)
@@ -133,7 +132,6 @@ gnunet_dns2gns_LDADD = \
133 libgnunetgns.la \ 132 libgnunetgns.la \
134 $(top_builddir)/src/util/libgnunetutil.la \ 133 $(top_builddir)/src/util/libgnunetutil.la \
135 $(top_builddir)/src/identity/libgnunetidentity.la \ 134 $(top_builddir)/src/identity/libgnunetidentity.la \
136 $(top_builddir)/src/namestore/libgnunetnamestore.la \
137 $(top_builddir)/src/dns/libgnunetdnsparser.la \ 135 $(top_builddir)/src/dns/libgnunetdnsparser.la \
138 $(top_builddir)/src/dns/libgnunetdnsstub.la \ 136 $(top_builddir)/src/dns/libgnunetdnsstub.la \
139 $(GN_LIBINTL) 137 $(GN_LIBINTL)
@@ -197,7 +195,6 @@ gnunet_service_gns_LDADD = \
197 $(top_builddir)/src/dht/libgnunetdht.la \ 195 $(top_builddir)/src/dht/libgnunetdht.la \
198 $(top_builddir)/src/tun/libgnunettun.la \ 196 $(top_builddir)/src/tun/libgnunettun.la \
199 $(top_builddir)/src/namecache/libgnunetnamecache.la \ 197 $(top_builddir)/src/namecache/libgnunetnamecache.la \
200 $(top_builddir)/src/namestore/libgnunetnamestore.la \
201 $(USE_VPN) \ 198 $(USE_VPN) \
202 $(GN_LIBINTL) 199 $(GN_LIBINTL)
203 200
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 1e8d07bc5..570c07fdf 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -29,14 +29,11 @@
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_namestore_service.h"
33#include "gnunet_identity_service.h" 32#include "gnunet_identity_service.h"
34#include "gnunet_gns_service.h" 33#include "gnunet_gns_service.h"
35#include "gnunet_statistics_service.h" 34#include "gnunet_statistics_service.h"
36#include "gns.h" 35#include "gns.h"
37#include "gnunet-service-gns_resolver.h" 36#include "gnunet-service-gns_resolver.h"
38#include "gnunet-service-gns_reverser.h"
39#include "gnunet-service-gns_shorten.h"
40#include "gnunet-service-gns_interceptor.h" 37#include "gnunet-service-gns_interceptor.h"
41#include "gnunet_protocols.h" 38#include "gnunet_protocols.h"
42 39
@@ -114,11 +111,6 @@ static struct GNUNET_DHT_Handle *dht_handle;
114static struct GNUNET_NAMECACHE_Handle *namecache_handle; 111static struct GNUNET_NAMECACHE_Handle *namecache_handle;
115 112
116/** 113/**
117 * Our handle to the namestore service
118 */
119static struct GNUNET_NAMESTORE_Handle *namestore_handle;
120
121/**
122 * Our handle to the identity service 114 * Our handle to the identity service
123 */ 115 */
124static struct GNUNET_IDENTITY_Handle *identity_handle; 116static struct GNUNET_IDENTITY_Handle *identity_handle;
@@ -174,11 +166,6 @@ shutdown_task (void *cls)
174 GNUNET_NO); 166 GNUNET_NO);
175 statistics = NULL; 167 statistics = NULL;
176 } 168 }
177 if (NULL != namestore_handle)
178 {
179 GNUNET_NAMESTORE_disconnect (namestore_handle);
180 namestore_handle = NULL;
181 }
182 if (NULL != namecache_handle) 169 if (NULL != namecache_handle)
183 { 170 {
184 GNUNET_NAMECACHE_disconnect (namecache_handle); 171 GNUNET_NAMECACHE_disconnect (namecache_handle);
@@ -447,15 +434,7 @@ run (void *cls,
447 434
448 v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6); 435 v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6);
449 v4_enabled = GNUNET_NETWORK_test_pf (PF_INET); 436 v4_enabled = GNUNET_NETWORK_test_pf (PF_INET);
450 namestore_handle = GNUNET_NAMESTORE_connect (c); 437 namecache_handle = GNUNET_NAMECACHE_connect (c);
451 if (NULL == namestore_handle)
452 {
453 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
454 _("Failed to connect to the namestore!\n"));
455 GNUNET_SCHEDULER_shutdown ();
456 return;
457 }
458 namecache_handle = GNUNET_NAMECACHE_connect (c);
459 if (NULL == namecache_handle) 438 if (NULL == namecache_handle)
460 { 439 {
461 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 440 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 40b340ad7..c58190599 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -30,7 +30,6 @@
30#include "gnunet_dht_service.h" 30#include "gnunet_dht_service.h"
31#include "gnunet_gnsrecord_lib.h" 31#include "gnunet_gnsrecord_lib.h"
32#include "gnunet_namecache_service.h" 32#include "gnunet_namecache_service.h"
33#include "gnunet_namestore_service.h"
34#include "gnunet_dns_service.h" 33#include "gnunet_dns_service.h"
35#include "gnunet_resolver_service.h" 34#include "gnunet_resolver_service.h"
36#include "gnunet_revocation_service.h" 35#include "gnunet_revocation_service.h"
@@ -39,7 +38,6 @@
39#include "gnunet_gns_service.h" 38#include "gnunet_gns_service.h"
40#include "gns.h" 39#include "gns.h"
41#include "gnunet-service-gns_resolver.h" 40#include "gnunet-service-gns_resolver.h"
42#include "gnunet-service-gns_shorten.h"
43#include "gnunet_vpn_service.h" 41#include "gnunet_vpn_service.h"
44 42
45 43
diff --git a/src/gns/gnunet-service-gns_reverser.c b/src/gns/gnunet-service-gns_reverser.c
deleted file mode 100644
index b5b8b31b7..000000000
--- a/src/gns/gnunet-service-gns_reverser.c
+++ /dev/null
@@ -1,601 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2013 GNUnet e.V.
4
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.
9
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.
14
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file gns/gnunet-service-gns_reverser.c
22 * @brief GNUnet GNS service
23 * @author Martin Schanzenbach
24 */
25
26
27#include "platform.h"
28#include "gnunet_gns_service.h"
29#include "gnunet-service-gns_resolver.h"
30#include "gnunet-service-gns_reverser.h"
31
32struct ReverseRecordEntry
33{
34 /**
35 * DLL
36 */
37 struct ReverseRecordEntry *next;
38
39 /**
40 * DLL
41 */
42 struct ReverseRecordEntry *prev;
43
44 /**
45 * ReverseRecord
46 */
47 struct GNUNET_GNSRECORD_ReverseRecord *record;
48
49 /**
50 * Record length
51 */
52 size_t record_len;
53
54};
55
56struct IteratorHandle
57{
58 /**
59 * Records found
60 */
61 struct ReverseRecordEntry *records_head;
62
63 /**
64 * Records found
65 */
66 struct ReverseRecordEntry *records_tail;
67
68 /**
69 * Record count
70 */
71 uint64_t record_count;
72
73 /**
74 * Current delegation to expect
75 */
76 struct GNUNET_CRYPTO_EcdsaPublicKey target;
77
78 /**
79 * Queue entry
80 */
81 struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
82
83};
84
85struct ReverseTreeNode
86{
87 /**
88 * DLL
89 */
90 struct ReverseTreeNode *next;
91
92 /**
93 * DLL
94 */
95 struct ReverseTreeNode *prev;
96
97 /**
98 * Resolved name until now
99 */
100 char *name;
101
102 /**
103 * Depth of the resolution at this node
104 */
105 uint8_t depth;
106
107 /**
108 * The pkey of the namespace
109 */
110 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
111
112};
113
114
115struct GNS_ReverserHandle
116{
117 /**
118 * GNS resolver handle
119 */
120 struct GNS_ResolverHandle *rh;
121
122 /**
123 * The authority to look for
124 */
125 struct GNUNET_CRYPTO_EcdsaPublicKey authority;
126
127 /**
128 * Resolution candidate queue
129 */
130 struct ReverseTreeNode *node_queue_head;
131
132 /**
133 * Resolution candidate queue
134 */
135 struct ReverseTreeNode *node_queue_tail;
136
137 /**
138 * Max depth for the resolution
139 */
140 uint8_t max_depth;
141
142 /**
143 * Result callback
144 */
145 GNS_ReverseResultProcessor proc;
146
147 /**
148 * Callback closure
149 */
150 void *proc_cls;
151};
152
153/**
154 * Reverse record collection task
155 */
156static struct GNUNET_SCHEDULER_Task *reverse_record_check_task;
157
158/**
159 * NS iterator task
160 */
161static struct GNUNET_SCHEDULER_Task *it_task;
162
163/**
164 * GNS lookup handle
165 */
166static struct GNS_ResolverHandle *gns_lookup_reverse;
167
168/**
169 * NS handle
170 */
171static struct GNUNET_NAMESTORE_Handle *ns;
172
173/**
174 * NS Iterator
175 */
176static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
177
178/**
179 * The zone target for reverse record resolution
180 */
181static struct GNUNET_CRYPTO_EcdsaPublicKey myzone;
182
183/**
184 * The zone target for reverse record resolution
185 */
186static struct GNUNET_CRYPTO_EcdsaPrivateKey pzone;
187
188/**
189 * The nick of our zone
190 */
191static char *mynick;
192
193
194static void
195cleanup_handle (struct GNS_ReverserHandle *rh)
196{
197 struct ReverseTreeNode *rtn;
198
199 for (rtn = rh->node_queue_head; NULL != rtn; rtn = rh->node_queue_head)
200 {
201 if (NULL != rtn->name)
202 GNUNET_free (rtn->name);
203 GNUNET_CONTAINER_DLL_remove (rh->node_queue_head,
204 rh->node_queue_tail,
205 rtn);
206 GNUNET_free (rtn);
207 }
208 GNUNET_free (rh);
209}
210
211static void
212handle_gns_result (void *cls,
213 uint32_t rd_count,
214 const struct GNUNET_GNSRECORD_Data *rd)
215{
216 struct GNS_ReverserHandle *rh = cls;
217 const struct GNUNET_GNSRECORD_ReverseRecord *rr;
218 struct ReverseTreeNode *rtn;
219 char *result;
220 const char *name;
221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222 "Got result (%d)\n", rd_count);
223
224 for (int i = 0; i < rd_count; i++)
225 {
226 /**
227 * Check if we are in the delegation set
228 */
229 if (GNUNET_GNSRECORD_TYPE_REVERSE != rd[i].record_type)
230 continue;
231 rr = rd[i].data;
232 name = (const char*) &rr[1];
233 if (0 == memcmp (&rh->authority,
234 &rr->pkey,
235 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
236 {
237 //Found!
238 GNUNET_asprintf (&result,
239 "%s.%s.gnu",
240 rh->node_queue_head->name,
241 name);
242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
243 "Found path from %s\n", result);
244
245 rh->proc (rh->proc_cls, result);
246 cleanup_handle (rh);
247 GNUNET_free (result);
248 return;
249 } else {
250 if (rh->node_queue_head->depth >= rh->max_depth)
251 break;
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 "Found REVERSE from %s\n", name);
254
255 rtn = GNUNET_new (struct ReverseTreeNode);
256 if (NULL == rh->node_queue_head->name)
257 rtn->name = GNUNET_strdup (name);
258 else
259 GNUNET_asprintf (&rtn->name,
260 "%s.%s",
261 rh->node_queue_head->name,
262 name);
263 rtn->depth = rh->node_queue_head->depth + 1;
264 rtn->pkey = rr->pkey;
265 GNUNET_CONTAINER_DLL_insert_tail (rh->node_queue_head,
266 rh->node_queue_tail,
267 rtn);
268 }
269 }
270
271 /**
272 * Done here remove node from queue
273 */
274 rtn = rh->node_queue_head;
275 if (NULL != rtn)
276 GNUNET_CONTAINER_DLL_remove (rh->node_queue_head,
277 rh->node_queue_tail,
278 rtn);
279 if (NULL == rh->node_queue_head)
280 {
281 //No luck
282 rh->proc (rh->proc_cls, NULL);
283 cleanup_handle (rh);
284 return;
285 }
286 rh->rh = GNS_resolver_lookup (&rh->node_queue_head->pkey,
287 GNUNET_GNSRECORD_TYPE_REVERSE,
288 "+.gnu",
289 NULL,
290 GNUNET_GNS_LO_DEFAULT,
291 &handle_gns_result,
292 rh);
293}
294
295/**
296 * Reverse lookup of a specific zone
297 * calls RecordLookupProcessor on result or timeout
298 *
299 * @param target the zone to perform the lookup in
300 * @param authority the authority
301 * @param proc the processor to call
302 * @param proc_cls the closure to pass to @a proc
303 * @return handle to cancel operation
304 */
305struct GNS_ReverserHandle *
306GNS_reverse_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *target,
307 const struct GNUNET_CRYPTO_EcdsaPublicKey *authority,
308 GNS_ReverseResultProcessor proc,
309 void *proc_cls)
310{
311 struct GNS_ReverserHandle *rh;
312 struct ReverseTreeNode *rtn;
313
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
315 "Starting reverse resolution\n");
316 rh = GNUNET_new (struct GNS_ReverserHandle);
317 rh->proc = proc;
318 rh->proc_cls = proc_cls;
319 rtn = GNUNET_new (struct ReverseTreeNode);
320 rtn->name = NULL;
321 rtn->pkey = *target;
322 rtn->depth = 0;
323 GNUNET_CONTAINER_DLL_insert (rh->node_queue_head,
324 rh->node_queue_tail,
325 rtn);
326 rh->authority = *authority;
327 rh->max_depth = 3; //TODO make argument
328 rh->rh = GNS_resolver_lookup (target,
329 GNUNET_GNSRECORD_TYPE_REVERSE,
330 "+.gnu",
331 NULL,
332 GNUNET_GNS_LO_DEFAULT,
333 &handle_gns_result,
334 rh);
335 return rh;
336}
337
338/**
339 * Cancel active resolution (i.e. client disconnected).
340 *
341 * @param rh resolution to abort
342 */
343void
344GNS_reverse_lookup_cancel (struct GNS_ReverserHandle *rh)
345{
346 cleanup_handle (rh);
347 return;
348}
349
350/********************************************
351 * Reverse iterator
352 * ******************************************/
353
354
355static void
356next_it (void *cls);
357
358static void
359handle_gns_result_iter (void *cls,
360 uint32_t rd_count,
361 const struct GNUNET_GNSRECORD_Data *rd)
362{
363 struct IteratorHandle *ith = cls;
364 struct ReverseRecordEntry *rr;
365 gns_lookup_reverse = NULL;
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
367 "GNS for REVERSE (%s)\n", mynick);
368
369
370 if ((rd_count != 1) ||
371 (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type))
372 {
373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
374 "GNS invalid REVERSE (%s)\n", mynick);
375 gns_lookup_reverse = NULL;
376 it_task = GNUNET_SCHEDULER_add_now (&next_it, ith);
377 return;
378 }
379
380
381 rr = GNUNET_new (struct ReverseRecordEntry);
382 rr->record_len = sizeof (struct GNUNET_GNSRECORD_ReverseRecord)
383 + strlen (mynick) + 1;
384 rr->record = GNUNET_malloc (rr->record_len);
385 rr->record->pkey = ith->target;
386 rr->record->expiration.abs_value_us = rd->expiration_time;
387 GNUNET_memcpy ((char*)&rr->record[1],
388 mynick,
389 strlen (mynick));
390 GNUNET_CONTAINER_DLL_insert (ith->records_head,
391 ith->records_tail,
392 rr);
393 ith->record_count++;
394 it_task = GNUNET_SCHEDULER_add_now (&next_it, ith);
395}
396
397
398static void
399next_it (void *cls)
400{
401 it_task = NULL;
402 GNUNET_assert (NULL != namestore_iter);
403 GNUNET_NAMESTORE_zone_iterator_next (namestore_iter);
404}
405
406
407static void
408iterator_cb (void *cls,
409 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
410 const char *label,
411 unsigned int rd_count,
412 const struct GNUNET_GNSRECORD_Data *rd)
413{
414 struct IteratorHandle *ith = cls;
415 struct GNUNET_CRYPTO_EcdsaPublicKey zone;
416 char *name;
417
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
419 "iterating for REVERSE (%s / %s)\n",
420 label,
421 mynick);
422
423
424 if ((rd_count != 1) ||
425 (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type))
426 {
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
428 "wrong format (%s)\n", mynick);
429
430
431 it_task = GNUNET_SCHEDULER_add_now (&next_it, ith);
432 return;
433 }
434 GNUNET_CRYPTO_ecdsa_key_get_public (key,
435 &zone);
436 if (0 != memcmp (&zone, &myzone,
437 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
438 {
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "wrong zone (%s)\n", mynick);
441
442
443 it_task = GNUNET_SCHEDULER_add_now (&next_it, ith);
444 return;
445 }
446 ith->target = *((struct GNUNET_CRYPTO_EcdsaPublicKey *) rd->data);
447 GNUNET_asprintf (&name,
448 "%s.gnu",
449 mynick);
450 gns_lookup_reverse = GNS_resolver_lookup (&ith->target,
451 GNUNET_GNSRECORD_TYPE_PKEY,
452 name,
453 NULL,
454 GNUNET_GNS_LO_DEFAULT,
455 &handle_gns_result_iter,
456 ith);
457 GNUNET_free (name);
458}
459
460static void check_reverse_records (void *cls);
461
462static void
463store_reverse (void *cls,
464 int32_t success,
465 const char *emsg)
466{
467 struct IteratorHandle *ith = cls;
468 struct ReverseRecordEntry *rr;
469
470 if (GNUNET_SYSERR == success)
471 {
472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
473 "%s\n",
474 emsg);
475 }
476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stored records (%s)\n", mynick);
477
478 for (rr = ith->records_head; NULL != rr; rr = ith->records_head)
479 {
480 GNUNET_CONTAINER_DLL_remove (ith->records_head,
481 ith->records_tail,
482 rr);
483 GNUNET_free (rr->record);
484 GNUNET_free (rr);
485 }
486 reverse_record_check_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_DAYS,
487 &check_reverse_records,
488 NULL);
489 GNUNET_free (ith);
490}
491
492
493static void
494finished_cb (void *cls)
495{
496 struct IteratorHandle *ith = cls;
497 struct ReverseRecordEntry *rr;
498 struct GNUNET_GNSRECORD_Data rd[ith->record_count];
499
500 memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * ith->record_count);
501
502 rr = ith->records_head;
503 for (int i = 0; i < ith->record_count; i++)
504 {
505 rd[i].data_size = rr->record_len;
506 rd[i].data = GNUNET_malloc (rr->record_len);
507 rd[i].record_type = GNUNET_GNSRECORD_TYPE_REVERSE;
508 rd[i].expiration_time = rr->record->expiration.abs_value_us;
509 GNUNET_memcpy ((char*) rd[i].data,
510 rr->record,
511 rr->record_len);
512 rr = rr->next;
513 }
514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
515 "Finished iterating for REVERSE\n");
516
517 ith->ns_qe = GNUNET_NAMESTORE_records_store (ns,
518 &pzone,
519 "+",
520 ith->record_count,
521 rd,
522 &store_reverse,
523 ith);
524 namestore_iter = NULL;
525
526}
527
528
529static void
530it_error (void *cls)
531{
532 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
533 "Error iterating for REVERSE\n");
534}
535
536
537static void
538check_reverse_records (void *cls)
539{
540 struct IteratorHandle *ith;
541 ith = GNUNET_new (struct IteratorHandle);
542 ith->record_count = 0;
543 reverse_record_check_task = NULL;
544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
545 "Start iterating for REVERSE (%s)\n", mynick);
546 namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (ns,
547 NULL,
548 &it_error,
549 ith,
550 &iterator_cb,
551 ith,
552 &finished_cb,
553 ith);
554}
555
556
557/**
558 * Initialize reverser
559 *
560 * @param nh handle to a namestore
561 * @param key the private key of the gns-reverse zone
562 * @param name the name of the gns-reverse zone
563 * @return GNUNET_OK
564 */
565int
566GNS_reverse_init (struct GNUNET_NAMESTORE_Handle *nh,
567 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
568 const char *nick)
569{
570 GNUNET_asprintf (&mynick,
571 "%s",
572 nick);
573 GNUNET_CRYPTO_ecdsa_key_get_public (zone,
574 &myzone);
575 GNUNET_memcpy (&pzone,
576 zone,
577 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
578 ns = nh;
579 reverse_record_check_task = GNUNET_SCHEDULER_add_now (&check_reverse_records,
580 NULL);
581 return GNUNET_OK;
582}
583
584/**
585 * Cleanup reverser
586 */
587void
588GNS_reverse_done ()
589{
590 if (NULL != mynick)
591 GNUNET_free (mynick);
592 if (NULL != it_task)
593 GNUNET_SCHEDULER_cancel (it_task);
594 if (NULL != reverse_record_check_task)
595 GNUNET_SCHEDULER_cancel (reverse_record_check_task);
596 if (NULL != gns_lookup_reverse)
597 GNS_resolver_lookup_cancel (gns_lookup_reverse);
598 if (NULL != namestore_iter)
599 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
600}
601
diff --git a/src/gns/gnunet-service-gns_reverser.h b/src/gns/gnunet-service-gns_reverser.h
deleted file mode 100644
index fc9680a29..000000000
--- a/src/gns/gnunet-service-gns_reverser.h
+++ /dev/null
@@ -1,91 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2013 GNUnet e.V.
4
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.
9
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.
14
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file gns/gnunet-service-gns_reverser.h
22 * @brief GNUnet GNS service
23 * @author Martin Schanzenbach
24 */
25#ifndef GNS_REVERSER_H
26#define GNS_REVERSER_H
27#include "gns.h"
28#include "gnunet_gns_service.h"
29
30/**
31 * Handle for an active request.
32 */
33struct GNS_ReverserHandle;
34
35
36/**
37 * Function called with results for a GNS resolution.
38 *
39 * @param cls closure
40 * @param rd_count number of records in @a rd
41 * @param rd records returned for the lookup
42 */
43typedef void (*GNS_ReverseResultProcessor)(void *cls,
44 const char *name);
45
46
47/**
48 * Reverse lookup of a specific zone
49 * calls RecordLookupProcessor on result or timeout
50 *
51 * @param target the zone to perform the lookup in
52 * @param authority the authority
53 * @param proc the processor to call
54 * @param proc_cls the closure to pass to @a proc
55 * @return handle to cancel operation
56 */
57struct GNS_ReverserHandle *
58GNS_reverse_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *target,
59 const struct GNUNET_CRYPTO_EcdsaPublicKey *authority,
60 GNS_ReverseResultProcessor proc,
61 void *proc_cls);
62
63
64/**
65 * Cancel active resolution (i.e. client disconnected).
66 *
67 * @param rh resolution to abort
68 */
69void
70GNS_reverse_lookup_cancel (struct GNS_ReverserHandle *rh);
71
72/**
73 * Initialize reverser
74 *
75 * @param nh handle to a namestore
76 * @param key the private key of the gns-reverse zone
77 * @param name the name of the gns-reverse zone
78 * @return GNUNET_OK
79 */
80int
81GNS_reverse_init (struct GNUNET_NAMESTORE_Handle *nh,
82 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
83 const char *name);
84
85/**
86 * Cleanup reverser
87 */
88void
89GNS_reverse_done ();
90
91#endif
diff --git a/src/gns/gnunet-service-gns_shorten.c b/src/gns/gnunet-service-gns_shorten.c
deleted file mode 100644
index 9aa0419aa..000000000
--- a/src/gns/gnunet-service-gns_shorten.c
+++ /dev/null
@@ -1,466 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011-2013 GNUnet e.V.
4
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.
9
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.
14
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file gns/gnunet-service-gns_shorten.c
23 * @brief GNUnet GNS shortening logic
24 * @author Martin Schanzenbach
25 * @author Christian Grothoff
26 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_dht_service.h"
30#include "gnunet_gnsrecord_lib.h"
31#include "gnunet_namestore_service.h"
32#include "gnunet_resolver_service.h"
33#include "gnunet_gns_service.h"
34#include "gns.h"
35#include "gnunet-service-gns_shorten.h"
36#include "gnunet_vpn_service.h"
37
38
39/**
40 * Default DHT timeout for lookups.
41 */
42#define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
43
44/**
45 * DHT replication level
46 */
47#define DHT_GNS_REPLICATION_LEVEL 5
48
49
50/**
51 * Handle for a PSEU lookup used to shorten names.
52 */
53struct GetPseuAuthorityHandle
54{
55 /**
56 * DLL
57 */
58 struct GetPseuAuthorityHandle *next;
59
60 /**
61 * DLL
62 */
63 struct GetPseuAuthorityHandle *prev;
64
65 /**
66 * Private key of the (shorten) zone to store the resulting
67 * pseudonym in.
68 */
69 struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_zone_key;
70
71 /**
72 * Original label (used if no PSEU record is found).
73 */
74 char label[GNUNET_DNSPARSER_MAX_LABEL_LENGTH + 1];
75
76 /**
77 * Suggested label based on NICK record
78 */
79 char * suggested_label;
80
81 /**
82 * Label we are currently trying out
83 */
84 char *current_label;
85
86 /**
87 * The zone for which we are trying to find the PSEU record.
88 */
89 struct GNUNET_CRYPTO_EcdsaPublicKey target_zone;
90
91 /**
92 * Handle for DHT lookups. Should be NULL if no lookups are in progress
93 */
94 struct GNUNET_DHT_GetHandle *get_handle;
95
96 /**
97 * Handle to namestore request
98 */
99 struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
100
101 /**
102 * Handle to namecache request
103 */
104 struct GNUNET_NAMECACHE_QueueEntry *namecache_task;
105
106 /**
107 * Task to abort DHT lookup operation.
108 */
109 struct GNUNET_SCHEDULER_Task * timeout_task;
110
111};
112
113
114/**
115 * Head of PSEU/shorten operations list.
116 */
117static struct GetPseuAuthorityHandle *gph_head;
118
119/**
120 * Tail of PSEU/shorten operations list.
121 */
122static struct GetPseuAuthorityHandle *gph_tail;
123
124/**
125 * Our handle to the namestore service
126 */
127static struct GNUNET_NAMESTORE_Handle *namestore_handle;
128
129/**
130 * Our handle to the namecache service
131 */
132static struct GNUNET_NAMECACHE_Handle *namecache_handle;
133
134/**
135 * Resolver handle to the dht
136 */
137static struct GNUNET_DHT_Handle *dht_handle;
138
139/**
140 * Cleanup a 'struct GetPseuAuthorityHandle', terminating all
141 * pending activities.
142 *
143 * @param gph handle to terminate
144 */
145static void
146free_get_pseu_authority_handle (struct GetPseuAuthorityHandle *gph)
147{
148 if (NULL != gph->get_handle)
149 {
150 GNUNET_DHT_get_stop (gph->get_handle);
151 gph->get_handle = NULL;
152 }
153 if (NULL != gph->namestore_task)
154 {
155 GNUNET_NAMESTORE_cancel (gph->namestore_task);
156 gph->namestore_task = NULL;
157 }
158 if (NULL != gph->namecache_task)
159 {
160 GNUNET_NAMECACHE_cancel (gph->namecache_task);
161 gph->namecache_task = NULL;
162 }
163 if (NULL != gph->timeout_task)
164 {
165 GNUNET_SCHEDULER_cancel (gph->timeout_task);
166 gph->timeout_task = NULL;
167 }
168 GNUNET_CONTAINER_DLL_remove (gph_head, gph_tail, gph);
169 GNUNET_free_non_null (gph->current_label);
170 GNUNET_free (gph);
171}
172
173
174/**
175 * Continuation for pkey record creation (shorten)
176 *
177 * @param cls a GetPseuAuthorityHandle
178 * @param success unused
179 * @param emsg unused
180 */
181static void
182create_pkey_cont (void* cls,
183 int32_t success,
184 const char *emsg)
185{
186 struct GetPseuAuthorityHandle* gph = cls;
187
188 gph->namestore_task = NULL;
189 free_get_pseu_authority_handle (gph);
190}
191
192
193/**
194 * Namestore calls this function if we have record for this name.
195 * (or with rd_count=0 to indicate no matches).
196 *
197 * @param cls the pending query
198 * @param rd_count the number of records with 'name'
199 * @param rd the record data
200 */
201static void
202process_pseu_lookup_ns (void *cls,
203 unsigned int rd_count,
204 const struct GNUNET_GNSRECORD_Data *rd);
205
206
207/**
208 * We obtained a result for our query to the shorten zone from
209 * the namestore. Try to decrypt.
210 *
211 * @param cls the handle to our shorten operation
212 * @param block resulting encrypted block
213 */
214static void
215process_pseu_block_ns (void *cls,
216 const struct GNUNET_GNSRECORD_Block *block)
217{
218 struct GetPseuAuthorityHandle *gph = cls;
219 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
220
221 gph->namecache_task = NULL;
222 if (NULL == block)
223 {
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
225 "Namecache did not return information for label `%s' \n",
226 gph->current_label);
227 process_pseu_lookup_ns (gph, 0, NULL);
228 return;
229 }
230 GNUNET_CRYPTO_ecdsa_key_get_public (&gph->shorten_zone_key,
231 &pub);
232 if (GNUNET_OK !=
233 GNUNET_GNSRECORD_block_decrypt (block,
234 &pub,
235 gph->current_label,
236 &process_pseu_lookup_ns,
237 gph))
238 {
239 GNUNET_break (0);
240 free_get_pseu_authority_handle (gph);
241 return;
242 }
243}
244
245
246/**
247 * Lookup in the namecache for the shorten zone the given label.
248 *
249 * @param gph the handle to our shorten operation
250 * @param label the label to lookup
251 */
252static void
253perform_nick_lookup (struct GetPseuAuthorityHandle *gph,
254 const char *label)
255{
256 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
257 struct GNUNET_HashCode query;
258
259 GNUNET_CRYPTO_ecdsa_key_get_public (&gph->shorten_zone_key,
260 &pub);
261 GNUNET_free_non_null (gph->current_label);
262 gph->current_label = GNUNET_strdup (label);
263 GNUNET_GNSRECORD_query_from_public_key (&pub,
264 label,
265 &query);
266 gph->namecache_task = GNUNET_NAMECACHE_lookup_block (namecache_handle,
267 &query,
268 &process_pseu_block_ns,
269 gph);
270}
271
272
273/**
274 * Namestore calls this function if we have record for this name.
275 * (or with rd_count=0 to indicate no matches).
276 *
277 * @param cls the pending query
278 * @param rd_count the number of records with 'name'
279 * @param rd the record data
280 */
281static void
282process_pseu_lookup_ns (void *cls,
283 unsigned int rd_count,
284 const struct GNUNET_GNSRECORD_Data *rd)
285{
286 struct GetPseuAuthorityHandle *gph = cls;
287 struct GNUNET_GNSRECORD_Data new_pkey;
288
289 gph->namestore_task = NULL;
290 if (rd_count > 0)
291 {
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "Name `%s' already taken, cannot shorten.\n",
294 gph->current_label);
295 /* if this was not yet the original label, try one more
296 time, this time not using PSEU but the original label */
297 if (0 == strcmp (gph->current_label,
298 gph->label))
299 {
300 free_get_pseu_authority_handle (gph);
301 }
302 else
303 {
304 perform_nick_lookup (gph, gph->label);
305 }
306 return;
307 }
308 /* name is available */
309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
310 "Shortening `%s' to `%s'\n",
311 GNUNET_GNSRECORD_z2s (&gph->target_zone),
312 gph->current_label);
313 new_pkey.expiration_time = UINT64_MAX;
314 new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
315 new_pkey.data = &gph->target_zone;
316 new_pkey.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
317 new_pkey.flags = GNUNET_GNSRECORD_RF_NONE
318 | GNUNET_GNSRECORD_RF_PRIVATE;
319 gph->namestore_task
320 = GNUNET_NAMESTORE_records_store (namestore_handle,
321 &gph->shorten_zone_key,
322 gph->current_label,
323 1, &new_pkey,
324 &create_pkey_cont, gph);
325}
326
327
328/**
329 * Encountered an error in zone-to-name lookup, give up on shortening.
330 */
331static void
332zone_to_name_error_cb (void *cls)
333{
334 struct GetPseuAuthorityHandle* gph = cls;
335
336 gph->namestore_task = NULL;
337 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
338 "Shortening aborted, internal error talking to namestore\n");
339 free_get_pseu_authority_handle (gph);
340}
341
342
343/**
344 * Callback called by namestore for a zone to name result. We're
345 * trying to see if a short name for a given zone already exists.
346 *
347 * @param cls the closure
348 * @param zone_key the zone we queried
349 * @param name the name found or NULL
350 * @param rd_len number of records for the name
351 * @param rd the record data (PKEY) for the name
352 */
353static void
354process_zone_to_name_discover (void *cls,
355 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
356 const char *name,
357 unsigned int rd_len,
358 const struct GNUNET_GNSRECORD_Data *rd)
359{
360 struct GetPseuAuthorityHandle* gph = cls;
361
362 gph->namestore_task = NULL;
363 if (0 != rd_len)
364 {
365 /* we found a match in our own zone */
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
367 "Shortening aborted, name `%s' already reserved for the zone\n",
368 name);
369 free_get_pseu_authority_handle (gph);
370 return;
371 }
372 else
373 {
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "Shortening continuing, no name not reserved in shorten zone\n");
376 }
377 /* record does not yet exist, check if suggested label is available */
378 perform_nick_lookup (gph, gph->suggested_label);
379}
380
381
382/**
383 * Start shortening algorithm, try to allocate a nice short
384 * canonical name for @a pub in @a shorten_zone, using
385 * @a original_label as one possible suggestion.
386 *
387 * @param original_label original label for the zone
388 * @param suggested_label suggested label for the zone
389 * @param pub public key of the zone to shorten
390 * @param shorten_zone private key of the target zone for the new record
391 */
392void
393GNS_shorten_start (const char *original_label,
394 const char *suggested_label,
395 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub,
396 const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone)
397{
398 struct GetPseuAuthorityHandle *gph;
399 struct GNUNET_CRYPTO_EcdsaPublicKey shorten_pub;
400
401 if (strlen (original_label) > GNUNET_DNSPARSER_MAX_LABEL_LENGTH)
402 {
403 GNUNET_break (0);
404 return;
405 }
406 GNUNET_CRYPTO_ecdsa_key_get_public (shorten_zone, &shorten_pub);
407 if (0 == memcmp (&shorten_pub, pub, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
408 {
409 /* Do not shorten the shorten zone */
410 return;
411 }
412
413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
414 "Starting shortening process for `%s' with old label `%s' and suggested nickname `%s'\n",
415 GNUNET_GNSRECORD_z2s (pub),
416 original_label, suggested_label);
417 gph = GNUNET_new (struct GetPseuAuthorityHandle);
418 gph->shorten_zone_key = *shorten_zone;
419 gph->target_zone = *pub;
420 gph->suggested_label = GNUNET_strdup (suggested_label);
421 strcpy (gph->label, original_label);
422 GNUNET_CONTAINER_DLL_insert (gph_head, gph_tail, gph);
423 /* first, check if we *already* have a record for this zone */
424 gph->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
425 shorten_zone,
426 pub,
427 &zone_to_name_error_cb,
428 gph,
429 &process_zone_to_name_discover,
430 gph);
431}
432
433
434/**
435 * Initialize the shortening subsystem
436 *
437 * @param nh the namestore handle
438 * @param nc the namecache handle
439 * @param dht the dht handle
440 */
441void
442GNS_shorten_init (struct GNUNET_NAMESTORE_Handle *nh,
443 struct GNUNET_NAMECACHE_Handle *nc,
444 struct GNUNET_DHT_Handle *dht)
445{
446 namestore_handle = nh;
447 namecache_handle = nc;
448 dht_handle = dht;
449}
450
451
452/**
453 * Shutdown shortening.
454 */
455void
456GNS_shorten_done ()
457{
458 /* abort active shorten operations */
459 while (NULL != gph_head)
460 free_get_pseu_authority_handle (gph_head);
461 dht_handle = NULL;
462 namestore_handle = NULL;
463 namecache_handle = NULL;
464}
465
466/* end of gnunet-service-gns_shorten.c */
diff --git a/src/gns/gnunet-service-gns_shorten.h b/src/gns/gnunet-service-gns_shorten.h
deleted file mode 100644
index d82bb52f7..000000000
--- a/src/gns/gnunet-service-gns_shorten.h
+++ /dev/null
@@ -1,70 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2013 GNUnet e.V.
4
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.
9
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.
14
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file gns/gnunet-service-gns_shorten.h
22 * @brief GNUnet GNS shortening API
23 * @author Martin Schanzenbach
24 */
25#ifndef GNS_SHORTEN_H
26#define GNS_SHORTEN_H
27#include "gns.h"
28#include "gnunet_dht_service.h"
29#include "gnunet_namecache_service.h"
30#include "gnunet_namestore_service.h"
31
32
33/**
34 * Initialize the shorten subsystem.
35 * MUST be called before #GNS_shorten_start.
36 *
37 * @param nh handle to the namestore
38 * @param nc the namecache handle
39 * @param dht handle to the dht
40 */
41void
42GNS_shorten_init (struct GNUNET_NAMESTORE_Handle *nh,
43 struct GNUNET_NAMECACHE_Handle *nc,
44 struct GNUNET_DHT_Handle *dht);
45
46
47/**
48 * Cleanup shorten: Terminate pending lookups
49 */
50void
51GNS_shorten_done (void);
52
53
54/**
55 * Start shortening algorithm, try to allocate a nice short
56 * canonical name for @a pub in @a shorten_zone, using
57 * @a original_label as one possible suggestion.
58 *
59 * @param original_label original label for the zone
60 * @param pub public key of the zone to shorten
61 * @param shorten_zone private key of the target zone for the new record
62 */
63void
64GNS_shorten_start (const char *original_label,
65 const char *suggested_label,
66 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub,
67 const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone);
68
69
70#endif