aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-05-23 23:34:23 +0000
committerJulius Bünger <buenger@mytum.de>2015-05-23 23:34:23 +0000
commit2f61fb7ffc7232c69e66a13c956892d6f6d13081 (patch)
tree40d8f0f87e5a48c4dd9044d40c4479f16f428b38
parentc2224023ebd389a62c5a569549ee67e1f984e6ba (diff)
downloadgnunet-2f61fb7ffc7232c69e66a13c956892d6f6d13081.tar.gz
gnunet-2f61fb7ffc7232c69e66a13c956892d6f6d13081.zip
-better splitted brahms sampler and modified one
-rw-r--r--src/rps/gnunet-service-rps.c14
-rw-r--r--src/rps/gnunet-service-rps_sampler.c109
-rw-r--r--src/rps/gnunet-service-rps_sampler.h22
3 files changed, 92 insertions, 53 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index b8bfe8f9e..c77e8eddf 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -1281,8 +1281,8 @@ void client_respond (void *cls,
1281 */ 1281 */
1282static void 1282static void
1283handle_client_request (void *cls, 1283handle_client_request (void *cls,
1284 struct GNUNET_SERVER_Client *client, 1284 struct GNUNET_SERVER_Client *client,
1285 const struct GNUNET_MessageHeader *message) 1285 const struct GNUNET_MessageHeader *message)
1286{ 1286{
1287 struct GNUNET_RPS_CS_RequestMessage *msg; 1287 struct GNUNET_RPS_CS_RequestMessage *msg;
1288 uint32_t num_peers; 1288 uint32_t num_peers;
@@ -1316,8 +1316,7 @@ handle_client_request (void *cls,
1316 RPS_sampler_get_n_rand_peers (client_sampler, 1316 RPS_sampler_get_n_rand_peers (client_sampler,
1317 client_respond, 1317 client_respond,
1318 reply_cls, 1318 reply_cls,
1319 num_peers, 1319 num_peers);
1320 GNUNET_YES);
1321 1320
1322 GNUNET_SERVER_receive_done (client, 1321 GNUNET_SERVER_receive_done (client,
1323 GNUNET_OK); 1322 GNUNET_OK);
@@ -2069,8 +2068,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2069 RPS_sampler_get_n_rand_peers (prot_sampler, 2068 RPS_sampler_get_n_rand_peers (prot_sampler,
2070 hist_update, 2069 hist_update,
2071 NULL, 2070 NULL,
2072 1, 2071 1);
2073 GNUNET_NO);
2074 num_hist_update_tasks++; 2072 num_hist_update_tasks++;
2075 // TODO change the peer_flags accordingly 2073 // TODO change the peer_flags accordingly
2076 } 2074 }
@@ -2551,8 +2549,8 @@ run (void *cls,
2551 half_round_interval = GNUNET_TIME_relative_multiply (round_interval, .5); 2549 half_round_interval = GNUNET_TIME_relative_multiply (round_interval, .5);
2552 max_round_interval = GNUNET_TIME_relative_add (round_interval, half_round_interval); 2550 max_round_interval = GNUNET_TIME_relative_add (round_interval, half_round_interval);
2553 2551
2554 prot_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval); 2552 prot_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval);
2555 client_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval); 2553 client_sampler = RPS_sampler_mod_init (sampler_size_est_need, max_round_interval);
2556 2554
2557 /* Initialise push and pull maps */ 2555 /* Initialise push and pull maps */
2558 push_list = NULL; 2556 push_list = NULL;
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c
index 5ea728628..a0624c942 100644
--- a/src/rps/gnunet-service-rps_sampler.c
+++ b/src/rps/gnunet-service-rps_sampler.c
@@ -111,6 +111,35 @@ struct RPS_SamplerElement
111 #endif /* TO_FILE */ 111 #endif /* TO_FILE */
112}; 112};
113 113
114/**
115 * Type of function used to differentiate between modified and not modified
116 * Sampler.
117 */
118typedef void
119(*RPS_get_peers_type) (void *cls,
120 const struct GNUNET_SCHEDULER_TaskContext *tc);
121
122/**
123 * Get one random peer out of the sampled peers.
124 *
125 * We might want to reinitialise this sampler after giving the
126 * corrsponding peer to the client.
127 * Only used internally
128 */
129static void
130sampler_get_rand_peer2 (void *cls,
131 const struct GNUNET_SCHEDULER_TaskContext *tc);
132
133/**
134 * Get one random peer out of the sampled peers.
135 *
136 * We might want to reinitialise this sampler after giving the
137 * corrsponding peer to the client.
138 */
139static void
140sampler_get_rand_peer (void *cls,
141 const struct GNUNET_SCHEDULER_TaskContext *tc);
142
114 143
115/** 144/**
116 * Sampler with its own array of SamplerElements 145 * Sampler with its own array of SamplerElements
@@ -129,12 +158,18 @@ struct RPS_Sampler
129 struct RPS_SamplerElement **sampler_elements; 158 struct RPS_SamplerElement **sampler_elements;
130 159
131 /** 160 /**
132 * Max time a round takes 161 * Maximum time a round takes
133 * 162 *
134 * Used in the context of RPS 163 * Used in the context of RPS
135 */ 164 */
136 struct GNUNET_TIME_Relative max_round_interval; 165 struct GNUNET_TIME_Relative max_round_interval;
137 166
167 /**
168 * Stores the function to return peers. Which one it is depends on whether
169 * the Sampler is the modified one or not.
170 */
171 RPS_get_peers_type get_peers;
172
138 #ifdef TO_FILE 173 #ifdef TO_FILE
139 /** 174 /**
140 * File name to log to 175 * File name to log to
@@ -182,7 +217,7 @@ struct NRandPeersReadyCls
182 */ 217 */
183typedef void 218typedef void
184(*RPS_sampler_rand_peer_ready_cont) (void *cls, 219(*RPS_sampler_rand_peer_ready_cont) (void *cls,
185 const struct GNUNET_PeerIdentity *id); 220 const struct GNUNET_PeerIdentity *id);
186 221
187/** 222/**
188 * Closure for #sampler_get_rand_peer() 223 * Closure for #sampler_get_rand_peer()
@@ -634,12 +669,7 @@ sampler_empty (struct RPS_Sampler *sampler)
634 * Initialise a tuple of sampler elements. 669 * Initialise a tuple of sampler elements.
635 * 670 *
636 * @param init_size the size the sampler is initialised with 671 * @param init_size the size the sampler is initialised with
637 * @param ins_cb the callback that will be called on every PeerID that is 672 * @param max_round_interval maximum time a round takes
638 * newly inserted into a sampler element
639 * @param ins_cls the closure given to #ins_cb
640 * @param rem_cb the callback that will be called on every PeerID that is
641 * removed from a sampler element
642 * @param rem_cls the closure given to #rem_cb
643 * @return a handle to a sampler that consists of sampler elements. 673 * @return a handle to a sampler that consists of sampler elements.
644 */ 674 */
645struct RPS_Sampler * 675struct RPS_Sampler *
@@ -647,7 +677,6 @@ RPS_sampler_init (size_t init_size,
647 struct GNUNET_TIME_Relative max_round_interval) 677 struct GNUNET_TIME_Relative max_round_interval)
648{ 678{
649 struct RPS_Sampler *sampler; 679 struct RPS_Sampler *sampler;
650 //uint32_t i;
651 680
652 /* Initialise context around extended sampler */ 681 /* Initialise context around extended sampler */
653 min_size = 10; // TODO make input to _samplers_init() 682 min_size = 10; // TODO make input to _samplers_init()
@@ -667,6 +696,7 @@ RPS_sampler_init (size_t init_size,
667 sampler->sampler_size = 0; 696 sampler->sampler_size = 0;
668 sampler->sampler_elements = NULL; 697 sampler->sampler_elements = NULL;
669 sampler->max_round_interval = max_round_interval; 698 sampler->max_round_interval = max_round_interval;
699 sampler->get_peers = sampler_get_rand_peer;
670 //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); 700 //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity);
671 //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); 701 //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size);
672 RPS_sampler_resize (sampler, init_size); 702 RPS_sampler_resize (sampler, init_size);
@@ -677,6 +707,33 @@ RPS_sampler_init (size_t init_size,
677 return sampler; 707 return sampler;
678} 708}
679 709
710/**
711 * Initialise a modified tuple of sampler elements.
712 *
713 * @param init_size the size the sampler is initialised with
714 * @param max_round_interval maximum time a round takes
715 * @return a handle to a sampler that consists of sampler elements.
716 */
717struct RPS_Sampler *
718RPS_sampler_mod_init (size_t init_size,
719 struct GNUNET_TIME_Relative max_round_interval)
720{
721 struct RPS_Sampler *sampler;
722
723 sampler = RPS_sampler_init (init_size, max_round_interval);
724 sampler->get_peers = sampler_get_rand_peer2;
725
726 #ifdef TO_FILE
727 LOG (GNUNET_ERROR_TYPE_DEBUG,
728 "Initialised modified sampler %s\n",
729 sampler->file_name);
730 to_file (sampler->file_name,
731 "This is a modified sampler");
732 #endif /* TO_FILE */
733
734 return sampler;
735}
736
680 737
681/** 738/**
682 * A fuction to update every sampler in the given list 739 * A fuction to update every sampler in the given list
@@ -738,7 +795,8 @@ RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler,
738 * Only used internally 795 * Only used internally
739 */ 796 */
740static void 797static void
741sampler_get_rand_peer2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 798sampler_get_rand_peer2 (void *cls,
799 const struct GNUNET_SCHEDULER_TaskContext *tc)
742{ 800{
743 struct GetPeerCls *gpc = cls; 801 struct GetPeerCls *gpc = cls;
744 uint32_t r_index; 802 uint32_t r_index;
@@ -779,7 +837,8 @@ sampler_get_rand_peer2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
779 * corrsponding peer to the client. 837 * corrsponding peer to the client.
780 */ 838 */
781static void 839static void
782sampler_get_rand_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 840sampler_get_rand_peer (void *cls,
841 const struct GNUNET_SCHEDULER_TaskContext *tc)
783{ 842{
784 struct GetPeerCls *gpc = cls; 843 struct GetPeerCls *gpc = cls;
785 struct GNUNET_PeerIdentity tmp_id; 844 struct GNUNET_PeerIdentity tmp_id;
@@ -893,7 +952,7 @@ sampler_get_rand_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
893 void 952 void
894RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, 953RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
895 RPS_sampler_n_rand_peers_ready_cb cb, 954 RPS_sampler_n_rand_peers_ready_cb cb,
896 void *cls, uint32_t num_peers, int for_client) 955 void *cls, uint32_t num_peers)
897{ 956{
898 GNUNET_assert (0 != sampler->sampler_size); 957 GNUNET_assert (0 != sampler->sampler_size);
899 958
@@ -909,25 +968,6 @@ RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
909 cb_cls->callback = cb; 968 cb_cls->callback = cb;
910 cb_cls->cls = cls; 969 cb_cls->cls = cls;
911 970
912 #ifdef TO_FILE
913 if (GNUNET_NO == for_client)
914 {
915 to_file (sampler->file_name,
916 "This sampler is probably for Brahms itself");
917 }
918 else if (GNUNET_YES == for_client)
919 {
920 to_file (sampler->file_name,
921 "This sampler is probably for the client");
922 }
923 else
924 {
925 to_file (sampler->file_name,
926 "This shouldn't happen: for_client is %i",
927 for_client);
928 }
929 #endif /* TO_FILE */
930
931 LOG (GNUNET_ERROR_TYPE_DEBUG, 971 LOG (GNUNET_ERROR_TYPE_DEBUG,
932 "Scheduling requests for %" PRIu32 " peers\n", num_peers); 972 "Scheduling requests for %" PRIu32 " peers\n", num_peers);
933 973
@@ -940,12 +980,7 @@ RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
940 gpc->id = &cb_cls->ids[i]; 980 gpc->id = &cb_cls->ids[i];
941 981
942 // maybe add a little delay 982 // maybe add a little delay
943 if (GNUNET_YES == for_client) 983 gpc->get_peer_task = GNUNET_SCHEDULER_add_now (sampler->get_peers, gpc);
944 gpc->get_peer_task = GNUNET_SCHEDULER_add_now (&sampler_get_rand_peer, gpc);
945 else if (GNUNET_NO == for_client)
946 gpc->get_peer_task = GNUNET_SCHEDULER_add_now (&sampler_get_rand_peer2, gpc);
947 else
948 GNUNET_assert (0);
949 984
950 GNUNET_CONTAINER_DLL_insert (gpc_head, gpc_tail, gpc); 985 GNUNET_CONTAINER_DLL_insert (gpc_head, gpc_tail, gpc);
951 } 986 }
diff --git a/src/rps/gnunet-service-rps_sampler.h b/src/rps/gnunet-service-rps_sampler.h
index 708de6980..3b4584d87 100644
--- a/src/rps/gnunet-service-rps_sampler.h
+++ b/src/rps/gnunet-service-rps_sampler.h
@@ -71,13 +71,7 @@ RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size);
71 * Initialise a tuple of samplers. 71 * Initialise a tuple of samplers.
72 * 72 *
73 * @param init_size the size the sampler is initialised with 73 * @param init_size the size the sampler is initialised with
74 * @param id with which all newly created sampler elements are initialised 74 * @param max_round_interval maximum time a round takes
75 * @param ins_cb the callback that will be called on every PeerID that is
76 * newly inserted into a sampler element
77 * @param ins_cls the closure given to #ins_cb
78 * @param rem_cb the callback that will be called on every PeerID that is
79 * removed from a sampler element
80 * @param rem_cls the closure given to #rem_cb
81 * @return a handle to a sampler that consists of sampler elements. 75 * @return a handle to a sampler that consists of sampler elements.
82 */ 76 */
83struct RPS_Sampler * 77struct RPS_Sampler *
@@ -86,6 +80,18 @@ RPS_sampler_init (size_t init_size,
86 80
87 81
88/** 82/**
83 * Initialise a modified tuple of sampler elements.
84 *
85 * @param init_size the size the sampler is initialised with
86 * @param max_round_interval maximum time a round takes
87 * @return a handle to a sampler that consists of sampler elements.
88 */
89struct RPS_Sampler *
90RPS_sampler_mod_init (size_t init_size,
91 struct GNUNET_TIME_Relative max_round_interval);
92
93
94/**
89 * A fuction to update every sampler in the given list 95 * A fuction to update every sampler in the given list
90 * 96 *
91 * @param sampler the sampler to update. 97 * @param sampler the sampler to update.
@@ -127,7 +133,7 @@ RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler,
127 void 133 void
128RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, 134RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
129 RPS_sampler_n_rand_peers_ready_cb cb, 135 RPS_sampler_n_rand_peers_ready_cb cb,
130 void *cls, uint32_t num_peers, int for_client); 136 void *cls, uint32_t num_peers);
131 137
132 138
133/** 139/**