1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
|
/*
This file is part of GNUnet.
(C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @file gns/gnunet-service-gns_resolver.h
* @brief GNUnet GNS service
* @author Martin Schanzenbach
*/
#ifndef GNS_RESOLVER_H
#define GNS_RESOLVER_H
#include "gns.h"
#include "gnunet_dht_service.h"
#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
#define GNUNET_GNS_DEFAULT_LOOKUP_TIMEOUT \
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
#define DHT_GNS_REPLICATION_LEVEL 5
#define GNUNET_GNS_MAX_PARALLEL_LOOKUPS 500
#define GNUNET_GNS_MAX_NS_TASKS 500
/*
* DLL to hold the authority chain
* we had to pass in the resolution process
*/
struct AuthorityChain
{
struct AuthorityChain *prev;
struct AuthorityChain *next;
/**
* the zone hash of the authority
*/
struct GNUNET_CRYPTO_ShortHashCode zone;
/**
* (local) name of the authority
*/
char name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
/**
* was the ns entry fresh
*/
int fresh;
};
/**
* handle to a resolution process
*/
struct ResolverHandle;
/**
* processor for a record lookup result
*
* @param cls the closure
* @param rd_count number of results
* @param rd result data
*/
typedef void (*RecordLookupProcessor) (void *cls,
uint32_t rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd);
/**
* processor for a shorten result
*
* @param cls the closure
* @param name shortened name
*/
typedef void (*ShortenResultProcessor) (void *cls,
const char* name);
/**
* processor for an authority result
*
* @param cls the closure
* @param name name of the authority
*/
typedef void (*GetAuthorityResultProcessor) (void *cls,
const char* name);
/**
* processor for a resolution result
*
* @param cls the closure
* @param rh the resolution handle
* @param rd_count number of results
* @param rd result data (array of 'rd_count' records)
*/
typedef void (*ResolutionResultProcessor) (void *cls,
struct ResolverHandle *rh,
uint32_t rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd);
/**
* Resolution status indicator
*/
enum ResolutionStatus
{
/**
* the name to lookup exists
*/
RSL_RECORD_EXISTS = 1,
/**
* the name in the record expired
*/
RSL_RECORD_EXPIRED = 2,
/**
* resolution timed out
*/
RSL_TIMED_OUT = 4,
/**
* Found VPN delegation
*/
RSL_DELEGATE_VPN = 8,
/**
* Found NS delegation
*/
RSL_DELEGATE_NS = 16,
/**
* Found PKEY delegation
*/
RSL_DELEGATE_PKEY = 32,
/**
* Found CNAME record
*/
RSL_CNAME_FOUND = 64,
/**
* Found PKEY has been revoked
*/
RSL_PKEY_REVOKED = 128
};
/**
* Handle to a currenty pending resolution
* a ResolverHandle is passed to, for example
* resolve_record_ns to resolve a record in the namestore.
* On result (positive or negative) the ResolutionResultProcessor
* is called.
* If a timeout is set timeout_cont will be called.
* If no timeout is set (ie timeout forever) then background resolutions
* might be triggered.
*/
struct ResolverHandle
{
/**
* DLL
*/
struct ResolverHandle *next;
/**
* DLL
*/
struct ResolverHandle *prev;
/**
* Last record data found
*/
struct GNUNET_NAMESTORE_RecordData rd;
/**
* Number of last record data found
*/
unsigned int rd_count;
/**
* The name to resolve
*/
char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* has this query been answered? how many matches
*/
int answered;
/**
* Use only cache
*/
int only_cached;
/**
* the authoritative zone to query
*/
struct GNUNET_CRYPTO_ShortHashCode authority;
/**
* the name of the authoritative zone to query
*/
char authority_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
/**
* a handle for dht lookups. should be NULL if no lookups are in progress
*/
struct GNUNET_DHT_GetHandle *get_handle;
/**
* timeout set for this lookup task
*/
struct GNUNET_TIME_Relative timeout;
/**
* a handle to a vpn request
*/
struct GNUNET_VPN_RedirectionRequest *vpn_handle;
/**
* a socket for a dns request
*/
struct GNUNET_NETWORK_Handle *dns_sock;
/**
* a synthesized dns name
*/
char dns_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* the authoritative dns zone
*/
char dns_zone[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* the address of the DNS server FIXME not needed?
*/
struct sockaddr_in dns_addr;
/**
* handle to the local stub resolver request
*/
struct GNUNET_RESOLVER_RequestHandle *dns_resolver_handle;
/**
* select task for DNS
*/
GNUNET_SCHEDULER_TaskIdentifier dns_read_task;
/**
* pointer to raw dns query payload FIXME needs to be freed/NULL
*/
char *dns_raw_packet;
/**
* size of the raw dns query
*/
size_t dns_raw_packet_size;
/**
* timeout task for the lookup
*/
GNUNET_SCHEDULER_TaskIdentifier timeout_task;
/**
* continuation to call on timeout
*/
GNUNET_SCHEDULER_Task timeout_cont;
/**
* closure for timeout cont
*/
void* timeout_cont_cls;
/**
* called when resolution phase finishes
*/
ResolutionResultProcessor proc;
/**
* closure passed to proc
*/
void* proc_cls;
/**
* DLL to store the authority chain
*/
struct AuthorityChain *authority_chain_head;
/**
* DLL to store the authority chain
*/
struct AuthorityChain *authority_chain_tail;
/**
* status of the resolution result
*/
enum ResolutionStatus status;
/**
* The provate local zone of this request
*/
struct GNUNET_CRYPTO_ShortHashCode private_local_zone;
/**
* private key of an/our authoritative zone
* can be NULL but automatical PKEY import will not work
*/
struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
/**
* the heap node associated with this lookup, null if timeout is set
* used for DHT background lookups.
*/
struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
/**
* Id for resolution process
*/
unsigned long long id;
/**
* Pending Namestore task
*/
struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
};
/**
* Handle to a record lookup
*/
struct RecordLookupHandle
{
/**
* the record type to look up
*/
enum GNUNET_GNS_RecordType record_type;
/**
* the name to look up
*/
char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* Method to call on record resolution result
*/
RecordLookupProcessor proc;
/**
* closure to pass to proc
*/
void* proc_cls;
};
/**
* Handle to a shorten context
*/
struct NameShortenHandle
{
/**
* Method to call on shorten result
*/
ShortenResultProcessor proc;
/**
* closure to pass to proc
*/
void* proc_cls;
/**
* result of shorten
*/
char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* root zone
*/
struct GNUNET_CRYPTO_ShortHashCode *root_zone;
/**
* private zone
*/
struct GNUNET_CRYPTO_ShortHashCode *private_zone;
/**
* name of private zone
*/
char private_zone_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
/**
* shorten zone
*/
struct GNUNET_CRYPTO_ShortHashCode *shorten_zone;
/**
* name of shorten zone
*/
char shorten_zone_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
};
/**
* Handle to a get authority context
*/
struct GetNameAuthorityHandle
{
/**
* the name to look up authority for
*/
char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* the result
*/
char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* Method to call on result
*/
GetAuthorityResultProcessor proc;
/**
* closure to pass to proc
*/
void* proc_cls;
};
/**
* Handle to a pseu lookup
*/
struct GetPseuAuthorityHandle
{
/**
* DLL
*/
struct GetPseuAuthorityHandle *next;
/**
* DLL
*/
struct GetPseuAuthorityHandle *prev;
/**
* the name to store the zone under
*/
char name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
/**
* test name to store the zone under
*/
char test_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
/**
* the zone of our authority
*/
struct GNUNET_CRYPTO_ShortHashCode our_zone;
/**
* the private key of the zone to store the pseu in
*/
struct GNUNET_CRYPTO_RsaPrivateKey *key;
/**
* a handle for dht lookups. should be NULL if no lookups are in progress
*/
struct GNUNET_DHT_GetHandle *get_handle;
/**
* timeout task for lookup
*/
GNUNET_SCHEDULER_TaskIdentifier timeout;
/**
* Authority to shorten
*/
struct AuthorityChain *auth;
/**
* handle to namestore request
*/
struct GNUNET_NAMESTORE_QueueEntry* namestore_task;
};
/**
* Namestore queue entries in background
*/
struct NamestoreBGTask
{
/**
* node in heap
*/
struct GNUNET_CONTAINER_HeapNode *node;
/**
* queue entry
*/
struct GNUNET_NAMESTORE_QueueEntry *qe;
};
/**
* Initialize the resolver
* MUST be called before other gns_resolver_* methods
*
* @param nh handle to the namestore
* @param dh handle to the dht
* @param lz the local zone
* @param c configuration handle
* @param max_bg_queries maximum amount of background queries
* @param ignore_pending ignore records that still require user confirmation
* on lookup
* @returns GNUNET_OK on success
*/
int
gns_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
struct GNUNET_DHT_Handle *dh,
struct GNUNET_CRYPTO_ShortHashCode lz,
const struct GNUNET_CONFIGURATION_Handle *c,
unsigned long long max_bg_queries,
int ignore_pending);
/**
* Cleanup resolver: Terminate pending lookups
*/
void
gns_resolver_cleanup (void);
/**
* Lookup of a record in a specific zone
* calls RecordLookupProcessor on result or timeout
*
* @param zone the root zone
* @param pzone the private local zone
* @param record_type the record type to look up
* @param name the name to look up
* @param key optional private key for authority caching
* @param timeout timeout for the resolution
* @param only_cached GNUNET_NO to only check locally not DHT for performance
* @param proc the processor to call
* @param cls the closure to pass to proc
*/
void
gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone,
struct GNUNET_CRYPTO_ShortHashCode pzone,
uint32_t record_type,
const char* name,
struct GNUNET_CRYPTO_RsaPrivateKey *key,
struct GNUNET_TIME_Relative timeout,
int only_cached,
RecordLookupProcessor proc,
void* cls);
/**
* Shortens a name if possible. If the shortening fails
* name will be returned as shortened string. Else
* a shorter version of the name will be returned.
* There is no guarantee that the shortened name will
* actually be canonical/short etc.
*
* @param zone the root zone to use
* @param pzone the private zone to use
* @param szone the shorten zone to use
* @param name name to shorten
* @param private_zone_name name of the private zone
* @param shorten_zone_name name of the shorten zone
* @param proc the processor to call on shorten result
* @param proc_cls the closure to pass to proc
*/
void
gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
struct GNUNET_CRYPTO_ShortHashCode *pzone,
struct GNUNET_CRYPTO_ShortHashCode *szone,
const char* name,
const char* private_zone_name,
const char* shorten_zone_name,
ShortenResultProcessor proc,
void* proc_cls);
/**
* Tries to resolve the authority for name
* in our namestore
*
* @param zone the root zone to look up for
* @param pzone the private local zone
* @param name the name to lookup up
* @param proc the processor to call when finished
* @param proc_cls the closure to pass to the processor
*/
void
gns_resolver_get_authority (struct GNUNET_CRYPTO_ShortHashCode zone,
struct GNUNET_CRYPTO_ShortHashCode pzone,
const char* name,
GetAuthorityResultProcessor proc,
void* proc_cls);
/**
* Generic function to check for TLDs
*
* @param name the name to check
* @param tld the tld to check
* @return GNUNET_YES or GNUNET_NO
*/
int
is_tld (const char* name,
const char* tld);
/**
* Checks for gads/zkey
*/
#define is_gads_tld(name) is_tld(name, GNUNET_GNS_TLD)
#define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)
#endif
|