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