diff options
author | Gabor X Toth <*@tg-x.net> | 2016-08-17 22:28:52 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2016-08-17 22:28:52 +0000 |
commit | d226c5f08990628851ac0b61894727e3817f8ad7 (patch) | |
tree | 7dec7dd7500d38f7a83287ca1b6427557467d2bf /src/social | |
parent | 4f51ef196f6dff91fd83085462fd9c4624f7296b (diff) | |
download | gnunet-d226c5f08990628851ac0b61894727e3817f8ad7.tar.gz gnunet-d226c5f08990628851ac0b61894727e3817f8ad7.zip |
multicast, psyc, social: wait till last message sent before disconnect
Diffstat (limited to 'src/social')
-rw-r--r-- | src/social/social_api.c | 143 |
1 files changed, 93 insertions, 50 deletions
diff --git a/src/social/social_api.c b/src/social/social_api.c index 9f15b4146..c08de0356 100644 --- a/src/social/social_api.c +++ b/src/social/social_api.c | |||
@@ -359,7 +359,6 @@ struct GNUNET_SOCIAL_LookHandle | |||
359 | 359 | ||
360 | struct ZoneAddPlaceHandle | 360 | struct ZoneAddPlaceHandle |
361 | { | 361 | { |
362 | struct ZoneAddPlaceRequest *req; | ||
363 | GNUNET_ResultCallback result_cb; | 362 | GNUNET_ResultCallback result_cb; |
364 | void *result_cls; | 363 | void *result_cls; |
365 | }; | 364 | }; |
@@ -1007,6 +1006,28 @@ handle_app_place_end (void *cls, | |||
1007 | } | 1006 | } |
1008 | 1007 | ||
1009 | 1008 | ||
1009 | /*** CLEANUP / DISCONNECT ***/ | ||
1010 | |||
1011 | |||
1012 | static void | ||
1013 | host_cleanup (struct GNUNET_SOCIAL_Host *hst) | ||
1014 | { | ||
1015 | if (NULL != hst->slicer) | ||
1016 | { | ||
1017 | GNUNET_PSYC_slicer_destroy (hst->slicer); | ||
1018 | hst->slicer = NULL; | ||
1019 | } | ||
1020 | GNUNET_free (hst); | ||
1021 | } | ||
1022 | |||
1023 | |||
1024 | static void | ||
1025 | guest_cleanup (struct GNUNET_SOCIAL_Guest *gst) | ||
1026 | { | ||
1027 | GNUNET_free (gst); | ||
1028 | } | ||
1029 | |||
1030 | |||
1010 | static void | 1031 | static void |
1011 | place_cleanup (struct GNUNET_SOCIAL_Place *plc) | 1032 | place_cleanup (struct GNUNET_SOCIAL_Place *plc) |
1012 | { | 1033 | { |
@@ -1027,32 +1048,59 @@ place_cleanup (struct GNUNET_SOCIAL_Place *plc) | |||
1027 | GNUNET_MQ_discard (plc->connect_env); | 1048 | GNUNET_MQ_discard (plc->connect_env); |
1028 | plc->connect_env = NULL; | 1049 | plc->connect_env = NULL; |
1029 | } | 1050 | } |
1051 | if (NULL != plc->mq) | ||
1052 | { | ||
1053 | GNUNET_MQ_destroy (plc->mq); | ||
1054 | plc->mq = NULL; | ||
1055 | } | ||
1030 | if (NULL != plc->disconnect_cb) | 1056 | if (NULL != plc->disconnect_cb) |
1031 | { | 1057 | { |
1032 | plc->disconnect_cb (plc->disconnect_cls); | 1058 | plc->disconnect_cb (plc->disconnect_cls); |
1033 | plc->disconnect_cb = NULL; | 1059 | plc->disconnect_cb = NULL; |
1034 | } | 1060 | } |
1061 | |||
1062 | (GNUNET_YES == plc->is_host) | ||
1063 | ? host_cleanup ((struct GNUNET_SOCIAL_Host *) plc) | ||
1064 | : guest_cleanup ((struct GNUNET_SOCIAL_Guest *) plc); | ||
1035 | } | 1065 | } |
1036 | 1066 | ||
1037 | 1067 | ||
1038 | static void | 1068 | void |
1039 | host_cleanup (struct GNUNET_SOCIAL_Host *hst) | 1069 | place_disconnect (struct GNUNET_SOCIAL_Place *plc, |
1070 | GNUNET_ContinuationCallback disconnect_cb, | ||
1071 | void *disconnect_cls) | ||
1040 | { | 1072 | { |
1041 | place_cleanup (&hst->plc); | 1073 | plc->disconnect_cb = disconnect_cb; |
1042 | if (NULL != hst->slicer) | 1074 | plc->disconnect_cls = disconnect_cls; |
1075 | |||
1076 | if (NULL != plc->mq) | ||
1043 | { | 1077 | { |
1044 | GNUNET_PSYC_slicer_destroy (hst->slicer); | 1078 | struct GNUNET_MQ_Envelope *last = GNUNET_MQ_get_last_envelope (plc->mq); |
1045 | hst->slicer = NULL; | 1079 | if (NULL != last) |
1080 | { | ||
1081 | GNUNET_MQ_notify_sent (last, | ||
1082 | (GNUNET_MQ_NotifyCallback) place_cleanup, plc); | ||
1083 | } | ||
1084 | else | ||
1085 | { | ||
1086 | place_cleanup (plc); | ||
1087 | } | ||
1088 | } | ||
1089 | else | ||
1090 | { | ||
1091 | place_cleanup (plc); | ||
1046 | } | 1092 | } |
1047 | GNUNET_free (hst); | ||
1048 | } | 1093 | } |
1049 | 1094 | ||
1050 | 1095 | ||
1051 | static void | 1096 | void |
1052 | guest_cleanup (struct GNUNET_SOCIAL_Guest *gst) | 1097 | place_leave (struct GNUNET_SOCIAL_Place *plc) |
1053 | { | 1098 | { |
1054 | place_cleanup (&gst->plc); | 1099 | struct GNUNET_MessageHeader *msg; |
1055 | GNUNET_free (gst); | 1100 | struct GNUNET_MQ_Envelope * |
1101 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE); | ||
1102 | |||
1103 | GNUNET_MQ_send (plc->mq, env); | ||
1056 | } | 1104 | } |
1057 | 1105 | ||
1058 | 1106 | ||
@@ -1518,34 +1566,6 @@ GNUNET_SOCIAL_host_get_place (struct GNUNET_SOCIAL_Host *hst) | |||
1518 | } | 1566 | } |
1519 | 1567 | ||
1520 | 1568 | ||
1521 | void | ||
1522 | place_leave (struct GNUNET_SOCIAL_Place *plc) | ||
1523 | { | ||
1524 | struct GNUNET_MessageHeader *msg; | ||
1525 | struct GNUNET_MQ_Envelope * | ||
1526 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE); | ||
1527 | |||
1528 | GNUNET_MQ_send (plc->mq, env); | ||
1529 | } | ||
1530 | |||
1531 | |||
1532 | void | ||
1533 | place_disconnect (struct GNUNET_SOCIAL_Place *plc, | ||
1534 | GNUNET_ContinuationCallback disconnect_cb, | ||
1535 | void *disconnect_cls) | ||
1536 | { | ||
1537 | plc->disconnect_cb = disconnect_cb; | ||
1538 | plc->disconnect_cls = disconnect_cls; | ||
1539 | |||
1540 | // FIXME: wait till queued messages are sent | ||
1541 | if (NULL != plc->mq) | ||
1542 | { | ||
1543 | GNUNET_MQ_destroy (plc->mq); | ||
1544 | plc->mq = NULL; | ||
1545 | } | ||
1546 | } | ||
1547 | |||
1548 | |||
1549 | /** | 1569 | /** |
1550 | * Disconnect from a home. | 1570 | * Disconnect from a home. |
1551 | * | 1571 | * |
@@ -1560,7 +1580,6 @@ GNUNET_SOCIAL_host_disconnect (struct GNUNET_SOCIAL_Host *hst, | |||
1560 | void *cls) | 1580 | void *cls) |
1561 | { | 1581 | { |
1562 | place_disconnect (&hst->plc, disconnect_cb, cls); | 1582 | place_disconnect (&hst->plc, disconnect_cb, cls); |
1563 | host_cleanup (hst); | ||
1564 | } | 1583 | } |
1565 | 1584 | ||
1566 | 1585 | ||
@@ -2016,7 +2035,6 @@ GNUNET_SOCIAL_guest_disconnect (struct GNUNET_SOCIAL_Guest *gst, | |||
2016 | void *cls) | 2035 | void *cls) |
2017 | { | 2036 | { |
2018 | place_disconnect (&gst->plc, disconnect_cb, cls); | 2037 | place_disconnect (&gst->plc, disconnect_cb, cls); |
2019 | guest_cleanup (gst); | ||
2020 | } | 2038 | } |
2021 | 2039 | ||
2022 | 2040 | ||
@@ -2363,7 +2381,6 @@ op_recv_zone_add_place_result (void *cls, int64_t result, | |||
2363 | if (NULL != add_plc->result_cb) | 2381 | if (NULL != add_plc->result_cb) |
2364 | add_plc->result_cb (add_plc->result_cls, result, err_msg, err_msg_size); | 2382 | add_plc->result_cb (add_plc->result_cls, result, err_msg, err_msg_size); |
2365 | 2383 | ||
2366 | GNUNET_free (add_plc->req); | ||
2367 | GNUNET_free (add_plc); | 2384 | GNUNET_free (add_plc); |
2368 | } | 2385 | } |
2369 | 2386 | ||
@@ -2435,7 +2452,6 @@ GNUNET_SOCIAL_zone_add_place (const struct GNUNET_SOCIAL_App *app, | |||
2435 | GNUNET_memcpy (p, relays, relay_size); | 2452 | GNUNET_memcpy (p, relays, relay_size); |
2436 | 2453 | ||
2437 | struct ZoneAddPlaceHandle * add_plc = GNUNET_malloc (sizeof (*add_plc)); | 2454 | struct ZoneAddPlaceHandle * add_plc = GNUNET_malloc (sizeof (*add_plc)); |
2438 | add_plc->req = preq; | ||
2439 | add_plc->result_cb = result_cb; | 2455 | add_plc->result_cb = result_cb; |
2440 | add_plc->result_cls = result_cls; | 2456 | add_plc->result_cls = result_cls; |
2441 | 2457 | ||
@@ -2657,6 +2673,22 @@ GNUNET_SOCIAL_app_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2657 | } | 2673 | } |
2658 | 2674 | ||
2659 | 2675 | ||
2676 | static void | ||
2677 | app_cleanup (struct GNUNET_SOCIAL_App *app) | ||
2678 | { | ||
2679 | if (NULL != app->mq) | ||
2680 | { | ||
2681 | GNUNET_MQ_destroy (app->mq); | ||
2682 | app->mq = NULL; | ||
2683 | } | ||
2684 | if (NULL != app->disconnect_cb) | ||
2685 | { | ||
2686 | app->disconnect_cb (app->disconnect_cls); | ||
2687 | app->disconnect_cb = NULL; | ||
2688 | } | ||
2689 | GNUNET_free (app); | ||
2690 | } | ||
2691 | |||
2660 | /** | 2692 | /** |
2661 | * Disconnect application. | 2693 | * Disconnect application. |
2662 | * | 2694 | * |
@@ -2672,15 +2704,26 @@ GNUNET_SOCIAL_app_disconnect (struct GNUNET_SOCIAL_App *app, | |||
2672 | GNUNET_ContinuationCallback disconnect_cb, | 2704 | GNUNET_ContinuationCallback disconnect_cb, |
2673 | void *disconnect_cls) | 2705 | void *disconnect_cls) |
2674 | { | 2706 | { |
2675 | // FIXME: wait till queued messages are sent | 2707 | app->disconnect_cb = disconnect_cb; |
2708 | app->disconnect_cls = disconnect_cls; | ||
2709 | |||
2676 | if (NULL != app->mq) | 2710 | if (NULL != app->mq) |
2677 | { | 2711 | { |
2678 | GNUNET_MQ_destroy (app->mq); | 2712 | struct GNUNET_MQ_Envelope *last = GNUNET_MQ_get_last_envelope (app->mq); |
2679 | app->mq = NULL; | 2713 | if (NULL != last) |
2714 | { | ||
2715 | GNUNET_MQ_notify_sent (last, | ||
2716 | (GNUNET_MQ_NotifyCallback) app_cleanup, app); | ||
2717 | } | ||
2718 | else | ||
2719 | { | ||
2720 | app_cleanup (app); | ||
2721 | } | ||
2722 | } | ||
2723 | else | ||
2724 | { | ||
2725 | app_cleanup (app); | ||
2680 | } | 2726 | } |
2681 | |||
2682 | if (NULL != disconnect_cb) | ||
2683 | disconnect_cb (disconnect_cls); | ||
2684 | } | 2727 | } |
2685 | 2728 | ||
2686 | 2729 | ||