aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht_neighbours.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c982
1 files changed, 454 insertions, 528 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 02124b488..9ebf16400 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -275,7 +275,7 @@ struct P2PPendingMessage
275 275
276 /** 276 /**
277 * Actual message to be sent, allocated at the end of the struct: 277 * Actual message to be sent, allocated at the end of the struct:
278 * // msg = (cast) &pm[1]; 278 * // msg = (cast) &pm[1];
279 * // memcpy (&pm[1], data, len); 279 * // memcpy (&pm[1], data, len);
280 */ 280 */
281 const struct GNUNET_MessageHeader *msg; 281 const struct GNUNET_MessageHeader *msg;
@@ -399,7 +399,7 @@ static GNUNET_SCHEDULER_TaskIdentifier find_peer_task;
399 399
400/** 400/**
401 * Identity of this peer. 401 * Identity of this peer.
402 */ 402 */
403static struct GNUNET_PeerIdentity my_identity; 403static struct GNUNET_PeerIdentity my_identity;
404 404
405/** 405/**
@@ -428,11 +428,11 @@ find_bucket (const GNUNET_HashCode * hc)
428 428
429 bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, hc); 429 bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, hc);
430 if (bits == MAX_BUCKETS) 430 if (bits == MAX_BUCKETS)
431 { 431 {
432 /* How can all bits match? Got my own ID? */ 432 /* How can all bits match? Got my own ID? */
433 GNUNET_break (0); 433 GNUNET_break (0);
434 return GNUNET_SYSERR; 434 return GNUNET_SYSERR;
435 } 435 }
436 return MAX_BUCKETS - bits - 1; 436 return MAX_BUCKETS - bits - 1;
437} 437}
438 438
@@ -442,7 +442,7 @@ find_bucket (const GNUNET_HashCode * hc)
442 * 442 *
443 * @param cls the 'struct PeerInfo' of the peer 443 * @param cls the 'struct PeerInfo' of the peer
444 * @param tc scheduler context. 444 * @param tc scheduler context.
445 */ 445 */
446static void 446static void
447update_core_preference (void *cls, 447update_core_preference (void *cls,
448 const struct GNUNET_SCHEDULER_TaskContext *tc) 448 const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -454,10 +454,10 @@ update_core_preference (void *cls,
454 454
455 peer->preference_task = GNUNET_SCHEDULER_NO_TASK; 455 peer->preference_task = GNUNET_SCHEDULER_NO_TASK;
456 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 456 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
457 return; 457 return;
458 matching = 458 matching =
459 GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, 459 GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey,
460 &peer->id.hashPubKey); 460 &peer->id.hashPubKey);
461 if (matching >= 64) 461 if (matching >= 64)
462 matching = 63; 462 matching = 63;
463 bucket = find_bucket (&peer->id.hashPubKey); 463 bucket = find_bucket (&peer->id.hashPubKey);
@@ -469,22 +469,21 @@ update_core_preference (void *cls,
469 preference = (1LL << matching) / k_buckets[bucket].peers_size; 469 preference = (1LL << matching) / k_buckets[bucket].peers_size;
470 } 470 }
471 if (preference == 0) 471 if (preference == 0)
472 { 472 {
473 peer->preference_task 473 peer->preference_task =
474 = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, 474 GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
475 &update_core_preference, peer); 475 &update_core_preference, peer);
476 return; 476 return;
477 } 477 }
478 GNUNET_STATISTICS_update (GDS_stats, 478 GNUNET_STATISTICS_update (GDS_stats,
479 gettext_noop ("# Preference updates given to core"), 1, 479 gettext_noop ("# Preference updates given to core"),
480 GNUNET_NO); 480 1, GNUNET_NO);
481 GNUNET_ATS_change_preference (atsAPI, &peer->id, 481 GNUNET_ATS_change_preference (atsAPI, &peer->id,
482 GNUNET_ATS_PREFERENCE_BANDWIDTH, 482 GNUNET_ATS_PREFERENCE_BANDWIDTH,
483 (double) preference, 483 (double) preference, GNUNET_ATS_PREFERENCE_END);
484 GNUNET_ATS_PREFERENCE_END); 484 peer->preference_task =
485 peer->preference_task 485 GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
486 = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, 486 &update_core_preference, peer);
487 &update_core_preference, peer);
488 487
489 488
490} 489}
@@ -525,9 +524,8 @@ add_known_to_bloom (void *cls, const GNUNET_HashCode * key, void *value)
525 GNUNET_BLOCK_mingle_hash (key, ctx->bf_mutator, &mh); 524 GNUNET_BLOCK_mingle_hash (key, ctx->bf_mutator, &mh);
526#if DEBUG_DHT 525#if DEBUG_DHT
527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
528 "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n", 527 "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n",
529 GNUNET_h2s (key), 528 GNUNET_h2s (key), ctx->bf_mutator);
530 ctx->bf_mutator);
531#endif 529#endif
532 GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh); 530 GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh);
533 return GNUNET_YES; 531 return GNUNET_YES;
@@ -553,46 +551,46 @@ send_find_peer_message (void *cls,
553 find_peer_task = GNUNET_SCHEDULER_NO_TASK; 551 find_peer_task = GNUNET_SCHEDULER_NO_TASK;
554 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 552 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
555 return; 553 return;
556 if (newly_found_peers > bucket_size) 554 if (newly_found_peers > bucket_size)
557 { 555 {
558 /* If we are finding many peers already, no need to send out our request right now! */ 556 /* If we are finding many peers already, no need to send out our request right now! */
559 find_peer_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 557 find_peer_task =
560 &send_find_peer_message, NULL); 558 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
559 &send_find_peer_message, NULL);
561 newly_found_peers = 0; 560 newly_found_peers = 0;
562 return; 561 return;
563 } 562 }
564 bcc.bf_mutator = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 563 bcc.bf_mutator =
564 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
565 bcc.bloom = 565 bcc.bloom =
566 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, GNUNET_CONSTANTS_BLOOMFILTER_K); 566 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
567 GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, 567 GNUNET_CONSTANTS_BLOOMFILTER_K);
568 &add_known_to_bloom, 568 GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, &add_known_to_bloom,
569 &bcc); 569 &bcc);
570 GNUNET_STATISTICS_update (GDS_stats, 570 GNUNET_STATISTICS_update (GDS_stats,
571 gettext_noop ("# FIND PEER messages initiated"), 1, 571 gettext_noop ("# FIND PEER messages initiated"), 1,
572 GNUNET_NO); 572 GNUNET_NO);
573 peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 573 peer_bf =
574 DHT_BLOOM_SIZE, 574 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
575 GNUNET_CONSTANTS_BLOOMFILTER_K); 575 GNUNET_CONSTANTS_BLOOMFILTER_K);
576 // FIXME: pass priority!? 576 // FIXME: pass priority!?
577 GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, 577 GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO,
578 GNUNET_DHT_RO_FIND_PEER, 578 GNUNET_DHT_RO_FIND_PEER,
579 FIND_PEER_REPLICATION_LEVEL, 579 FIND_PEER_REPLICATION_LEVEL, 0,
580 0, 580 &my_identity.hashPubKey, NULL, 0, bcc.bloom,
581 &my_identity.hashPubKey, 581 bcc.bf_mutator, peer_bf);
582 NULL, 0,
583 bcc.bloom, bcc.bf_mutator,
584 peer_bf);
585 GNUNET_CONTAINER_bloomfilter_free (peer_bf); 582 GNUNET_CONTAINER_bloomfilter_free (peer_bf);
586 GNUNET_CONTAINER_bloomfilter_free (bcc.bloom); 583 GNUNET_CONTAINER_bloomfilter_free (bcc.bloom);
587 /* schedule next round */ 584 /* schedule next round */
588 next_send_time.rel_value = 585 next_send_time.rel_value =
589 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + 586 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
590 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 587 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
591 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / (newly_found_peers+1)); 588 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value /
589 (newly_found_peers + 1));
592 newly_found_peers = 0; 590 newly_found_peers = 0;
593 find_peer_task = GNUNET_SCHEDULER_add_delayed (next_send_time, 591 find_peer_task =
594 &send_find_peer_message, 592 GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_peer_message,
595 NULL); 593 NULL);
596} 594}
597 595
598 596
@@ -607,7 +605,7 @@ send_find_peer_message (void *cls,
607static void 605static void
608handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 606handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
609 const struct GNUNET_ATS_Information *atsi, 607 const struct GNUNET_ATS_Information *atsi,
610 unsigned int atsi_count) 608 unsigned int atsi_count)
611{ 609{
612 struct PeerInfo *ret; 610 struct PeerInfo *ret;
613 int peer_bucket; 611 int peer_bucket;
@@ -616,10 +614,8 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
616 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) 614 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
617 return; 615 return;
618#if DEBUG_DHT 616#if DEBUG_DHT
619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected %s to %s\n",
620 "Connected %s to %s\n", 618 GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey));
621 GNUNET_i2s (&my_identity),
622 GNUNET_h2s (&peer->hashPubKey));
623#endif 619#endif
624 if (GNUNET_YES == 620 if (GNUNET_YES ==
625 GNUNET_CONTAINER_multihashmap_contains (all_known_peers, 621 GNUNET_CONTAINER_multihashmap_contains (all_known_peers,
@@ -628,11 +624,10 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
628 GNUNET_break (0); 624 GNUNET_break (0);
629 return; 625 return;
630 } 626 }
631 GNUNET_STATISTICS_update (GDS_stats, 627 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers connected"), 1,
632 gettext_noop ("# Peers connected"), 1, 628 GNUNET_NO);
633 GNUNET_NO);
634 peer_bucket = find_bucket (&peer->hashPubKey); 629 peer_bucket = find_bucket (&peer->hashPubKey);
635 GNUNET_assert ( (peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS) ); 630 GNUNET_assert ((peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS));
636 ret = GNUNET_malloc (sizeof (struct PeerInfo)); 631 ret = GNUNET_malloc (sizeof (struct PeerInfo));
637#if 0 632#if 0
638 ret->latency = latency; 633 ret->latency = latency;
@@ -640,25 +635,23 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
640#endif 635#endif
641 ret->id = *peer; 636 ret->id = *peer;
642 GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head, 637 GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head,
643 k_buckets[peer_bucket].tail, ret); 638 k_buckets[peer_bucket].tail, ret);
644 k_buckets[peer_bucket].peers_size++; 639 k_buckets[peer_bucket].peers_size++;
645 closest_bucket = GNUNET_MAX (closest_bucket, 640 closest_bucket = GNUNET_MAX (closest_bucket, peer_bucket);
646 peer_bucket); 641 if ((peer_bucket > 0) && (k_buckets[peer_bucket].peers_size <= bucket_size))
647 if ( (peer_bucket > 0) &&
648 (k_buckets[peer_bucket].peers_size <= bucket_size) )
649 { 642 {
650 ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference, ret); 643 ret->preference_task =
644 GNUNET_SCHEDULER_add_now (&update_core_preference, ret);
651 newly_found_peers++; 645 newly_found_peers++;
652 } 646 }
653 GNUNET_assert (GNUNET_OK == 647 GNUNET_assert (GNUNET_OK ==
654 GNUNET_CONTAINER_multihashmap_put (all_known_peers, 648 GNUNET_CONTAINER_multihashmap_put (all_known_peers,
655 &peer->hashPubKey, ret, 649 &peer->hashPubKey, ret,
656 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 650 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
657 if (1 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)) 651 if (1 == GNUNET_CONTAINER_multihashmap_size (all_known_peers))
658 { 652 {
659 /* got a first connection, good time to start with FIND PEER requests... */ 653 /* got a first connection, good time to start with FIND PEER requests... */
660 find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, 654 find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, NULL);
661 NULL);
662 } 655 }
663} 656}
664 657
@@ -681,21 +674,18 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
681 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) 674 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
682 return; 675 return;
683#if DEBUG_DHT 676#if DEBUG_DHT
684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnected %s from %s\n",
685 "Disconnected %s from %s\n", 678 GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey));
686 GNUNET_i2s (&my_identity),
687 GNUNET_h2s (&peer->hashPubKey));
688#endif 679#endif
689 to_remove = 680 to_remove =
690 GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey); 681 GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey);
691 if (NULL == to_remove) 682 if (NULL == to_remove)
692 { 683 {
693 GNUNET_break (0); 684 GNUNET_break (0);
694 return; 685 return;
695 } 686 }
696 GNUNET_STATISTICS_update (GDS_stats, 687 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers connected"), -1,
697 gettext_noop ("# Peers connected"), -1, 688 GNUNET_NO);
698 GNUNET_NO);
699 GNUNET_assert (GNUNET_YES == 689 GNUNET_assert (GNUNET_YES ==
700 GNUNET_CONTAINER_multihashmap_remove (all_known_peers, 690 GNUNET_CONTAINER_multihashmap_remove (all_known_peers,
701 &peer->hashPubKey, 691 &peer->hashPubKey,
@@ -708,15 +698,13 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
708 current_bucket = find_bucket (&to_remove->id.hashPubKey); 698 current_bucket = find_bucket (&to_remove->id.hashPubKey);
709 GNUNET_assert (current_bucket >= 0); 699 GNUNET_assert (current_bucket >= 0);
710 GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head, 700 GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head,
711 k_buckets[current_bucket].tail, 701 k_buckets[current_bucket].tail, to_remove);
712 to_remove);
713 GNUNET_assert (k_buckets[current_bucket].peers_size > 0); 702 GNUNET_assert (k_buckets[current_bucket].peers_size > 0);
714 k_buckets[current_bucket].peers_size--; 703 k_buckets[current_bucket].peers_size--;
715 while ( (closest_bucket > 0) && 704 while ((closest_bucket > 0) && (k_buckets[closest_bucket].peers_size == 0))
716 (k_buckets[closest_bucket].peers_size == 0) )
717 closest_bucket--; 705 closest_bucket--;
718 706
719 if (to_remove->th != NULL) 707 if (to_remove->th != NULL)
720 { 708 {
721 GNUNET_CORE_notify_transmit_ready_cancel (to_remove->th); 709 GNUNET_CORE_notify_transmit_ready_cancel (to_remove->th);
722 to_remove->th = NULL; 710 to_remove->th = NULL;
@@ -724,15 +712,14 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
724 discarded = 0; 712 discarded = 0;
725 while (NULL != (pos = to_remove->head)) 713 while (NULL != (pos = to_remove->head))
726 { 714 {
727 GNUNET_CONTAINER_DLL_remove (to_remove->head, 715 GNUNET_CONTAINER_DLL_remove (to_remove->head, to_remove->tail, pos);
728 to_remove->tail,
729 pos);
730 discarded++; 716 discarded++;
731 GNUNET_free (pos); 717 GNUNET_free (pos);
732 } 718 }
733 GNUNET_STATISTICS_update (GDS_stats, 719 GNUNET_STATISTICS_update (GDS_stats,
734 gettext_noop ("# Queued messages discarded (peer disconnected)"), discarded, 720 gettext_noop
735 GNUNET_NO); 721 ("# Queued messages discarded (peer disconnected)"),
722 discarded, GNUNET_NO);
736 GNUNET_free (to_remove); 723 GNUNET_free (to_remove);
737} 724}
738 725
@@ -756,8 +743,8 @@ core_transmit_notify (void *cls, size_t size, void *buf)
756 size_t msize; 743 size_t msize;
757 744
758 peer->th = NULL; 745 peer->th = NULL;
759 while ( (NULL != (pending = peer->head)) && 746 while ((NULL != (pending = peer->head)) &&
760 (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0) ) 747 (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0))
761 { 748 {
762 peer->pending_count--; 749 peer->pending_count--;
763 GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending); 750 GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending);
@@ -770,22 +757,24 @@ core_transmit_notify (void *cls, size_t size, void *buf)
770 } 757 }
771 if (buf == NULL) 758 if (buf == NULL)
772 { 759 {
773 peer->th 760 peer->th =
774 = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, 761 GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
775 pending->importance, 762 pending->importance,
776 GNUNET_TIME_absolute_get_remaining (pending->timeout), 763 GNUNET_TIME_absolute_get_remaining
777 &peer->id, ntohs (pending->msg->size), 764 (pending->timeout), &peer->id,
778 &core_transmit_notify, peer); 765 ntohs (pending->msg->size),
766 &core_transmit_notify, peer);
779 GNUNET_break (NULL != peer->th); 767 GNUNET_break (NULL != peer->th);
780 return 0; 768 return 0;
781 } 769 }
782 off = 0; 770 off = 0;
783 while ( (NULL != (pending = peer->head)) && 771 while ((NULL != (pending = peer->head)) &&
784 (size - off >= (msize = ntohs (pending->msg->size))) ) 772 (size - off >= (msize = ntohs (pending->msg->size))))
785 { 773 {
786 GNUNET_STATISTICS_update (GDS_stats, 774 GNUNET_STATISTICS_update (GDS_stats,
787 gettext_noop ("# Bytes transmitted to other peers"), msize, 775 gettext_noop
788 GNUNET_NO); 776 ("# Bytes transmitted to other peers"), msize,
777 GNUNET_NO);
789 memcpy (&cbuf[off], pending->msg, msize); 778 memcpy (&cbuf[off], pending->msg, msize);
790 off += msize; 779 off += msize;
791 peer->pending_count--; 780 peer->pending_count--;
@@ -794,12 +783,12 @@ core_transmit_notify (void *cls, size_t size, void *buf)
794 } 783 }
795 if (peer->head != NULL) 784 if (peer->head != NULL)
796 { 785 {
797 peer->th 786 peer->th =
798 = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, 787 GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
799 pending->importance, 788 pending->importance,
800 GNUNET_TIME_absolute_get_remaining (pending->timeout), 789 GNUNET_TIME_absolute_get_remaining
801 &peer->id, msize, 790 (pending->timeout), &peer->id, msize,
802 &core_transmit_notify, peer); 791 &core_transmit_notify, peer);
803 GNUNET_break (NULL != peer->th); 792 GNUNET_break (NULL != peer->th);
804 } 793 }
805 return off; 794 return off;
@@ -821,16 +810,16 @@ process_peer_queue (struct PeerInfo *peer)
821 if (NULL != peer->th) 810 if (NULL != peer->th)
822 return; 811 return;
823 GNUNET_STATISTICS_update (GDS_stats, 812 GNUNET_STATISTICS_update (GDS_stats,
824 gettext_noop ("# Bytes of bandwdith requested from core"), 813 gettext_noop
825 ntohs (pending->msg->size), 814 ("# Bytes of bandwdith requested from core"),
826 GNUNET_NO); 815 ntohs (pending->msg->size), GNUNET_NO);
827 peer->th 816 peer->th =
828 = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, 817 GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
829 pending->importance, 818 pending->importance,
830 GNUNET_TIME_absolute_get_remaining (pending->timeout), 819 GNUNET_TIME_absolute_get_remaining
831 &peer->id, 820 (pending->timeout), &peer->id,
832 ntohs (pending->msg->size), 821 ntohs (pending->msg->size),
833 &core_transmit_notify, peer); 822 &core_transmit_notify, peer);
834 GNUNET_break (NULL != peer->th); 823 GNUNET_break (NULL != peer->th);
835} 824}
836 825
@@ -844,8 +833,7 @@ process_peer_queue (struct PeerInfo *peer)
844 * @return Some number of peers to forward the message to 833 * @return Some number of peers to forward the message to
845 */ 834 */
846static unsigned int 835static unsigned int
847get_forward_count (uint32_t hop_count, 836get_forward_count (uint32_t hop_count, uint32_t target_replication)
848 uint32_t target_replication)
849{ 837{
850 uint32_t random_value; 838 uint32_t random_value;
851 uint32_t forward_count; 839 uint32_t forward_count;
@@ -862,18 +850,18 @@ get_forward_count (uint32_t hop_count,
862 return 1; 850 return 1;
863 } 851 }
864 /* bound by system-wide maximum */ 852 /* bound by system-wide maximum */
865 target_replication = GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, 853 target_replication =
866 target_replication); 854 GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, target_replication);
867 target_value = 855 target_value =
868 1 + (target_replication - 1.0) / (GDS_NSE_get () + 856 1 + (target_replication - 1.0) / (GDS_NSE_get () +
869 ((float) (target_replication - 1.0) * 857 ((float) (target_replication - 1.0) *
870 hop_count)); 858 hop_count));
871 /* Set forward count to floor of target_value */ 859 /* Set forward count to floor of target_value */
872 forward_count = (uint32_t) target_value; 860 forward_count = (uint32_t) target_value;
873 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ 861 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
874 target_value = target_value - forward_count; 862 target_value = target_value - forward_count;
875 random_value = 863 random_value =
876 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 864 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
877 if (random_value < (target_value * UINT32_MAX)) 865 if (random_value < (target_value * UINT32_MAX))
878 forward_count++; 866 forward_count++;
879 return forward_count; 867 return forward_count;
@@ -950,7 +938,7 @@ get_distance (const GNUNET_HashCode * target, const GNUNET_HashCode * have)
950 * GNUNET_NO otherwise. 938 * GNUNET_NO otherwise.
951 */ 939 */
952static int 940static int
953am_closest_peer (const GNUNET_HashCode *key, 941am_closest_peer (const GNUNET_HashCode * key,
954 const struct GNUNET_CONTAINER_BloomFilter *bloom) 942 const struct GNUNET_CONTAINER_BloomFilter *bloom)
955{ 943{
956 int bits; 944 int bits;
@@ -978,7 +966,7 @@ am_closest_peer (const GNUNET_HashCode *key,
978 other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, key); 966 other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, key);
979 if (other_bits > bits) 967 if (other_bits > bits)
980 return GNUNET_NO; 968 return GNUNET_NO;
981 if (other_bits == bits) /* We match the same number of bits */ 969 if (other_bits == bits) /* We match the same number of bits */
982 return GNUNET_YES; 970 return GNUNET_YES;
983 pos = pos->next; 971 pos = pos->next;
984 } 972 }
@@ -997,7 +985,7 @@ am_closest_peer (const GNUNET_HashCode *key,
997 * exponentially declining probability. 985 * exponentially declining probability.
998 * 986 *
999 * FIXME: double-check that this is fine 987 * FIXME: double-check that this is fine
1000 * 988 *
1001 * 989 *
1002 * @param key the key we are selecting a peer to route to 990 * @param key the key we are selecting a peer to route to
1003 * @param bloom a bloomfilter containing entries this request has seen already 991 * @param bloom a bloomfilter containing entries this request has seen already
@@ -1005,9 +993,8 @@ am_closest_peer (const GNUNET_HashCode *key,
1005 * @return Peer to route to, or NULL on error 993 * @return Peer to route to, or NULL on error
1006 */ 994 */
1007static struct PeerInfo * 995static struct PeerInfo *
1008select_peer (const GNUNET_HashCode *key, 996select_peer (const GNUNET_HashCode * key,
1009 const struct GNUNET_CONTAINER_BloomFilter *bloom, 997 const struct GNUNET_CONTAINER_BloomFilter *bloom, uint32_t hops)
1010 uint32_t hops)
1011{ 998{
1012 unsigned int bc; 999 unsigned int bc;
1013 unsigned int count; 1000 unsigned int count;
@@ -1028,10 +1015,10 @@ select_peer (const GNUNET_HashCode *key,
1028 count = 0; 1015 count = 0;
1029 while ((pos != NULL) && (count < bucket_size)) 1016 while ((pos != NULL) && (count < bucket_size))
1030 { 1017 {
1031 if ( (bloom == NULL) || 1018 if ((bloom == NULL) ||
1032 (GNUNET_NO == 1019 (GNUNET_NO ==
1033 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) 1020 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)))
1034 { 1021 {
1035 dist = get_distance (key, &pos->id.hashPubKey); 1022 dist = get_distance (key, &pos->id.hashPubKey);
1036 if (dist < smallest_distance) 1023 if (dist < smallest_distance)
1037 { 1024 {
@@ -1040,25 +1027,25 @@ select_peer (const GNUNET_HashCode *key,
1040 } 1027 }
1041 } 1028 }
1042 else 1029 else
1043 { 1030 {
1044#if DEBUG_DHT 1031#if DEBUG_DHT
1045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1046 "Excluded peer `%s' due to BF match in greedy routing for %s\n", 1033 "Excluded peer `%s' due to BF match in greedy routing for %s\n",
1047 GNUNET_i2s (&pos->id), 1034 GNUNET_i2s (&pos->id), GNUNET_h2s (key));
1048 GNUNET_h2s (key));
1049#endif 1035#endif
1050 GNUNET_STATISTICS_update (GDS_stats, 1036 GNUNET_STATISTICS_update (GDS_stats,
1051 gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, 1037 gettext_noop
1052 GNUNET_NO); 1038 ("# Peers excluded from routing due to Bloomfilter"),
1053 } 1039 1, GNUNET_NO);
1040 }
1054 count++; 1041 count++;
1055 pos = pos->next; 1042 pos = pos->next;
1056 } 1043 }
1057 } 1044 }
1058 if (NULL == chosen) 1045 if (NULL == chosen)
1059 GNUNET_STATISTICS_update (GDS_stats, 1046 GNUNET_STATISTICS_update (GDS_stats,
1060 gettext_noop ("# Peer selection failed"), 1, 1047 gettext_noop ("# Peer selection failed"), 1,
1061 GNUNET_NO); 1048 GNUNET_NO);
1062 return chosen; 1049 return chosen;
1063 } 1050 }
1064 1051
@@ -1070,18 +1057,18 @@ select_peer (const GNUNET_HashCode *key,
1070 pos = k_buckets[bc].head; 1057 pos = k_buckets[bc].head;
1071 while ((pos != NULL) && (count < bucket_size)) 1058 while ((pos != NULL) && (count < bucket_size))
1072 { 1059 {
1073 if ( (bloom != NULL) && 1060 if ((bloom != NULL) &&
1074 (GNUNET_YES == 1061 (GNUNET_YES ==
1075 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) 1062 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)))
1076 { 1063 {
1077 GNUNET_STATISTICS_update (GDS_stats, 1064 GNUNET_STATISTICS_update (GDS_stats,
1078 gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, 1065 gettext_noop
1079 GNUNET_NO); 1066 ("# Peers excluded from routing due to Bloomfilter"),
1067 1, GNUNET_NO);
1080#if DEBUG_DHT 1068#if DEBUG_DHT
1081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1082 "Excluded peer `%s' due to BF match in random routing for %s\n", 1070 "Excluded peer `%s' due to BF match in random routing for %s\n",
1083 GNUNET_i2s (&pos->id), 1071 GNUNET_i2s (&pos->id), GNUNET_h2s (key));
1084 GNUNET_h2s (key));
1085#endif 1072#endif
1086 pos = pos->next; 1073 pos = pos->next;
1087 continue; /* Ignore bloomfiltered peers */ 1074 continue; /* Ignore bloomfiltered peers */
@@ -1093,8 +1080,8 @@ select_peer (const GNUNET_HashCode *key,
1093 if (count == 0) /* No peers to select from! */ 1080 if (count == 0) /* No peers to select from! */
1094 { 1081 {
1095 GNUNET_STATISTICS_update (GDS_stats, 1082 GNUNET_STATISTICS_update (GDS_stats,
1096 gettext_noop ("# Peer selection failed"), 1, 1083 gettext_noop ("# Peer selection failed"), 1,
1097 GNUNET_NO); 1084 GNUNET_NO);
1098 return NULL; 1085 return NULL;
1099 } 1086 }
1100 /* Now actually choose a peer */ 1087 /* Now actually choose a peer */
@@ -1105,9 +1092,9 @@ select_peer (const GNUNET_HashCode *key,
1105 pos = k_buckets[bc].head; 1092 pos = k_buckets[bc].head;
1106 while ((pos != NULL) && (count < bucket_size)) 1093 while ((pos != NULL) && (count < bucket_size))
1107 { 1094 {
1108 if ( (bloom != NULL) && 1095 if ((bloom != NULL) &&
1109 (GNUNET_YES == 1096 (GNUNET_YES ==
1110 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) 1097 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)))
1111 { 1098 {
1112 pos = pos->next; 1099 pos = pos->next;
1113 continue; /* Ignore bloomfiltered peers */ 1100 continue; /* Ignore bloomfiltered peers */
@@ -1136,11 +1123,10 @@ select_peer (const GNUNET_HashCode *key,
1136 * @return number of peers returned in 'targets'. 1123 * @return number of peers returned in 'targets'.
1137 */ 1124 */
1138static unsigned int 1125static unsigned int
1139get_target_peers (const GNUNET_HashCode *key, 1126get_target_peers (const GNUNET_HashCode * key,
1140 struct GNUNET_CONTAINER_BloomFilter *bloom, 1127 struct GNUNET_CONTAINER_BloomFilter *bloom,
1141 uint32_t hop_count, 1128 uint32_t hop_count, uint32_t target_replication,
1142 uint32_t target_replication, 1129 struct PeerInfo ***targets)
1143 struct PeerInfo ***targets)
1144{ 1130{
1145 unsigned int ret; 1131 unsigned int ret;
1146 unsigned int off; 1132 unsigned int off;
@@ -1154,25 +1140,23 @@ get_target_peers (const GNUNET_HashCode *key,
1154 *targets = NULL; 1140 *targets = NULL;
1155 return 0; 1141 return 0;
1156 } 1142 }
1157 rtargets = GNUNET_malloc (sizeof (struct PeerInfo*) * ret); 1143 rtargets = GNUNET_malloc (sizeof (struct PeerInfo *) * ret);
1158 for (off = 0; off < ret; off++) 1144 for (off = 0; off < ret; off++)
1159 { 1145 {
1160 nxt = select_peer (key, bloom, hop_count); 1146 nxt = select_peer (key, bloom, hop_count);
1161 if (nxt == NULL) 1147 if (nxt == NULL)
1162 break; 1148 break;
1163 rtargets[off] = nxt; 1149 rtargets[off] = nxt;
1164 GNUNET_break (GNUNET_NO == 1150 GNUNET_break (GNUNET_NO ==
1165 GNUNET_CONTAINER_bloomfilter_test (bloom, &nxt->id.hashPubKey)); 1151 GNUNET_CONTAINER_bloomfilter_test (bloom,
1152 &nxt->id.hashPubKey));
1166 GNUNET_CONTAINER_bloomfilter_add (bloom, &rtargets[off]->id.hashPubKey); 1153 GNUNET_CONTAINER_bloomfilter_add (bloom, &rtargets[off]->id.hashPubKey);
1167 } 1154 }
1168#if DEBUG_DHT 1155#if DEBUG_DHT
1169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1170 "Selected %u/%u peers at hop %u for %s (target was %u)\n", 1157 "Selected %u/%u peers at hop %u for %s (target was %u)\n", off,
1171 off, 1158 GNUNET_CONTAINER_multihashmap_size (all_known_peers),
1172 GNUNET_CONTAINER_multihashmap_size (all_known_peers), 1159 (unsigned int) hop_count, GNUNET_h2s (key), ret);
1173 (unsigned int) hop_count,
1174 GNUNET_h2s (key),
1175 ret);
1176#endif 1160#endif
1177 if (0 == off) 1161 if (0 == off)
1178 { 1162 {
@@ -1206,16 +1190,15 @@ get_target_peers (const GNUNET_HashCode *key,
1206 */ 1190 */
1207void 1191void
1208GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, 1192GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1209 enum GNUNET_DHT_RouteOption options, 1193 enum GNUNET_DHT_RouteOption options,
1210 uint32_t desired_replication_level, 1194 uint32_t desired_replication_level,
1211 struct GNUNET_TIME_Absolute expiration_time, 1195 struct GNUNET_TIME_Absolute expiration_time,
1212 uint32_t hop_count, 1196 uint32_t hop_count,
1213 struct GNUNET_CONTAINER_BloomFilter *bf, 1197 struct GNUNET_CONTAINER_BloomFilter *bf,
1214 const GNUNET_HashCode *key, 1198 const GNUNET_HashCode * key,
1215 unsigned int put_path_length, 1199 unsigned int put_path_length,
1216 struct GNUNET_PeerIdentity *put_path, 1200 struct GNUNET_PeerIdentity *put_path,
1217 const void *data, 1201 const void *data, size_t data_size)
1218 size_t data_size)
1219{ 1202{
1220 unsigned int target_count; 1203 unsigned int target_count;
1221 unsigned int i; 1204 unsigned int i;
@@ -1225,33 +1208,32 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1225 size_t msize; 1208 size_t msize;
1226 struct PeerPutMessage *ppm; 1209 struct PeerPutMessage *ppm;
1227 struct GNUNET_PeerIdentity *pp; 1210 struct GNUNET_PeerIdentity *pp;
1228 1211
1229 GNUNET_assert (NULL != bf); 1212 GNUNET_assert (NULL != bf);
1230#if DEBUG_DHT 1213#if DEBUG_DHT
1231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1232 "Adding myself (%s) to PUT bloomfilter for %s\n", 1215 "Adding myself (%s) to PUT bloomfilter for %s\n",
1233 GNUNET_i2s (&my_identity), 1216 GNUNET_i2s (&my_identity), GNUNET_h2s (key));
1234 GNUNET_h2s (key));
1235#endif 1217#endif
1236 GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity.hashPubKey); 1218 GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity.hashPubKey);
1237 GNUNET_STATISTICS_update (GDS_stats, 1219 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# PUT requests routed"),
1238 gettext_noop ("# PUT requests routed"), 1, 1220 1, GNUNET_NO);
1239 GNUNET_NO); 1221 target_count =
1240 target_count = get_target_peers (key, bf, hop_count, 1222 get_target_peers (key, bf, hop_count, desired_replication_level,
1241 desired_replication_level, 1223 &targets);
1242 &targets);
1243 if (0 == target_count) 1224 if (0 == target_count)
1244 { 1225 {
1245#if DEBUG_DHT 1226#if DEBUG_DHT
1246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1247 "Routing PUT for %s terminates after %u hops at %s\n", 1228 "Routing PUT for %s terminates after %u hops at %s\n",
1248 GNUNET_h2s (key), 1229 GNUNET_h2s (key), (unsigned int) hop_count,
1249 (unsigned int) hop_count, 1230 GNUNET_i2s (&my_identity));
1250 GNUNET_i2s (&my_identity));
1251#endif 1231#endif
1252 return; 1232 return;
1253 } 1233 }
1254 msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + sizeof (struct PeerPutMessage); 1234 msize =
1235 put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size +
1236 sizeof (struct PeerPutMessage);
1255 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1237 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1256 { 1238 {
1257 put_path_length = 0; 1239 put_path_length = 0;
@@ -1264,22 +1246,21 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1264 return; 1246 return;
1265 } 1247 }
1266 GNUNET_STATISTICS_update (GDS_stats, 1248 GNUNET_STATISTICS_update (GDS_stats,
1267 gettext_noop ("# PUT messages queued for transmission"), target_count, 1249 gettext_noop
1268 GNUNET_NO); 1250 ("# PUT messages queued for transmission"),
1269 for (i=0;i<target_count;i++) 1251 target_count, GNUNET_NO);
1252 for (i = 0; i < target_count; i++)
1270 { 1253 {
1271 target = targets[i]; 1254 target = targets[i];
1272#if DEBUG_DHT 1255#if DEBUG_DHT
1273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1274 "Routing PUT for %s after %u hops to %s\n", 1257 "Routing PUT for %s after %u hops to %s\n", GNUNET_h2s (key),
1275 GNUNET_h2s (key), 1258 (unsigned int) hop_count, GNUNET_i2s (&target->id));
1276 (unsigned int) hop_count,
1277 GNUNET_i2s (&target->id));
1278#endif 1259#endif
1279 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1260 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1280 pending->importance = 0; /* FIXME */ 1261 pending->importance = 0; /* FIXME */
1281 pending->timeout = expiration_time; 1262 pending->timeout = expiration_time;
1282 ppm = (struct PeerPutMessage*) &pending[1]; 1263 ppm = (struct PeerPutMessage *) &pending[1];
1283 pending->msg = &ppm->header; 1264 pending->msg = &ppm->header;
1284 ppm->header.size = htons (msize); 1265 ppm->header.size = htons (msize);
1285 ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); 1266 ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT);
@@ -1289,18 +1270,19 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1289 ppm->desired_replication_level = htonl (desired_replication_level); 1270 ppm->desired_replication_level = htonl (desired_replication_level);
1290 ppm->put_path_length = htonl (put_path_length); 1271 ppm->put_path_length = htonl (put_path_length);
1291 ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); 1272 ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1292 GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &target->id.hashPubKey)); 1273 GNUNET_break (GNUNET_YES ==
1274 GNUNET_CONTAINER_bloomfilter_test (bf,
1275 &target->id.hashPubKey));
1293 GNUNET_assert (GNUNET_OK == 1276 GNUNET_assert (GNUNET_OK ==
1294 GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, 1277 GNUNET_CONTAINER_bloomfilter_get_raw_data (bf,
1295 ppm->bloomfilter, 1278 ppm->bloomfilter,
1296 DHT_BLOOM_SIZE)); 1279 DHT_BLOOM_SIZE));
1297 ppm->key = *key; 1280 ppm->key = *key;
1298 pp = (struct GNUNET_PeerIdentity*) &ppm[1]; 1281 pp = (struct GNUNET_PeerIdentity *) &ppm[1];
1299 memcpy (pp, put_path, sizeof (struct GNUNET_PeerIdentity) * put_path_length); 1282 memcpy (pp, put_path,
1283 sizeof (struct GNUNET_PeerIdentity) * put_path_length);
1300 memcpy (&pp[put_path_length], data, data_size); 1284 memcpy (&pp[put_path_length], data, data_size);
1301 GNUNET_CONTAINER_DLL_insert_tail (target->head, 1285 GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending);
1302 target->tail,
1303 pending);
1304 target->pending_count++; 1286 target->pending_count++;
1305 process_peer_queue (target); 1287 process_peer_queue (target);
1306 } 1288 }
@@ -1327,15 +1309,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1327 */ 1309 */
1328void 1310void
1329GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, 1311GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1330 enum GNUNET_DHT_RouteOption options, 1312 enum GNUNET_DHT_RouteOption options,
1331 uint32_t desired_replication_level, 1313 uint32_t desired_replication_level,
1332 uint32_t hop_count, 1314 uint32_t hop_count, const GNUNET_HashCode * key,
1333 const GNUNET_HashCode *key, 1315 const void *xquery, size_t xquery_size,
1334 const void *xquery, 1316 const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
1335 size_t xquery_size, 1317 uint32_t reply_bf_mutator,
1336 const struct GNUNET_CONTAINER_BloomFilter *reply_bf, 1318 struct GNUNET_CONTAINER_BloomFilter *peer_bf)
1337 uint32_t reply_bf_mutator,
1338 struct GNUNET_CONTAINER_BloomFilter *peer_bf)
1339{ 1319{
1340 unsigned int target_count; 1320 unsigned int target_count;
1341 unsigned int i; 1321 unsigned int i;
@@ -1347,28 +1327,25 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1347 char *xq; 1327 char *xq;
1348 size_t reply_bf_size; 1328 size_t reply_bf_size;
1349 1329
1350 GNUNET_assert (NULL != peer_bf); 1330 GNUNET_assert (NULL != peer_bf);
1351 GNUNET_STATISTICS_update (GDS_stats, 1331 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# GET requests routed"),
1352 gettext_noop ("# GET requests routed"), 1, 1332 1, GNUNET_NO);
1353 GNUNET_NO); 1333 target_count =
1354 target_count = get_target_peers (key, peer_bf, hop_count, 1334 get_target_peers (key, peer_bf, hop_count, desired_replication_level,
1355 desired_replication_level, 1335 &targets);
1356 &targets);
1357#if DEBUG_DHT 1336#if DEBUG_DHT
1358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1359 "Adding myself (%s) to GET bloomfilter for %s\n", 1338 "Adding myself (%s) to GET bloomfilter for %s\n",
1360 GNUNET_i2s (&my_identity), 1339 GNUNET_i2s (&my_identity), GNUNET_h2s (key));
1361 GNUNET_h2s (key));
1362#endif 1340#endif
1363 GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity.hashPubKey); 1341 GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity.hashPubKey);
1364 if (0 == target_count) 1342 if (0 == target_count)
1365 { 1343 {
1366#if DEBUG_DHT 1344#if DEBUG_DHT
1367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1368 "Routing GET for %s terminates after %u hops at %s\n", 1346 "Routing GET for %s terminates after %u hops at %s\n",
1369 GNUNET_h2s (key), 1347 GNUNET_h2s (key), (unsigned int) hop_count,
1370 (unsigned int) hop_count, 1348 GNUNET_i2s (&my_identity));
1371 GNUNET_i2s (&my_identity));
1372#endif 1349#endif
1373 return; 1350 return;
1374 } 1351 }
@@ -1381,23 +1358,22 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1381 return; 1358 return;
1382 } 1359 }
1383 GNUNET_STATISTICS_update (GDS_stats, 1360 GNUNET_STATISTICS_update (GDS_stats,
1384 gettext_noop ("# GET messages queued for transmission"), target_count, 1361 gettext_noop
1385 GNUNET_NO); 1362 ("# GET messages queued for transmission"),
1363 target_count, GNUNET_NO);
1386 /* forward request */ 1364 /* forward request */
1387 for (i=0;i<target_count;i++) 1365 for (i = 0; i < target_count; i++)
1388 { 1366 {
1389 target = targets[i]; 1367 target = targets[i];
1390#if DEBUG_DHT 1368#if DEBUG_DHT
1391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1392 "Routing GET for %s after %u hops to %s\n", 1370 "Routing GET for %s after %u hops to %s\n", GNUNET_h2s (key),
1393 GNUNET_h2s (key), 1371 (unsigned int) hop_count, GNUNET_i2s (&target->id));
1394 (unsigned int) hop_count,
1395 GNUNET_i2s (&target->id));
1396#endif 1372#endif
1397 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1373 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1398 pending->importance = 0; /* FIXME */ 1374 pending->importance = 0; /* FIXME */
1399 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); 1375 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
1400 pgm = (struct PeerGetMessage*) &pending[1]; 1376 pgm = (struct PeerGetMessage *) &pending[1];
1401 pending->msg = &pgm->header; 1377 pending->msg = &pgm->header;
1402 pgm->header.size = htons (msize); 1378 pgm->header.size = htons (msize);
1403 pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); 1379 pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET);
@@ -1406,23 +1382,24 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1406 pgm->hop_count = htonl (hop_count + 1); 1382 pgm->hop_count = htonl (hop_count + 1);
1407 pgm->desired_replication_level = htonl (desired_replication_level); 1383 pgm->desired_replication_level = htonl (desired_replication_level);
1408 pgm->xquery_size = htonl (xquery_size); 1384 pgm->xquery_size = htonl (xquery_size);
1409 pgm->bf_mutator = reply_bf_mutator; 1385 pgm->bf_mutator = reply_bf_mutator;
1410 GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &target->id.hashPubKey)); 1386 GNUNET_break (GNUNET_YES ==
1387 GNUNET_CONTAINER_bloomfilter_test (peer_bf,
1388 &target->id.hashPubKey));
1411 GNUNET_assert (GNUNET_OK == 1389 GNUNET_assert (GNUNET_OK ==
1412 GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, 1390 GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf,
1413 pgm->bloomfilter, 1391 pgm->bloomfilter,
1414 DHT_BLOOM_SIZE)); 1392 DHT_BLOOM_SIZE));
1415 pgm->key = *key; 1393 pgm->key = *key;
1416 xq = (char *) &pgm[1]; 1394 xq = (char *) &pgm[1];
1417 memcpy (xq, xquery, xquery_size); 1395 memcpy (xq, xquery, xquery_size);
1418 if (NULL != reply_bf) 1396 if (NULL != reply_bf)
1419 GNUNET_assert (GNUNET_OK == 1397 GNUNET_assert (GNUNET_OK ==
1420 GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf, 1398 GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf,
1421 &xq[xquery_size], 1399 &xq
1422 reply_bf_size)); 1400 [xquery_size],
1423 GNUNET_CONTAINER_DLL_insert_tail (target->head, 1401 reply_bf_size));
1424 target->tail, 1402 GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending);
1425 pending);
1426 target->pending_count++; 1403 target->pending_count++;
1427 process_peer_queue (target); 1404 process_peer_queue (target);
1428 } 1405 }
@@ -1448,46 +1425,49 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1448 */ 1425 */
1449void 1426void
1450GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, 1427GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
1451 enum GNUNET_BLOCK_Type type, 1428 enum GNUNET_BLOCK_Type type,
1452 struct GNUNET_TIME_Absolute expiration_time, 1429 struct GNUNET_TIME_Absolute expiration_time,
1453 const GNUNET_HashCode *key, 1430 const GNUNET_HashCode * key,
1454 unsigned int put_path_length, 1431 unsigned int put_path_length,
1455 const struct GNUNET_PeerIdentity *put_path, 1432 const struct GNUNET_PeerIdentity *put_path,
1456 unsigned int get_path_length, 1433 unsigned int get_path_length,
1457 const struct GNUNET_PeerIdentity *get_path, 1434 const struct GNUNET_PeerIdentity *get_path,
1458 const void *data, 1435 const void *data, size_t data_size)
1459 size_t data_size)
1460{ 1436{
1461 struct PeerInfo *pi; 1437 struct PeerInfo *pi;
1462 struct P2PPendingMessage *pending; 1438 struct P2PPendingMessage *pending;
1463 size_t msize; 1439 size_t msize;
1464 struct PeerResultMessage *prm; 1440 struct PeerResultMessage *prm;
1465 struct GNUNET_PeerIdentity *paths; 1441 struct GNUNET_PeerIdentity *paths;
1466 1442
1467 msize = data_size + sizeof (struct PeerResultMessage) + 1443 msize =
1468 (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); 1444 data_size + sizeof (struct PeerResultMessage) + (get_path_length +
1469 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 1445 put_path_length) *
1470 (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || 1446 sizeof (struct GNUNET_PeerIdentity);
1471 (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || 1447 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
1472 (data_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) ) 1448 (get_path_length >
1449 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
1450 (put_path_length >
1451 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
1452 (data_size > GNUNET_SERVER_MAX_MESSAGE_SIZE))
1473 { 1453 {
1474 GNUNET_break (0); 1454 GNUNET_break (0);
1475 return; 1455 return;
1476 } 1456 }
1477 pi = GNUNET_CONTAINER_multihashmap_get (all_known_peers, 1457 pi = GNUNET_CONTAINER_multihashmap_get (all_known_peers, &target->hashPubKey);
1478 &target->hashPubKey);
1479 if (NULL == pi) 1458 if (NULL == pi)
1480 { 1459 {
1481 /* peer disconnected in the meantime, drop reply */ 1460 /* peer disconnected in the meantime, drop reply */
1482 return; 1461 return;
1483 } 1462 }
1484 GNUNET_STATISTICS_update (GDS_stats, 1463 GNUNET_STATISTICS_update (GDS_stats,
1485 gettext_noop ("# RESULT messages queued for transmission"), 1, 1464 gettext_noop
1486 GNUNET_NO); 1465 ("# RESULT messages queued for transmission"), 1,
1487 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1466 GNUNET_NO);
1488 pending->importance = 0; /* FIXME */ 1467 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1468 pending->importance = 0; /* FIXME */
1489 pending->timeout = expiration_time; 1469 pending->timeout = expiration_time;
1490 prm = (struct PeerResultMessage*) &pending[1]; 1470 prm = (struct PeerResultMessage *) &pending[1];
1491 pending->msg = &prm->header; 1471 pending->msg = &prm->header;
1492 prm->header.size = htons (msize); 1472 prm->header.size = htons (msize);
1493 prm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); 1473 prm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT);
@@ -1496,15 +1476,13 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
1496 prm->get_path_length = htonl (get_path_length); 1476 prm->get_path_length = htonl (get_path_length);
1497 prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); 1477 prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1498 prm->key = *key; 1478 prm->key = *key;
1499 paths = (struct GNUNET_PeerIdentity*) &prm[1]; 1479 paths = (struct GNUNET_PeerIdentity *) &prm[1];
1500 memcpy (paths, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); 1480 memcpy (paths, put_path,
1501 memcpy (&paths[put_path_length], 1481 put_path_length * sizeof (struct GNUNET_PeerIdentity));
1502 get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); 1482 memcpy (&paths[put_path_length], get_path,
1503 memcpy (&paths[put_path_length + get_path_length], 1483 get_path_length * sizeof (struct GNUNET_PeerIdentity));
1504 data, data_size); 1484 memcpy (&paths[put_path_length + get_path_length], data, data_size);
1505 GNUNET_CONTAINER_DLL_insert (pi->head, 1485 GNUNET_CONTAINER_DLL_insert (pi->head, pi->tail, pending);
1506 pi->tail,
1507 pending);
1508 pi->pending_count++; 1486 pi->pending_count++;
1509 process_peer_queue (pi); 1487 process_peer_queue (pi);
1510} 1488}
@@ -1539,12 +1517,10 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
1539 * GNUNET_SYSERR to close it (signal serious error) 1517 * GNUNET_SYSERR to close it (signal serious error)
1540 */ 1518 */
1541static int 1519static int
1542handle_dht_p2p_put (void *cls, 1520handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
1543 const struct GNUNET_PeerIdentity *peer, 1521 const struct GNUNET_MessageHeader *message,
1544 const struct GNUNET_MessageHeader *message, 1522 const struct GNUNET_ATS_Information *atsi,
1545 const struct GNUNET_ATS_Information 1523 unsigned int atsi_count)
1546 *atsi,
1547 unsigned int atsi_count)
1548{ 1524{
1549 const struct PeerPutMessage *put; 1525 const struct PeerPutMessage *put;
1550 const struct GNUNET_PeerIdentity *put_path; 1526 const struct GNUNET_PeerIdentity *put_path;
@@ -1555,33 +1531,36 @@ handle_dht_p2p_put (void *cls,
1555 enum GNUNET_DHT_RouteOption options; 1531 enum GNUNET_DHT_RouteOption options;
1556 struct GNUNET_CONTAINER_BloomFilter *bf; 1532 struct GNUNET_CONTAINER_BloomFilter *bf;
1557 GNUNET_HashCode test_key; 1533 GNUNET_HashCode test_key;
1558 1534
1559 msize = ntohs (message->size); 1535 msize = ntohs (message->size);
1560 if (msize < sizeof (struct PeerPutMessage)) 1536 if (msize < sizeof (struct PeerPutMessage))
1561 { 1537 {
1562 GNUNET_break_op (0); 1538 GNUNET_break_op (0);
1563 return GNUNET_YES; 1539 return GNUNET_YES;
1564 } 1540 }
1565 put = (const struct PeerPutMessage*) message; 1541 put = (const struct PeerPutMessage *) message;
1566 putlen = ntohl (put->put_path_length); 1542 putlen = ntohl (put->put_path_length);
1567 if ( (msize < sizeof (struct PeerPutMessage) + putlen * sizeof (struct GNUNET_PeerIdentity)) || 1543 if ((msize <
1568 (putlen > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ) 1544 sizeof (struct PeerPutMessage) +
1569 { 1545 putlen * sizeof (struct GNUNET_PeerIdentity)) ||
1570 GNUNET_break_op (0); 1546 (putlen >
1571 return GNUNET_YES; 1547 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
1572 } 1548 {
1549 GNUNET_break_op (0);
1550 return GNUNET_YES;
1551 }
1573 GNUNET_STATISTICS_update (GDS_stats, 1552 GNUNET_STATISTICS_update (GDS_stats,
1574 gettext_noop ("# P2P PUT requests received"), 1, 1553 gettext_noop ("# P2P PUT requests received"), 1,
1575 GNUNET_NO); 1554 GNUNET_NO);
1576 put_path = (const struct GNUNET_PeerIdentity*) &put[1]; 1555 put_path = (const struct GNUNET_PeerIdentity *) &put[1];
1577 payload = &put_path[putlen]; 1556 payload = &put_path[putlen];
1578 options = ntohl (put->options); 1557 options = ntohl (put->options);
1579 payload_size = msize - (sizeof (struct PeerPutMessage) + 1558 payload_size =
1580 putlen * sizeof (struct GNUNET_PeerIdentity)); 1559 msize - (sizeof (struct PeerPutMessage) +
1581 switch (GNUNET_BLOCK_get_key (GDS_block_context, 1560 putlen * sizeof (struct GNUNET_PeerIdentity));
1582 ntohl (put->type), 1561 switch (GNUNET_BLOCK_get_key
1583 payload, payload_size, 1562 (GDS_block_context, ntohl (put->type), payload, payload_size,
1584 &test_key)) 1563 &test_key))
1585 { 1564 {
1586 case GNUNET_YES: 1565 case GNUNET_YES:
1587 if (0 != memcmp (&test_key, &put->key, sizeof (GNUNET_HashCode))) 1566 if (0 != memcmp (&test_key, &put->key, sizeof (GNUNET_HashCode)))
@@ -1598,18 +1577,16 @@ handle_dht_p2p_put (void *cls,
1598 break; 1577 break;
1599 } 1578 }
1600#if DEBUG_DHT 1579#if DEBUG_DHT
1601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PUT for %s at %s\n",
1602 "PUT for %s at %s\n", 1581 GNUNET_h2s (&put->key), GNUNET_i2s (&my_identity));
1603 GNUNET_h2s (&put->key),
1604 GNUNET_i2s (&my_identity));
1605#endif 1582#endif
1606 bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, 1583 bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, DHT_BLOOM_SIZE,
1607 DHT_BLOOM_SIZE, 1584 GNUNET_CONSTANTS_BLOOMFILTER_K);
1608 GNUNET_CONSTANTS_BLOOMFILTER_K); 1585 GNUNET_break_op (GNUNET_YES ==
1609 GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey)); 1586 GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey));
1610 { 1587 {
1611 struct GNUNET_PeerIdentity pp[putlen+1]; 1588 struct GNUNET_PeerIdentity pp[putlen + 1];
1612 1589
1613 /* extend 'put path' by sender */ 1590 /* extend 'put path' by sender */
1614 if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) 1591 if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE))
1615 { 1592 {
@@ -1619,37 +1596,23 @@ handle_dht_p2p_put (void *cls,
1619 } 1596 }
1620 else 1597 else
1621 putlen = 0; 1598 putlen = 0;
1622 1599
1623 /* give to local clients */ 1600 /* give to local clients */
1624 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time), 1601 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time),
1625 &put->key, 1602 &put->key, 0, NULL, putlen, pp, ntohl (put->type),
1626 0, NULL, 1603 payload_size, payload);
1627 putlen,
1628 pp,
1629 ntohl (put->type),
1630 payload_size,
1631 payload);
1632 /* store locally */ 1604 /* store locally */
1633 if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || 1605 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
1634 (am_closest_peer (&put->key, 1606 (am_closest_peer (&put->key, bf)))
1635 bf) ) ) 1607 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh
1636 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), 1608 (put->expiration_time), &put->key, putlen, pp,
1637 &put->key, 1609 ntohl (put->type), payload_size, payload);
1638 putlen, pp,
1639 ntohl (put->type),
1640 payload_size,
1641 payload);
1642 /* route to other peers */ 1610 /* route to other peers */
1643 GDS_NEIGHBOURS_handle_put (ntohl (put->type), 1611 GDS_NEIGHBOURS_handle_put (ntohl (put->type), options,
1644 options, 1612 ntohl (put->desired_replication_level),
1645 ntohl (put->desired_replication_level), 1613 GNUNET_TIME_absolute_ntoh (put->expiration_time),
1646 GNUNET_TIME_absolute_ntoh (put->expiration_time), 1614 ntohl (put->hop_count), bf, &put->key, putlen,
1647 ntohl (put->hop_count), 1615 pp, payload, payload_size);
1648 bf,
1649 &put->key,
1650 putlen, pp,
1651 payload,
1652 payload_size);
1653 } 1616 }
1654 GNUNET_CONTAINER_bloomfilter_free (bf); 1617 GNUNET_CONTAINER_bloomfilter_free (bf);
1655 return GNUNET_YES; 1618 return GNUNET_YES;
@@ -1667,9 +1630,8 @@ handle_dht_p2p_put (void *cls,
1667 */ 1630 */
1668static void 1631static void
1669handle_find_peer (const struct GNUNET_PeerIdentity *sender, 1632handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1670 const GNUNET_HashCode *key, 1633 const GNUNET_HashCode * key,
1671 struct GNUNET_CONTAINER_BloomFilter *bf, 1634 struct GNUNET_CONTAINER_BloomFilter *bf, uint32_t bf_mutator)
1672 uint32_t bf_mutator)
1673{ 1635{
1674 int bucket_idx; 1636 int bucket_idx;
1675 struct PeerBucket *bucket; 1637 struct PeerBucket *bucket;
@@ -1682,30 +1644,31 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1682 if (NULL != GDS_my_hello) 1644 if (NULL != GDS_my_hello)
1683 { 1645 {
1684 GNUNET_BLOCK_mingle_hash (&my_identity.hashPubKey, bf_mutator, &mhash); 1646 GNUNET_BLOCK_mingle_hash (&my_identity.hashPubKey, bf_mutator, &mhash);
1685 if ( (NULL == bf) || 1647 if ((NULL == bf) ||
1686 (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) ) 1648 (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)))
1687 { 1649 {
1688 GDS_NEIGHBOURS_handle_reply (sender, 1650 GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO,
1689 GNUNET_BLOCK_TYPE_DHT_HELLO, 1651 GNUNET_TIME_relative_to_absolute
1690 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), 1652 (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION),
1691 key, 1653 key, 0, NULL, 0, NULL, GDS_my_hello,
1692 0, NULL, 1654 GNUNET_HELLO_size ((const struct
1693 0, NULL, 1655 GNUNET_HELLO_Message *)
1694 GDS_my_hello, 1656 GDS_my_hello));
1695 GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message*) GDS_my_hello));
1696 } 1657 }
1697 else 1658 else
1698 { 1659 {
1699 GNUNET_STATISTICS_update (GDS_stats, 1660 GNUNET_STATISTICS_update (GDS_stats,
1700 gettext_noop ("# FIND PEER requests ignored due to Bloomfilter"), 1, 1661 gettext_noop
1701 GNUNET_NO); 1662 ("# FIND PEER requests ignored due to Bloomfilter"),
1663 1, GNUNET_NO);
1702 } 1664 }
1703 } 1665 }
1704 else 1666 else
1705 { 1667 {
1706 GNUNET_STATISTICS_update (GDS_stats, 1668 GNUNET_STATISTICS_update (GDS_stats,
1707 gettext_noop ("# FIND PEER requests ignored due to lack of HELLO"), 1, 1669 gettext_noop
1708 GNUNET_NO); 1670 ("# FIND PEER requests ignored due to lack of HELLO"),
1671 1, GNUNET_NO);
1709 } 1672 }
1710 1673
1711 /* then, also consider sending a random HELLO from the closest bucket */ 1674 /* then, also consider sending a random HELLO from the closest bucket */
@@ -1718,8 +1681,8 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1718 bucket = &k_buckets[bucket_idx]; 1681 bucket = &k_buckets[bucket_idx];
1719 if (bucket->peers_size == 0) 1682 if (bucket->peers_size == 0)
1720 return; 1683 return;
1721 choice = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1684 choice =
1722 bucket->peers_size); 1685 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, bucket->peers_size);
1723 peer = bucket->head; 1686 peer = bucket->head;
1724 while (choice > 0) 1687 while (choice > 0)
1725 { 1688 {
@@ -1729,25 +1692,22 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1729 } 1692 }
1730 choice = bucket->peers_size; 1693 choice = bucket->peers_size;
1731 do 1694 do
1732 { 1695 {
1733 peer = peer->next; 1696 peer = peer->next;
1734 if (choice-- == 0) 1697 if (choice-- == 0)
1735 return; /* no non-masked peer available */ 1698 return; /* no non-masked peer available */
1736 if (peer == NULL) 1699 if (peer == NULL)
1737 peer = bucket->head; 1700 peer = bucket->head;
1738 GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash); 1701 GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash);
1739 hello = GDS_HELLO_get (&peer->id); 1702 hello = GDS_HELLO_get (&peer->id);
1740 } 1703 }
1741 while ( (hello == NULL) || 1704 while ((hello == NULL) ||
1742 (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) ); 1705 (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)));
1743 GDS_NEIGHBOURS_handle_reply (sender, 1706 GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO,
1744 GNUNET_BLOCK_TYPE_DHT_HELLO, 1707 GNUNET_TIME_relative_to_absolute
1745 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), 1708 (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), key,
1746 key, 1709 0, NULL, 0, NULL, hello,
1747 0, NULL, 1710 GNUNET_HELLO_size (hello));
1748 0, NULL,
1749 hello,
1750 GNUNET_HELLO_size (hello));
1751} 1711}
1752 1712
1753 1713
@@ -1765,10 +1725,9 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1765 */ 1725 */
1766static int 1726static int
1767handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, 1727handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1768 const struct GNUNET_MessageHeader *message, 1728 const struct GNUNET_MessageHeader *message,
1769 const struct GNUNET_ATS_Information 1729 const struct GNUNET_ATS_Information *atsi,
1770 *atsi, 1730 unsigned int atsi_count)
1771 unsigned int atsi_count)
1772{ 1731{
1773 struct PeerGetMessage *get; 1732 struct PeerGetMessage *get;
1774 uint32_t xquery_size; 1733 uint32_t xquery_size;
@@ -1781,7 +1740,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1781 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 1740 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
1782 const char *xquery; 1741 const char *xquery;
1783 1742
1784 GNUNET_break (0 != memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))); 1743 GNUNET_break (0 !=
1744 memcmp (peer, &my_identity,
1745 sizeof (struct GNUNET_PeerIdentity)));
1785 /* parse and validate message */ 1746 /* parse and validate message */
1786 msize = ntohs (message->size); 1747 msize = ntohs (message->size);
1787 if (msize < sizeof (struct PeerGetMessage)) 1748 if (msize < sizeof (struct PeerGetMessage))
@@ -1797,24 +1758,20 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1797 return GNUNET_YES; 1758 return GNUNET_YES;
1798 } 1759 }
1799 GNUNET_STATISTICS_update (GDS_stats, 1760 GNUNET_STATISTICS_update (GDS_stats,
1800 gettext_noop ("# P2P GET requests received"), 1, 1761 gettext_noop ("# P2P GET requests received"), 1,
1801 GNUNET_NO); 1762 GNUNET_NO);
1802 reply_bf_size = msize - (sizeof (struct PeerGetMessage) + xquery_size); 1763 reply_bf_size = msize - (sizeof (struct PeerGetMessage) + xquery_size);
1803 type = ntohl (get->type); 1764 type = ntohl (get->type);
1804 options = ntohl (get->options); 1765 options = ntohl (get->options);
1805 xquery = (const char*) &get[1]; 1766 xquery = (const char *) &get[1];
1806 reply_bf = NULL; 1767 reply_bf = NULL;
1807 if (reply_bf_size > 0) 1768 if (reply_bf_size > 0)
1808 reply_bf = GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], 1769 reply_bf =
1809 reply_bf_size, 1770 GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], reply_bf_size,
1810 GNUNET_CONSTANTS_BLOOMFILTER_K); 1771 GNUNET_CONSTANTS_BLOOMFILTER_K);
1811 eval = GNUNET_BLOCK_evaluate (GDS_block_context, 1772 eval =
1812 type, 1773 GNUNET_BLOCK_evaluate (GDS_block_context, type, &get->key, &reply_bf,
1813 &get->key, 1774 get->bf_mutator, xquery, xquery_size, NULL, 0);
1814 &reply_bf,
1815 get->bf_mutator,
1816 xquery, xquery_size,
1817 NULL, 0);
1818 if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID) 1775 if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID)
1819 { 1776 {
1820 /* request invalid or block type not supported */ 1777 /* request invalid or block type not supported */
@@ -1824,70 +1781,55 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1824 return GNUNET_YES; 1781 return GNUNET_YES;
1825 } 1782 }
1826 peer_bf = 1783 peer_bf =
1827 GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, 1784 GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, DHT_BLOOM_SIZE,
1828 DHT_BLOOM_SIZE, 1785 GNUNET_CONSTANTS_BLOOMFILTER_K);
1829 GNUNET_CONSTANTS_BLOOMFILTER_K); 1786 GNUNET_break_op (GNUNET_YES ==
1830 GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &peer->hashPubKey)); 1787 GNUNET_CONTAINER_bloomfilter_test (peer_bf,
1788 &peer->hashPubKey));
1831 /* remember request for routing replies */ 1789 /* remember request for routing replies */
1832 GDS_ROUTING_add (peer, 1790 GDS_ROUTING_add (peer, type, options, &get->key, xquery, xquery_size,
1833 type, 1791 reply_bf, get->bf_mutator);
1834 options,
1835 &get->key,
1836 xquery, xquery_size,
1837 reply_bf, get->bf_mutator);
1838#if DEBUG_DHT 1792#if DEBUG_DHT
1839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1793 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET for %s at %s after %u hops\n",
1840 "GET for %s at %s after %u hops\n", 1794 GNUNET_h2s (&get->key), GNUNET_i2s (&my_identity),
1841 GNUNET_h2s (&get->key), 1795 (unsigned int) ntohl (get->hop_count));
1842 GNUNET_i2s (&my_identity),
1843 (unsigned int) ntohl (get->hop_count));
1844#endif 1796#endif
1845 /* local lookup (this may update the reply_bf) */ 1797 /* local lookup (this may update the reply_bf) */
1846 if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || 1798 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
1847 (am_closest_peer (&get->key, 1799 (am_closest_peer (&get->key, peer_bf)))
1848 peer_bf) ) ) 1800 {
1849 { 1801 if ((0 != (options & GNUNET_DHT_RO_FIND_PEER)))
1850 if ( (0 != (options & GNUNET_DHT_RO_FIND_PEER)))
1851 { 1802 {
1852 GNUNET_STATISTICS_update (GDS_stats, 1803 GNUNET_STATISTICS_update (GDS_stats,
1853 gettext_noop ("# P2P FIND PEER requests processed"), 1, 1804 gettext_noop
1854 GNUNET_NO); 1805 ("# P2P FIND PEER requests processed"), 1,
1855 handle_find_peer (peer, 1806 GNUNET_NO);
1856 &get->key, 1807 handle_find_peer (peer, &get->key, reply_bf, get->bf_mutator);
1857 reply_bf,
1858 get->bf_mutator);
1859 } 1808 }
1860 else 1809 else
1861 { 1810 {
1862 eval = GDS_DATACACHE_handle_get (&get->key, 1811 eval =
1863 type, 1812 GDS_DATACACHE_handle_get (&get->key, type, xquery, xquery_size,
1864 xquery, xquery_size, 1813 &reply_bf, get->bf_mutator);
1865 &reply_bf,
1866 get->bf_mutator);
1867 } 1814 }
1868 } 1815 }
1869 else 1816 else
1870 { 1817 {
1871 GNUNET_STATISTICS_update (GDS_stats, 1818 GNUNET_STATISTICS_update (GDS_stats,
1872 gettext_noop ("# P2P GET requests ONLY routed"), 1, 1819 gettext_noop ("# P2P GET requests ONLY routed"),
1873 GNUNET_NO); 1820 1, GNUNET_NO);
1874 } 1821 }
1875 1822
1876 /* P2P forwarding */ 1823 /* P2P forwarding */
1877 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) 1824 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
1878 GDS_NEIGHBOURS_handle_get (type, 1825 GDS_NEIGHBOURS_handle_get (type, options,
1879 options, 1826 ntohl (get->desired_replication_level),
1880 ntohl (get->desired_replication_level), 1827 ntohl (get->hop_count), &get->key, xquery,
1881 ntohl (get->hop_count), 1828 xquery_size, reply_bf, get->bf_mutator, peer_bf);
1882 &get->key,
1883 xquery, xquery_size,
1884 reply_bf,
1885 get->bf_mutator,
1886 peer_bf);
1887 /* clean up */ 1829 /* clean up */
1888 if (NULL != reply_bf) 1830 if (NULL != reply_bf)
1889 GNUNET_CONTAINER_bloomfilter_free (reply_bf); 1831 GNUNET_CONTAINER_bloomfilter_free (reply_bf);
1890 GNUNET_CONTAINER_bloomfilter_free (peer_bf); 1832 GNUNET_CONTAINER_bloomfilter_free (peer_bf);
1891 return GNUNET_YES; 1833 return GNUNET_YES;
1892} 1834}
1893 1835
@@ -1904,10 +1846,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1904 */ 1846 */
1905static int 1847static int
1906handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, 1848handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1907 const struct GNUNET_MessageHeader *message, 1849 const struct GNUNET_MessageHeader *message,
1908 const struct GNUNET_ATS_Information 1850 const struct GNUNET_ATS_Information *atsi,
1909 *atsi, 1851 unsigned int atsi_count)
1910 unsigned int atsi_count)
1911{ 1852{
1912 const struct PeerResultMessage *prm; 1853 const struct PeerResultMessage *prm;
1913 const struct GNUNET_PeerIdentity *put_path; 1854 const struct GNUNET_PeerIdentity *put_path;
@@ -1918,7 +1859,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1918 uint16_t msize; 1859 uint16_t msize;
1919 size_t data_size; 1860 size_t data_size;
1920 enum GNUNET_BLOCK_Type type; 1861 enum GNUNET_BLOCK_Type type;
1921 1862
1922 /* parse and validate message */ 1863 /* parse and validate message */
1923 msize = ntohs (message->size); 1864 msize = ntohs (message->size);
1924 if (msize < sizeof (struct PeerResultMessage)) 1865 if (msize < sizeof (struct PeerResultMessage))
@@ -1929,23 +1870,28 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1929 prm = (struct PeerResultMessage *) message; 1870 prm = (struct PeerResultMessage *) message;
1930 put_path_length = ntohl (prm->put_path_length); 1871 put_path_length = ntohl (prm->put_path_length);
1931 get_path_length = ntohl (prm->get_path_length); 1872 get_path_length = ntohl (prm->get_path_length);
1932 if ( (msize < sizeof (struct PeerResultMessage) + 1873 if ((msize <
1933 (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity)) || 1874 sizeof (struct PeerResultMessage) + (get_path_length +
1934 (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || 1875 put_path_length) *
1935 (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ) 1876 sizeof (struct GNUNET_PeerIdentity)) ||
1877 (get_path_length >
1878 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
1879 (put_path_length >
1880 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
1936 { 1881 {
1937 GNUNET_break_op (0); 1882 GNUNET_break_op (0);
1938 return GNUNET_YES; 1883 return GNUNET_YES;
1939 } 1884 }
1940 GNUNET_STATISTICS_update (GDS_stats, 1885 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P RESULTS received"),
1941 gettext_noop ("# P2P RESULTS received"), 1, 1886 1, GNUNET_NO);
1942 GNUNET_NO); 1887 put_path = (const struct GNUNET_PeerIdentity *) &prm[1];
1943 put_path = (const struct GNUNET_PeerIdentity*) &prm[1];
1944 get_path = &put_path[put_path_length]; 1888 get_path = &put_path[put_path_length];
1945 type = ntohl (prm->type); 1889 type = ntohl (prm->type);
1946 data = (const void*) &get_path[get_path_length]; 1890 data = (const void *) &get_path[get_path_length];
1947 data_size = msize - (sizeof (struct PeerResultMessage) + 1891 data_size =
1948 (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity)); 1892 msize - (sizeof (struct PeerResultMessage) +
1893 (get_path_length +
1894 put_path_length) * sizeof (struct GNUNET_PeerIdentity));
1949 1895
1950 /* if we got a HELLO, consider it for our own routing table */ 1896 /* if we got a HELLO, consider it for our own routing table */
1951 if (type == GNUNET_BLOCK_TYPE_DHT_HELLO) 1897 if (type == GNUNET_BLOCK_TYPE_DHT_HELLO)
@@ -1967,8 +1913,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1967 return GNUNET_YES; 1913 return GNUNET_YES;
1968 } 1914 }
1969 if (GNUNET_OK != 1915 if (GNUNET_OK !=
1970 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*) h, 1916 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h, &pid))
1971 &pid))
1972 { 1917 {
1973 GNUNET_break_op (0); 1918 GNUNET_break_op (0);
1974 return GNUNET_YES; 1919 return GNUNET_YES;
@@ -1976,49 +1921,35 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1976 if (0 != memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity))) 1921 if (0 != memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity)))
1977 { 1922 {
1978 bucket = find_bucket (&pid.hashPubKey); 1923 bucket = find_bucket (&pid.hashPubKey);
1979 if ( (bucket >= 0) && 1924 if ((bucket >= 0) && (k_buckets[bucket].peers_size < bucket_size))
1980 (k_buckets[bucket].peers_size < bucket_size) ) 1925 {
1981 { 1926 if (NULL != GDS_transport_handle)
1982 if (NULL != GDS_transport_handle) 1927 {
1983 { 1928 GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, h, NULL, NULL);
1984 GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, 1929 GNUNET_TRANSPORT_try_connect (GDS_transport_handle, &pid);
1985 h, NULL, NULL); 1930 }
1986 GNUNET_TRANSPORT_try_connect (GDS_transport_handle, 1931 }
1987 &pid);
1988 }
1989 }
1990 } 1932 }
1991 } 1933 }
1992 1934
1993 /* append 'peer' to 'get_path' */ 1935 /* append 'peer' to 'get_path' */
1994 { 1936 {
1995 struct GNUNET_PeerIdentity xget_path[get_path_length+1]; 1937 struct GNUNET_PeerIdentity xget_path[get_path_length + 1];
1996 1938
1997 memcpy (xget_path, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); 1939 memcpy (xget_path, get_path,
1940 get_path_length * sizeof (struct GNUNET_PeerIdentity));
1998 xget_path[get_path_length] = *peer; 1941 xget_path[get_path_length] = *peer;
1999 get_path_length++; 1942 get_path_length++;
2000 1943
2001 /* forward to local clients */ 1944 /* forward to local clients */
2002 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time), 1945 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time),
2003 &prm->key, 1946 &prm->key, get_path_length, xget_path,
2004 get_path_length, 1947 put_path_length, put_path, type, data_size, data);
2005 xget_path,
2006 put_path_length,
2007 put_path,
2008 type,
2009 data_size,
2010 data);
2011 1948
2012 /* forward to other peers */ 1949 /* forward to other peers */
2013 GDS_ROUTING_process (type, 1950 GDS_ROUTING_process (type, GNUNET_TIME_absolute_ntoh (prm->expiration_time),
2014 GNUNET_TIME_absolute_ntoh (prm->expiration_time), 1951 &prm->key, put_path_length, put_path, get_path_length,
2015 &prm->key, 1952 xget_path, data, data_size);
2016 put_path_length,
2017 put_path,
2018 get_path_length,
2019 xget_path,
2020 data,
2021 data_size);
2022 } 1953 }
2023 return GNUNET_YES; 1954 return GNUNET_YES;
2024} 1955}
@@ -2039,21 +1970,16 @@ GDS_NEIGHBOURS_init ()
2039 {NULL, 0, 0} 1970 {NULL, 0, 0}
2040 }; 1971 };
2041 unsigned long long temp_config_num; 1972 unsigned long long temp_config_num;
2042 1973
2043 if (GNUNET_OK == 1974 if (GNUNET_OK ==
2044 GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size", 1975 GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size",
2045 &temp_config_num)) 1976 &temp_config_num))
2046 bucket_size = (unsigned int) temp_config_num; 1977 bucket_size = (unsigned int) temp_config_num;
2047 atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); 1978 atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL);
2048 coreAPI = GNUNET_CORE_connect (GDS_cfg, 1979 coreAPI =
2049 1, 1980 GNUNET_CORE_connect (GDS_cfg, 1, NULL, &core_init, &handle_core_connect,
2050 NULL, 1981 &handle_core_disconnect, NULL, GNUNET_NO, NULL,
2051 &core_init, 1982 GNUNET_NO, core_handlers);
2052 &handle_core_connect,
2053 &handle_core_disconnect,
2054 NULL, GNUNET_NO,
2055 NULL, GNUNET_NO,
2056 core_handlers);
2057 if (coreAPI == NULL) 1983 if (coreAPI == NULL)
2058 return GNUNET_SYSERR; 1984 return GNUNET_SYSERR;
2059 all_known_peers = GNUNET_CONTAINER_multihashmap_create (256); 1985 all_known_peers = GNUNET_CONTAINER_multihashmap_create (256);
@@ -2070,9 +1996,9 @@ GDS_NEIGHBOURS_done ()
2070 if (coreAPI == NULL) 1996 if (coreAPI == NULL)
2071 return; 1997 return;
2072 GNUNET_CORE_disconnect (coreAPI); 1998 GNUNET_CORE_disconnect (coreAPI);
2073 coreAPI = NULL; 1999 coreAPI = NULL;
2074 GNUNET_ATS_performance_done (atsAPI); 2000 GNUNET_ATS_performance_done (atsAPI);
2075 atsAPI = NULL; 2001 atsAPI = NULL;
2076 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)); 2002 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers));
2077 GNUNET_CONTAINER_multihashmap_destroy (all_known_peers); 2003 GNUNET_CONTAINER_multihashmap_destroy (all_known_peers);
2078 all_known_peers = NULL; 2004 all_known_peers = NULL;