From c9e414861225f5ac84971845015a67c6bd959153 Mon Sep 17 00:00:00 2001 From: lurchi Date: Wed, 8 Nov 2017 19:19:29 +0100 Subject: [PATCH] protocol change: add ack message for guests/hosts leaving a place --- src/include/gnunet_protocols.h | 23 ++-- src/social/gnunet-service-social.c | 9 +- src/social/social_api.c | 168 +++++++++++++++++------------ 3 files changed, 117 insertions(+), 83 deletions(-) diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 72054913f..2daf5eb46 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -2398,35 +2398,38 @@ extern "C" /** C->S: request to leave a place */ #define GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE 848 +/** S->C: place leave acknowledgement */ +#define GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK 849 + /** C->S: add place to GNS zone */ -#define GNUNET_MESSAGE_TYPE_SOCIAL_ZONE_ADD_PLACE 849 +#define GNUNET_MESSAGE_TYPE_SOCIAL_ZONE_ADD_PLACE 850 /** C->S: add nym to GNS zone */ -#define GNUNET_MESSAGE_TYPE_SOCIAL_ZONE_ADD_NYM 850 +#define GNUNET_MESSAGE_TYPE_SOCIAL_ZONE_ADD_NYM 851 /** C->S: connect application */ -#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_CONNECT 851 +#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_CONNECT 852 /** C->S: detach a place from application */ -#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_DETACH 852 +#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_DETACH 853 /** S->C: notify about an existing ego */ -#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO 853 +#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO 854 /** S->C: end of ego list */ -#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END 854 +#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END 855 /** S->C: notify about an existing place */ -#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE 855 +#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE 856 /** S->C: end of place list */ -#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END 856 +#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END 857 /** C->S: set message processing flags */ -#define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_SET 860 +#define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_SET 858 /** C->S: clear message processing flags */ -#define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_CLEAR 861 +#define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_CLEAR 859 /******************************************************************************* * X-VINE DHT messages diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c index 04bbba192..609cdab06 100644 --- a/src/social/gnunet-service-social.c +++ b/src/social/gnunet-service-social.c @@ -2227,6 +2227,8 @@ handle_client_place_leave (void *cls, struct Client *c = cls; struct GNUNET_SERVICE_Client *client = c->client; struct Place *plc = c->place; + struct GNUNET_MQ_Envelope *env; + struct GNUNET_MessageHeader *ack_msg; GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "handle_client_place_leave\n"); @@ -2255,9 +2257,10 @@ handle_client_place_leave (void *cls, NULL != cli; cli = cli->next) { - // protocol design failure: should *tell* clients that room is gone! - if (client != cli->client) - GNUNET_SERVICE_client_drop (cli->client); + env = GNUNET_MQ_msg (ack_msg, + GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK); + GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cli->client), + env); } if (GNUNET_YES != plc->is_disconnected) diff --git a/src/social/social_api.c b/src/social/social_api.c index 1db8e501a..c89e79453 100644 --- a/src/social/social_api.c +++ b/src/social/social_api.c @@ -371,6 +371,83 @@ struct ZoneAddNymHandle }; +/*** CLEANUP / DISCONNECT ***/ + + +static void +host_cleanup (struct GNUNET_SOCIAL_Host *hst) +{ + if (NULL != hst->slicer) + { + GNUNET_PSYC_slicer_destroy (hst->slicer); + hst->slicer = NULL; + } + GNUNET_free (hst); +} + + +static void +guest_cleanup (struct GNUNET_SOCIAL_Guest *gst) +{ + GNUNET_free (gst); +} + + +static void +place_cleanup (struct GNUNET_SOCIAL_Place *plc) +{ + struct GNUNET_HashCode place_pub_hash; + + GNUNET_CRYPTO_hash (&plc->pub_key, sizeof (plc->pub_key), &place_pub_hash); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "%s place cleanup: %s\n", + GNUNET_YES == plc->is_host ? "host" : "guest", + GNUNET_h2s (&place_pub_hash)); + + if (NULL != plc->tmit) + { + GNUNET_PSYC_transmit_destroy (plc->tmit); + plc->tmit = NULL; + } + if (NULL != plc->connect_env) + { + GNUNET_MQ_discard (plc->connect_env); + plc->connect_env = NULL; + } + if (NULL != plc->mq) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "destroying MQ (place_cleanup)\n"); + GNUNET_MQ_destroy (plc->mq); + plc->mq = NULL; + } + if (NULL != plc->disconnect_cb) + { + plc->disconnect_cb (plc->disconnect_cls); + plc->disconnect_cb = NULL; + } + + (GNUNET_YES == plc->is_host) + ? host_cleanup ((struct GNUNET_SOCIAL_Host *) plc) + : guest_cleanup ((struct GNUNET_SOCIAL_Guest *) plc); +} + + +static void +place_disconnect (struct GNUNET_SOCIAL_Place *plc) +{ + struct GNUNET_HashCode place_pub_hash; + + GNUNET_CRYPTO_hash (&plc->pub_key, + sizeof (plc->pub_key), + &place_pub_hash); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "place_disconnect, plc = %s\n", + GNUNET_h2s (&place_pub_hash)); + place_cleanup (plc); +} + + /*** NYM ***/ static struct GNUNET_SOCIAL_Nym * @@ -1018,80 +1095,23 @@ handle_app_place_end (void *cls, } -/*** CLEANUP / DISCONNECT ***/ - - -static void -host_cleanup (struct GNUNET_SOCIAL_Host *hst) -{ - if (NULL != hst->slicer) - { - GNUNET_PSYC_slicer_destroy (hst->slicer); - hst->slicer = NULL; - } - GNUNET_free (hst); -} - - -static void -guest_cleanup (struct GNUNET_SOCIAL_Guest *gst) -{ - GNUNET_free (gst); -} - - -static void -place_cleanup (struct GNUNET_SOCIAL_Place *plc) -{ - struct GNUNET_HashCode place_pub_hash; - - GNUNET_CRYPTO_hash (&plc->pub_key, sizeof (plc->pub_key), &place_pub_hash); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "%s place cleanup: %s\n", - GNUNET_YES == plc->is_host ? "host" : "guest", - GNUNET_h2s (&place_pub_hash)); - - if (NULL != plc->tmit) - { - GNUNET_PSYC_transmit_destroy (plc->tmit); - plc->tmit = NULL; - } - if (NULL != plc->connect_env) - { - GNUNET_MQ_discard (plc->connect_env); - plc->connect_env = NULL; - } - if (NULL != plc->mq) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "destroying MQ (place_cleanup)\n"); - GNUNET_MQ_destroy (plc->mq); - plc->mq = NULL; - } - if (NULL != plc->disconnect_cb) - { - plc->disconnect_cb (plc->disconnect_cls); - plc->disconnect_cb = NULL; - } - - (GNUNET_YES == plc->is_host) - ? host_cleanup ((struct GNUNET_SOCIAL_Host *) plc) - : guest_cleanup ((struct GNUNET_SOCIAL_Guest *) plc); -} - - +/** + * Handle an acknowledgement that a guest or host left a place. + * + * @param cls a `struct GNUNET_SOCIAL_Place` + * @param msg the message from the service + */ static void -place_disconnect (struct GNUNET_SOCIAL_Place *plc) +handle_place_leave_ack (void *cls, + const struct GNUNET_MessageHeader *msg) { - struct GNUNET_HashCode place_pub_hash; + struct GNUNET_SOCIAL_Place *plc = cls; - GNUNET_CRYPTO_hash (&plc->pub_key, - sizeof (plc->pub_key), - &place_pub_hash); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "place_disconnect, plc = %s\n", - GNUNET_h2s (&place_pub_hash)); - place_cleanup (plc); + "%s left place %p\n", + plc->is_host ? "host" : "guest", + plc); + place_disconnect (plc); } @@ -1153,6 +1173,10 @@ host_connect (struct GNUNET_SOCIAL_Host *hst) GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER_ACK, struct HostEnterAck, hst), + GNUNET_MQ_hd_fixed_size (place_leave_ack, + GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK, + struct GNUNET_MessageHeader, + plc), GNUNET_MQ_hd_var_size (host_enter_request, GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST, struct GNUNET_PSYC_JoinRequestMessage, @@ -1702,6 +1726,10 @@ guest_connect (struct GNUNET_SOCIAL_Guest *gst) GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK, struct GNUNET_PSYC_CountersResultMessage, gst), + GNUNET_MQ_hd_fixed_size (place_leave_ack, + GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK, + struct GNUNET_MessageHeader, + plc), GNUNET_MQ_hd_var_size (guest_enter_decision, GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, struct GNUNET_PSYC_JoinDecisionMessage, -- 2.25.1