diff options
Diffstat (limited to 'src/testbed/test_gnunet_helper_testbed.c')
-rw-r--r-- | src/testbed/test_gnunet_helper_testbed.c | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/src/testbed/test_gnunet_helper_testbed.c b/src/testbed/test_gnunet_helper_testbed.c index 851375291..8bf1fd7ca 100644 --- a/src/testbed/test_gnunet_helper_testbed.c +++ b/src/testbed/test_gnunet_helper_testbed.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -36,8 +36,8 @@ | |||
36 | /** | 36 | /** |
37 | * Generic logging shortcut | 37 | * Generic logging shortcut |
38 | */ | 38 | */ |
39 | #define LOG(kind,...) \ | 39 | #define LOG(kind, ...) \ |
40 | GNUNET_log (kind, __VA_ARGS__) | 40 | GNUNET_log(kind, __VA_ARGS__) |
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
@@ -82,15 +82,15 @@ static int result; | |||
82 | * @param cls NULL | 82 | * @param cls NULL |
83 | */ | 83 | */ |
84 | static void | 84 | static void |
85 | do_shutdown (void *cls) | 85 | do_shutdown(void *cls) |
86 | { | 86 | { |
87 | if (NULL != abort_task) | 87 | if (NULL != abort_task) |
88 | GNUNET_SCHEDULER_cancel (abort_task); | 88 | GNUNET_SCHEDULER_cancel(abort_task); |
89 | if (NULL != helper) | 89 | if (NULL != helper) |
90 | GNUNET_HELPER_stop (helper, GNUNET_NO); | 90 | GNUNET_HELPER_stop(helper, GNUNET_NO); |
91 | GNUNET_free_non_null (msg); | 91 | GNUNET_free_non_null(msg); |
92 | if (NULL != cfg) | 92 | if (NULL != cfg) |
93 | GNUNET_CONFIGURATION_destroy (cfg); | 93 | GNUNET_CONFIGURATION_destroy(cfg); |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
@@ -100,15 +100,15 @@ do_shutdown (void *cls) | |||
100 | * @param cls NULL | 100 | * @param cls NULL |
101 | */ | 101 | */ |
102 | static void | 102 | static void |
103 | do_abort (void *cls) | 103 | do_abort(void *cls) |
104 | { | 104 | { |
105 | abort_task = NULL; | 105 | abort_task = NULL; |
106 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | 106 | LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); |
107 | result = GNUNET_SYSERR; | 107 | result = GNUNET_SYSERR; |
108 | if (NULL != shandle) | 108 | if (NULL != shandle) |
109 | GNUNET_HELPER_send_cancel (shandle); | 109 | GNUNET_HELPER_send_cancel(shandle); |
110 | if (NULL == shutdown_task) | 110 | if (NULL == shutdown_task) |
111 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 111 | shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
112 | } | 112 | } |
113 | 113 | ||
114 | 114 | ||
@@ -121,13 +121,13 @@ do_abort (void *cls) | |||
121 | * #GNUNET_SYSERR during GNUNET_HELPER_stop() | 121 | * #GNUNET_SYSERR during GNUNET_HELPER_stop() |
122 | */ | 122 | */ |
123 | static void | 123 | static void |
124 | cont_cb (void *cls, | 124 | cont_cb(void *cls, |
125 | int result) | 125 | int result) |
126 | { | 126 | { |
127 | shandle = NULL; | 127 | shandle = NULL; |
128 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 128 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
129 | "Message sent\n"); | 129 | "Message sent\n"); |
130 | GNUNET_assert (GNUNET_OK == result); | 130 | GNUNET_assert(GNUNET_OK == result); |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
@@ -143,35 +143,35 @@ cont_cb (void *cls, | |||
143 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing | 143 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing |
144 | */ | 144 | */ |
145 | static int | 145 | static int |
146 | mst_cb (void *cls, | 146 | mst_cb(void *cls, |
147 | const struct GNUNET_MessageHeader *message) | 147 | const struct GNUNET_MessageHeader *message) |
148 | { | 148 | { |
149 | const struct GNUNET_TESTBED_HelperReply *msg; | 149 | const struct GNUNET_TESTBED_HelperReply *msg; |
150 | char *config; | 150 | char *config; |
151 | uLongf config_size; | 151 | uLongf config_size; |
152 | uLongf xconfig_size; | 152 | uLongf xconfig_size; |
153 | 153 | ||
154 | msg = (const struct GNUNET_TESTBED_HelperReply *) message; | 154 | msg = (const struct GNUNET_TESTBED_HelperReply *)message; |
155 | config_size = 0; | 155 | config_size = 0; |
156 | xconfig_size = 0; | 156 | xconfig_size = 0; |
157 | GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) < | 157 | GNUNET_assert(sizeof(struct GNUNET_TESTBED_HelperReply) < |
158 | ntohs (msg->header.size)); | 158 | ntohs(msg->header.size)); |
159 | GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == | 159 | GNUNET_assert(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == |
160 | ntohs (msg->header.type)); | 160 | ntohs(msg->header.type)); |
161 | config_size = (uLongf) ntohs (msg->config_size); | 161 | config_size = (uLongf)ntohs(msg->config_size); |
162 | xconfig_size = | 162 | xconfig_size = |
163 | (uLongf) (ntohs (msg->header.size) - | 163 | (uLongf)(ntohs(msg->header.size) - |
164 | sizeof (struct GNUNET_TESTBED_HelperReply)); | 164 | sizeof(struct GNUNET_TESTBED_HelperReply)); |
165 | config = GNUNET_malloc (config_size); | 165 | config = GNUNET_malloc(config_size); |
166 | GNUNET_assert (Z_OK == | 166 | GNUNET_assert(Z_OK == |
167 | uncompress ((Bytef *) config, &config_size, | 167 | uncompress((Bytef *)config, &config_size, |
168 | (const Bytef *) &msg[1], xconfig_size)); | 168 | (const Bytef *)&msg[1], xconfig_size)); |
169 | GNUNET_free (config); | 169 | GNUNET_free(config); |
170 | if (NULL == shutdown_task) | 170 | if (NULL == shutdown_task) |
171 | shutdown_task = | 171 | shutdown_task = |
172 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 172 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
173 | (GNUNET_TIME_UNIT_SECONDS, 1), | 173 | (GNUNET_TIME_UNIT_SECONDS, 1), |
174 | &do_shutdown, NULL); | 174 | &do_shutdown, NULL); |
175 | return GNUNET_OK; | 175 | return GNUNET_OK; |
176 | } | 176 | } |
177 | 177 | ||
@@ -183,7 +183,7 @@ mst_cb (void *cls, | |||
183 | * @param cls the closure from GNUNET_HELPER_start() | 183 | * @param cls the closure from GNUNET_HELPER_start() |
184 | */ | 184 | */ |
185 | static void | 185 | static void |
186 | exp_cb (void *cls) | 186 | exp_cb(void *cls) |
187 | { | 187 | { |
188 | helper = NULL; | 188 | helper = NULL; |
189 | result = GNUNET_SYSERR; | 189 | result = GNUNET_SYSERR; |
@@ -199,8 +199,8 @@ exp_cb (void *cls) | |||
199 | * @param cfg configuration | 199 | * @param cfg configuration |
200 | */ | 200 | */ |
201 | static void | 201 | static void |
202 | run (void *cls, char *const *args, const char *cfgfile, | 202 | run(void *cls, char *const *args, const char *cfgfile, |
203 | const struct GNUNET_CONFIGURATION_Handle *cfg2) | 203 | const struct GNUNET_CONFIGURATION_Handle *cfg2) |
204 | { | 204 | { |
205 | static char *const binary_argv[] = { | 205 | static char *const binary_argv[] = { |
206 | "gnunet-helper-testbed", | 206 | "gnunet-helper-testbed", |
@@ -209,22 +209,22 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
209 | const char *trusted_ip = "127.0.0.1"; | 209 | const char *trusted_ip = "127.0.0.1"; |
210 | 210 | ||
211 | helper = | 211 | helper = |
212 | GNUNET_HELPER_start (GNUNET_YES, | 212 | GNUNET_HELPER_start(GNUNET_YES, |
213 | "gnunet-helper-testbed", | 213 | "gnunet-helper-testbed", |
214 | binary_argv, | 214 | binary_argv, |
215 | &mst_cb, | 215 | &mst_cb, |
216 | &exp_cb, | 216 | &exp_cb, |
217 | NULL); | 217 | NULL); |
218 | GNUNET_assert (NULL != helper); | 218 | GNUNET_assert(NULL != helper); |
219 | cfg = GNUNET_CONFIGURATION_dup (cfg2); | 219 | cfg = GNUNET_CONFIGURATION_dup(cfg2); |
220 | msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, NULL, cfg); | 220 | msg = GNUNET_TESTBED_create_helper_init_msg_(trusted_ip, NULL, cfg); |
221 | shandle = | 221 | shandle = |
222 | GNUNET_HELPER_send (helper, &msg->header, GNUNET_NO, &cont_cb, NULL); | 222 | GNUNET_HELPER_send(helper, &msg->header, GNUNET_NO, &cont_cb, NULL); |
223 | GNUNET_assert (NULL != shandle); | 223 | GNUNET_assert(NULL != shandle); |
224 | abort_task = | 224 | abort_task = |
225 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 225 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
226 | (GNUNET_TIME_UNIT_MINUTES, 1), &do_abort, | 226 | (GNUNET_TIME_UNIT_MINUTES, 1), &do_abort, |
227 | NULL); | 227 | NULL); |
228 | } | 228 | } |
229 | 229 | ||
230 | 230 | ||
@@ -236,7 +236,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
236 | * @return return code | 236 | * @return return code |
237 | */ | 237 | */ |
238 | int | 238 | int |
239 | main (int argc, char **argv) | 239 | main(int argc, char **argv) |
240 | { | 240 | { |
241 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 241 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
242 | GNUNET_GETOPT_OPTION_END | 242 | GNUNET_GETOPT_OPTION_END |
@@ -244,9 +244,9 @@ main (int argc, char **argv) | |||
244 | 244 | ||
245 | result = GNUNET_OK; | 245 | result = GNUNET_OK; |
246 | if (GNUNET_OK != | 246 | if (GNUNET_OK != |
247 | GNUNET_PROGRAM_run (argc, argv, "test_gnunet_helper_testbed", | 247 | GNUNET_PROGRAM_run(argc, argv, "test_gnunet_helper_testbed", |
248 | "Testcase for testing gnunet-helper-testbed.c", | 248 | "Testcase for testing gnunet-helper-testbed.c", |
249 | options, &run, NULL)) | 249 | options, &run, NULL)) |
250 | return 1; | 250 | return 1; |
251 | return (GNUNET_OK == result) ? 0 : 1; | 251 | return (GNUNET_OK == result) ? 0 : 1; |
252 | } | 252 | } |