diff options
author | Phil <phil.buschmann@tum.de> | 2018-06-11 22:10:32 +0200 |
---|---|---|
committer | Phil <phil.buschmann@tum.de> | 2018-06-11 22:10:32 +0200 |
commit | 09b6a814e0ddcca0497c5cbf37940c27e6a5d9de (patch) | |
tree | f9884590450463aa95d9f858e9992e103467e89e /src/rps/gnunet-rps-profiler.c | |
parent | c1062075eddca49cfeaac8f7fd8c84e73198c2aa (diff) | |
parent | bb581dc55bfb90fc7f34797111b55d16e69b7af0 (diff) | |
download | gnunet-09b6a814e0ddcca0497c5cbf37940c27e6a5d9de.tar.gz gnunet-09b6a814e0ddcca0497c5cbf37940c27e6a5d9de.zip |
-Merge branch 'master' of ssh://gnunet.org/gnunet into gsoc2018/rest_api
Diffstat (limited to 'src/rps/gnunet-rps-profiler.c')
-rw-r--r-- | src/rps/gnunet-rps-profiler.c | 2713 |
1 files changed, 2713 insertions, 0 deletions
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c new file mode 100644 index 000000000..5ef42187f --- /dev/null +++ b/src/rps/gnunet-rps-profiler.c | |||
@@ -0,0 +1,2713 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2012 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | /** | ||
19 | * @file rps/test_rps.c | ||
20 | * @brief Testcase for the random peer sampling service. Starts | ||
21 | * a peergroup with a given number of peers, then waits to | ||
22 | * receive size pushes/pulls from each peer. Expects to wait | ||
23 | * for one message from each peer. | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | //#include "rps_test_lib.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_testbed_service.h" | ||
29 | |||
30 | #include "gnunet_rps_service.h" | ||
31 | #include "rps-test_util.h" | ||
32 | #include "gnunet-service-rps_sampler_elem.h" | ||
33 | |||
34 | #include <inttypes.h> | ||
35 | |||
36 | |||
37 | #define BIT(n) (1 << (n)) | ||
38 | |||
39 | /** | ||
40 | * How many peers do we start? | ||
41 | */ | ||
42 | static uint32_t num_peers; | ||
43 | |||
44 | /** | ||
45 | * How long do we run the test? | ||
46 | * In seconds. | ||
47 | */ | ||
48 | static uint32_t timeout_s; | ||
49 | |||
50 | /** | ||
51 | * How long do we run the test? | ||
52 | */ | ||
53 | //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
54 | static struct GNUNET_TIME_Relative timeout; | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Portion of malicious peers | ||
59 | */ | ||
60 | static double portion = .1; | ||
61 | |||
62 | /** | ||
63 | * Type of malicious peer to test | ||
64 | */ | ||
65 | static unsigned int mal_type = 0; | ||
66 | |||
67 | /** | ||
68 | * Handles to all of the running peers | ||
69 | */ | ||
70 | static struct GNUNET_TESTBED_Peer **testbed_peers; | ||
71 | |||
72 | enum STAT_TYPE | ||
73 | { | ||
74 | STAT_TYPE_ROUNDS, /* 0 */ | ||
75 | STAT_TYPE_BLOCKS, /* 1 */ | ||
76 | STAT_TYPE_BLOCKS_MANY_PUSH, /* 2 */ | ||
77 | STAT_TYPE_BLOCKS_NO_PUSH, /* 3 */ | ||
78 | STAT_TYPE_BLOCKS_NO_PULL, /* 4 */ | ||
79 | STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL, /* 5 */ | ||
80 | STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL, /* 6 */ | ||
81 | STAT_TYPE_ISSUED_PUSH_SEND, /* 7 */ | ||
82 | STAT_TYPE_ISSUED_PULL_REQ, /* 8 */ | ||
83 | STAT_TYPE_ISSUED_PULL_REP, /* 9 */ | ||
84 | STAT_TYPE_SENT_PUSH_SEND, /* 10 */ | ||
85 | STAT_TYPE_SENT_PULL_REQ, /* 11 */ | ||
86 | STAT_TYPE_SENT_PULL_REP, /* 12 */ | ||
87 | STAT_TYPE_RECV_PUSH_SEND, /* 13 */ | ||
88 | STAT_TYPE_RECV_PULL_REQ, /* 14 */ | ||
89 | STAT_TYPE_RECV_PULL_REP, /* 15 */ | ||
90 | STAT_TYPE_MAX, /* 16 */ | ||
91 | }; | ||
92 | |||
93 | struct STATcls | ||
94 | { | ||
95 | struct RPSPeer *rps_peer; | ||
96 | enum STAT_TYPE stat_type; | ||
97 | }; | ||
98 | |||
99 | |||
100 | /** | ||
101 | * @brief Converts string representation to the corresponding #STAT_TYPE enum. | ||
102 | * | ||
103 | * @param stat_str string representation of statistics specifier | ||
104 | * | ||
105 | * @return corresponding enum | ||
106 | */ | ||
107 | enum STAT_TYPE stat_str_2_type (const char *stat_str) | ||
108 | { | ||
109 | if (0 == strncmp ("# rounds blocked - no pull replies", stat_str, strlen ("# rounds blocked - no pull replies"))) | ||
110 | { | ||
111 | return STAT_TYPE_BLOCKS_NO_PULL; | ||
112 | } | ||
113 | else if (0 == strncmp ("# rounds blocked - too many pushes, no pull replies", stat_str, strlen ("# rounds blocked - too many pushes, no pull replies"))) | ||
114 | { | ||
115 | return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL; | ||
116 | } | ||
117 | else if (0 == strncmp ("# rounds blocked - too many pushes", stat_str, strlen ("# rounds blocked - too many pushes"))) | ||
118 | { | ||
119 | return STAT_TYPE_BLOCKS_MANY_PUSH; | ||
120 | } | ||
121 | else if (0 == strncmp ("# rounds blocked - no pushes, no pull replies", stat_str, strlen ("# rounds blocked - no pushes, no pull replies"))) | ||
122 | { | ||
123 | return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL; | ||
124 | } | ||
125 | else if (0 == strncmp ("# rounds blocked - no pushes", stat_str, strlen ("# rounds blocked - no pushes"))) | ||
126 | { | ||
127 | return STAT_TYPE_BLOCKS_NO_PUSH; | ||
128 | } | ||
129 | else if (0 == strncmp ("# rounds blocked", stat_str, strlen ("# rounds blocked"))) | ||
130 | { | ||
131 | return STAT_TYPE_BLOCKS; | ||
132 | } | ||
133 | else if (0 == strncmp ("# rounds", stat_str, strlen ("# rounds"))) | ||
134 | { | ||
135 | return STAT_TYPE_ROUNDS; | ||
136 | } | ||
137 | else if (0 == strncmp ("# push send issued", stat_str, strlen ("# push send issued"))) | ||
138 | { | ||
139 | return STAT_TYPE_ISSUED_PUSH_SEND; | ||
140 | } | ||
141 | else if (0 == strncmp ("# pull request send issued", stat_str, strlen ("# pull request send issued"))) | ||
142 | { | ||
143 | return STAT_TYPE_ISSUED_PULL_REQ; | ||
144 | } | ||
145 | else if (0 == strncmp ("# pull reply send issued", stat_str, strlen ("# pull reply send issued"))) | ||
146 | { | ||
147 | return STAT_TYPE_ISSUED_PULL_REP; | ||
148 | } | ||
149 | else if (0 == strncmp ("# pushes sent", stat_str, strlen ("# pushes sent"))) | ||
150 | { | ||
151 | return STAT_TYPE_SENT_PUSH_SEND; | ||
152 | } | ||
153 | else if (0 == strncmp ("# pull requests sent", stat_str, strlen ("# pull requests sent"))) | ||
154 | { | ||
155 | return STAT_TYPE_SENT_PULL_REQ; | ||
156 | } | ||
157 | else if (0 == strncmp ("# pull replys sent", stat_str, strlen ("# pull replys sent"))) | ||
158 | { | ||
159 | return STAT_TYPE_SENT_PULL_REP; | ||
160 | } | ||
161 | else if (0 == strncmp ("# push message received", stat_str, strlen ("# push message received"))) | ||
162 | { | ||
163 | return STAT_TYPE_RECV_PUSH_SEND; | ||
164 | } | ||
165 | else if (0 == strncmp ("# pull request message received", stat_str, strlen ("# pull request message received"))) | ||
166 | { | ||
167 | return STAT_TYPE_RECV_PULL_REQ; | ||
168 | } | ||
169 | else if (0 == strncmp ("# pull reply messages received", stat_str, strlen ("# pull reply messages received"))) | ||
170 | { | ||
171 | return STAT_TYPE_RECV_PULL_REP; | ||
172 | } | ||
173 | return STAT_TYPE_MAX; | ||
174 | } | ||
175 | |||
176 | |||
177 | /** | ||
178 | * @brief Converts #STAT_TYPE enum to the equivalent string representation that | ||
179 | * is stored with the statistics service. | ||
180 | * | ||
181 | * @param stat_type #STAT_TYPE enum | ||
182 | * | ||
183 | * @return string representation that matches statistics value | ||
184 | */ | ||
185 | char* stat_type_2_str (enum STAT_TYPE stat_type) | ||
186 | { | ||
187 | switch (stat_type) | ||
188 | { | ||
189 | case STAT_TYPE_ROUNDS: | ||
190 | return "# rounds"; | ||
191 | case STAT_TYPE_BLOCKS: | ||
192 | return "# rounds blocked"; | ||
193 | case STAT_TYPE_BLOCKS_MANY_PUSH: | ||
194 | return "# rounds blocked - too many pushes"; | ||
195 | case STAT_TYPE_BLOCKS_NO_PUSH: | ||
196 | return "# rounds blocked - no pushes"; | ||
197 | case STAT_TYPE_BLOCKS_NO_PULL: | ||
198 | return "# rounds blocked - no pull replies"; | ||
199 | case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL: | ||
200 | return "# rounds blocked - too many pushes, no pull replies"; | ||
201 | case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL: | ||
202 | return "# rounds blocked - no pushes, no pull replies"; | ||
203 | case STAT_TYPE_ISSUED_PUSH_SEND: | ||
204 | return "# push send issued"; | ||
205 | case STAT_TYPE_ISSUED_PULL_REQ: | ||
206 | return "# pull request send issued"; | ||
207 | case STAT_TYPE_ISSUED_PULL_REP: | ||
208 | return "# pull reply send issued"; | ||
209 | case STAT_TYPE_SENT_PUSH_SEND: | ||
210 | return "# pushes sent"; | ||
211 | case STAT_TYPE_SENT_PULL_REQ: | ||
212 | return "# pull requests sent"; | ||
213 | case STAT_TYPE_SENT_PULL_REP: | ||
214 | return "# pull replys sent"; | ||
215 | case STAT_TYPE_RECV_PUSH_SEND: | ||
216 | return "# push message received"; | ||
217 | case STAT_TYPE_RECV_PULL_REQ: | ||
218 | return "# pull request message received"; | ||
219 | case STAT_TYPE_RECV_PULL_REP: | ||
220 | return "# pull reply messages received"; | ||
221 | case STAT_TYPE_MAX: | ||
222 | default: | ||
223 | return "ERROR"; | ||
224 | ; | ||
225 | } | ||
226 | } | ||
227 | |||
228 | |||
229 | /** | ||
230 | * @brief Indicates whether peer should go off- or online | ||
231 | */ | ||
232 | enum PEER_ONLINE_DELTA { | ||
233 | /** | ||
234 | * @brief Indicates peer going online | ||
235 | */ | ||
236 | PEER_GO_ONLINE = 1, | ||
237 | /** | ||
238 | * @brief Indicates peer going offline | ||
239 | */ | ||
240 | PEER_GO_OFFLINE = -1, | ||
241 | }; | ||
242 | |||
243 | /** | ||
244 | * Operation map entry | ||
245 | */ | ||
246 | struct OpListEntry | ||
247 | { | ||
248 | /** | ||
249 | * DLL next ptr | ||
250 | */ | ||
251 | struct OpListEntry *next; | ||
252 | |||
253 | /** | ||
254 | * DLL prev ptr | ||
255 | */ | ||
256 | struct OpListEntry *prev; | ||
257 | |||
258 | /** | ||
259 | * The testbed operation | ||
260 | */ | ||
261 | struct GNUNET_TESTBED_Operation *op; | ||
262 | |||
263 | /** | ||
264 | * Depending on whether we start or stop RPS service at the peer, set this to | ||
265 | * #PEER_GO_ONLINE (1) or #PEER_GO_OFFLINE (-1) | ||
266 | */ | ||
267 | enum PEER_ONLINE_DELTA delta; | ||
268 | |||
269 | /** | ||
270 | * Index of the regarding peer | ||
271 | */ | ||
272 | unsigned int index; | ||
273 | }; | ||
274 | |||
275 | /** | ||
276 | * OpList DLL head | ||
277 | */ | ||
278 | static struct OpListEntry *oplist_head; | ||
279 | |||
280 | /** | ||
281 | * OpList DLL tail | ||
282 | */ | ||
283 | static struct OpListEntry *oplist_tail; | ||
284 | |||
285 | |||
286 | /** | ||
287 | * A pending reply: A request was sent and the reply is pending. | ||
288 | */ | ||
289 | struct PendingReply | ||
290 | { | ||
291 | /** | ||
292 | * DLL next,prev ptr | ||
293 | */ | ||
294 | struct PendingReply *next; | ||
295 | struct PendingReply *prev; | ||
296 | |||
297 | /** | ||
298 | * Handle to the request we are waiting for | ||
299 | */ | ||
300 | struct GNUNET_RPS_Request_Handle *req_handle; | ||
301 | |||
302 | /** | ||
303 | * The peer that requested | ||
304 | */ | ||
305 | struct RPSPeer *rps_peer; | ||
306 | }; | ||
307 | |||
308 | |||
309 | /** | ||
310 | * A pending request: A request was not made yet but is scheduled for later. | ||
311 | */ | ||
312 | struct PendingRequest | ||
313 | { | ||
314 | /** | ||
315 | * DLL next,prev ptr | ||
316 | */ | ||
317 | struct PendingRequest *next; | ||
318 | struct PendingRequest *prev; | ||
319 | |||
320 | /** | ||
321 | * Handle to the request we are waiting for | ||
322 | */ | ||
323 | struct GNUNET_SCHEDULER_Task *request_task; | ||
324 | |||
325 | /** | ||
326 | * The peer that requested | ||
327 | */ | ||
328 | struct RPSPeer *rps_peer; | ||
329 | }; | ||
330 | |||
331 | |||
332 | /** | ||
333 | * Information we track for each peer. | ||
334 | */ | ||
335 | struct RPSPeer | ||
336 | { | ||
337 | /** | ||
338 | * Index of the peer. | ||
339 | */ | ||
340 | unsigned int index; | ||
341 | |||
342 | /** | ||
343 | * Handle for RPS connect operation. | ||
344 | */ | ||
345 | struct GNUNET_TESTBED_Operation *op; | ||
346 | |||
347 | /** | ||
348 | * Handle to RPS service. | ||
349 | */ | ||
350 | struct GNUNET_RPS_Handle *rps_handle; | ||
351 | |||
352 | /** | ||
353 | * ID of the peer. | ||
354 | */ | ||
355 | struct GNUNET_PeerIdentity *peer_id; | ||
356 | |||
357 | /** | ||
358 | * A request handle to check for an request | ||
359 | */ | ||
360 | //struct GNUNET_RPS_Request_Handle *req_handle; | ||
361 | |||
362 | /** | ||
363 | * Peer on- or offline? | ||
364 | */ | ||
365 | int online; | ||
366 | |||
367 | /** | ||
368 | * Number of Peer IDs to request during the whole test | ||
369 | */ | ||
370 | unsigned int num_ids_to_request; | ||
371 | |||
372 | /** | ||
373 | * Pending requests DLL | ||
374 | */ | ||
375 | struct PendingRequest *pending_req_head; | ||
376 | struct PendingRequest *pending_req_tail; | ||
377 | |||
378 | /** | ||
379 | * Number of pending requests | ||
380 | */ | ||
381 | unsigned int num_pending_reqs; | ||
382 | |||
383 | /** | ||
384 | * Pending replies DLL | ||
385 | */ | ||
386 | struct PendingReply *pending_rep_head; | ||
387 | struct PendingReply *pending_rep_tail; | ||
388 | |||
389 | /** | ||
390 | * Number of pending replies | ||
391 | */ | ||
392 | unsigned int num_pending_reps; | ||
393 | |||
394 | /** | ||
395 | * Number of received PeerIDs | ||
396 | */ | ||
397 | unsigned int num_recv_ids; | ||
398 | |||
399 | /** | ||
400 | * Pending operation on that peer | ||
401 | */ | ||
402 | const struct OpListEntry *entry_op_manage; | ||
403 | |||
404 | /** | ||
405 | * Testbed operation to connect to statistics service | ||
406 | */ | ||
407 | struct GNUNET_TESTBED_Operation *stat_op; | ||
408 | |||
409 | /** | ||
410 | * Handle to the statistics service | ||
411 | */ | ||
412 | struct GNUNET_STATISTICS_Handle *stats_h; | ||
413 | |||
414 | /** | ||
415 | * @brief flags to indicate which statistics values have been already | ||
416 | * collected from the statistics service. | ||
417 | * Used to check whether we are able to shutdown. | ||
418 | */ | ||
419 | uint32_t stat_collected_flags; | ||
420 | |||
421 | /** | ||
422 | * @brief File name of the file the stats are finally written to | ||
423 | */ | ||
424 | const char *file_name_stats; | ||
425 | |||
426 | /** | ||
427 | * @brief File name of the file the stats are finally written to | ||
428 | */ | ||
429 | const char *file_name_probs; | ||
430 | |||
431 | /** | ||
432 | * @brief The current view | ||
433 | */ | ||
434 | struct GNUNET_PeerIdentity *cur_view; | ||
435 | |||
436 | /** | ||
437 | * @brief Number of peers in the #cur_view. | ||
438 | */ | ||
439 | uint32_t cur_view_count; | ||
440 | |||
441 | /** | ||
442 | * @brief Number of occurrences in other peer's view | ||
443 | */ | ||
444 | uint32_t count_in_views; | ||
445 | |||
446 | /** | ||
447 | * @brief statistics values | ||
448 | */ | ||
449 | uint64_t stats[STAT_TYPE_MAX]; | ||
450 | }; | ||
451 | |||
452 | /** | ||
453 | * Information for all the peers. | ||
454 | */ | ||
455 | static struct RPSPeer *rps_peers; | ||
456 | |||
457 | /** | ||
458 | * Peermap to get the index of a given peer ID quick. | ||
459 | */ | ||
460 | static struct GNUNET_CONTAINER_MultiPeerMap *peer_map; | ||
461 | |||
462 | /** | ||
463 | * IDs of the peers. | ||
464 | */ | ||
465 | static struct GNUNET_PeerIdentity *rps_peer_ids; | ||
466 | |||
467 | /** | ||
468 | * ID of the targeted peer. | ||
469 | */ | ||
470 | static struct GNUNET_PeerIdentity *target_peer; | ||
471 | |||
472 | /** | ||
473 | * ID of the peer that requests for the evaluation. | ||
474 | */ | ||
475 | static struct RPSPeer *eval_peer; | ||
476 | |||
477 | /** | ||
478 | * Number of online peers. | ||
479 | */ | ||
480 | static unsigned int num_peers_online; | ||
481 | |||
482 | /** | ||
483 | * @brief The added sizes of the peer's views | ||
484 | */ | ||
485 | static unsigned int view_sizes; | ||
486 | |||
487 | /** | ||
488 | * Return value from 'main'. | ||
489 | */ | ||
490 | static int ok; | ||
491 | |||
492 | /** | ||
493 | * Identifier for the churn task that runs periodically | ||
494 | */ | ||
495 | static struct GNUNET_SCHEDULER_Task *post_test_task; | ||
496 | |||
497 | /** | ||
498 | * Identifier for the churn task that runs periodically | ||
499 | */ | ||
500 | static struct GNUNET_SCHEDULER_Task *shutdown_task; | ||
501 | |||
502 | /** | ||
503 | * Identifier for the churn task that runs periodically | ||
504 | */ | ||
505 | static struct GNUNET_SCHEDULER_Task *churn_task; | ||
506 | |||
507 | /** | ||
508 | * Called to initialise the given RPSPeer | ||
509 | */ | ||
510 | typedef void (*InitPeer) (struct RPSPeer *rps_peer); | ||
511 | |||
512 | /** | ||
513 | * @brief Called directly after connecting to the service | ||
514 | * | ||
515 | * @param rps_peer Specific peer the function is called on | ||
516 | * @param h the handle to the rps service | ||
517 | */ | ||
518 | typedef void (*PreTest) (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h); | ||
519 | |||
520 | /** | ||
521 | * @brief Executes functions to test the api/service for a given peer | ||
522 | * | ||
523 | * Called from within #rps_connect_complete_cb () | ||
524 | * Implemented by #churn_test_cb, #profiler_cb, #mal_cb, #single_req_cb, | ||
525 | * #delay_req_cb, #seed_big_cb, #single_peer_seed_cb, #seed_cb, #req_cancel_cb | ||
526 | * | ||
527 | * @param rps_peer the peer the task runs on | ||
528 | */ | ||
529 | typedef void (*MainTest) (struct RPSPeer *rps_peer); | ||
530 | |||
531 | /** | ||
532 | * Callback called once the requested random peers are available | ||
533 | */ | ||
534 | typedef void (*ReplyHandle) (void *cls, | ||
535 | uint64_t n, | ||
536 | const struct GNUNET_PeerIdentity *recv_peers); | ||
537 | |||
538 | /** | ||
539 | * Called directly before disconnecting from the service | ||
540 | */ | ||
541 | typedef void (*PostTest) (struct RPSPeer *peer); | ||
542 | |||
543 | /** | ||
544 | * Function called after disconnect to evaluate test success | ||
545 | */ | ||
546 | typedef int (*EvaluationCallback) (void); | ||
547 | |||
548 | /** | ||
549 | * @brief Do we have Churn? | ||
550 | */ | ||
551 | enum OPTION_CHURN { | ||
552 | /** | ||
553 | * @brief If we have churn this is set | ||
554 | */ | ||
555 | HAVE_CHURN, | ||
556 | /** | ||
557 | * @brief If we have no churn this is set | ||
558 | */ | ||
559 | HAVE_NO_CHURN, | ||
560 | }; | ||
561 | |||
562 | /** | ||
563 | * @brief Is it ok to quit the test before the timeout? | ||
564 | */ | ||
565 | enum OPTION_QUICK_QUIT { | ||
566 | /** | ||
567 | * @brief It is ok for the test to quit before the timeout triggers | ||
568 | */ | ||
569 | HAVE_QUICK_QUIT, | ||
570 | |||
571 | /** | ||
572 | * @brief It is NOT ok for the test to quit before the timeout triggers | ||
573 | */ | ||
574 | HAVE_NO_QUICK_QUIT, | ||
575 | }; | ||
576 | |||
577 | /** | ||
578 | * @brief Do we collect statistics at the end? | ||
579 | */ | ||
580 | enum OPTION_COLLECT_STATISTICS { | ||
581 | /** | ||
582 | * @brief We collect statistics at the end | ||
583 | */ | ||
584 | COLLECT_STATISTICS, | ||
585 | |||
586 | /** | ||
587 | * @brief We do not collect statistics at the end | ||
588 | */ | ||
589 | NO_COLLECT_STATISTICS, | ||
590 | }; | ||
591 | |||
592 | /** | ||
593 | * @brief Do we collect views during run? | ||
594 | */ | ||
595 | enum OPTION_COLLECT_VIEW { | ||
596 | /** | ||
597 | * @brief We collect view during run | ||
598 | */ | ||
599 | COLLECT_VIEW, | ||
600 | |||
601 | /** | ||
602 | * @brief We do not collect the view during run | ||
603 | */ | ||
604 | NO_COLLECT_VIEW, | ||
605 | }; | ||
606 | |||
607 | /** | ||
608 | * Structure to define a single test | ||
609 | */ | ||
610 | struct SingleTestRun | ||
611 | { | ||
612 | /** | ||
613 | * Name of the test | ||
614 | */ | ||
615 | char *name; | ||
616 | |||
617 | /** | ||
618 | * Called with a single peer in order to initialise that peer | ||
619 | */ | ||
620 | InitPeer init_peer; | ||
621 | |||
622 | /** | ||
623 | * Called directly after connecting to the service | ||
624 | */ | ||
625 | PreTest pre_test; | ||
626 | |||
627 | /** | ||
628 | * Main function for each peer | ||
629 | */ | ||
630 | MainTest main_test; | ||
631 | |||
632 | /** | ||
633 | * Callback called once the requested peers are available | ||
634 | */ | ||
635 | ReplyHandle reply_handle; | ||
636 | |||
637 | /** | ||
638 | * Called directly before disconnecting from the service | ||
639 | */ | ||
640 | PostTest post_test; | ||
641 | |||
642 | /** | ||
643 | * Function to evaluate the test results | ||
644 | */ | ||
645 | EvaluationCallback eval_cb; | ||
646 | |||
647 | /** | ||
648 | * Request interval | ||
649 | */ | ||
650 | uint32_t request_interval; | ||
651 | |||
652 | /** | ||
653 | * Number of Requests to make. | ||
654 | */ | ||
655 | uint32_t num_requests; | ||
656 | |||
657 | /** | ||
658 | * Run with (-out) churn | ||
659 | */ | ||
660 | enum OPTION_CHURN have_churn; | ||
661 | |||
662 | /** | ||
663 | * Quit test before timeout? | ||
664 | */ | ||
665 | enum OPTION_QUICK_QUIT have_quick_quit; | ||
666 | |||
667 | /** | ||
668 | * Collect statistics at the end? | ||
669 | */ | ||
670 | enum OPTION_COLLECT_STATISTICS have_collect_statistics; | ||
671 | |||
672 | /** | ||
673 | * Collect view during run? | ||
674 | */ | ||
675 | enum OPTION_COLLECT_VIEW have_collect_view; | ||
676 | |||
677 | /** | ||
678 | * @brief Mark which values from the statistics service to collect at the end | ||
679 | * of the run | ||
680 | */ | ||
681 | uint32_t stat_collect_flags; | ||
682 | } cur_test_run; | ||
683 | |||
684 | /** | ||
685 | * Did we finish the test? | ||
686 | */ | ||
687 | static int post_test; | ||
688 | |||
689 | /** | ||
690 | * Are we shutting down? | ||
691 | */ | ||
692 | static int in_shutdown; | ||
693 | |||
694 | /** | ||
695 | * Append arguments to file | ||
696 | */ | ||
697 | static void | ||
698 | tofile_ (const char *file_name, const char *line) | ||
699 | { | ||
700 | struct GNUNET_DISK_FileHandle *f; | ||
701 | /* char output_buffer[512]; */ | ||
702 | size_t size; | ||
703 | /* int size; */ | ||
704 | size_t size2; | ||
705 | |||
706 | if (NULL == (f = GNUNET_DISK_file_open (file_name, | ||
707 | GNUNET_DISK_OPEN_APPEND | | ||
708 | GNUNET_DISK_OPEN_WRITE | | ||
709 | GNUNET_DISK_OPEN_CREATE, | ||
710 | GNUNET_DISK_PERM_USER_READ | | ||
711 | GNUNET_DISK_PERM_USER_WRITE | | ||
712 | GNUNET_DISK_PERM_GROUP_READ | | ||
713 | GNUNET_DISK_PERM_OTHER_READ))) | ||
714 | { | ||
715 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
716 | "Not able to open file %s\n", | ||
717 | file_name); | ||
718 | return; | ||
719 | } | ||
720 | /* size = GNUNET_snprintf (output_buffer, | ||
721 | sizeof (output_buffer), | ||
722 | "%llu %s\n", | ||
723 | GNUNET_TIME_absolute_get ().abs_value_us, | ||
724 | line); | ||
725 | if (0 > size) | ||
726 | { | ||
727 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
728 | "Failed to write string to buffer (size: %i)\n", | ||
729 | size); | ||
730 | return; | ||
731 | } */ | ||
732 | |||
733 | size = strlen (line) * sizeof (char); | ||
734 | |||
735 | size2 = GNUNET_DISK_file_write (f, line, size); | ||
736 | if (size != size2) | ||
737 | { | ||
738 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
739 | "Unable to write to file! (Size: %lu, size2: %lu)\n", | ||
740 | size, | ||
741 | size2); | ||
742 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
743 | { | ||
744 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
745 | "Unable to close file\n"); | ||
746 | } | ||
747 | return; | ||
748 | } | ||
749 | |||
750 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
751 | { | ||
752 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
753 | "Unable to close file\n"); | ||
754 | } | ||
755 | } | ||
756 | |||
757 | /** | ||
758 | * This function is used to facilitate writing important information to disk | ||
759 | */ | ||
760 | #define tofile(file_name, ...) do {\ | ||
761 | char tmp_buf[512];\ | ||
762 | int size;\ | ||
763 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | ||
764 | if (0 > size)\ | ||
765 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ | ||
766 | "Failed to create tmp_buf\n");\ | ||
767 | else\ | ||
768 | tofile_(file_name,tmp_buf);\ | ||
769 | } while (0); | ||
770 | |||
771 | |||
772 | /** | ||
773 | * Write the ids and their according index in the given array to a file | ||
774 | * Unused | ||
775 | */ | ||
776 | /* static void | ||
777 | ids_to_file (char *file_name, | ||
778 | struct GNUNET_PeerIdentity *peer_ids, | ||
779 | unsigned int num_peer_ids) | ||
780 | { | ||
781 | unsigned int i; | ||
782 | |||
783 | for (i=0 ; i < num_peer_ids ; i++) | ||
784 | { | ||
785 | to_file (file_name, | ||
786 | "%u\t%s", | ||
787 | i, | ||
788 | GNUNET_i2s_full (&peer_ids[i])); | ||
789 | } | ||
790 | } */ | ||
791 | |||
792 | /** | ||
793 | * Test the success of a single test | ||
794 | */ | ||
795 | static int | ||
796 | evaluate (void) | ||
797 | { | ||
798 | unsigned int i; | ||
799 | int tmp_ok; | ||
800 | |||
801 | tmp_ok = 1; | ||
802 | |||
803 | for (i = 0; i < num_peers; i++) | ||
804 | { | ||
805 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
806 | "%u. peer [%s] received %u of %u expected peer_ids: %i\n", | ||
807 | i, | ||
808 | GNUNET_i2s (rps_peers[i].peer_id), | ||
809 | rps_peers[i].num_recv_ids, | ||
810 | rps_peers[i].num_ids_to_request, | ||
811 | (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); | ||
812 | tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids); | ||
813 | } | ||
814 | return tmp_ok? 0 : 1; | ||
815 | } | ||
816 | |||
817 | |||
818 | /** | ||
819 | * Creates an oplist entry and adds it to the oplist DLL | ||
820 | */ | ||
821 | static struct OpListEntry * | ||
822 | make_oplist_entry () | ||
823 | { | ||
824 | struct OpListEntry *entry; | ||
825 | |||
826 | entry = GNUNET_new (struct OpListEntry); | ||
827 | GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); | ||
828 | return entry; | ||
829 | } | ||
830 | |||
831 | |||
832 | /** | ||
833 | * @brief Checks if given peer already received its statistics value from the | ||
834 | * statistics service. | ||
835 | * | ||
836 | * @param rps_peer the peer to check for | ||
837 | * | ||
838 | * @return #GNUNET_YES if so | ||
839 | * #GNUNET_NO otherwise | ||
840 | */ | ||
841 | static int check_statistics_collect_completed_single_peer ( | ||
842 | const struct RPSPeer *rps_peer) | ||
843 | { | ||
844 | if (cur_test_run.stat_collect_flags != | ||
845 | (cur_test_run.stat_collect_flags & | ||
846 | rps_peer->stat_collected_flags)) | ||
847 | { | ||
848 | return GNUNET_NO; | ||
849 | } | ||
850 | return GNUNET_YES; | ||
851 | } | ||
852 | /** | ||
853 | * @brief Checks if all peers already received their statistics value from the | ||
854 | * statistics service. | ||
855 | * | ||
856 | * @return #GNUNET_YES if so | ||
857 | * #GNUNET_NO otherwise | ||
858 | */ | ||
859 | static int check_statistics_collect_completed () | ||
860 | { | ||
861 | uint32_t i; | ||
862 | |||
863 | for (i = 0; i < num_peers; i++) | ||
864 | { | ||
865 | if (GNUNET_NO == check_statistics_collect_completed_single_peer (&rps_peers[i])) | ||
866 | { | ||
867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
868 | "At least Peer %" PRIu32 " did not yet receive all statistics values\n", | ||
869 | i); | ||
870 | return GNUNET_NO; | ||
871 | } | ||
872 | } | ||
873 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
874 | "All peers received their statistics values\n"); | ||
875 | return GNUNET_YES; | ||
876 | } | ||
877 | |||
878 | /** | ||
879 | * Task run on timeout to shut everything down. | ||
880 | */ | ||
881 | static void | ||
882 | shutdown_op (void *cls) | ||
883 | { | ||
884 | unsigned int i; | ||
885 | |||
886 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
887 | "Shutdown task scheduled, going down.\n"); | ||
888 | in_shutdown = GNUNET_YES; | ||
889 | if (NULL != post_test_task) | ||
890 | { | ||
891 | GNUNET_SCHEDULER_cancel (post_test_task); | ||
892 | } | ||
893 | if (NULL != churn_task) | ||
894 | { | ||
895 | GNUNET_SCHEDULER_cancel (churn_task); | ||
896 | churn_task = NULL; | ||
897 | } | ||
898 | for (i = 0; i < num_peers; i++) | ||
899 | { | ||
900 | if (NULL != rps_peers[i].rps_handle) | ||
901 | { | ||
902 | GNUNET_RPS_disconnect (rps_peers[i].rps_handle); | ||
903 | } | ||
904 | if (NULL != rps_peers[i].op) | ||
905 | { | ||
906 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | ||
907 | } | ||
908 | } | ||
909 | } | ||
910 | |||
911 | |||
912 | /** | ||
913 | * Task run on timeout to collect statistics and potentially shut down. | ||
914 | */ | ||
915 | static void | ||
916 | post_test_op (void *cls) | ||
917 | { | ||
918 | unsigned int i; | ||
919 | |||
920 | post_test_task = NULL; | ||
921 | post_test = GNUNET_YES; | ||
922 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
923 | "Post test task scheduled, going down.\n"); | ||
924 | if (NULL != churn_task) | ||
925 | { | ||
926 | GNUNET_SCHEDULER_cancel (churn_task); | ||
927 | churn_task = NULL; | ||
928 | } | ||
929 | for (i = 0; i < num_peers; i++) | ||
930 | { | ||
931 | if (NULL != rps_peers[i].op) | ||
932 | { | ||
933 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | ||
934 | rps_peers[i].op = NULL; | ||
935 | } | ||
936 | if (NULL != cur_test_run.post_test) | ||
937 | { | ||
938 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); | ||
939 | cur_test_run.post_test (&rps_peers[i]); | ||
940 | } | ||
941 | } | ||
942 | /* If we do not collect statistics, shut down directly */ | ||
943 | if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics || | ||
944 | GNUNET_YES == check_statistics_collect_completed()) | ||
945 | { | ||
946 | GNUNET_SCHEDULER_shutdown (); | ||
947 | } | ||
948 | } | ||
949 | |||
950 | |||
951 | /** | ||
952 | * Seed peers. | ||
953 | */ | ||
954 | static void | ||
955 | seed_peers (void *cls) | ||
956 | { | ||
957 | struct RPSPeer *peer = cls; | ||
958 | unsigned int amount; | ||
959 | unsigned int i; | ||
960 | |||
961 | // TODO if malicious don't seed mal peers | ||
962 | amount = round (.5 * num_peers); | ||
963 | |||
964 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); | ||
965 | for (i = 0 ; i < amount ; i++) | ||
966 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", | ||
967 | i, | ||
968 | GNUNET_i2s (&rps_peer_ids[i])); | ||
969 | |||
970 | GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids); | ||
971 | } | ||
972 | |||
973 | |||
974 | /** | ||
975 | * Get the id of peer i. | ||
976 | */ | ||
977 | void | ||
978 | info_cb (void *cb_cls, | ||
979 | struct GNUNET_TESTBED_Operation *op, | ||
980 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
981 | const char *emsg) | ||
982 | { | ||
983 | struct OpListEntry *entry = (struct OpListEntry *) cb_cls; | ||
984 | |||
985 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
986 | { | ||
987 | return; | ||
988 | } | ||
989 | |||
990 | if (NULL == pinfo || NULL != emsg) | ||
991 | { | ||
992 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); | ||
993 | GNUNET_TESTBED_operation_done (entry->op); | ||
994 | return; | ||
995 | } | ||
996 | |||
997 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
998 | "Peer %u is %s\n", | ||
999 | entry->index, | ||
1000 | GNUNET_i2s (pinfo->result.id)); | ||
1001 | |||
1002 | rps_peer_ids[entry->index] = *(pinfo->result.id); | ||
1003 | rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; | ||
1004 | |||
1005 | GNUNET_assert (GNUNET_OK == | ||
1006 | GNUNET_CONTAINER_multipeermap_put (peer_map, | ||
1007 | &rps_peer_ids[entry->index], | ||
1008 | &rps_peers[entry->index], | ||
1009 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1010 | tofile ("/tmp/rps/peer_ids", | ||
1011 | "%u\t%s\n", | ||
1012 | entry->index, | ||
1013 | GNUNET_i2s_full (&rps_peer_ids[entry->index])); | ||
1014 | |||
1015 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | ||
1016 | GNUNET_TESTBED_operation_done (entry->op); | ||
1017 | GNUNET_free (entry); | ||
1018 | } | ||
1019 | |||
1020 | |||
1021 | /** | ||
1022 | * Callback to be called when RPS service connect operation is completed | ||
1023 | * | ||
1024 | * @param cls the callback closure from functions generating an operation | ||
1025 | * @param op the operation that has been finished | ||
1026 | * @param ca_result the RPS service handle returned from rps_connect_adapter | ||
1027 | * @param emsg error message in case the operation has failed; will be NULL if | ||
1028 | * operation has executed successfully. | ||
1029 | */ | ||
1030 | static void | ||
1031 | rps_connect_complete_cb (void *cls, | ||
1032 | struct GNUNET_TESTBED_Operation *op, | ||
1033 | void *ca_result, | ||
1034 | const char *emsg) | ||
1035 | { | ||
1036 | struct RPSPeer *rps_peer = cls; | ||
1037 | struct GNUNET_RPS_Handle *rps = ca_result; | ||
1038 | |||
1039 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1040 | { | ||
1041 | return; | ||
1042 | } | ||
1043 | |||
1044 | rps_peer->rps_handle = rps; | ||
1045 | rps_peer->online = GNUNET_YES; | ||
1046 | num_peers_online++; | ||
1047 | |||
1048 | GNUNET_assert (op == rps_peer->op); | ||
1049 | if (NULL != emsg) | ||
1050 | { | ||
1051 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1052 | "Failed to connect to RPS service: %s\n", | ||
1053 | emsg); | ||
1054 | ok = 1; | ||
1055 | GNUNET_SCHEDULER_shutdown (); | ||
1056 | return; | ||
1057 | } | ||
1058 | |||
1059 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); | ||
1060 | |||
1061 | cur_test_run.main_test (rps_peer); | ||
1062 | } | ||
1063 | |||
1064 | |||
1065 | /** | ||
1066 | * Adapter function called to establish a connection to | ||
1067 | * the RPS service. | ||
1068 | * | ||
1069 | * @param cls closure | ||
1070 | * @param cfg configuration of the peer to connect to; will be available until | ||
1071 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
1072 | * from GNUNET_TESTBED_service_connect() | ||
1073 | * @return service handle to return in 'op_result', NULL on error | ||
1074 | */ | ||
1075 | static void * | ||
1076 | rps_connect_adapter (void *cls, | ||
1077 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
1078 | { | ||
1079 | struct GNUNET_RPS_Handle *h; | ||
1080 | |||
1081 | h = GNUNET_RPS_connect (cfg); | ||
1082 | |||
1083 | if (NULL != cur_test_run.pre_test) | ||
1084 | cur_test_run.pre_test (cls, h); | ||
1085 | |||
1086 | return h; | ||
1087 | } | ||
1088 | |||
1089 | /** | ||
1090 | * Called to open a connection to the peer's statistics | ||
1091 | * | ||
1092 | * @param cls peer context | ||
1093 | * @param cfg configuration of the peer to connect to; will be available until | ||
1094 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
1095 | * from GNUNET_TESTBED_service_connect() | ||
1096 | * @return service handle to return in 'op_result', NULL on error | ||
1097 | */ | ||
1098 | static void * | ||
1099 | stat_connect_adapter (void *cls, | ||
1100 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
1101 | { | ||
1102 | struct RPSPeer *peer = cls; | ||
1103 | |||
1104 | peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg); | ||
1105 | return peer->stats_h; | ||
1106 | } | ||
1107 | |||
1108 | /** | ||
1109 | * Called to disconnect from peer's statistics service | ||
1110 | * | ||
1111 | * @param cls peer context | ||
1112 | * @param op_result service handle returned from the connect adapter | ||
1113 | */ | ||
1114 | static void | ||
1115 | stat_disconnect_adapter (void *cls, void *op_result) | ||
1116 | { | ||
1117 | struct RPSPeer *peer = cls; | ||
1118 | |||
1119 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel | ||
1120 | // (peer->stats_h, "core", "# peers connected", | ||
1121 | // stat_iterator, peer)); | ||
1122 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel | ||
1123 | // (peer->stats_h, "nse", "# peers connected", | ||
1124 | // stat_iterator, peer)); | ||
1125 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); | ||
1126 | peer->stats_h = NULL; | ||
1127 | } | ||
1128 | |||
1129 | /** | ||
1130 | * Called after successfully opening a connection to a peer's statistics | ||
1131 | * service; we register statistics monitoring for CORE and NSE here. | ||
1132 | * | ||
1133 | * @param cls the callback closure from functions generating an operation | ||
1134 | * @param op the operation that has been finished | ||
1135 | * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() | ||
1136 | * @param emsg error message in case the operation has failed; will be NULL if | ||
1137 | * operation has executed successfully. | ||
1138 | */ | ||
1139 | static void | ||
1140 | stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | ||
1141 | void *ca_result, const char *emsg ) | ||
1142 | { | ||
1143 | //struct GNUNET_STATISTICS_Handle *sh = ca_result; | ||
1144 | //struct RPSPeer *peer = (struct RPSPeer *) cls; | ||
1145 | |||
1146 | if (NULL != emsg) | ||
1147 | { | ||
1148 | GNUNET_break (0); | ||
1149 | return; | ||
1150 | } | ||
1151 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch | ||
1152 | // (sh, "core", "# peers connected", | ||
1153 | // stat_iterator, peer)); | ||
1154 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch | ||
1155 | // (sh, "nse", "# peers connected", | ||
1156 | // stat_iterator, peer)); | ||
1157 | } | ||
1158 | |||
1159 | |||
1160 | /** | ||
1161 | * Adapter function called to destroy connection to | ||
1162 | * RPS service. | ||
1163 | * | ||
1164 | * @param cls closure | ||
1165 | * @param op_result service handle returned from the connect adapter | ||
1166 | */ | ||
1167 | static void | ||
1168 | rps_disconnect_adapter (void *cls, | ||
1169 | void *op_result) | ||
1170 | { | ||
1171 | struct RPSPeer *peer = cls; | ||
1172 | struct GNUNET_RPS_Handle *h = op_result; | ||
1173 | |||
1174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnect_adapter()\n"); | ||
1175 | GNUNET_assert (NULL != peer); | ||
1176 | GNUNET_RPS_disconnect (h); | ||
1177 | peer->rps_handle = NULL; | ||
1178 | } | ||
1179 | |||
1180 | |||
1181 | /*********************************************************************** | ||
1182 | * Definition of tests | ||
1183 | ***********************************************************************/ | ||
1184 | |||
1185 | /** | ||
1186 | * Callback to call on receipt of a reply | ||
1187 | * | ||
1188 | * @param cls closure | ||
1189 | * @param n number of peers | ||
1190 | * @param recv_peers the received peers | ||
1191 | */ | ||
1192 | static void | ||
1193 | default_reply_handle (void *cls, | ||
1194 | uint64_t n, | ||
1195 | const struct GNUNET_PeerIdentity *recv_peers) | ||
1196 | { | ||
1197 | struct RPSPeer *rps_peer; | ||
1198 | struct PendingReply *pending_rep = (struct PendingReply *) cls; | ||
1199 | unsigned int i; | ||
1200 | |||
1201 | rps_peer = pending_rep->rps_peer; | ||
1202 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, | ||
1203 | rps_peer->pending_rep_tail, | ||
1204 | pending_rep); | ||
1205 | rps_peer->num_pending_reps--; | ||
1206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1207 | "[%s] got %" PRIu64 " peers:\n", | ||
1208 | GNUNET_i2s (rps_peer->peer_id), | ||
1209 | n); | ||
1210 | |||
1211 | for (i = 0; i < n; i++) | ||
1212 | { | ||
1213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1214 | "%u: %s\n", | ||
1215 | i, | ||
1216 | GNUNET_i2s (&recv_peers[i])); | ||
1217 | |||
1218 | rps_peer->num_recv_ids++; | ||
1219 | } | ||
1220 | |||
1221 | if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) | ||
1222 | { | ||
1223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); | ||
1224 | GNUNET_assert (NULL != post_test_task); | ||
1225 | GNUNET_SCHEDULER_cancel (post_test_task); | ||
1226 | post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); | ||
1227 | GNUNET_assert (NULL!= post_test_task); | ||
1228 | } | ||
1229 | } | ||
1230 | |||
1231 | /** | ||
1232 | * Request random peers. | ||
1233 | */ | ||
1234 | static void | ||
1235 | request_peers (void *cls) | ||
1236 | { | ||
1237 | struct PendingRequest *pending_req = cls; | ||
1238 | struct RPSPeer *rps_peer; | ||
1239 | struct PendingReply *pending_rep; | ||
1240 | |||
1241 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1242 | return; | ||
1243 | rps_peer = pending_req->rps_peer; | ||
1244 | GNUNET_assert (1 <= rps_peer->num_pending_reqs); | ||
1245 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, | ||
1246 | rps_peer->pending_req_tail, | ||
1247 | pending_req); | ||
1248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1249 | "Requesting one peer\n"); | ||
1250 | pending_rep = GNUNET_new (struct PendingReply); | ||
1251 | pending_rep->rps_peer = rps_peer; | ||
1252 | pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, | ||
1253 | 1, | ||
1254 | cur_test_run.reply_handle, | ||
1255 | pending_rep); | ||
1256 | GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head, | ||
1257 | rps_peer->pending_rep_tail, | ||
1258 | pending_rep); | ||
1259 | rps_peer->num_pending_reps++; | ||
1260 | rps_peer->num_pending_reqs--; | ||
1261 | } | ||
1262 | |||
1263 | static void | ||
1264 | cancel_pending_req (struct PendingRequest *pending_req) | ||
1265 | { | ||
1266 | struct RPSPeer *rps_peer; | ||
1267 | |||
1268 | rps_peer = pending_req->rps_peer; | ||
1269 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, | ||
1270 | rps_peer->pending_req_tail, | ||
1271 | pending_req); | ||
1272 | rps_peer->num_pending_reqs--; | ||
1273 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1274 | "Cancelling pending request\n"); | ||
1275 | GNUNET_SCHEDULER_cancel (pending_req->request_task); | ||
1276 | GNUNET_free (pending_req); | ||
1277 | } | ||
1278 | |||
1279 | static void | ||
1280 | cancel_request (struct PendingReply *pending_rep) | ||
1281 | { | ||
1282 | struct RPSPeer *rps_peer; | ||
1283 | |||
1284 | rps_peer = pending_rep->rps_peer; | ||
1285 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, | ||
1286 | rps_peer->pending_rep_tail, | ||
1287 | pending_rep); | ||
1288 | rps_peer->num_pending_reps--; | ||
1289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1290 | "Cancelling request\n"); | ||
1291 | GNUNET_RPS_request_cancel (pending_rep->req_handle); | ||
1292 | GNUNET_free (pending_rep); | ||
1293 | } | ||
1294 | |||
1295 | |||
1296 | /** | ||
1297 | * Schedule requests for peer @a rps_peer that have neither been scheduled, nor | ||
1298 | * issued, nor replied | ||
1299 | */ | ||
1300 | void | ||
1301 | schedule_missing_requests (struct RPSPeer *rps_peer) | ||
1302 | { | ||
1303 | unsigned int i; | ||
1304 | struct PendingRequest *pending_req; | ||
1305 | |||
1306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1307 | "Scheduling %u - %u missing requests\n", | ||
1308 | rps_peer->num_ids_to_request, | ||
1309 | rps_peer->num_pending_reqs + rps_peer->num_pending_reps); | ||
1310 | GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= | ||
1311 | rps_peer->num_ids_to_request); | ||
1312 | for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps; | ||
1313 | i < rps_peer->num_ids_to_request; i++) | ||
1314 | { | ||
1315 | pending_req = GNUNET_new (struct PendingRequest); | ||
1316 | pending_req->rps_peer = rps_peer; | ||
1317 | pending_req->request_task = GNUNET_SCHEDULER_add_delayed ( | ||
1318 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
1319 | cur_test_run.request_interval * i), | ||
1320 | request_peers, | ||
1321 | pending_req); | ||
1322 | GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head, | ||
1323 | rps_peer->pending_req_tail, | ||
1324 | pending_req); | ||
1325 | rps_peer->num_pending_reqs++; | ||
1326 | } | ||
1327 | } | ||
1328 | |||
1329 | void | ||
1330 | cancel_pending_req_rep (struct RPSPeer *rps_peer) | ||
1331 | { | ||
1332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1333 | "Cancelling all (pending) requests.\n"); | ||
1334 | while (NULL != rps_peer->pending_req_head) | ||
1335 | cancel_pending_req (rps_peer->pending_req_head); | ||
1336 | GNUNET_assert (0 == rps_peer->num_pending_reqs); | ||
1337 | while (NULL != rps_peer->pending_rep_head) | ||
1338 | cancel_request (rps_peer->pending_rep_head); | ||
1339 | GNUNET_assert (0 == rps_peer->num_pending_reps); | ||
1340 | } | ||
1341 | |||
1342 | /*********************************** | ||
1343 | * MALICIOUS | ||
1344 | ***********************************/ | ||
1345 | |||
1346 | /** | ||
1347 | * Initialise only non-mal RPSPeers | ||
1348 | */ | ||
1349 | static void mal_init_peer (struct RPSPeer *rps_peer) | ||
1350 | { | ||
1351 | if (rps_peer->index >= round (portion * num_peers)) | ||
1352 | rps_peer->num_ids_to_request = 1; | ||
1353 | } | ||
1354 | |||
1355 | |||
1356 | /** | ||
1357 | * @brief Set peers to (non-)malicious before execution | ||
1358 | * | ||
1359 | * Of signature #PreTest | ||
1360 | * | ||
1361 | * @param rps_peer the peer to set (non-) malicious | ||
1362 | * @param h the handle to the service | ||
1363 | */ | ||
1364 | static void | ||
1365 | mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) | ||
1366 | { | ||
1367 | #ifdef ENABLE_MALICIOUS | ||
1368 | uint32_t num_mal_peers; | ||
1369 | |||
1370 | GNUNET_assert ( (1 >= portion) && | ||
1371 | (0 < portion) ); | ||
1372 | num_mal_peers = round (portion * num_peers); | ||
1373 | |||
1374 | if (rps_peer->index < num_mal_peers) | ||
1375 | { | ||
1376 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1377 | "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", | ||
1378 | rps_peer->index, | ||
1379 | GNUNET_i2s (rps_peer->peer_id), | ||
1380 | num_mal_peers); | ||
1381 | |||
1382 | GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, | ||
1383 | rps_peer_ids, target_peer); | ||
1384 | } | ||
1385 | #endif /* ENABLE_MALICIOUS */ | ||
1386 | } | ||
1387 | |||
1388 | static void | ||
1389 | mal_cb (struct RPSPeer *rps_peer) | ||
1390 | { | ||
1391 | uint32_t num_mal_peers; | ||
1392 | |||
1393 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1394 | { | ||
1395 | return; | ||
1396 | } | ||
1397 | |||
1398 | #ifdef ENABLE_MALICIOUS | ||
1399 | GNUNET_assert ( (1 >= portion) && | ||
1400 | (0 < portion) ); | ||
1401 | num_mal_peers = round (portion * num_peers); | ||
1402 | |||
1403 | if (rps_peer->index >= num_mal_peers) | ||
1404 | { /* It's useless to ask a malicious peer about a random sample - | ||
1405 | it's not sampling */ | ||
1406 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), | ||
1407 | seed_peers, rps_peer); | ||
1408 | schedule_missing_requests (rps_peer); | ||
1409 | } | ||
1410 | #endif /* ENABLE_MALICIOUS */ | ||
1411 | } | ||
1412 | |||
1413 | /*********************************** | ||
1414 | * CHURN | ||
1415 | ***********************************/ | ||
1416 | |||
1417 | static void | ||
1418 | churn (void *cls); | ||
1419 | |||
1420 | /** | ||
1421 | * @brief Starts churn | ||
1422 | * | ||
1423 | * Has signature of #MainTest | ||
1424 | * | ||
1425 | * This is not implemented too nicely as this is called for each peer, but we | ||
1426 | * only need to call it once. (Yes we check that we only schedule the task | ||
1427 | * once.) | ||
1428 | * | ||
1429 | * @param rps_peer The peer it's called for | ||
1430 | */ | ||
1431 | static void | ||
1432 | churn_test_cb (struct RPSPeer *rps_peer) | ||
1433 | { | ||
1434 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1435 | { | ||
1436 | return; | ||
1437 | } | ||
1438 | |||
1439 | /* Start churn */ | ||
1440 | if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) | ||
1441 | { | ||
1442 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1443 | "Starting churn task\n"); | ||
1444 | churn_task = GNUNET_SCHEDULER_add_delayed ( | ||
1445 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | ||
1446 | churn, | ||
1447 | NULL); | ||
1448 | } else { | ||
1449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1450 | "Not starting churn task\n"); | ||
1451 | } | ||
1452 | |||
1453 | schedule_missing_requests (rps_peer); | ||
1454 | } | ||
1455 | |||
1456 | /*********************************** | ||
1457 | * PROFILER | ||
1458 | ***********************************/ | ||
1459 | |||
1460 | /** | ||
1461 | * Callback to be called when RPS service is started or stopped at peers | ||
1462 | * | ||
1463 | * @param cls NULL | ||
1464 | * @param op the operation handle | ||
1465 | * @param emsg NULL on success; otherwise an error description | ||
1466 | */ | ||
1467 | static void | ||
1468 | churn_cb (void *cls, | ||
1469 | struct GNUNET_TESTBED_Operation *op, | ||
1470 | const char *emsg) | ||
1471 | { | ||
1472 | // FIXME | ||
1473 | struct OpListEntry *entry = cls; | ||
1474 | |||
1475 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1476 | { | ||
1477 | return; | ||
1478 | } | ||
1479 | |||
1480 | GNUNET_TESTBED_operation_done (entry->op); | ||
1481 | if (NULL != emsg) | ||
1482 | { | ||
1483 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); | ||
1484 | GNUNET_SCHEDULER_shutdown (); | ||
1485 | return; | ||
1486 | } | ||
1487 | GNUNET_assert (0 != entry->delta); | ||
1488 | |||
1489 | num_peers_online += entry->delta; | ||
1490 | |||
1491 | if (PEER_GO_OFFLINE == entry->delta) | ||
1492 | { /* Peer hopefully just went offline */ | ||
1493 | if (GNUNET_YES != rps_peers[entry->index].online) | ||
1494 | { | ||
1495 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1496 | "peer %s was expected to go offline but is still marked as online\n", | ||
1497 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | ||
1498 | GNUNET_break (0); | ||
1499 | } | ||
1500 | else | ||
1501 | { | ||
1502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1503 | "peer %s probably went offline as expected\n", | ||
1504 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | ||
1505 | } | ||
1506 | rps_peers[entry->index].online = GNUNET_NO; | ||
1507 | } | ||
1508 | |||
1509 | else if (PEER_GO_ONLINE < entry->delta) | ||
1510 | { /* Peer hopefully just went online */ | ||
1511 | if (GNUNET_NO != rps_peers[entry->index].online) | ||
1512 | { | ||
1513 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1514 | "peer %s was expected to go online but is still marked as offline\n", | ||
1515 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | ||
1516 | GNUNET_break (0); | ||
1517 | } | ||
1518 | else | ||
1519 | { | ||
1520 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1521 | "peer %s probably went online as expected\n", | ||
1522 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | ||
1523 | if (NULL != cur_test_run.pre_test) | ||
1524 | { | ||
1525 | cur_test_run.pre_test (&rps_peers[entry->index], | ||
1526 | rps_peers[entry->index].rps_handle); | ||
1527 | schedule_missing_requests (&rps_peers[entry->index]); | ||
1528 | } | ||
1529 | } | ||
1530 | rps_peers[entry->index].online = GNUNET_YES; | ||
1531 | } | ||
1532 | else | ||
1533 | { | ||
1534 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1535 | "Invalid value for delta: %i\n", entry->delta); | ||
1536 | GNUNET_break (0); | ||
1537 | } | ||
1538 | |||
1539 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | ||
1540 | rps_peers[entry->index].entry_op_manage = NULL; | ||
1541 | GNUNET_free (entry); | ||
1542 | //if (num_peers_in_round[current_round] == peers_running) | ||
1543 | // run_round (); | ||
1544 | } | ||
1545 | |||
1546 | /** | ||
1547 | * @brief Set the rps-service up or down for a specific peer | ||
1548 | * | ||
1549 | * @param i index of action | ||
1550 | * @param j index of peer | ||
1551 | * @param delta (#PEER_ONLINE_DELTA) down (-1) or up (1) | ||
1552 | * @param prob_go_on_off the probability of the action | ||
1553 | */ | ||
1554 | static void | ||
1555 | manage_service_wrapper (unsigned int i, unsigned int j, | ||
1556 | enum PEER_ONLINE_DELTA delta, | ||
1557 | double prob_go_on_off) | ||
1558 | { | ||
1559 | struct OpListEntry *entry = NULL; | ||
1560 | uint32_t prob; | ||
1561 | |||
1562 | /* make sure that management operation is not already scheduled */ | ||
1563 | if (NULL != rps_peers[j].entry_op_manage) | ||
1564 | { | ||
1565 | return; | ||
1566 | } | ||
1567 | |||
1568 | prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1569 | UINT32_MAX); | ||
1570 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1571 | "%u. selected peer (%u: %s) is %s.\n", | ||
1572 | i, | ||
1573 | j, | ||
1574 | GNUNET_i2s (rps_peers[j].peer_id), | ||
1575 | (PEER_GO_ONLINE == delta) ? "online" : "offline"); | ||
1576 | if (prob < prob_go_on_off * UINT32_MAX) | ||
1577 | { | ||
1578 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1579 | "%s goes %s\n", | ||
1580 | GNUNET_i2s (rps_peers[j].peer_id), | ||
1581 | (PEER_GO_OFFLINE == delta) ? "offline" : "online"); | ||
1582 | |||
1583 | if (PEER_GO_OFFLINE == delta) | ||
1584 | cancel_pending_req_rep (&rps_peers[j]); | ||
1585 | entry = make_oplist_entry (); | ||
1586 | entry->delta = delta; | ||
1587 | entry->index = j; | ||
1588 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, | ||
1589 | testbed_peers[j], | ||
1590 | "rps", | ||
1591 | &churn_cb, | ||
1592 | entry, | ||
1593 | (PEER_GO_OFFLINE == delta) ? 0 : 1); | ||
1594 | rps_peers[j].entry_op_manage = entry; | ||
1595 | } | ||
1596 | } | ||
1597 | |||
1598 | |||
1599 | static void | ||
1600 | churn (void *cls) | ||
1601 | { | ||
1602 | unsigned int i; | ||
1603 | unsigned int j; | ||
1604 | double portion_online; | ||
1605 | unsigned int *permut; | ||
1606 | double prob_go_offline; | ||
1607 | double portion_go_online; | ||
1608 | double portion_go_offline; | ||
1609 | |||
1610 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1611 | { | ||
1612 | return; | ||
1613 | } | ||
1614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1615 | "Churn function executing\n"); | ||
1616 | |||
1617 | churn_task = NULL; /* Should be invalid by now */ | ||
1618 | |||
1619 | /* Compute the probability for an online peer to go offline | ||
1620 | * this round */ | ||
1621 | portion_online = num_peers_online * 1.0 / num_peers; | ||
1622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1623 | "Portion online: %f\n", | ||
1624 | portion_online); | ||
1625 | portion_go_online = ((1 - portion_online) * .5 * .66); | ||
1626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1627 | "Portion that should go online: %f\n", | ||
1628 | portion_go_online); | ||
1629 | portion_go_offline = (portion_online + portion_go_online) - .75; | ||
1630 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1631 | "Portion that probably goes offline: %f\n", | ||
1632 | portion_go_offline); | ||
1633 | prob_go_offline = portion_go_offline / (portion_online * .5); | ||
1634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1635 | "Probability of a selected online peer to go offline: %f\n", | ||
1636 | prob_go_offline); | ||
1637 | |||
1638 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1639 | (unsigned int) num_peers); | ||
1640 | |||
1641 | /* Go over 50% randomly chosen peers */ | ||
1642 | for (i = 0; i < .5 * num_peers; i++) | ||
1643 | { | ||
1644 | j = permut[i]; | ||
1645 | |||
1646 | /* If online, shut down with certain probability */ | ||
1647 | if (GNUNET_YES == rps_peers[j].online) | ||
1648 | { | ||
1649 | manage_service_wrapper (i, j, -1, prob_go_offline); | ||
1650 | } | ||
1651 | |||
1652 | /* If offline, restart with certain probability */ | ||
1653 | else if (GNUNET_NO == rps_peers[j].online) | ||
1654 | { | ||
1655 | manage_service_wrapper (i, j, 1, 0.66); | ||
1656 | } | ||
1657 | } | ||
1658 | |||
1659 | GNUNET_free (permut); | ||
1660 | |||
1661 | churn_task = GNUNET_SCHEDULER_add_delayed ( | ||
1662 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), | ||
1663 | churn, | ||
1664 | NULL); | ||
1665 | } | ||
1666 | |||
1667 | |||
1668 | /** | ||
1669 | * Initialise given RPSPeer | ||
1670 | */ | ||
1671 | static void profiler_init_peer (struct RPSPeer *rps_peer) | ||
1672 | { | ||
1673 | if (num_peers - 1 == rps_peer->index) | ||
1674 | { | ||
1675 | rps_peer->num_ids_to_request = cur_test_run.num_requests; | ||
1676 | } else { | ||
1677 | rps_peer->num_ids_to_request = 0; | ||
1678 | } | ||
1679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n", | ||
1680 | rps_peer->num_ids_to_request); | ||
1681 | } | ||
1682 | |||
1683 | |||
1684 | /** | ||
1685 | * Callback to call on receipt of a reply | ||
1686 | * | ||
1687 | * @param cls closure | ||
1688 | * @param n number of peers | ||
1689 | * @param recv_peers the received peers | ||
1690 | */ | ||
1691 | static void | ||
1692 | profiler_reply_handle (void *cls, | ||
1693 | uint64_t n, | ||
1694 | const struct GNUNET_PeerIdentity *recv_peers) | ||
1695 | { | ||
1696 | struct RPSPeer *rps_peer; | ||
1697 | struct RPSPeer *rcv_rps_peer; | ||
1698 | char *file_name; | ||
1699 | char *file_name_dh; | ||
1700 | char *file_name_dhr; | ||
1701 | unsigned int i; | ||
1702 | struct PendingReply *pending_rep = (struct PendingReply *) cls; | ||
1703 | |||
1704 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); | ||
1705 | rps_peer = pending_rep->rps_peer; | ||
1706 | file_name = "/tmp/rps/received_ids"; | ||
1707 | file_name_dh = "/tmp/rps/diehard_input"; | ||
1708 | file_name_dhr = "/tmp/rps/diehard_input_raw"; | ||
1709 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1710 | "[%s] got %" PRIu64 " peers:\n", | ||
1711 | GNUNET_i2s (rps_peer->peer_id), | ||
1712 | n); | ||
1713 | for (i = 0; i < n; i++) | ||
1714 | { | ||
1715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1716 | "%u: %s\n", | ||
1717 | i, | ||
1718 | GNUNET_i2s (&recv_peers[i])); | ||
1719 | tofile (file_name, | ||
1720 | "%s\n", | ||
1721 | GNUNET_i2s_full (&recv_peers[i])); | ||
1722 | rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]); | ||
1723 | GNUNET_assert (NULL != rcv_rps_peer); | ||
1724 | tofile (file_name_dh, | ||
1725 | "%" PRIu32 "\n", | ||
1726 | (uint32_t) rcv_rps_peer->index); | ||
1727 | to_file_raw (file_name_dhr, | ||
1728 | &rcv_rps_peer->index, | ||
1729 | sizeof (uint32_t)); | ||
1730 | } | ||
1731 | default_reply_handle (cls, n, recv_peers); | ||
1732 | } | ||
1733 | |||
1734 | |||
1735 | static void | ||
1736 | profiler_cb (struct RPSPeer *rps_peer) | ||
1737 | { | ||
1738 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1739 | { | ||
1740 | return; | ||
1741 | } | ||
1742 | |||
1743 | /* Start churn */ | ||
1744 | if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) | ||
1745 | { | ||
1746 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1747 | "Starting churn task\n"); | ||
1748 | churn_task = GNUNET_SCHEDULER_add_delayed ( | ||
1749 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | ||
1750 | churn, | ||
1751 | NULL); | ||
1752 | } else { | ||
1753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1754 | "Not starting churn task\n"); | ||
1755 | } | ||
1756 | |||
1757 | /* Only request peer ids at one peer. | ||
1758 | * (It's the before-last because last one is target of the focussed attack.) | ||
1759 | */ | ||
1760 | if (eval_peer == rps_peer) | ||
1761 | schedule_missing_requests (rps_peer); | ||
1762 | } | ||
1763 | |||
1764 | /** | ||
1765 | * Function called from #profiler_eval with a filename. | ||
1766 | * | ||
1767 | * @param cls closure | ||
1768 | * @param filename complete filename (absolute path) | ||
1769 | * @return #GNUNET_OK to continue to iterate, | ||
1770 | * #GNUNET_NO to stop iteration with no error, | ||
1771 | * #GNUNET_SYSERR to abort iteration with error! | ||
1772 | */ | ||
1773 | int | ||
1774 | file_name_cb (void *cls, const char *filename) | ||
1775 | { | ||
1776 | if (NULL != strstr (filename, "sampler_el")) | ||
1777 | { | ||
1778 | struct RPS_SamplerElement *s_elem; | ||
1779 | struct GNUNET_CRYPTO_AuthKey auth_key; | ||
1780 | const char *key_char; | ||
1781 | uint32_t i; | ||
1782 | |||
1783 | key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */ | ||
1784 | tofile (filename, "--------------------------\n"); | ||
1785 | |||
1786 | auth_key = string_to_auth_key (key_char); | ||
1787 | s_elem = RPS_sampler_elem_create (); | ||
1788 | RPS_sampler_elem_set (s_elem, auth_key); | ||
1789 | |||
1790 | for (i = 0; i < num_peers; i++) | ||
1791 | { | ||
1792 | RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]); | ||
1793 | } | ||
1794 | RPS_sampler_elem_destroy (s_elem); | ||
1795 | } | ||
1796 | return GNUNET_OK; | ||
1797 | } | ||
1798 | |||
1799 | /** | ||
1800 | * This is run after the test finished. | ||
1801 | * | ||
1802 | * Compute all perfect samples. | ||
1803 | */ | ||
1804 | int | ||
1805 | profiler_eval (void) | ||
1806 | { | ||
1807 | /* Compute perfect sample for each sampler element */ | ||
1808 | if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL)) | ||
1809 | { | ||
1810 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); | ||
1811 | } | ||
1812 | |||
1813 | return evaluate (); | ||
1814 | } | ||
1815 | |||
1816 | static uint32_t fac (uint32_t x) | ||
1817 | { | ||
1818 | if (1 >= x) | ||
1819 | { | ||
1820 | return x; | ||
1821 | } | ||
1822 | return x * fac (x - 1); | ||
1823 | } | ||
1824 | |||
1825 | static uint32_t binom (uint32_t n, uint32_t k) | ||
1826 | { | ||
1827 | //GNUNET_assert (n >= k); | ||
1828 | if (k > n) return 0; | ||
1829 | if (0 > n) return 0; | ||
1830 | if (0 > k) return 0; | ||
1831 | if (0 == k) return 1; | ||
1832 | return fac (n) | ||
1833 | / | ||
1834 | fac(k) * fac(n - k); | ||
1835 | } | ||
1836 | |||
1837 | /** | ||
1838 | * @brief is b in view of a? | ||
1839 | * | ||
1840 | * @param a | ||
1841 | * @param b | ||
1842 | * | ||
1843 | * @return | ||
1844 | */ | ||
1845 | static int is_in_view (uint32_t a, uint32_t b) | ||
1846 | { | ||
1847 | uint32_t i; | ||
1848 | for (i = 0; i < rps_peers[a].cur_view_count; i++) | ||
1849 | { | ||
1850 | if (0 == memcmp (rps_peers[b].peer_id, | ||
1851 | &rps_peers[a].cur_view[i], | ||
1852 | sizeof (struct GNUNET_PeerIdentity))) | ||
1853 | { | ||
1854 | return GNUNET_YES; | ||
1855 | } | ||
1856 | } | ||
1857 | return GNUNET_NO; | ||
1858 | } | ||
1859 | |||
1860 | static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid) | ||
1861 | { | ||
1862 | uint32_t i; | ||
1863 | |||
1864 | for (i = 0; i < num_peers; i++) | ||
1865 | { | ||
1866 | if (0 == memcmp (pid, | ||
1867 | rps_peers[i].peer_id, | ||
1868 | sizeof (struct GNUNET_PeerIdentity))) | ||
1869 | { | ||
1870 | return i; | ||
1871 | } | ||
1872 | } | ||
1873 | //return 0; /* Should not happen - make compiler happy */ | ||
1874 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1875 | "No known _PeerIdentity %s!\n", | ||
1876 | GNUNET_i2s_full (pid)); | ||
1877 | GNUNET_assert (0); | ||
1878 | } | ||
1879 | |||
1880 | /** | ||
1881 | * @brief Counts number of peers in view of a that have b in their view | ||
1882 | * | ||
1883 | * @param a | ||
1884 | * @param uint32_tb | ||
1885 | * | ||
1886 | * @return | ||
1887 | */ | ||
1888 | static uint32_t count_containing_views (uint32_t a, uint32_t b) | ||
1889 | { | ||
1890 | uint32_t i; | ||
1891 | uint32_t peer_idx; | ||
1892 | uint32_t count = 0; | ||
1893 | |||
1894 | for (i = 0; i < rps_peers[a].cur_view_count; i++) | ||
1895 | { | ||
1896 | peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]); | ||
1897 | if (GNUNET_YES == is_in_view (peer_idx, b)) | ||
1898 | { | ||
1899 | count++; | ||
1900 | } | ||
1901 | } | ||
1902 | return count; | ||
1903 | } | ||
1904 | |||
1905 | /** | ||
1906 | * @brief Computes the probability for each other peer to be selected by the | ||
1907 | * sampling process based on the views of all peers | ||
1908 | * | ||
1909 | * @param peer_idx index of the peer that is about to sample | ||
1910 | */ | ||
1911 | static void compute_probabilities (uint32_t peer_idx) | ||
1912 | { | ||
1913 | //double probs[num_peers] = { 0 }; | ||
1914 | double probs[num_peers]; | ||
1915 | size_t probs_as_str_size = (num_peers * 10 + 1) * sizeof (char); | ||
1916 | char *probs_as_str = GNUNET_malloc (probs_as_str_size); | ||
1917 | char *probs_as_str_cpy; | ||
1918 | uint32_t i; | ||
1919 | double prob_push; | ||
1920 | double prob_pull; | ||
1921 | uint32_t view_size; | ||
1922 | uint32_t cont_views; | ||
1923 | uint32_t number_of_being_in_pull_events; | ||
1924 | int tmp; | ||
1925 | uint32_t count_non_zero_prob = 0; | ||
1926 | |||
1927 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1928 | "Computing probabilities for peer %" PRIu32 "\n", peer_idx); | ||
1929 | /* Firstly without knowledge of old views */ | ||
1930 | for (i = 0; i < num_peers; i++) | ||
1931 | { | ||
1932 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1933 | "\tfor peer %" PRIu32 ":\n", i); | ||
1934 | view_size = rps_peers[i].cur_view_count; | ||
1935 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1936 | "\t\tview_size: %" PRIu32 "\n", view_size); | ||
1937 | /* For peer i the probability of being sampled is | ||
1938 | * evenly distributed among all possibly observed peers. */ | ||
1939 | /* We could have observed a peer in three cases: | ||
1940 | * 1. peer sent a push | ||
1941 | * 2. peer was contained in a pull reply | ||
1942 | * 3. peer was in history (sampler) - ignored for now */ | ||
1943 | /* 1. Probability of having received a push from peer i */ | ||
1944 | if ((GNUNET_YES == is_in_view (i, peer_idx)) && | ||
1945 | (1 <= (0.45 * view_size))) | ||
1946 | { | ||
1947 | prob_push = 1.0 * binom (0.45 * view_size, 1) | ||
1948 | / | ||
1949 | binom (view_size, 0.45 * view_size); | ||
1950 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1951 | "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", | ||
1952 | peer_idx, | ||
1953 | i, | ||
1954 | prob_push); | ||
1955 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1956 | "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n", | ||
1957 | binom (view_size, 0.45 * view_size), | ||
1958 | binom (0.45 * view_size, 1)); | ||
1959 | } else { | ||
1960 | prob_push = 0; | ||
1961 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1962 | "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", | ||
1963 | peer_idx, | ||
1964 | i); | ||
1965 | } | ||
1966 | /* 2. Probability of peer i being contained in pulls */ | ||
1967 | view_size = rps_peers[peer_idx].cur_view_count; | ||
1968 | cont_views = count_containing_views (peer_idx, i); | ||
1969 | number_of_being_in_pull_events = | ||
1970 | (binom (view_size, 0.45 * view_size) - | ||
1971 | binom (view_size - cont_views, 0.45 * view_size)); | ||
1972 | if (0 != number_of_being_in_pull_events) | ||
1973 | { | ||
1974 | prob_pull = number_of_being_in_pull_events | ||
1975 | / | ||
1976 | (1.0 * binom (view_size, 0.45 * view_size)); | ||
1977 | } else | ||
1978 | { | ||
1979 | prob_pull = 0; | ||
1980 | } | ||
1981 | probs[i] = prob_push + prob_pull - (prob_push * prob_pull); | ||
1982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1983 | "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32 | ||
1984 | " peers in its view who know %" PRIu32 " prob: %f\n", | ||
1985 | peer_idx, | ||
1986 | cont_views, | ||
1987 | view_size, | ||
1988 | i, | ||
1989 | prob_pull); | ||
1990 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1991 | "\t\tnumber of possible pull combinations: %" PRIu32 "\n", | ||
1992 | binom (view_size, 0.45 * view_size)); | ||
1993 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1994 | "\t\tnumber of possible pull combinations without %" PRIu32 | ||
1995 | ": %" PRIu32 "\n", | ||
1996 | i, | ||
1997 | binom (view_size - cont_views, 0.45 * view_size)); | ||
1998 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1999 | "\t\tnumber of possible pull combinations with %" PRIu32 | ||
2000 | ": %" PRIu32 "\n", | ||
2001 | i, | ||
2002 | number_of_being_in_pull_events); | ||
2003 | |||
2004 | if (0 != probs[i]) count_non_zero_prob++; | ||
2005 | } | ||
2006 | /* normalize */ | ||
2007 | if (0 != count_non_zero_prob) | ||
2008 | { | ||
2009 | for (i = 0; i < num_peers; i++) | ||
2010 | { | ||
2011 | probs[i] = probs[i] * (1.0 / count_non_zero_prob); | ||
2012 | } | ||
2013 | } else { | ||
2014 | for (i = 0; i < num_peers; i++) | ||
2015 | { | ||
2016 | probs[i] = 0; | ||
2017 | } | ||
2018 | } | ||
2019 | /* str repr */ | ||
2020 | for (i = 0; i < num_peers; i++) | ||
2021 | { | ||
2022 | probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); | ||
2023 | tmp = GNUNET_snprintf (probs_as_str, | ||
2024 | probs_as_str_size, | ||
2025 | "%s %7.6f", probs_as_str_cpy, probs[i]); | ||
2026 | GNUNET_free (probs_as_str_cpy); | ||
2027 | GNUNET_assert (0 <= tmp); | ||
2028 | } | ||
2029 | |||
2030 | to_file_w_len (rps_peers[peer_idx].file_name_probs, | ||
2031 | probs_as_str_size, | ||
2032 | probs_as_str); | ||
2033 | GNUNET_free (probs_as_str); | ||
2034 | } | ||
2035 | |||
2036 | /** | ||
2037 | * @brief This counts the number of peers in which views a given peer occurs. | ||
2038 | * | ||
2039 | * It also stores this value in the rps peer. | ||
2040 | * | ||
2041 | * @param peer_idx the index of the peer to count the representation | ||
2042 | * | ||
2043 | * @return the number of occurrences | ||
2044 | */ | ||
2045 | static uint32_t count_peer_in_views_2 (uint32_t peer_idx) | ||
2046 | { | ||
2047 | uint32_t i, j; | ||
2048 | uint32_t count = 0; | ||
2049 | |||
2050 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ | ||
2051 | { | ||
2052 | for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ | ||
2053 | { | ||
2054 | if (0 == memcmp (rps_peers[peer_idx].peer_id, | ||
2055 | &rps_peers[i].cur_view[j], | ||
2056 | sizeof (struct GNUNET_PeerIdentity))) | ||
2057 | { | ||
2058 | count++; | ||
2059 | break; | ||
2060 | } | ||
2061 | } | ||
2062 | } | ||
2063 | rps_peers[peer_idx].count_in_views = count; | ||
2064 | return count; | ||
2065 | } | ||
2066 | |||
2067 | static uint32_t cumulated_view_sizes () | ||
2068 | { | ||
2069 | uint32_t i; | ||
2070 | |||
2071 | view_sizes = 0; | ||
2072 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ | ||
2073 | { | ||
2074 | view_sizes += rps_peers[i].cur_view_count; | ||
2075 | } | ||
2076 | return view_sizes; | ||
2077 | } | ||
2078 | |||
2079 | static void count_peer_in_views (uint32_t *count_peers) | ||
2080 | { | ||
2081 | uint32_t i, j; | ||
2082 | |||
2083 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ | ||
2084 | { | ||
2085 | for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ | ||
2086 | { | ||
2087 | if (0 == memcmp (rps_peers[i].peer_id, | ||
2088 | &rps_peers[i].cur_view[j], | ||
2089 | sizeof (struct GNUNET_PeerIdentity))) | ||
2090 | { | ||
2091 | count_peers[i]++; | ||
2092 | } | ||
2093 | } | ||
2094 | } | ||
2095 | } | ||
2096 | |||
2097 | void compute_diversity () | ||
2098 | { | ||
2099 | uint32_t i; | ||
2100 | /* ith entry represents the numer of occurrences in other peer's views */ | ||
2101 | uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t); | ||
2102 | uint32_t views_total_size; | ||
2103 | double expected; | ||
2104 | /* deviation from expected number of peers */ | ||
2105 | double *deviation = GNUNET_new_array (num_peers, double); | ||
2106 | |||
2107 | views_total_size = 0; | ||
2108 | expected = 0; | ||
2109 | |||
2110 | /* For each peer count its representation in other peer's views*/ | ||
2111 | for (i = 0; i < num_peers; i++) /* Peer to count */ | ||
2112 | { | ||
2113 | views_total_size += rps_peers[i].cur_view_count; | ||
2114 | count_peer_in_views (count_peers); | ||
2115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2116 | "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32"\n", | ||
2117 | i, | ||
2118 | GNUNET_i2s (rps_peers[i].peer_id), | ||
2119 | count_peers[i]); | ||
2120 | } | ||
2121 | |||
2122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2123 | "size of all views combined: %" PRIu32 "\n", | ||
2124 | views_total_size); | ||
2125 | expected = ((double) 1/num_peers) * views_total_size; | ||
2126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2127 | "Expected number of occurrences of each peer in all views: %f\n", | ||
2128 | expected); | ||
2129 | for (i = 0; i < num_peers; i++) /* Peer to count */ | ||
2130 | { | ||
2131 | deviation[i] = expected - count_peers[i]; | ||
2132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2133 | "Deviation from expectation: %f\n", deviation[i]); | ||
2134 | } | ||
2135 | GNUNET_free (count_peers); | ||
2136 | GNUNET_free (deviation); | ||
2137 | } | ||
2138 | |||
2139 | void print_view_sizes() | ||
2140 | { | ||
2141 | uint32_t i; | ||
2142 | |||
2143 | for (i = 0; i < num_peers; i++) /* Peer to count */ | ||
2144 | { | ||
2145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2146 | "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n", | ||
2147 | i, | ||
2148 | GNUNET_i2s (rps_peers[i].peer_id), | ||
2149 | rps_peers[i].cur_view_count); | ||
2150 | } | ||
2151 | } | ||
2152 | |||
2153 | void all_views_updated_cb() | ||
2154 | { | ||
2155 | compute_diversity(); | ||
2156 | print_view_sizes(); | ||
2157 | } | ||
2158 | |||
2159 | void view_update_cb (void *cls, | ||
2160 | uint64_t view_size, | ||
2161 | const struct GNUNET_PeerIdentity *peers) | ||
2162 | { | ||
2163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2164 | "View was updated (%" PRIu64 ")\n", view_size); | ||
2165 | struct RPSPeer *rps_peer = (struct RPSPeer *) cls; | ||
2166 | to_file ("/tmp/rps/view_sizes.txt", | ||
2167 | "%" PRIu64 " %" PRIu32 "", | ||
2168 | rps_peer->index, | ||
2169 | view_size); | ||
2170 | for (int i = 0; i < view_size; i++) | ||
2171 | { | ||
2172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2173 | "\t%s\n", GNUNET_i2s (&peers[i])); | ||
2174 | } | ||
2175 | GNUNET_array_grow (rps_peer->cur_view, | ||
2176 | rps_peer->cur_view_count, | ||
2177 | view_size); | ||
2178 | //*rps_peer->cur_view = *peers; | ||
2179 | GNUNET_memcpy (rps_peer->cur_view, | ||
2180 | peers, | ||
2181 | view_size * sizeof (struct GNUNET_PeerIdentity)); | ||
2182 | to_file ("/tmp/rps/count_in_views.txt", | ||
2183 | "%" PRIu64 " %" PRIu32 "", | ||
2184 | rps_peer->index, | ||
2185 | count_peer_in_views_2 (rps_peer->index)); | ||
2186 | cumulated_view_sizes(); | ||
2187 | if (0 != view_size) | ||
2188 | { | ||
2189 | to_file ("/tmp/rps/repr.txt", | ||
2190 | "%" PRIu64 /* index */ | ||
2191 | " %" PRIu32 /* occurrence in views */ | ||
2192 | " %" PRIu32 /* view sizes */ | ||
2193 | " %f" /* fraction of repr in views */ | ||
2194 | " %f" /* average view size */ | ||
2195 | " %f" /* prob of occurrence in view slot */ | ||
2196 | " %f" "", /* exp frac of repr in views */ | ||
2197 | rps_peer->index, | ||
2198 | count_peer_in_views_2 (rps_peer->index), | ||
2199 | view_sizes, | ||
2200 | count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ | ||
2201 | view_sizes / (view_size * 1.0), /* average view size */ | ||
2202 | 1.0 /view_size, /* prob of occurrence in view slot */ | ||
2203 | (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */ | ||
2204 | ); | ||
2205 | } | ||
2206 | compute_probabilities (rps_peer->index); | ||
2207 | all_views_updated_cb(); | ||
2208 | } | ||
2209 | |||
2210 | static void | ||
2211 | pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) | ||
2212 | { | ||
2213 | rps_peer->file_name_probs = | ||
2214 | store_prefix_file_name (rps_peer->peer_id, "probs"); | ||
2215 | GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer); | ||
2216 | } | ||
2217 | |||
2218 | void write_final_stats (void){ | ||
2219 | uint64_t sums[STAT_TYPE_MAX] = { 0 }; | ||
2220 | |||
2221 | for (uint32_t i = 0; i < num_peers; i++) | ||
2222 | { | ||
2223 | to_file ("/tmp/rps/final_stats.dat", | ||
2224 | "%" PRIu32 " " /* index */ | ||
2225 | "%s %" /* id */ | ||
2226 | PRIu64 " %" /* rounds */ | ||
2227 | PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ | ||
2228 | PRIu64 " %" PRIu64 " %" PRIu64 " %" /* issued */ | ||
2229 | PRIu64 " %" PRIu64 " %" PRIu64 " %" /* sent */ | ||
2230 | PRIu64 " %" PRIu64 " %" PRIu64 /* recv */, | ||
2231 | i, | ||
2232 | GNUNET_i2s (rps_peers[i].peer_id), | ||
2233 | rps_peers[i].stats[STAT_TYPE_ROUNDS], | ||
2234 | rps_peers[i].stats[STAT_TYPE_BLOCKS], | ||
2235 | rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH], | ||
2236 | rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH], | ||
2237 | rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PULL], | ||
2238 | rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], | ||
2239 | rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], | ||
2240 | rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND], | ||
2241 | rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ], | ||
2242 | rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REP], | ||
2243 | rps_peers[i].stats[STAT_TYPE_SENT_PUSH_SEND], | ||
2244 | rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ], | ||
2245 | rps_peers[i].stats[STAT_TYPE_SENT_PULL_REP], | ||
2246 | rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND], | ||
2247 | rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ], | ||
2248 | rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP]); | ||
2249 | for (uint32_t stat_type = STAT_TYPE_ROUNDS; | ||
2250 | stat_type < STAT_TYPE_MAX; | ||
2251 | stat_type++) | ||
2252 | { | ||
2253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2254 | "Add to sum (%" PRIu64 ") %" PRIu64 " of stat type %u - %s\n", | ||
2255 | sums[stat_type], | ||
2256 | rps_peers[i].stats[stat_type], | ||
2257 | stat_type, | ||
2258 | stat_type_2_str (stat_type)); | ||
2259 | sums[stat_type] += rps_peers[i].stats[stat_type]; | ||
2260 | } | ||
2261 | } | ||
2262 | to_file ("/tmp/rps/final_stats.dat", | ||
2263 | "SUM %" | ||
2264 | PRIu64 " %" /* rounds */ | ||
2265 | PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ | ||
2266 | PRIu64 " %" PRIu64 " %" PRIu64 " %" /* issued */ | ||
2267 | PRIu64 " %" PRIu64 " %" PRIu64 " %" /* sent */ | ||
2268 | PRIu64 " %" PRIu64 " %" PRIu64 /* recv */, | ||
2269 | sums[STAT_TYPE_ROUNDS], | ||
2270 | sums[STAT_TYPE_BLOCKS], | ||
2271 | sums[STAT_TYPE_BLOCKS_MANY_PUSH], | ||
2272 | sums[STAT_TYPE_BLOCKS_NO_PUSH], | ||
2273 | sums[STAT_TYPE_BLOCKS_NO_PULL], | ||
2274 | sums[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], | ||
2275 | sums[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], | ||
2276 | sums[STAT_TYPE_ISSUED_PUSH_SEND], | ||
2277 | sums[STAT_TYPE_ISSUED_PULL_REQ], | ||
2278 | sums[STAT_TYPE_ISSUED_PULL_REP], | ||
2279 | sums[STAT_TYPE_SENT_PUSH_SEND], | ||
2280 | sums[STAT_TYPE_SENT_PULL_REQ], | ||
2281 | sums[STAT_TYPE_SENT_PULL_REP], | ||
2282 | sums[STAT_TYPE_RECV_PUSH_SEND], | ||
2283 | sums[STAT_TYPE_RECV_PULL_REQ], | ||
2284 | sums[STAT_TYPE_RECV_PULL_REP]); | ||
2285 | } | ||
2286 | |||
2287 | /** | ||
2288 | * Continuation called by #GNUNET_STATISTICS_get() functions. | ||
2289 | * | ||
2290 | * Remembers that this specific statistics value was received for this peer. | ||
2291 | * Checks whether all peers received their statistics yet. | ||
2292 | * Issues the shutdown. | ||
2293 | * | ||
2294 | * @param cls closure | ||
2295 | * @param success #GNUNET_OK if statistics were | ||
2296 | * successfully obtained, #GNUNET_SYSERR if not. | ||
2297 | */ | ||
2298 | void | ||
2299 | post_test_shutdown_ready_cb (void *cls, | ||
2300 | int success) | ||
2301 | { | ||
2302 | struct STATcls *stat_cls = (struct STATcls *) cls; | ||
2303 | struct RPSPeer *rps_peer = stat_cls->rps_peer; | ||
2304 | if (GNUNET_OK == success) | ||
2305 | { | ||
2306 | /* set flag that we we got the value */ | ||
2307 | rps_peer->stat_collected_flags |= BIT(stat_cls->stat_type); | ||
2308 | } else { | ||
2309 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2310 | "Peer %u did not receive statistics value\n", | ||
2311 | rps_peer->index); | ||
2312 | GNUNET_free (stat_cls); | ||
2313 | GNUNET_break (0); | ||
2314 | } | ||
2315 | |||
2316 | if (NULL != rps_peer->stat_op && | ||
2317 | GNUNET_YES == check_statistics_collect_completed_single_peer (rps_peer)) | ||
2318 | { | ||
2319 | GNUNET_TESTBED_operation_done (rps_peer->stat_op); | ||
2320 | } | ||
2321 | |||
2322 | write_final_stats (); | ||
2323 | if (GNUNET_YES == check_statistics_collect_completed()) | ||
2324 | { | ||
2325 | //write_final_stats (); | ||
2326 | GNUNET_free (stat_cls); | ||
2327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2328 | "Shutting down\n"); | ||
2329 | GNUNET_SCHEDULER_shutdown (); | ||
2330 | } else { | ||
2331 | GNUNET_free (stat_cls); | ||
2332 | } | ||
2333 | } | ||
2334 | |||
2335 | /** | ||
2336 | * Callback function to process statistic values. | ||
2337 | * | ||
2338 | * @param cls closure | ||
2339 | * @param subsystem name of subsystem that created the statistic | ||
2340 | * @param name the name of the datum | ||
2341 | * @param value the current value | ||
2342 | * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not | ||
2343 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | ||
2344 | */ | ||
2345 | int | ||
2346 | stat_iterator (void *cls, | ||
2347 | const char *subsystem, | ||
2348 | const char *name, | ||
2349 | uint64_t value, | ||
2350 | int is_persistent) | ||
2351 | { | ||
2352 | const struct STATcls *stat_cls = (const struct STATcls *) cls; | ||
2353 | struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer; | ||
2354 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", | ||
2355 | //stat_type_2_str (stat_cls->stat_type), | ||
2356 | name, | ||
2357 | value); | ||
2358 | to_file (rps_peer->file_name_stats, | ||
2359 | "%s: %" PRIu64 "\n", | ||
2360 | name, | ||
2361 | value); | ||
2362 | switch (stat_str_2_type (name)) | ||
2363 | { | ||
2364 | case STAT_TYPE_ROUNDS: | ||
2365 | rps_peer->stats[STAT_TYPE_ROUNDS] = value; | ||
2366 | break; | ||
2367 | case STAT_TYPE_BLOCKS: | ||
2368 | rps_peer->stats[STAT_TYPE_BLOCKS] = value; | ||
2369 | break; | ||
2370 | case STAT_TYPE_BLOCKS_MANY_PUSH: | ||
2371 | rps_peer->stats[STAT_TYPE_BLOCKS_MANY_PUSH] = value; | ||
2372 | break; | ||
2373 | case STAT_TYPE_BLOCKS_NO_PUSH: | ||
2374 | rps_peer->stats[STAT_TYPE_BLOCKS_NO_PUSH] = value; | ||
2375 | break; | ||
2376 | case STAT_TYPE_BLOCKS_NO_PULL: | ||
2377 | rps_peer->stats[STAT_TYPE_BLOCKS_NO_PULL] = value; | ||
2378 | break; | ||
2379 | case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL: | ||
2380 | rps_peer->stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL] = value; | ||
2381 | break; | ||
2382 | case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL: | ||
2383 | rps_peer->stats[STAT_TYPE_BLOCKS] = value; | ||
2384 | break; | ||
2385 | case STAT_TYPE_ISSUED_PUSH_SEND: | ||
2386 | rps_peer->stats[STAT_TYPE_ISSUED_PUSH_SEND] = value; | ||
2387 | break; | ||
2388 | case STAT_TYPE_ISSUED_PULL_REQ: | ||
2389 | rps_peer->stats[STAT_TYPE_ISSUED_PULL_REQ] = value; | ||
2390 | break; | ||
2391 | case STAT_TYPE_ISSUED_PULL_REP: | ||
2392 | rps_peer->stats[STAT_TYPE_ISSUED_PULL_REP] = value; | ||
2393 | break; | ||
2394 | case STAT_TYPE_SENT_PUSH_SEND: | ||
2395 | rps_peer->stats[STAT_TYPE_SENT_PUSH_SEND] = value; | ||
2396 | break; | ||
2397 | case STAT_TYPE_SENT_PULL_REQ: | ||
2398 | rps_peer->stats[STAT_TYPE_SENT_PULL_REQ] = value; | ||
2399 | break; | ||
2400 | case STAT_TYPE_SENT_PULL_REP: | ||
2401 | rps_peer->stats[STAT_TYPE_SENT_PULL_REP] = value; | ||
2402 | break; | ||
2403 | case STAT_TYPE_RECV_PUSH_SEND: | ||
2404 | rps_peer->stats[STAT_TYPE_RECV_PUSH_SEND] = value; | ||
2405 | break; | ||
2406 | case STAT_TYPE_RECV_PULL_REQ: | ||
2407 | rps_peer->stats[STAT_TYPE_RECV_PULL_REQ] = value; | ||
2408 | break; | ||
2409 | case STAT_TYPE_RECV_PULL_REP: | ||
2410 | rps_peer->stats[STAT_TYPE_RECV_PULL_REP] = value; | ||
2411 | break; | ||
2412 | case STAT_TYPE_MAX: | ||
2413 | default: | ||
2414 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2415 | "Unknown statistics string: %s\n", | ||
2416 | name); | ||
2417 | break; | ||
2418 | } | ||
2419 | return GNUNET_OK; | ||
2420 | } | ||
2421 | |||
2422 | void post_profiler (struct RPSPeer *rps_peer) | ||
2423 | { | ||
2424 | if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics) | ||
2425 | { | ||
2426 | return; | ||
2427 | } | ||
2428 | |||
2429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2430 | "Going to request statistic values with mask 0x%" PRIx32 "\n", | ||
2431 | cur_test_run.stat_collect_flags); | ||
2432 | |||
2433 | struct STATcls *stat_cls; | ||
2434 | uint32_t stat_type; | ||
2435 | for (stat_type = STAT_TYPE_ROUNDS; | ||
2436 | stat_type < STAT_TYPE_MAX; | ||
2437 | stat_type++) | ||
2438 | { | ||
2439 | if (BIT(stat_type) & cur_test_run.stat_collect_flags) | ||
2440 | { | ||
2441 | stat_cls = GNUNET_malloc (sizeof (struct STATcls)); | ||
2442 | stat_cls->rps_peer = rps_peer; | ||
2443 | stat_cls->stat_type = stat_type; | ||
2444 | rps_peer->file_name_stats = | ||
2445 | store_prefix_file_name (rps_peer->peer_id, "stats"); | ||
2446 | GNUNET_STATISTICS_get (rps_peer->stats_h, | ||
2447 | "rps", | ||
2448 | stat_type_2_str (stat_type), | ||
2449 | post_test_shutdown_ready_cb, | ||
2450 | stat_iterator, | ||
2451 | (struct STATcls *) stat_cls); | ||
2452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2453 | "Requested statistics for %s (peer %" PRIu32 ")\n", | ||
2454 | stat_type_2_str (stat_type), | ||
2455 | rps_peer->index); | ||
2456 | } | ||
2457 | } | ||
2458 | } | ||
2459 | |||
2460 | |||
2461 | /*********************************************************************** | ||
2462 | * /Definition of tests | ||
2463 | ***********************************************************************/ | ||
2464 | |||
2465 | |||
2466 | /** | ||
2467 | * Actual "main" function for the testcase. | ||
2468 | * | ||
2469 | * @param cls closure | ||
2470 | * @param h the run handle | ||
2471 | * @param n_peers number of peers in 'peers' | ||
2472 | * @param peers handle to peers run in the testbed | ||
2473 | * @param links_succeeded the number of overlay link connection attempts that | ||
2474 | * succeeded | ||
2475 | * @param links_failed the number of overlay link connection attempts that | ||
2476 | * failed | ||
2477 | */ | ||
2478 | static void | ||
2479 | test_run (void *cls, | ||
2480 | struct GNUNET_TESTBED_RunHandle *h, | ||
2481 | unsigned int n_peers, | ||
2482 | struct GNUNET_TESTBED_Peer **peers, | ||
2483 | unsigned int links_succeeded, | ||
2484 | unsigned int links_failed) | ||
2485 | { | ||
2486 | unsigned int i; | ||
2487 | struct OpListEntry *entry; | ||
2488 | |||
2489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n"); | ||
2490 | printf ("test 1\n"); | ||
2491 | |||
2492 | /* Check whether we timed out */ | ||
2493 | if (n_peers != num_peers || | ||
2494 | NULL == peers || | ||
2495 | 0 == links_succeeded) | ||
2496 | { | ||
2497 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n"); | ||
2498 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers); | ||
2499 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers); | ||
2500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers); | ||
2501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded); | ||
2502 | GNUNET_SCHEDULER_shutdown (); | ||
2503 | return; | ||
2504 | } | ||
2505 | |||
2506 | |||
2507 | /* Initialize peers */ | ||
2508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n"); | ||
2509 | testbed_peers = peers; | ||
2510 | num_peers_online = 0; | ||
2511 | for (i = 0; i < num_peers; i++) | ||
2512 | { | ||
2513 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i); | ||
2514 | entry = make_oplist_entry (); | ||
2515 | entry->index = i; | ||
2516 | rps_peers[i].index = i; | ||
2517 | if (NULL != cur_test_run.init_peer) | ||
2518 | cur_test_run.init_peer (&rps_peers[i]); | ||
2519 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) | ||
2520 | { | ||
2521 | rps_peers->cur_view_count = 0; | ||
2522 | rps_peers->cur_view = NULL; | ||
2523 | } | ||
2524 | entry->op = GNUNET_TESTBED_peer_get_information (peers[i], | ||
2525 | GNUNET_TESTBED_PIT_IDENTITY, | ||
2526 | &info_cb, | ||
2527 | entry); | ||
2528 | } | ||
2529 | |||
2530 | /* Bring peers up */ | ||
2531 | GNUNET_assert (num_peers == n_peers); | ||
2532 | for (i = 0; i < n_peers; i++) | ||
2533 | { | ||
2534 | rps_peers[i].index = i; | ||
2535 | rps_peers[i].op = | ||
2536 | GNUNET_TESTBED_service_connect (&rps_peers[i], | ||
2537 | peers[i], | ||
2538 | "rps", | ||
2539 | &rps_connect_complete_cb, | ||
2540 | &rps_peers[i], | ||
2541 | &rps_connect_adapter, | ||
2542 | &rps_disconnect_adapter, | ||
2543 | &rps_peers[i]); | ||
2544 | /* Connect all peers to statistics service */ | ||
2545 | if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) | ||
2546 | { | ||
2547 | rps_peers[i].stat_op = | ||
2548 | GNUNET_TESTBED_service_connect (NULL, | ||
2549 | peers[i], | ||
2550 | "statistics", | ||
2551 | stat_complete_cb, | ||
2552 | &rps_peers[i], | ||
2553 | &stat_connect_adapter, | ||
2554 | &stat_disconnect_adapter, | ||
2555 | &rps_peers[i]); | ||
2556 | } | ||
2557 | } | ||
2558 | |||
2559 | if (NULL != churn_task) | ||
2560 | GNUNET_SCHEDULER_cancel (churn_task); | ||
2561 | post_test_task = GNUNET_SCHEDULER_add_delayed (timeout, &post_test_op, NULL); | ||
2562 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
2563 | (timeout_s * 1.2) + 0.1 * num_peers); | ||
2564 | shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); | ||
2565 | shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL); | ||
2566 | |||
2567 | } | ||
2568 | |||
2569 | |||
2570 | /** | ||
2571 | * Entry point for the testcase, sets up the testbed. | ||
2572 | * | ||
2573 | * @param argc unused | ||
2574 | * @param argv unused | ||
2575 | * @return 0 on success | ||
2576 | */ | ||
2577 | static void | ||
2578 | run (void *cls, | ||
2579 | char *const *args, | ||
2580 | const char *cfgfile, | ||
2581 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
2582 | { | ||
2583 | //int ret_value; | ||
2584 | |||
2585 | /* Defaults for tests */ | ||
2586 | churn_task = NULL; | ||
2587 | |||
2588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); | ||
2589 | cur_test_run.name = "test-rps-profiler"; | ||
2590 | num_peers = 10; | ||
2591 | mal_type = 3; | ||
2592 | cur_test_run.init_peer = profiler_init_peer; | ||
2593 | //cur_test_run.pre_test = mal_pre; | ||
2594 | cur_test_run.pre_test = pre_profiler; | ||
2595 | cur_test_run.main_test = profiler_cb; | ||
2596 | cur_test_run.reply_handle = profiler_reply_handle; | ||
2597 | cur_test_run.eval_cb = profiler_eval; | ||
2598 | cur_test_run.post_test = post_profiler; | ||
2599 | cur_test_run.request_interval = 2; | ||
2600 | cur_test_run.num_requests = 5; | ||
2601 | //cur_test_run.have_churn = HAVE_CHURN; | ||
2602 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2603 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; | ||
2604 | cur_test_run.have_collect_statistics = COLLECT_STATISTICS; | ||
2605 | cur_test_run.stat_collect_flags = BIT(STAT_TYPE_ROUNDS) | | ||
2606 | BIT(STAT_TYPE_BLOCKS) | | ||
2607 | BIT(STAT_TYPE_BLOCKS_MANY_PUSH) | | ||
2608 | BIT(STAT_TYPE_BLOCKS_NO_PUSH) | | ||
2609 | BIT(STAT_TYPE_BLOCKS_NO_PULL) | | ||
2610 | BIT(STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL) | | ||
2611 | BIT(STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL) | | ||
2612 | BIT(STAT_TYPE_ISSUED_PUSH_SEND) | | ||
2613 | BIT(STAT_TYPE_ISSUED_PULL_REQ) | | ||
2614 | BIT(STAT_TYPE_ISSUED_PULL_REP) | | ||
2615 | BIT(STAT_TYPE_SENT_PUSH_SEND) | | ||
2616 | BIT(STAT_TYPE_SENT_PULL_REQ) | | ||
2617 | BIT(STAT_TYPE_SENT_PULL_REP) | | ||
2618 | BIT(STAT_TYPE_RECV_PUSH_SEND) | | ||
2619 | BIT(STAT_TYPE_RECV_PULL_REQ) | | ||
2620 | BIT(STAT_TYPE_RECV_PULL_REP); | ||
2621 | cur_test_run.have_collect_view = COLLECT_VIEW; | ||
2622 | timeout_s = 300; | ||
2623 | |||
2624 | /* 'Clean' directory */ | ||
2625 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); | ||
2626 | GNUNET_DISK_directory_create ("/tmp/rps/"); | ||
2627 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s); | ||
2628 | |||
2629 | rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); | ||
2630 | peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); | ||
2631 | rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); | ||
2632 | if ( (2 == mal_type) || | ||
2633 | (3 == mal_type)) | ||
2634 | target_peer = &rps_peer_ids[num_peers - 2]; | ||
2635 | if (profiler_eval == cur_test_run.eval_cb) | ||
2636 | eval_peer = &rps_peers[num_peers - 1]; /* FIXME: eval_peer could be a | ||
2637 | malicious peer if not careful | ||
2638 | with the malicious portion */ | ||
2639 | |||
2640 | ok = 1; | ||
2641 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2642 | "before _run()\n"); | ||
2643 | GNUNET_TESTBED_run (NULL, | ||
2644 | cfg, | ||
2645 | num_peers, | ||
2646 | 0, /* event mask */ | ||
2647 | NULL, | ||
2648 | NULL, | ||
2649 | &test_run, | ||
2650 | NULL); | ||
2651 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2652 | "after _run()\n"); | ||
2653 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2654 | "gnunet-rps-profiler returned.\n"); | ||
2655 | } | ||
2656 | |||
2657 | /** | ||
2658 | * Entry point for the testcase, sets up the testbed. | ||
2659 | * | ||
2660 | * @param argc unused | ||
2661 | * @param argv unused | ||
2662 | * @return 0 on success | ||
2663 | */ | ||
2664 | int | ||
2665 | main (int argc, char *argv[]) | ||
2666 | { | ||
2667 | int ret_value; | ||
2668 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
2669 | GNUNET_GETOPT_option_uint ('n', | ||
2670 | "peers", | ||
2671 | "COUNT", | ||
2672 | gettext_noop ("number of peers to start"), | ||
2673 | &num_peers), | ||
2674 | GNUNET_GETOPT_OPTION_END | ||
2675 | }; | ||
2676 | |||
2677 | //if (GNUNET_OK != | ||
2678 | // GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
2679 | // &argc, &argv)) | ||
2680 | // return 2; | ||
2681 | ret_value = 0; | ||
2682 | if (GNUNET_OK != | ||
2683 | GNUNET_PROGRAM_run (argc, | ||
2684 | argv, | ||
2685 | "gnunet-rps-profiler", | ||
2686 | gettext_noop ("Measure quality and performance of the RPS service."), | ||
2687 | options, | ||
2688 | &run, | ||
2689 | NULL)) | ||
2690 | { | ||
2691 | ret_value = 1; | ||
2692 | } | ||
2693 | if (GNUNET_OK != ret_value) | ||
2694 | { | ||
2695 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2696 | "Test did not run successfully!\n"); | ||
2697 | } | ||
2698 | |||
2699 | ret_value = cur_test_run.eval_cb(); | ||
2700 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) | ||
2701 | { | ||
2702 | GNUNET_array_grow (rps_peers->cur_view, | ||
2703 | rps_peers->cur_view_count, | ||
2704 | 0); | ||
2705 | } | ||
2706 | GNUNET_free (rps_peers); | ||
2707 | GNUNET_free (rps_peer_ids); | ||
2708 | GNUNET_CONTAINER_multipeermap_destroy (peer_map); | ||
2709 | printf ("test -1\n"); | ||
2710 | return ret_value; | ||
2711 | } | ||
2712 | |||
2713 | /* end of test_rps.c */ | ||