aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rps/Makefile.am3
-rw-r--r--src/rps/gnunet-service-rps.c123
2 files changed, 52 insertions, 74 deletions
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am
index 4091b2c17..9425c6e87 100644
--- a/src/rps/Makefile.am
+++ b/src/rps/Makefile.am
@@ -47,8 +47,9 @@ endif
47 47
48 48
49gnunet_service_rps_SOURCES = \ 49gnunet_service_rps_SOURCES = \
50 gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \
51 gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c \ 50 gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c \
51 gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \
52 gnunet-service-rps_peers.h gnunet-service-rps_peers.c \
52 rps-test_util.h rps-test_util.c \ 53 rps-test_util.h rps-test_util.c \
53 gnunet-service-rps.c 54 gnunet-service-rps.c
54 55
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 872598e03..ba6dbee3e 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -29,6 +29,7 @@
29#include "gnunet_peerinfo_service.h" 29#include "gnunet_peerinfo_service.h"
30#include "gnunet_nse_service.h" 30#include "gnunet_nse_service.h"
31#include "rps.h" 31#include "rps.h"
32#include "gnunet-service-rps_peers.h"
32#include "rps-test_util.h" 33#include "rps-test_util.h"
33 34
34#include "gnunet-service-rps_sampler.h" 35#include "gnunet-service-rps_sampler.h"
@@ -366,29 +367,13 @@ static struct GNUNET_TIME_Relative round_interval;
366 367
367/** 368/**
368 * List to store peers received through pushes temporary. 369 * List to store peers received through pushes temporary.
369 *
370 * TODO -> multipeermap
371 */
372static struct GNUNET_PeerIdentity *push_list;
373
374/**
375 * Size of the push_list;
376 */ 370 */
377static unsigned int push_list_size; 371static struct CustomPeerMap *push_map;
378//size_t push_list_size;
379 372
380/** 373/**
381 * List to store peers received through pulls temporary. 374 * List to store peers received through pulls temporary.
382 *
383 * TODO -> multipeermap
384 */ 375 */
385static struct GNUNET_PeerIdentity *pull_list; 376static struct CustomPeerMap *pull_map;
386
387/**
388 * Size of the pull_list;
389 */
390static unsigned int pull_list_size;
391//size_t pull_list_size;
392 377
393 378
394/** 379/**
@@ -935,27 +920,26 @@ T_relative_avg (const struct GNUNET_TIME_Relative *rel_array, uint32_t arr_size)
935 920
936 921
937/** 922/**
938 * Insert PeerID in #pull_list 923 * Insert PeerID in #pull_map
939 * 924 *
940 * Called once we know a peer is live. 925 * Called once we know a peer is live.
941 */ 926 */
942 void 927 void
943insert_in_pull_list (void *cls, const struct GNUNET_PeerIdentity *peer) 928insert_in_pull_map (void *cls, const struct GNUNET_PeerIdentity *peer)
944{ 929{
945 if (GNUNET_NO == in_arr (pull_list, pull_list_size, peer)) 930 CustomPeerMap_put (pull_map, peer);
946 GNUNET_array_append (pull_list, pull_list_size, *peer);
947} 931}
948 932
949/** 933/**
950 * Check whether #insert_in_pull_list was already scheduled 934 * Check whether #insert_in_pull_map was already scheduled
951 */ 935 */
952 int 936 int
953insert_in_pull_list_scheduled (const struct PeerContext *peer_ctx) 937insert_in_pull_map_scheduled (const struct PeerContext *peer_ctx)
954{ 938{
955 unsigned int i; 939 unsigned int i;
956 940
957 for ( i = 0 ; i < peer_ctx->num_outstanding_ops ; i++ ) 941 for ( i = 0 ; i < peer_ctx->num_outstanding_ops ; i++ )
958 if (insert_in_pull_list == peer_ctx->outstanding_ops[i].op) 942 if (insert_in_pull_map == peer_ctx->outstanding_ops[i].op)
959 return GNUNET_YES; 943 return GNUNET_YES;
960 return GNUNET_NO; 944 return GNUNET_NO;
961} 945}
@@ -1686,12 +1670,8 @@ handle_peer_push (void *cls,
1686 1670
1687 #endif /* ENABLE_MALICIOUS */ 1671 #endif /* ENABLE_MALICIOUS */
1688 1672
1689 /* Add the sending peer to the push_list */ 1673 /* Add the sending peer to the push_map */
1690 if (GNUNET_NO == in_arr (push_list, push_list_size, peer)) 1674 CustomPeerMap_put (push_map, peer);
1691 {
1692 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer));
1693 GNUNET_array_append (push_list, push_list_size, *peer);
1694 }
1695 1675
1696 GNUNET_CADET_receive_done (channel); 1676 GNUNET_CADET_receive_done (channel);
1697 return GNUNET_OK; 1677 return GNUNET_OK;
@@ -1925,12 +1905,11 @@ handle_peer_pull_reply (void *cls,
1925 1905
1926 if (GNUNET_YES == get_peer_flag (peer_ctx, VALID)) 1906 if (GNUNET_YES == get_peer_flag (peer_ctx, VALID))
1927 { 1907 {
1928 if (GNUNET_NO == in_arr (pull_list, pull_list_size, &peers[i])) 1908 CustomPeerMap_put (pull_map, &peers[i]);
1929 GNUNET_array_append (pull_list, pull_list_size, peers[i]);
1930 } 1909 }
1931 else if (GNUNET_NO == insert_in_pull_list_scheduled (peer_ctx)) 1910 else if (GNUNET_NO == insert_in_pull_map_scheduled (peer_ctx))
1932 { 1911 {
1933 out_op.op = insert_in_pull_list; 1912 out_op.op = insert_in_pull_map;
1934 out_op.op_cls = NULL; 1913 out_op.op_cls = NULL;
1935 GNUNET_array_append (peer_ctx->outstanding_ops, 1914 GNUNET_array_append (peer_ctx->outstanding_ops,
1936 peer_ctx->num_outstanding_ops, 1915 peer_ctx->num_outstanding_ops,
@@ -2344,6 +2323,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2344 uint32_t second_border; 2323 uint32_t second_border;
2345 struct GNUNET_PeerIdentity peer; 2324 struct GNUNET_PeerIdentity peer;
2346 struct PeerContext *peer_ctx; 2325 struct PeerContext *peer_ctx;
2326 struct GNUNET_PeerIdentity *update_peer;
2347 2327
2348 do_round_task = NULL; 2328 do_round_task = NULL;
2349 LOG (GNUNET_ERROR_TYPE_DEBUG, 2329 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2414,10 +2394,10 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2414 /* Update view */ 2394 /* Update view */
2415 /* TODO see how many peers are in push-/pull- list! */ 2395 /* TODO see how many peers are in push-/pull- list! */
2416 2396
2417 if (push_list_size <= alpha * view_size && 2397 if ((CustomPeerMap_size (push_map) <= alpha * view_size) &&
2418 0 < push_list_size && 2398 (0 < CustomPeerMap_size (push_map)) &&
2419 0 < pull_list_size) 2399 (0 < CustomPeerMap_size (pull_map)))
2420 { 2400 { /* If conditions for update are fulfilled, update */
2421 LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n"); 2401 LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n");
2422 2402
2423 uint32_t final_size; 2403 uint32_t final_size;
@@ -2438,10 +2418,10 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2438 "--- emptied ---"); 2418 "--- emptied ---");
2439 2419
2440 first_border = GNUNET_MIN (ceil (alpha * sampler_size_est_need), 2420 first_border = GNUNET_MIN (ceil (alpha * sampler_size_est_need),
2441 push_list_size); 2421 CustomPeerMap_size (push_map));
2442 second_border = first_border + 2422 second_border = first_border +
2443 GNUNET_MIN (floor (beta * sampler_size_est_need), 2423 GNUNET_MIN (floor (beta * sampler_size_est_need),
2444 pull_list_size); 2424 CustomPeerMap_size (pull_map));
2445 final_size = second_border + 2425 final_size = second_border +
2446 ceil ((1 - (alpha + beta)) * sampler_size_est_need); 2426 ceil ((1 - (alpha + beta)) * sampler_size_est_need);
2447 2427
@@ -2449,11 +2429,11 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2449 2429
2450 /* Update view with peers received through PUSHes */ 2430 /* Update view with peers received through PUSHes */
2451 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, 2431 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG,
2452 push_list_size); 2432 CustomPeerMap_size (push_map));
2453 for (i = 0; i < first_border; i++) 2433 for (i = 0; i < first_border; i++)
2454 { 2434 {
2455 view_array[i] = push_list[permut[i]]; 2435 view_array[i] = *CustomPeerMap_get_peer_by_index (push_map, permut[i]);
2456 GNUNET_CONTAINER_multipeermap_put (view, &push_list[permut[i]], NULL, 2436 GNUNET_CONTAINER_multipeermap_put (view, &view_array[i], NULL,
2457 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 2437 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
2458 2438
2459 to_file (file_name_view_log, 2439 to_file (file_name_view_log,
@@ -2466,13 +2446,12 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2466 2446
2467 /* Update view with peers received through PULLs */ 2447 /* Update view with peers received through PULLs */
2468 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, 2448 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG,
2469 pull_list_size); 2449 CustomPeerMap_size (pull_map));
2470 for (i = first_border; i < second_border; i++) 2450 for (i = first_border; i < second_border; i++)
2471 { 2451 {
2472 view_array[i] = pull_list[permut[i - first_border]]; 2452 view_array[i] =
2473 GNUNET_CONTAINER_multipeermap_put (view, 2453 *CustomPeerMap_get_peer_by_index (pull_map, permut[i - first_border]);
2474 &pull_list[permut[i - first_border]], 2454 GNUNET_CONTAINER_multipeermap_put (view, &view_array[i], NULL,
2475 NULL,
2476 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 2455 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
2477 2456
2478 to_file (file_name_view_log, 2457 to_file (file_name_view_log,
@@ -2514,35 +2493,37 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2514 2493
2515 LOG (GNUNET_ERROR_TYPE_DEBUG, 2494 LOG (GNUNET_ERROR_TYPE_DEBUG,
2516 "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (%u) = %.2f)\n", 2495 "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (%u) = %.2f)\n",
2517 push_list_size, 2496 CustomPeerMap_size (push_map),
2518 pull_list_size, 2497 CustomPeerMap_size (pull_map),
2519 alpha, 2498 alpha,
2520 view_size, 2499 view_size,
2521 alpha * view_size); 2500 alpha * view_size);
2522 2501
2523 /* Update samplers */ 2502 /* Update samplers */
2524 for (i = 0; i < push_list_size; i++) 2503 for (i = 0; i < CustomPeerMap_size (push_map); i++)
2525 { 2504 {
2505 update_peer = CustomPeerMap_get_peer_by_index (push_map, i);
2526 LOG (GNUNET_ERROR_TYPE_DEBUG, 2506 LOG (GNUNET_ERROR_TYPE_DEBUG,
2527 "Updating with peer %s from push list\n", 2507 "Updating with peer %s from push list\n",
2528 GNUNET_i2s (&push_list[i])); 2508 GNUNET_i2s (update_peer));
2529 insert_in_sampler (NULL, &push_list[i]); 2509 insert_in_sampler (NULL, update_peer);
2530 peer_clean (&push_list[i]); /* This cleans only if it is not in the view */ 2510 peer_clean (update_peer); /* This cleans only if it is not in the view */
2531 } 2511 }
2532 2512
2533 for (i = 0; i < pull_list_size; i++) 2513 for (i = 0; i < CustomPeerMap_size (pull_map); i++)
2534 { 2514 {
2535 LOG (GNUNET_ERROR_TYPE_DEBUG, 2515 LOG (GNUNET_ERROR_TYPE_DEBUG,
2536 "Updating with peer %s from pull list\n", 2516 "Updating with peer %s from pull list\n",
2537 GNUNET_i2s (&pull_list[i])); 2517 GNUNET_i2s (CustomPeerMap_get_peer_by_index (pull_map, i)));
2538 insert_in_sampler (NULL, &pull_list[i]); 2518 insert_in_sampler (NULL, CustomPeerMap_get_peer_by_index (pull_map, i));
2539 peer_clean (&pull_list[i]); /* This cleans only if it is not in the view */ 2519 /* This cleans only if it is not in the view */
2520 peer_clean (CustomPeerMap_get_peer_by_index (pull_map, i));
2540 } 2521 }
2541 2522
2542 2523
2543 /* Empty push/pull lists */ 2524 /* Empty push/pull lists */
2544 GNUNET_array_grow (push_list, push_list_size, 0); 2525 CustomPeerMap_clear (push_map);
2545 GNUNET_array_grow (pull_list, pull_list_size, 0); 2526 CustomPeerMap_clear (pull_map);
2546 2527
2547 struct GNUNET_TIME_Relative time_next_round; 2528 struct GNUNET_TIME_Relative time_next_round;
2548 2529
@@ -2662,10 +2643,8 @@ peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2662 } 2643 }
2663 2644
2664 /* Remove from push and pull lists */ 2645 /* Remove from push and pull lists */
2665 if (GNUNET_YES == in_arr (push_list, push_list_size, key)) 2646 CustomPeerMap_remove_peer (push_map, key);
2666 rem_from_list (&push_list, &push_list_size, key); 2647 CustomPeerMap_remove_peer (pull_map, key);
2667 if (GNUNET_YES == in_arr (pull_list, pull_list_size, key))
2668 rem_from_list (&pull_list, &pull_list_size, key);
2669 2648
2670 /* Cancle messages that have not been sent yet */ 2649 /* Cancle messages that have not been sent yet */
2671 while (NULL != peer_ctx->pending_messages_head) 2650 while (NULL != peer_ctx->pending_messages_head)
@@ -2730,8 +2709,8 @@ peer_clean (const struct GNUNET_PeerIdentity *peer)
2730 2709
2731 if ( (0 == RPS_sampler_count_id (prot_sampler, peer)) && 2710 if ( (0 == RPS_sampler_count_id (prot_sampler, peer)) &&
2732 (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (view, peer)) && 2711 (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (view, peer)) &&
2733 (GNUNET_NO == in_arr (push_list, push_list_size, peer)) && 2712 (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) &&
2734 (GNUNET_NO == in_arr (pull_list, pull_list_size, peer)) && 2713 (GNUNET_NO == CustomPeerMap_contains_peer (pull_map, peer)) &&
2735 (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) ) 2714 (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) )
2736 { 2715 {
2737 peer_ctx = get_peer_ctx (peer); 2716 peer_ctx = get_peer_ctx (peer);
@@ -2791,8 +2770,8 @@ shutdown_task (void *cls,
2791 GNUNET_CONTAINER_multipeermap_destroy (peer_map); 2770 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
2792 GNUNET_CONTAINER_multipeermap_destroy (view); 2771 GNUNET_CONTAINER_multipeermap_destroy (view);
2793 view = NULL; 2772 view = NULL;
2794 GNUNET_array_grow (push_list, push_list_size, 0); 2773 CustomPeerMap_destroy (push_map);
2795 GNUNET_array_grow (pull_list, pull_list_size, 0); 2774 CustomPeerMap_destroy (pull_map);
2796 #ifdef ENABLE_MALICIOUS 2775 #ifdef ENABLE_MALICIOUS
2797 struct AttackedPeer *tmp_att_peer; 2776 struct AttackedPeer *tmp_att_peer;
2798 GNUNET_array_grow (mal_peers, num_mal_peers, 0); 2777 GNUNET_array_grow (mal_peers, num_mal_peers, 0);
@@ -3131,10 +3110,8 @@ run (void *cls,
3131 client_sampler = RPS_sampler_mod_init (sampler_size_est_need, max_round_interval); 3110 client_sampler = RPS_sampler_mod_init (sampler_size_est_need, max_round_interval);
3132 3111
3133 /* Initialise push and pull maps */ 3112 /* Initialise push and pull maps */
3134 push_list = NULL; 3113 push_map = CustomPeerMap_create (4);
3135 push_list_size = 0; 3114 pull_map = CustomPeerMap_create (4);
3136 pull_list = NULL;
3137 pull_list_size = 0;
3138 3115
3139 3116
3140 num_hist_update_tasks = 0; 3117 num_hist_update_tasks = 0;