aboutsummaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-08-02 14:48:30 +0000
committerJulius Bünger <buenger@mytum.de>2015-08-02 14:48:30 +0000
commit0003886059ee5fc76b17e268efd289b0503cd185 (patch)
tree3605afa784f69d3e249c3d71791ca60c9f3c70bc /src/rps
parentbae0066688e7571b4abdebfb914dba6df0578a6b (diff)
downloadgnunet-0003886059ee5fc76b17e268efd289b0503cd185.tar.gz
gnunet-0003886059ee5fc76b17e268efd289b0503cd185.zip
-improved management of peer information
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/gnunet-service-rps.c98
1 files changed, 48 insertions, 50 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 8c1a1dc12..96a4000de 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -712,48 +712,6 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer)
712 712
713 713
714/** 714/**
715 * Put random peer from sampler into the view as history update.
716 */
717 void
718hist_update (void *cls, struct GNUNET_PeerIdentity *ids, uint32_t num_peers)
719{
720 unsigned int i;
721
722 for (i = 0; i < GNUNET_MIN (
723 sampler_size_est_need - GNUNET_CONTAINER_multipeermap_size (view),
724 num_peers); i++)
725 {
726 /* Make sure there is a context associated with the id in the peermap */
727 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, &ids[i]))
728 (void) create_peer_ctx (&ids[i]);
729
730 if (GNUNET_OK != GNUNET_CONTAINER_multipeermap_put (view,
731 &ids[i],
732 NULL,
733 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
734 {
735 LOG (GNUNET_ERROR_TYPE_WARNING,
736 "Failed to put peer in peermap. (hist_update)\n");
737 }
738
739 /* Might want to check that we really updated the view */
740 if (NULL != view_array)
741 {
742 GNUNET_free (view_array);
743 view_array = NULL;
744 }
745
746 to_file (file_name_view_log,
747 "+%s\t(hist)",
748 GNUNET_i2s_full (ids));
749 }
750
751 if (0 < num_hist_update_tasks)
752 num_hist_update_tasks--;
753}
754
755
756/**
757 * Set the peer flag to living and call the outstanding operations on this peer. 715 * Set the peer flag to living and call the outstanding operations on this peer.
758 */ 716 */
759static size_t 717static size_t
@@ -985,14 +943,13 @@ insert_in_view (void *cls, const struct GNUNET_PeerIdentity *peer)
985 LOG (GNUNET_ERROR_TYPE_WARNING, 943 LOG (GNUNET_ERROR_TYPE_WARNING,
986 "Failed to put peer into view. (insert_in_view)\n"); 944 "Failed to put peer into view. (insert_in_view)\n");
987 } 945 }
988
989 /* Might want to check whether we really modified the view */
990 if (NULL != view_array) 946 if (NULL != view_array)
991 { 947 {
992 GNUNET_free (view_array); 948 GNUNET_free (view_array);
993 view_array = NULL; 949 view_array = NULL;
994 } 950 }
995 951 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
952 create_peer_ctx (peer);
996 (void) get_channel (peer); 953 (void) get_channel (peer);
997} 954}
998 955
@@ -1022,6 +979,12 @@ insert_in_sampler (void *cls, const struct GNUNET_PeerIdentity *peer)
1022 GNUNET_i2s (peer)); 979 GNUNET_i2s (peer));
1023 RPS_sampler_update (prot_sampler, peer); 980 RPS_sampler_update (prot_sampler, peer);
1024 RPS_sampler_update (client_sampler, peer); 981 RPS_sampler_update (client_sampler, peer);
982 if (0 < RPS_sampler_count_id (prot_sampler, peer))
983 {
984 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
985 (void) create_peer_ctx (peer);
986 (void) get_channel (peer);
987 }
1025} 988}
1026 989
1027 990
@@ -1039,6 +1002,28 @@ insert_in_sampler_scheduled (const struct PeerContext *peer_ctx)
1039 return GNUNET_NO; 1002 return GNUNET_NO;
1040} 1003}
1041 1004
1005/**
1006 * Put random peer from sampler into the view as history update.
1007 */
1008 void
1009hist_update (void *cls, struct GNUNET_PeerIdentity *ids, uint32_t num_peers)
1010{
1011 unsigned int i;
1012
1013 for (i = 0; i < GNUNET_MIN (
1014 sampler_size_est_need - GNUNET_CONTAINER_multipeermap_size (view),
1015 num_peers); i++)
1016 {
1017 insert_in_view (NULL, &ids[i]);
1018 to_file (file_name_view_log,
1019 "+%s\t(hist)",
1020 GNUNET_i2s_full (ids));
1021 }
1022 if (0 < num_hist_update_tasks)
1023 num_hist_update_tasks--;
1024}
1025
1026
1042 1027
1043/** 1028/**
1044 * Wrapper around #RPS_sampler_resize() 1029 * Wrapper around #RPS_sampler_resize()
@@ -2421,8 +2406,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2421 LOG (GNUNET_ERROR_TYPE_DEBUG, 2406 LOG (GNUNET_ERROR_TYPE_DEBUG,
2422 "Updating with peer %s from push list\n", 2407 "Updating with peer %s from push list\n",
2423 GNUNET_i2s (&push_list[i])); 2408 GNUNET_i2s (&push_list[i]));
2424 RPS_sampler_update (prot_sampler, &push_list[i]); 2409 insert_in_sampler (NULL, &push_list[i]);
2425 RPS_sampler_update (client_sampler, &push_list[i]);
2426 peer_clean (&push_list[i]); /* This cleans only if it is not in the view */ 2410 peer_clean (&push_list[i]); /* This cleans only if it is not in the view */
2427 } 2411 }
2428 2412
@@ -2431,8 +2415,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2431 LOG (GNUNET_ERROR_TYPE_DEBUG, 2415 LOG (GNUNET_ERROR_TYPE_DEBUG,
2432 "Updating with peer %s from pull list\n", 2416 "Updating with peer %s from pull list\n",
2433 GNUNET_i2s (&pull_list[i])); 2417 GNUNET_i2s (&pull_list[i]));
2434 RPS_sampler_update (prot_sampler, &pull_list[i]); 2418 insert_in_sampler (NULL, &pull_list[i]);
2435 RPS_sampler_update (client_sampler, &pull_list[i]);
2436 peer_clean (&pull_list[i]); /* This cleans only if it is not in the view */ 2419 peer_clean (&pull_list[i]); /* This cleans only if it is not in the view */
2437 } 2420 }
2438 2421
@@ -2520,6 +2503,9 @@ peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2520 "Going to remove peer %s\n", 2503 "Going to remove peer %s\n",
2521 GNUNET_i2s (&peer_ctx->peer_id)); 2504 GNUNET_i2s (&peer_ctx->peer_id));
2522 2505
2506 /* Remove it from the sampler used for the Brahms protocol */
2507 RPS_sampler_reinitialise_by_value (prot_sampler, key);
2508
2523 /* If operations are still scheduled for this peer cancel those */ 2509 /* If operations are still scheduled for this peer cancel those */
2524 if (0 != peer_ctx->num_outstanding_ops) 2510 if (0 != peer_ctx->num_outstanding_ops)
2525 { 2511 {
@@ -2555,6 +2541,12 @@ peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2555 } 2541 }
2556 } 2542 }
2557 2543
2544 /* Remove from push and pull lists */
2545 if (GNUNET_YES == in_arr (push_list, push_list_size, key))
2546 rem_from_list (&push_list, &push_list_size, key);
2547 if (GNUNET_YES == in_arr (pull_list, pull_list_size, key))
2548 rem_from_list (&pull_list, &pull_list_size, key);
2549
2558 /* If there is still a mq destroy it */ 2550 /* If there is still a mq destroy it */
2559 if (NULL != peer_ctx->mq) 2551 if (NULL != peer_ctx->mq)
2560 { 2552 {
@@ -2604,7 +2596,8 @@ peer_clean (const struct GNUNET_PeerIdentity *peer)
2604 struct PeerContext *peer_ctx; 2596 struct PeerContext *peer_ctx;
2605 /* struct GNUNET_CADET_Channel *channel; */ 2597 /* struct GNUNET_CADET_Channel *channel; */
2606 2598
2607 if ( (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (view, peer)) && 2599 if ( (0 == RPS_sampler_count_id (prot_sampler, peer)) &&
2600 (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (view, peer)) &&
2608 (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) && 2601 (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) &&
2609 (GNUNET_NO == in_arr (push_list, push_list_size, peer)) && 2602 (GNUNET_NO == in_arr (push_list, push_list_size, peer)) &&
2610 (GNUNET_NO == in_arr (pull_list, pull_list_size, peer)) ) 2603 (GNUNET_NO == in_arr (pull_list, pull_list_size, peer)) )
@@ -2614,7 +2607,12 @@ peer_clean (const struct GNUNET_PeerIdentity *peer)
2614 if ( (NULL == peer_ctx->recv_channel) && 2607 if ( (NULL == peer_ctx->recv_channel) &&
2615 (GNUNET_NO == get_peer_flag (peer_ctx, PULL_REPLY_PENDING)) ) 2608 (GNUNET_NO == get_peer_flag (peer_ctx, PULL_REPLY_PENDING)) )
2616 { 2609 {
2610 #ifdef ENABLE_MALICIOUS
2611 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer))
2612 peer_remove_cb (NULL, peer, peer_ctx);
2613 #else
2617 peer_remove_cb (NULL, peer, peer_ctx); 2614 peer_remove_cb (NULL, peer, peer_ctx);
2615 #endif /* ENABLE_MALICIOUS */
2618 } 2616 }
2619 } 2617 }
2620} 2618}