RPS: Fix writing internals to disk
[oweals/gnunet.git] / src / rps / rps-test_util.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C)
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 /**
20  * @file rps/rps-test_util.h
21  * @brief Some utils faciliating the view into the internals for the sampler
22  *        needed for evaluation
23  * @author Julius Bünger
24  */
25
26 #ifndef RPS_TEST_UTIL_H
27 #define RPS_TEST_UTIL_H
28
29 #define TO_FILE 1
30
31
32 char *
33 auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key);
34
35 struct GNUNET_CRYPTO_AuthKey
36 string_to_auth_key (const char *str);
37
38 char *
39 create_file (const char *name);
40
41 /**
42  * This function is used to facilitate writing important information to disk
43  */
44 #ifdef TO_FILE
45 #  define to_file(file_name, ...) do {char tmp_buf[512] = "";\
46     int size;\
47     size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
48     if (0 > size)\
49       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
50            "Failed to create tmp_buf\n");\
51     else\
52       GNUNET_DISK_fn_write(file_name,tmp_buf, sizeof(tmp_buf),\
53                             GNUNET_DISK_PERM_USER_READ |\
54                             GNUNET_DISK_PERM_USER_WRITE |\
55                             GNUNET_DISK_PERM_GROUP_READ |\
56                             GNUNET_DISK_PERM_OTHER_READ);\
57   } while (0);
58
59 #define to_file_w_len(file_name, len, ...) do {char tmp_buf[len];\
60     int size;\
61     memset (tmp_buf, 0, len);\
62     size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
63     if (0 > size)\
64       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
65            "Failed to create tmp_buf\n");\
66     else\
67       GNUNET_DISK_fn_write(file_name,tmp_buf, len, \
68                             GNUNET_DISK_PERM_USER_READ |\
69                             GNUNET_DISK_PERM_USER_WRITE |\
70                             GNUNET_DISK_PERM_GROUP_READ |\
71                             GNUNET_DISK_PERM_OTHER_READ);\
72   } while (0);
73 #else /* TO_FILE */
74 #  define to_file(file_name, ...)
75 #  define to_file_w_len(file_name, len, ...)
76 #endif /* TO_FILE */
77
78 char *
79 store_prefix_file_name (const struct GNUNET_PeerIdentity *peer,
80                         const char *prefix);
81
82 void
83 to_file_raw (const char *file_name, const char *buf, size_t size_buf);
84
85 void
86 to_file_raw_unaligned (const char *file_name,
87                        const char *buf,
88                        size_t size_buf,
89                        unsigned bits_needed);
90
91 #endif /* RPS_TEST_UTIL_H */
92 /* end of gnunet-service-rps.c */