aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-08 18:19:52 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-08 18:19:52 +0000
commitb2bdeca1c78a40abb2f2295c48a31f92e6e32ec0 (patch)
tree5324cedba75f6598234d260621b01bc96579b5d2 /src/core
parentc32824526668948c5555f95ef545733004cc5e4a (diff)
downloadgnunet-b2bdeca1c78a40abb2f2295c48a31f92e6e32ec0.tar.gz
gnunet-b2bdeca1c78a40abb2f2295c48a31f92e6e32ec0.zip
-fix cancellations in test
Diffstat (limited to 'src/core')
-rw-r--r--src/core/test_core_api.c36
-rw-r--r--src/core/test_core_api_reliability.c57
-rw-r--r--src/core/test_core_quota_compliance.c29
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
35 struct GNUNET_CONFIGURATION_Handle *cfg; 35 struct GNUNET_CONFIGURATION_Handle *cfg;
36 struct GNUNET_CORE_Handle *ch; 36 struct GNUNET_CORE_Handle *ch;
37 struct GNUNET_PeerIdentity id; 37 struct GNUNET_PeerIdentity id;
38 struct GNUNET_TRANSPORT_Handle *th; 38 struct GNUNET_TRANSPORT_OfferHelloHandle *oh;
39 struct GNUNET_TRANSPORT_GetHelloHandle *ghh; 39 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
40 struct GNUNET_ATS_ConnectivityHandle *ats; 40 struct GNUNET_ATS_ConnectivityHandle *ats;
41 struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; 41 struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
@@ -56,6 +56,15 @@ static int ok;
56 56
57 57
58static void 58static void
59offer_hello_done (void *cls)
60{
61 struct PeerContext *p = cls;
62
63 p->oh = NULL;
64}
65
66
67static void
59process_hello (void *cls, 68process_hello (void *cls,
60 const struct GNUNET_MessageHeader *message) 69 const struct GNUNET_MessageHeader *message)
61{ 70{
@@ -64,10 +73,15 @@ process_hello (void *cls,
64 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
65 "Received (my) `%s' from transport service\n", "HELLO"); 74 "Received (my) `%s' from transport service\n", "HELLO");
66 GNUNET_assert (message != NULL); 75 GNUNET_assert (message != NULL);
67 if ((p == &p1) && (p2.th != NULL)) 76 if ((p == &p1) && (NULL == p2.oh))
68 GNUNET_TRANSPORT_offer_hello (p2.cfg, message, NULL, NULL); 77 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, message,
69 if ((p == &p2) && (p1.th != NULL)) 78 &offer_hello_done,
70 GNUNET_TRANSPORT_offer_hello (p1.cfg, message, NULL, NULL); 79 &p2);
80 if ((p == &p2) && (NULL == p1.oh))
81 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg,
82 message,
83 &offer_hello_done,
84 &p1);
71} 85}
72 86
73 87
@@ -79,11 +93,15 @@ terminate_peer (struct PeerContext *p)
79 GNUNET_CORE_disconnect (p->ch); 93 GNUNET_CORE_disconnect (p->ch);
80 p->ch = NULL; 94 p->ch = NULL;
81 } 95 }
82 if (NULL != p->th) 96 if (NULL != p->ghh)
83 { 97 {
84 GNUNET_TRANSPORT_get_hello_cancel (p->ghh); 98 GNUNET_TRANSPORT_get_hello_cancel (p->ghh);
85 GNUNET_TRANSPORT_disconnect (p->th); 99 p->ghh = NULL;
86 p->th = NULL; 100 }
101 if (NULL != p->oh)
102 {
103 GNUNET_TRANSPORT_offer_hello_cancel (p->oh);
104 p->oh = NULL;
87 } 105 }
88 if (NULL != p->ats_sh) 106 if (NULL != p->ats_sh)
89 { 107 {
@@ -276,8 +294,6 @@ setup_peer (struct PeerContext *p,
276 "gnunet-service-arm", 294 "gnunet-service-arm",
277 "-c", cfgname, NULL); 295 "-c", cfgname, NULL);
278 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 296 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
279 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
280 GNUNET_assert (NULL != p->th);
281 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 297 p->ats = GNUNET_ATS_connectivity_init (p->cfg);
282 GNUNET_assert (NULL != p->ats); 298 GNUNET_assert (NULL != p->ats);
283 p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg, &process_hello, p); 299 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
61 struct GNUNET_CONFIGURATION_Handle *cfg; 61 struct GNUNET_CONFIGURATION_Handle *cfg;
62 struct GNUNET_CORE_Handle *ch; 62 struct GNUNET_CORE_Handle *ch;
63 struct GNUNET_PeerIdentity id; 63 struct GNUNET_PeerIdentity id;
64 struct GNUNET_TRANSPORT_Handle *th; 64 struct GNUNET_TRANSPORT_OfferHelloHandle *oh;
65 struct GNUNET_MessageHeader *hello; 65 struct GNUNET_MessageHeader *hello;
66 struct GNUNET_TRANSPORT_GetHelloHandle *ghh; 66 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
67 struct GNUNET_ATS_ConnectivityHandle *ats; 67 struct GNUNET_ATS_ConnectivityHandle *ats;
@@ -108,11 +108,15 @@ terminate_peer (struct PeerContext *p)
108 GNUNET_CORE_disconnect (p->ch); 108 GNUNET_CORE_disconnect (p->ch);
109 p->ch = NULL; 109 p->ch = NULL;
110 } 110 }
111 if (NULL != p->th) 111 if (NULL != p->ghh)
112 { 112 {
113 GNUNET_TRANSPORT_get_hello_cancel (p->ghh); 113 GNUNET_TRANSPORT_get_hello_cancel (p->ghh);
114 GNUNET_TRANSPORT_disconnect (p->th); 114 p->ghh = NULL;
115 p->th = NULL; 115 }
116 if (NULL != p->oh)
117 {
118 GNUNET_TRANSPORT_offer_hello_cancel (p->oh);
119 p->oh = NULL;
116 } 120 }
117 if (NULL != p->ats_sh) 121 if (NULL != p->ats_sh)
118 { 122 {
@@ -402,6 +406,15 @@ init_notify (void *cls,
402 406
403 407
404static void 408static void
409offer_hello_done (void *cls)
410{
411 struct PeerContext *p = cls;
412
413 p->oh = NULL;
414}
415
416
417static void
405process_hello (void *cls, 418process_hello (void *cls,
406 const struct GNUNET_MessageHeader *message) 419 const struct GNUNET_MessageHeader *message)
407{ 420{
@@ -411,15 +424,27 @@ process_hello (void *cls,
411 "Received (my) `%s' from transport service\n", "HELLO"); 424 "Received (my) `%s' from transport service\n", "HELLO");
412 GNUNET_assert (message != NULL); 425 GNUNET_assert (message != NULL);
413 p->hello = GNUNET_copy_message (message); 426 p->hello = GNUNET_copy_message (message);
414 if ((p == &p1) && (p2.th != NULL)) 427 if ((p == &p1) && (NULL == p2.oh))
415 GNUNET_TRANSPORT_offer_hello (p2.cfg, message, NULL, NULL); 428 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg,
416 if ((p == &p2) && (p1.th != NULL)) 429 message,
417 GNUNET_TRANSPORT_offer_hello (p1.cfg, message, NULL, NULL); 430 &offer_hello_done,
418 431 &p2);
419 if ((p == &p1) && (p2.hello != NULL)) 432 if ((p == &p2) && (NULL == p1.oh))
420 GNUNET_TRANSPORT_offer_hello (p1.cfg, p2.hello, NULL, NULL); 433 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg,
421 if ((p == &p2) && (p1.hello != NULL)) 434 message,
422 GNUNET_TRANSPORT_offer_hello (p2.cfg, p1.hello, NULL, NULL); 435 &offer_hello_done,
436 &p1);
437
438 if ((p == &p1) && (p2.hello != NULL) && (NULL == p1.oh) )
439 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg,
440 p2.hello,
441 &offer_hello_done,
442 &p1);
443 if ((p == &p2) && (p1.hello != NULL) && (NULL == p2.oh) )
444 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg,
445 p1.hello,
446 &offer_hello_done,
447 &p2);
423} 448}
424 449
425 450
@@ -438,11 +463,11 @@ setup_peer (struct PeerContext *p,
438 "gnunet-service-arm", 463 "gnunet-service-arm",
439 "-c", cfgname, NULL); 464 "-c", cfgname, NULL);
440 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 465 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
441 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
442 GNUNET_assert (p->th != NULL);
443 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 466 p->ats = GNUNET_ATS_connectivity_init (p->cfg);
444 GNUNET_assert (NULL != p->ats); 467 GNUNET_assert (NULL != p->ats);
445 p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg, &process_hello, p); 468 p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg,
469 &process_hello,
470 p);
446 GNUNET_free (binary); 471 GNUNET_free (binary);
447} 472}
448 473
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
@@ -541,6 +541,15 @@ init_notify (void *cls,
541 541
542 542
543static void 543static void
544offer_hello_done (void *cls)
545{
546 struct PeerContext *p = cls;
547
548 p->oh = NULL;
549}
550
551
552static void
544process_hello (void *cls, const struct GNUNET_MessageHeader *message) 553process_hello (void *cls, const struct GNUNET_MessageHeader *message)
545{ 554{
546 struct PeerContext *p = cls; 555 struct PeerContext *p = cls;
@@ -551,18 +560,28 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
551 p->hello = GNUNET_malloc (ntohs (message->size)); 560 p->hello = GNUNET_malloc (ntohs (message->size));
552 GNUNET_memcpy (p->hello, message, ntohs (message->size)); 561 GNUNET_memcpy (p->hello, message, ntohs (message->size));
553 if ((p == &p1) && (NULL == p2.oh)) 562 if ((p == &p1) && (NULL == p2.oh))
554 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, message, NULL, NULL); 563 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg,
564 message,
565 &offer_hello_done,
566 &p2);
555 if ((p == &p2) && (NULL == p1.oh)) 567 if ((p == &p2) && (NULL == p1.oh))
556 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, message, NULL, NULL); 568 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, message,
569 &offer_hello_done,
570 &p1);
557 571
558 if ((p == &p1) && (p2.hello != NULL) && (NULL == p1.oh)) 572 if ((p == &p1) && (p2.hello != NULL) && (NULL == p1.oh))
559 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, p2.hello, NULL, NULL); 573 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg,
574 p2.hello,
575 &offer_hello_done,
576 &p1);
560 if ((p == &p2) && (p1.hello != NULL) && (NULL == p2.oh) ) 577 if ((p == &p2) && (p1.hello != NULL) && (NULL == p2.oh) )
561 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, p1.hello, NULL, NULL); 578 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg,
579 p1.hello,
580 &offer_hello_done,
581 &p2);
562} 582}
563 583
564 584
565
566static void 585static void
567setup_peer (struct PeerContext *p, const char *cfgname) 586setup_peer (struct PeerContext *p, const char *cfgname)
568{ 587{