aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_address_switch.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-22 22:02:38 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-22 22:02:38 +0000
commit25a2ea0274d4d958bd9b7ca72390f0a4fb0cfc9d (patch)
tree861f5c21828a3cc6d8b0cfe2623ad7a185ab22eb /src/transport/test_transport_address_switch.c
parent8d0883a3f695261cfd8651ed53734f2f4fb30417 (diff)
downloadgnunet-25a2ea0274d4d958bd9b7ca72390f0a4fb0cfc9d.tar.gz
gnunet-25a2ea0274d4d958bd9b7ca72390f0a4fb0cfc9d.zip
migrate more tests to new transmission API
Diffstat (limited to 'src/transport/test_transport_address_switch.c')
-rw-r--r--src/transport/test_transport_address_switch.c135
1 files changed, 31 insertions, 104 deletions
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c
index 198e82118..23325d392 100644
--- a/src/transport/test_transport_address_switch.c
+++ b/src/transport/test_transport_address_switch.c
@@ -48,40 +48,16 @@
48#include "transport-testing.h" 48#include "transport-testing.h"
49 49
50 50
51GNUNET_NETWORK_STRUCT_BEGIN
52struct TestMessage
53{
54 struct GNUNET_MessageHeader header;
55 uint32_t num GNUNET_PACKED;
56};
57GNUNET_NETWORK_STRUCT_END
58
59/**
60 * Message type for test messages
61 */
62#define MTYPE 12345
63
64/**
65 * Message size for test messages
66 */
67#define MSIZE 2048
68
69/** 51/**
70 * Testcase timeout 52 * Testcase timeout
71 */ 53 */
72#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 54#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
73 55
74/**
75 * How long until we give up on transmitting the message?
76 */
77#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
78
79 56
80static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 57static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
81 58
82static struct GNUNET_SCHEDULER_Task *measure_task; 59static struct GNUNET_SCHEDULER_Task *measure_task;
83 60
84static struct GNUNET_TRANSPORT_TransmitHandle *th;
85 61
86/** 62/**
87 * Statistics we track per peer. 63 * Statistics we track per peer.
@@ -243,11 +219,6 @@ custom_shutdown (void *cls)
243 stats[i].stat = NULL; 219 stats[i].stat = NULL;
244 } 220 }
245 } 221 }
246 if (NULL != th)
247 {
248 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
249 th = NULL;
250 }
251 222
252 result = 0; 223 result = 0;
253 FPRINTF (stderr, "\n"); 224 FPRINTF (stderr, "\n");
@@ -293,14 +264,16 @@ custom_shutdown (void *cls)
293 if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && 264 if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
294 (bytes_sent_after_switch == 0) ) 265 (bytes_sent_after_switch == 0) )
295 { 266 {
296 FPRINTF (stderr, "No data sent after switching!\n"); 267 FPRINTF (stderr,
268 "No data sent after switching!\n");
297 GNUNET_break (0); 269 GNUNET_break (0);
298 result++; 270 result++;
299 } 271 }
300 if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && 272 if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
301 (bytes_recv_after_switch == 0) ) 273 (bytes_recv_after_switch == 0) )
302 { 274 {
303 FPRINTF (stderr, "No data received after switching!\n"); 275 FPRINTF (stderr,
276 "No data received after switching!\n");
304 GNUNET_break (0); 277 GNUNET_break (0);
305 result++; 278 result++;
306 } 279 }
@@ -315,10 +288,10 @@ notify_receive (void *cls,
315 const struct GNUNET_PeerIdentity *sender, 288 const struct GNUNET_PeerIdentity *sender,
316 const struct GNUNET_MessageHeader *message) 289 const struct GNUNET_MessageHeader *message)
317{ 290{
318 const struct TestMessage *hdr; 291 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr;
319 292
320 hdr = (const struct TestMessage *) message; 293 hdr = (const struct GNUNET_TRANSPORT_TESTING_TestMessage *) message;
321 if (MTYPE != ntohs (message->type)) 294 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type))
322 return; 295 return;
323 296
324 { 297 {
@@ -338,7 +311,8 @@ notify_receive (void *cls,
338 (stats[1].switch_attempts == stats[1].switch_fail + stats[1].switch_success) ) 311 (stats[1].switch_attempts == stats[1].switch_fail + stats[1].switch_success) )
339 { 312 {
340 bytes_recv_after_switch += ntohs(hdr->header.size); 313 bytes_recv_after_switch += ntohs(hdr->header.size);
341 if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0)) 314 if ( (bytes_sent_after_switch > 0) &&
315 (bytes_recv_after_switch > 0) )
342 { 316 {
343 /* A peer switched addresses and sent and received data after the 317 /* A peer switched addresses and sent and received data after the
344 * switch operations */ 318 * switch operations */
@@ -348,75 +322,26 @@ notify_receive (void *cls,
348} 322}
349 323
350 324
351static size_t 325static void
352notify_ready (void *cls, size_t size, void *buf) 326notify_send (void *cls)
353{ 327{
354 static uint32_t counter; 328 static uint32_t cnt;
355 char *cbuf = buf; 329
356 struct TestMessage hdr; 330 GNUNET_assert (GNUNET_OK ==
357 331 GNUNET_TRANSPORT_TESTING_send (ccc->p[1],
358 th = NULL; 332 ccc->p[0],
359 if (buf == NULL) 333 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
360 { 334 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE,
361 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 335 ++cnt,
362 "Timeout occurred while waiting for transmit_ready for message\n"); 336 &notify_send,
363 ccc->global_ret = GNUNET_SYSERR; 337 NULL));
364 GNUNET_SCHEDULER_shutdown ();
365 return 0;
366 }
367
368 GNUNET_assert(size >= MSIZE);
369 GNUNET_assert(buf != NULL);
370 cbuf = buf;
371
372 hdr.header.size = htons (MSIZE);
373 hdr.header.type = htons (MTYPE);
374 hdr.num = htonl (counter++);
375 GNUNET_memcpy (&cbuf[0], &hdr, sizeof(struct TestMessage));
376 memset (&cbuf[sizeof(struct TestMessage)], '0', MSIZE - sizeof(struct TestMessage));
377
378 {
379 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
380
381 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
382 "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n",
383 (unsigned int) (counter - 1),
384 MSIZE,
385 ccc->p[1]->no,
386 GNUNET_i2s (&ccc->p[1]->id),
387 ccc->p[0]->no,
388 receiver_s);
389 GNUNET_free(receiver_s);
390 }
391
392 if (th == NULL)
393 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
394 &ccc->p[0]->id,
395 MSIZE,
396 TIMEOUT_TRANSMIT,
397 &notify_ready,
398 NULL);
399
400 if ( ( (stats[0].switch_attempts >= 1) || 338 if ( ( (stats[0].switch_attempts >= 1) ||
401 (stats[1].switch_attempts >= 1) ) && 339 (stats[1].switch_attempts >= 1) ) &&
402 (stats[0].switch_attempts == stats[0].switch_fail + stats[0].switch_success) && 340 (stats[0].switch_attempts == stats[0].switch_fail + stats[0].switch_success) &&
403 (stats[1].switch_attempts == stats[1].switch_fail + stats[1].switch_success) ) 341 (stats[1].switch_attempts == stats[1].switch_fail + stats[1].switch_success) )
404 { 342 {
405 bytes_sent_after_switch += MSIZE; 343 bytes_sent_after_switch
406 } 344 += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE;
407 return MSIZE;
408}
409
410
411static void
412notify_disconnect (void *cls,
413 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
414 const struct GNUNET_PeerIdentity *other)
415{
416 if (NULL != th)
417 {
418 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
419 th = NULL;
420 } 345 }
421} 346}
422 347
@@ -472,11 +397,14 @@ connected_cb (void *cls)
472 &progress_indicator, 397 &progress_indicator,
473 NULL); 398 NULL);
474 /* Peers are connected, start transmit test messages */ 399 /* Peers are connected, start transmit test messages */
475 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, 400 GNUNET_assert (GNUNET_OK ==
476 &ccc->p[0]->id, MSIZE, 401 GNUNET_TRANSPORT_TESTING_send (ccc->p[1],
477 TIMEOUT_TRANSMIT, 402 ccc->p[0],
478 &notify_ready, NULL); 403 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
479 404 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE,
405 0,
406 &notify_send,
407 NULL));
480} 408}
481 409
482 410
@@ -489,7 +417,6 @@ main (int argc,
489 .config_file = "test_transport_api.conf", 417 .config_file = "test_transport_api.conf",
490 .rec = &notify_receive, 418 .rec = &notify_receive,
491 .nc = &GNUNET_TRANSPORT_TESTING_log_connect, 419 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
492 .nd = &notify_disconnect,
493 .shutdown_task = &custom_shutdown, 420 .shutdown_task = &custom_shutdown,
494 .timeout = TIMEOUT 421 .timeout = TIMEOUT
495 }; 422 };