use comfort functions of MQ API
authorlurchi <lurchi@strangeplace.net>
Sat, 18 Nov 2017 10:08:32 +0000 (11:08 +0100)
committerlurchi <lurchi@strangeplace.net>
Sat, 18 Nov 2017 10:08:32 +0000 (11:08 +0100)
src/social/gnunet-service-social.c
src/social/social_api.c

index 3e527cbaf929d10ec87f76fae73eb2926e91bc96..3f69992698a273225d6e9067fe9947b3c89422f3 100644 (file)
@@ -635,6 +635,22 @@ place_send_msg (const struct Place *plc,
 }
 
 
+static void
+place_send_leave_ack (const struct Place *plc)
+{
+  struct GNUNET_MQ_Envelope *env;
+  
+  for (struct ClientListItem *cli = plc->clients_head;
+       NULL != cli;
+       cli = cli->next)
+  {
+    env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK);
+    GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cli->client),
+                    env); 
+  }
+}
+
+
 /**
  * Send a result code back to the client.
  *
@@ -2139,7 +2155,6 @@ 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;
 
   if (NULL == plc)
   {
@@ -2148,24 +2163,22 @@ handle_client_place_leave (void *cls,
     return;
   }
 
-  for (struct ClientListItem *cli = plc->clients_head;
-       NULL != cli;
-       cli = cli->next)
-  {
-    env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK);
-    GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cli->client),
-                    env); 
-  }
-
   if (GNUNET_YES != plc->is_disconnected)
   {
     plc->is_disconnected = GNUNET_YES;
     if (NULL != plc->tmit_msgs_head)
     { /* Send pending messages to PSYC before cleanup. */
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "not cleaning up place of client %p\n",
+                  client);
       psyc_transmit_message (plc);
     }
     else
     {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "cleaning up place of client %p\n",
+                  client);
+      place_send_leave_ack (plc);
       cleanup_place (plc);
       c->place = NULL;
     }
@@ -2867,6 +2880,9 @@ handle_client_psyc_message (void *cls,
 
   if (NULL == plc)
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "received PSYC message for non-existing client %p\n",
+                client);
     GNUNET_break (0);
     GNUNET_SERVICE_client_drop (client);
     return;
index 73587598b5a647ba7087b712a7e36a76530a1219..f37c52e2c644a494360bc208846a27b056c857cf 100644 (file)
@@ -398,6 +398,9 @@ place_cleanup (struct GNUNET_SOCIAL_Place *plc)
 {
   struct GNUNET_HashCode place_pub_hash;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "place_cleanup\n");
+
   GNUNET_CRYPTO_hash (&plc->pub_key, sizeof (plc->pub_key), &place_pub_hash);
   if (NULL != plc->tmit)
   {
@@ -1511,6 +1514,8 @@ GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *hst,
                              void *notify_data_cls,
                              enum GNUNET_SOCIAL_AnnounceFlags flags)
 {
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "PSYC_transmit_message for host\n");
   if (GNUNET_OK ==
       GNUNET_PSYC_transmit_message (hst->plc.tmit, method_name, env,
                                     NULL, notify_data, notify_data_cls, flags))
@@ -1606,15 +1611,15 @@ GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *hst,
                           GNUNET_ContinuationCallback disconnect_cb,
                           void *cls)
 {
-  struct GNUNET_MessageHeader *msg;
   struct GNUNET_MQ_Envelope *envelope;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "sending _notice_place_closing\n");
   GNUNET_SOCIAL_host_announce (hst, "_notice_place_closing", env, NULL, NULL,
                                GNUNET_SOCIAL_ANNOUNCE_NONE);
   hst->plc.disconnect_cb = disconnect_cb;
   hst->plc.disconnect_cls = cls;
-  envelope = GNUNET_MQ_msg (msg,
-                            GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
+  envelope = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
   GNUNET_MQ_send (hst->plc.mq,
                   envelope);
 }
@@ -1987,6 +1992,9 @@ GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *gst,
                           void *notify_data_cls,
                           enum GNUNET_SOCIAL_TalkFlags flags)
 {
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "PSYC_transmit_message for guest\n");
+
   struct GNUNET_SOCIAL_Place *plc = &gst->plc;
   GNUNET_assert (NULL != plc->tmit);
 
@@ -2068,15 +2076,13 @@ GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst,
                            GNUNET_ContinuationCallback disconnect_cb,
                            void *cls)
 {
-  struct GNUNET_MessageHeader *msg;
   struct GNUNET_MQ_Envelope *envelope;
 
   GNUNET_SOCIAL_guest_talk (gst, "_notice_place_leave", env, NULL, NULL,
                             GNUNET_SOCIAL_TALK_NONE);
   gst->plc.disconnect_cb = disconnect_cb;
   gst->plc.disconnect_cls = cls;
-  envelope = GNUNET_MQ_msg (msg,
-                            GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
+  envelope = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
   GNUNET_MQ_send (gst->plc.mq,
                   envelope);
 }