diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-10-18 19:41:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-10-18 19:41:06 +0000 |
commit | 4ef41d6e9d0fd46311c3267e26f0e73281f090b7 (patch) | |
tree | 1ce61b9ddcf8eb2d2d30ccd50d5bcc58c25621b5 | |
parent | 6ef954d076ce02e91eac5e898ca867e59e8c9e15 (diff) | |
download | gnunet-4ef41d6e9d0fd46311c3267e26f0e73281f090b7.tar.gz gnunet-4ef41d6e9d0fd46311c3267e26f0e73281f090b7.zip |
rename all_known_peers to all_connected_peers
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index f2897f1fa..f4d817223 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -404,14 +404,15 @@ static unsigned int newly_found_peers; | |||
404 | static int disable_try_connect; | 404 | static int disable_try_connect; |
405 | 405 | ||
406 | /** | 406 | /** |
407 | * The buckets. Array of size MAX_BUCKET_SIZE. Offset 0 means 0 bits matching. | 407 | * The buckets. Array of size #MAX_BUCKETS. Offset 0 means 0 bits matching. |
408 | */ | 408 | */ |
409 | static struct PeerBucket k_buckets[MAX_BUCKETS]; | 409 | static struct PeerBucket k_buckets[MAX_BUCKETS]; |
410 | 410 | ||
411 | /** | 411 | /** |
412 | * Hash map of all known peers, for easy removal from k_buckets on disconnect. | 412 | * Hash map of all CORE-connected peers, for easy removal from |
413 | * #k_buckets on disconnect. | ||
413 | */ | 414 | */ |
414 | static struct GNUNET_CONTAINER_MultiPeerMap *all_known_peers; | 415 | static struct GNUNET_CONTAINER_MultiPeerMap *all_connected_peers; |
415 | 416 | ||
416 | /** | 417 | /** |
417 | * Maximum size for each bucket. | 418 | * Maximum size for each bucket. |
@@ -609,7 +610,8 @@ send_find_peer_message (void *cls, | |||
609 | bcc.bloom = | 610 | bcc.bloom = |
610 | GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, | 611 | GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, |
611 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 612 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
612 | GNUNET_CONTAINER_multipeermap_iterate (all_known_peers, &add_known_to_bloom, | 613 | GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, |
614 | &add_known_to_bloom, | ||
613 | &bcc); | 615 | &bcc); |
614 | GNUNET_STATISTICS_update (GDS_stats, | 616 | GNUNET_STATISTICS_update (GDS_stats, |
615 | gettext_noop ("# FIND PEER messages initiated"), 1, | 617 | gettext_noop ("# FIND PEER messages initiated"), 1, |
@@ -645,7 +647,8 @@ send_find_peer_message (void *cls, | |||
645 | * @param peer peer identity this notification is about | 647 | * @param peer peer identity this notification is about |
646 | */ | 648 | */ |
647 | static void | 649 | static void |
648 | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 650 | handle_core_connect (void *cls, |
651 | const struct GNUNET_PeerIdentity *peer) | ||
649 | { | 652 | { |
650 | struct PeerInfo *ret; | 653 | struct PeerInfo *ret; |
651 | struct GNUNET_HashCode phash; | 654 | struct GNUNET_HashCode phash; |
@@ -658,7 +661,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
658 | "Connected to %s\n", | 661 | "Connected to %s\n", |
659 | GNUNET_i2s (peer)); | 662 | GNUNET_i2s (peer)); |
660 | if (GNUNET_YES == | 663 | if (GNUNET_YES == |
661 | GNUNET_CONTAINER_multipeermap_contains (all_known_peers, | 664 | GNUNET_CONTAINER_multipeermap_contains (all_connected_peers, |
662 | peer)) | 665 | peer)) |
663 | { | 666 | { |
664 | GNUNET_break (0); | 667 | GNUNET_break (0); |
@@ -678,7 +681,8 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
678 | #endif | 681 | #endif |
679 | ret->id = *peer; | 682 | ret->id = *peer; |
680 | GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head, | 683 | GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head, |
681 | k_buckets[peer_bucket].tail, ret); | 684 | k_buckets[peer_bucket].tail, |
685 | ret); | ||
682 | k_buckets[peer_bucket].peers_size++; | 686 | k_buckets[peer_bucket].peers_size++; |
683 | closest_bucket = GNUNET_MAX (closest_bucket, peer_bucket); | 687 | closest_bucket = GNUNET_MAX (closest_bucket, peer_bucket); |
684 | if ((peer_bucket > 0) && (k_buckets[peer_bucket].peers_size <= bucket_size)) | 688 | if ((peer_bucket > 0) && (k_buckets[peer_bucket].peers_size <= bucket_size)) |
@@ -688,14 +692,16 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
688 | newly_found_peers++; | 692 | newly_found_peers++; |
689 | } | 693 | } |
690 | GNUNET_assert (GNUNET_OK == | 694 | GNUNET_assert (GNUNET_OK == |
691 | GNUNET_CONTAINER_multipeermap_put (all_known_peers, | 695 | GNUNET_CONTAINER_multipeermap_put (all_connected_peers, |
692 | peer, ret, | 696 | peer, |
697 | ret, | ||
693 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 698 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
694 | if (1 == GNUNET_CONTAINER_multipeermap_size (all_known_peers) && | 699 | if (1 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers) && |
695 | (GNUNET_YES != disable_try_connect)) | 700 | (GNUNET_YES != disable_try_connect)) |
696 | { | 701 | { |
697 | /* got a first connection, good time to start with FIND PEER requests... */ | 702 | /* got a first connection, good time to start with FIND PEER requests... */ |
698 | find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, NULL); | 703 | find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, |
704 | NULL); | ||
699 | } | 705 | } |
700 | } | 706 | } |
701 | 707 | ||
@@ -723,7 +729,8 @@ handle_core_disconnect (void *cls, | |||
723 | "Disconnected %s\n", | 729 | "Disconnected %s\n", |
724 | GNUNET_i2s (peer)); | 730 | GNUNET_i2s (peer)); |
725 | to_remove = | 731 | to_remove = |
726 | GNUNET_CONTAINER_multipeermap_get (all_known_peers, peer); | 732 | GNUNET_CONTAINER_multipeermap_get (all_connected_peers, |
733 | peer); | ||
727 | if (NULL == to_remove) | 734 | if (NULL == to_remove) |
728 | { | 735 | { |
729 | GNUNET_break (0); | 736 | GNUNET_break (0); |
@@ -732,7 +739,7 @@ handle_core_disconnect (void *cls, | |||
732 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), -1, | 739 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), -1, |
733 | GNUNET_NO); | 740 | GNUNET_NO); |
734 | GNUNET_assert (GNUNET_YES == | 741 | GNUNET_assert (GNUNET_YES == |
735 | GNUNET_CONTAINER_multipeermap_remove (all_known_peers, | 742 | GNUNET_CONTAINER_multipeermap_remove (all_connected_peers, |
736 | peer, | 743 | peer, |
737 | to_remove)); | 744 | to_remove)); |
738 | if (NULL != to_remove->preference_task) | 745 | if (NULL != to_remove->preference_task) |
@@ -1237,9 +1244,12 @@ get_target_peers (const struct GNUNET_HashCode *key, | |||
1237 | GNUNET_CONTAINER_bloomfilter_add (bloom, &nhash); | 1244 | GNUNET_CONTAINER_bloomfilter_add (bloom, &nhash); |
1238 | } | 1245 | } |
1239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1240 | "Selected %u/%u peers at hop %u for %s (target was %u)\n", off, | 1247 | "Selected %u/%u peers at hop %u for %s (target was %u)\n", |
1241 | GNUNET_CONTAINER_multipeermap_size (all_known_peers), | 1248 | off, |
1242 | (unsigned int) hop_count, GNUNET_h2s (key), ret); | 1249 | GNUNET_CONTAINER_multipeermap_size (all_connected_peers), |
1250 | (unsigned int) hop_count, | ||
1251 | GNUNET_h2s (key), | ||
1252 | ret); | ||
1243 | if (0 == off) | 1253 | if (0 == off) |
1244 | { | 1254 | { |
1245 | GNUNET_free (rtargets); | 1255 | GNUNET_free (rtargets); |
@@ -1536,12 +1546,13 @@ void | |||
1536 | GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | 1546 | GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, |
1537 | enum GNUNET_BLOCK_Type type, | 1547 | enum GNUNET_BLOCK_Type type, |
1538 | struct GNUNET_TIME_Absolute expiration_time, | 1548 | struct GNUNET_TIME_Absolute expiration_time, |
1539 | const struct GNUNET_HashCode * key, | 1549 | const struct GNUNET_HashCode *key, |
1540 | unsigned int put_path_length, | 1550 | unsigned int put_path_length, |
1541 | const struct GNUNET_PeerIdentity *put_path, | 1551 | const struct GNUNET_PeerIdentity *put_path, |
1542 | unsigned int get_path_length, | 1552 | unsigned int get_path_length, |
1543 | const struct GNUNET_PeerIdentity *get_path, | 1553 | const struct GNUNET_PeerIdentity *get_path, |
1544 | const void *data, size_t data_size) | 1554 | const void *data, |
1555 | size_t data_size) | ||
1545 | { | 1556 | { |
1546 | struct PeerInfo *pi; | 1557 | struct PeerInfo *pi; |
1547 | struct P2PPendingMessage *pending; | 1558 | struct P2PPendingMessage *pending; |
@@ -1563,7 +1574,8 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | |||
1563 | GNUNET_break (0); | 1574 | GNUNET_break (0); |
1564 | return; | 1575 | return; |
1565 | } | 1576 | } |
1566 | pi = GNUNET_CONTAINER_multipeermap_get (all_known_peers, target); | 1577 | pi = GNUNET_CONTAINER_multipeermap_get (all_connected_peers, |
1578 | target); | ||
1567 | if (NULL == pi) | 1579 | if (NULL == pi) |
1568 | { | 1580 | { |
1569 | /* peer disconnected in the meantime, drop reply */ | 1581 | /* peer disconnected in the meantime, drop reply */ |
@@ -2258,7 +2270,8 @@ GDS_NEIGHBOURS_init () | |||
2258 | GNUNET_NO, core_handlers); | 2270 | GNUNET_NO, core_handlers); |
2259 | if (core_api == NULL) | 2271 | if (core_api == NULL) |
2260 | return GNUNET_SYSERR; | 2272 | return GNUNET_SYSERR; |
2261 | all_known_peers = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); | 2273 | all_connected_peers = GNUNET_CONTAINER_multipeermap_create (256, |
2274 | GNUNET_NO); | ||
2262 | return GNUNET_OK; | 2275 | return GNUNET_OK; |
2263 | } | 2276 | } |
2264 | 2277 | ||
@@ -2277,9 +2290,9 @@ GDS_NEIGHBOURS_done () | |||
2277 | ats_perf = NULL; | 2290 | ats_perf = NULL; |
2278 | GNUNET_ATS_connectivity_done (ats_ch); | 2291 | GNUNET_ATS_connectivity_done (ats_ch); |
2279 | ats_ch = NULL; | 2292 | ats_ch = NULL; |
2280 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (all_known_peers)); | 2293 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)); |
2281 | GNUNET_CONTAINER_multipeermap_destroy (all_known_peers); | 2294 | GNUNET_CONTAINER_multipeermap_destroy (all_connected_peers); |
2282 | all_known_peers = NULL; | 2295 | all_connected_peers = NULL; |
2283 | if (NULL != find_peer_task) | 2296 | if (NULL != find_peer_task) |
2284 | { | 2297 | { |
2285 | GNUNET_SCHEDULER_cancel (find_peer_task); | 2298 | GNUNET_SCHEDULER_cancel (find_peer_task); |