diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/cadet/test_cadet_local_mq.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/cadet/test_cadet_local_mq.c')
-rw-r--r-- | src/cadet/test_cadet_local_mq.c | 257 |
1 files changed, 129 insertions, 128 deletions
diff --git a/src/cadet/test_cadet_local_mq.c b/src/cadet/test_cadet_local_mq.c index 7ae0a90c4..c56b510ae 100644 --- a/src/cadet/test_cadet_local_mq.c +++ b/src/cadet/test_cadet_local_mq.c | |||
@@ -36,7 +36,8 @@ | |||
36 | /** | 36 | /** |
37 | * Test message structure. | 37 | * Test message structure. |
38 | */ | 38 | */ |
39 | struct GNUNET_CADET_TestMsg { | 39 | struct GNUNET_CADET_TestMsg |
40 | { | ||
40 | /** | 41 | /** |
41 | * Type: #TEST_MESSAGE_TYPE | 42 | * Type: #TEST_MESSAGE_TYPE |
42 | * | 43 | * |
@@ -73,46 +74,46 @@ static struct GNUNET_SCHEDULER_Task *connect_task; | |||
73 | * @param cls Closue (unused). | 74 | * @param cls Closue (unused). |
74 | */ | 75 | */ |
75 | static void | 76 | static void |
76 | do_connect(void *cls); | 77 | do_connect (void *cls); |
77 | 78 | ||
78 | 79 | ||
79 | /** | 80 | /** |
80 | * Shutdown nicely | 81 | * Shutdown nicely |
81 | */ | 82 | */ |
82 | static void | 83 | static void |
83 | do_shutdown(void *cls) | 84 | do_shutdown (void *cls) |
84 | { | 85 | { |
85 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 86 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
86 | "shutdown\n"); | 87 | "shutdown\n"); |
87 | if (NULL != abort_task) | 88 | if (NULL != abort_task) |
88 | { | 89 | { |
89 | GNUNET_SCHEDULER_cancel(abort_task); | 90 | GNUNET_SCHEDULER_cancel (abort_task); |
90 | abort_task = NULL; | 91 | abort_task = NULL; |
91 | } | 92 | } |
92 | if (NULL != ch) | 93 | if (NULL != ch) |
93 | { | 94 | { |
94 | GNUNET_CADET_channel_destroy(ch); | 95 | GNUNET_CADET_channel_destroy (ch); |
95 | ch = NULL; | 96 | ch = NULL; |
96 | } | 97 | } |
97 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 98 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
98 | "Disconnect client 1\n"); | 99 | "Disconnect client 1\n"); |
99 | if (NULL != cadet_peer_1) | 100 | if (NULL != cadet_peer_1) |
100 | { | 101 | { |
101 | GNUNET_CADET_disconnect(cadet_peer_1); | 102 | GNUNET_CADET_disconnect (cadet_peer_1); |
102 | cadet_peer_1 = NULL; | 103 | cadet_peer_1 = NULL; |
103 | } | 104 | } |
104 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
105 | "Disconnect client 2\n"); | 106 | "Disconnect client 2\n"); |
106 | if (NULL != cadet_peer_2) | 107 | if (NULL != cadet_peer_2) |
107 | { | 108 | { |
108 | GNUNET_CADET_disconnect(cadet_peer_2); | 109 | GNUNET_CADET_disconnect (cadet_peer_2); |
109 | cadet_peer_2 = NULL; | 110 | cadet_peer_2 = NULL; |
110 | } | 111 | } |
111 | if (NULL != connect_task) | 112 | if (NULL != connect_task) |
112 | { | 113 | { |
113 | GNUNET_SCHEDULER_cancel(connect_task); | 114 | GNUNET_SCHEDULER_cancel (connect_task); |
114 | connect_task = NULL; | 115 | connect_task = NULL; |
115 | } | 116 | } |
116 | } | 117 | } |
117 | 118 | ||
118 | 119 | ||
@@ -120,14 +121,14 @@ do_shutdown(void *cls) | |||
120 | * Something went wrong and timed out. Kill everything and set error flag | 121 | * Something went wrong and timed out. Kill everything and set error flag |
121 | */ | 122 | */ |
122 | static void | 123 | static void |
123 | do_abort(void *cls) | 124 | do_abort (void *cls) |
124 | { | 125 | { |
125 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
126 | "ABORT from line %ld\n", | 127 | "ABORT from line %ld\n", |
127 | (long)cls); | 128 | (long) cls); |
128 | result = GNUNET_SYSERR; | 129 | result = GNUNET_SYSERR; |
129 | abort_task = NULL; | 130 | abort_task = NULL; |
130 | GNUNET_SCHEDULER_shutdown(); | 131 | GNUNET_SCHEDULER_shutdown (); |
131 | } | 132 | } |
132 | 133 | ||
133 | /** | 134 | /** |
@@ -143,14 +144,14 @@ do_abort(void *cls) | |||
143 | * received on the @a channel. | 144 | * received on the @a channel. |
144 | */ | 145 | */ |
145 | static void * | 146 | static void * |
146 | connected(void *cls, | 147 | connected (void *cls, |
147 | struct GNUNET_CADET_Channel *channel, | 148 | struct GNUNET_CADET_Channel *channel, |
148 | const struct GNUNET_PeerIdentity *source) | 149 | const struct GNUNET_PeerIdentity *source) |
149 | { | 150 | { |
150 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
151 | "connected %s, cls: %p\n", | 152 | "connected %s, cls: %p\n", |
152 | GNUNET_i2s(source), | 153 | GNUNET_i2s (source), |
153 | cls); | 154 | cls); |
154 | return channel; | 155 | return channel; |
155 | } | 156 | } |
156 | 157 | ||
@@ -166,12 +167,12 @@ connected(void *cls, | |||
166 | * @param channel Connection to the other end (henceforth invalid). | 167 | * @param channel Connection to the other end (henceforth invalid). |
167 | */ | 168 | */ |
168 | static void | 169 | static void |
169 | disconnected(void *cls, | 170 | disconnected (void *cls, |
170 | const struct GNUNET_CADET_Channel *channel) | 171 | const struct GNUNET_CADET_Channel *channel) |
171 | { | 172 | { |
172 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
173 | "disconnected channel %p, cls: %p\n", | 174 | "disconnected channel %p, cls: %p\n", |
174 | channel, cls); | 175 | channel, cls); |
175 | if (channel == ch) | 176 | if (channel == ch) |
176 | ch = NULL; | 177 | ch = NULL; |
177 | } | 178 | } |
@@ -184,19 +185,19 @@ disconnected(void *cls, | |||
184 | * @param msg A message with the details of the new incoming channel | 185 | * @param msg A message with the details of the new incoming channel |
185 | */ | 186 | */ |
186 | static void | 187 | static void |
187 | handle_data_received(void *cls, | 188 | handle_data_received (void *cls, |
188 | const struct GNUNET_CADET_TestMsg *msg) | 189 | const struct GNUNET_CADET_TestMsg *msg) |
189 | { | 190 | { |
190 | uint64_t payload; | 191 | uint64_t payload; |
191 | 192 | ||
192 | payload = GNUNET_ntohll(msg->payload); | 193 | payload = GNUNET_ntohll (msg->payload); |
193 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
194 | "Data callback payload %llu with cls: %p! Shutting down.\n", | 195 | "Data callback payload %llu with cls: %p! Shutting down.\n", |
195 | (unsigned long long)payload, | 196 | (unsigned long long) payload, |
196 | cls); | 197 | cls); |
197 | GNUNET_assert(42 == payload); | 198 | GNUNET_assert (42 == payload); |
198 | got_data = GNUNET_YES; | 199 | got_data = GNUNET_YES; |
199 | GNUNET_SCHEDULER_shutdown(); | 200 | GNUNET_SCHEDULER_shutdown (); |
200 | } | 201 | } |
201 | 202 | ||
202 | 203 | ||
@@ -206,10 +207,10 @@ handle_data_received(void *cls, | |||
206 | * @param cls Closure (unused). | 207 | * @param cls Closure (unused). |
207 | */ | 208 | */ |
208 | static void | 209 | static void |
209 | message_sent(void *cls) | 210 | message_sent (void *cls) |
210 | { | 211 | { |
211 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
212 | "message sent\n"); | 213 | "message sent\n"); |
213 | } | 214 | } |
214 | 215 | ||
215 | 216 | ||
@@ -219,7 +220,7 @@ message_sent(void *cls) | |||
219 | * @param cls Closure (unused). | 220 | * @param cls Closure (unused). |
220 | */ | 221 | */ |
221 | static void | 222 | static void |
222 | do_connect(void *cls) | 223 | do_connect (void *cls) |
223 | { | 224 | { |
224 | struct GNUNET_PeerIdentity id; | 225 | struct GNUNET_PeerIdentity id; |
225 | struct GNUNET_MQ_Handle *mq; | 226 | struct GNUNET_MQ_Handle *mq; |
@@ -227,32 +228,32 @@ do_connect(void *cls) | |||
227 | struct GNUNET_CADET_TestMsg *msg; | 228 | struct GNUNET_CADET_TestMsg *msg; |
228 | 229 | ||
229 | struct GNUNET_MQ_MessageHandler handlers[] = { | 230 | struct GNUNET_MQ_MessageHandler handlers[] = { |
230 | GNUNET_MQ_hd_fixed_size(data_received, | 231 | GNUNET_MQ_hd_fixed_size (data_received, |
231 | TEST_MESSAGE_TYPE, | 232 | TEST_MESSAGE_TYPE, |
232 | struct GNUNET_CADET_TestMsg, | 233 | struct GNUNET_CADET_TestMsg, |
233 | cadet_peer_1), | 234 | cadet_peer_1), |
234 | GNUNET_MQ_handler_end() | 235 | GNUNET_MQ_handler_end () |
235 | }; | 236 | }; |
236 | 237 | ||
237 | connect_task = NULL; | 238 | connect_task = NULL; |
238 | GNUNET_TESTING_peer_get_identity(me, &id); | 239 | GNUNET_TESTING_peer_get_identity (me, &id); |
239 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
240 | "creating channel\n"); | 241 | "creating channel\n"); |
241 | ch = GNUNET_CADET_channel_create(cadet_peer_1, /* cadet handle */ | 242 | ch = GNUNET_CADET_channel_create (cadet_peer_1, /* cadet handle */ |
242 | NULL, /* channel cls */ | 243 | NULL, /* channel cls */ |
243 | &id, /* destination */ | 244 | &id, /* destination */ |
244 | GC_u2h(TEST_MESSAGE_TYPE), /* port */ | 245 | GC_u2h (TEST_MESSAGE_TYPE), /* port */ |
245 | NULL, /* window change */ | 246 | NULL, /* window change */ |
246 | &disconnected, /* disconnect handler */ | 247 | &disconnected, /* disconnect handler */ |
247 | handlers /* traffic handlers */ | 248 | handlers /* traffic handlers */ |
248 | ); | 249 | ); |
249 | env = GNUNET_MQ_msg(msg, TEST_MESSAGE_TYPE); | 250 | env = GNUNET_MQ_msg (msg, TEST_MESSAGE_TYPE); |
250 | msg->payload = GNUNET_htonll(42); | 251 | msg->payload = GNUNET_htonll (42); |
251 | mq = GNUNET_CADET_get_mq(ch); | 252 | mq = GNUNET_CADET_get_mq (ch); |
252 | GNUNET_MQ_notify_sent(env, &message_sent, NULL); | 253 | GNUNET_MQ_notify_sent (env, &message_sent, NULL); |
253 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
254 | "sending message\n"); | 255 | "sending message\n"); |
255 | GNUNET_MQ_send(mq, env); | 256 | GNUNET_MQ_send (mq, env); |
256 | } | 257 | } |
257 | 258 | ||
258 | 259 | ||
@@ -264,53 +265,53 @@ do_connect(void *cls) | |||
264 | * @param peer Testing peer handle. | 265 | * @param peer Testing peer handle. |
265 | */ | 266 | */ |
266 | static void | 267 | static void |
267 | run(void *cls, | 268 | run (void *cls, |
268 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 269 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
269 | struct GNUNET_TESTING_Peer *peer) | 270 | struct GNUNET_TESTING_Peer *peer) |
270 | { | 271 | { |
271 | struct GNUNET_MQ_MessageHandler handlers[] = { | 272 | struct GNUNET_MQ_MessageHandler handlers[] = { |
272 | GNUNET_MQ_hd_fixed_size(data_received, | 273 | GNUNET_MQ_hd_fixed_size (data_received, |
273 | TEST_MESSAGE_TYPE, | 274 | TEST_MESSAGE_TYPE, |
274 | struct GNUNET_CADET_TestMsg, | 275 | struct GNUNET_CADET_TestMsg, |
275 | cadet_peer_2), | 276 | cadet_peer_2), |
276 | GNUNET_MQ_handler_end() | 277 | GNUNET_MQ_handler_end () |
277 | }; | 278 | }; |
278 | struct GNUNET_TIME_Relative delay; | 279 | struct GNUNET_TIME_Relative delay; |
279 | 280 | ||
280 | me = peer; | 281 | me = peer; |
281 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | 282 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
282 | NULL); | 283 | NULL); |
283 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15); | 284 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15); |
284 | abort_task = GNUNET_SCHEDULER_add_delayed(delay, | 285 | abort_task = GNUNET_SCHEDULER_add_delayed (delay, |
285 | &do_abort, | 286 | &do_abort, |
286 | (void *)(long)__LINE__); | 287 | (void *) (long) __LINE__); |
287 | cadet_peer_1 = GNUNET_CADET_connect(cfg); | 288 | cadet_peer_1 = GNUNET_CADET_connect (cfg); |
288 | cadet_peer_2 = GNUNET_CADET_connect(cfg); | 289 | cadet_peer_2 = GNUNET_CADET_connect (cfg); |
289 | 290 | ||
290 | if ((NULL == cadet_peer_1) || | 291 | if ((NULL == cadet_peer_1) || |
291 | (NULL == cadet_peer_2)) | 292 | (NULL == cadet_peer_2)) |
292 | { | 293 | { |
293 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 294 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
294 | "Couldn't connect to cadet\n"); | 295 | "Couldn't connect to cadet\n"); |
295 | result = GNUNET_SYSERR; | 296 | result = GNUNET_SYSERR; |
296 | GNUNET_SCHEDULER_shutdown(); | 297 | GNUNET_SCHEDULER_shutdown (); |
297 | return; | 298 | return; |
298 | } | 299 | } |
299 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CADET 1: %p\n", cadet_peer_1); | 300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CADET 1: %p\n", cadet_peer_1); |
300 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CADET 2: %p\n", cadet_peer_2); | 301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CADET 2: %p\n", cadet_peer_2); |
301 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "handlers 2: %p\n", handlers); | 302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handlers 2: %p\n", handlers); |
302 | GNUNET_CADET_open_port(cadet_peer_2, /* cadet handle */ | 303 | GNUNET_CADET_open_port (cadet_peer_2, /* cadet handle */ |
303 | GC_u2h(TEST_PORT_ID), /* port id */ | 304 | GC_u2h (TEST_PORT_ID), /* port id */ |
304 | &connected, /* connect handler */ | 305 | &connected, /* connect handler */ |
305 | (void *)2L, /* handle for #connected */ | 306 | (void *) 2L, /* handle for #connected */ |
306 | NULL, /* window size handler */ | 307 | NULL, /* window size handler */ |
307 | &disconnected, /* disconnect handler */ | 308 | &disconnected, /* disconnect handler */ |
308 | handlers); /* traffic handlers */ | 309 | handlers); /* traffic handlers */ |
309 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2); | 310 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2); |
310 | if (NULL == connect_task) | 311 | if (NULL == connect_task) |
311 | connect_task = GNUNET_SCHEDULER_add_delayed(delay, | 312 | connect_task = GNUNET_SCHEDULER_add_delayed (delay, |
312 | &do_connect, | 313 | &do_connect, |
313 | NULL); | 314 | NULL); |
314 | } | 315 | } |
315 | 316 | ||
316 | 317 | ||
@@ -318,16 +319,16 @@ run(void *cls, | |||
318 | * Main | 319 | * Main |
319 | */ | 320 | */ |
320 | int | 321 | int |
321 | main(int argc, char *argv[]) | 322 | main (int argc, char *argv[]) |
322 | { | 323 | { |
323 | if (0 != GNUNET_TESTING_peer_run("test-cadet-local", | 324 | if (0 != GNUNET_TESTING_peer_run ("test-cadet-local", |
324 | "test_cadet.conf", | 325 | "test_cadet.conf", |
325 | &run, NULL)) | 326 | &run, NULL)) |
326 | { | 327 | { |
327 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "run failed\n"); | 328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "run failed\n"); |
328 | return 2; | 329 | return 2; |
329 | } | 330 | } |
330 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Final result: %d\n", result); | 331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Final result: %d\n", result); |
331 | return (result == GNUNET_OK) ? 0 : 1; | 332 | return (result == GNUNET_OK) ? 0 : 1; |
332 | } | 333 | } |
333 | 334 | ||