aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-service-rps.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps/gnunet-service-rps.c')
-rw-r--r--src/rps/gnunet-service-rps.c283
1 files changed, 0 insertions, 283 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 862514264..e3714bdba 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -1805,11 +1805,6 @@ struct ClientContext *cli_ctx_tail;
1805static struct RPS_Sampler *prot_sampler; 1805static struct RPS_Sampler *prot_sampler;
1806 1806
1807/** 1807/**
1808 * Sampler used for the clients.
1809 */
1810static struct RPS_Sampler *client_sampler;
1811
1812/**
1813 * Name to log view to 1808 * Name to log view to
1814 */ 1809 */
1815static const char *file_name_view_log; 1810static const char *file_name_view_log;
@@ -1832,12 +1827,6 @@ static struct GNUNET_CONTAINER_MultiPeerMap *observed_unique_peers;
1832#endif /* TO_FILE */ 1827#endif /* TO_FILE */
1833 1828
1834/** 1829/**
1835 * The size of sampler we need to be able to satisfy the client's need
1836 * of random peers.
1837 */
1838static unsigned int sampler_size_client_need;
1839
1840/**
1841 * The size of sampler we need to be able to satisfy the Brahms protocol's 1830 * The size of sampler we need to be able to satisfy the Brahms protocol's
1842 * need of random peers. 1831 * need of random peers.
1843 * 1832 *
@@ -1923,38 +1912,6 @@ static struct GNUNET_PEERINFO_Handle *peerinfo_handle;
1923 */ 1912 */
1924static struct GNUNET_PEERINFO_NotifyContext *peerinfo_notify_handle; 1913static struct GNUNET_PEERINFO_NotifyContext *peerinfo_notify_handle;
1925 1914
1926/**
1927 * Request counter.
1928 *
1929 * Counts how many requets clients already issued.
1930 * Only needed in the beginning to check how many of the 64 deltas
1931 * we already have
1932 */
1933static unsigned int req_counter;
1934
1935/**
1936 * Time of the last request we received.
1937 *
1938 * Used to compute the expected request rate.
1939 */
1940static struct GNUNET_TIME_Absolute last_request;
1941
1942/**
1943 * Size of #request_deltas.
1944 */
1945#define REQUEST_DELTAS_SIZE 64
1946static unsigned int request_deltas_size = REQUEST_DELTAS_SIZE;
1947
1948/**
1949 * Last 64 deltas between requests
1950 */
1951static struct GNUNET_TIME_Relative request_deltas[REQUEST_DELTAS_SIZE];
1952
1953/**
1954 * The prediction of the rate of requests
1955 */
1956static struct GNUNET_TIME_Relative request_rate;
1957
1958 1915
1959#ifdef ENABLE_MALICIOUS 1916#ifdef ENABLE_MALICIOUS
1960/** 1917/**
@@ -2108,38 +2065,6 @@ rem_from_list (struct GNUNET_PeerIdentity **peer_list,
2108 2065
2109 2066
2110/** 2067/**
2111 * Sum all time relatives of an array.
2112 */
2113static struct GNUNET_TIME_Relative
2114T_relative_sum (const struct GNUNET_TIME_Relative *rel_array,
2115 uint32_t arr_size)
2116{
2117 struct GNUNET_TIME_Relative sum;
2118 uint32_t i;
2119
2120 sum = GNUNET_TIME_UNIT_ZERO;
2121 for ( i = 0 ; i < arr_size ; i++ )
2122 {
2123 sum = GNUNET_TIME_relative_add (sum, rel_array[i]);
2124 }
2125 return sum;
2126}
2127
2128
2129/**
2130 * Compute the average of given time relatives.
2131 */
2132static struct GNUNET_TIME_Relative
2133T_relative_avg (const struct GNUNET_TIME_Relative *rel_array,
2134 uint32_t arr_size)
2135{
2136 return GNUNET_TIME_relative_divide (T_relative_sum (rel_array,
2137 arr_size),
2138 arr_size);
2139}
2140
2141
2142/**
2143 * Insert PeerID in #view 2068 * Insert PeerID in #view
2144 * 2069 *
2145 * Called once we know a peer is live. 2070 * Called once we know a peer is live.
@@ -2369,69 +2294,6 @@ resize_wrapper (struct RPS_Sampler *sampler, uint32_t new_size)
2369 2294
2370 2295
2371/** 2296/**
2372 * Wrapper around #RPS_sampler_resize() resizing the client sampler
2373 */
2374static void
2375client_resize_wrapper ()
2376{
2377 uint32_t bigger_size;
2378
2379 // TODO statistics
2380
2381 bigger_size = GNUNET_MAX (sampler_size_est_need, sampler_size_client_need);
2382
2383 // TODO respect the min, max
2384 resize_wrapper (client_sampler, bigger_size);
2385 LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler_size_client is now %" PRIu32 "\n",
2386 bigger_size);
2387}
2388
2389
2390/**
2391 * Estimate request rate
2392 *
2393 * Called every time we receive a request from the client.
2394 */
2395static void
2396est_request_rate()
2397{
2398 struct GNUNET_TIME_Relative max_round_duration;
2399
2400 if (request_deltas_size > req_counter)
2401 req_counter++;
2402 if ( 1 < req_counter)
2403 {
2404 /* Shift last request deltas to the right */
2405 memmove (&request_deltas[1],
2406 request_deltas,
2407 (req_counter - 1) * sizeof (struct GNUNET_TIME_Relative));
2408
2409 /* Add current delta to beginning */
2410 request_deltas[0] =
2411 GNUNET_TIME_absolute_get_difference (last_request,
2412 GNUNET_TIME_absolute_get ());
2413 request_rate = T_relative_avg (request_deltas, req_counter);
2414 request_rate = (request_rate.rel_value_us < 1) ?
2415 GNUNET_TIME_relative_get_unit_ () : request_rate;
2416
2417 /* Compute the duration a round will maximally take */
2418 max_round_duration =
2419 GNUNET_TIME_relative_add (round_interval,
2420 GNUNET_TIME_relative_divide (round_interval, 2));
2421
2422 /* Set the estimated size the sampler has to have to
2423 * satisfy the current client request rate */
2424 sampler_size_client_need =
2425 max_round_duration.rel_value_us / request_rate.rel_value_us;
2426
2427 /* Resize the sampler */
2428 client_resize_wrapper ();
2429 }
2430 last_request = GNUNET_TIME_absolute_get ();
2431}
2432
2433
2434/**
2435 * Add all peers in @a peer_array to @a peer_map used as set. 2297 * Add all peers in @a peer_array to @a peer_map used as set.
2436 * 2298 *
2437 * @param peer_array array containing the peers 2299 * @param peer_array array containing the peers
@@ -2565,7 +2427,6 @@ insert_in_sampler (void *cls,
2565 "Updating samplers with peer %s from insert_in_sampler()\n", 2427 "Updating samplers with peer %s from insert_in_sampler()\n",
2566 GNUNET_i2s (peer)); 2428 GNUNET_i2s (peer));
2567 RPS_sampler_update (prot_sampler, peer); 2429 RPS_sampler_update (prot_sampler, peer);
2568 RPS_sampler_update (client_sampler, peer);
2569 if (0 < RPS_sampler_count_id (prot_sampler, peer)) 2430 if (0 < RPS_sampler_count_id (prot_sampler, peer))
2570 { 2431 {
2571 /* Make sure we 'know' about this peer */ 2432 /* Make sure we 'know' about this peer */
@@ -2658,7 +2519,6 @@ remove_peer (const struct GNUNET_PeerIdentity *peer)
2658 CustomPeerMap_remove_peer (pull_map, peer); 2519 CustomPeerMap_remove_peer (pull_map, peer);
2659 CustomPeerMap_remove_peer (push_map, peer); 2520 CustomPeerMap_remove_peer (push_map, peer);
2660 RPS_sampler_reinitialise_by_value (prot_sampler, peer); 2521 RPS_sampler_reinitialise_by_value (prot_sampler, peer);
2661 RPS_sampler_reinitialise_by_value (client_sampler, peer);
2662 destroy_peer (get_peer_ctx (peer)); 2522 destroy_peer (get_peer_ctx (peer));
2663} 2523}
2664 2524
@@ -2691,7 +2551,6 @@ clean_peer (const struct GNUNET_PeerIdentity *peer)
2691 (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && 2551 (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) &&
2692 (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && 2552 (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) &&
2693 (0 == RPS_sampler_count_id (prot_sampler, peer)) && 2553 (0 == RPS_sampler_count_id (prot_sampler, peer)) &&
2694 (0 == RPS_sampler_count_id (client_sampler, peer)) &&
2695 (GNUNET_NO != check_removable (peer)) ) 2554 (GNUNET_NO != check_removable (peer)) )
2696 { /* We can safely remove this peer */ 2555 { /* We can safely remove this peer */
2697 LOG (GNUNET_ERROR_TYPE_DEBUG, 2556 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2813,143 +2672,11 @@ nse_callback (void *cls,
2813 2672
2814 /* If the NSE has changed adapt the lists accordingly */ 2673 /* If the NSE has changed adapt the lists accordingly */
2815 resize_wrapper (prot_sampler, sampler_size_est_need); 2674 resize_wrapper (prot_sampler, sampler_size_est_need);
2816 client_resize_wrapper ();
2817 View_change_len (view_size_est_need); 2675 View_change_len (view_size_est_need);
2818} 2676}
2819 2677
2820 2678
2821/** 2679/**
2822 * Callback called once the requested PeerIDs are ready.
2823 *
2824 * Sends those to the requesting client.
2825 */
2826static void
2827client_respond (const struct GNUNET_PeerIdentity *peer_ids,
2828 uint32_t num_peers,
2829 void *cls)
2830{
2831 struct ReplyCls *reply_cls = cls;
2832 uint32_t i;
2833 struct GNUNET_MQ_Envelope *ev;
2834 struct GNUNET_RPS_CS_ReplyMessage *out_msg;
2835 uint32_t size_needed;
2836 struct ClientContext *cli_ctx;
2837
2838 GNUNET_assert (NULL != reply_cls);
2839 LOG (GNUNET_ERROR_TYPE_DEBUG,
2840 "sampler returned %" PRIu32 " peers:\n",
2841 num_peers);
2842 for (i = 0; i < num_peers; i++)
2843 {
2844 LOG (GNUNET_ERROR_TYPE_DEBUG,
2845 " %" PRIu32 ": %s\n",
2846 i,
2847 GNUNET_i2s (&peer_ids[i]));
2848 }
2849
2850 size_needed = sizeof (struct GNUNET_RPS_CS_ReplyMessage) +
2851 num_peers * sizeof (struct GNUNET_PeerIdentity);
2852
2853 GNUNET_assert (GNUNET_MAX_MESSAGE_SIZE >= size_needed);
2854
2855 ev = GNUNET_MQ_msg_extra (out_msg,
2856 num_peers * sizeof (struct GNUNET_PeerIdentity),
2857 GNUNET_MESSAGE_TYPE_RPS_CS_REPLY);
2858 out_msg->num_peers = htonl (num_peers);
2859 out_msg->id = htonl (reply_cls->id);
2860
2861 GNUNET_memcpy (&out_msg[1],
2862 peer_ids,
2863 num_peers * sizeof (struct GNUNET_PeerIdentity));
2864
2865 cli_ctx = reply_cls->cli_ctx;
2866 GNUNET_assert (NULL != cli_ctx);
2867 reply_cls->req_handle = NULL;
2868 destroy_reply_cls (reply_cls);
2869 GNUNET_MQ_send (cli_ctx->mq, ev);
2870}
2871
2872
2873/**
2874 * Handle RPS request from the client.
2875 *
2876 * @param cls closure
2877 * @param message the actual message
2878 */
2879static void
2880handle_client_request (void *cls,
2881 const struct GNUNET_RPS_CS_RequestMessage *msg)
2882{
2883 struct ClientContext *cli_ctx = cls;
2884 uint32_t num_peers;
2885 uint32_t size_needed;
2886 struct ReplyCls *reply_cls;
2887 uint32_t i;
2888
2889 num_peers = ntohl (msg->num_peers);
2890 size_needed = sizeof (struct GNUNET_RPS_CS_RequestMessage) +
2891 num_peers * sizeof (struct GNUNET_PeerIdentity);
2892
2893 if (GNUNET_MAX_MESSAGE_SIZE < size_needed)
2894 {
2895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2896 "Message received from client has size larger than expected\n");
2897 GNUNET_SERVICE_client_drop (cli_ctx->client);
2898 return;
2899 }
2900
2901 for (i = 0 ; i < num_peers ; i++)
2902 est_request_rate();
2903
2904 LOG (GNUNET_ERROR_TYPE_DEBUG,
2905 "Client requested %" PRIu32 " random peer(s).\n",
2906 num_peers);
2907
2908 reply_cls = GNUNET_new (struct ReplyCls);
2909 reply_cls->id = ntohl (msg->id);
2910 reply_cls->cli_ctx = cli_ctx;
2911 reply_cls->req_handle = RPS_sampler_get_n_rand_peers (client_sampler,
2912 num_peers,
2913 client_respond,
2914 reply_cls);
2915
2916 GNUNET_assert (NULL != cli_ctx);
2917 GNUNET_CONTAINER_DLL_insert (cli_ctx->rep_cls_head,
2918 cli_ctx->rep_cls_tail,
2919 reply_cls);
2920 GNUNET_SERVICE_client_continue (cli_ctx->client);
2921}
2922
2923
2924/**
2925 * @brief Handle a message that requests the cancellation of a request
2926 *
2927 * @param cls unused
2928 * @param message the message containing the id of the request
2929 */
2930static void
2931handle_client_request_cancel (void *cls,
2932 const struct GNUNET_RPS_CS_RequestCancelMessage *msg)
2933{
2934 struct ClientContext *cli_ctx = cls;
2935 struct ReplyCls *rep_cls;
2936
2937 GNUNET_assert (NULL != cli_ctx);
2938 GNUNET_assert (NULL != cli_ctx->rep_cls_head);
2939 rep_cls = cli_ctx->rep_cls_head;
2940 LOG (GNUNET_ERROR_TYPE_DEBUG,
2941 "Client cancels request with id %" PRIu32 "\n",
2942 ntohl (msg->id));
2943 while ( (NULL != rep_cls->next) &&
2944 (rep_cls->id != ntohl (msg->id)) )
2945 rep_cls = rep_cls->next;
2946 GNUNET_assert (rep_cls->id == ntohl (msg->id));
2947 destroy_reply_cls (rep_cls);
2948 GNUNET_SERVICE_client_continue (cli_ctx->client);
2949}
2950
2951
2952/**
2953 * @brief This function is called, when the client seeds peers. 2680 * @brief This function is called, when the client seeds peers.
2954 * It verifies that @a msg is well-formed. 2681 * It verifies that @a msg is well-formed.
2955 * 2682 *
@@ -4102,7 +3829,6 @@ shutdown_task (void *cls)
4102 3829
4103 GNUNET_NSE_disconnect (nse); 3830 GNUNET_NSE_disconnect (nse);
4104 RPS_sampler_destroy (prot_sampler); 3831 RPS_sampler_destroy (prot_sampler);
4105 RPS_sampler_destroy (client_sampler);
4106 GNUNET_CADET_close_port (cadet_port); 3832 GNUNET_CADET_close_port (cadet_port);
4107 GNUNET_CADET_disconnect (cadet_handle); 3833 GNUNET_CADET_disconnect (cadet_handle);
4108 cadet_handle = NULL; 3834 cadet_handle = NULL;
@@ -4345,7 +4071,6 @@ run (void *cls,
4345 max_round_interval = GNUNET_TIME_relative_add (round_interval, half_round_interval); 4071 max_round_interval = GNUNET_TIME_relative_add (round_interval, half_round_interval);
4346 4072
4347 prot_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval); 4073 prot_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval);
4348 client_sampler = RPS_sampler_mod_init (sampler_size_est_need, max_round_interval);
4349 4074
4350 /* Initialise push and pull maps */ 4075 /* Initialise push and pull maps */
4351 push_map = CustomPeerMap_create (4); 4076 push_map = CustomPeerMap_create (4);
@@ -4385,14 +4110,6 @@ GNUNET_SERVICE_MAIN
4385 &client_connect_cb, 4110 &client_connect_cb,
4386 &client_disconnect_cb, 4111 &client_disconnect_cb,
4387 NULL, 4112 NULL,
4388 GNUNET_MQ_hd_fixed_size (client_request,
4389 GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST,
4390 struct GNUNET_RPS_CS_RequestMessage,
4391 NULL),
4392 GNUNET_MQ_hd_fixed_size (client_request_cancel,
4393 GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST_CANCEL,
4394 struct GNUNET_RPS_CS_RequestCancelMessage,
4395 NULL),
4396 GNUNET_MQ_hd_var_size (client_seed, 4113 GNUNET_MQ_hd_var_size (client_seed,
4397 GNUNET_MESSAGE_TYPE_RPS_CS_SEED, 4114 GNUNET_MESSAGE_TYPE_RPS_CS_SEED,
4398 struct GNUNET_RPS_CS_SeedMessage, 4115 struct GNUNET_RPS_CS_SeedMessage,