From 187f3ee1b6edac986b7bc46c62c86a138290b147 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 5 Jun 2011 13:07:13 +0000 Subject: adapting testcases to use new API --- src/transport/test_transport_api_unreliability.c | 192 ++++++++++++----------- 1 file changed, 97 insertions(+), 95 deletions(-) (limited to 'src/transport/test_transport_api_unreliability.c') diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c index d27a5193e..fadb49f5d 100644 --- a/src/transport/test_transport_api_unreliability.c +++ b/src/transport/test_transport_api_unreliability.c @@ -98,6 +98,8 @@ static struct GNUNET_TIME_Absolute start_time; static GNUNET_SCHEDULER_TaskIdentifier die_task; +static GNUNET_SCHEDULER_TaskIdentifier tct; + static char *key_file_p1; static char *cert_file_p1; @@ -112,13 +114,6 @@ static int msg_scheduled; static int msg_sent; static int msg_recv_expected; static int msg_recv; -static struct GNUNET_TRANSPORT_TransmitHandle * transmit_handle; - -#if VERBOSE -#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) -#else -#define OKPP do { ok++; } while (0) -#endif /** * Sets a bit active in the bitmap. @@ -261,10 +256,20 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Reliability failed: \nLast message sent %u \nNext message scheduled %u\nLast message received %u\nMessage expected %u \n ", msg_sent, msg_scheduled, msg_recv, msg_recv_expected); + "Reliability failed: Last message sent %u Next message scheduled %u Last message received %u Message expected %u\n", + msg_sent, + msg_scheduled, + msg_recv, + msg_recv_expected); GNUNET_break (0); GNUNET_TRANSPORT_disconnect (p1.th); GNUNET_TRANSPORT_disconnect (p2.th); + + if (GNUNET_SCHEDULER_NO_TASK != tct) + { + GNUNET_SCHEDULER_cancel (tct); + tct = GNUNET_SCHEDULER_NO_TASK; + } ok = 1; } @@ -427,12 +432,67 @@ notify_ready (void *cls, size_t size, void *buf) } + +static void +notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) +{ + connected--; +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer `%4s' disconnected (%p)!\n", + GNUNET_i2s (peer), cls); +#endif +} + + + +static void +exchange_hello_last (void *cls, + const struct GNUNET_MessageHeader *message) +{ + struct PeerContext *me = cls; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Exchanging HELLO of size %d with peer (%s)!\n", + (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), + GNUNET_i2s (&me->id)); + GNUNET_assert (message != NULL); + GNUNET_assert (GNUNET_OK == + GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) + message, &me->id)); + GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL); +} + + + +static void +exchange_hello (void *cls, + const struct GNUNET_MessageHeader *message) +{ + struct PeerContext *me = cls; + + GNUNET_assert (message != NULL); + GNUNET_assert (GNUNET_OK == + GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) + message, &me->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Exchanging HELLO of size %d from peer %s!\n", + (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), + GNUNET_i2s (&me->id)); + GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); +} + + static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer `%4s' connected to us (%p)!\n", + GNUNET_i2s (peer), + cls); if (cls == &p1) { GNUNET_TRANSPORT_set_quota (p1.th, @@ -450,35 +510,22 @@ notify_connect (void *cls, GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024)); connected++; } - - if (connected == 2) + if (2 == connected) { - - if ((transmit_handle!=NULL) && (cls == NULL)) - GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); - if ((transmit_handle!=NULL) && (cls == &transmit_handle)) - transmit_handle=NULL; + GNUNET_SCHEDULER_cancel (die_task); + GNUNET_SCHEDULER_cancel (tct); + tct = GNUNET_SCHEDULER_NO_TASK; + GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); + GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); + die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &end_badly, NULL); GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, get_size (0), 0, TIMEOUT, ¬ify_ready, NULL); + } -#if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); -#endif -} - - -static void -notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) -{ -#if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer `%4s' disconnected (%p)!\n", - GNUNET_i2s (peer), cls); -#endif } @@ -562,69 +609,6 @@ setup_peer (struct PeerContext *p, const char *cfgname) GNUNET_assert (p->th != NULL); } -static size_t -notify_ready_connect (void *cls, size_t size, void *buf) -{ - return 0; -} - -static void -exchange_hello_last (void *cls, - const struct GNUNET_MessageHeader *message) -{ - struct PeerContext *me = cls; - transmit_handle = NULL; - GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, me); -#if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Exchanging HELLO with peer (%p)!\n", cls); -#endif - GNUNET_assert (ok >= 3); - OKPP; - GNUNET_assert (message != NULL); - GNUNET_assert (GNUNET_OK == - GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) - message, &me->id)); - - GNUNET_assert(NULL != (transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, - &p1.id, - sizeof (struct GNUNET_MessageHeader), 0, - TIMEOUT, - ¬ify_ready_connect, - &transmit_handle))); - - /* both HELLOs exchanged, get ready to test transmission! */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finished exchanging HELLOs, now waiting for transmission!\n"); -} - - -static void -exchange_hello (void *cls, - const struct GNUNET_MessageHeader *message) -{ - struct PeerContext *me = cls; - - GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me); -#if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Exchanging HELLO with peer (%p)!\n", cls); -#endif - GNUNET_assert (ok >= 2); - OKPP; - GNUNET_assert (message != NULL); - GNUNET_assert (GNUNET_OK == - GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) - message, &me->id)); - -#if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received HELLO size %d\n", - GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message)); -#endif - GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); - GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); -} /** * Return the actual path to a file found in the current @@ -737,13 +721,29 @@ check_gnunet_nat_binary(char *binary) #endif } + +static void +try_connect (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Asking peers to connect...\n"); + GNUNET_TRANSPORT_try_connect (p2.th, + &p1.id); + GNUNET_TRANSPORT_try_connect (p1.th, + &p2.id); + tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &try_connect, + NULL); +} + + + static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { - GNUNET_assert (ok == 1); - OKPP; die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); @@ -787,6 +787,8 @@ run (void *cls, GNUNET_assert(p1.th != NULL); GNUNET_assert(p2.th != NULL); GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); + GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); + tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL); } -- cgit v1.2.3