aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-28 08:40:01 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-28 08:40:01 +0000
commit955f3f4305d193bd8e3dd37d59b78e0f5a3bd88d (patch)
tree2102694d420f7065b7ba4faef8fbfc30107ae9ac /src/gns/gnunet-service-gns.c
parentf5449375d42db43d4884848ea44bea41349d930c (diff)
downloadgnunet-955f3f4305d193bd8e3dd37d59b78e0f5a3bd88d.tar.gz
gnunet-955f3f4305d193bd8e3dd37d59b78e0f5a3bd88d.zip
-cleanup,fixes,logging
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r--src/gns/gnunet-service-gns.c224
1 files changed, 132 insertions, 92 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 101acb5a9..e236716ea 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -44,7 +44,7 @@
44#define GNUNET_MESSAGE_TYPE_GNS_CLIENT_RESULT 24 44#define GNUNET_MESSAGE_TYPE_GNS_CLIENT_RESULT 24
45 45
46/** 46/**
47 * A result list for namestore queries 47 * Handle to a currenty pending resolution
48 */ 48 */
49struct GNUNET_GNS_ResolverHandle 49struct GNUNET_GNS_ResolverHandle
50{ 50{
@@ -135,7 +135,7 @@ static int num_public_records = 3600;
135struct GNUNET_TIME_Relative dht_update_interval; 135struct GNUNET_TIME_Relative dht_update_interval;
136GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid = GNUNET_SCHEDULER_NO_TASK; 136GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid = GNUNET_SCHEDULER_NO_TASK;
137 137
138//Prototypes 138/* Prototypes */
139void reply_to_dns(struct GNUNET_GNS_ResolverHandle *answer, uint32_t rd_count, 139void reply_to_dns(struct GNUNET_GNS_ResolverHandle *answer, uint32_t rd_count,
140 const struct GNUNET_NAMESTORE_RecordData *rd); 140 const struct GNUNET_NAMESTORE_RecordData *rd);
141void resolve_name(struct GNUNET_GNS_ResolverHandle *rh); 141void resolve_name(struct GNUNET_GNS_ResolverHandle *rh);
@@ -149,8 +149,9 @@ void resolve_name(struct GNUNET_GNS_ResolverHandle *rh);
149static void 149static void
150shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 150shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
151{ 151{
152 //Kill zone task for it may make the scheduler hang 152 /* Kill zone task for it may make the scheduler hang */
153 GNUNET_SCHEDULER_cancel(zone_update_taskid); 153 GNUNET_SCHEDULER_cancel(zone_update_taskid);
154
154 GNUNET_DNS_disconnect(dns_handle); 155 GNUNET_DNS_disconnect(dns_handle);
155 GNUNET_NAMESTORE_disconnect(namestore_handle, 0); 156 GNUNET_NAMESTORE_disconnect(namestore_handle, 0);
156 GNUNET_DHT_disconnect(dht_handle); 157 GNUNET_DHT_disconnect(dht_handle);
@@ -222,6 +223,7 @@ process_authority_dht_result(void* cls,
222 return; 223 return;
223 224
224 //FIXME check expiration? 225 //FIXME check expiration?
226
225 rh = (struct GNUNET_GNS_ResolverHandle *)cls; 227 rh = (struct GNUNET_GNS_ResolverHandle *)cls;
226 nrb = (struct GNSNameRecordBlock*)data; 228 nrb = (struct GNSNameRecordBlock*)data;
227 229
@@ -241,19 +243,20 @@ process_authority_dht_result(void* cls,
241 rd[i].expiration = GNUNET_TIME_absolute_ntoh(rb->expiration); 243 rd[i].expiration = GNUNET_TIME_absolute_ntoh(rb->expiration);
242 rd[i].flags = ntohl(rb->flags); 244 rd[i].flags = ntohl(rb->flags);
243 245
244 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 246 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
245 "Got name: %s (wanted %s)\n", name, rh->authority_name); 247 "Got name: %s (wanted %s)\n", name, rh->authority_name);
246 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 248 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
247 "Got type: %d raw %d (wanted %d)\n", 249 "Got type: %d raw %d (wanted %d)\n",
248 rd[i].record_type, rb->type, GNUNET_GNS_RECORD_PKEY); 250 rd[i].record_type, rb->type, GNUNET_GNS_RECORD_PKEY);
249 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 251 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
250 "Got data length: %d\n", rd[i].data_size); 252 "Got data length: %d\n", rd[i].data_size);
251 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 253 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
252 "Got flag %d\n", rd[i].flags); 254 "Got flag %d\n", rd[i].flags);
255
253 if ((strcmp(name, rh->authority_name) == 0) && 256 if ((strcmp(name, rh->authority_name) == 0) &&
254 (rd[i].record_type == GNUNET_GNS_RECORD_PKEY)) 257 (rd[i].record_type == GNUNET_GNS_RECORD_PKEY))
255 { 258 {
256 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Authority found in DHT\n"); 259 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Authority found in DHT\n");
257 rh->answered = 1; 260 rh->answered = 1;
258 GNUNET_CRYPTO_hash( 261 GNUNET_CRYPTO_hash(
259 (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *)rd[i].data, 262 (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *)rd[i].data,
@@ -267,7 +270,7 @@ process_authority_dht_result(void* cls,
267 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); 270 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
268 GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); 271 GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone);
269 272
270 //Save to namestore 273 /* Save to namestore */
271 if (0 == GNUNET_CRYPTO_hash_cmp(&zone_hash, &zone)) 274 if (0 == GNUNET_CRYPTO_hash_cmp(&zone_hash, &zone))
272 { 275 {
273 GNUNET_NAMESTORE_record_put (namestore_handle, 276 GNUNET_NAMESTORE_record_put (namestore_handle,
@@ -287,7 +290,7 @@ process_authority_dht_result(void* cls,
287 resolve_name(rh); 290 resolve_name(rh);
288 return; 291 return;
289 } 292 }
290 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "No authority in records\n"); 293 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "No authority in records\n");
291 reply_to_dns(rh, 0, NULL); 294 reply_to_dns(rh, 0, NULL);
292} 295}
293 296
@@ -299,14 +302,16 @@ process_authority_dht_result(void* cls,
299 * @param name the name of the PKEY record 302 * @param name the name of the PKEY record
300 */ 303 */
301void 304void
302resolve_authority_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name) 305resolve_authority_dht(struct GNUNET_GNS_ResolverHandle *rh)
303{ 306{
304 uint32_t xquery; 307 uint32_t xquery;
305 struct GNUNET_TIME_Relative timeout; 308 struct GNUNET_TIME_Relative timeout;
306 GNUNET_HashCode name_hash; 309 GNUNET_HashCode name_hash;
307 GNUNET_HashCode lookup_key; 310 GNUNET_HashCode lookup_key;
308 311
309 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); 312 GNUNET_CRYPTO_hash(rh->authority_name,
313 strlen(rh->authority_name),
314 &name_hash);
310 GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key); 315 GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key);
311 316
312 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5); 317 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5);
@@ -314,7 +319,7 @@ resolve_authority_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name)
314 xquery = htonl(GNUNET_GNS_RECORD_PKEY); 319 xquery = htonl(GNUNET_GNS_RECORD_PKEY);
315 //FIXME how long to wait for results? 320 //FIXME how long to wait for results?
316 rh->get_handle = GNUNET_DHT_get_start(dht_handle, timeout, 321 rh->get_handle = GNUNET_DHT_get_start(dht_handle, timeout,
317 GNUNET_BLOCK_TYPE_GNS_NAMERECORD, //FIXME todo 322 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
318 &lookup_key, 323 &lookup_key,
319 5, //Replication level FIXME 324 5, //Replication level FIXME
320 GNUNET_DHT_RO_NONE, 325 GNUNET_DHT_RO_NONE,
@@ -358,7 +363,8 @@ process_name_dht_result(void* cls,
358 char* name = NULL; 363 char* name = NULL;
359 int i; 364 int i;
360 GNUNET_HashCode zone, name_hash; 365 GNUNET_HashCode zone, name_hash;
361 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "got dht result (size=%d)\n", size); 366 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "got dht result (size=%d)\n", size);
367
362 if (data == NULL) 368 if (data == NULL)
363 return; 369 return;
364 370
@@ -382,16 +388,18 @@ process_name_dht_result(void* cls,
382 rd[i].data = (char*)&rb[1]; 388 rd[i].data = (char*)&rb[1];
383 rd[i].expiration = GNUNET_TIME_absolute_ntoh(rb->expiration); 389 rd[i].expiration = GNUNET_TIME_absolute_ntoh(rb->expiration);
384 rd[i].flags = ntohl(rb->flags); 390 rd[i].flags = ntohl(rb->flags);
385 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 391
392 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
386 "Got name: %s (wanted %s)\n", name, rh->name); 393 "Got name: %s (wanted %s)\n", name, rh->name);
387 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 394 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
388 "Got type: %d raw %d (wanted %d)\n", 395 "Got type: %d raw %d (wanted %d)\n",
389 rd[i].record_type, rb->type, rh->query->type); 396 rd[i].record_type, rb->type, rh->query->type);
390 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 397 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
391 "Got data length: %d\n", rd[i].data_size); 398 "Got data length: %d\n", rd[i].data_size);
392 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 399 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
393 "Got flag %d\n", rd[i].flags); 400 "Got flag %d\n", rd[i].flags);
394 //FIXME class? 401
402 /* FIXME class? */
395 if ((strcmp(name, rh->name) == 0) && 403 if ((strcmp(name, rh->name) == 0) &&
396 (rd[i].record_type == rh->query->type)) 404 (rd[i].record_type == rh->query->type))
397 { 405 {
@@ -405,10 +413,12 @@ process_name_dht_result(void* cls,
405 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); 413 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
406 GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); 414 GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone);
407 415
408 //FIXME check pubkey against existing key in namestore? 416 /**
409 //https://gnunet.org/bugs/view.php?id=2179 417 * FIXME check pubkey against existing key in namestore?
418 * https://gnunet.org/bugs/view.php?id=2179
419 */
410 420
411 //Save to namestore 421 /* Save to namestore */
412 GNUNET_NAMESTORE_record_put (namestore_handle, 422 GNUNET_NAMESTORE_record_put (namestore_handle,
413 &nrb->public_key, 423 &nrb->public_key,
414 name, 424 name,
@@ -445,7 +455,8 @@ resolve_name_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name)
445 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); 455 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
446 GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key); 456 GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key);
447 GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string); 457 GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string);
448 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 458
459 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
449 "starting dht lookup for %s with key: %s\n", 460 "starting dht lookup for %s with key: %s\n",
450 name, (char*)&lookup_key_string); 461 name, (char*)&lookup_key_string);
451 462
@@ -454,7 +465,7 @@ resolve_name_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name)
454 xquery = htonl(rh->query->type); 465 xquery = htonl(rh->query->type);
455 //FIXME how long to wait for results? 466 //FIXME how long to wait for results?
456 rh->get_handle = GNUNET_DHT_get_start(dht_handle, timeout, 467 rh->get_handle = GNUNET_DHT_get_start(dht_handle, timeout,
457 GNUNET_BLOCK_TYPE_GNS_NAMERECORD, //FIXME todo 468 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
458 &lookup_key, 469 &lookup_key,
459 5, //Replication level FIXME 470 5, //Replication level FIXME
460 GNUNET_DHT_RO_NONE, 471 GNUNET_DHT_RO_NONE,
@@ -496,7 +507,9 @@ process_authority_lookup(void* cls,
496 GNUNET_HashCode zone; 507 GNUNET_HashCode zone;
497 508
498 rh = (struct GNUNET_GNS_ResolverHandle *)cls; 509 rh = (struct GNUNET_GNS_ResolverHandle *)cls;
499 GNUNET_CRYPTO_hash(key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); 510 GNUNET_CRYPTO_hash(key,
511 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
512 &zone);
500 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); 513 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
501 514
502 /** 515 /**
@@ -512,10 +525,11 @@ process_authority_lookup(void* cls,
512 if (0 != GNUNET_CRYPTO_hash_cmp(&zone, &zone_hash) && 525 if (0 != GNUNET_CRYPTO_hash_cmp(&zone, &zone_hash) &&
513 (remaining_time.rel_value == 0)) 526 (remaining_time.rel_value == 0))
514 { 527 {
515 resolve_authority_dht(rh, name); 528 resolve_authority_dht(rh);
516 return; 529 return;
517 } 530 }
518 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Authority unknown\n"); 531 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Authority %s unknown\n",
532 rh->authority_name);
519 reply_to_dns(rh, 0, NULL); 533 reply_to_dns(rh, 0, NULL);
520 return; 534 return;
521 } 535 }
@@ -529,8 +543,7 @@ process_authority_lookup(void* cls,
529 for (i=0; i<rd_count;i++) 543 for (i=0; i<rd_count;i++)
530 { 544 {
531 545
532 if (strcmp(name, rh->query->name) && rd[i].record_type 546 if (rd[i].record_type != GNUNET_GNS_RECORD_PKEY)
533 != GNUNET_GNS_RECORD_PKEY)
534 continue; 547 continue;
535 548
536 if ((GNUNET_TIME_absolute_get_remaining (rd[i].expiration)).rel_value 549 if ((GNUNET_TIME_absolute_get_remaining (rd[i].expiration)).rel_value
@@ -541,14 +554,18 @@ process_authority_lookup(void* cls,
541 { 554 {
542 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 555 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
543 "This dht entry is expired. Refreshing\n"); 556 "This dht entry is expired. Refreshing\n");
544 resolve_authority_dht(rh, name); 557 resolve_authority_dht(rh);
545 } 558 }
546 559
547 continue; 560 continue;
548 } 561 }
549 562
563 /**
564 * Resolve rest of query with new authority
565 */
550 GNUNET_assert(rd[i].record_type == GNUNET_GNS_RECORD_PKEY); 566 GNUNET_assert(rd[i].record_type == GNUNET_GNS_RECORD_PKEY);
551 GNUNET_CRYPTO_hash(rd[i].data, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 567 GNUNET_CRYPTO_hash(rd[i].data,
568 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
552 &rh->authority); 569 &rh->authority);
553 resolve_name(rh); 570 resolve_name(rh);
554 return; 571 return;
@@ -558,9 +575,8 @@ process_authority_lookup(void* cls,
558 /** 575 /**
559 * no answers found 576 * no answers found
560 */ 577 */
561 578 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
562 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 579 "Authority lookup successful but no PKEY... never get here\n");
563 "Authority lookup successful but no PKEY... never get here?\n");
564 reply_to_dns(rh, 0, NULL); 580 reply_to_dns(rh, 0, NULL);
565} 581}
566 582
@@ -586,15 +602,21 @@ reply_to_dns(struct GNUNET_GNS_ResolverHandle *rh, uint32_t rd_count,
586 packet->answers = answer_records; 602 packet->answers = answer_records;
587 packet->additional_records = additional_records; 603 packet->additional_records = additional_records;
588 604
605 /**
606 * Put records in the DNS packet and modify it
607 * to a response
608 */
589 len = sizeof(struct GNUNET_DNSPARSER_Record*); 609 len = sizeof(struct GNUNET_DNSPARSER_Record*);
590 for (i=0; i < rd_count; i++) 610 for (i=0; i < rd_count; i++)
591 { 611 {
592 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 612
613 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
593 "Adding type %d to DNS response\n", rd[i].record_type); 614 "Adding type %d to DNS response\n", rd[i].record_type);
594 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Name: %s\n", rh->name); 615 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Name: %s\n", rh->name);
595 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "QName: %s\n", rh->query->name); 616 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "QName: %s\n", rh->query->name);
596 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Record %d/%d\n", i+1, rd_count); 617 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Record %d/%d\n", i+1, rd_count);
597 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Record len %d\n", rd[i].data_size); 618 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Record len %d\n", rd[i].data_size);
619
598 if (rd[i].record_type == rh->query->type) 620 if (rd[i].record_type == rh->query->type)
599 { 621 {
600 answer_records[i].name = rh->query->name; 622 answer_records[i].name = rh->query->name;
@@ -613,16 +635,15 @@ reply_to_dns(struct GNUNET_GNS_ResolverHandle *rh, uint32_t rd_count,
613 additional_records[i].expiration_time = rd[i].expiration; 635 additional_records[i].expiration_time = rd[i].expiration;
614 additional_records[i].class = GNUNET_DNSPARSER_CLASS_INTERNET;//hmmn 636 additional_records[i].class = GNUNET_DNSPARSER_CLASS_INTERNET;//hmmn
615 } 637 }
616 //GNUNET_free(i->record); DO this later!
617 } 638 }
618 639
619 packet->num_answers = rh->answered; //answer->num_records; 640 packet->num_answers = rh->answered;
620 packet->num_additional_records = rd_count-(rh->answered); 641 packet->num_additional_records = rd_count-(rh->answered);
621 642
622 if (0 == GNUNET_CRYPTO_hash_cmp(&rh->authority, &zone_hash)) 643 if (0 == GNUNET_CRYPTO_hash_cmp(&rh->authority, &zone_hash))
623 packet->flags.authoritative_answer = 1; 644 packet->flags.authoritative_answer = 1;
624 else 645 else
625 packet->flags.authoritative_answer = 0; 646 packet->flags.authoritative_answer = 0;
626 647
627 if (rd == NULL) 648 if (rd == NULL)
628 packet->flags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NAME_ERROR; 649 packet->flags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NAME_ERROR;
@@ -631,25 +652,27 @@ reply_to_dns(struct GNUNET_GNS_ResolverHandle *rh, uint32_t rd_count,
631 652
632 packet->flags.query_or_response = 1; 653 packet->flags.query_or_response = 1;
633 654
634 //FIXME this is silently discarded 655
635 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 656 /**
657 * Reply to DNS
658 */
659 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
636 "Building DNS response\n"); 660 "Building DNS response\n");
637 ret = GNUNET_DNSPARSER_pack (packet, 661 ret = GNUNET_DNSPARSER_pack (packet,
638 1024, /* FIXME magic from dns redirector */ 662 1024, /* FIXME magic from dns redirector */
639 &buf, 663 &buf,
640 &len); 664 &len);
641 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 665 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
642 "Built DNS response! (ret=%d,len=%d)\n", ret, len); 666 "Built DNS response! (ret=%d,len=%d)\n", ret, len);
643 if (ret == GNUNET_OK) 667 if (ret == GNUNET_OK)
644 { 668 {
645 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 669 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
646 "Answering DNS request\n"); 670 "Answering DNS request\n");
647 GNUNET_DNS_request_answer(rh->request_handle, 671 GNUNET_DNS_request_answer(rh->request_handle,
648 len, 672 len,
649 buf); 673 buf);
650 //GNUNET_free(answer); 674 //GNUNET_free(answer);
651 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Answered DNS request\n"); 675 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answered DNS request\n");
652 //FIXME return code, free datastructures
653 } 676 }
654 else 677 else
655 { 678 {
@@ -657,15 +680,14 @@ reply_to_dns(struct GNUNET_GNS_ResolverHandle *rh, uint32_t rd_count,
657 "Error building DNS response! (ret=%d)", ret); 680 "Error building DNS response! (ret=%d)", ret);
658 } 681 }
659 682
660 //FIXME into free_resolver(rh)
661 GNUNET_free(rh->name); 683 GNUNET_free(rh->name);
662 GNUNET_free(rh); 684 GNUNET_free(rh);
663} 685}
664 686
665 687
666/** 688/**
667 * Namestore calls this function if we have an entry for this name. 689 * Namestore calls this function if we have record for this name.
668 * (or data=null to indicate the lookup has finished 690 * (or with rd_count=0 to indicate no matches)
669 * 691 *
670 * @param cls the pending query 692 * @param cls the pending query
671 * @param key the key of the zone we did the lookup 693 * @param key the key of the zone we did the lookup
@@ -688,18 +710,18 @@ process_authoritative_result(void* cls,
688 GNUNET_HashCode zone; 710 GNUNET_HashCode zone;
689 711
690 rh = (struct GNUNET_GNS_ResolverHandle *) cls; 712 rh = (struct GNUNET_GNS_ResolverHandle *) cls;
691 GNUNET_CRYPTO_hash(key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); 713 GNUNET_CRYPTO_hash(key,
714 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
715 &zone);
692 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); 716 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
693 717
694 //FIXME Handle results in rd
695
696 if (rd_count == 0) 718 if (rd_count == 0)
697 { 719 {
698 /** 720 /**
699 * Lookup terminated and no results 721 * Lookup terminated and no results
700 * -> DHT Phase unless data is recent 722 * -> DHT Phase unless data is recent
701 */ 723 */
702 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 724 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
703 "Namestore lookup for %s terminated without results\n", name); 725 "Namestore lookup for %s terminated without results\n", name);
704 726
705 /** 727 /**
@@ -710,14 +732,14 @@ process_authoritative_result(void* cls,
710 { 732 {
711 if (remaining_time.rel_value == 0) 733 if (remaining_time.rel_value == 0)
712 { 734 {
713 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 735 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
714 "trying dht...\n"); 736 "trying dht...\n");
715 resolve_name_dht(rh, name); 737 resolve_name_dht(rh, name);
716 return; 738 return;
717 } 739 }
718 else 740 else
719 { 741 {
720 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 742 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
721 "Record is still recent. No DHT lookup\n"); 743 "Record is still recent. No DHT lookup\n");
722 } 744 }
723 } 745 }
@@ -726,26 +748,26 @@ process_authoritative_result(void* cls,
726 * Our zone and no result? Cannot resolve TT 748 * Our zone and no result? Cannot resolve TT
727 */ 749 */
728 GNUNET_assert(rh->answered == 0); 750 GNUNET_assert(rh->answered == 0);
729 reply_to_dns(rh, 0, NULL); //answered should be 0 751 reply_to_dns(rh, 0, NULL);
730 return; 752 return;
731 753
732 } 754 }
733 else 755 else
734 { 756 {
735 757
736 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 758 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
737 "Processing additional result %s from namestore\n", name); 759 "Processing additional result %s from namestore\n", name);
738 int i; 760 int i;
739 for (i=0; i<rd_count;i++) 761 for (i=0; i<rd_count;i++)
740 { 762 {
741 763
742 if (strcmp(name, rh->query->name) && rd[i].record_type != rh->query->type) 764 if ((strcmp(name, rh->query->name) == 0)
765 && (rd[i].record_type != rh->query->type))
743 continue; 766 continue;
744 767
745 if ((GNUNET_TIME_absolute_get_remaining (rd[i].expiration)).rel_value 768 if ((GNUNET_TIME_absolute_get_remaining (rd[i].expiration)).rel_value
746 == 0) 769 == 0)
747 { 770 {
748 //FIXME there is a catch here...
749 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This record is expired. Skipping\n"); 771 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This record is expired. Skipping\n");
750 continue; 772 continue;
751 } 773 }
@@ -766,7 +788,7 @@ process_authoritative_result(void* cls,
766 return; 788 return;
767 } 789 }
768 790
769 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Found %d answer(s) to query!\n", 791 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found %d answer(s) to query!\n",
770 rh->answered); 792 rh->answered);
771 793
772 reply_to_dns(rh, rd_count, rd); 794 reply_to_dns(rh, rd_count, rd);
@@ -829,10 +851,9 @@ char* pop_tld(char* name)
829 * The first phase of resolution. 851 * The first phase of resolution.
830 * First check if the name is canonical. 852 * First check if the name is canonical.
831 * If it is then try to resolve directly. 853 * If it is then try to resolve directly.
832 * If not then first have to resolve the authoritative entities. 854 * If not then we first have to resolve the authoritative entities.
833 * 855 *
834 * @param rh the pending lookup 856 * @param rh the pending lookup
835 * @param zone the zone we are currently resolving in
836 */ 857 */
837void 858void
838resolve_name(struct GNUNET_GNS_ResolverHandle *rh) 859resolve_name(struct GNUNET_GNS_ResolverHandle *rh)
@@ -862,8 +883,6 @@ resolve_name(struct GNUNET_GNS_ResolverHandle *rh)
862 883
863/** 884/**
864 * Entry point for name resolution 885 * Entry point for name resolution
865 * Lookup local namestore of our zone.
866 *
867 * Setup a new query and try to resolve 886 * Setup a new query and try to resolve
868 * 887 *
869 * @param request the request handle of the DNS request from a client 888 * @param request the request handle of the DNS request from a client
@@ -877,7 +896,7 @@ start_resolution(struct GNUNET_DNS_RequestHandle *request,
877{ 896{
878 struct GNUNET_GNS_ResolverHandle *rh; 897 struct GNUNET_GNS_ResolverHandle *rh;
879 898
880 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting resolution for (%s)!\n", 899 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting resolution for (%s)!\n",
881 q->name); 900 q->name);
882 901
883 rh = GNUNET_malloc(sizeof (struct GNUNET_GNS_ResolverHandle)); 902 rh = GNUNET_malloc(sizeof (struct GNUNET_GNS_ResolverHandle));
@@ -916,12 +935,12 @@ handle_dns_request(void *cls,
916 struct GNUNET_DNSPARSER_Packet *p; 935 struct GNUNET_DNSPARSER_Packet *p;
917 char *tldoffset; 936 char *tldoffset;
918 937
919 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Hijacked a DNS request...processing\n"); 938 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacked a DNS request...processing\n");
920 p = GNUNET_DNSPARSER_parse (request, request_length); 939 p = GNUNET_DNSPARSER_parse (request, request_length);
921 940
922 if (NULL == p) 941 if (NULL == p)
923 { 942 {
924 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 943 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
925 "Received malformed DNS packet, leaving it untouched\n"); 944 "Received malformed DNS packet, leaving it untouched\n");
926 GNUNET_DNS_request_forward (rh); 945 GNUNET_DNS_request_forward (rh);
927 return; 946 return;
@@ -953,7 +972,10 @@ handle_dns_request(void *cls,
953 ">1 queriy in DNS packet... odd. We only process #1\n"); 972 ">1 queriy in DNS packet... odd. We only process #1\n");
954 } 973 }
955 974
956 975
976 /**
977 * Check for .gnunet
978 */
957 tldoffset = p->queries[0].name + strlen(p->queries[0].name); 979 tldoffset = p->queries[0].name + strlen(p->queries[0].name);
958 980
959 while ((*tldoffset) != '.') 981 while ((*tldoffset) != '.')
@@ -968,7 +990,7 @@ handle_dns_request(void *cls,
968 /** 990 /**
969 * This request does not concern us. Forward to real DNS. 991 * This request does not concern us. Forward to real DNS.
970 */ 992 */
971 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 993 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
972 "Request for %s is forwarded to DNS\n", p->queries[0].name); 994 "Request for %s is forwarded to DNS\n", p->queries[0].name);
973 GNUNET_DNS_request_forward (rh); 995 GNUNET_DNS_request_forward (rh);
974 } 996 }
@@ -977,11 +999,13 @@ handle_dns_request(void *cls,
977 999
978/** 1000/**
979 * test function that stores some data in the namestore 1001 * test function that stores some data in the namestore
1002 * This will also be replaced by a test progrm that
1003 * directl interfaces with the namestore
980 */ 1004 */
981void 1005void
982put_some_records(void) 1006put_some_records(void)
983{ 1007{
984 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Populating namestore\n"); 1008 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Populating namestore\n");
985 /* put an A record into namestore FIXME use gnunet.org */ 1009 /* put an A record into namestore FIXME use gnunet.org */
986 char* ipB = "5.6.7.8"; 1010 char* ipB = "5.6.7.8";
987 1011
@@ -1003,16 +1027,29 @@ put_some_records(void)
1003 NULL); 1027 NULL);
1004} 1028}
1005 1029
1030/**
1031 * Method called periodicattluy that triggers
1032 * iteration over root zone
1033 *
1034 * @param cls closure
1035 * @param tc task context
1036 */
1006void 1037void
1007update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1038update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1008{ 1039{
1009 GNUNET_NAMESTORE_zone_iterator_next(namestore_iter); 1040 GNUNET_NAMESTORE_zone_iterator_next(namestore_iter);
1010} 1041}
1011 1042
1043/**
1044 * Continuation for DHT put
1045 *
1046 * @param cls closure
1047 * @param tc task context
1048 */
1012void 1049void
1013record_dht_put(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1050record_dht_put(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1014{ 1051{
1015 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "put request transmitted\n"); 1052 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "put request transmitted\n");
1016} 1053}
1017 1054
1018/* prototype */ 1055/* prototype */
@@ -1040,7 +1077,8 @@ put_gns_record(void *cls,
1040 const struct GNUNET_NAMESTORE_RecordData *rd, 1077 const struct GNUNET_NAMESTORE_RecordData *rd,
1041 const struct GNUNET_CRYPTO_RsaSignature *signature) 1078 const struct GNUNET_CRYPTO_RsaSignature *signature)
1042{ 1079{
1043 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Putting records into the DHT\n"); 1080 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1081 "Putting records for %s into the DHT\n", name);
1044 struct GNUNET_TIME_Relative timeout; 1082 struct GNUNET_TIME_Relative timeout;
1045 struct GNSNameRecordBlock *nrb; 1083 struct GNSNameRecordBlock *nrb;
1046 struct GNSRecordBlock *rb; 1084 struct GNSRecordBlock *rb;
@@ -1053,7 +1091,7 @@ put_gns_record(void *cls,
1053 /* we're done */ 1091 /* we're done */
1054 if (NULL == name) 1092 if (NULL == name)
1055 { 1093 {
1056 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Zone iteration finished\n"); 1094 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Zone iteration finished\n");
1057 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); 1095 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
1058 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, 1096 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start,
1059 NULL); 1097 NULL);
@@ -1086,7 +1124,7 @@ put_gns_record(void *cls,
1086 1124
1087 for (i=0; i<rd_count; i++) 1125 for (i=0; i<rd_count; i++)
1088 { 1126 {
1089 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "putting record with type %d\n", 1127 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Read record with type %d\n",
1090 rd[i].record_type); 1128 rd[i].record_type);
1091 rb->type = htonl(rd[i].record_type); 1129 rb->type = htonl(rd[i].record_type);
1092 rb->expiration = GNUNET_TIME_absolute_hton(rd[i].expiration); 1130 rb->expiration = GNUNET_TIME_absolute_hton(rd[i].expiration);
@@ -1101,22 +1139,16 @@ put_gns_record(void *cls,
1101 * DHT_WAIT_TIMEOUT 1139 * DHT_WAIT_TIMEOUT
1102 */ 1140 */
1103 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20); 1141 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20);
1142
1143 /*
1144 * calculate DHT key: H(name) xor H(pubkey)
1145 */
1104 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); 1146 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
1105 GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash); 1147 GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash);
1106 GNUNET_CRYPTO_hash_to_enc (&xor_hash, &xor_hash_string); 1148 GNUNET_CRYPTO_hash_to_enc (&xor_hash, &xor_hash_string);
1107 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1149 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1108 "putting records for %s under key: %s with size %d\n", 1150 "putting records for %s under key: %s with size %d\n",
1109 name, (char*)&xor_hash_string, rd_payload_length); 1151 name, (char*)&xor_hash_string, rd_payload_length);
1110 GNUNET_CRYPTO_hash_to_enc (&zone_hash, &xor_hash_string);
1111 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Pub key: %s\n", (char*)&xor_hash_string);
1112 GNUNET_CRYPTO_hash_to_enc (&name_hash, &xor_hash_string);
1113 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Name: %s\n", (char*)&xor_hash_string);
1114
1115 GNUNET_HashCode key_hash;
1116 GNUNET_CRYPTO_hash(key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1117 &key_hash);
1118 GNUNET_CRYPTO_hash_to_enc (&key_hash, &xor_hash_string);
1119 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Pub2: %s\n", (char*)&xor_hash_string);
1120 1152
1121 GNUNET_DHT_put (dht_handle, &xor_hash, 1153 GNUNET_DHT_put (dht_handle, &xor_hash,
1122 5, //replication level 1154 5, //replication level
@@ -1140,6 +1172,15 @@ put_gns_record(void *cls,
1140 1172
1141} 1173}
1142 1174
1175/**
1176 * Puts a single trusted entity into the
1177 * namestore. Will be replaced in a testcase
1178 * that directly interacts with a persistent
1179 * namestore.
1180 *
1181 * @param name name of entity
1182 * @param keyfile keyfile
1183 */
1143void 1184void
1144put_trusted(char* name, char* keyfile) 1185put_trusted(char* name, char* keyfile)
1145{ 1186{
@@ -1174,7 +1215,7 @@ put_trusted(char* name, char* keyfile)
1174static void 1215static void
1175update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1216update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1176{ 1217{
1177 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Update zone!\n"); 1218 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting DHT zone update!\n");
1178 if (0 == num_public_records) 1219 if (0 == num_public_records)
1179 { 1220 {
1180 dht_update_interval = GNUNET_TIME_relative_multiply( 1221 dht_update_interval = GNUNET_TIME_relative_multiply(
@@ -1208,7 +1249,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1208 const struct GNUNET_CONFIGURATION_Handle *c) 1249 const struct GNUNET_CONFIGURATION_Handle *c)
1209{ 1250{
1210 1251
1211 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Init GNS\n"); 1252 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initializing GNS\n");
1253
1212 char* keyfile; 1254 char* keyfile;
1213 char* trusted_entities; 1255 char* trusted_entities;
1214 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; 1256 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
@@ -1224,7 +1266,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1224 1266
1225 zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 1267 zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
1226 GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey); 1268 GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey);
1227 //zone_key = GNUNET_CRYPTO_rsa_key_create ();
1228 1269
1229 GNUNET_CRYPTO_hash(&pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1270 GNUNET_CRYPTO_hash(&pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1230 &zone_hash); 1271 &zone_hash);
@@ -1304,7 +1345,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1304 } 1345 }
1305 else 1346 else
1306 { 1347 {
1307 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Keyfile %s does not exist!\n", 1348 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Keyfile %s does not exist!\n",
1308 trusted_key); 1349 trusted_key);
1309 //put_trusted(trusted_name, trusted_key); //FIXME for testing 1350 //put_trusted(trusted_name, trusted_key); //FIXME for testing
1310 } 1351 }
@@ -1332,7 +1373,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1332 dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1373 dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
1333 1); 1374 1);
1334 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL); 1375 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL);
1335 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "GNS Init done!\n");
1336 1376
1337} 1377}
1338 1378