aboutsummaryrefslogtreecommitdiff
path: root/src/social
diff options
context:
space:
mode:
authorlurchi <lurchi@strangeplace.net>2017-11-08 19:19:29 +0100
committerlurchi <lurchi@strangeplace.net>2017-11-08 19:19:29 +0100
commitc9e414861225f5ac84971845015a67c6bd959153 (patch)
treec18de76be18dc4c66c0f39c3430d1dad8aaf284a /src/social
parent7c1ce9a71e362727509f013900a50ba5879ca8b2 (diff)
protocol change: add ack message for guests/hosts leaving a place
Diffstat (limited to 'src/social')
-rw-r--r--src/social/gnunet-service-social.c9
-rw-r--r--src/social/social_api.c168
2 files changed, 104 insertions, 73 deletions
diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c
index 04bbba1923..609cdab06e 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 1db8e501ac..c89e794538 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,