diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-04 11:40:36 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-04 11:40:36 +0000 |
commit | 7350aa9b35cf4c92207cbfb12dfa92cbffc4ef3e (patch) | |
tree | 93b196d700fe1fbc5f82c0b1ed2592602a959c3e /src/core/test_core_quota_compliance.c | |
parent | abcc6105589215b4e9ea10a2fdd82dad5203bf48 (diff) | |
download | gnunet-7350aa9b35cf4c92207cbfb12dfa92cbffc4ef3e.tar.gz gnunet-7350aa9b35cf4c92207cbfb12dfa92cbffc4ef3e.zip |
cleaning up test code to keep references to allocated handles and to clean them up where needed; this should fix #1803
Diffstat (limited to 'src/core/test_core_quota_compliance.c')
-rw-r--r-- | src/core/test_core_quota_compliance.c | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index d955e0fd0..90a140d46 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c | |||
@@ -77,6 +77,7 @@ struct PeerContext | |||
77 | { | 77 | { |
78 | struct GNUNET_CONFIGURATION_Handle *cfg; | 78 | struct GNUNET_CONFIGURATION_Handle *cfg; |
79 | struct GNUNET_CORE_Handle *ch; | 79 | struct GNUNET_CORE_Handle *ch; |
80 | struct GNUNET_CORE_TransmitHandle *nth; | ||
80 | struct GNUNET_PeerIdentity id; | 81 | struct GNUNET_PeerIdentity id; |
81 | struct GNUNET_TRANSPORT_Handle *th; | 82 | struct GNUNET_TRANSPORT_Handle *th; |
82 | struct GNUNET_MessageHeader *hello; | 83 | struct GNUNET_MessageHeader *hello; |
@@ -123,8 +124,14 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
123 | { | 124 | { |
124 | struct GNUNET_CORE_Handle *ch; | 125 | struct GNUNET_CORE_Handle *ch; |
125 | 126 | ||
127 | err_task = GNUNET_SCHEDULER_NO_TASK; | ||
126 | GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); | 128 | GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); |
127 | GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); | 129 | GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); |
130 | if (p1.nth != NULL) | ||
131 | { | ||
132 | GNUNET_CORE_notify_transmit_ready_cancel (p1.nth); | ||
133 | p1.nth = NULL; | ||
134 | } | ||
128 | ch = p1.ch; | 135 | ch = p1.ch; |
129 | p1.ch = NULL; | 136 | p1.ch = NULL; |
130 | GNUNET_CORE_disconnect (ch); | 137 | GNUNET_CORE_disconnect (ch); |
@@ -141,10 +148,16 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
141 | static void | 148 | static void |
142 | terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 149 | terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
143 | { | 150 | { |
151 | err_task = GNUNET_SCHEDULER_NO_TASK; | ||
152 | |||
144 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 153 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
145 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase failed!\n"); | 154 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase failed!\n"); |
146 | //GNUNET_break (0); | 155 | //GNUNET_break (0); |
147 | 156 | if (p1.nth != NULL) | |
157 | { | ||
158 | GNUNET_CORE_notify_transmit_ready_cancel (p1.nth); | ||
159 | p1.nth = NULL; | ||
160 | } | ||
148 | if (measure_task != GNUNET_SCHEDULER_NO_TASK) | 161 | if (measure_task != GNUNET_SCHEDULER_NO_TASK) |
149 | GNUNET_SCHEDULER_cancel (measure_task); | 162 | GNUNET_SCHEDULER_cancel (measure_task); |
150 | 163 | ||
@@ -286,7 +299,7 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kB/s\n",max_quota_out/1024); | 299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kB/s\n",max_quota_out/1024); |
287 | */ | 300 | */ |
288 | GNUNET_SCHEDULER_cancel (err_task); | 301 | GNUNET_SCHEDULER_cancel (err_task); |
289 | GNUNET_SCHEDULER_add_now (&terminate_task, NULL); | 302 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL); |
290 | 303 | ||
291 | } | 304 | } |
292 | 305 | ||
@@ -297,15 +310,16 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
297 | struct TestMessage hdr; | 310 | struct TestMessage hdr; |
298 | unsigned int ret; | 311 | unsigned int ret; |
299 | 312 | ||
313 | p1.nth = NULL; | ||
300 | GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); | 314 | GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); |
301 | if (buf == NULL) | 315 | if (buf == NULL) |
302 | { | 316 | { |
303 | if ((p1.ch != NULL) && (p1.connect_status == 1)) | 317 | if ((p1.ch != NULL) && (p1.connect_status == 1)) |
304 | GNUNET_break (NULL != | 318 | GNUNET_break (NULL != |
305 | GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0, | 319 | (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0, |
306 | FAST_TIMEOUT, &p2.id, | 320 | FAST_TIMEOUT, &p2.id, |
307 | MESSAGESIZE, | 321 | MESSAGESIZE, |
308 | &transmit_ready, &p1)); | 322 | &transmit_ready, &p1))); |
309 | return 0; | 323 | return 0; |
310 | } | 324 | } |
311 | GNUNET_assert (tr_n < TOTAL_MSGS); | 325 | GNUNET_assert (tr_n < TOTAL_MSGS); |
@@ -349,7 +363,7 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
349 | struct PeerContext *pc = cls; | 363 | struct PeerContext *pc = cls; |
350 | 364 | ||
351 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) | 365 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
352 | return; | 366 | return; /* loopback */ |
353 | GNUNET_assert (pc->connect_status == 0); | 367 | GNUNET_assert (pc->connect_status == 0); |
354 | pc->connect_status = 1; | 368 | pc->connect_status = 1; |
355 | if (pc == &p1) | 369 | if (pc == &p1) |
@@ -373,10 +387,10 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
373 | NULL); | 387 | NULL); |
374 | 388 | ||
375 | GNUNET_break (NULL != | 389 | GNUNET_break (NULL != |
376 | GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0, | 390 | (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0, |
377 | TIMEOUT, &p2.id, | 391 | TIMEOUT, &p2.id, |
378 | MESSAGESIZE, | 392 | MESSAGESIZE, |
379 | &transmit_ready, &p1)); | 393 | &transmit_ready, &p1))); |
380 | } | 394 | } |
381 | } | 395 | } |
382 | 396 | ||
@@ -387,8 +401,13 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
387 | struct PeerContext *pc = cls; | 401 | struct PeerContext *pc = cls; |
388 | 402 | ||
389 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) | 403 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
390 | return; | 404 | return; /* loopback */ |
391 | pc->connect_status = 0; | 405 | pc->connect_status = 0; |
406 | if (pc->nth != NULL) | ||
407 | { | ||
408 | GNUNET_CORE_notify_transmit_ready_cancel (pc->nth); | ||
409 | pc->nth = NULL; | ||
410 | } | ||
392 | #if DEBUG_TRANSMISSION | 411 | #if DEBUG_TRANSMISSION |
393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%4s' cut\n", | 412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%4s' cut\n", |
394 | GNUNET_i2s (peer)); | 413 | GNUNET_i2s (peer)); |
@@ -495,15 +514,15 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server, | |||
495 | GNUNET_i2s (my_identity)); | 514 | GNUNET_i2s (my_identity)); |
496 | GNUNET_assert (server != NULL); | 515 | GNUNET_assert (server != NULL); |
497 | p->id = *my_identity; | 516 | p->id = *my_identity; |
498 | p->ch = server; | 517 | GNUNET_assert (p->ch == server); |
499 | if (cls == &p1) | 518 | if (cls == &p1) |
500 | { | 519 | { |
501 | GNUNET_assert (ok == 2); | 520 | GNUNET_assert (ok == 2); |
502 | OKPP; | 521 | OKPP; |
503 | /* connect p2 */ | 522 | /* connect p2 */ |
504 | GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, | 523 | p2.ch = GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, |
505 | &disconnect_notify, NULL, &inbound_notify, GNUNET_YES, | 524 | &disconnect_notify, NULL, &inbound_notify, GNUNET_YES, |
506 | &outbound_notify, GNUNET_YES, handlers); | 525 | &outbound_notify, GNUNET_YES, handlers); |
507 | } | 526 | } |
508 | else | 527 | else |
509 | { | 528 | { |
@@ -610,9 +629,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
610 | "TOTAL_QUOTA_OUT", | 629 | "TOTAL_QUOTA_OUT", |
611 | ¤t_quota_p2_out)); | 630 | ¤t_quota_p2_out)); |
612 | 631 | ||
613 | GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, | 632 | p1.ch = GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, |
614 | &disconnect_notify, NULL, &inbound_notify, GNUNET_YES, | 633 | &disconnect_notify, NULL, &inbound_notify, GNUNET_YES, |
615 | &outbound_notify, GNUNET_YES, handlers); | 634 | &outbound_notify, GNUNET_YES, handlers); |
616 | } | 635 | } |
617 | 636 | ||
618 | 637 | ||