aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-rps-profiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps/gnunet-rps-profiler.c')
-rw-r--r--src/rps/gnunet-rps-profiler.c2967
1 files changed, 1493 insertions, 1474 deletions
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c
index bd68b905b..a963476cf 100644
--- a/src/rps/gnunet-rps-profiler.c
+++ b/src/rps/gnunet-rps-profiler.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file rps/test_rps.c 21 * @file rps/test_rps.c
22 * @brief Testcase for the random peer sampling service. Starts 22 * @brief Testcase for the random peer sampling service. Starts
@@ -74,8 +74,7 @@ static unsigned int mal_type = 0;
74 */ 74 */
75static struct GNUNET_TESTBED_Peer **testbed_peers; 75static struct GNUNET_TESTBED_Peer **testbed_peers;
76 76
77enum STAT_TYPE 77enum STAT_TYPE {
78{
79 STAT_TYPE_ROUNDS, /* 0 */ 78 STAT_TYPE_ROUNDS, /* 0 */
80 STAT_TYPE_BLOCKS, /* 1 */ 79 STAT_TYPE_BLOCKS, /* 1 */
81 STAT_TYPE_BLOCKS_MANY_PUSH, /* 2 */ 80 STAT_TYPE_BLOCKS_MANY_PUSH, /* 2 */
@@ -146,8 +145,7 @@ static char* stat_type_strings[] = {
146 "view size aim", 145 "view size aim",
147}; 146};
148 147
149struct STATcls 148struct STATcls {
150{
151 struct RPSPeer *rps_peer; 149 struct RPSPeer *rps_peer;
152 enum STAT_TYPE stat_type; 150 enum STAT_TYPE stat_type;
153}; 151};
@@ -160,200 +158,200 @@ struct STATcls
160 * 158 *
161 * @return corresponding enum 159 * @return corresponding enum
162 */ 160 */
163enum STAT_TYPE stat_str_2_type (const char *stat_str) 161enum STAT_TYPE stat_str_2_type(const char *stat_str)
164{ 162{
165 if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL], 163 if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL],
166 stat_str, 164 stat_str,
167 strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL]))) 165 strlen(stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL])))
168 { 166 {
169 return STAT_TYPE_BLOCKS_NO_PULL; 167 return STAT_TYPE_BLOCKS_NO_PULL;
170 } 168 }
171 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], 169 else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL],
172 stat_str, 170 stat_str,
173 strlen (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL]))) 171 strlen(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL])))
174 { 172 {
175 return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL; 173 return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL;
176 } 174 }
177 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH], 175 else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH],
178 stat_str, 176 stat_str,
179 strlen (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH]))) 177 strlen(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH])))
180 { 178 {
181 return STAT_TYPE_BLOCKS_MANY_PUSH; 179 return STAT_TYPE_BLOCKS_MANY_PUSH;
182 } 180 }
183 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], 181 else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL],
184 stat_str, 182 stat_str,
185 strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL]))) 183 strlen(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL])))
186 { 184 {
187 return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL; 185 return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL;
188 } 186 }
189 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH], 187 else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH],
190 stat_str, 188 stat_str,
191 strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH]))) 189 strlen(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH])))
192 { 190 {
193 return STAT_TYPE_BLOCKS_NO_PUSH; 191 return STAT_TYPE_BLOCKS_NO_PUSH;
194 } 192 }
195 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS], 193 else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS],
196 stat_str, 194 stat_str,
197 strlen (stat_type_strings[STAT_TYPE_BLOCKS]))) 195 strlen(stat_type_strings[STAT_TYPE_BLOCKS])))
198 { 196 {
199 return STAT_TYPE_BLOCKS; 197 return STAT_TYPE_BLOCKS;
200 } 198 }
201 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ROUNDS], 199 else if (0 == strncmp(stat_type_strings[STAT_TYPE_ROUNDS],
202 stat_str, 200 stat_str,
203 strlen (stat_type_strings[STAT_TYPE_ROUNDS]))) 201 strlen(stat_type_strings[STAT_TYPE_ROUNDS])))
204 { 202 {
205 return STAT_TYPE_ROUNDS; 203 return STAT_TYPE_ROUNDS;
206 } 204 }
207 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND], 205 else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND],
208 stat_str, 206 stat_str,
209 strlen (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND]))) 207 strlen(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND])))
210 { 208 {
211 return STAT_TYPE_ISSUED_PUSH_SEND; 209 return STAT_TYPE_ISSUED_PUSH_SEND;
212 } 210 }
213 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH], 211 else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH],
214 stat_str, 212 stat_str,
215 strlen (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH]))) 213 strlen(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH])))
216 { 214 {
217 return STAT_TYPE_ISSUED_PUSH_SEND_MH; 215 return STAT_TYPE_ISSUED_PUSH_SEND_MH;
218 } 216 }
219 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ], 217 else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ],
220 stat_str, 218 stat_str,
221 strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ]))) 219 strlen(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ])))
222 { 220 {
223 return STAT_TYPE_ISSUED_PULL_REQ; 221 return STAT_TYPE_ISSUED_PULL_REQ;
224 } 222 }
225 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH], 223 else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH],
226 stat_str, 224 stat_str,
227 strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH]))) 225 strlen(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH])))
228 { 226 {
229 return STAT_TYPE_ISSUED_PULL_REQ_MH; 227 return STAT_TYPE_ISSUED_PULL_REQ_MH;
230 } 228 }
231 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REP], 229 else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PULL_REP],
232 stat_str, 230 stat_str,
233 strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REP]))) 231 strlen(stat_type_strings[STAT_TYPE_ISSUED_PULL_REP])))
234 { 232 {
235 return STAT_TYPE_ISSUED_PULL_REP; 233 return STAT_TYPE_ISSUED_PULL_REP;
236 } 234 }
237 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PUSH_SEND], 235 else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PUSH_SEND],
238 stat_str, 236 stat_str,
239 strlen (stat_type_strings[STAT_TYPE_SENT_PUSH_SEND]))) 237 strlen(stat_type_strings[STAT_TYPE_SENT_PUSH_SEND])))
240 { 238 {
241 return STAT_TYPE_SENT_PUSH_SEND; 239 return STAT_TYPE_SENT_PUSH_SEND;
242 } 240 }
243 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REQ], 241 else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PULL_REQ],
244 stat_str, 242 stat_str,
245 strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REQ]))) 243 strlen(stat_type_strings[STAT_TYPE_SENT_PULL_REQ])))
246 { 244 {
247 return STAT_TYPE_SENT_PULL_REQ; 245 return STAT_TYPE_SENT_PULL_REQ;
248 } 246 }
249 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH], 247 else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH],
250 stat_str, 248 stat_str,
251 strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH]))) 249 strlen(stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH])))
252 { 250 {
253 return STAT_TYPE_SENT_PULL_REQ_MH; 251 return STAT_TYPE_SENT_PULL_REQ_MH;
254 } 252 }
255 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REP], 253 else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PULL_REP],
256 stat_str, 254 stat_str,
257 strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REP]))) 255 strlen(stat_type_strings[STAT_TYPE_SENT_PULL_REP])))
258 { 256 {
259 return STAT_TYPE_SENT_PULL_REP; 257 return STAT_TYPE_SENT_PULL_REP;
260 } 258 }
261 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND], 259 else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND],
262 stat_str, 260 stat_str,
263 strlen (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND]))) 261 strlen(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND])))
264 { 262 {
265 return STAT_TYPE_RECV_PUSH_SEND; 263 return STAT_TYPE_RECV_PUSH_SEND;
266 } 264 }
267 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH], 265 else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH],
268 stat_str, 266 stat_str,
269 strlen (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH]))) 267 strlen(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH])))
270 { 268 {
271 return STAT_TYPE_RECV_PUSH_SEND_MH; 269 return STAT_TYPE_RECV_PUSH_SEND_MH;
272 } 270 }
273 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REQ], 271 else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REQ],
274 stat_str, 272 stat_str,
275 strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REQ]))) 273 strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REQ])))
276 { 274 {
277 return STAT_TYPE_RECV_PULL_REQ; 275 return STAT_TYPE_RECV_PULL_REQ;
278 } 276 }
279 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH], 277 else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH],
280 stat_str, 278 stat_str,
281 strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH]))) 279 strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH])))
282 { 280 {
283 return STAT_TYPE_RECV_PULL_REQ_MH; 281 return STAT_TYPE_RECV_PULL_REQ_MH;
284 } 282 }
285 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REP], 283 else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REP],
286 stat_str, 284 stat_str,
287 strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REP]))) 285 strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REP])))
288 { 286 {
289 return STAT_TYPE_RECV_PULL_REP; 287 return STAT_TYPE_RECV_PULL_REP;
290 } 288 }
291 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH], 289 else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH],
292 stat_str, 290 stat_str,
293 strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH]))) 291 strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH])))
294 { 292 {
295 return STAT_TYPE_RECV_PULL_REP_MH; 293 return STAT_TYPE_RECV_PULL_REP_MH;
296 } 294 }
297 else if (0 == strncmp (stat_type_strings[STAT_TYPE_VIEW_SIZE], 295 else if (0 == strncmp(stat_type_strings[STAT_TYPE_VIEW_SIZE],
298 stat_str, 296 stat_str,
299 strlen (stat_type_strings[STAT_TYPE_VIEW_SIZE]))) 297 strlen(stat_type_strings[STAT_TYPE_VIEW_SIZE])))
300 { 298 {
301 return STAT_TYPE_VIEW_SIZE; 299 return STAT_TYPE_VIEW_SIZE;
302 } 300 }
303 else if (0 == strncmp (stat_type_strings[STAT_TYPE_KNOWN_PEERS], 301 else if (0 == strncmp(stat_type_strings[STAT_TYPE_KNOWN_PEERS],
304 stat_str, 302 stat_str,
305 strlen (stat_type_strings[STAT_TYPE_KNOWN_PEERS]))) 303 strlen(stat_type_strings[STAT_TYPE_KNOWN_PEERS])))
306 { 304 {
307 return STAT_TYPE_KNOWN_PEERS; 305 return STAT_TYPE_KNOWN_PEERS;
308 } 306 }
309 else if (0 == strncmp (stat_type_strings[STAT_TYPE_VALID_PEERS], 307 else if (0 == strncmp(stat_type_strings[STAT_TYPE_VALID_PEERS],
310 stat_str, 308 stat_str,
311 strlen (stat_type_strings[STAT_TYPE_VALID_PEERS]))) 309 strlen(stat_type_strings[STAT_TYPE_VALID_PEERS])))
312 { 310 {
313 return STAT_TYPE_VALID_PEERS; 311 return STAT_TYPE_VALID_PEERS;
314 } 312 }
315 else if (0 == strncmp (stat_type_strings[STAT_TYPE_LEARND_PEERS], 313 else if (0 == strncmp(stat_type_strings[STAT_TYPE_LEARND_PEERS],
316 stat_str, 314 stat_str,
317 strlen (stat_type_strings[STAT_TYPE_LEARND_PEERS]))) 315 strlen(stat_type_strings[STAT_TYPE_LEARND_PEERS])))
318 { 316 {
319 return STAT_TYPE_LEARND_PEERS; 317 return STAT_TYPE_LEARND_PEERS;
320 } 318 }
321 else if (0 == strncmp (stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS], 319 else if (0 == strncmp(stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS],
322 stat_str, 320 stat_str,
323 strlen (stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS]))) 321 strlen(stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS])))
324 { 322 {
325 return STAT_TYPE_PENDING_ONLINE_CHECKS; 323 return STAT_TYPE_PENDING_ONLINE_CHECKS;
326 } 324 }
327 else if (0 == strncmp (stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES], 325 else if (0 == strncmp(stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES],
328 stat_str, 326 stat_str,
329 strlen (stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES]))) 327 strlen(stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES])))
330 { 328 {
331 return STAT_TYPE_UNREQUESTED_PULL_REPLIES; 329 return STAT_TYPE_UNREQUESTED_PULL_REPLIES;
332 } 330 }
333 else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP], 331 else if (0 == strncmp(stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP],
334 stat_str, 332 stat_str,
335 strlen (stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP]))) 333 strlen(stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP])))
336 { 334 {
337 return STAT_TYPE_PEERS_IN_PUSH_MAP; 335 return STAT_TYPE_PEERS_IN_PUSH_MAP;
338 } 336 }
339 else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP], 337 else if (0 == strncmp(stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP],
340 stat_str, 338 stat_str,
341 strlen (stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP]))) 339 strlen(stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP])))
342 { 340 {
343 return STAT_TYPE_PEERS_IN_PULL_MAP; 341 return STAT_TYPE_PEERS_IN_PULL_MAP;
344 } 342 }
345 else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_VIEW], 343 else if (0 == strncmp(stat_type_strings[STAT_TYPE_PEERS_IN_VIEW],
346 stat_str, 344 stat_str,
347 strlen (stat_type_strings[STAT_TYPE_PEERS_IN_VIEW]))) 345 strlen(stat_type_strings[STAT_TYPE_PEERS_IN_VIEW])))
348 { 346 {
349 return STAT_TYPE_PEERS_IN_VIEW; 347 return STAT_TYPE_PEERS_IN_VIEW;
350 } 348 }
351 else if (0 == strncmp (stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM], 349 else if (0 == strncmp(stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM],
352 stat_str, 350 stat_str,
353 strlen (stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM]))) 351 strlen(stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM])))
354 { 352 {
355 return STAT_TYPE_VIEW_SIZE_AIM; 353 return STAT_TYPE_VIEW_SIZE_AIM;
356 } 354 }
357 return STAT_TYPE_MAX; 355 return STAT_TYPE_MAX;
358} 356}
359 357
@@ -375,8 +373,7 @@ enum PEER_ONLINE_DELTA {
375/** 373/**
376 * Operation map entry 374 * Operation map entry
377 */ 375 */
378struct OpListEntry 376struct OpListEntry {
379{
380 /** 377 /**
381 * DLL next ptr 378 * DLL next ptr
382 */ 379 */
@@ -418,8 +415,7 @@ static struct OpListEntry *oplist_tail;
418/** 415/**
419 * A pending reply: A request was sent and the reply is pending. 416 * A pending reply: A request was sent and the reply is pending.
420 */ 417 */
421struct PendingReply 418struct PendingReply {
422{
423 /** 419 /**
424 * DLL next,prev ptr 420 * DLL next,prev ptr
425 */ 421 */
@@ -441,8 +437,7 @@ struct PendingReply
441/** 437/**
442 * A pending request: A request was not made yet but is scheduled for later. 438 * A pending request: A request was not made yet but is scheduled for later.
443 */ 439 */
444struct PendingRequest 440struct PendingRequest {
445{
446 /** 441 /**
447 * DLL next,prev ptr 442 * DLL next,prev ptr
448 */ 443 */
@@ -464,8 +459,7 @@ struct PendingRequest
464/** 459/**
465 * Information we track for each peer. 460 * Information we track for each peer.
466 */ 461 */
467struct RPSPeer 462struct RPSPeer {
468{
469 /** 463 /**
470 * Index of the peer. 464 * Index of the peer.
471 */ 465 */
@@ -750,8 +744,7 @@ enum OPTION_COLLECT_VIEW {
750/** 744/**
751 * Structure to define a single test 745 * Structure to define a single test
752 */ 746 */
753struct SingleTestRun 747struct SingleTestRun {
754{
755 /** 748 /**
756 * Name of the test 749 * Name of the test
757 */ 750 */
@@ -838,7 +831,7 @@ static int in_shutdown;
838 * Append arguments to file 831 * Append arguments to file
839 */ 832 */
840static void 833static void
841tofile_ (const char *file_name, const char *line) 834tofile_(const char *file_name, const char *line)
842{ 835{
843 struct GNUNET_DISK_FileHandle *f; 836 struct GNUNET_DISK_FileHandle *f;
844 /* char output_buffer[512]; */ 837 /* char output_buffer[512]; */
@@ -846,69 +839,69 @@ tofile_ (const char *file_name, const char *line)
846 /* int size; */ 839 /* int size; */
847 size_t size2; 840 size_t size2;
848 841
849 if (NULL == (f = GNUNET_DISK_file_open (file_name, 842 if (NULL == (f = GNUNET_DISK_file_open(file_name,
850 GNUNET_DISK_OPEN_APPEND | 843 GNUNET_DISK_OPEN_APPEND |
851 GNUNET_DISK_OPEN_WRITE | 844 GNUNET_DISK_OPEN_WRITE |
852 GNUNET_DISK_OPEN_CREATE, 845 GNUNET_DISK_OPEN_CREATE,
853 GNUNET_DISK_PERM_USER_READ | 846 GNUNET_DISK_PERM_USER_READ |
854 GNUNET_DISK_PERM_USER_WRITE | 847 GNUNET_DISK_PERM_USER_WRITE |
855 GNUNET_DISK_PERM_GROUP_READ | 848 GNUNET_DISK_PERM_GROUP_READ |
856 GNUNET_DISK_PERM_OTHER_READ))) 849 GNUNET_DISK_PERM_OTHER_READ)))
857 { 850 {
858 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 851 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
859 "Not able to open file %s\n", 852 "Not able to open file %s\n",
860 file_name); 853 file_name);
861 return; 854 return;
862 } 855 }
863 /* size = GNUNET_snprintf (output_buffer, 856 /* size = GNUNET_snprintf (output_buffer,
864 sizeof (output_buffer), 857 sizeof (output_buffer),
865 "%llu %s\n", 858 "%llu %s\n",
866 GNUNET_TIME_absolute_get ().abs_value_us, 859 GNUNET_TIME_absolute_get ().abs_value_us,
867 line); 860 line);
868 if (0 > size) 861 if (0 > size)
869 { 862 {
870 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 863 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
871 "Failed to write string to buffer (size: %i)\n", 864 "Failed to write string to buffer (size: %i)\n",
872 size); 865 size);
873 return; 866 return;
874 } */ 867 } */
875 868
876 size = strlen (line) * sizeof (char); 869 size = strlen(line) * sizeof(char);
877 870
878 size2 = GNUNET_DISK_file_write (f, line, size); 871 size2 = GNUNET_DISK_file_write(f, line, size);
879 if (size != size2) 872 if (size != size2)
880 {
881 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
882 "Unable to write to file! (Size: %lu, size2: %lu)\n",
883 size,
884 size2);
885 if (GNUNET_YES != GNUNET_DISK_file_close (f))
886 { 873 {
887 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 874 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
888 "Unable to close file\n"); 875 "Unable to write to file! (Size: %lu, size2: %lu)\n",
876 size,
877 size2);
878 if (GNUNET_YES != GNUNET_DISK_file_close(f))
879 {
880 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
881 "Unable to close file\n");
882 }
883 return;
889 } 884 }
890 return;
891 }
892 885
893 if (GNUNET_YES != GNUNET_DISK_file_close (f)) 886 if (GNUNET_YES != GNUNET_DISK_file_close(f))
894 { 887 {
895 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 888 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
896 "Unable to close file\n"); 889 "Unable to close file\n");
897 } 890 }
898} 891}
899 892
900/** 893/**
901 * This function is used to facilitate writing important information to disk 894 * This function is used to facilitate writing important information to disk
902 */ 895 */
903#define tofile(file_name, ...) do {\ 896#define tofile(file_name, ...) do { \
904 char tmp_buf[512];\ 897 char tmp_buf[512]; \
905 int size;\ 898 int size; \
906 size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ 899 size = GNUNET_snprintf(tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \
907 if (0 > size)\ 900 if (0 > size) \
908 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ 901 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
909 "Failed to create tmp_buf\n");\ 902 "Failed to create tmp_buf\n"); \
910 else\ 903 else \
911 tofile_(file_name,tmp_buf);\ 904 tofile_ (file_name, tmp_buf); \
912 } while (0); 905 } while (0);
913 906
914 907
@@ -917,26 +910,26 @@ tofile_ (const char *file_name, const char *line)
917 * Unused 910 * Unused
918 */ 911 */
919/* static void 912/* static void
920ids_to_file (char *file_name, 913 ids_to_file (char *file_name,
921 struct GNUNET_PeerIdentity *peer_ids, 914 struct GNUNET_PeerIdentity *peer_ids,
922 unsigned int num_peer_ids) 915 unsigned int num_peer_ids)
923{ 916 {
924 unsigned int i; 917 unsigned int i;
925 918
926 for (i=0 ; i < num_peer_ids ; i++) 919 for (i=0 ; i < num_peer_ids ; i++)
927 { 920 {
928 to_file (file_name, 921 to_file (file_name,
929 "%u\t%s", 922 "%u\t%s",
930 i, 923 i,
931 GNUNET_i2s_full (&peer_ids[i])); 924 GNUNET_i2s_full (&peer_ids[i]));
932 } 925 }
933} */ 926 } */
934 927
935/** 928/**
936 * Test the success of a single test 929 * Test the success of a single test
937 */ 930 */
938static int 931static int
939evaluate (void) 932evaluate(void)
940{ 933{
941 unsigned int i; 934 unsigned int i;
942 int tmp_ok; 935 int tmp_ok;
@@ -944,17 +937,17 @@ evaluate (void)
944 tmp_ok = 1; 937 tmp_ok = 1;
945 938
946 for (i = 0; i < num_peers; i++) 939 for (i = 0; i < num_peers; i++)
947 { 940 {
948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 941 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
949 "%u. peer [%s] received %u of %u expected peer_ids: %i\n", 942 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
950 i, 943 i,
951 GNUNET_i2s (rps_peers[i].peer_id), 944 GNUNET_i2s(rps_peers[i].peer_id),
952 rps_peers[i].num_recv_ids, 945 rps_peers[i].num_recv_ids,
953 rps_peers[i].num_ids_to_request, 946 rps_peers[i].num_ids_to_request,
954 (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); 947 (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids));
955 tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids); 948 tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids);
956 } 949 }
957 return tmp_ok? 0 : 1; 950 return tmp_ok ? 0 : 1;
958} 951}
959 952
960 953
@@ -962,12 +955,12 @@ evaluate (void)
962 * Creates an oplist entry and adds it to the oplist DLL 955 * Creates an oplist entry and adds it to the oplist DLL
963 */ 956 */
964static struct OpListEntry * 957static struct OpListEntry *
965make_oplist_entry () 958make_oplist_entry()
966{ 959{
967 struct OpListEntry *entry; 960 struct OpListEntry *entry;
968 961
969 entry = GNUNET_new (struct OpListEntry); 962 entry = GNUNET_new(struct OpListEntry);
970 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); 963 GNUNET_CONTAINER_DLL_insert_tail(oplist_head, oplist_tail, entry);
971 return entry; 964 return entry;
972} 965}
973 966
@@ -981,15 +974,15 @@ make_oplist_entry ()
981 * @return #GNUNET_YES if so 974 * @return #GNUNET_YES if so
982 * #GNUNET_NO otherwise 975 * #GNUNET_NO otherwise
983 */ 976 */
984static int check_statistics_collect_completed_single_peer ( 977static int check_statistics_collect_completed_single_peer(
985 const struct RPSPeer *rps_peer) 978 const struct RPSPeer *rps_peer)
986{ 979{
987 if (cur_test_run.stat_collect_flags != 980 if (cur_test_run.stat_collect_flags !=
988 (cur_test_run.stat_collect_flags & 981 (cur_test_run.stat_collect_flags &
989 rps_peer->stat_collected_flags)) 982 rps_peer->stat_collected_flags))
990 { 983 {
991 return GNUNET_NO; 984 return GNUNET_NO;
992 } 985 }
993 return GNUNET_YES; 986 return GNUNET_YES;
994} 987}
995/** 988/**
@@ -999,152 +992,153 @@ static int check_statistics_collect_completed_single_peer (
999 * @return #GNUNET_YES if so 992 * @return #GNUNET_YES if so
1000 * #GNUNET_NO otherwise 993 * #GNUNET_NO otherwise
1001 */ 994 */
1002static int check_statistics_collect_completed () 995static int check_statistics_collect_completed()
1003{ 996{
1004 uint32_t i; 997 uint32_t i;
1005 998
1006 for (i = 0; i < num_peers; i++) 999 for (i = 0; i < num_peers; i++)
1007 {
1008 if (GNUNET_NO == check_statistics_collect_completed_single_peer (&rps_peers[i]))
1009 { 1000 {
1010 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1001 if (GNUNET_NO == check_statistics_collect_completed_single_peer(&rps_peers[i]))
1011 "At least Peer %" PRIu32 " did not yet receive all statistics values\n", 1002 {
1012 i); 1003 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1013 return GNUNET_NO; 1004 "At least Peer %" PRIu32 " did not yet receive all statistics values\n",
1005 i);
1006 return GNUNET_NO;
1007 }
1014 } 1008 }
1015 } 1009 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1010 "All peers received their statistics values\n");
1017 "All peers received their statistics values\n");
1018 return GNUNET_YES; 1011 return GNUNET_YES;
1019} 1012}
1020 1013
1021static void 1014static void
1022rps_disconnect_adapter (void *cls, 1015rps_disconnect_adapter(void *cls,
1023 void *op_result); 1016 void *op_result);
1024 1017
1025static void 1018static void
1026cancel_pending_req (struct PendingRequest *pending_req) 1019cancel_pending_req(struct PendingRequest *pending_req)
1027{ 1020{
1028 struct RPSPeer *rps_peer; 1021 struct RPSPeer *rps_peer;
1029 1022
1030 rps_peer = pending_req->rps_peer; 1023 rps_peer = pending_req->rps_peer;
1031 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, 1024 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head,
1032 rps_peer->pending_req_tail, 1025 rps_peer->pending_req_tail,
1033 pending_req); 1026 pending_req);
1034 rps_peer->num_pending_reqs--; 1027 rps_peer->num_pending_reqs--;
1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1028 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1036 "Cancelling pending rps get request\n"); 1029 "Cancelling pending rps get request\n");
1037 GNUNET_SCHEDULER_cancel (pending_req->request_task); 1030 GNUNET_SCHEDULER_cancel(pending_req->request_task);
1038 GNUNET_free (pending_req); 1031 GNUNET_free(pending_req);
1039} 1032}
1040 1033
1041static void 1034static void
1042cancel_request (struct PendingReply *pending_rep) 1035cancel_request(struct PendingReply *pending_rep)
1043{ 1036{
1044 struct RPSPeer *rps_peer; 1037 struct RPSPeer *rps_peer;
1045 1038
1046 rps_peer = pending_rep->rps_peer; 1039 rps_peer = pending_rep->rps_peer;
1047 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, 1040 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head,
1048 rps_peer->pending_rep_tail, 1041 rps_peer->pending_rep_tail,
1049 pending_rep); 1042 pending_rep);
1050 rps_peer->num_pending_reps--; 1043 rps_peer->num_pending_reps--;
1051 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1044 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1052 "Cancelling rps get reply\n"); 1045 "Cancelling rps get reply\n");
1053 GNUNET_assert (NULL != pending_rep->req_handle); 1046 GNUNET_assert(NULL != pending_rep->req_handle);
1054 GNUNET_RPS_request_single_info_cancel (pending_rep->req_handle); 1047 GNUNET_RPS_request_single_info_cancel(pending_rep->req_handle);
1055 pending_rep->req_handle = NULL; 1048 pending_rep->req_handle = NULL;
1056 GNUNET_free (pending_rep); 1049 GNUNET_free(pending_rep);
1057 pending_rep = NULL; 1050 pending_rep = NULL;
1058} 1051}
1059 1052
1060void 1053void
1061clean_peer (unsigned peer_index) 1054clean_peer(unsigned peer_index)
1062{ 1055{
1063 struct PendingRequest *pending_req; 1056 struct PendingRequest *pending_req;
1064 1057
1065 while (NULL != (pending_req = rps_peers[peer_index].pending_req_head)) 1058 while (NULL != (pending_req = rps_peers[peer_index].pending_req_head))
1066 { 1059 {
1067 cancel_pending_req (pending_req); 1060 cancel_pending_req(pending_req);
1068 } 1061 }
1069 pending_req = rps_peers[peer_index].pending_req_head; 1062 pending_req = rps_peers[peer_index].pending_req_head;
1070 rps_disconnect_adapter (&rps_peers[peer_index], 1063 rps_disconnect_adapter(&rps_peers[peer_index],
1071 &rps_peers[peer_index].rps_handle); 1064 &rps_peers[peer_index].rps_handle);
1072 for (unsigned stat_type = STAT_TYPE_ROUNDS; 1065 for (unsigned stat_type = STAT_TYPE_ROUNDS;
1073 stat_type < STAT_TYPE_MAX; 1066 stat_type < STAT_TYPE_MAX;
1074 stat_type++) 1067 stat_type++)
1075 {
1076 if (NULL != rps_peers[peer_index].h_stat_get[stat_type])
1077 { 1068 {
1078 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1069 if (NULL != rps_peers[peer_index].h_stat_get[stat_type])
1079 "(%u) did not yet receive stat value for `%s'\n", 1070 {
1080 rps_peers[peer_index].index, 1071 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1081 stat_type_strings[stat_type]); 1072 "(%u) did not yet receive stat value for `%s'\n",
1082 GNUNET_STATISTICS_get_cancel ( 1073 rps_peers[peer_index].index,
1083 rps_peers[peer_index].h_stat_get[stat_type]); 1074 stat_type_strings[stat_type]);
1075 GNUNET_STATISTICS_get_cancel(
1076 rps_peers[peer_index].h_stat_get[stat_type]);
1077 }
1084 } 1078 }
1085 }
1086 if (NULL != rps_peers[peer_index].op) 1079 if (NULL != rps_peers[peer_index].op)
1087 { 1080 {
1088 GNUNET_TESTBED_operation_done (rps_peers[peer_index].op); 1081 GNUNET_TESTBED_operation_done(rps_peers[peer_index].op);
1089 rps_peers[peer_index].op = NULL; 1082 rps_peers[peer_index].op = NULL;
1090 } 1083 }
1091} 1084}
1092 1085
1093/** 1086/**
1094 * Task run on timeout to shut everything down. 1087 * Task run on timeout to shut everything down.
1095 */ 1088 */
1096static void 1089static void
1097shutdown_op (void *cls) 1090shutdown_op(void *cls)
1098{ 1091{
1099 unsigned int i; 1092 unsigned int i;
1100 struct OpListEntry *entry; 1093 struct OpListEntry *entry;
1101 (void) cls;
1102 1094
1103 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1095 (void)cls;
1104 "Shutdown task scheduled, going down.\n"); 1096
1097 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1098 "Shutdown task scheduled, going down.\n");
1105 in_shutdown = GNUNET_YES; 1099 in_shutdown = GNUNET_YES;
1106 1100
1107 if (NULL != shutdown_task) 1101 if (NULL != shutdown_task)
1108 { 1102 {
1109 GNUNET_SCHEDULER_cancel (shutdown_task); 1103 GNUNET_SCHEDULER_cancel(shutdown_task);
1110 shutdown_task = NULL; 1104 shutdown_task = NULL;
1111 } 1105 }
1112 if (NULL != post_test_task) 1106 if (NULL != post_test_task)
1113 { 1107 {
1114 GNUNET_SCHEDULER_cancel (post_test_task); 1108 GNUNET_SCHEDULER_cancel(post_test_task);
1115 post_test_task = NULL; 1109 post_test_task = NULL;
1116 } 1110 }
1117 if (NULL != churn_task) 1111 if (NULL != churn_task)
1118 { 1112 {
1119 GNUNET_SCHEDULER_cancel (churn_task); 1113 GNUNET_SCHEDULER_cancel(churn_task);
1120 churn_task = NULL; 1114 churn_task = NULL;
1121 } 1115 }
1122 entry = oplist_head; 1116 entry = oplist_head;
1123 while (NULL != (entry = oplist_head)) 1117 while (NULL != (entry = oplist_head))
1124 { 1118 {
1125 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1119 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1126 "Operation still pending on shutdown (%u)\n", 1120 "Operation still pending on shutdown (%u)\n",
1127 entry->index); 1121 entry->index);
1128 GNUNET_TESTBED_operation_done (entry->op); 1122 GNUNET_TESTBED_operation_done(entry->op);
1129 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); 1123 GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry);
1130 GNUNET_free (entry); 1124 GNUNET_free(entry);
1131 } 1125 }
1132 for (i = 0; i < num_peers; i++) 1126 for (i = 0; i < num_peers; i++)
1133 { 1127 {
1134 clean_peer (i); 1128 clean_peer(i);
1135 } 1129 }
1136 close_all_files(); 1130 close_all_files();
1137} 1131}
1138 1132
1139static void 1133static void
1140trigger_shutdown (void *cls) 1134trigger_shutdown(void *cls)
1141{ 1135{
1142 (void) cls; 1136 (void)cls;
1143 1137
1144 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1138 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1145 "Shutdown was triggerd by timeout, going down.\n"); 1139 "Shutdown was triggerd by timeout, going down.\n");
1146 shutdown_task = NULL; 1140 shutdown_task = NULL;
1147 GNUNET_SCHEDULER_shutdown (); 1141 GNUNET_SCHEDULER_shutdown();
1148} 1142}
1149 1143
1150 1144
@@ -1152,46 +1146,47 @@ trigger_shutdown (void *cls)
1152 * Task run after #duration to collect statistics and potentially shut down. 1146 * Task run after #duration to collect statistics and potentially shut down.
1153 */ 1147 */
1154static void 1148static void
1155post_test_op (void *cls) 1149post_test_op(void *cls)
1156{ 1150{
1157 unsigned int i; 1151 unsigned int i;
1158 (void) cls; 1152
1153 (void)cls;
1159 1154
1160 post_test_task = NULL; 1155 post_test_task = NULL;
1161 post_test = GNUNET_YES; 1156 post_test = GNUNET_YES;
1162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1157 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1163 "Executing post test op.\n"); 1158 "Executing post test op.\n");
1164 if (NULL != churn_task) 1159 if (NULL != churn_task)
1165 {
1166 GNUNET_SCHEDULER_cancel (churn_task);
1167 churn_task = NULL;
1168 }
1169 for (i = 0; i < num_peers; i++)
1170 {
1171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1172 "Executing post test op. (peer %" PRIu32 ")\n",
1173 rps_peers[i].index);
1174 if (NULL != rps_peers[i].op)
1175 { 1160 {
1176 GNUNET_TESTBED_operation_done (rps_peers[i].op); 1161 GNUNET_SCHEDULER_cancel(churn_task);
1177 rps_peers[i].op = NULL; 1162 churn_task = NULL;
1178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1179 "Cancelled testbed operation\n");
1180 } 1163 }
1181 if (NULL != cur_test_run.post_test) 1164 for (i = 0; i < num_peers; i++)
1182 { 1165 {
1183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); 1166 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1184 cur_test_run.post_test (&rps_peers[i]); 1167 "Executing post test op. (peer %" PRIu32 ")\n",
1168 rps_peers[i].index);
1169 if (NULL != rps_peers[i].op)
1170 {
1171 GNUNET_TESTBED_operation_done(rps_peers[i].op);
1172 rps_peers[i].op = NULL;
1173 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1174 "Cancelled testbed operation\n");
1175 }
1176 if (NULL != cur_test_run.post_test)
1177 {
1178 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i);
1179 cur_test_run.post_test(&rps_peers[i]);
1180 }
1185 } 1181 }
1186 }
1187 /* If we do not collect statistics, shut down directly */ 1182 /* If we do not collect statistics, shut down directly */
1188 if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics || 1183 if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics ||
1189 GNUNET_YES == check_statistics_collect_completed()) 1184 GNUNET_YES == check_statistics_collect_completed())
1190 { 1185 {
1191 GNUNET_SCHEDULER_cancel (shutdown_task); 1186 GNUNET_SCHEDULER_cancel(shutdown_task);
1192 shutdown_task = NULL; 1187 shutdown_task = NULL;
1193 GNUNET_SCHEDULER_shutdown (); 1188 GNUNET_SCHEDULER_shutdown();
1194 } 1189 }
1195} 1190}
1196 1191
1197 1192
@@ -1199,70 +1194,71 @@ post_test_op (void *cls)
1199 * Seed peers. 1194 * Seed peers.
1200 */ 1195 */
1201static void 1196static void
1202seed_peers (void *cls) 1197seed_peers(void *cls)
1203{ 1198{
1204 struct RPSPeer *peer = cls; 1199 struct RPSPeer *peer = cls;
1205 unsigned int amount; 1200 unsigned int amount;
1206 unsigned int i; 1201 unsigned int i;
1207 1202
1208 // TODO if malicious don't seed mal peers 1203 // TODO if malicious don't seed mal peers
1209 amount = round (.5 * num_peers); 1204 amount = round(.5 * num_peers);
1210 1205
1211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); 1206 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
1212 for (i = 0 ; i < amount ; i++) 1207 for (i = 0; i < amount; i++)
1213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", 1208 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
1214 i, 1209 i,
1215 GNUNET_i2s (&rps_peer_ids[i])); 1210 GNUNET_i2s(&rps_peer_ids[i]));
1216 1211
1217 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids); 1212 GNUNET_RPS_seed_ids(peer->rps_handle, amount, rps_peer_ids);
1218} 1213}
1219 1214
1220 1215
1221/** 1216/**
1222 * Get the id of peer i. 1217 * Get the id of peer i.
1223 */ 1218 */
1224 void 1219void
1225info_cb (void *cb_cls, 1220info_cb(void *cb_cls,
1226 struct GNUNET_TESTBED_Operation *op, 1221 struct GNUNET_TESTBED_Operation *op,
1227 const struct GNUNET_TESTBED_PeerInformation *pinfo, 1222 const struct GNUNET_TESTBED_PeerInformation *pinfo,
1228 const char *emsg) 1223 const char *emsg)
1229{ 1224{
1230 struct OpListEntry *entry = (struct OpListEntry *) cb_cls; 1225 struct OpListEntry *entry = (struct OpListEntry *)cb_cls;
1231 (void) op; 1226
1227 (void)op;
1232 1228
1233 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1229 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1234 { 1230 {
1235 return; 1231 return;
1236 } 1232 }
1237 1233
1238 if (NULL == pinfo || NULL != emsg) 1234 if (NULL == pinfo || NULL != emsg)
1239 { 1235 {
1240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); 1236 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
1241 GNUNET_TESTBED_operation_done (entry->op); 1237 GNUNET_TESTBED_operation_done(entry->op);
1242 return; 1238 return;
1243 } 1239 }
1244 1240
1245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1241 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1246 "Peer %u is %s\n", 1242 "Peer %u is %s\n",
1247 entry->index, 1243 entry->index,
1248 GNUNET_i2s (pinfo->result.id)); 1244 GNUNET_i2s(pinfo->result.id));
1249 1245
1250 rps_peer_ids[entry->index] = *(pinfo->result.id); 1246 rps_peer_ids[entry->index] = *(pinfo->result.id);
1251 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; 1247 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
1252 1248
1253 GNUNET_assert (GNUNET_OK == 1249 GNUNET_assert(GNUNET_OK ==
1254 GNUNET_CONTAINER_multipeermap_put (peer_map, 1250 GNUNET_CONTAINER_multipeermap_put(peer_map,
1255 &rps_peer_ids[entry->index], 1251 &rps_peer_ids[entry->index],
1256 &rps_peers[entry->index], 1252 &rps_peers[entry->index],
1257 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1253 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1258 tofile ("/tmp/rps/peer_ids", 1254 tofile("/tmp/rps/peer_ids",
1259 "%u\t%s\n", 1255 "%u\t%s\n",
1260 entry->index, 1256 entry->index,
1261 GNUNET_i2s_full (&rps_peer_ids[entry->index])); 1257 GNUNET_i2s_full(&rps_peer_ids[entry->index]));
1262 1258
1263 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); 1259 GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry);
1264 GNUNET_TESTBED_operation_done (entry->op); 1260 GNUNET_TESTBED_operation_done(entry->op);
1265 GNUNET_free (entry); 1261 GNUNET_free(entry);
1266} 1262}
1267 1263
1268 1264
@@ -1276,39 +1272,39 @@ info_cb (void *cb_cls,
1276 * operation has executed successfully. 1272 * operation has executed successfully.
1277 */ 1273 */
1278static void 1274static void
1279rps_connect_complete_cb (void *cls, 1275rps_connect_complete_cb(void *cls,
1280 struct GNUNET_TESTBED_Operation *op, 1276 struct GNUNET_TESTBED_Operation *op,
1281 void *ca_result, 1277 void *ca_result,
1282 const char *emsg) 1278 const char *emsg)
1283{ 1279{
1284 struct RPSPeer *rps_peer = cls; 1280 struct RPSPeer *rps_peer = cls;
1285 struct GNUNET_RPS_Handle *rps = ca_result; 1281 struct GNUNET_RPS_Handle *rps = ca_result;
1286 1282
1287 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1283 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1288 { 1284 {
1289 return; 1285 return;
1290 } 1286 }
1291 1287
1292 rps_peer->rps_handle = rps; 1288 rps_peer->rps_handle = rps;
1293 rps_peer->online = GNUNET_YES; 1289 rps_peer->online = GNUNET_YES;
1294 num_peers_online++; 1290 num_peers_online++;
1295 1291
1296 GNUNET_assert (op == rps_peer->op); 1292 GNUNET_assert(op == rps_peer->op);
1297 if (NULL != emsg) 1293 if (NULL != emsg)
1298 { 1294 {
1299 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1295 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1300 "Failed to connect to RPS service: %s\n", 1296 "Failed to connect to RPS service: %s\n",
1301 emsg); 1297 emsg);
1302 ok = 1; 1298 ok = 1;
1303 GNUNET_SCHEDULER_shutdown (); 1299 GNUNET_SCHEDULER_shutdown();
1304 return; 1300 return;
1305 } 1301 }
1306 1302
1307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1303 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1308 "Started client successfully (%u)\n", 1304 "Started client successfully (%u)\n",
1309 rps_peer->index); 1305 rps_peer->index);
1310 1306
1311 cur_test_run.main_test (rps_peer); 1307 cur_test_run.main_test(rps_peer);
1312} 1308}
1313 1309
1314 1310
@@ -1323,15 +1319,15 @@ rps_connect_complete_cb (void *cls,
1323 * @return service handle to return in 'op_result', NULL on error 1319 * @return service handle to return in 'op_result', NULL on error
1324 */ 1320 */
1325static void * 1321static void *
1326rps_connect_adapter (void *cls, 1322rps_connect_adapter(void *cls,
1327 const struct GNUNET_CONFIGURATION_Handle *cfg) 1323 const struct GNUNET_CONFIGURATION_Handle *cfg)
1328{ 1324{
1329 struct GNUNET_RPS_Handle *h; 1325 struct GNUNET_RPS_Handle *h;
1330 1326
1331 h = GNUNET_RPS_connect (cfg); 1327 h = GNUNET_RPS_connect(cfg);
1332 1328
1333 if (NULL != cur_test_run.pre_test) 1329 if (NULL != cur_test_run.pre_test)
1334 cur_test_run.pre_test (cls, h); 1330 cur_test_run.pre_test(cls, h);
1335 1331
1336 return h; 1332 return h;
1337} 1333}
@@ -1346,12 +1342,12 @@ rps_connect_adapter (void *cls,
1346 * @return service handle to return in 'op_result', NULL on error 1342 * @return service handle to return in 'op_result', NULL on error
1347 */ 1343 */
1348static void * 1344static void *
1349stat_connect_adapter (void *cls, 1345stat_connect_adapter(void *cls,
1350 const struct GNUNET_CONFIGURATION_Handle *cfg) 1346 const struct GNUNET_CONFIGURATION_Handle *cfg)
1351{ 1347{
1352 struct RPSPeer *peer = cls; 1348 struct RPSPeer *peer = cls;
1353 1349
1354 peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg); 1350 peer->stats_h = GNUNET_STATISTICS_create("rps-profiler", cfg);
1355 return peer->stats_h; 1351 return peer->stats_h;
1356} 1352}
1357 1353
@@ -1362,7 +1358,7 @@ stat_connect_adapter (void *cls,
1362 * @param op_result service handle returned from the connect adapter 1358 * @param op_result service handle returned from the connect adapter
1363 */ 1359 */
1364static void 1360static void
1365stat_disconnect_adapter (void *cls, void *op_result) 1361stat_disconnect_adapter(void *cls, void *op_result)
1366{ 1362{
1367 struct RPSPeer *peer = cls; 1363 struct RPSPeer *peer = cls;
1368 1364
@@ -1372,7 +1368,7 @@ stat_disconnect_adapter (void *cls, void *op_result)
1372 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel 1368 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
1373 // (peer->stats_h, "nse", "# peers connected", 1369 // (peer->stats_h, "nse", "# peers connected",
1374 // stat_iterator, peer)); 1370 // stat_iterator, peer));
1375 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); 1371 GNUNET_STATISTICS_destroy(op_result, GNUNET_NO);
1376 peer->stats_h = NULL; 1372 peer->stats_h = NULL;
1377} 1373}
1378 1374
@@ -1387,22 +1383,22 @@ stat_disconnect_adapter (void *cls, void *op_result)
1387 * operation has executed successfully. 1383 * operation has executed successfully.
1388 */ 1384 */
1389static void 1385static void
1390stat_complete_cb (void *cls, 1386stat_complete_cb(void *cls,
1391 struct GNUNET_TESTBED_Operation *op, 1387 struct GNUNET_TESTBED_Operation *op,
1392 void *ca_result, 1388 void *ca_result,
1393 const char *emsg ) 1389 const char *emsg)
1394{ 1390{
1395 //struct GNUNET_STATISTICS_Handle *sh = ca_result; 1391 //struct GNUNET_STATISTICS_Handle *sh = ca_result;
1396 //struct RPSPeer *peer = (struct RPSPeer *) cls; 1392 //struct RPSPeer *peer = (struct RPSPeer *) cls;
1397 (void) cls; 1393 (void)cls;
1398 (void) op; 1394 (void)op;
1399 (void) ca_result; 1395 (void)ca_result;
1400 1396
1401 if (NULL != emsg) 1397 if (NULL != emsg)
1402 { 1398 {
1403 GNUNET_break (0); 1399 GNUNET_break(0);
1404 return; 1400 return;
1405 } 1401 }
1406 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch 1402 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
1407 // (sh, "core", "# peers connected", 1403 // (sh, "core", "# peers connected",
1408 // stat_iterator, peer)); 1404 // stat_iterator, peer));
@@ -1420,36 +1416,36 @@ stat_complete_cb (void *cls,
1420 * @param op_result service handle returned from the connect adapter 1416 * @param op_result service handle returned from the connect adapter
1421 */ 1417 */
1422static void 1418static void
1423rps_disconnect_adapter (void *cls, 1419rps_disconnect_adapter(void *cls,
1424 void *op_result) 1420 void *op_result)
1425{ 1421{
1426 struct RPSPeer *peer = cls; 1422 struct RPSPeer *peer = cls;
1427 struct GNUNET_RPS_Handle *h = op_result; 1423 struct GNUNET_RPS_Handle *h = op_result;
1428 struct PendingReply *pending_rep; 1424 struct PendingReply *pending_rep;
1429 1425
1430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1426 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1431 "disconnect_adapter (%u)\n", 1427 "disconnect_adapter (%u)\n",
1432 peer->index); 1428 peer->index);
1433 GNUNET_assert (NULL != peer); 1429 GNUNET_assert(NULL != peer);
1434 if (NULL != peer->rps_handle) 1430 if (NULL != peer->rps_handle)
1435 {
1436 while (NULL != (pending_rep = peer->pending_rep_head))
1437 { 1431 {
1438 cancel_request (pending_rep); 1432 while (NULL != (pending_rep = peer->pending_rep_head))
1433 {
1434 cancel_request(pending_rep);
1435 }
1436 GNUNET_assert(h == peer->rps_handle);
1437 if (NULL != h)
1438 {
1439 GNUNET_RPS_disconnect(h);
1440 h = NULL;
1441 }
1442 peer->rps_handle = NULL;
1439 } 1443 }
1440 GNUNET_assert (h == peer->rps_handle);
1441 if (NULL != h)
1442 {
1443 GNUNET_RPS_disconnect (h);
1444 h = NULL;
1445 }
1446 peer->rps_handle = NULL;
1447 }
1448} 1444}
1449 1445
1450 1446
1451/*********************************************************************** 1447/***********************************************************************
1452 * Definition of tests 1448* Definition of tests
1453***********************************************************************/ 1449***********************************************************************/
1454 1450
1455/** 1451/**
@@ -1460,84 +1456,88 @@ rps_disconnect_adapter (void *cls,
1460 * @param recv_peers the received peers 1456 * @param recv_peers the received peers
1461 */ 1457 */
1462static void 1458static void
1463default_reply_handle (void *cls, 1459default_reply_handle(void *cls,
1464 uint64_t n, 1460 uint64_t n,
1465 const struct GNUNET_PeerIdentity *recv_peers) 1461 const struct GNUNET_PeerIdentity *recv_peers)
1466{ 1462{
1467 struct RPSPeer *rps_peer; 1463 struct RPSPeer *rps_peer;
1468 struct PendingReply *pending_rep = (struct PendingReply *) cls; 1464 struct PendingReply *pending_rep = (struct PendingReply *)cls;
1469 unsigned int i; 1465 unsigned int i;
1470 1466
1471 rps_peer = pending_rep->rps_peer; 1467 rps_peer = pending_rep->rps_peer;
1472 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, 1468 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head,
1473 rps_peer->pending_rep_tail, 1469 rps_peer->pending_rep_tail,
1474 pending_rep); 1470 pending_rep);
1475 rps_peer->num_pending_reps--; 1471 rps_peer->num_pending_reps--;
1476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1472 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1477 "[%s] got %" PRIu64 " peers:\n", 1473 "[%s] got %" PRIu64 " peers:\n",
1478 GNUNET_i2s (rps_peer->peer_id), 1474 GNUNET_i2s(rps_peer->peer_id),
1479 n); 1475 n);
1480 1476
1481 for (i = 0; i < n; i++) 1477 for (i = 0; i < n; i++)
1482 { 1478 {
1483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1479 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1484 "%u: %s\n", 1480 "%u: %s\n",
1485 i, 1481 i,
1486 GNUNET_i2s (&recv_peers[i])); 1482 GNUNET_i2s(&recv_peers[i]));
1487 1483
1488 rps_peer->num_recv_ids++; 1484 rps_peer->num_recv_ids++;
1489 } 1485 }
1490 1486
1491 if (GNUNET_YES != post_test) return; 1487 if (GNUNET_YES != post_test)
1492 if (HAVE_QUICK_QUIT != cur_test_run.have_quick_quit) return; 1488 return;
1489 if (HAVE_QUICK_QUIT != cur_test_run.have_quick_quit)
1490 return;
1493 if (0 == evaluate()) 1491 if (0 == evaluate())
1494 { 1492 {
1495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1493 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1496 "Test succeeded before end of duration\n"); 1494 "Test succeeded before end of duration\n");
1497 if (NULL != post_test_task) GNUNET_SCHEDULER_cancel (post_test_task); 1495 if (NULL != post_test_task)
1498 post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); 1496 GNUNET_SCHEDULER_cancel(post_test_task);
1499 GNUNET_assert (NULL != post_test_task); 1497 post_test_task = GNUNET_SCHEDULER_add_now(&post_test_op, NULL);
1500 } 1498 GNUNET_assert(NULL != post_test_task);
1499 }
1501} 1500}
1502 1501
1503 1502
1504static void 1503static void
1505profiler_reply_handle_info (void *cls, 1504profiler_reply_handle_info(void *cls,
1506 const struct GNUNET_PeerIdentity *recv_peer, 1505 const struct GNUNET_PeerIdentity *recv_peer,
1507 double probability, 1506 double probability,
1508 uint32_t num_observed); 1507 uint32_t num_observed);
1509 1508
1510/** 1509/**
1511 * Request random peers. 1510 * Request random peers.
1512 */ 1511 */
1513static void 1512static void
1514request_peers (void *cls) 1513request_peers(void *cls)
1515{ 1514{
1516 struct PendingRequest *pending_req = cls; 1515 struct PendingRequest *pending_req = cls;
1517 struct RPSPeer *rps_peer; 1516 struct RPSPeer *rps_peer;
1518 struct PendingReply *pending_rep; 1517 struct PendingReply *pending_rep;
1519 1518
1520 rps_peer = pending_req->rps_peer; 1519 rps_peer = pending_req->rps_peer;
1521 GNUNET_assert (1 <= rps_peer->num_pending_reqs); 1520 GNUNET_assert(1 <= rps_peer->num_pending_reqs);
1522 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, 1521 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head,
1523 rps_peer->pending_req_tail, 1522 rps_peer->pending_req_tail,
1524 pending_req); 1523 pending_req);
1525 rps_peer->num_pending_reqs--; 1524 rps_peer->num_pending_reqs--;
1526 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) return; 1525 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1526 return;
1528 "Requesting one peer\n"); 1527 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1529 pending_rep = GNUNET_new (struct PendingReply); 1528 "Requesting one peer\n");
1529 pending_rep = GNUNET_new(struct PendingReply);
1530 pending_rep->rps_peer = rps_peer; 1530 pending_rep->rps_peer = rps_peer;
1531 //pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, 1531 //pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle,
1532 // 1, 1532 // 1,
1533 // cur_test_run.reply_handle, 1533 // cur_test_run.reply_handle,
1534 // pending_rep); 1534 // pending_rep);
1535 pending_rep->req_handle = GNUNET_RPS_request_peer_info (rps_peer->rps_handle, 1535 pending_rep->req_handle = GNUNET_RPS_request_peer_info(rps_peer->rps_handle,
1536 profiler_reply_handle_info, 1536 profiler_reply_handle_info,
1537 pending_rep); 1537 pending_rep);
1538 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head, 1538 GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_rep_head,
1539 rps_peer->pending_rep_tail, 1539 rps_peer->pending_rep_tail,
1540 pending_rep); 1540 pending_rep);
1541 rps_peer->num_pending_reps++; 1541 rps_peer->num_pending_reps++;
1542} 1542}
1543 1543
@@ -1547,57 +1547,57 @@ request_peers (void *cls)
1547 * issued, nor replied 1547 * issued, nor replied
1548 */ 1548 */
1549void 1549void
1550schedule_missing_requests (struct RPSPeer *rps_peer) 1550schedule_missing_requests(struct RPSPeer *rps_peer)
1551{ 1551{
1552 unsigned int i; 1552 unsigned int i;
1553 struct PendingRequest *pending_req; 1553 struct PendingRequest *pending_req;
1554 1554
1555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1555 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1556 "Scheduling %u - %u missing requests\n", 1556 "Scheduling %u - %u missing requests\n",
1557 rps_peer->num_ids_to_request, 1557 rps_peer->num_ids_to_request,
1558 rps_peer->num_pending_reqs + rps_peer->num_pending_reps); 1558 rps_peer->num_pending_reqs + rps_peer->num_pending_reps);
1559 GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= 1559 GNUNET_assert(rps_peer->num_pending_reqs + rps_peer->num_pending_reps <=
1560 rps_peer->num_ids_to_request); 1560 rps_peer->num_ids_to_request);
1561 for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps; 1561 for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps;
1562 i < rps_peer->num_ids_to_request; i++) 1562 i < rps_peer->num_ids_to_request; i++)
1563 { 1563 {
1564 pending_req = GNUNET_new (struct PendingRequest); 1564 pending_req = GNUNET_new(struct PendingRequest);
1565 pending_req->rps_peer = rps_peer; 1565 pending_req->rps_peer = rps_peer;
1566 pending_req->request_task = GNUNET_SCHEDULER_add_delayed ( 1566 pending_req->request_task = GNUNET_SCHEDULER_add_delayed(
1567 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1567 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
1568 cur_test_run.request_interval * i), 1568 cur_test_run.request_interval * i),
1569 request_peers, 1569 request_peers,
1570 pending_req); 1570 pending_req);
1571 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head, 1571 GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_req_head,
1572 rps_peer->pending_req_tail, 1572 rps_peer->pending_req_tail,
1573 pending_req); 1573 pending_req);
1574 rps_peer->num_pending_reqs++; 1574 rps_peer->num_pending_reqs++;
1575 } 1575 }
1576} 1576}
1577 1577
1578void 1578void
1579cancel_pending_req_rep (struct RPSPeer *rps_peer) 1579cancel_pending_req_rep(struct RPSPeer *rps_peer)
1580{ 1580{
1581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1581 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1582 "Cancelling all (pending) requests.\n"); 1582 "Cancelling all (pending) requests.\n");
1583 while (NULL != rps_peer->pending_req_head) 1583 while (NULL != rps_peer->pending_req_head)
1584 cancel_pending_req (rps_peer->pending_req_head); 1584 cancel_pending_req(rps_peer->pending_req_head);
1585 GNUNET_assert (0 == rps_peer->num_pending_reqs); 1585 GNUNET_assert(0 == rps_peer->num_pending_reqs);
1586 while (NULL != rps_peer->pending_rep_head) 1586 while (NULL != rps_peer->pending_rep_head)
1587 cancel_request (rps_peer->pending_rep_head); 1587 cancel_request(rps_peer->pending_rep_head);
1588 GNUNET_assert (0 == rps_peer->num_pending_reps); 1588 GNUNET_assert(0 == rps_peer->num_pending_reps);
1589} 1589}
1590 1590
1591/*********************************** 1591/***********************************
1592 * MALICIOUS 1592* MALICIOUS
1593***********************************/ 1593***********************************/
1594 1594
1595/** 1595/**
1596 * Initialise only non-mal RPSPeers 1596 * Initialise only non-mal RPSPeers
1597 */ 1597 */
1598static void mal_init_peer (struct RPSPeer *rps_peer) 1598static void mal_init_peer(struct RPSPeer *rps_peer)
1599{ 1599{
1600 if (rps_peer->index >= round (portion * num_peers)) 1600 if (rps_peer->index >= round(portion * num_peers))
1601 rps_peer->num_ids_to_request = 1; 1601 rps_peer->num_ids_to_request = 1;
1602} 1602}
1603 1603
@@ -1611,60 +1611,60 @@ static void mal_init_peer (struct RPSPeer *rps_peer)
1611 * @param h the handle to the service 1611 * @param h the handle to the service
1612 */ 1612 */
1613static void 1613static void
1614mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 1614mal_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1615{ 1615{
1616 #if ENABLE_MALICIOUS 1616 #if ENABLE_MALICIOUS
1617 uint32_t num_mal_peers; 1617 uint32_t num_mal_peers;
1618 1618
1619 GNUNET_assert ( (1 >= portion) && 1619 GNUNET_assert((1 >= portion) &&
1620 (0 < portion) ); 1620 (0 < portion));
1621 num_mal_peers = round (portion * num_peers); 1621 num_mal_peers = round(portion * num_peers);
1622 1622
1623 if (rps_peer->index < num_mal_peers) 1623 if (rps_peer->index < num_mal_peers)
1624 { 1624 {
1625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1625 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1626 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", 1626 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
1627 rps_peer->index, 1627 rps_peer->index,
1628 GNUNET_i2s (rps_peer->peer_id), 1628 GNUNET_i2s(rps_peer->peer_id),
1629 num_mal_peers); 1629 num_mal_peers);
1630 1630
1631 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, 1631 GNUNET_RPS_act_malicious(h, mal_type, num_mal_peers,
1632 rps_peer_ids, target_peer); 1632 rps_peer_ids, target_peer);
1633 } 1633 }
1634 #endif /* ENABLE_MALICIOUS */ 1634 #endif /* ENABLE_MALICIOUS */
1635} 1635}
1636 1636
1637static void 1637static void
1638mal_cb (struct RPSPeer *rps_peer) 1638mal_cb(struct RPSPeer *rps_peer)
1639{ 1639{
1640 uint32_t num_mal_peers; 1640 uint32_t num_mal_peers;
1641 1641
1642 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1642 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1643 { 1643 {
1644 return; 1644 return;
1645 } 1645 }
1646 1646
1647 #if ENABLE_MALICIOUS 1647 #if ENABLE_MALICIOUS
1648 GNUNET_assert ( (1 >= portion) && 1648 GNUNET_assert((1 >= portion) &&
1649 (0 < portion) ); 1649 (0 < portion));
1650 num_mal_peers = round (portion * num_peers); 1650 num_mal_peers = round(portion * num_peers);
1651 1651
1652 if (rps_peer->index >= num_mal_peers) 1652 if (rps_peer->index >= num_mal_peers)
1653 { /* It's useless to ask a malicious peer about a random sample - 1653 { /* It's useless to ask a malicious peer about a random sample -
1654 it's not sampling */ 1654 it's not sampling */
1655 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), 1655 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
1656 seed_peers, rps_peer); 1656 seed_peers, rps_peer);
1657 schedule_missing_requests (rps_peer); 1657 schedule_missing_requests(rps_peer);
1658 } 1658 }
1659 #endif /* ENABLE_MALICIOUS */ 1659 #endif /* ENABLE_MALICIOUS */
1660} 1660}
1661 1661
1662/*********************************** 1662/***********************************
1663 * CHURN 1663* CHURN
1664***********************************/ 1664***********************************/
1665 1665
1666static void 1666static void
1667churn (void *cls); 1667churn(void *cls);
1668 1668
1669/** 1669/**
1670 * @brief Starts churn 1670 * @brief Starts churn
@@ -1678,32 +1678,34 @@ churn (void *cls);
1678 * @param rps_peer The peer it's called for 1678 * @param rps_peer The peer it's called for
1679 */ 1679 */
1680static void 1680static void
1681churn_test_cb (struct RPSPeer *rps_peer) 1681churn_test_cb(struct RPSPeer *rps_peer)
1682{ 1682{
1683 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1683 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1684 { 1684 {
1685 return; 1685 return;
1686 } 1686 }
1687 1687
1688 /* Start churn */ 1688 /* Start churn */
1689 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) 1689 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task)
1690 { 1690 {
1691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1691 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1692 "Starting churn task\n"); 1692 "Starting churn task\n");
1693 churn_task = GNUNET_SCHEDULER_add_delayed ( 1693 churn_task = GNUNET_SCHEDULER_add_delayed(
1694 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), 1694 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
1695 churn, 1695 churn,
1696 NULL); 1696 NULL);
1697 } else { 1697 }
1698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1698 else
1699 "Not starting churn task\n"); 1699 {
1700 } 1700 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1701 1701 "Not starting churn task\n");
1702 schedule_missing_requests (rps_peer); 1702 }
1703
1704 schedule_missing_requests(rps_peer);
1703} 1705}
1704 1706
1705/*********************************** 1707/***********************************
1706 * PROFILER 1708* PROFILER
1707***********************************/ 1709***********************************/
1708 1710
1709/** 1711/**
@@ -1714,81 +1716,82 @@ churn_test_cb (struct RPSPeer *rps_peer)
1714 * @param emsg NULL on success; otherwise an error description 1716 * @param emsg NULL on success; otherwise an error description
1715 */ 1717 */
1716static void 1718static void
1717churn_cb (void *cls, 1719churn_cb(void *cls,
1718 struct GNUNET_TESTBED_Operation *op, 1720 struct GNUNET_TESTBED_Operation *op,
1719 const char *emsg) 1721 const char *emsg)
1720{ 1722{
1721 // FIXME 1723 // FIXME
1722 struct OpListEntry *entry = cls; 1724 struct OpListEntry *entry = cls;
1723 (void) op; 1725
1726 (void)op;
1724 1727
1725 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1728 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1726 { 1729 {
1727 return; 1730 return;
1728 } 1731 }
1729 1732
1730 GNUNET_TESTBED_operation_done (entry->op); 1733 GNUNET_TESTBED_operation_done(entry->op);
1731 if (NULL != emsg) 1734 if (NULL != emsg)
1732 { 1735 {
1733 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); 1736 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n");
1734 GNUNET_SCHEDULER_shutdown (); 1737 GNUNET_SCHEDULER_shutdown();
1735 return; 1738 return;
1736 } 1739 }
1737 GNUNET_assert (0 != entry->delta); 1740 GNUNET_assert(0 != entry->delta);
1738 1741
1739 num_peers_online += entry->delta; 1742 num_peers_online += entry->delta;
1740 1743
1741 if (PEER_GO_OFFLINE == entry->delta) 1744 if (PEER_GO_OFFLINE == entry->delta)
1742 { /* Peer hopefully just went offline */ 1745 { /* Peer hopefully just went offline */
1743 if (GNUNET_YES != rps_peers[entry->index].online) 1746 if (GNUNET_YES != rps_peers[entry->index].online)
1744 { 1747 {
1745 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1748 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1746 "peer %s was expected to go offline but is still marked as online\n", 1749 "peer %s was expected to go offline but is still marked as online\n",
1747 GNUNET_i2s (rps_peers[entry->index].peer_id)); 1750 GNUNET_i2s(rps_peers[entry->index].peer_id));
1748 GNUNET_break (0); 1751 GNUNET_break(0);
1749 } 1752 }
1750 else 1753 else
1751 { 1754 {
1752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1755 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1753 "peer %s probably went offline as expected\n", 1756 "peer %s probably went offline as expected\n",
1754 GNUNET_i2s (rps_peers[entry->index].peer_id)); 1757 GNUNET_i2s(rps_peers[entry->index].peer_id));
1758 }
1759 rps_peers[entry->index].online = GNUNET_NO;
1755 } 1760 }
1756 rps_peers[entry->index].online = GNUNET_NO;
1757 }
1758 1761
1759 else if (PEER_GO_ONLINE < entry->delta) 1762 else if (PEER_GO_ONLINE < entry->delta)
1760 { /* Peer hopefully just went online */ 1763 { /* Peer hopefully just went online */
1761 if (GNUNET_NO != rps_peers[entry->index].online) 1764 if (GNUNET_NO != rps_peers[entry->index].online)
1762 { 1765 {
1763 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1766 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1764 "peer %s was expected to go online but is still marked as offline\n", 1767 "peer %s was expected to go online but is still marked as offline\n",
1765 GNUNET_i2s (rps_peers[entry->index].peer_id)); 1768 GNUNET_i2s(rps_peers[entry->index].peer_id));
1766 GNUNET_break (0); 1769 GNUNET_break(0);
1767 } 1770 }
1768 else 1771 else
1769 { 1772 {
1770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1773 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1771 "peer %s probably went online as expected\n", 1774 "peer %s probably went online as expected\n",
1772 GNUNET_i2s (rps_peers[entry->index].peer_id)); 1775 GNUNET_i2s(rps_peers[entry->index].peer_id));
1773 if (NULL != cur_test_run.pre_test) 1776 if (NULL != cur_test_run.pre_test)
1774 { 1777 {
1775 cur_test_run.pre_test (&rps_peers[entry->index], 1778 cur_test_run.pre_test(&rps_peers[entry->index],
1776 rps_peers[entry->index].rps_handle); 1779 rps_peers[entry->index].rps_handle);
1777 schedule_missing_requests (&rps_peers[entry->index]); 1780 schedule_missing_requests(&rps_peers[entry->index]);
1778 } 1781 }
1779 } 1782 }
1780 rps_peers[entry->index].online = GNUNET_YES; 1783 rps_peers[entry->index].online = GNUNET_YES;
1781 } 1784 }
1782 else 1785 else
1783 { 1786 {
1784 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1787 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1785 "Invalid value for delta: %i\n", entry->delta); 1788 "Invalid value for delta: %i\n", entry->delta);
1786 GNUNET_break (0); 1789 GNUNET_break(0);
1787 } 1790 }
1788 1791
1789 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); 1792 GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry);
1790 rps_peers[entry->index].entry_op_manage = NULL; 1793 rps_peers[entry->index].entry_op_manage = NULL;
1791 GNUNET_free (entry); 1794 GNUNET_free(entry);
1792 //if (num_peers_in_round[current_round] == peers_running) 1795 //if (num_peers_in_round[current_round] == peers_running)
1793 // run_round (); 1796 // run_round ();
1794} 1797}
@@ -1802,52 +1805,52 @@ churn_cb (void *cls,
1802 * @param prob_go_on_off the probability of the action 1805 * @param prob_go_on_off the probability of the action
1803 */ 1806 */
1804static void 1807static void
1805manage_service_wrapper (unsigned int i, unsigned int j, 1808manage_service_wrapper(unsigned int i, unsigned int j,
1806 enum PEER_ONLINE_DELTA delta, 1809 enum PEER_ONLINE_DELTA delta,
1807 double prob_go_on_off) 1810 double prob_go_on_off)
1808{ 1811{
1809 struct OpListEntry *entry = NULL; 1812 struct OpListEntry *entry = NULL;
1810 uint32_t prob; 1813 uint32_t prob;
1811 1814
1812 /* make sure that management operation is not already scheduled */ 1815 /* make sure that management operation is not already scheduled */
1813 if (NULL != rps_peers[j].entry_op_manage) 1816 if (NULL != rps_peers[j].entry_op_manage)
1814 { 1817 {
1815 return; 1818 return;
1816 } 1819 }
1817 1820
1818 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1821 prob = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
1819 UINT32_MAX); 1822 UINT32_MAX);
1820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1823 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1821 "%u. selected peer (%u: %s) is %s.\n", 1824 "%u. selected peer (%u: %s) is %s.\n",
1822 i, 1825 i,
1823 j, 1826 j,
1824 GNUNET_i2s (rps_peers[j].peer_id), 1827 GNUNET_i2s(rps_peers[j].peer_id),
1825 (PEER_GO_ONLINE == delta) ? "online" : "offline"); 1828 (PEER_GO_ONLINE == delta) ? "online" : "offline");
1826 if (prob < prob_go_on_off * UINT32_MAX) 1829 if (prob < prob_go_on_off * UINT32_MAX)
1827 { 1830 {
1828 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1831 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1829 "%s goes %s\n", 1832 "%s goes %s\n",
1830 GNUNET_i2s (rps_peers[j].peer_id), 1833 GNUNET_i2s(rps_peers[j].peer_id),
1831 (PEER_GO_OFFLINE == delta) ? "offline" : "online"); 1834 (PEER_GO_OFFLINE == delta) ? "offline" : "online");
1832 1835
1833 if (PEER_GO_OFFLINE == delta) 1836 if (PEER_GO_OFFLINE == delta)
1834 cancel_pending_req_rep (&rps_peers[j]); 1837 cancel_pending_req_rep(&rps_peers[j]);
1835 entry = make_oplist_entry (); 1838 entry = make_oplist_entry();
1836 entry->delta = delta; 1839 entry->delta = delta;
1837 entry->index = j; 1840 entry->index = j;
1838 entry->op = GNUNET_TESTBED_peer_manage_service (NULL, 1841 entry->op = GNUNET_TESTBED_peer_manage_service(NULL,
1839 testbed_peers[j], 1842 testbed_peers[j],
1840 "rps", 1843 "rps",
1841 &churn_cb, 1844 &churn_cb,
1842 entry, 1845 entry,
1843 (PEER_GO_OFFLINE == delta) ? 0 : 1); 1846 (PEER_GO_OFFLINE == delta) ? 0 : 1);
1844 rps_peers[j].entry_op_manage = entry; 1847 rps_peers[j].entry_op_manage = entry;
1845 } 1848 }
1846} 1849}
1847 1850
1848 1851
1849static void 1852static void
1850churn (void *cls) 1853churn(void *cls)
1851{ 1854{
1852 unsigned int i; 1855 unsigned int i;
1853 unsigned int j; 1856 unsigned int j;
@@ -1856,74 +1859,75 @@ churn (void *cls)
1856 double prob_go_offline; 1859 double prob_go_offline;
1857 double portion_go_online; 1860 double portion_go_online;
1858 double portion_go_offline; 1861 double portion_go_offline;
1859 (void) cls; 1862
1863 (void)cls;
1860 1864
1861 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1865 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1862 { 1866 {
1863 return; 1867 return;
1864 } 1868 }
1865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1869 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1866 "Churn function executing\n"); 1870 "Churn function executing\n");
1867 1871
1868 churn_task = NULL; /* Should be invalid by now */ 1872 churn_task = NULL; /* Should be invalid by now */
1869 1873
1870 /* Compute the probability for an online peer to go offline 1874 /* Compute the probability for an online peer to go offline
1871 * this round */ 1875 * this round */
1872 portion_online = num_peers_online * 1.0 / num_peers; 1876 portion_online = num_peers_online * 1.0 / num_peers;
1873 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1877 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1874 "Portion online: %f\n", 1878 "Portion online: %f\n",
1875 portion_online); 1879 portion_online);
1876 portion_go_online = ((1 - portion_online) * .5 * .66); 1880 portion_go_online = ((1 - portion_online) * .5 * .66);
1877 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1881 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1878 "Portion that should go online: %f\n", 1882 "Portion that should go online: %f\n",
1879 portion_go_online); 1883 portion_go_online);
1880 portion_go_offline = (portion_online + portion_go_online) - .75; 1884 portion_go_offline = (portion_online + portion_go_online) - .75;
1881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1885 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1882 "Portion that probably goes offline: %f\n", 1886 "Portion that probably goes offline: %f\n",
1883 portion_go_offline); 1887 portion_go_offline);
1884 prob_go_offline = portion_go_offline / (portion_online * .5); 1888 prob_go_offline = portion_go_offline / (portion_online * .5);
1885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1889 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1886 "Probability of a selected online peer to go offline: %f\n", 1890 "Probability of a selected online peer to go offline: %f\n",
1887 prob_go_offline); 1891 prob_go_offline);
1888 1892
1889 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, 1893 permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK,
1890 (unsigned int) num_peers); 1894 (unsigned int)num_peers);
1891 1895
1892 /* Go over 50% randomly chosen peers */ 1896 /* Go over 50% randomly chosen peers */
1893 for (i = 0; i < .5 * num_peers; i++) 1897 for (i = 0; i < .5 * num_peers; i++)
1894 {
1895 j = permut[i];
1896
1897 /* If online, shut down with certain probability */
1898 if (GNUNET_YES == rps_peers[j].online)
1899 {
1900 manage_service_wrapper (i, j, -1, prob_go_offline);
1901 }
1902
1903 /* If offline, restart with certain probability */
1904 else if (GNUNET_NO == rps_peers[j].online)
1905 { 1898 {
1906 manage_service_wrapper (i, j, 1, 0.66); 1899 j = permut[i];
1900
1901 /* If online, shut down with certain probability */
1902 if (GNUNET_YES == rps_peers[j].online)
1903 {
1904 manage_service_wrapper(i, j, -1, prob_go_offline);
1905 }
1906
1907 /* If offline, restart with certain probability */
1908 else if (GNUNET_NO == rps_peers[j].online)
1909 {
1910 manage_service_wrapper(i, j, 1, 0.66);
1911 }
1907 } 1912 }
1908 }
1909 1913
1910 GNUNET_free (permut); 1914 GNUNET_free(permut);
1911 1915
1912 churn_task = GNUNET_SCHEDULER_add_delayed ( 1916 churn_task = GNUNET_SCHEDULER_add_delayed(
1913 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), 1917 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
1914 churn, 1918 churn,
1915 NULL); 1919 NULL);
1916} 1920}
1917 1921
1918 1922
1919/** 1923/**
1920 * Initialise given RPSPeer 1924 * Initialise given RPSPeer
1921 */ 1925 */
1922static void profiler_init_peer (struct RPSPeer *rps_peer) 1926static void profiler_init_peer(struct RPSPeer *rps_peer)
1923{ 1927{
1924 rps_peer->num_ids_to_request = cur_test_run.num_requests; 1928 rps_peer->num_ids_to_request = cur_test_run.num_requests;
1925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n", 1929 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n",
1926 rps_peer->num_ids_to_request); 1930 rps_peer->num_ids_to_request);
1927} 1931}
1928 1932
1929 1933
@@ -1935,7 +1939,7 @@ static void profiler_init_peer (struct RPSPeer *rps_peer)
1935 * @param recv_peers the received peers 1939 * @param recv_peers the received peers
1936 */ 1940 */
1937static void 1941static void
1938profiler_reply_handle (void *cls, 1942profiler_reply_handle(void *cls,
1939 uint64_t n, 1943 uint64_t n,
1940 const struct GNUNET_PeerIdentity *recv_peers) 1944 const struct GNUNET_PeerIdentity *recv_peers)
1941{ 1945{
@@ -1950,53 +1954,53 @@ profiler_reply_handle (void *cls,
1950 char *file_name_dhr = file_name_dhr_buf; 1954 char *file_name_dhr = file_name_dhr_buf;
1951 char *file_name_dhru = file_name_dhru_buf; 1955 char *file_name_dhru = file_name_dhru_buf;
1952 unsigned int i; 1956 unsigned int i;
1953 struct PendingReply *pending_rep = (struct PendingReply *) cls; 1957 struct PendingReply *pending_rep = (struct PendingReply *)cls;
1954 1958
1955 pending_rep->req_handle = NULL; 1959 pending_rep->req_handle = NULL;
1956 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); 1960 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n");
1957 rps_peer = pending_rep->rps_peer; 1961 rps_peer = pending_rep->rps_peer;
1958 (void) GNUNET_asprintf (&file_name, 1962 (void)GNUNET_asprintf(&file_name,
1959 "/tmp/rps/received_ids-%u", 1963 "/tmp/rps/received_ids-%u",
1960 rps_peer->index); 1964 rps_peer->index);
1961 1965
1962 (void) GNUNET_asprintf (&file_name_dh, 1966 (void)GNUNET_asprintf(&file_name_dh,
1963 "/tmp/rps/diehard_input-%u", 1967 "/tmp/rps/diehard_input-%u",
1964 rps_peer->index); 1968 rps_peer->index);
1965 (void) GNUNET_asprintf (&file_name_dhr, 1969 (void)GNUNET_asprintf(&file_name_dhr,
1966 "/tmp/rps/diehard_input_raw-%u", 1970 "/tmp/rps/diehard_input_raw-%u",
1967 rps_peer->index); 1971 rps_peer->index);
1968 (void) GNUNET_asprintf (&file_name_dhru, 1972 (void)GNUNET_asprintf(&file_name_dhru,
1969 "/tmp/rps/diehard_input_raw_aligned-%u", 1973 "/tmp/rps/diehard_input_raw_aligned-%u",
1970 rps_peer->index); 1974 rps_peer->index);
1971 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1975 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1972 "[%s] got %" PRIu64 " peers:\n", 1976 "[%s] got %" PRIu64 " peers:\n",
1973 GNUNET_i2s (rps_peer->peer_id), 1977 GNUNET_i2s(rps_peer->peer_id),
1974 n); 1978 n);
1975 for (i = 0; i < n; i++) 1979 for (i = 0; i < n; i++)
1976 { 1980 {
1977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1981 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1978 "%u: %s\n", 1982 "%u: %s\n",
1979 i, 1983 i,
1980 GNUNET_i2s (&recv_peers[i])); 1984 GNUNET_i2s(&recv_peers[i]));
1981 tofile (file_name, 1985 tofile(file_name,
1982 "%s\n", 1986 "%s\n",
1983 GNUNET_i2s_full (&recv_peers[i])); 1987 GNUNET_i2s_full(&recv_peers[i]));
1984 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]); 1988 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get(peer_map, &recv_peers[i]);
1985 GNUNET_assert (NULL != rcv_rps_peer); 1989 GNUNET_assert(NULL != rcv_rps_peer);
1986 tofile (file_name_dh, 1990 tofile(file_name_dh,
1987 "%" PRIu32 "\n", 1991 "%" PRIu32 "\n",
1988 (uint32_t) rcv_rps_peer->index); 1992 (uint32_t)rcv_rps_peer->index);
1989#ifdef TO_FILE 1993#ifdef TO_FILE
1990 to_file_raw (file_name_dhr, 1994 to_file_raw(file_name_dhr,
1991 (char *) &rcv_rps_peer->index, 1995 (char *)&rcv_rps_peer->index,
1992 sizeof (uint32_t)); 1996 sizeof(uint32_t));
1993 to_file_raw_unaligned (file_name_dhru, 1997 to_file_raw_unaligned(file_name_dhru,
1994 (char *) &rcv_rps_peer->index, 1998 (char *)&rcv_rps_peer->index,
1995 sizeof (uint32_t), 1999 sizeof(uint32_t),
1996 bits_needed); 2000 bits_needed);
1997#endif /* TO_FILE */ 2001#endif /* TO_FILE */
1998 } 2002 }
1999 default_reply_handle (cls, n, recv_peers); 2003 default_reply_handle(cls, n, recv_peers);
2000} 2004}
2001 2005
2002 2006
@@ -2008,10 +2012,10 @@ profiler_reply_handle (void *cls,
2008 * @param recv_peers the received peers 2012 * @param recv_peers the received peers
2009 */ 2013 */
2010static void 2014static void
2011profiler_reply_handle_info (void *cls, 2015profiler_reply_handle_info(void *cls,
2012 const struct GNUNET_PeerIdentity *recv_peer, 2016 const struct GNUNET_PeerIdentity *recv_peer,
2013 double probability, 2017 double probability,
2014 uint32_t num_observed) 2018 uint32_t num_observed)
2015{ 2019{
2016 struct RPSPeer *rps_peer; 2020 struct RPSPeer *rps_peer;
2017 struct RPSPeer *rcv_rps_peer; 2021 struct RPSPeer *rcv_rps_peer;
@@ -2024,80 +2028,82 @@ profiler_reply_handle_info (void *cls,
2024 char *file_name_dhr = file_name_dhr_buf; 2028 char *file_name_dhr = file_name_dhr_buf;
2025 char *file_name_dhru = file_name_dhru_buf; 2029 char *file_name_dhru = file_name_dhru_buf;
2026 unsigned int i; 2030 unsigned int i;
2027 struct PendingReply *pending_rep = (struct PendingReply *) cls; 2031 struct PendingReply *pending_rep = (struct PendingReply *)cls;
2028 2032
2029 pending_rep->req_handle = NULL; 2033 pending_rep->req_handle = NULL;
2030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); 2034 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n");
2031 rps_peer = pending_rep->rps_peer; 2035 rps_peer = pending_rep->rps_peer;
2032 (void) GNUNET_asprintf (&file_name, 2036 (void)GNUNET_asprintf(&file_name,
2033 "/tmp/rps/received_ids-%u", 2037 "/tmp/rps/received_ids-%u",
2034 rps_peer->index); 2038 rps_peer->index);
2035 2039
2036 (void) GNUNET_asprintf (&file_name_dh, 2040 (void)GNUNET_asprintf(&file_name_dh,
2037 "/tmp/rps/diehard_input-%u", 2041 "/tmp/rps/diehard_input-%u",
2038 rps_peer->index); 2042 rps_peer->index);
2039 (void) GNUNET_asprintf (&file_name_dhr, 2043 (void)GNUNET_asprintf(&file_name_dhr,
2040 "/tmp/rps/diehard_input_raw-%u", 2044 "/tmp/rps/diehard_input_raw-%u",
2041 rps_peer->index); 2045 rps_peer->index);
2042 (void) GNUNET_asprintf (&file_name_dhru, 2046 (void)GNUNET_asprintf(&file_name_dhru,
2043 "/tmp/rps/diehard_input_raw_aligned-%u", 2047 "/tmp/rps/diehard_input_raw_aligned-%u",
2044 rps_peer->index); 2048 rps_peer->index);
2045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2049 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2046 "[%s] got peer with info:\n", 2050 "[%s] got peer with info:\n",
2047 GNUNET_i2s (rps_peer->peer_id)); 2051 GNUNET_i2s(rps_peer->peer_id));
2048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2052 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2049 " %s\n", 2053 " %s\n",
2050 GNUNET_i2s (recv_peer)); 2054 GNUNET_i2s(recv_peer));
2051 tofile (file_name, 2055 tofile(file_name,
2052 "%s %d %" PRIu32 " \n", 2056 "%s %d %" PRIu32 " \n",
2053 GNUNET_i2s_full (recv_peer), 2057 GNUNET_i2s_full(recv_peer),
2054 probability, 2058 probability,
2055 num_observed); 2059 num_observed);
2056 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, recv_peer); 2060 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get(peer_map, recv_peer);
2057 GNUNET_assert (NULL != rcv_rps_peer); 2061 GNUNET_assert(NULL != rcv_rps_peer);
2058 tofile (file_name_dh, 2062 tofile(file_name_dh,
2059 "%" PRIu32 "\n", 2063 "%" PRIu32 "\n",
2060 (uint32_t) rcv_rps_peer->index); 2064 (uint32_t)rcv_rps_peer->index);
2061#ifdef TO_FILE 2065#ifdef TO_FILE
2062 to_file_raw (file_name_dhr, 2066 to_file_raw(file_name_dhr,
2063 (char *) &rcv_rps_peer->index, 2067 (char *)&rcv_rps_peer->index,
2064 sizeof (uint32_t)); 2068 sizeof(uint32_t));
2065 to_file_raw_unaligned (file_name_dhru, 2069 to_file_raw_unaligned(file_name_dhru,
2066 (char *) &rcv_rps_peer->index, 2070 (char *)&rcv_rps_peer->index,
2067 sizeof (uint32_t), 2071 sizeof(uint32_t),
2068 bits_needed); 2072 bits_needed);
2069#endif /* TO_FILE */ 2073#endif /* TO_FILE */
2070 default_reply_handle (cls, 1, recv_peer); 2074 default_reply_handle(cls, 1, recv_peer);
2071} 2075}
2072 2076
2073 2077
2074static void 2078static void
2075profiler_cb (struct RPSPeer *rps_peer) 2079profiler_cb(struct RPSPeer *rps_peer)
2076{ 2080{
2077 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 2081 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
2078 { 2082 {
2079 return; 2083 return;
2080 } 2084 }
2081 2085
2082 /* Start churn */ 2086 /* Start churn */
2083 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) 2087 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task)
2084 { 2088 {
2085 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2089 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2086 "Starting churn task\n"); 2090 "Starting churn task\n");
2087 churn_task = GNUNET_SCHEDULER_add_delayed ( 2091 churn_task = GNUNET_SCHEDULER_add_delayed(
2088 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), 2092 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
2089 churn, 2093 churn,
2090 NULL); 2094 NULL);
2091 } else { 2095 }
2092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2096 else
2093 "Not starting churn task\n"); 2097 {
2094 } 2098 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2099 "Not starting churn task\n");
2100 }
2095 2101
2096 /* Only request peer ids at one peer. 2102 /* Only request peer ids at one peer.
2097 * (It's the before-last because last one is target of the focussed attack.) 2103 * (It's the before-last because last one is target of the focussed attack.)
2098 */ 2104 */
2099 if (0 < rps_peer->num_ids_to_request) 2105 if (0 < rps_peer->num_ids_to_request)
2100 schedule_missing_requests (rps_peer); 2106 schedule_missing_requests(rps_peer);
2101} 2107}
2102 2108
2103/** 2109/**
@@ -2110,29 +2116,29 @@ profiler_cb (struct RPSPeer *rps_peer)
2110 * #GNUNET_SYSERR to abort iteration with error! 2116 * #GNUNET_SYSERR to abort iteration with error!
2111 */ 2117 */
2112static int 2118static int
2113file_name_cb (void *cls, const char *filename) 2119file_name_cb(void *cls, const char *filename)
2114{ 2120{
2115 if (NULL != strstr (filename, "sampler_el")) 2121 if (NULL != strstr(filename, "sampler_el"))
2116 {
2117 struct RPS_SamplerElement *s_elem;
2118 struct GNUNET_CRYPTO_AuthKey auth_key;
2119 const char *key_char;
2120 uint32_t i;
2121 (void) cls;
2122
2123 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
2124 tofile (filename, "--------------------------\n");
2125
2126 auth_key = string_to_auth_key (key_char);
2127 s_elem = RPS_sampler_elem_create ();
2128 RPS_sampler_elem_set (s_elem, auth_key);
2129
2130 for (i = 0; i < num_peers; i++)
2131 { 2122 {
2132 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]); 2123 struct RPS_SamplerElement *s_elem;
2124 struct GNUNET_CRYPTO_AuthKey auth_key;
2125 const char *key_char;
2126 uint32_t i;
2127 (void)cls;
2128
2129 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
2130 tofile(filename, "--------------------------\n");
2131
2132 auth_key = string_to_auth_key(key_char);
2133 s_elem = RPS_sampler_elem_create();
2134 RPS_sampler_elem_set(s_elem, auth_key);
2135
2136 for (i = 0; i < num_peers; i++)
2137 {
2138 RPS_sampler_elem_next(s_elem, &rps_peer_ids[i]);
2139 }
2140 RPS_sampler_elem_destroy(s_elem);
2133 } 2141 }
2134 RPS_sampler_elem_destroy (s_elem);
2135 }
2136 return GNUNET_OK; 2142 return GNUNET_OK;
2137} 2143}
2138 2144
@@ -2142,17 +2148,17 @@ file_name_cb (void *cls, const char *filename)
2142 * Compute all perfect samples. 2148 * Compute all perfect samples.
2143 */ 2149 */
2144static int 2150static int
2145profiler_eval (void) 2151profiler_eval(void)
2146{ 2152{
2147#ifdef TO_FILE 2153#ifdef TO_FILE
2148 /* Compute perfect sample for each sampler element */ 2154 /* Compute perfect sample for each sampler element */
2149 if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL)) 2155 if (-1 == GNUNET_DISK_directory_scan("/tmp/rps/", file_name_cb, NULL))
2150 { 2156 {
2151 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); 2157 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
2152 } 2158 }
2153#endif /* TO_FILE */ 2159#endif /* TO_FILE */
2154 2160
2155 return evaluate (); 2161 return evaluate();
2156} 2162}
2157 2163
2158 2164
@@ -2163,39 +2169,40 @@ profiler_eval (void)
2163 * 2169 *
2164 * @return 2170 * @return
2165 */ 2171 */
2166static int is_in_view (uint32_t a, uint32_t b) 2172static int is_in_view(uint32_t a, uint32_t b)
2167{ 2173{
2168 uint32_t i; 2174 uint32_t i;
2175
2169 for (i = 0; i < rps_peers[a].cur_view_count; i++) 2176 for (i = 0; i < rps_peers[a].cur_view_count; i++)
2170 {
2171 if (0 == memcmp (rps_peers[b].peer_id,
2172 &rps_peers[a].cur_view[i],
2173 sizeof (struct GNUNET_PeerIdentity)))
2174 { 2177 {
2175 return GNUNET_YES; 2178 if (0 == memcmp(rps_peers[b].peer_id,
2179 &rps_peers[a].cur_view[i],
2180 sizeof(struct GNUNET_PeerIdentity)))
2181 {
2182 return GNUNET_YES;
2183 }
2176 } 2184 }
2177 }
2178 return GNUNET_NO; 2185 return GNUNET_NO;
2179} 2186}
2180 2187
2181static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid) 2188static uint32_t get_idx_of_pid(const struct GNUNET_PeerIdentity *pid)
2182{ 2189{
2183 uint32_t i; 2190 uint32_t i;
2184 2191
2185 for (i = 0; i < num_peers; i++) 2192 for (i = 0; i < num_peers; i++)
2186 {
2187 if (0 == memcmp (pid,
2188 rps_peers[i].peer_id,
2189 sizeof (struct GNUNET_PeerIdentity)))
2190 { 2193 {
2191 return i; 2194 if (0 == memcmp(pid,
2195 rps_peers[i].peer_id,
2196 sizeof(struct GNUNET_PeerIdentity)))
2197 {
2198 return i;
2199 }
2192 } 2200 }
2193 }
2194 //return 0; /* Should not happen - make compiler happy */ 2201 //return 0; /* Should not happen - make compiler happy */
2195 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2202 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2196 "No known _PeerIdentity %s!\n", 2203 "No known _PeerIdentity %s!\n",
2197 GNUNET_i2s_full (pid)); 2204 GNUNET_i2s_full(pid));
2198 GNUNET_assert (0); 2205 GNUNET_assert(0);
2199} 2206}
2200 2207
2201/** 2208/**
@@ -2206,20 +2213,20 @@ static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid)
2206 * 2213 *
2207 * @return 2214 * @return
2208 */ 2215 */
2209static uint32_t count_containing_views (uint32_t a, uint32_t b) 2216static uint32_t count_containing_views(uint32_t a, uint32_t b)
2210{ 2217{
2211 uint32_t i; 2218 uint32_t i;
2212 uint32_t peer_idx; 2219 uint32_t peer_idx;
2213 uint32_t count = 0; 2220 uint32_t count = 0;
2214 2221
2215 for (i = 0; i < rps_peers[a].cur_view_count; i++) 2222 for (i = 0; i < rps_peers[a].cur_view_count; i++)
2216 {
2217 peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]);
2218 if (GNUNET_YES == is_in_view (peer_idx, b))
2219 { 2223 {
2220 count++; 2224 peer_idx = get_idx_of_pid(&rps_peers[a].cur_view[i]);
2225 if (GNUNET_YES == is_in_view(peer_idx, b))
2226 {
2227 count++;
2228 }
2221 } 2229 }
2222 }
2223 return count; 2230 return count;
2224} 2231}
2225 2232
@@ -2229,13 +2236,13 @@ static uint32_t count_containing_views (uint32_t a, uint32_t b)
2229 * 2236 *
2230 * @param peer_idx index of the peer that is about to sample 2237 * @param peer_idx index of the peer that is about to sample
2231 */ 2238 */
2232static void compute_probabilities (uint32_t peer_idx) 2239static void compute_probabilities(uint32_t peer_idx)
2233{ 2240{
2234 //double probs[num_peers] = { 0 }; 2241 //double probs[num_peers] = { 0 };
2235 double probs[num_peers]; 2242 double probs[num_peers];
2236 double probs_hist[num_peers]; /* Probability respecting the history */ 2243 double probs_hist[num_peers]; /* Probability respecting the history */
2237 size_t probs_as_str_size = (num_peers * 10 + 2) * sizeof (char); 2244 size_t probs_as_str_size = (num_peers * 10 + 2) * sizeof(char);
2238 char *probs_as_str = GNUNET_malloc (probs_as_str_size); 2245 char *probs_as_str = GNUNET_malloc(probs_as_str_size);
2239 char *probs_as_str_cpy; 2246 char *probs_as_str_cpy;
2240 uint32_t i; 2247 uint32_t i;
2241 double prob_push; 2248 double prob_push;
@@ -2247,139 +2254,143 @@ static void compute_probabilities (uint32_t peer_idx)
2247 double sum_non_zero_prob = 0; 2254 double sum_non_zero_prob = 0;
2248 double sum_non_zero_prob_hist = 0; 2255 double sum_non_zero_prob_hist = 0;
2249 2256
2250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2257 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2251 "Computing probabilities for peer %" PRIu32 "\n", peer_idx); 2258 "Computing probabilities for peer %" PRIu32 "\n", peer_idx);
2252 /* Firstly without knowledge of old views */ 2259 /* Firstly without knowledge of old views */
2253 for (i = 0; i < num_peers; i++) 2260 for (i = 0; i < num_peers; i++)
2254 { 2261 {
2255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2262 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2256 "\tfor peer %" PRIu32 ":\n", i); 2263 "\tfor peer %" PRIu32 ":\n", i);
2257 view_size = rps_peers[i].cur_view_count; 2264 view_size = rps_peers[i].cur_view_count;
2258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2265 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2259 "\t\tview_size: %" PRIu32 "\n", view_size); 2266 "\t\tview_size: %" PRIu32 "\n", view_size);
2260 /* For peer i the probability of being sampled is 2267 /* For peer i the probability of being sampled is
2261 * evenly distributed among all possibly observed peers. */ 2268 * evenly distributed among all possibly observed peers. */
2262 /* We could have observed a peer in three cases: 2269 /* We could have observed a peer in three cases:
2263 * 1. peer sent a push 2270 * 1. peer sent a push
2264 * 2. peer was contained in a pull reply 2271 * 2. peer was contained in a pull reply
2265 * 3. peer was in history (sampler) - ignored for now */ 2272 * 3. peer was in history (sampler) - ignored for now */
2266 /* 1. Probability of having received a push from peer i */ 2273 /* 1. Probability of having received a push from peer i */
2267 if ((GNUNET_YES == is_in_view (i, peer_idx)) && 2274 if ((GNUNET_YES == is_in_view(i, peer_idx)) &&
2268 (1 <= (0.45 * view_size))) 2275 (1 <= (0.45 * view_size)))
2269 { 2276 {
2270 if (0 == binom (view_size, 0.45 * view_size)) prob_push = 0; 2277 if (0 == binom(view_size, 0.45 * view_size))
2278 prob_push = 0;
2279 else
2280 {
2281 prob_push = 1.0 * binom(0.45 * view_size, 1)
2282 /
2283 binom(view_size, 0.45 * view_size);
2284 }
2285 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2286 "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n",
2287 peer_idx,
2288 i,
2289 prob_push);
2290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2291 "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n",
2292 binom(view_size, 0.45 * view_size),
2293 binom(0.45 * view_size, 1));
2294 }
2295 else
2296 {
2297 prob_push = 0;
2298 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2299 "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n",
2300 peer_idx,
2301 i);
2302 }
2303 /* 2. Probability of peer i being contained in pulls */
2304 view_size = rps_peers[peer_idx].cur_view_count;
2305 cont_views = count_containing_views(peer_idx, i);
2306 number_of_being_in_pull_events =
2307 (binom(view_size, 0.45 * view_size) -
2308 binom(view_size - cont_views, 0.45 * view_size));
2309 if (0 != number_of_being_in_pull_events)
2310 {
2311 prob_pull = number_of_being_in_pull_events
2312 /
2313 (1.0 * binom(view_size, 0.45 * view_size));
2314 }
2271 else 2315 else
2272 { 2316 {
2273 prob_push = 1.0 * binom (0.45 * view_size, 1) 2317 prob_pull = 0;
2274 / 2318 }
2275 binom (view_size, 0.45 * view_size); 2319 probs[i] = prob_push + prob_pull - (prob_push * prob_pull);
2276 } 2320 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2321 "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32
2278 "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", 2322 " peers in its view who know %" PRIu32 " prob: %f\n",
2279 peer_idx, 2323 peer_idx,
2324 cont_views,
2325 view_size,
2280 i, 2326 i,
2281 prob_push); 2327 prob_pull);
2282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2328 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2283 "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n", 2329 "\t\tnumber of possible pull combinations: %" PRIu32 "\n",
2284 binom (view_size, 0.45 * view_size), 2330 binom(view_size, 0.45 * view_size));
2285 binom (0.45 * view_size, 1)); 2331 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2286 } else { 2332 "\t\tnumber of possible pull combinations without %" PRIu32
2287 prob_push = 0; 2333 ": %" PRIu32 "\n",
2288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2334 i,
2289 "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", 2335 binom(view_size - cont_views, 0.45 * view_size));
2290 peer_idx, 2336 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2291 i); 2337 "\t\tnumber of possible pull combinations with %" PRIu32
2292 } 2338 ": %" PRIu32 "\n",
2293 /* 2. Probability of peer i being contained in pulls */ 2339 i,
2294 view_size = rps_peers[peer_idx].cur_view_count; 2340 number_of_being_in_pull_events);
2295 cont_views = count_containing_views (peer_idx, i);
2296 number_of_being_in_pull_events =
2297 (binom (view_size, 0.45 * view_size) -
2298 binom (view_size - cont_views, 0.45 * view_size));
2299 if (0 != number_of_being_in_pull_events)
2300 {
2301 prob_pull = number_of_being_in_pull_events
2302 /
2303 (1.0 * binom (view_size, 0.45 * view_size));
2304 } else
2305 {
2306 prob_pull = 0;
2307 }
2308 probs[i] = prob_push + prob_pull - (prob_push * prob_pull);
2309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2310 "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32
2311 " peers in its view who know %" PRIu32 " prob: %f\n",
2312 peer_idx,
2313 cont_views,
2314 view_size,
2315 i,
2316 prob_pull);
2317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2318 "\t\tnumber of possible pull combinations: %" PRIu32 "\n",
2319 binom (view_size, 0.45 * view_size));
2320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2321 "\t\tnumber of possible pull combinations without %" PRIu32
2322 ": %" PRIu32 "\n",
2323 i,
2324 binom (view_size - cont_views, 0.45 * view_size));
2325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2326 "\t\tnumber of possible pull combinations with %" PRIu32
2327 ": %" PRIu32 "\n",
2328 i,
2329 number_of_being_in_pull_events);
2330 2341
2331 probs_hist[i] = 0.9 * rps_peers[peer_idx].eval_probs_cache[i] + probs[i]; 2342 probs_hist[i] = 0.9 * rps_peers[peer_idx].eval_probs_cache[i] + probs[i];
2332 rps_peers[peer_idx].eval_probs_cache[i] = probs_hist[i]; 2343 rps_peers[peer_idx].eval_probs_cache[i] = probs_hist[i];
2333 2344
2334 sum_non_zero_prob += probs[i]; 2345 sum_non_zero_prob += probs[i];
2335 sum_non_zero_prob_hist += probs_hist[i]; 2346 sum_non_zero_prob_hist += probs_hist[i];
2336 } 2347 }
2337 /* normalize */ 2348 /* normalize */
2338 if (0 != sum_non_zero_prob) 2349 if (0 != sum_non_zero_prob)
2339 {
2340 for (i = 0; i < num_peers; i++)
2341 { 2350 {
2342 probs[i] = probs[i] * (1.0 / sum_non_zero_prob); 2351 for (i = 0; i < num_peers; i++)
2352 {
2353 probs[i] = probs[i] * (1.0 / sum_non_zero_prob);
2354 }
2343 } 2355 }
2344 }
2345 if (0 != sum_non_zero_prob_hist) 2356 if (0 != sum_non_zero_prob_hist)
2346 {
2347 for (i = 0; i < num_peers; i++)
2348 { 2357 {
2349 probs_hist[i] = probs_hist[i] * (1.0 / sum_non_zero_prob_hist); 2358 for (i = 0; i < num_peers; i++)
2359 {
2360 probs_hist[i] = probs_hist[i] * (1.0 / sum_non_zero_prob_hist);
2361 }
2350 } 2362 }
2351 }
2352 2363
2353 /* str repr */ 2364 /* str repr */
2354 for (i = 0; i < num_peers; i++) 2365 for (i = 0; i < num_peers; i++)
2355 { 2366 {
2356 probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); 2367 probs_as_str_cpy = GNUNET_strndup(probs_as_str, probs_as_str_size);
2357 tmp = GNUNET_snprintf (probs_as_str, 2368 tmp = GNUNET_snprintf(probs_as_str,
2358 probs_as_str_size, 2369 probs_as_str_size,
2359 "%s %7.6f", probs_as_str_cpy, probs[i]); 2370 "%s %7.6f", probs_as_str_cpy, probs[i]);
2360 GNUNET_free (probs_as_str_cpy); 2371 GNUNET_free(probs_as_str_cpy);
2361 GNUNET_assert (0 <= tmp); 2372 GNUNET_assert(0 <= tmp);
2362 } 2373 }
2363 2374
2364 to_file_w_len (rps_peers[peer_idx].file_name_probs, 2375 to_file_w_len(rps_peers[peer_idx].file_name_probs,
2365 probs_as_str_size, 2376 probs_as_str_size,
2366 probs_as_str); 2377 probs_as_str);
2367 2378
2368 probs_as_str[0] = '\0'; 2379 probs_as_str[0] = '\0';
2369 for (i = 0; i < num_peers; i++) 2380 for (i = 0; i < num_peers; i++)
2370 { 2381 {
2371 probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); 2382 probs_as_str_cpy = GNUNET_strndup(probs_as_str, probs_as_str_size);
2372 tmp = GNUNET_snprintf (probs_as_str, 2383 tmp = GNUNET_snprintf(probs_as_str,
2373 probs_as_str_size, 2384 probs_as_str_size,
2374 "%s %7.6f", probs_as_str_cpy, probs_hist[i]); 2385 "%s %7.6f", probs_as_str_cpy, probs_hist[i]);
2375 GNUNET_free (probs_as_str_cpy); 2386 GNUNET_free(probs_as_str_cpy);
2376 GNUNET_assert (0 <= tmp); 2387 GNUNET_assert(0 <= tmp);
2377 } 2388 }
2378 2389
2379 to_file_w_len (rps_peers[peer_idx].file_name_probs_hist, 2390 to_file_w_len(rps_peers[peer_idx].file_name_probs_hist,
2380 probs_as_str_size, 2391 probs_as_str_size,
2381 probs_as_str); 2392 probs_as_str);
2382 GNUNET_free (probs_as_str); 2393 GNUNET_free(probs_as_str);
2383} 2394}
2384 2395
2385/** 2396/**
@@ -2391,98 +2402,98 @@ static void compute_probabilities (uint32_t peer_idx)
2391 * 2402 *
2392 * @return the number of occurrences 2403 * @return the number of occurrences
2393 */ 2404 */
2394static uint32_t count_peer_in_views_2 (uint32_t peer_idx) 2405static uint32_t count_peer_in_views_2(uint32_t peer_idx)
2395{ 2406{
2396 uint32_t i, j; 2407 uint32_t i, j;
2397 uint32_t count = 0; 2408 uint32_t count = 0;
2398 2409
2399 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ 2410 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2400 { 2411 {
2401 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ 2412 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2402 { 2413 {
2403 if (0 == memcmp (rps_peers[peer_idx].peer_id, 2414 if (0 == memcmp(rps_peers[peer_idx].peer_id,
2404 &rps_peers[i].cur_view[j], 2415 &rps_peers[i].cur_view[j],
2405 sizeof (struct GNUNET_PeerIdentity))) 2416 sizeof(struct GNUNET_PeerIdentity)))
2406 { 2417 {
2407 count++; 2418 count++;
2408 break; 2419 break;
2409 } 2420 }
2410 } 2421 }
2411 } 2422 }
2412 rps_peers[peer_idx].count_in_views = count; 2423 rps_peers[peer_idx].count_in_views = count;
2413 return count; 2424 return count;
2414} 2425}
2415 2426
2416static uint32_t cumulated_view_sizes () 2427static uint32_t cumulated_view_sizes()
2417{ 2428{
2418 uint32_t i; 2429 uint32_t i;
2419 2430
2420 view_sizes = 0; 2431 view_sizes = 0;
2421 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ 2432 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2422 { 2433 {
2423 view_sizes += rps_peers[i].cur_view_count; 2434 view_sizes += rps_peers[i].cur_view_count;
2424 } 2435 }
2425 return view_sizes; 2436 return view_sizes;
2426} 2437}
2427 2438
2428static void count_peer_in_views (uint32_t *count_peers) 2439static void count_peer_in_views(uint32_t *count_peers)
2429{ 2440{
2430 uint32_t i, j; 2441 uint32_t i, j;
2431 2442
2432 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ 2443 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2433 {
2434 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2435 { 2444 {
2436 if (0 == memcmp (rps_peers[i].peer_id, 2445 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2437 &rps_peers[i].cur_view[j], 2446 {
2438 sizeof (struct GNUNET_PeerIdentity))) 2447 if (0 == memcmp(rps_peers[i].peer_id,
2439 { 2448 &rps_peers[i].cur_view[j],
2440 count_peers[i]++; 2449 sizeof(struct GNUNET_PeerIdentity)))
2441 } 2450 {
2451 count_peers[i]++;
2452 }
2453 }
2442 } 2454 }
2443 }
2444} 2455}
2445 2456
2446void compute_diversity () 2457void compute_diversity()
2447{ 2458{
2448 uint32_t i; 2459 uint32_t i;
2449 /* ith entry represents the numer of occurrences in other peer's views */ 2460 /* ith entry represents the numer of occurrences in other peer's views */
2450 uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t); 2461 uint32_t *count_peers = GNUNET_new_array(num_peers, uint32_t);
2451 uint32_t views_total_size; 2462 uint32_t views_total_size;
2452 double expected; 2463 double expected;
2453 /* deviation from expected number of peers */ 2464 /* deviation from expected number of peers */
2454 double *deviation = GNUNET_new_array (num_peers, double); 2465 double *deviation = GNUNET_new_array(num_peers, double);
2455 2466
2456 views_total_size = 0; 2467 views_total_size = 0;
2457 expected = 0; 2468 expected = 0;
2458 2469
2459 /* For each peer count its representation in other peer's views*/ 2470 /* For each peer count its representation in other peer's views*/
2460 for (i = 0; i < num_peers; i++) /* Peer to count */ 2471 for (i = 0; i < num_peers; i++) /* Peer to count */
2461 { 2472 {
2462 views_total_size += rps_peers[i].cur_view_count; 2473 views_total_size += rps_peers[i].cur_view_count;
2463 count_peer_in_views (count_peers); 2474 count_peer_in_views(count_peers);
2464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2475 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2465 "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32"\n", 2476 "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32 "\n",
2466 i, 2477 i,
2467 GNUNET_i2s (rps_peers[i].peer_id), 2478 GNUNET_i2s(rps_peers[i].peer_id),
2468 count_peers[i]); 2479 count_peers[i]);
2469 } 2480 }
2470 2481
2471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2482 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2472 "size of all views combined: %" PRIu32 "\n", 2483 "size of all views combined: %" PRIu32 "\n",
2473 views_total_size); 2484 views_total_size);
2474 expected = ((double) 1/num_peers) * views_total_size; 2485 expected = ((double)1 / num_peers) * views_total_size;
2475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2486 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2476 "Expected number of occurrences of each peer in all views: %f\n", 2487 "Expected number of occurrences of each peer in all views: %f\n",
2477 expected); 2488 expected);
2478 for (i = 0; i < num_peers; i++) /* Peer to count */ 2489 for (i = 0; i < num_peers; i++) /* Peer to count */
2479 { 2490 {
2480 deviation[i] = expected - count_peers[i]; 2491 deviation[i] = expected - count_peers[i];
2481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2492 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2482 "Deviation from expectation: %f\n", deviation[i]); 2493 "Deviation from expectation: %f\n", deviation[i]);
2483 } 2494 }
2484 GNUNET_free (count_peers); 2495 GNUNET_free(count_peers);
2485 GNUNET_free (deviation); 2496 GNUNET_free(deviation);
2486} 2497}
2487 2498
2488void print_view_sizes() 2499void print_view_sizes()
@@ -2490,13 +2501,13 @@ void print_view_sizes()
2490 uint32_t i; 2501 uint32_t i;
2491 2502
2492 for (i = 0; i < num_peers; i++) /* Peer to count */ 2503 for (i = 0; i < num_peers; i++) /* Peer to count */
2493 { 2504 {
2494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2505 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2495 "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n", 2506 "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n",
2496 i, 2507 i,
2497 GNUNET_i2s (rps_peers[i].peer_id), 2508 GNUNET_i2s(rps_peers[i].peer_id),
2498 rps_peers[i].cur_view_count); 2509 rps_peers[i].cur_view_count);
2499 } 2510 }
2500} 2511}
2501 2512
2502void all_views_updated_cb() 2513void all_views_updated_cb()
@@ -2505,180 +2516,181 @@ void all_views_updated_cb()
2505 print_view_sizes(); 2516 print_view_sizes();
2506} 2517}
2507 2518
2508void view_update_cb (void *cls, 2519void view_update_cb(void *cls,
2509 uint64_t view_size, 2520 uint64_t view_size,
2510 const struct GNUNET_PeerIdentity *peers) 2521 const struct GNUNET_PeerIdentity *peers)
2511{ 2522{
2512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2523 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2513 "View was updated (%" PRIu64 ")\n", view_size); 2524 "View was updated (%" PRIu64 ")\n", view_size);
2514 struct RPSPeer *rps_peer = (struct RPSPeer *) cls; 2525 struct RPSPeer *rps_peer = (struct RPSPeer *)cls;
2515 to_file ("/tmp/rps/view_sizes.txt", 2526 to_file("/tmp/rps/view_sizes.txt",
2516 "%" PRIu64 " %" PRIu32 "", 2527 "%" PRIu64 " %" PRIu32 "",
2517 rps_peer->index, 2528 rps_peer->index,
2518 view_size); 2529 view_size);
2519 for (uint64_t i = 0; i < view_size; i++) 2530 for (uint64_t i = 0; i < view_size; i++)
2520 { 2531 {
2521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2532 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2522 "\t%s\n", GNUNET_i2s (&peers[i])); 2533 "\t%s\n", GNUNET_i2s(&peers[i]));
2523 } 2534 }
2524 GNUNET_array_grow (rps_peer->cur_view, 2535 GNUNET_array_grow(rps_peer->cur_view,
2525 rps_peer->cur_view_count, 2536 rps_peer->cur_view_count,
2526 view_size); 2537 view_size);
2527 //*rps_peer->cur_view = *peers; 2538 //*rps_peer->cur_view = *peers;
2528 GNUNET_memcpy (rps_peer->cur_view, 2539 GNUNET_memcpy(rps_peer->cur_view,
2529 peers, 2540 peers,
2530 view_size * sizeof (struct GNUNET_PeerIdentity)); 2541 view_size * sizeof(struct GNUNET_PeerIdentity));
2531 to_file ("/tmp/rps/count_in_views.txt", 2542 to_file("/tmp/rps/count_in_views.txt",
2532 "%" PRIu64 " %" PRIu32 "", 2543 "%" PRIu64 " %" PRIu32 "",
2533 rps_peer->index, 2544 rps_peer->index,
2534 count_peer_in_views_2 (rps_peer->index)); 2545 count_peer_in_views_2(rps_peer->index));
2535 cumulated_view_sizes(); 2546 cumulated_view_sizes();
2536 if (0 != view_size) 2547 if (0 != view_size)
2537 { 2548 {
2538 to_file ("/tmp/rps/repr.txt", 2549 to_file("/tmp/rps/repr.txt",
2539 "%" PRIu64 /* index */ 2550 "%" PRIu64 /* index */
2540 " %" PRIu32 /* occurrence in views */ 2551 " %" PRIu32 /* occurrence in views */
2541 " %" PRIu32 /* view sizes */ 2552 " %" PRIu32 /* view sizes */
2542 " %f" /* fraction of repr in views */ 2553 " %f" /* fraction of repr in views */
2543 " %f" /* average view size */ 2554 " %f" /* average view size */
2544 " %f" /* prob of occurrence in view slot */ 2555 " %f" /* prob of occurrence in view slot */
2545 " %f" "", /* exp frac of repr in views */ 2556 " %f" "", /* exp frac of repr in views */
2546 rps_peer->index, 2557 rps_peer->index,
2547 count_peer_in_views_2 (rps_peer->index), 2558 count_peer_in_views_2(rps_peer->index),
2548 view_sizes, 2559 view_sizes,
2549 count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ 2560 count_peer_in_views_2(rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */
2550 view_sizes / (view_size * 1.0), /* average view size */ 2561 view_sizes / (view_size * 1.0), /* average view size */
2551 1.0 /view_size, /* prob of occurrence in view slot */ 2562 1.0 / view_size, /* prob of occurrence in view slot */
2552 (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */ 2563 (1.0 / view_size) * (view_sizes / view_size) /* expected fraction of repr in views */
2553 ); 2564 );
2554 } 2565 }
2555 compute_probabilities (rps_peer->index); 2566 compute_probabilities(rps_peer->index);
2556 all_views_updated_cb(); 2567 all_views_updated_cb();
2557} 2568}
2558 2569
2559static void 2570static void
2560pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 2571pre_profiler(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
2561{ 2572{
2562 rps_peer->file_name_probs = 2573 rps_peer->file_name_probs =
2563 store_prefix_file_name (rps_peer->index, "probs"); 2574 store_prefix_file_name(rps_peer->index, "probs");
2564 rps_peer->file_name_probs_hist = 2575 rps_peer->file_name_probs_hist =
2565 store_prefix_file_name (rps_peer->index, "probs_hist"); 2576 store_prefix_file_name(rps_peer->index, "probs_hist");
2566 GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer); 2577 GNUNET_RPS_view_request(h, 0, view_update_cb, rps_peer);
2567} 2578}
2568 2579
2569void write_final_stats (void){ 2580void write_final_stats(void)
2581{
2570 uint64_t sums[STAT_TYPE_MAX] = { 0 }; 2582 uint64_t sums[STAT_TYPE_MAX] = { 0 };
2571 2583
2572 for (uint32_t i = 0; i < num_peers; i++) 2584 for (uint32_t i = 0; i < num_peers; i++)
2573 { 2585 {
2574 to_file ("/tmp/rps/final_stats.csv", 2586 to_file("/tmp/rps/final_stats.csv",
2575 "%" PRIu32 ", " /* index */ 2587 "%" PRIu32 ", " /* index */
2576 "%s, %" /* id */ 2588 "%s, %" /* id */
2577 PRIu64 ", %" /* rounds */ 2589 PRIu64 ", %" /* rounds */
2578 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* blocking */ 2590 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* blocking */
2579 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ 2591 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */
2580 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ 2592 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */
2581 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* recv */ 2593 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* recv */
2582 PRIu64 ", %" /* view size */ 2594 PRIu64 ", %" /* view size */
2583 PRIu64 ", %" /* known peers */ 2595 PRIu64 ", %" /* known peers */
2584 PRIu64 ", %" /* valid peers */ 2596 PRIu64 ", %" /* valid peers */
2585 PRIu64 ", %" /* learned peers */ 2597 PRIu64 ", %" /* learned peers */
2586 PRIu64 ", %" /* pending online checks */ 2598 PRIu64 ", %" /* pending online checks */
2587 PRIu64 ", %" /* unrequested pull replies */ 2599 PRIu64 ", %" /* unrequested pull replies */
2588 PRIu64 ", %" /* peers in push map */ 2600 PRIu64 ", %" /* peers in push map */
2589 PRIu64 ", %" /* peers in pull map */ 2601 PRIu64 ", %" /* peers in pull map */
2590 PRIu64 ", %" /* peers in view */ 2602 PRIu64 ", %" /* peers in view */
2591 PRIu64 "\n"/* view size aim */, 2603 PRIu64 "\n" /* view size aim */,
2592 i, 2604 i,
2593 GNUNET_i2s (rps_peers[i].peer_id), 2605 GNUNET_i2s(rps_peers[i].peer_id),
2594 rps_peers[i].stats[STAT_TYPE_ROUNDS], 2606 rps_peers[i].stats[STAT_TYPE_ROUNDS],
2595 rps_peers[i].stats[STAT_TYPE_BLOCKS], 2607 rps_peers[i].stats[STAT_TYPE_BLOCKS],
2596 rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH], 2608 rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH],
2597 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH], 2609 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH],
2598 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PULL], 2610 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PULL],
2599 rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], 2611 rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL],
2600 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], 2612 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL],
2601 rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND], 2613 rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND],
2602 rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND_MH], 2614 rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND_MH],
2603 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ], 2615 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ],
2604 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ_MH], 2616 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ_MH],
2605 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REP], 2617 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REP],
2606 rps_peers[i].stats[STAT_TYPE_SENT_PUSH_SEND], 2618 rps_peers[i].stats[STAT_TYPE_SENT_PUSH_SEND],
2607 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ], 2619 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ],
2608 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ_MH], 2620 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ_MH],
2609 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REP], 2621 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REP],
2610 rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND], 2622 rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND],
2611 rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND_MH], 2623 rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND_MH],
2612 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ], 2624 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ],
2613 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ_MH], 2625 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ_MH],
2614 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP_MH], 2626 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP_MH],
2615 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP], 2627 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP],
2616 rps_peers[i].stats[STAT_TYPE_VIEW_SIZE], 2628 rps_peers[i].stats[STAT_TYPE_VIEW_SIZE],
2617 rps_peers[i].stats[STAT_TYPE_KNOWN_PEERS], 2629 rps_peers[i].stats[STAT_TYPE_KNOWN_PEERS],
2618 rps_peers[i].stats[STAT_TYPE_VALID_PEERS], 2630 rps_peers[i].stats[STAT_TYPE_VALID_PEERS],
2619 rps_peers[i].stats[STAT_TYPE_LEARND_PEERS], 2631 rps_peers[i].stats[STAT_TYPE_LEARND_PEERS],
2620 rps_peers[i].stats[STAT_TYPE_PENDING_ONLINE_CHECKS], 2632 rps_peers[i].stats[STAT_TYPE_PENDING_ONLINE_CHECKS],
2621 rps_peers[i].stats[STAT_TYPE_UNREQUESTED_PULL_REPLIES], 2633 rps_peers[i].stats[STAT_TYPE_UNREQUESTED_PULL_REPLIES],
2622 rps_peers[i].stats[STAT_TYPE_PEERS_IN_PUSH_MAP], 2634 rps_peers[i].stats[STAT_TYPE_PEERS_IN_PUSH_MAP],
2623 rps_peers[i].stats[STAT_TYPE_PEERS_IN_PULL_MAP], 2635 rps_peers[i].stats[STAT_TYPE_PEERS_IN_PULL_MAP],
2624 rps_peers[i].stats[STAT_TYPE_PEERS_IN_VIEW], 2636 rps_peers[i].stats[STAT_TYPE_PEERS_IN_VIEW],
2625 rps_peers[i].stats[STAT_TYPE_VIEW_SIZE_AIM]); 2637 rps_peers[i].stats[STAT_TYPE_VIEW_SIZE_AIM]);
2626 for (enum STAT_TYPE stat_type = STAT_TYPE_ROUNDS; 2638 for (enum STAT_TYPE stat_type = STAT_TYPE_ROUNDS;
2627 stat_type < STAT_TYPE_MAX; 2639 stat_type < STAT_TYPE_MAX;
2628 stat_type++) 2640 stat_type++)
2629 { 2641 {
2630 sums[stat_type] += rps_peers[i].stats[stat_type]; 2642 sums[stat_type] += rps_peers[i].stats[stat_type];
2631 } 2643 }
2632 } 2644 }
2633 to_file ("/tmp/rps/final_stats.dat", 2645 to_file("/tmp/rps/final_stats.dat",
2634 "SUM %" 2646 "SUM %"
2635 PRIu64 " %" /* rounds */ 2647 PRIu64 " %" /* rounds */
2636 PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ 2648 PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */
2637 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ 2649 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */
2638 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ 2650 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */
2639 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* recv */ 2651 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* recv */
2640 PRIu64 ", %" /* view size */ 2652 PRIu64 ", %" /* view size */
2641 PRIu64 ", %" /* known peers */ 2653 PRIu64 ", %" /* known peers */
2642 PRIu64 ", %" /* valid peers */ 2654 PRIu64 ", %" /* valid peers */
2643 PRIu64 ", %" /* learned peers */ 2655 PRIu64 ", %" /* learned peers */
2644 PRIu64 ", %" /* pending online checks */ 2656 PRIu64 ", %" /* pending online checks */
2645 PRIu64 ", %" /* unrequested pull replies */ 2657 PRIu64 ", %" /* unrequested pull replies */
2646 PRIu64 ", %" /* peers in push map */ 2658 PRIu64 ", %" /* peers in push map */
2647 PRIu64 ", %" /* peers in pull map */ 2659 PRIu64 ", %" /* peers in pull map */
2648 PRIu64 ", %" /* peers in view */ 2660 PRIu64 ", %" /* peers in view */
2649 PRIu64 "\n"/* view size aim */, 2661 PRIu64 "\n" /* view size aim */,
2650 sums[STAT_TYPE_ROUNDS], 2662 sums[STAT_TYPE_ROUNDS],
2651 sums[STAT_TYPE_BLOCKS], 2663 sums[STAT_TYPE_BLOCKS],
2652 sums[STAT_TYPE_BLOCKS_MANY_PUSH], 2664 sums[STAT_TYPE_BLOCKS_MANY_PUSH],
2653 sums[STAT_TYPE_BLOCKS_NO_PUSH], 2665 sums[STAT_TYPE_BLOCKS_NO_PUSH],
2654 sums[STAT_TYPE_BLOCKS_NO_PULL], 2666 sums[STAT_TYPE_BLOCKS_NO_PULL],
2655 sums[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], 2667 sums[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL],
2656 sums[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], 2668 sums[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL],
2657 sums[STAT_TYPE_ISSUED_PUSH_SEND], 2669 sums[STAT_TYPE_ISSUED_PUSH_SEND],
2658 sums[STAT_TYPE_ISSUED_PUSH_SEND_MH], 2670 sums[STAT_TYPE_ISSUED_PUSH_SEND_MH],
2659 sums[STAT_TYPE_ISSUED_PULL_REQ], 2671 sums[STAT_TYPE_ISSUED_PULL_REQ],
2660 sums[STAT_TYPE_ISSUED_PULL_REQ_MH], 2672 sums[STAT_TYPE_ISSUED_PULL_REQ_MH],
2661 sums[STAT_TYPE_ISSUED_PULL_REP], 2673 sums[STAT_TYPE_ISSUED_PULL_REP],
2662 sums[STAT_TYPE_SENT_PUSH_SEND], 2674 sums[STAT_TYPE_SENT_PUSH_SEND],
2663 sums[STAT_TYPE_SENT_PULL_REQ], 2675 sums[STAT_TYPE_SENT_PULL_REQ],
2664 sums[STAT_TYPE_SENT_PULL_REQ_MH], 2676 sums[STAT_TYPE_SENT_PULL_REQ_MH],
2665 sums[STAT_TYPE_SENT_PULL_REP], 2677 sums[STAT_TYPE_SENT_PULL_REP],
2666 sums[STAT_TYPE_RECV_PUSH_SEND], 2678 sums[STAT_TYPE_RECV_PUSH_SEND],
2667 sums[STAT_TYPE_RECV_PUSH_SEND_MH], 2679 sums[STAT_TYPE_RECV_PUSH_SEND_MH],
2668 sums[STAT_TYPE_RECV_PULL_REQ], 2680 sums[STAT_TYPE_RECV_PULL_REQ],
2669 sums[STAT_TYPE_RECV_PULL_REQ_MH], 2681 sums[STAT_TYPE_RECV_PULL_REQ_MH],
2670 sums[STAT_TYPE_RECV_PULL_REP], 2682 sums[STAT_TYPE_RECV_PULL_REP],
2671 sums[STAT_TYPE_RECV_PULL_REP_MH], 2683 sums[STAT_TYPE_RECV_PULL_REP_MH],
2672 sums[STAT_TYPE_VIEW_SIZE], 2684 sums[STAT_TYPE_VIEW_SIZE],
2673 sums[STAT_TYPE_KNOWN_PEERS], 2685 sums[STAT_TYPE_KNOWN_PEERS],
2674 sums[STAT_TYPE_VALID_PEERS], 2686 sums[STAT_TYPE_VALID_PEERS],
2675 sums[STAT_TYPE_LEARND_PEERS], 2687 sums[STAT_TYPE_LEARND_PEERS],
2676 sums[STAT_TYPE_PENDING_ONLINE_CHECKS], 2688 sums[STAT_TYPE_PENDING_ONLINE_CHECKS],
2677 sums[STAT_TYPE_UNREQUESTED_PULL_REPLIES], 2689 sums[STAT_TYPE_UNREQUESTED_PULL_REPLIES],
2678 sums[STAT_TYPE_PEERS_IN_PUSH_MAP], 2690 sums[STAT_TYPE_PEERS_IN_PUSH_MAP],
2679 sums[STAT_TYPE_PEERS_IN_PULL_MAP], 2691 sums[STAT_TYPE_PEERS_IN_PULL_MAP],
2680 sums[STAT_TYPE_PEERS_IN_VIEW], 2692 sums[STAT_TYPE_PEERS_IN_VIEW],
2681 sums[STAT_TYPE_VIEW_SIZE_AIM]); 2693 sums[STAT_TYPE_VIEW_SIZE_AIM]);
2682} 2694}
2683 2695
2684/** 2696/**
@@ -2693,43 +2705,47 @@ void write_final_stats (void){
2693 * successfully obtained, #GNUNET_SYSERR if not. 2705 * successfully obtained, #GNUNET_SYSERR if not.
2694 */ 2706 */
2695void 2707void
2696post_test_shutdown_ready_cb (void *cls, 2708post_test_shutdown_ready_cb(void *cls,
2697 int success) 2709 int success)
2698{ 2710{
2699 struct STATcls *stat_cls = (struct STATcls *) cls; 2711 struct STATcls *stat_cls = (struct STATcls *)cls;
2700 struct RPSPeer *rps_peer = stat_cls->rps_peer; 2712 struct RPSPeer *rps_peer = stat_cls->rps_peer;
2701 2713
2702 rps_peer->h_stat_get[stat_cls->stat_type] = NULL; 2714 rps_peer->h_stat_get[stat_cls->stat_type] = NULL;
2703 if (GNUNET_OK == success) 2715 if (GNUNET_OK == success)
2704 { 2716 {
2705 /* set flag that we we got the value */ 2717 /* set flag that we we got the value */
2706 rps_peer->stat_collected_flags |= BIT(stat_cls->stat_type); 2718 rps_peer->stat_collected_flags |= BIT(stat_cls->stat_type);
2707 } else { 2719 }
2708 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2720 else
2709 "Peer %u did not receive statistics value\n", 2721 {
2710 rps_peer->index); 2722 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2711 GNUNET_free (stat_cls); 2723 "Peer %u did not receive statistics value\n",
2712 GNUNET_break (0); 2724 rps_peer->index);
2713 return; 2725 GNUNET_free(stat_cls);
2714 } 2726 GNUNET_break(0);
2727 return;
2728 }
2715 2729
2716 if (NULL != rps_peer->stat_op && 2730 if (NULL != rps_peer->stat_op &&
2717 GNUNET_YES == check_statistics_collect_completed_single_peer (rps_peer)) 2731 GNUNET_YES == check_statistics_collect_completed_single_peer(rps_peer))
2718 { 2732 {
2719 GNUNET_TESTBED_operation_done (rps_peer->stat_op); 2733 GNUNET_TESTBED_operation_done(rps_peer->stat_op);
2720 } 2734 }
2721 2735
2722 write_final_stats (); 2736 write_final_stats();
2723 if (GNUNET_YES == check_statistics_collect_completed()) 2737 if (GNUNET_YES == check_statistics_collect_completed())
2724 { 2738 {
2725 //write_final_stats (); 2739 //write_final_stats ();
2726 GNUNET_free (stat_cls); 2740 GNUNET_free(stat_cls);
2727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2741 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2728 "Shutting down\n"); 2742 "Shutting down\n");
2729 GNUNET_SCHEDULER_shutdown (); 2743 GNUNET_SCHEDULER_shutdown();
2730 } else { 2744 }
2731 GNUNET_free (stat_cls); 2745 else
2732 } 2746 {
2747 GNUNET_free(stat_cls);
2748 }
2733} 2749}
2734 2750
2735/** 2751/**
@@ -2743,80 +2759,81 @@ post_test_shutdown_ready_cb (void *cls,
2743 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 2759 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
2744 */ 2760 */
2745int 2761int
2746stat_iterator (void *cls, 2762stat_iterator(void *cls,
2747 const char *subsystem, 2763 const char *subsystem,
2748 const char *name, 2764 const char *name,
2749 uint64_t value, 2765 uint64_t value,
2750 int is_persistent) 2766 int is_persistent)
2751{ 2767{
2752 const struct STATcls *stat_cls = (const struct STATcls *) cls; 2768 const struct STATcls *stat_cls = (const struct STATcls *)cls;
2753 struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer; 2769 struct RPSPeer *rps_peer = (struct RPSPeer *)stat_cls->rps_peer;
2754 enum STAT_TYPE stat_type; 2770 enum STAT_TYPE stat_type;
2755 (void) subsystem; 2771
2756 (void) is_persistent; 2772 (void)subsystem;
2757 2773 (void)is_persistent;
2758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2774
2759 "Got stat value: %s - %" PRIu64 " (%u)\n", 2775 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2760 name, 2776 "Got stat value: %s - %" PRIu64 " (%u)\n",
2761 value, 2777 name,
2762 rps_peer->index); 2778 value,
2763 to_file (rps_peer->file_name_stats, 2779 rps_peer->index);
2780 to_file(rps_peer->file_name_stats,
2764 "%s: %" PRIu64 "\n", 2781 "%s: %" PRIu64 "\n",
2765 name, 2782 name,
2766 value); 2783 value);
2767 stat_type = stat_str_2_type (name); 2784 stat_type = stat_str_2_type(name);
2768 GNUNET_assert (STAT_TYPE_ROUNDS <= stat_type && 2785 GNUNET_assert(STAT_TYPE_ROUNDS <= stat_type &&
2769 STAT_TYPE_MAX > stat_type); 2786 STAT_TYPE_MAX > stat_type);
2770 rps_peer->stats[stat_type] = value; 2787 rps_peer->stats[stat_type] = value;
2771 return GNUNET_OK; 2788 return GNUNET_OK;
2772} 2789}
2773 2790
2774 2791
2775void 2792void
2776post_profiler (struct RPSPeer *rps_peer) 2793post_profiler(struct RPSPeer *rps_peer)
2777{ 2794{
2778 if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics) 2795 if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics)
2779 { 2796 {
2780 return; 2797 return;
2781 } 2798 }
2782 2799
2783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2800 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2784 "Going to request statistic values with mask 0x%" PRIx32 "\n", 2801 "Going to request statistic values with mask 0x%" PRIx32 "\n",
2785 cur_test_run.stat_collect_flags); 2802 cur_test_run.stat_collect_flags);
2786 2803
2787 struct STATcls *stat_cls; 2804 struct STATcls *stat_cls;
2788 uint32_t stat_type; 2805 uint32_t stat_type;
2789 for (stat_type = STAT_TYPE_ROUNDS; 2806 for (stat_type = STAT_TYPE_ROUNDS;
2790 stat_type < STAT_TYPE_MAX; 2807 stat_type < STAT_TYPE_MAX;
2791 stat_type++) 2808 stat_type++)
2792 { 2809 {
2793 if (BIT(stat_type) & cur_test_run.stat_collect_flags) 2810 if (BIT(stat_type) & cur_test_run.stat_collect_flags)
2794 { 2811 {
2795 stat_cls = GNUNET_malloc (sizeof (struct STATcls)); 2812 stat_cls = GNUNET_malloc(sizeof(struct STATcls));
2796 stat_cls->rps_peer = rps_peer; 2813 stat_cls->rps_peer = rps_peer;
2797 stat_cls->stat_type = stat_type; 2814 stat_cls->stat_type = stat_type;
2798 rps_peer->file_name_stats = 2815 rps_peer->file_name_stats =
2799 store_prefix_file_name (rps_peer->peer_id, "stats"); 2816 store_prefix_file_name(rps_peer->peer_id, "stats");
2800 rps_peer->h_stat_get[stat_type] = 2817 rps_peer->h_stat_get[stat_type] =
2801 GNUNET_STATISTICS_get (rps_peer->stats_h, 2818 GNUNET_STATISTICS_get(rps_peer->stats_h,
2802 "rps", 2819 "rps",
2803 stat_type_strings [stat_type], 2820 stat_type_strings [stat_type],
2804 post_test_shutdown_ready_cb, 2821 post_test_shutdown_ready_cb,
2805 stat_iterator, 2822 stat_iterator,
2806 (struct STATcls *) stat_cls); 2823 (struct STATcls *)stat_cls);
2807 GNUNET_assert (NULL != rps_peer->h_stat_get); 2824 GNUNET_assert(NULL != rps_peer->h_stat_get);
2808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2825 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2809 "Requested statistics for %s (peer %" PRIu32 ")\n", 2826 "Requested statistics for %s (peer %" PRIu32 ")\n",
2810 stat_type_strings [stat_type], 2827 stat_type_strings [stat_type],
2811 rps_peer->index); 2828 rps_peer->index);
2812 } 2829 }
2813 } 2830 }
2814 GNUNET_free (rps_peer->eval_probs_cache); 2831 GNUNET_free(rps_peer->eval_probs_cache);
2815} 2832}
2816 2833
2817 2834
2818/*********************************************************************** 2835/***********************************************************************
2819 * /Definition of tests 2836* /Definition of tests
2820***********************************************************************/ 2837***********************************************************************/
2821 2838
2822 2839
@@ -2833,99 +2850,100 @@ post_profiler (struct RPSPeer *rps_peer)
2833 * failed 2850 * failed
2834 */ 2851 */
2835static void 2852static void
2836test_run (void *cls, 2853test_run(void *cls,
2837 struct GNUNET_TESTBED_RunHandle *h, 2854 struct GNUNET_TESTBED_RunHandle *h,
2838 unsigned int n_peers, 2855 unsigned int n_peers,
2839 struct GNUNET_TESTBED_Peer **peers, 2856 struct GNUNET_TESTBED_Peer **peers,
2840 unsigned int links_succeeded, 2857 unsigned int links_succeeded,
2841 unsigned int links_failed) 2858 unsigned int links_failed)
2842{ 2859{
2843 unsigned int i; 2860 unsigned int i;
2844 struct OpListEntry *entry; 2861 struct OpListEntry *entry;
2845 (void) cls;
2846 (void) h;
2847 (void) links_failed;
2848 2862
2849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n"); 2863 (void)cls;
2864 (void)h;
2865 (void)links_failed;
2866
2867 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n");
2850 2868
2851 /* Check whether we timed out */ 2869 /* Check whether we timed out */
2852 if (n_peers != num_peers || 2870 if (n_peers != num_peers ||
2853 NULL == peers || 2871 NULL == peers ||
2854 0 == links_succeeded) 2872 0 == links_succeeded)
2855 { 2873 {
2856 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n"); 2874 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n");
2857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers); 2875 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers);
2858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers); 2876 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers);
2859 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers); 2877 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers);
2860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded); 2878 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded);
2861 ok = 1; 2879 ok = 1;
2862 GNUNET_SCHEDULER_shutdown (); 2880 GNUNET_SCHEDULER_shutdown();
2863 return; 2881 return;
2864 } 2882 }
2865 2883
2866 2884
2867 /* Initialize peers */ 2885 /* Initialize peers */
2868 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n"); 2886 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n");
2869 testbed_peers = peers; 2887 testbed_peers = peers;
2870 num_peers_online = 0; 2888 num_peers_online = 0;
2871 for (i = 0; i < num_peers; i++) 2889 for (i = 0; i < num_peers; i++)
2872 { 2890 {
2873 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i); 2891 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i);
2874 entry = make_oplist_entry (); 2892 entry = make_oplist_entry();
2875 entry->index = i; 2893 entry->index = i;
2876 rps_peers[i].index = i; 2894 rps_peers[i].index = i;
2877 if (NULL != cur_test_run.init_peer) 2895 if (NULL != cur_test_run.init_peer)
2878 cur_test_run.init_peer (&rps_peers[i]); 2896 cur_test_run.init_peer(&rps_peers[i]);
2879 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) 2897 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
2880 { 2898 {
2881 rps_peers->cur_view_count = 0; 2899 rps_peers->cur_view_count = 0;
2882 rps_peers->cur_view = NULL; 2900 rps_peers->cur_view = NULL;
2883 } 2901 }
2884 entry->op = GNUNET_TESTBED_peer_get_information (peers[i], 2902 entry->op = GNUNET_TESTBED_peer_get_information(peers[i],
2885 GNUNET_TESTBED_PIT_IDENTITY, 2903 GNUNET_TESTBED_PIT_IDENTITY,
2886 &info_cb, 2904 &info_cb,
2887 entry); 2905 entry);
2888 } 2906 }
2889 2907
2890 /* Bring peers up */ 2908 /* Bring peers up */
2891 GNUNET_assert (num_peers == n_peers); 2909 GNUNET_assert(num_peers == n_peers);
2892 for (i = 0; i < n_peers; i++) 2910 for (i = 0; i < n_peers; i++)
2893 { 2911 {
2894 rps_peers[i].index = i; 2912 rps_peers[i].index = i;
2895 rps_peers[i].op = 2913 rps_peers[i].op =
2896 GNUNET_TESTBED_service_connect (&rps_peers[i], 2914 GNUNET_TESTBED_service_connect(&rps_peers[i],
2897 peers[i], 2915 peers[i],
2898 "rps", 2916 "rps",
2899 &rps_connect_complete_cb, 2917 &rps_connect_complete_cb,
2900 &rps_peers[i], 2918 &rps_peers[i],
2901 &rps_connect_adapter, 2919 &rps_connect_adapter,
2902 &rps_disconnect_adapter, 2920 &rps_disconnect_adapter,
2903 &rps_peers[i]); 2921 &rps_peers[i]);
2904 /* Connect all peers to statistics service */ 2922 /* Connect all peers to statistics service */
2905 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) 2923 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
2906 { 2924 {
2907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2925 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2908 "Connecting to statistics service\n"); 2926 "Connecting to statistics service\n");
2909 rps_peers[i].stat_op = 2927 rps_peers[i].stat_op =
2910 GNUNET_TESTBED_service_connect (NULL, 2928 GNUNET_TESTBED_service_connect(NULL,
2911 peers[i], 2929 peers[i],
2912 "statistics", 2930 "statistics",
2913 stat_complete_cb, 2931 stat_complete_cb,
2914 &rps_peers[i], 2932 &rps_peers[i],
2915 &stat_connect_adapter, 2933 &stat_connect_adapter,
2916 &stat_disconnect_adapter, 2934 &stat_disconnect_adapter,
2917 &rps_peers[i]); 2935 &rps_peers[i]);
2918 } 2936 }
2919 } 2937 }
2920 2938
2921 if (NULL != churn_task) 2939 if (NULL != churn_task)
2922 GNUNET_SCHEDULER_cancel (churn_task); 2940 GNUNET_SCHEDULER_cancel(churn_task);
2923 post_test_task = GNUNET_SCHEDULER_add_delayed (duration, &post_test_op, NULL); 2941 post_test_task = GNUNET_SCHEDULER_add_delayed(duration, &post_test_op, NULL);
2924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n", timeout.rel_value_us/1000000); 2942 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n", timeout.rel_value_us / 1000000);
2925 shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, 2943 shutdown_task = GNUNET_SCHEDULER_add_delayed(timeout,
2926 &trigger_shutdown, 2944 &trigger_shutdown,
2927 NULL); 2945 NULL);
2928 GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL); 2946 GNUNET_SCHEDULER_add_shutdown(shutdown_op, NULL);
2929} 2947}
2930 2948
2931 2949
@@ -2936,20 +2954,20 @@ test_run (void *cls,
2936 * @param argv unused 2954 * @param argv unused
2937 */ 2955 */
2938static void 2956static void
2939run (void *cls, 2957run(void *cls,
2940 char *const *args, 2958 char *const *args,
2941 const char *cfgfile, 2959 const char *cfgfile,
2942 const struct GNUNET_CONFIGURATION_Handle *cfg) 2960 const struct GNUNET_CONFIGURATION_Handle *cfg)
2943{ 2961{
2944 //int ret_value; 2962 //int ret_value;
2945 (void) cls; 2963 (void)cls;
2946 (void) args; 2964 (void)args;
2947 (void) cfgfile; 2965 (void)cfgfile;
2948 2966
2949 /* Defaults for tests */ 2967 /* Defaults for tests */
2950 churn_task = NULL; 2968 churn_task = NULL;
2951 2969
2952 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); 2970 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
2953 cur_test_run.name = "test-rps-profiler"; 2971 cur_test_run.name = "test-rps-profiler";
2954 if (0 == num_peers) 2972 if (0 == num_peers)
2955 num_peers = 10; 2973 num_peers = 10;
@@ -2962,7 +2980,8 @@ run (void *cls,
2962 cur_test_run.eval_cb = profiler_eval; 2980 cur_test_run.eval_cb = profiler_eval;
2963 cur_test_run.post_test = post_profiler; 2981 cur_test_run.post_test = post_profiler;
2964 cur_test_run.request_interval = 2; 2982 cur_test_run.request_interval = 2;
2965 if (0 == cur_test_run.num_requests) cur_test_run.num_requests = 5; 2983 if (0 == cur_test_run.num_requests)
2984 cur_test_run.num_requests = 5;
2966 //cur_test_run.have_churn = HAVE_CHURN; 2985 //cur_test_run.have_churn = HAVE_CHURN;
2967 cur_test_run.have_churn = HAVE_NO_CHURN; 2986 cur_test_run.have_churn = HAVE_NO_CHURN;
2968 cur_test_run.have_quick_quit = HAVE_QUICK_QUIT; 2987 cur_test_run.have_quick_quit = HAVE_QUICK_QUIT;
@@ -3002,65 +3021,65 @@ run (void *cls,
3002 cur_test_run.have_collect_view = COLLECT_VIEW; 3021 cur_test_run.have_collect_view = COLLECT_VIEW;
3003 3022
3004 /* 'Clean' directory */ 3023 /* 'Clean' directory */
3005 (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); 3024 (void)GNUNET_DISK_directory_remove("/tmp/rps/");
3006 GNUNET_DISK_directory_create ("/tmp/rps/"); 3025 GNUNET_DISK_directory_create("/tmp/rps/");
3007 if (0 == duration.rel_value_us) 3026 if (0 == duration.rel_value_us)
3008 {
3009 if (0 == timeout.rel_value_us)
3010 { 3027 {
3011 duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90); 3028 if (0 == timeout.rel_value_us)
3012 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3029 {
3013 (90 * 1.2) + 3030 duration = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90);
3014 (0.01 * num_peers)); 3031 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
3032 (90 * 1.2) +
3033 (0.01 * num_peers));
3034 }
3035 else
3036 {
3037 duration = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
3038 (timeout.rel_value_us / 1000000)
3039 * 0.75);
3040 }
3015 } 3041 }
3016 else 3042 else
3017 { 3043 {
3018 duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3044 if (0 == timeout.rel_value_us)
3019 (timeout.rel_value_us/1000000) 3045 {
3020 * 0.75); 3046 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
3047 ((duration.rel_value_us / 1000000)
3048 * 1.2) + (0.01 * num_peers));
3049 }
3021 } 3050 }
3022 } 3051 GNUNET_assert(duration.rel_value_us < timeout.rel_value_us);
3023 else 3052 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3024 { 3053 "duration is %lus\n",
3025 if (0 == timeout.rel_value_us) 3054 duration.rel_value_us / 1000000);
3026 { 3055 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3027 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3056 "timeout is %lus\n",
3028 ((duration.rel_value_us/1000000) 3057 timeout.rel_value_us / 1000000);
3029 * 1.2) + (0.01 * num_peers));
3030 }
3031 }
3032 GNUNET_assert (duration.rel_value_us < timeout.rel_value_us);
3033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3034 "duration is %lus\n",
3035 duration.rel_value_us/1000000);
3036 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3037 "timeout is %lus\n",
3038 timeout.rel_value_us/1000000);
3039 3058
3040 /* Compute number of bits for representing largest peer id */ 3059 /* Compute number of bits for representing largest peer id */
3041 for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++) 3060 for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++)
3042 ; 3061 ;
3043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3062 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3044 "Need %u bits to represent %" PRIu32 " peers\n", 3063 "Need %u bits to represent %" PRIu32 " peers\n",
3045 bits_needed, 3064 bits_needed,
3046 num_peers); 3065 num_peers);
3047 3066
3048 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); 3067 rps_peers = GNUNET_new_array(num_peers, struct RPSPeer);
3049 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); 3068 peer_map = GNUNET_CONTAINER_multipeermap_create(num_peers, GNUNET_NO);
3050 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); 3069 rps_peer_ids = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity);
3051 if ( (2 == mal_type) || 3070 if ((2 == mal_type) ||
3052 (3 == mal_type)) 3071 (3 == mal_type))
3053 target_peer = &rps_peer_ids[num_peers - 2]; 3072 target_peer = &rps_peer_ids[num_peers - 2];
3054 3073
3055 ok = 1; 3074 ok = 1;
3056 GNUNET_TESTBED_run (NULL, 3075 GNUNET_TESTBED_run(NULL,
3057 cfg, 3076 cfg,
3058 num_peers, 3077 num_peers,
3059 0, /* event mask */ 3078 0, /* event mask */
3060 NULL, 3079 NULL,
3061 NULL, 3080 NULL,
3062 &test_run, 3081 &test_run,
3063 NULL); 3082 NULL);
3064} 3083}
3065 3084
3066/** 3085/**
@@ -3071,69 +3090,69 @@ run (void *cls,
3071 * @return 0 on success 3090 * @return 0 on success
3072 */ 3091 */
3073int 3092int
3074main (int argc, char *argv[]) 3093main(int argc, char *argv[])
3075{ 3094{
3076 int ret_value; 3095 int ret_value;
3077 struct GNUNET_GETOPT_CommandLineOption options[] = { 3096 struct GNUNET_GETOPT_CommandLineOption options[] = {
3078 GNUNET_GETOPT_option_uint ('n', 3097 GNUNET_GETOPT_option_uint('n',
3079 "num-peers", 3098 "num-peers",
3080 "COUNT", 3099 "COUNT",
3081 gettext_noop ("number of peers to start"), 3100 gettext_noop("number of peers to start"),
3082 &num_peers), 3101 &num_peers),
3083 GNUNET_GETOPT_option_relative_time ('d', 3102 GNUNET_GETOPT_option_relative_time('d',
3084 "duration", 3103 "duration",
3085 "DURATION", 3104 "DURATION",
3086 gettext_noop ("duration of the profiling"), 3105 gettext_noop("duration of the profiling"),
3087 &duration), 3106 &duration),
3088 GNUNET_GETOPT_option_relative_time ('t', 3107 GNUNET_GETOPT_option_relative_time('t',
3089 "timeout", 3108 "timeout",
3090 "TIMEOUT", 3109 "TIMEOUT",
3091 gettext_noop ("timeout for the profiling"), 3110 gettext_noop("timeout for the profiling"),
3092 &timeout), 3111 &timeout),
3093 GNUNET_GETOPT_option_uint ('r', 3112 GNUNET_GETOPT_option_uint('r',
3094 "num-requests", 3113 "num-requests",
3095 "COUNT", 3114 "COUNT",
3096 gettext_noop ("number of PeerIDs to request"), 3115 gettext_noop("number of PeerIDs to request"),
3097 &cur_test_run.num_requests), 3116 &cur_test_run.num_requests),
3098 GNUNET_GETOPT_OPTION_END 3117 GNUNET_GETOPT_OPTION_END
3099 }; 3118 };
3100 3119
3101 unsetenv ("XDG_DATA_HOME"); 3120 unsetenv("XDG_DATA_HOME");
3102 unsetenv ("XDG_CONFIG_HOME"); 3121 unsetenv("XDG_CONFIG_HOME");
3103 //if (GNUNET_OK != 3122 //if (GNUNET_OK !=
3104 // GNUNET_STRINGS_get_utf8_args (argc, argv, 3123 // GNUNET_STRINGS_get_utf8_args (argc, argv,
3105 // &argc, &argv)) 3124 // &argc, &argv))
3106 // return 2; 3125 // return 2;
3107 ret_value = 0; 3126 ret_value = 0;
3108 if (GNUNET_OK != 3127 if (GNUNET_OK !=
3109 GNUNET_PROGRAM_run (argc, 3128 GNUNET_PROGRAM_run(argc,
3110 argv, 3129 argv,
3111 "gnunet-rps-profiler", 3130 "gnunet-rps-profiler",
3112 gettext_noop ("Measure quality and performance of the RPS service."), 3131 gettext_noop("Measure quality and performance of the RPS service."),
3113 options, 3132 options,
3114 &run, 3133 &run,
3115 NULL)) 3134 NULL))
3116 { 3135 {
3117 ret_value = 1; 3136 ret_value = 1;
3118 } 3137 }
3119 if (0 != ret_value) 3138 if (0 != ret_value)
3120 { 3139 {
3121 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3140 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
3122 "Test did not run successfully!\n"); 3141 "Test did not run successfully!\n");
3123 } 3142 }
3124 else 3143 else
3125 { 3144 {
3126 ret_value = cur_test_run.eval_cb(); 3145 ret_value = cur_test_run.eval_cb();
3127 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) 3146 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
3128 { 3147 {
3129 GNUNET_array_grow (rps_peers->cur_view, 3148 GNUNET_array_grow(rps_peers->cur_view,
3130 rps_peers->cur_view_count, 3149 rps_peers->cur_view_count,
3131 0); 3150 0);
3132 } 3151 }
3133 GNUNET_free (rps_peers); 3152 GNUNET_free(rps_peers);
3134 GNUNET_free (rps_peer_ids); 3153 GNUNET_free(rps_peer_ids);
3135 GNUNET_CONTAINER_multipeermap_destroy (peer_map); 3154 GNUNET_CONTAINER_multipeermap_destroy(peer_map);
3136 } 3155 }
3137 return ret_value; 3156 return ret_value;
3138} 3157}
3139 3158