protocol change: add ack message for guests/hosts leaving a place
authorlurchi <lurchi@strangeplace.net>
Wed, 8 Nov 2017 18:19:29 +0000 (19:19 +0100)
committerlurchi <lurchi@strangeplace.net>
Wed, 8 Nov 2017 18:19:29 +0000 (19:19 +0100)
src/include/gnunet_protocols.h
src/social/gnunet-service-social.c
src/social/social_api.c

index 72054913f74eaebb7e54b81263a9bad2ad6c0015..2daf5eb46235273b1b1d12a86e39138c4446cdff 100644 (file)
@@ -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
index 04bbba1923fe639a83a0ba3f698f18bb56251366..609cdab06e599f1f2ef2927b98fc37107f40cf2f 100644 (file)
@@ -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)
index 1db8e501ac0b51e4d94b3b73e0fc4e09b70d5818..c89e794538f0cfa2a7680eda858598ed7706cf67 100644 (file)
@@ -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,