From b2bdeca1c78a40abb2f2295c48a31f92e6e32ec0 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 8 Jul 2016 18:19:52 +0000 Subject: [PATCH] -fix cancellations in test --- src/core/test_core_api.c | 36 ++++++++++++----- src/core/test_core_api_reliability.c | 57 +++++++++++++++++++-------- src/core/test_core_quota_compliance.c | 29 +++++++++++--- 3 files changed, 91 insertions(+), 31 deletions(-) diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index 43f4c421e..b012aa213 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c @@ -35,7 +35,7 @@ struct PeerContext struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_CORE_Handle *ch; struct GNUNET_PeerIdentity id; - struct GNUNET_TRANSPORT_Handle *th; + struct GNUNET_TRANSPORT_OfferHelloHandle *oh; struct GNUNET_TRANSPORT_GetHelloHandle *ghh; struct GNUNET_ATS_ConnectivityHandle *ats; struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; @@ -55,6 +55,15 @@ static int ok; #define OKPP do { ok++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) +static void +offer_hello_done (void *cls) +{ + struct PeerContext *p = cls; + + p->oh = NULL; +} + + static void process_hello (void *cls, const struct GNUNET_MessageHeader *message) @@ -64,10 +73,15 @@ process_hello (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received (my) `%s' from transport service\n", "HELLO"); GNUNET_assert (message != NULL); - if ((p == &p1) && (p2.th != NULL)) - GNUNET_TRANSPORT_offer_hello (p2.cfg, message, NULL, NULL); - if ((p == &p2) && (p1.th != NULL)) - GNUNET_TRANSPORT_offer_hello (p1.cfg, message, NULL, NULL); + if ((p == &p1) && (NULL == p2.oh)) + p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, message, + &offer_hello_done, + &p2); + if ((p == &p2) && (NULL == p1.oh)) + p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, + message, + &offer_hello_done, + &p1); } @@ -79,11 +93,15 @@ terminate_peer (struct PeerContext *p) GNUNET_CORE_disconnect (p->ch); p->ch = NULL; } - if (NULL != p->th) + if (NULL != p->ghh) { GNUNET_TRANSPORT_get_hello_cancel (p->ghh); - GNUNET_TRANSPORT_disconnect (p->th); - p->th = NULL; + p->ghh = NULL; + } + if (NULL != p->oh) + { + GNUNET_TRANSPORT_offer_hello_cancel (p->oh); + p->oh = NULL; } if (NULL != p->ats_sh) { @@ -276,8 +294,6 @@ setup_peer (struct PeerContext *p, "gnunet-service-arm", "-c", cfgname, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); - p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); - GNUNET_assert (NULL != p->th); p->ats = GNUNET_ATS_connectivity_init (p->cfg); GNUNET_assert (NULL != p->ats); p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg, &process_hello, p); diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c index 10cef0e0d..99eb7ea21 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c @@ -61,7 +61,7 @@ struct PeerContext struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_CORE_Handle *ch; struct GNUNET_PeerIdentity id; - struct GNUNET_TRANSPORT_Handle *th; + struct GNUNET_TRANSPORT_OfferHelloHandle *oh; struct GNUNET_MessageHeader *hello; struct GNUNET_TRANSPORT_GetHelloHandle *ghh; struct GNUNET_ATS_ConnectivityHandle *ats; @@ -108,11 +108,15 @@ terminate_peer (struct PeerContext *p) GNUNET_CORE_disconnect (p->ch); p->ch = NULL; } - if (NULL != p->th) + if (NULL != p->ghh) { GNUNET_TRANSPORT_get_hello_cancel (p->ghh); - GNUNET_TRANSPORT_disconnect (p->th); - p->th = NULL; + p->ghh = NULL; + } + if (NULL != p->oh) + { + GNUNET_TRANSPORT_offer_hello_cancel (p->oh); + p->oh = NULL; } if (NULL != p->ats_sh) { @@ -401,6 +405,15 @@ init_notify (void *cls, } +static void +offer_hello_done (void *cls) +{ + struct PeerContext *p = cls; + + p->oh = NULL; +} + + static void process_hello (void *cls, const struct GNUNET_MessageHeader *message) @@ -411,15 +424,27 @@ process_hello (void *cls, "Received (my) `%s' from transport service\n", "HELLO"); GNUNET_assert (message != NULL); p->hello = GNUNET_copy_message (message); - if ((p == &p1) && (p2.th != NULL)) - GNUNET_TRANSPORT_offer_hello (p2.cfg, message, NULL, NULL); - if ((p == &p2) && (p1.th != NULL)) - GNUNET_TRANSPORT_offer_hello (p1.cfg, message, NULL, NULL); - - if ((p == &p1) && (p2.hello != NULL)) - GNUNET_TRANSPORT_offer_hello (p1.cfg, p2.hello, NULL, NULL); - if ((p == &p2) && (p1.hello != NULL)) - GNUNET_TRANSPORT_offer_hello (p2.cfg, p1.hello, NULL, NULL); + if ((p == &p1) && (NULL == p2.oh)) + p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, + message, + &offer_hello_done, + &p2); + if ((p == &p2) && (NULL == p1.oh)) + p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, + message, + &offer_hello_done, + &p1); + + if ((p == &p1) && (p2.hello != NULL) && (NULL == p1.oh) ) + p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, + p2.hello, + &offer_hello_done, + &p1); + if ((p == &p2) && (p1.hello != NULL) && (NULL == p2.oh) ) + p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, + p1.hello, + &offer_hello_done, + &p2); } @@ -438,11 +463,11 @@ setup_peer (struct PeerContext *p, "gnunet-service-arm", "-c", cfgname, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); - p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); - GNUNET_assert (p->th != NULL); p->ats = GNUNET_ATS_connectivity_init (p->cfg); GNUNET_assert (NULL != p->ats); - p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg, &process_hello, p); + p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg, + &process_hello, + p); GNUNET_free (binary); } diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index c30a4fec8..a0c456cef 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c @@ -540,6 +540,15 @@ init_notify (void *cls, } +static void +offer_hello_done (void *cls) +{ + struct PeerContext *p = cls; + + p->oh = NULL; +} + + static void process_hello (void *cls, const struct GNUNET_MessageHeader *message) { @@ -551,18 +560,28 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) p->hello = GNUNET_malloc (ntohs (message->size)); GNUNET_memcpy (p->hello, message, ntohs (message->size)); if ((p == &p1) && (NULL == p2.oh)) - p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, message, NULL, NULL); + p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, + message, + &offer_hello_done, + &p2); if ((p == &p2) && (NULL == p1.oh)) - p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, message, NULL, NULL); + p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, message, + &offer_hello_done, + &p1); if ((p == &p1) && (p2.hello != NULL) && (NULL == p1.oh)) - p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, p2.hello, NULL, NULL); + p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, + p2.hello, + &offer_hello_done, + &p1); if ((p == &p2) && (p1.hello != NULL) && (NULL == p2.oh) ) - p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, p1.hello, NULL, NULL); + p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, + p1.hello, + &offer_hello_done, + &p2); } - static void setup_peer (struct PeerContext *p, const char *cfgname) { -- 2.25.1