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