diff options
author | Julius Bünger <buenger@mytum.de> | 2015-06-05 23:03:04 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-06-05 23:03:04 +0000 |
commit | 1e4ddb54ca92d3feb5c6382c97c08de7fb9cb7e8 (patch) | |
tree | 6f83ceec54d8be3f01930987d84266c3cd2b978a /src/rps | |
parent | 6c0a7bacca0e00bcaa72b8b0a279660d146649ad (diff) | |
download | gnunet-1e4ddb54ca92d3feb5c6382c97c08de7fb9cb7e8.tar.gz gnunet-1e4ddb54ca92d3feb5c6382c97c08de7fb9cb7e8.zip |
-restructured the code to faciliate viewing the internals
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/Makefile.am | 1 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.c | 137 | ||||
-rw-r--r-- | src/rps/rps-test_util.c | 163 | ||||
-rw-r--r-- | src/rps/rps-test_util.h | 63 |
4 files changed, 246 insertions, 118 deletions
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am index cdf80b39c..97f73ed3d 100644 --- a/src/rps/Makefile.am +++ b/src/rps/Makefile.am | |||
@@ -48,6 +48,7 @@ endif | |||
48 | 48 | ||
49 | gnunet_service_rps_SOURCES = \ | 49 | gnunet_service_rps_SOURCES = \ |
50 | gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \ | 50 | gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \ |
51 | rps-test_util.h rps-test_util.c \ | ||
51 | gnunet-service-rps.c | 52 | gnunet-service-rps.c |
52 | 53 | ||
53 | 54 | ||
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index 07bd1e317..f382786a4 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c | |||
@@ -32,8 +32,11 @@ | |||
32 | #include <math.h> | 32 | #include <math.h> |
33 | #include <inttypes.h> | 33 | #include <inttypes.h> |
34 | 34 | ||
35 | #include "rps-test_util.h" | ||
36 | |||
35 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler",__VA_ARGS__) | 37 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler",__VA_ARGS__) |
36 | 38 | ||
39 | |||
37 | // multiple 'clients'? | 40 | // multiple 'clients'? |
38 | 41 | ||
39 | // TODO check for overflows | 42 | // TODO check for overflows |
@@ -299,76 +302,6 @@ static size_t max_size; | |||
299 | static uint32_t client_get_index; | 302 | static uint32_t client_get_index; |
300 | 303 | ||
301 | 304 | ||
302 | #ifdef TO_FILE | ||
303 | /** | ||
304 | * This function is used to facilitate writing important information to disk | ||
305 | */ | ||
306 | #define to_file(file_name, ...) do {char tmp_buf[512];\ | ||
307 | int size;\ | ||
308 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | ||
309 | if (0 > size)\ | ||
310 | LOG (GNUNET_ERROR_TYPE_WARNING,\ | ||
311 | "Failed to create tmp_buf\n");\ | ||
312 | else\ | ||
313 | to_file_(file_name,tmp_buf);\ | ||
314 | } while (0); | ||
315 | |||
316 | static void | ||
317 | to_file_ (char *file_name, char *line) | ||
318 | { | ||
319 | struct GNUNET_DISK_FileHandle *f; | ||
320 | char output_buffer[512]; | ||
321 | //size_t size; | ||
322 | int size; | ||
323 | size_t size2; | ||
324 | |||
325 | |||
326 | if (NULL == (f = GNUNET_DISK_file_open (file_name, | ||
327 | GNUNET_DISK_OPEN_APPEND | | ||
328 | GNUNET_DISK_OPEN_WRITE | | ||
329 | GNUNET_DISK_OPEN_CREATE, | ||
330 | GNUNET_DISK_PERM_USER_WRITE))) | ||
331 | { | ||
332 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
333 | "Not able to open file %s\n", | ||
334 | file_name); | ||
335 | return; | ||
336 | } | ||
337 | size = GNUNET_snprintf (output_buffer, | ||
338 | sizeof (output_buffer), | ||
339 | "%llu %s\n", | ||
340 | GNUNET_TIME_absolute_get ().abs_value_us, | ||
341 | line); | ||
342 | if (0 > size) | ||
343 | { | ||
344 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
345 | "Failed to write string to buffer (size: %i)\n", | ||
346 | size); | ||
347 | return; | ||
348 | } | ||
349 | |||
350 | size2 = GNUNET_DISK_file_write (f, output_buffer, size); | ||
351 | if (size != size2) | ||
352 | { | ||
353 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
354 | "Unable to write to file! (Size: %u, size2: %u)\n", | ||
355 | size, | ||
356 | size2); | ||
357 | return; | ||
358 | } | ||
359 | |||
360 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
361 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
362 | "Unable to close file\n"); | ||
363 | } | ||
364 | #endif /* TO_FILE */ | ||
365 | |||
366 | |||
367 | /** FIXME document */ | ||
368 | static struct GetPeerCls *gpc_head; | ||
369 | static struct GetPeerCls *gpc_tail; | ||
370 | |||
371 | |||
372 | /** | 305 | /** |
373 | * Callback to _get_rand_peer() used by _get_n_rand_peers(). | 306 | * Callback to _get_rand_peer() used by _get_n_rand_peers(). |
374 | * | 307 | * |
@@ -417,38 +350,11 @@ RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_el) | |||
417 | 350 | ||
418 | #ifdef TO_FILE | 351 | #ifdef TO_FILE |
419 | /* Create a file(-name) to store internals to */ | 352 | /* Create a file(-name) to store internals to */ |
420 | int size; | 353 | char *name_buf; |
421 | char *end; | 354 | name_buf = auth_key_to_string (sampler_el->auth_key); |
422 | char *buf; | ||
423 | char name_buf[512]; | ||
424 | size_t keylen = (sizeof (struct GNUNET_CRYPTO_AuthKey)) * 8; | ||
425 | |||
426 | if (keylen % 5 > 0) | ||
427 | keylen += 5 - keylen % 5; | ||
428 | keylen /= 5; | ||
429 | buf = GNUNET_malloc (keylen + 1); | ||
430 | |||
431 | end = GNUNET_STRINGS_data_to_string (&(sampler_el->auth_key.key), | ||
432 | sizeof (struct GNUNET_CRYPTO_AuthKey), | ||
433 | buf, | ||
434 | keylen); | ||
435 | |||
436 | if (NULL == end) | ||
437 | { | ||
438 | GNUNET_free (buf); | ||
439 | GNUNET_break (0); | ||
440 | } | ||
441 | else | ||
442 | { | ||
443 | *end = '\0'; | ||
444 | } | ||
445 | |||
446 | size = GNUNET_snprintf (name_buf, sizeof (name_buf), "sampler_el-%s-", buf); | ||
447 | if (0 > size) | ||
448 | LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); | ||
449 | 355 | ||
450 | if (NULL == (sampler_el->file_name = GNUNET_DISK_mktemp (name_buf))) | 356 | sampler_el->file_name = create_file (name_buf); |
451 | LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n"); | 357 | GNUNET_free (name_buf); |
452 | #endif /* TO_FILE */ | 358 | #endif /* TO_FILE */ |
453 | 359 | ||
454 | sampler_el->last_client_request = GNUNET_TIME_UNIT_FOREVER_ABS; | 360 | sampler_el->last_client_request = GNUNET_TIME_UNIT_FOREVER_ABS; |
@@ -495,11 +401,9 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, | |||
495 | 401 | ||
496 | s_elem->num_peers++; | 402 | s_elem->num_peers++; |
497 | 403 | ||
498 | #ifdef TO_FILE | ||
499 | to_file (s_elem->file_name, | 404 | to_file (s_elem->file_name, |
500 | "Got id %s", | 405 | "Got id %s", |
501 | GNUNET_i2s_full (other)); | 406 | GNUNET_i2s_full (other)); |
502 | #endif /* TO_FILE */ | ||
503 | 407 | ||
504 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (other, &(s_elem->peer_id))) | 408 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (other, &(s_elem->peer_id))) |
505 | { | 409 | { |
@@ -545,11 +449,10 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, | |||
545 | } | 449 | } |
546 | } | 450 | } |
547 | s_elem->is_empty = NOT_EMPTY; | 451 | s_elem->is_empty = NOT_EMPTY; |
548 | #ifdef TO_FILE | 452 | |
549 | to_file (s_elem->file_name, | 453 | to_file (s_elem->file_name, |
550 | "Now holding %s", | 454 | "Now holding %s", |
551 | GNUNET_i2s_full (&s_elem->peer_id)); | 455 | GNUNET_i2s_full (&s_elem->peer_id)); |
552 | #endif /* TO_FILE */ | ||
553 | } | 456 | } |
554 | 457 | ||
555 | 458 | ||
@@ -590,7 +493,7 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | |||
590 | "Shrinking sampler %d -> %d\n", | 493 | "Shrinking sampler %d -> %d\n", |
591 | old_size, | 494 | old_size, |
592 | new_size); | 495 | new_size); |
593 | #ifdef TO_FILE | 496 | |
594 | to_file (sampler->file_name, | 497 | to_file (sampler->file_name, |
595 | "Shrinking sampler %d -> %d", | 498 | "Shrinking sampler %d -> %d", |
596 | old_size, | 499 | old_size, |
@@ -603,7 +506,7 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | |||
603 | i, | 506 | i, |
604 | sampler->sampler_elements[i]->file_name); | 507 | sampler->sampler_elements[i]->file_name); |
605 | } | 508 | } |
606 | #endif /* TO_FILE */ | 509 | |
607 | GNUNET_array_grow (sampler->sampler_elements, | 510 | GNUNET_array_grow (sampler->sampler_elements, |
608 | sampler->sampler_size, | 511 | sampler->sampler_size, |
609 | new_size); | 512 | new_size); |
@@ -618,12 +521,12 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | |||
618 | "Growing sampler %d -> %d\n", | 521 | "Growing sampler %d -> %d\n", |
619 | old_size, | 522 | old_size, |
620 | new_size); | 523 | new_size); |
621 | #ifdef TO_FILE | 524 | |
622 | to_file (sampler->file_name, | 525 | to_file (sampler->file_name, |
623 | "Growing sampler %d -> %d", | 526 | "Growing sampler %d -> %d", |
624 | old_size, | 527 | old_size, |
625 | new_size); | 528 | new_size); |
626 | #endif /* TO_FILE */ | 529 | |
627 | GNUNET_array_grow (sampler->sampler_elements, | 530 | GNUNET_array_grow (sampler->sampler_elements, |
628 | sampler->sampler_size, | 531 | sampler->sampler_size, |
629 | new_size); | 532 | new_size); |
@@ -631,12 +534,11 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | |||
631 | for (i = old_size ; i < new_size ; i++) | 534 | for (i = old_size ; i < new_size ; i++) |
632 | { /* Add new sampler elements */ | 535 | { /* Add new sampler elements */ |
633 | sampler->sampler_elements[i] = RPS_sampler_elem_create (); | 536 | sampler->sampler_elements[i] = RPS_sampler_elem_create (); |
634 | #ifdef TO_FILE | 537 | |
635 | to_file (sampler->file_name, | 538 | to_file (sampler->file_name, |
636 | "+%" PRIu32 ": %s", | 539 | "+%" PRIu32 ": %s", |
637 | i, | 540 | i, |
638 | sampler->sampler_elements[i]->file_name); | 541 | sampler->sampler_elements[i]->file_name); |
639 | #endif /* TO_FILE */ | ||
640 | } | 542 | } |
641 | } | 543 | } |
642 | else | 544 | else |
@@ -696,9 +598,8 @@ RPS_sampler_init (size_t init_size, | |||
696 | sampler = GNUNET_new (struct RPS_Sampler); | 598 | sampler = GNUNET_new (struct RPS_Sampler); |
697 | 599 | ||
698 | #ifdef TO_FILE | 600 | #ifdef TO_FILE |
699 | if (NULL == (sampler->file_name = GNUNET_DISK_mktemp ("sampler-"))) | 601 | sampler->file_name = create_file ("sampler-"); |
700 | LOG (GNUNET_ERROR_TYPE_WARNING, | 602 | |
701 | "Could not create file\n"); | ||
702 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 603 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
703 | "Initialised sampler %s\n", | 604 | "Initialised sampler %s\n", |
704 | sampler->file_name); | 605 | sampler->file_name); |
@@ -736,13 +637,11 @@ RPS_sampler_mod_init (size_t init_size, | |||
736 | sampler = RPS_sampler_init (init_size, max_round_interval); | 637 | sampler = RPS_sampler_init (init_size, max_round_interval); |
737 | sampler->get_peers = sampler_mod_get_rand_peer; | 638 | sampler->get_peers = sampler_mod_get_rand_peer; |
738 | 639 | ||
739 | #ifdef TO_FILE | ||
740 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 640 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
741 | "Initialised modified sampler %s\n", | 641 | "Initialised modified sampler %s\n", |
742 | sampler->file_name); | 642 | sampler->file_name); |
743 | to_file (sampler->file_name, | 643 | to_file (sampler->file_name, |
744 | "This is a modified sampler"); | 644 | "This is a modified sampler"); |
745 | #endif /* TO_FILE */ | ||
746 | 645 | ||
747 | return sampler; | 646 | return sampler; |
748 | } | 647 | } |
@@ -760,11 +659,9 @@ RPS_sampler_update (struct RPS_Sampler *sampler, | |||
760 | { | 659 | { |
761 | uint32_t i; | 660 | uint32_t i; |
762 | 661 | ||
763 | #ifdef TO_FILE | ||
764 | to_file (sampler->file_name, | 662 | to_file (sampler->file_name, |
765 | "Got %s", | 663 | "Got %s", |
766 | GNUNET_i2s_full (id)); | 664 | GNUNET_i2s_full (id)); |
767 | #endif /* TO_FILE */ | ||
768 | 665 | ||
769 | for (i = 0 ; i < sampler->sampler_size ; i++) | 666 | for (i = 0 ; i < sampler->sampler_size ; i++) |
770 | { | 667 | { |
@@ -830,6 +727,10 @@ sampler_get_rand_peer (void *cls, | |||
830 | //LOG (GNUNET_ERROR_TYPE_DEBUG, | 727 | //LOG (GNUNET_ERROR_TYPE_DEBUG, |
831 | // "Not returning randomly selected, empty PeerID. - Rescheduling.\n"); | 728 | // "Not returning randomly selected, empty PeerID. - Rescheduling.\n"); |
832 | 729 | ||
730 | /* FIXME no active wait - get notified, when new id arrives? | ||
731 | * Might also be a freshly emptied one. Others might still contain ids. | ||
732 | * Counter? | ||
733 | */ | ||
833 | gpc->get_peer_task = | 734 | gpc->get_peer_task = |
834 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( | 735 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( |
835 | GNUNET_TIME_UNIT_SECONDS, 0.1), | 736 | GNUNET_TIME_UNIT_SECONDS, 0.1), |
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c new file mode 100644 index 000000000..c607a5300 --- /dev/null +++ b/src/rps/rps-test_util.c | |||
@@ -0,0 +1,163 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | 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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file rps/rps-test_util.c | ||
23 | * @brief Some utils faciliating the view into the internals for the sampler | ||
24 | * needed for evaluation | ||
25 | * | ||
26 | * @author Julius Bünger | ||
27 | */ | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | |||
32 | #include <inttypes.h> | ||
33 | |||
34 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler",__VA_ARGS__) | ||
35 | |||
36 | #ifndef TO_FILE | ||
37 | #define TO_FILE | ||
38 | #endif /* TO_FILE */ | ||
39 | |||
40 | #ifdef TO_FILE | ||
41 | void | ||
42 | to_file_ (char *file_name, char *line) | ||
43 | { | ||
44 | struct GNUNET_DISK_FileHandle *f; | ||
45 | char output_buffer[512]; | ||
46 | //size_t size; | ||
47 | int size; | ||
48 | size_t size2; | ||
49 | |||
50 | |||
51 | if (NULL == (f = GNUNET_DISK_file_open (file_name, | ||
52 | GNUNET_DISK_OPEN_APPEND | | ||
53 | GNUNET_DISK_OPEN_WRITE | | ||
54 | GNUNET_DISK_OPEN_CREATE, | ||
55 | GNUNET_DISK_PERM_USER_WRITE))) | ||
56 | { | ||
57 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
58 | "Not able to open file %s\n", | ||
59 | file_name); | ||
60 | return; | ||
61 | } | ||
62 | size = GNUNET_snprintf (output_buffer, | ||
63 | sizeof (output_buffer), | ||
64 | "%llu %s\n", | ||
65 | GNUNET_TIME_absolute_get ().abs_value_us, | ||
66 | line); | ||
67 | if (0 > size) | ||
68 | { | ||
69 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
70 | "Failed to write string to buffer (size: %i)\n", | ||
71 | size); | ||
72 | return; | ||
73 | } | ||
74 | |||
75 | size2 = GNUNET_DISK_file_write (f, output_buffer, size); | ||
76 | if (size != size2) | ||
77 | { | ||
78 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
79 | "Unable to write to file! (Size: %u, size2: %u)\n", | ||
80 | size, | ||
81 | size2); | ||
82 | return; | ||
83 | } | ||
84 | |||
85 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
86 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
87 | "Unable to close file\n"); | ||
88 | } | ||
89 | |||
90 | char * | ||
91 | auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key) | ||
92 | { | ||
93 | int size; | ||
94 | size_t name_buf_size; | ||
95 | char *end; | ||
96 | char *buf; | ||
97 | char *name_buf; | ||
98 | size_t keylen = (sizeof (struct GNUNET_CRYPTO_AuthKey)) * 8; | ||
99 | |||
100 | name_buf_size = 512 * sizeof (char); | ||
101 | name_buf = GNUNET_malloc (name_buf_size); | ||
102 | |||
103 | if (keylen % 5 > 0) | ||
104 | keylen += 5 - keylen % 5; | ||
105 | keylen /= 5; | ||
106 | buf = GNUNET_malloc (keylen + 1); | ||
107 | |||
108 | end = GNUNET_STRINGS_data_to_string (&(auth_key.key), | ||
109 | sizeof (struct GNUNET_CRYPTO_AuthKey), | ||
110 | buf, | ||
111 | keylen); | ||
112 | |||
113 | if (NULL == end) | ||
114 | { | ||
115 | GNUNET_free (buf); | ||
116 | GNUNET_break (0); | ||
117 | } | ||
118 | else | ||
119 | { | ||
120 | *end = '\0'; | ||
121 | } | ||
122 | |||
123 | size = GNUNET_snprintf (name_buf, name_buf_size, "sampler_el-%s-", buf); | ||
124 | if (0 > size) | ||
125 | LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); | ||
126 | |||
127 | GNUNET_free (buf); | ||
128 | |||
129 | return name_buf; | ||
130 | } | ||
131 | |||
132 | char * | ||
133 | create_file (const char *name) | ||
134 | { | ||
135 | int size; | ||
136 | size_t name_buf_size; | ||
137 | char *name_buf; | ||
138 | char *prefix; | ||
139 | char *file_name; | ||
140 | |||
141 | prefix = "/tmp/rps/"; | ||
142 | name_buf_size = (strlen (prefix) + strlen (name) + 2) * sizeof (char); | ||
143 | name_buf = GNUNET_malloc (name_buf_size); | ||
144 | |||
145 | size = GNUNET_snprintf (name_buf, name_buf_size, "%s%s-", prefix, name); | ||
146 | if (0 > size) | ||
147 | LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); | ||
148 | |||
149 | GNUNET_DISK_directory_create (prefix); | ||
150 | |||
151 | file_name = GNUNET_malloc (strlen (name_buf) + 6); | ||
152 | |||
153 | if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf))) | ||
154 | LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n"); | ||
155 | |||
156 | GNUNET_free (name_buf); | ||
157 | |||
158 | return file_name; | ||
159 | } | ||
160 | |||
161 | #endif /* TO_FILE */ | ||
162 | |||
163 | /* end of gnunet-service-rps.c */ | ||
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h new file mode 100644 index 000000000..0290c35e6 --- /dev/null +++ b/src/rps/rps-test_util.h | |||
@@ -0,0 +1,63 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | 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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file rps/rps-test_util.h | ||
23 | * @brief Some utils faciliating the view into the internals for the sampler | ||
24 | * needed for evaluation | ||
25 | * @author Julius Bünger | ||
26 | */ | ||
27 | |||
28 | #ifndef RPS_TEST_UTIL_H | ||
29 | #define RPS_TEST_UTIL_H | ||
30 | |||
31 | #ifndef TO_FILE | ||
32 | #define TO_FILE | ||
33 | #endif /* TO_FILE */ | ||
34 | |||
35 | |||
36 | void | ||
37 | to_file_ (char *file_name, char *line); | ||
38 | |||
39 | char * | ||
40 | auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key); | ||
41 | |||
42 | char * | ||
43 | create_file (const char *name); | ||
44 | |||
45 | /** | ||
46 | * This function is used to facilitate writing important information to disk | ||
47 | */ | ||
48 | #ifdef TO_FILE | ||
49 | # define to_file(file_name, ...) do {char tmp_buf[512];\ | ||
50 | int size;\ | ||
51 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | ||
52 | if (0 > size)\ | ||
53 | LOG (GNUNET_ERROR_TYPE_WARNING,\ | ||
54 | "Failed to create tmp_buf\n");\ | ||
55 | else\ | ||
56 | to_file_(file_name,tmp_buf);\ | ||
57 | } while (0); | ||
58 | #else /* TO_FILE */ | ||
59 | # define to_file(file_name, ...) | ||
60 | #endif /* TO_FILE */ | ||
61 | |||
62 | #endif /* RPS_TEST_UTIL_H */ | ||
63 | /* end of gnunet-service-rps.c */ | ||