aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/cadet_api.c
diff options
context:
space:
mode:
authorBart Polot <bart.polot+voyager@gmail.com>2017-01-31 04:33:36 +0100
committerBart Polot <bart.polot+voyager@gmail.com>2017-01-31 05:08:32 +0100
commitbdfdbcc9d8ad8f46131c0836a9d489005d6a7bd0 (patch)
tree02e7c24c9b6849729dbbbeb54042a0496331b9d1 /src/cadet/cadet_api.c
parent7a469336dc169173558720df45c03a76bf50e140 (diff)
downloadgnunet-bdfdbcc9d8ad8f46131c0836a9d489005d6a7bd0.tar.gz
gnunet-bdfdbcc9d8ad8f46131c0836a9d489005d6a7bd0.zip
Implement channel cleanup in MQ API, simplify destroy channel
Diffstat (limited to 'src/cadet/cadet_api.c')
-rw-r--r--src/cadet/cadet_api.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index e00203b25..50306b73b 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -491,10 +491,8 @@ create_channel (struct GNUNET_CADET_Handle *h,
491 * 491 *
492 * @return Handle to the required channel or NULL if not found. 492 * @return Handle to the required channel or NULL if not found.
493 */ 493 */
494// FIXME: simplify: call_cleaner is always #GNUNET_YES!!!
495static void 494static void
496destroy_channel (struct GNUNET_CADET_Channel *ch, 495destroy_channel (struct GNUNET_CADET_Channel *ch)
497 int call_cleaner)
498{ 496{
499 struct GNUNET_CADET_Handle *h; 497 struct GNUNET_CADET_Handle *h;
500 struct GNUNET_CADET_TransmitHandle *th; 498 struct GNUNET_CADET_TransmitHandle *th;
@@ -516,13 +514,28 @@ destroy_channel (struct GNUNET_CADET_Channel *ch,
516 ch); 514 ch);
517 515
518 /* signal channel destruction */ 516 /* signal channel destruction */
519 if ( (NULL != h->cleaner) && 517 if (0 != ch->peer)
520 (0 != ch->peer) &&
521 (GNUNET_YES == call_cleaner) )
522 { 518 {
523 LOG (GNUNET_ERROR_TYPE_DEBUG, 519 if (NULL != h->cleaner)
524 " calling cleaner\n"); 520 {
525 h->cleaner (h->cls, ch, ch->ctx); 521 /** @a deprecated */
522 LOG (GNUNET_ERROR_TYPE_DEBUG,
523 " calling cleaner\n");
524 h->cleaner (h->cls, ch, ch->ctx);
525 }
526 else if (NULL != ch->disconnects)
527 {
528 LOG (GNUNET_ERROR_TYPE_DEBUG,
529 " calling disconnect handler\n");
530 ch->disconnects (ch->ctx, ch);
531 }
532 else
533 {
534 /* Application won't be aware of the channel destruction and use
535 * a pointer to free'd memory.
536 */
537 GNUNET_assert (0);
538 }
526 } 539 }
527 540
528 /* check that clients did not leave messages behind in the queue */ 541 /* check that clients did not leave messages behind in the queue */
@@ -853,8 +866,7 @@ handle_channel_destroy (void *cls,
853 ntohl (ccn.channel_of_client)); 866 ntohl (ccn.channel_of_client));
854 return; 867 return;
855 } 868 }
856 destroy_channel (ch, 869 destroy_channel (ch);
857 GNUNET_YES);
858} 870}
859 871
860 872
@@ -1546,7 +1558,7 @@ reconnect (struct GNUNET_CADET_Handle *h)
1546 LOG (GNUNET_ERROR_TYPE_DEBUG, 1558 LOG (GNUNET_ERROR_TYPE_DEBUG,
1547 "Requested RECONNECT, destroying all channels\n"); 1559 "Requested RECONNECT, destroying all channels\n");
1548 while (NULL != (ch = h->channels_head)) 1560 while (NULL != (ch = h->channels_head))
1549 destroy_channel (ch, GNUNET_YES); 1561 destroy_channel (ch);
1550 if (NULL == h->reconnect_task) 1562 if (NULL == h->reconnect_task)
1551 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time, 1563 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time,
1552 &reconnect_cbk, h); 1564 &reconnect_cbk, h);
@@ -1621,8 +1633,7 @@ GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle)
1621 "channel %X not destroyed\n", 1633 "channel %X not destroyed\n",
1622 ntohl (ch->ccn.channel_of_client)); 1634 ntohl (ch->ccn.channel_of_client));
1623 } 1635 }
1624 destroy_channel (ch, 1636 destroy_channel (ch);
1625 GNUNET_YES);
1626 ch = aux; 1637 ch = aux;
1627 } 1638 }
1628 while (NULL != (th = handle->th_head)) 1639 while (NULL != (th = handle->th_head))
@@ -1829,8 +1840,7 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel)
1829 GNUNET_MQ_send (h->mq, 1840 GNUNET_MQ_send (h->mq,
1830 env); 1841 env);
1831 1842
1832 destroy_channel (channel, 1843 destroy_channel (channel);
1833 GNUNET_YES);
1834} 1844}
1835 1845
1836 1846
@@ -2362,7 +2372,7 @@ GNUNET_CADET_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg)
2362 h->mq_api = GNUNET_YES; 2372 h->mq_api = GNUNET_YES;
2363 h->ports = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_YES); 2373 h->ports = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_YES);
2364 do_reconnect (h); 2374 do_reconnect (h);
2365 if (h->mq == NULL) 2375 if (NULL == h->mq)
2366 { 2376 {
2367 GNUNET_break (0); 2377 GNUNET_break (0);
2368 GNUNET_CADET_disconnect (h); 2378 GNUNET_CADET_disconnect (h);
@@ -2403,6 +2413,7 @@ GNUNET_CADET_open_porT (struct GNUNET_CADET_Handle *h,
2403 struct GNUNET_CADET_Port *p; 2413 struct GNUNET_CADET_Port *p;
2404 2414
2405 GNUNET_assert (NULL != connects); 2415 GNUNET_assert (NULL != connects);
2416 GNUNET_assert (NULL != disconnects);
2406 2417
2407 p = GNUNET_new (struct GNUNET_CADET_Port); 2418 p = GNUNET_new (struct GNUNET_CADET_Port);
2408 p->cadet = h; 2419 p->cadet = h;
@@ -2462,6 +2473,8 @@ GNUNET_CADET_channel_creatE (struct GNUNET_CADET_Handle *h,
2462 struct GNUNET_CADET_LocalChannelCreateMessage *msg; 2473 struct GNUNET_CADET_LocalChannelCreateMessage *msg;
2463 struct GNUNET_MQ_Envelope *env; 2474 struct GNUNET_MQ_Envelope *env;
2464 2475
2476 GNUNET_assert (NULL != disconnects);
2477
2465 /* Save parameters */ 2478 /* Save parameters */
2466 ccn.channel_of_client = htonl (0); 2479 ccn.channel_of_client = htonl (0);
2467 ch = create_channel (h, ccn); 2480 ch = create_channel (h, ccn);