aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-09-29 17:38:25 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-09-29 17:38:25 +0000
commit212d423a7b173c8f8df8638dc73c794f2ee1ffde (patch)
tree984e9647d796b78ddb043587f415420f1f7d6c27 /src/gns
parent4ec371603a6dff2053daf6f839060c725d6c8d49 (diff)
downloadgnunet-212d423a7b173c8f8df8638dc73c794f2ee1ffde.tar.gz
gnunet-212d423a7b173c8f8df8638dc73c794f2ee1ffde.zip
-doxy
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/gns.conf.in2
-rw-r--r--src/gns/gns_api.c33
-rw-r--r--src/gns/gnunet-service-gns.c382
-rw-r--r--src/gns/gnunet-service-gns_resolver.c96
4 files changed, 312 insertions, 201 deletions
diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in
index 93e6ef3fa..91c0a4dc2 100644
--- a/src/gns/gns.conf.in
+++ b/src/gns/gns.conf.in
@@ -14,7 +14,7 @@ AUTO_IMPORT_PKEY = YES
14AUTO_IMPORT_CONFIRMATION_REQ = NO 14AUTO_IMPORT_CONFIRMATION_REQ = NO
15MAX_PARALLEL_BACKGROUND_QUERIES = 25 15MAX_PARALLEL_BACKGROUND_QUERIES = 25
16DEFAULT_LOOKUP_TIMEOUT = 10 16DEFAULT_LOOKUP_TIMEOUT = 10
17RECORD_PUT_INTERVAL = 4 h 17ZONE_PUBLISH_TIME_WINDOW = 4 h
18# PREFIX = valgrind --leak-check=full --track-origins=yes 18# PREFIX = valgrind --leak-check=full --track-origins=yes
19 19
20[gns-proxy] 20[gns-proxy]
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index 94142ea88..fef7b866d 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -88,19 +88,26 @@ struct GNUNET_GNS_ShortenRequest
88 */ 88 */
89 struct GNUNET_GNS_ShortenRequest *prev; 89 struct GNUNET_GNS_ShortenRequest *prev;
90 90
91 /* handle to gns */ 91 /**
92 * handle to gns
93 */
92 struct GNUNET_GNS_Handle *gns_handle; 94 struct GNUNET_GNS_Handle *gns_handle;
93 95
94 /* processor to call on shorten result */ 96 /**
97 * processor to call on shorten result
98 */
95 GNUNET_GNS_ShortenResultProcessor shorten_proc; 99 GNUNET_GNS_ShortenResultProcessor shorten_proc;
96 100
97 /* processor closure */ 101 /**
102 * processor closure
103 */
98 void *proc_cls; 104 void *proc_cls;
99 105
100 /* request id */ 106 /**
107 * request id
108 */
101 uint64_t r_id; 109 uint64_t r_id;
102 110
103
104}; 111};
105 112
106 113
@@ -119,16 +126,24 @@ struct GNUNET_GNS_GetAuthRequest
119 */ 126 */
120 struct GNUNET_GNS_GetAuthRequest *prev; 127 struct GNUNET_GNS_GetAuthRequest *prev;
121 128
122 /* handle to gns */ 129 /**
130 * handle to gns
131 */
123 struct GNUNET_GNS_Handle *gns_handle; 132 struct GNUNET_GNS_Handle *gns_handle;
124 133
125 /* processor to call on authority lookup result */ 134 /**
135 * processor to call on authority lookup result
136 */
126 GNUNET_GNS_GetAuthResultProcessor auth_proc; 137 GNUNET_GNS_GetAuthResultProcessor auth_proc;
127 138
128 /* processor closure */ 139 /**
140 * processor closure
141 */
129 void *proc_cls; 142 void *proc_cls;
130 143
131 /* request id */ 144 /**
145 * request id
146 */
132 uint32_t r_id; 147 uint32_t r_id;
133 148
134}; 149};
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 5ad0bcf76..c5c5ac2bf 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -40,9 +40,27 @@
40#include "gnunet-service-gns_interceptor.h" 40#include "gnunet-service-gns_interceptor.h"
41#include "gnunet_protocols.h" 41#include "gnunet_protocols.h"
42 42
43#define INITIAL_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS 43/**
44 * The initial interval in milliseconds btween puts in
45 * a zone iteration
46 */
47#define INITIAL_PUT_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS
48
49/**
50 * The upper bound for the zone iteration interval in milliseconds
51 */
44#define MINIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_SECONDS 52#define MINIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_SECONDS
45#define DEFAULT_RECORD_PUT_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) 53
54/**
55 * The default put interval for the zone iteration. In case
56 * No option is found
57 */
58#define DEFAULT_ZONE_PUBLISH_TIME_WINDOW GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
59
60/**
61 * The factor the current zone iteration interval is divided by for each
62 * additional new record
63 */
46#define LATE_ITERATION_SPEEDUP_FACTOR 2 64#define LATE_ITERATION_SPEEDUP_FACTOR 2
47 65
48 66
@@ -52,59 +70,85 @@
52struct ClientShortenHandle 70struct ClientShortenHandle
53{ 71{
54 72
55 /* DLL */ 73 /**
74 * List for all shorten requests
75 */
56 struct ClientShortenHandle *next; 76 struct ClientShortenHandle *next;
57 77 /**
58 /* DLL */ 78 * List for all shorten requests
79 */
59 struct ClientShortenHandle *prev; 80 struct ClientShortenHandle *prev;
60 81
61 /* the requesting client that */ 82 /**
83 * Handle to the requesting client
84 */
62 struct GNUNET_SERVER_Client *client; 85 struct GNUNET_SERVER_Client *client;
63 86
64 /* request id */ 87 /**
65 uint64_t unique_id; 88 * The request id
89 */
90 uint64_t request_id;
66 91
67 /* request type */ 92 /**
93 * request type
94 */
68 enum GNUNET_GNS_RecordType type; 95 enum GNUNET_GNS_RecordType type;
69 96
70 /* name to shorten */ 97 /**
98 * name to shorten
99 */
71 char name[MAX_DNS_NAME_LENGTH]; 100 char name[MAX_DNS_NAME_LENGTH];
72 101
73 /* name of private zone (relative to root) */ 102 /**
103 * name of private zone (relative to root)
104 */
74 char private_zone_id[MAX_DNS_NAME_LENGTH]; 105 char private_zone_id[MAX_DNS_NAME_LENGTH];
75 106
76 /* name of shorten zone (relative to root) */ 107 /**
108 * name of shorten zone (relative to root)
109 */
77 char shorten_zone_id[MAX_DNS_NAME_LENGTH]; 110 char shorten_zone_id[MAX_DNS_NAME_LENGTH];
78 111
79 /* root zone */ 112 /**
113 * master zone
114 */
80 struct GNUNET_CRYPTO_ShortHashCode root_zone; 115 struct GNUNET_CRYPTO_ShortHashCode root_zone;
81 116
82 /* private zone */ 117 /**
118 * private zone
119 */
83 struct GNUNET_CRYPTO_ShortHashCode private_zone; 120 struct GNUNET_CRYPTO_ShortHashCode private_zone;
84 121
85 /* shorten zone */ 122 /**
123 * shorten zone
124 */
86 struct GNUNET_CRYPTO_ShortHashCode shorten_zone; 125 struct GNUNET_CRYPTO_ShortHashCode shorten_zone;
87 126
88 /* Namestore lookup task */ 127 /**
128 * Namestore lookup task
129 */
89 struct GNUNET_NAMESTORE_QueueEntry *namestore_task; 130 struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
90
91}; 131};
92 132
93 133
94/** 134/**
95 * Handle to a get auhtority operation from api 135 * Handle to a get authority operation from api
96 */ 136 */
97struct ClientGetAuthHandle 137struct ClientGetAuthHandle
98{ 138{
99 /* the requesting client that */ 139 /**
140 * Handle to the requesting client */
100 struct GNUNET_SERVER_Client *client; 141 struct GNUNET_SERVER_Client *client;
101 142
102 /* request id */ 143 /**
103 uint64_t unique_id; 144 * request id
145 */
146 uint64_t request_id;
104 147
105 /* name to lookup authority */ 148 /**
149 * name to lookup authority
150 */
106 char *name; 151 char *name;
107
108}; 152};
109 153
110 154
@@ -114,25 +158,39 @@ struct ClientGetAuthHandle
114struct ClientLookupHandle 158struct ClientLookupHandle
115{ 159{
116 160
117 /* the requesting client that */ 161 /**
162 * Handle to the requesting client
163 */
118 struct GNUNET_SERVER_Client *client; 164 struct GNUNET_SERVER_Client *client;
119 165
120 /* The zone we look up in */ 166 /**
167 * The zone we look up in
168 */
121 struct GNUNET_CRYPTO_ShortHashCode zone; 169 struct GNUNET_CRYPTO_ShortHashCode zone;
122 170
123 /* Do we only want to lookup from local cache? */ 171 /**
172 * GNUNET_YES if we only want to lookup from local cache
173 */
124 int only_cached; 174 int only_cached;
125 175
126 /* request id */ 176 /**
127 uint64_t unique_id; 177 * request id
178 */
179 uint64_t request_id;
128 180
129 /* request type */ 181 /**
182 * request type
183 */
130 enum GNUNET_GNS_RecordType type; 184 enum GNUNET_GNS_RecordType type;
131 185
132 /* optional zone private key used for shorten */ 186 /**
187 * optional zone private key used for shorten
188 */
133 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key; 189 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key;
134 190
135 /* the name to look up */ 191 /**
192 * the name to look up
193 */
136 char *name; 194 char *name;
137}; 195};
138 196
@@ -149,7 +207,6 @@ static struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
149 207
150/** 208/**
151 * Our handle to the namestore service 209 * Our handle to the namestore service
152 * FIXME maybe need a second handle for iteration
153 */ 210 */
154static struct GNUNET_NAMESTORE_Handle *namestore_handle; 211static struct GNUNET_NAMESTORE_Handle *namestore_handle;
155 212
@@ -179,38 +236,59 @@ static unsigned long long num_public_records;
179static unsigned long long last_num_public_records; 236static unsigned long long last_num_public_records;
180 237
181/** 238/**
182 * FIXME! 239 * Zone iteration PUT interval.
183 */ 240 */
184static struct GNUNET_TIME_Relative zone_iteration_interval; 241static struct GNUNET_TIME_Relative put_interval;
185 242
186/* dht update interval FIXME define? */ 243/**
187static struct GNUNET_TIME_Relative record_put_interval; 244 * Time window for zone iteration
245 */
246static struct GNUNET_TIME_Relative zone_publish_time_window;
188 247
189/* zone update task */ 248/**
190static GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid; 249 * zone publish task
250 */
251static GNUNET_SCHEDULER_TaskIdentifier zone_publish_task;
191 252
192/* automatic pkey import for name shortening */ 253/**
254 * GNUNET_YES if automatic pkey import for name shortening
255 * is enabled
256 */
193static int auto_import_pkey; 257static int auto_import_pkey;
194 258
195/* first zone iteration is specia */ 259/**
260 * GNUNET_YES if zone has never been published before
261 */
196static int first_zone_iteration; 262static int first_zone_iteration;
197 263
198/* lookup timeout */ 264/**
265 * The lookup timeout
266 */
199static struct GNUNET_TIME_Relative default_lookup_timeout; 267static struct GNUNET_TIME_Relative default_lookup_timeout;
200 268
201/* ipv6 support */ 269/**
270 * GNUNET_YES if ipv6 is supported
271 */
202static int v6_enabled; 272static int v6_enabled;
203 273
204/* ipv4 support */ 274/**
275 * GNUNET_YES if ipv4 is supported
276 */
205static int v4_enabled; 277static int v4_enabled;
206 278
207/* Shorten DLL for cancelling NS requests */ 279/**
280 * List for shorten requests
281 */
208static struct ClientShortenHandle *csh_head; 282static struct ClientShortenHandle *csh_head;
209 283
210/* Shorten DLL for cancelling NS requests */ 284/**
285 * List for shorten requests
286 */
211static struct ClientShortenHandle *csh_tail; 287static struct ClientShortenHandle *csh_tail;
212 288
213/* Statistics handle */ 289/**
290 * Handle to the statistics service
291 */
214static struct GNUNET_STATISTICS_Handle *statistics; 292static struct GNUNET_STATISTICS_Handle *statistics;
215 293
216 294
@@ -237,8 +315,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
237 gns_resolver_cleanup (); 315 gns_resolver_cleanup ();
238 if (NULL != statistics) 316 if (NULL != statistics)
239 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); 317 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
240 if (zone_update_taskid != GNUNET_SCHEDULER_NO_TASK) 318 if (zone_publish_task != GNUNET_SCHEDULER_NO_TASK)
241 GNUNET_SCHEDULER_cancel (zone_update_taskid); 319 GNUNET_SCHEDULER_cancel (zone_publish_task);
242 if (NULL != namestore_iter) 320 if (NULL != namestore_iter)
243 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); 321 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
244 GNUNET_NAMESTORE_disconnect(namestore_handle); 322 GNUNET_NAMESTORE_disconnect(namestore_handle);
@@ -253,33 +331,23 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
253 * @param tc task context 331 * @param tc task context
254 */ 332 */
255static void 333static void
256update_zone_dht_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 334publish_zone_dht_next (void *cls,
335 const struct GNUNET_SCHEDULER_TaskContext *tc)
257{ 336{
258 zone_update_taskid = GNUNET_SCHEDULER_NO_TASK; 337 zone_publish_task = GNUNET_SCHEDULER_NO_TASK;
259 GNUNET_NAMESTORE_zone_iterator_next (namestore_iter); 338 GNUNET_NAMESTORE_zone_iterator_next (namestore_iter);
260} 339}
261 340
262 341
263/** 342/**
264 * Continuation for DHT put 343 * Periodically iterate over our zone and store everything in dht
265 * 344 *
266 * @param cls closure 345 * @param cls NULL
267 * @param success GNUNET_OK if the PUT was transmitted, 346 * @param tc task context
268 * GNUNET_NO on timeout,
269 * GNUNET_SYSERR on disconnect from service
270 * after the PUT message was transmitted
271 * (so we don't know if it was received or not)
272 */ 347 */
273static void 348static void
274record_dht_put(void *cls, int success) 349publish_zone_dht_start (void *cls,
275{ 350 const struct GNUNET_SCHEDULER_TaskContext *tc);
276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "put request transmitted\n");
277}
278
279
280/* prototype */
281static void
282update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
283 351
284 352
285/** 353/**
@@ -323,7 +391,7 @@ put_gns_record(void *cls,
323 * we can safely set the interval to the value for a single 391 * we can safely set the interval to the value for a single
324 * record 392 * record
325 */ 393 */
326 zone_iteration_interval = GNUNET_TIME_relative_divide (record_put_interval, 394 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
327 1); 395 1);
328 396
329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
@@ -331,18 +399,18 @@ put_gns_record(void *cls,
331 } 399 }
332 else 400 else
333 { 401 {
334 zone_iteration_interval = GNUNET_TIME_relative_divide (record_put_interval, 402 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
335 num_public_records); 403 num_public_records);
336 } 404 }
337 zone_iteration_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL, 405 put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL,
338 zone_iteration_interval); 406 put_interval);
339 407
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "Zone iteration finished. Adjusted zone iteration interval to %s\n", 409 "Zone iteration finished. Adjusted zone iteration interval to %s\n",
342 GNUNET_STRINGS_relative_time_to_string (zone_iteration_interval, GNUNET_YES)); 410 GNUNET_STRINGS_relative_time_to_string (put_interval, GNUNET_YES));
343 GNUNET_STATISTICS_set (statistics, 411 GNUNET_STATISTICS_set (statistics,
344 "Current zone iteration interval (in ms)", 412 "Current zone iteration interval (in ms)",
345 zone_iteration_interval.rel_value, 413 put_interval.rel_value,
346 GNUNET_NO); 414 GNUNET_NO);
347 GNUNET_STATISTICS_update (statistics, 415 GNUNET_STATISTICS_update (statistics,
348 "Number of zone iterations", 1, GNUNET_NO); 416 "Number of zone iterations", 1, GNUNET_NO);
@@ -351,11 +419,11 @@ put_gns_record(void *cls,
351 last_num_public_records, 419 last_num_public_records,
352 GNUNET_NO); 420 GNUNET_NO);
353 if (0 == num_public_records) 421 if (0 == num_public_records)
354 zone_update_taskid = GNUNET_SCHEDULER_add_delayed (zone_iteration_interval, 422 zone_publish_task = GNUNET_SCHEDULER_add_delayed (put_interval,
355 &update_zone_dht_start, 423 &publish_zone_dht_start,
356 NULL); 424 NULL);
357 else 425 else
358 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL); 426 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, NULL);
359 return; 427 return;
360 } 428 }
361 429
@@ -365,14 +433,14 @@ put_gns_record(void *cls,
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
366 "No records for name `%s'! Skipping.\n", 434 "No records for name `%s'! Skipping.\n",
367 name); 435 name);
368 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next, 436 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next,
369 NULL); 437 NULL);
370 return; 438 return;
371 } 439 }
372 if (NULL == signature) 440 if (NULL == signature)
373 { 441 {
374 GNUNET_break (0); 442 GNUNET_break (0);
375 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next, 443 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next,
376 NULL); 444 NULL);
377 return; 445 return;
378 } 446 }
@@ -401,8 +469,8 @@ put_gns_record(void *cls,
401 _("Records for name `%s' in zone %s too large to fit into DHT"), 469 _("Records for name `%s' in zone %s too large to fit into DHT"),
402 name, 470 name,
403 GNUNET_short_h2s (&zhash)); 471 GNUNET_short_h2s (&zhash));
404 GNUNET_free(nrb); 472 GNUNET_free (nrb);
405 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next, 473 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next,
406 NULL); 474 NULL);
407 return; 475 return;
408 } 476 }
@@ -428,7 +496,7 @@ put_gns_record(void *cls,
428 (char*)nrb, 496 (char*)nrb,
429 expiration, 497 expiration,
430 DHT_OPERATION_TIMEOUT, 498 DHT_OPERATION_TIMEOUT,
431 &record_dht_put, 499 NULL,
432 NULL); 500 NULL);
433 GNUNET_free (nrb); 501 GNUNET_free (nrb);
434 502
@@ -438,20 +506,20 @@ put_gns_record(void *cls,
438 { 506 {
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "Last record count was lower than current record count. Reducing interval.\n"); 508 "Last record count was lower than current record count. Reducing interval.\n");
441 zone_iteration_interval = GNUNET_TIME_relative_divide (record_put_interval, 509 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
442 num_public_records); 510 num_public_records);
443 next_put_interval = GNUNET_TIME_relative_divide (zone_iteration_interval, 511 next_put_interval = GNUNET_TIME_relative_divide (put_interval,
444 LATE_ITERATION_SPEEDUP_FACTOR); 512 LATE_ITERATION_SPEEDUP_FACTOR);
445 } 513 }
446 else 514 else
447 next_put_interval = zone_iteration_interval; 515 next_put_interval = put_interval;
448 516
449 GNUNET_STATISTICS_set (statistics, 517 GNUNET_STATISTICS_set (statistics,
450 "Current zone iteration interval (ms)", 518 "Current zone iteration interval (ms)",
451 next_put_interval.rel_value, 519 next_put_interval.rel_value,
452 GNUNET_NO); 520 GNUNET_NO);
453 zone_update_taskid = GNUNET_SCHEDULER_add_delayed (next_put_interval, 521 zone_publish_task = GNUNET_SCHEDULER_add_delayed (next_put_interval,
454 &update_zone_dht_next, 522 &publish_zone_dht_next,
455 NULL); 523 NULL);
456} 524}
457 525
@@ -463,9 +531,9 @@ put_gns_record(void *cls,
463 * @param tc task context 531 * @param tc task context
464 */ 532 */
465static void 533static void
466update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 534publish_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
467{ 535{
468 zone_update_taskid = GNUNET_SCHEDULER_NO_TASK; 536 zone_publish_task = GNUNET_SCHEDULER_NO_TASK;
469 537
470 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling DHT zone update!\n"); 538 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling DHT zone update!\n");
471 /* start counting again */ 539 /* start counting again */
@@ -507,7 +575,7 @@ send_shorten_response (void* cls, const char* name)
507 rmsg = GNUNET_malloc (sizeof (struct GNUNET_GNS_ClientShortenResultMessage) + 575 rmsg = GNUNET_malloc (sizeof (struct GNUNET_GNS_ClientShortenResultMessage) +
508 name_len); 576 name_len);
509 577
510 rmsg->id = csh->unique_id; 578 rmsg->id = csh->request_id;
511 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT); 579 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT);
512 rmsg->header.size = 580 rmsg->header.size =
513 htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) + 581 htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) +
@@ -733,8 +801,6 @@ handle_shorten (void *cls,
733 struct GNUNET_SERVER_Client * client, 801 struct GNUNET_SERVER_Client * client,
734 const struct GNUNET_MessageHeader * message) 802 const struct GNUNET_MessageHeader * message)
735{ 803{
736 uint16_t msg_size;
737 const struct GNUNET_GNS_ClientShortenMessage *sh_msg;
738 struct ClientShortenHandle *csh; 804 struct ClientShortenHandle *csh;
739 const char *utf_in; 805 const char *utf_in;
740 char name[MAX_DNS_NAME_LENGTH]; 806 char name[MAX_DNS_NAME_LENGTH];
@@ -748,17 +814,14 @@ handle_shorten (void *cls,
748 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 814 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
749 return; 815 return;
750 } 816 }
751 sh_msg = (const struct GNUNET_GNS_ClientShortenMessage *) message; 817
752 utf_in = (const char *) &sh_msg[1]; 818
753 if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientShortenMessage) - 1]) 819 const struct GNUNET_GNS_ClientShortenMessage *sh_msg =
754 { 820 (const struct GNUNET_GNS_ClientShortenMessage *) message;
755 GNUNET_break (0); 821
756 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 822 csh = GNUNET_malloc(sizeof (struct ClientShortenHandle));
757 return;
758 }
759 csh = GNUNET_malloc (sizeof (struct ClientShortenHandle));
760 csh->client = client; 823 csh->client = client;
761 csh->unique_id = sh_msg->id; 824 csh->request_id = sh_msg->id;
762 GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh); 825 GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh);
763 GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr); 826 GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr);
764 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 827 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -833,7 +896,7 @@ send_get_auth_response(void *cls, const char* name)
833 rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) 896 rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage)
834 + strlen(name) + 1); 897 + strlen(name) + 1);
835 898
836 rmsg->id = cah->unique_id; 899 rmsg->id = cah->request_id;
837 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT); 900 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT);
838 rmsg->header.size = 901 rmsg->header.size =
839 htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) + 902 htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) +
@@ -863,8 +926,6 @@ handle_get_authority (void *cls,
863 struct GNUNET_SERVER_Client * client, 926 struct GNUNET_SERVER_Client * client,
864 const struct GNUNET_MessageHeader * message) 927 const struct GNUNET_MessageHeader * message)
865{ 928{
866 uint16_t msg_size;
867 const struct GNUNET_GNS_ClientGetAuthMessage *sh_msg;
868 struct ClientGetAuthHandle *cah; 929 struct ClientGetAuthHandle *cah;
869 const char *utf_in; 930 const char *utf_in;
870 char name[MAX_DNS_NAME_LENGTH]; 931 char name[MAX_DNS_NAME_LENGTH];
@@ -880,18 +941,15 @@ handle_get_authority (void *cls,
880 } 941 }
881 GNUNET_SERVER_notification_context_add (nc, client); 942 GNUNET_SERVER_notification_context_add (nc, client);
882 943
883 sh_msg = (const struct GNUNET_GNS_ClientGetAuthMessage *) message; 944 struct GNUNET_GNS_ClientGetAuthMessage *sh_msg =
884 utf_in = (const char *) &sh_msg[1]; 945 (struct GNUNET_GNS_ClientGetAuthMessage *) message;
885 if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientGetAuthMessage) - 1]) 946
886 { 947 GNUNET_STRINGS_utf8_tolower((const char*)&sh_msg[1], &nameptr);
887 GNUNET_break (0); 948
888 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 949
889 return;
890 }
891 GNUNET_STRINGS_utf8_tolower(utf_in, &nameptr);
892 cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); 950 cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle));
893 cah->client = client; 951 cah->client = client;
894 cah->unique_id = sh_msg->id; 952 cah->request_id = sh_msg->id;
895 if (strlen (name) < strlen(GNUNET_GNS_TLD)) 953 if (strlen (name) < strlen(GNUNET_GNS_TLD))
896 { 954 {
897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 955 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -925,17 +983,16 @@ handle_get_authority (void *cls,
925 cah->name = NULL; 983 cah->name = NULL;
926 send_get_auth_response(cah, name); 984 send_get_auth_response(cah, name);
927 return; 985 return;
928 } 986 }
929 cah->name = GNUNET_malloc(strlen (name) 987
988 cah->name = GNUNET_malloc (strlen (name)
930 - strlen (GNUNET_GNS_TLD) + 1); 989 - strlen (GNUNET_GNS_TLD) + 1);
931 memset (cah->name, 0, 990 memcpy(cah->name, name,
932 strlen (name) - strlen (GNUNET_GNS_TLD) + 1); 991 strlen (name) - strlen (GNUNET_GNS_TLD));
933 memcpy (cah->name, name,
934 strlen (name) - strlen(GNUNET_GNS_TLD));
935 992
936 /* Start delegation resolution in our namestore */ 993 /* Start delegation resolution in our namestore */
937 gns_resolver_get_authority(zone_hash, zone_hash, name, &send_get_auth_response, cah); 994 gns_resolver_get_authority (zone_hash, zone_hash, name,
938 995 &send_get_auth_response, cah);
939 GNUNET_STATISTICS_update (statistics, 996 GNUNET_STATISTICS_update (statistics,
940 "Authority lookup attempts", 1, GNUNET_NO); 997 "Authority lookup attempts", 1, GNUNET_NO);
941} 998}
@@ -954,7 +1011,7 @@ send_lookup_response(void* cls,
954 uint32_t rd_count, 1011 uint32_t rd_count,
955 const struct GNUNET_NAMESTORE_RecordData *rd) 1012 const struct GNUNET_NAMESTORE_RecordData *rd)
956{ 1013{
957 struct ClientLookupHandle* clh = (struct ClientLookupHandle*)cls; 1014 struct ClientLookupHandle* clh = cls;
958 struct GNUNET_GNS_ClientLookupResultMessage *rmsg; 1015 struct GNUNET_GNS_ClientLookupResultMessage *rmsg;
959 size_t len; 1016 size_t len;
960 1017
@@ -962,9 +1019,10 @@ send_lookup_response(void* cls,
962 "LOOKUP_RESULT", rd_count); 1019 "LOOKUP_RESULT", rd_count);
963 1020
964 len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); 1021 len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
965 rmsg = GNUNET_malloc(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage)); 1022 rmsg = GNUNET_malloc (
1023 len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage));
966 1024
967 rmsg->id = clh->unique_id; 1025 rmsg->id = clh->request_id;
968 rmsg->rd_count = htonl(rd_count); 1026 rmsg->rd_count = htonl(rd_count);
969 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT); 1027 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT);
970 rmsg->header.size = 1028 rmsg->header.size =
@@ -982,18 +1040,13 @@ send_lookup_response(void* cls,
982 1040
983 if (NULL != clh->shorten_key) 1041 if (NULL != clh->shorten_key)
984 GNUNET_CRYPTO_rsa_key_free (clh->shorten_key); 1042 GNUNET_CRYPTO_rsa_key_free (clh->shorten_key);
985
986 GNUNET_free(clh); 1043 GNUNET_free(clh);
987 1044
988 GNUNET_STATISTICS_update (statistics, 1045 GNUNET_STATISTICS_update (statistics,
989 "Completed lookups", 1, GNUNET_NO); 1046 "Completed lookups", 1, GNUNET_NO);
990
991 if (rd != NULL) 1047 if (rd != NULL)
992 {
993 GNUNET_STATISTICS_update (statistics, 1048 GNUNET_STATISTICS_update (statistics,
994 "Records resolved", rd_count, GNUNET_NO); 1049 "Records resolved", rd_count, GNUNET_NO);
995 }
996
997} 1050}
998 1051
999 1052
@@ -1009,8 +1062,6 @@ handle_lookup(void *cls,
1009 struct GNUNET_SERVER_Client * client, 1062 struct GNUNET_SERVER_Client * client,
1010 const struct GNUNET_MessageHeader * message) 1063 const struct GNUNET_MessageHeader * message)
1011{ 1064{
1012 uint16_t msg_size;
1013 const struct GNUNET_GNS_ClientLookupMessage *sh_msg;
1014 size_t namelen; 1065 size_t namelen;
1015 char name[MAX_DNS_NAME_LENGTH]; 1066 char name[MAX_DNS_NAME_LENGTH];
1016 struct ClientLookupHandle *clh; 1067 struct ClientLookupHandle *clh;
@@ -1020,7 +1071,8 @@ handle_lookup(void *cls,
1020 struct GNUNET_CRYPTO_RsaPrivateKey *key; 1071 struct GNUNET_CRYPTO_RsaPrivateKey *key;
1021 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey; 1072 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey;
1022 char* tmp_pkey; 1073 char* tmp_pkey;
1023 1074
1075 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP");
1024 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP"); 1076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP");
1025 msg_size = ntohs(message->size); 1077 msg_size = ntohs(message->size);
1026 if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage)) 1078 if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage))
@@ -1031,42 +1083,40 @@ handle_lookup(void *cls,
1031 } 1083 }
1032 sh_msg = (const struct GNUNET_GNS_ClientLookupMessage *) message; 1084 sh_msg = (const struct GNUNET_GNS_ClientLookupMessage *) message;
1033 GNUNET_SERVER_notification_context_add (nc, client); 1085 GNUNET_SERVER_notification_context_add (nc, client);
1086
1087 struct GNUNET_GNS_ClientLookupMessage *sh_msg =
1088 (struct GNUNET_GNS_ClientLookupMessage *) message;
1089
1034 if (GNUNET_YES == ntohl (sh_msg->have_key)) 1090 if (GNUNET_YES == ntohl (sh_msg->have_key))
1035 { 1091 {
1036 pkey = (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *)&sh_msg[1]; 1092 pkey = (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *) &sh_msg[1];
1037 tmp_pkey = (char*)&sh_msg[1]; 1093 tmp_pkey = (char*) &sh_msg[1];
1038 key = GNUNET_CRYPTO_rsa_decode_key (tmp_pkey, ntohs(pkey->len)); 1094 key = GNUNET_CRYPTO_rsa_decode_key (tmp_pkey, ntohs (pkey->len));
1039 GNUNET_STRINGS_utf8_tolower(&tmp_pkey[ntohs(pkey->len)], &nameptr); 1095 GNUNET_STRINGS_utf8_tolower (&tmp_pkey[ntohs (pkey->len)], &nameptr);
1040 } 1096 }
1041 else 1097 else
1042 { 1098 {
1043 key = NULL; 1099 key = NULL;
1044 utf_in = (const char *) &sh_msg[1]; 1100 GNUNET_STRINGS_utf8_tolower ((char*) &sh_msg[1], &nameptr);
1045 if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientLookupMessage) - 1]) 1101 }
1046 { 1102
1047 GNUNET_break (0); 1103 namelen = strlen(name)+1;
1048 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1049 return;
1050 }
1051 GNUNET_STRINGS_utf8_tolower(utf_in, &nameptr);
1052 }
1053 namelen = strlen (name)+1;
1054 clh = GNUNET_malloc (sizeof (struct ClientLookupHandle)); 1104 clh = GNUNET_malloc (sizeof (struct ClientLookupHandle));
1055 memset (clh, 0, sizeof (struct ClientLookupHandle)); 1105 memset (clh, 0, sizeof (struct ClientLookupHandle));
1056 clh->client = client; 1106 clh->client = client;
1057 clh->name = GNUNET_malloc(namelen); 1107 clh->name = GNUNET_malloc (namelen);
1058 strcpy(clh->name, name); 1108 strcpy (clh->name, name);
1059 clh->unique_id = sh_msg->id; 1109 clh->request_id = sh_msg->id;
1060 clh->type = ntohl(sh_msg->type); 1110 clh->type = ntohl (sh_msg->type);
1061 clh->shorten_key = key; 1111 clh->shorten_key = key;
1062 1112
1063 only_cached = ntohl(sh_msg->only_cached); 1113 only_cached = ntohl (sh_msg->only_cached);
1064 1114
1065 if (strlen (name) > MAX_DNS_NAME_LENGTH) { 1115 if (strlen (name) > MAX_DNS_NAME_LENGTH) {
1066 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1067 "LOOKUP: %s is too long", name); 1117 "LOOKUP: %s is too long", name);
1068 clh->name = NULL; 1118 clh->name = NULL;
1069 send_lookup_response(clh, 0, NULL); 1119 send_lookup_response (clh, 0, NULL);
1070 return; 1120 return;
1071 } 1121 }
1072 1122
@@ -1076,21 +1126,21 @@ handle_lookup(void *cls,
1076 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1126 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1077 "LOOKUP: Query for A record but AF_INET not supported!"); 1127 "LOOKUP: Query for A record but AF_INET not supported!");
1078 clh->name = NULL; 1128 clh->name = NULL;
1079 send_lookup_response(clh, 0, NULL); 1129 send_lookup_response (clh, 0, NULL);
1080 return; 1130 return;
1081 } 1131 }
1082 1132
1083 if ((clh->type == GNUNET_GNS_RECORD_AAAA) && 1133 if ((clh->type == GNUNET_GNS_RECORD_AAAA) &&
1084 (GNUNET_OK != v6_enabled)) 1134 (GNUNET_OK != v6_enabled))
1085 { 1135 {
1086 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1087 "LOOKUP: Query for AAAA record but AF_INET6 not supported!"); 1137 "LOOKUP: Query for AAAA record but AF_INET6 not supported!");
1088 clh->name = NULL; 1138 clh->name = NULL;
1089 send_lookup_response(clh, 0, NULL); 1139 send_lookup_response (clh, 0, NULL);
1090 return; 1140 return;
1091 } 1141 }
1092 1142
1093 if (1 == ntohl(sh_msg->use_default_zone)) 1143 if (1 == ntohl (sh_msg->use_default_zone))
1094 clh->zone = zone_hash; //Default zone 1144 clh->zone = zone_hash; //Default zone
1095 else 1145 else
1096 clh->zone = sh_msg->zone; 1146 clh->zone = sh_msg->zone;
@@ -1210,18 +1260,18 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1210 1260
1211 } 1261 }
1212 1262
1213 zone_iteration_interval = INITIAL_ZONE_ITERATION_INTERVAL; 1263 put_interval = INITIAL_PUT_INTERVAL;
1214 1264
1215 record_put_interval = DEFAULT_RECORD_PUT_INTERVAL; 1265 zone_publish_time_window = DEFAULT_ZONE_PUBLISH_TIME_WINDOW;
1216 1266
1217 if (GNUNET_OK == 1267 if (GNUNET_OK ==
1218 GNUNET_CONFIGURATION_get_value_time (c, "gns", 1268 GNUNET_CONFIGURATION_get_value_time (c, "gns",
1219 "RECORD_PUT_INTERVAL", 1269 "ZONE_PUBLISH_TIME_WINDOW",
1220 &record_put_interval)) 1270 &zone_publish_time_window))
1221 { 1271 {
1222 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1272 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1223 "Record put interval: %s\n", 1273 "Time window for zone iteration: %s\n",
1224 GNUNET_STRINGS_relative_time_to_string (record_put_interval, GNUNET_YES)); 1274 GNUNET_STRINGS_relative_time_to_string (zone_publish_time_window, GNUNET_YES));
1225 } 1275 }
1226 1276
1227 if (GNUNET_OK == 1277 if (GNUNET_OK ==
@@ -1297,7 +1347,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1297 * We have roughly an hour for all records; 1347 * We have roughly an hour for all records;
1298 */ 1348 */
1299 first_zone_iteration = GNUNET_YES; 1349 first_zone_iteration = GNUNET_YES;
1300 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL); 1350 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, NULL);
1301 1351
1302 GNUNET_SERVER_add_handlers (server, handlers); 1352 GNUNET_SERVER_add_handlers (server, handlers);
1303 1353
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 0729d6674..ae576c908 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -40,8 +40,19 @@
40#include "gns.h" 40#include "gns.h"
41#include "gnunet-service-gns_resolver.h" 41#include "gnunet-service-gns_resolver.h"
42 42
43/**
44 * Default DHT timeout
45 */
43#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT 46#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
47
48/**
49 * DHT replication level
50 */
44#define DHT_GNS_REPLICATION_LEVEL 5 51#define DHT_GNS_REPLICATION_LEVEL 5
52
53/**
54 * Maximum label length of DNS names
55 */
45#define MAX_DNS_LABEL_LENGTH 63 56#define MAX_DNS_LABEL_LENGTH 63
46 57
47 58
@@ -137,7 +148,6 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
137 148
138/** 149/**
139 * a resolution identifier pool variable 150 * a resolution identifier pool variable
140 * FIXME overflow?
141 * This is a non critical identifier useful for debugging 151 * This is a non critical identifier useful for debugging
142 */ 152 */
143static unsigned long long rid = 0; 153static unsigned long long rid = 0;
@@ -351,6 +361,7 @@ handle_auth_discovery_timeout (void *cls,
351 process_pseu_result (gph, NULL); 361 process_pseu_result (gph, NULL);
352} 362}
353 363
364
354/** 365/**
355 * Function called when we find a PSEU entry in the DHT 366 * Function called when we find a PSEU entry in the DHT
356 * 367 *
@@ -437,6 +448,7 @@ process_auth_discovery_dht_result (void* cls,
437 process_pseu_result (gph, NULL); 448 process_pseu_result (gph, NULL);
438} 449}
439 450
451
440/** 452/**
441 * Process PSEU discovery for shorten via namestore 453 * Process PSEU discovery for shorten via namestore
442 * 454 *
@@ -508,6 +520,7 @@ process_auth_discovery_ns_result (void* cls,
508 process_pseu_result (gph, NULL); 520 process_pseu_result (gph, NULL);
509} 521}
510 522
523
511/** 524/**
512 * Callback called by namestore for a zone to name 525 * Callback called by namestore for a zone to name
513 * result 526 * result
@@ -571,6 +584,13 @@ shorten_authority_chain (struct GetPseuAuthorityHandle *gph)
571} 584}
572 585
573 586
587/**
588 * Start shortening algorithm using auth as
589 * authority chain
590 *
591 * @param auth the authorities that were resolved
592 * @param key the private key for PKEY import
593 */
574static void 594static void
575start_shorten (struct AuthorityChain *auth, 595start_shorten (struct AuthorityChain *auth,
576 const struct GNUNET_CRYPTO_RsaPrivateKey *key) 596 const struct GNUNET_CRYPTO_RsaPrivateKey *key)
@@ -777,6 +797,8 @@ free_resolver_handle (struct ResolverHandle* rh)
777static void 797static void
778finish_shorten (struct ResolverHandle *rh, 798finish_shorten (struct ResolverHandle *rh,
779 struct NameShortenHandle *nsh); 799 struct NameShortenHandle *nsh);
800
801
780/** 802/**
781 * finish get auth 803 * finish get auth
782 * 804 *
@@ -846,8 +868,6 @@ gns_resolver_cleanup ()
846} 868}
847 869
848 870
849
850
851/** 871/**
852 * Callback when record data is put into namestore 872 * Callback when record data is put into namestore
853 * 873 *
@@ -883,6 +903,12 @@ on_namestore_record_put_result (void *cls,
883} 903}
884 904
885 905
906/**
907 * Lookup timeout task
908 *
909 * @param cls the ResolverHandle for the task that timed out
910 * @param tc the task context
911 */
886static void 912static void
887handle_lookup_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 913handle_lookup_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
888{ 914{
@@ -890,7 +916,6 @@ handle_lookup_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
890 916
891 if (NULL != rh->timeout_cont) 917 if (NULL != rh->timeout_cont)
892 rh->timeout_cont (rh->timeout_cont_cls, tc); 918 rh->timeout_cont (rh->timeout_cont_cls, tc);
893 /* FIXME: does this leak memory? */
894} 919}
895 920
896 921
@@ -912,6 +937,7 @@ background_lookup_result_processor (void *cls,
912 rd_count); 937 rd_count);
913} 938}
914 939
940
915/** 941/**
916 * Handle timeout for DHT requests 942 * Handle timeout for DHT requests
917 * 943 *
@@ -1122,7 +1148,6 @@ resolve_record_dht (struct ResolverHandle *rh)
1122 "GNS_PHASE_REC-%llu: starting dht lookup for %s with key: %s\n", 1148 "GNS_PHASE_REC-%llu: starting dht lookup for %s with key: %s\n",
1123 rh->id, rh->name, GNUNET_h2s (&lookup_key)); 1149 rh->id, rh->name, GNUNET_h2s (&lookup_key));
1124 1150
1125 //rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1126 rh->dht_heap_node = NULL; 1151 rh->dht_heap_node = NULL;
1127 1152
1128 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value != rh->timeout.rel_value) 1153 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value != rh->timeout.rel_value)
@@ -1370,8 +1395,6 @@ process_record_result_vpn (void* cls, int af, const void *address)
1370} 1395}
1371 1396
1372 1397
1373
1374
1375/** 1398/**
1376 * Process VPN lookup result for record 1399 * Process VPN lookup result for record
1377 * 1400 *
@@ -1415,6 +1438,13 @@ static void
1415send_dns_packet (struct ResolverHandle *rh); 1438send_dns_packet (struct ResolverHandle *rh);
1416 1439
1417 1440
1441/**
1442 * Read DNS response
1443 *
1444 * @param cls the ResolverHandle for this lookup
1445 * @param addr the sockaddr
1446 * @param addrlen the socket address length
1447 */
1418static void 1448static void
1419handle_dns_resolver (void *cls, 1449handle_dns_resolver (void *cls,
1420 const struct sockaddr *addr, 1450 const struct sockaddr *addr,
@@ -1648,6 +1678,7 @@ read_dns_response (void *cls,
1648 return; 1678 return;
1649} 1679}
1650 1680
1681
1651/** 1682/**
1652 * Sends a UDP dns query to a nameserver specified in the rh 1683 * Sends a UDP dns query to a nameserver specified in the rh
1653 * 1684 *
@@ -1685,6 +1716,7 @@ send_dns_packet (struct ResolverHandle *rh)
1685 1716
1686} 1717}
1687 1718
1719
1688/** 1720/**
1689 * The final phase of resoution. 1721 * The final phase of resoution.
1690 * We found a NS RR and want to resolve via DNS 1722 * We found a NS RR and want to resolve via DNS
@@ -1888,9 +1920,9 @@ resolve_record_vpn (struct ResolverHandle *rh,
1888 GNUNET_TIME_UNIT_FOREVER_ABS, //FIXME 1920 GNUNET_TIME_UNIT_FOREVER_ABS, //FIXME
1889 &process_record_result_vpn, 1921 &process_record_result_vpn,
1890 rh); 1922 rh);
1891
1892} 1923}
1893 1924
1925
1894/** 1926/**
1895 * The final phase of resolution. 1927 * The final phase of resolution.
1896 * rh->name is a name that is canonical and we do not have a delegation. 1928 * rh->name is a name that is canonical and we do not have a delegation.
@@ -1935,7 +1967,6 @@ resolve_record_ns(struct ResolverHandle *rh)
1935} 1967}
1936 1968
1937 1969
1938
1939/** 1970/**
1940 * Handle timeout for DHT requests 1971 * Handle timeout for DHT requests
1941 * 1972 *
@@ -2003,10 +2034,21 @@ dht_authority_lookup_timeout(void *cls,
2003 rh->proc(rh->proc_cls, rh, 0, NULL); 2034 rh->proc(rh->proc_cls, rh, 0, NULL);
2004} 2035}
2005 2036
2006/* Prototype */ 2037
2038/**
2039 * Start DHT lookup for a name -> PKEY (compare NS) record in
2040 * rh->authority's zone
2041 *
2042 * @param rh the pending gns query
2043 */
2007static void resolve_delegation_dht(struct ResolverHandle *rh); 2044static void resolve_delegation_dht(struct ResolverHandle *rh);
2008 2045
2009/* Prototype */ 2046
2047/**
2048 * Resolve the delegation chain for the request in our namestore
2049 *
2050 * @param rh the resolver handle
2051 */
2010static void resolve_delegation_ns(struct ResolverHandle *rh); 2052static void resolve_delegation_ns(struct ResolverHandle *rh);
2011 2053
2012 2054
@@ -2136,6 +2178,7 @@ on_namestore_delegation_put_result(void *cls,
2136 "GNS_NS: Error putting records into namestore: %s\n", emsg); 2178 "GNS_NS: Error putting records into namestore: %s\n", emsg);
2137} 2179}
2138 2180
2181
2139/** 2182/**
2140 * Function called when we get a result from the dht 2183 * Function called when we get a result from the dht
2141 * for our query. Recursively tries to resolve authorities 2184 * for our query. Recursively tries to resolve authorities
@@ -2381,14 +2424,19 @@ process_delegation_result_dht(void* cls,
2381#define MAX_SRV_LENGTH (sizeof(uint16_t)*3)+MAX_DNS_NAME_LENGTH 2424#define MAX_SRV_LENGTH (sizeof(uint16_t)*3)+MAX_DNS_NAME_LENGTH
2382 2425
2383 2426
2427/**
2428 * Exands a name ending in .+ with the zone of origin
2429 *
2430 * @param dest destination buffer
2431 * @param sec the .+ name
2432 * @param repl the string to replace the + with
2433 */
2384static void 2434static void
2385expand_plus(char* dest, char* src, char* repl) 2435expand_plus(char* dest, char* src, char* repl)
2386{ 2436{
2387 char* pos; 2437 char* pos;
2388 unsigned int s_len = strlen(src)+1; 2438 unsigned int s_len = strlen(src)+1;
2389 2439
2390 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2391 "GNS_POSTPROCESS: Got %s to expand with %s\n", src, repl);
2392 //Eh? I guess this is at least strlen ('x.+') == 3 FIXME 2440 //Eh? I guess this is at least strlen ('x.+') == 3 FIXME
2393 if (3 > s_len) 2441 if (3 > s_len)
2394 { 2442 {
@@ -2414,10 +2462,13 @@ expand_plus(char* dest, char* src, char* repl)
2414 } 2462 }
2415 else 2463 else
2416 { 2464 {
2465 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2466 "GNS_POSTPROCESS: No postprocessing for %s\n", src);
2417 memcpy(dest, src, s_len+1); 2467 memcpy(dest, src, s_len+1);
2418 } 2468 }
2419} 2469}
2420 2470
2471
2421/** 2472/**
2422 * finish lookup 2473 * finish lookup
2423 */ 2474 */
@@ -2537,6 +2588,7 @@ finish_lookup (struct ResolverHandle *rh,
2537 free_resolver_handle (rh); 2588 free_resolver_handle (rh);
2538} 2589}
2539 2590
2591
2540/** 2592/**
2541 * Process DHT lookup result for record. 2593 * Process DHT lookup result for record.
2542 * 2594 *
@@ -2568,8 +2620,6 @@ handle_record_dht(void* cls, struct ResolverHandle *rh,
2568} 2620}
2569 2621
2570 2622
2571
2572
2573/** 2623/**
2574 * Process namestore lookup result for record. 2624 * Process namestore lookup result for record.
2575 * 2625 *
@@ -2681,6 +2731,7 @@ pop_tld(char* name, char* dest)
2681 strcpy(dest, (name+len+1)); 2731 strcpy(dest, (name+len+1));
2682} 2732}
2683 2733
2734
2684/** 2735/**
2685 * Checks if name is in tld 2736 * Checks if name is in tld
2686 * 2737 *
@@ -2706,6 +2757,7 @@ is_tld(const char* name, const char* tld)
2706 return GNUNET_YES; 2757 return GNUNET_YES;
2707} 2758}
2708 2759
2760
2709/** 2761/**
2710 * DHT resolution for delegation finished. Processing result. 2762 * DHT resolution for delegation finished. Processing result.
2711 * 2763 *
@@ -3380,10 +3432,8 @@ gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone,
3380 GNUNET_CONTAINER_DLL_insert (rlh_head, rlh_tail, rh); 3432 GNUNET_CONTAINER_DLL_insert (rlh_head, rlh_tail, rh);
3381 3433
3382 if (NULL == key) 3434 if (NULL == key)
3383 {
3384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3385 "No shorten key for resolution\n"); 3436 "No shorten key for resolution\n");
3386 }
3387 3437
3388 if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) 3438 if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
3389 { 3439 {
@@ -3653,6 +3703,7 @@ process_zone_to_name_shorten_shorten (void *cls,
3653 rh); 3703 rh);
3654} 3704}
3655 3705
3706
3656/** 3707/**
3657 * Callback calles by namestore for a zone to name 3708 * Callback calles by namestore for a zone to name
3658 * result 3709 * result
@@ -3767,6 +3818,7 @@ process_zone_to_name_shorten_private (void *cls,
3767 } 3818 }
3768} 3819}
3769 3820
3821
3770/** 3822/**
3771 * Callback calles by namestore for a zone to name 3823 * Callback calles by namestore for a zone to name
3772 * result 3824 * result
@@ -4106,7 +4158,6 @@ gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
4106 } 4158 }
4107 4159
4108 nsh = GNUNET_malloc (sizeof (struct NameShortenHandle)); 4160 nsh = GNUNET_malloc (sizeof (struct NameShortenHandle));
4109
4110 nsh->proc = proc; 4161 nsh->proc = proc;
4111 nsh->proc_cls = proc_cls; 4162 nsh->proc_cls = proc_cls;
4112 nsh->root_zone = zone; 4163 nsh->root_zone = zone;
@@ -4116,7 +4167,6 @@ gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
4116 strcpy (nsh->shorten_zone_name, shorten_zone_name); 4167 strcpy (nsh->shorten_zone_name, shorten_zone_name);
4117 strcpy (nsh->result, name); 4168 strcpy (nsh->result, name);
4118 4169
4119
4120 rh = GNUNET_malloc (sizeof (struct ResolverHandle)); 4170 rh = GNUNET_malloc (sizeof (struct ResolverHandle));
4121 rh->authority = *zone; 4171 rh->authority = *zone;
4122 rh->id = rid++; 4172 rh->id = rid++;
@@ -4128,9 +4178,8 @@ gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
4128 rh->private_local_zone = *zone; 4178 rh->private_local_zone = *zone;
4129 4179
4130 GNUNET_CONTAINER_DLL_insert (nsh_head, nsh_tail, rh); 4180 GNUNET_CONTAINER_DLL_insert (nsh_head, nsh_tail, rh);
4131
4132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4133 "Checking for TLD...\n"); 4182 "Checking for TLD...\n");
4134 if (is_zkey_tld (name) == GNUNET_YES) 4183 if (is_zkey_tld (name) == GNUNET_YES)
4135 { 4184 {
4136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -4162,7 +4211,6 @@ gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
4162 proc (proc_cls, name); 4211 proc (proc_cls, name);
4163 return; 4212 return;
4164 } 4213 }
4165
4166 rh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, 4214 rh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
4167 zone, //ours 4215 zone, //ours
4168 &zkey, 4216 &zkey,
@@ -4238,11 +4286,9 @@ handle_delegation_result_ns_get_auth(void* cls,
4238 uint32_t rd_count, 4286 uint32_t rd_count,
4239 const struct GNUNET_NAMESTORE_RecordData *rd) 4287 const struct GNUNET_NAMESTORE_RecordData *rd)
4240{ 4288{
4241 struct GetNameAuthorityHandle* nah; 4289 struct GetNameAuthorityHandle* nah = rh->proc_cls;
4242 size_t answer_len; 4290 size_t answer_len;
4243 4291
4244 nah = (struct GetNameAuthorityHandle*) rh->proc_cls;
4245
4246 /** 4292 /**
4247 * At this point rh->name contains the part of the name 4293 * At this point rh->name contains the part of the name
4248 * that we do not have a PKEY in our namestore to resolve. 4294 * that we do not have a PKEY in our namestore to resolve.