misc social hacking with Lurchi
authorChristian Grothoff <christian@grothoff.org>
Sat, 28 Oct 2017 09:21:55 +0000 (11:21 +0200)
committerChristian Grothoff <christian@grothoff.org>
Sat, 28 Oct 2017 09:21:55 +0000 (11:21 +0200)
src/social/gnunet-service-social.c
src/social/social_api.c
src/social/test_social.conf
src/util/mq.c
src/util/service.c

index 4541a4e06dcf2136f494dbabde59df18ca57e22b..f9e70a25da6eb4130321eb3d0b94db5fa93701b3 100644 (file)
@@ -1935,7 +1935,7 @@ client_guest_enter (struct Client *c,
   struct ClientListItem *cli = GNUNET_new (struct ClientListItem);
   cli->client = client;
   GNUNET_CONTAINER_DLL_insert (plc->clients_head, plc->clients_tail, cli);
-  return GNUNET_OK; 
+  return GNUNET_OK;
 }
 
 
@@ -2224,7 +2224,7 @@ handle_client_place_leave (void *cls,
   struct Client *c = cls;
   struct GNUNET_SERVICE_Client *client = c->client;
   struct Place *plc = c->place;
-  
+
   GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
               "handle_client_place_leave\n");
 
@@ -2251,6 +2251,7 @@ handle_client_place_leave (void *cls,
   while (NULL != cli)
   {
     GNUNET_CONTAINER_DLL_remove (plc->clients_head, plc->clients_tail, cli);
+    // protocol design failure: should *tell* clients that room is gone!
     GNUNET_SERVICE_client_drop (cli->client);
     next = cli->next;
     GNUNET_free (cli);
@@ -2269,8 +2270,8 @@ handle_client_place_leave (void *cls,
       cleanup_place (plc);
     }
   }
-  //GNUNET_SERVICE_client_continue (client);
-  //GNUNET_SERVICE_client_drop (client);
+  // FIXME: can't continue+drop above, but should not drop above!
+  // GNUNET_SERVICE_client_continue (client);
 }
 
 
@@ -2958,15 +2959,14 @@ handle_client_psyc_message (void *cls,
   struct Client *c = cls;
   struct GNUNET_SERVICE_Client *client = c->client;
   struct Place *plc = c->place;
+  int ret;
+
   if (NULL == plc)
   {
     GNUNET_break (0);
     GNUNET_SERVICE_client_drop (client);
     return;
   }
-
-  int ret = GNUNET_SYSERR;
-
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "%p Received message from client.\n", plc);
   GNUNET_PSYC_log_message (GNUNET_ERROR_TYPE_DEBUG, msg);
@@ -2994,10 +2994,11 @@ handle_client_psyc_message (void *cls,
     return;
   }
 
-  uint16_t first_ptype = 0, last_ptype = 0;
-  if (GNUNET_SYSERR
-      == GNUNET_PSYC_receive_check_parts (psize, (const char *) &msg[1],
-                                          &first_ptype, &last_ptype))
+  uint16_t first_ptype = 0;
+  uint16_t last_ptype = 0;
+  if (GNUNET_SYSERR ==
+      GNUNET_PSYC_receive_check_parts (psize, (const char *) &msg[1],
+                                       &first_ptype, &last_ptype))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "%p Received invalid message part from client.\n", plc);
@@ -3019,7 +3020,10 @@ handle_client_psyc_message (void *cls,
       c->tmit_msg = NULL;
     ret = psyc_transmit_message (plc);
   }
-
+  else
+  {
+    ret = GNUNET_SYSERR;
+  }
   if (GNUNET_OK != ret)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -3440,7 +3444,7 @@ path_basename (const char *path)
   if (NULL != basename)
     basename++;
 
-  if (NULL == basename || '\0' == basename)
+  if (NULL == basename || '\0' == *basename)
     return NULL;
 
   return basename;
index 923ab5e33b3b0c2743aea54f1b22c342eca6e12b..fc649fcdebec1b5506cd8d6cab5c9ab7cbfa456f 100644 (file)
@@ -1079,43 +1079,18 @@ place_cleanup (struct GNUNET_SOCIAL_Place *plc)
 }
 
 
-void
+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_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));
-  if (NULL != plc->mq)
-  {
-    struct GNUNET_MQ_Envelope *env = GNUNET_MQ_get_last_envelope (plc->mq);
-    if (NULL != env)
-    {
-      GNUNET_MQ_notify_sent (env, (GNUNET_SCHEDULER_TaskCallback) place_cleanup, plc);
-    }
-    else
-    {
-      place_cleanup (plc);
-    }
-  }
-  else
-  {
-    place_cleanup (plc);
-  }
-}
-
-
-void
-place_leave (struct GNUNET_SOCIAL_Place *plc)
-{
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-              "social_api: place_leave\n");
-  struct GNUNET_MessageHeader *msg;
-  struct GNUNET_MQ_Envelope *
-    env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
-
-  GNUNET_MQ_send (plc->mq, env);
+  place_cleanup (plc);
 }
 
 
@@ -1589,7 +1564,7 @@ GNUNET_SOCIAL_host_disconnect (struct GNUNET_SOCIAL_Host *hst,
                                GNUNET_ContinuationCallback disconnect_cb,
                                void *cls)
 {
-  struct GNUNET_SOCIAL_Place *plc = &hst->plc; 
+  struct GNUNET_SOCIAL_Place *plc = &hst->plc;
 
   plc->disconnect_cb = disconnect_cb;
   plc->disconnect_cls = cls;
@@ -1597,6 +1572,32 @@ GNUNET_SOCIAL_host_disconnect (struct GNUNET_SOCIAL_Host *hst,
 }
 
 
+/**
+ * Closure for #host_leave_cont.
+ */
+struct HostLeaveContext
+{
+  struct GNUNET_SOCIAL_Host *hst;
+  GNUNET_ContinuationCallback disconnect_cb;
+  void *disconnect_cb_cls;
+};
+
+
+/**
+ * FIXME.
+ */
+static void
+host_leave_cont (void *cls)
+{
+  struct HostLeaveContext *hlc = cls;
+
+  GNUNET_SOCIAL_host_disconnect (hlc->hst,
+                                 hlc->disconnect_cb,
+                                 hlc->disconnect_cb_cls);
+  GNUNET_free (hlc);
+}
+
+
 /**
  * Stop hosting the home.
  *
@@ -1620,12 +1621,25 @@ GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *hst,
                           GNUNET_ContinuationCallback disconnect_cb,
                           void *cls)
 {
+  struct GNUNET_MessageHeader *msg;
+  struct GNUNET_MQ_Envelope *envelope;
+  struct HostLeaveContext *hlc;
+
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
               "GNUNET_SOCIAL_host_leave\n");
   GNUNET_SOCIAL_host_announce (hst, "_notice_place_closing", env, NULL, NULL,
                                GNUNET_SOCIAL_ANNOUNCE_NONE);
-  place_leave (&hst->plc);
-  GNUNET_SOCIAL_host_disconnect (hst, disconnect_cb, cls);
+  envelope = GNUNET_MQ_msg (msg,
+                            GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
+  hlc = GNUNET_new (struct HostLeaveContext);
+  hlc->hst = hst;
+  hlc->disconnect_cb = disconnect_cb;
+  hlc->disconnect_cb_cls = cls;
+  GNUNET_MQ_notify_sent (envelope,
+                         &host_leave_cont,
+                         hlc);
+  GNUNET_MQ_send (hst->plc.mq,
+                  envelope);
 }
 
 
@@ -2056,6 +2070,35 @@ GNUNET_SOCIAL_guest_disconnect (struct GNUNET_SOCIAL_Guest *gst,
 }
 
 
+/**
+ * Closure for #leave_done_cont.
+ */
+struct LeaveContext
+{
+  struct GNUNET_SOCIAL_Guest *gst;
+  GNUNET_ContinuationCallback disconnect_cb;
+  void *disconnect_cb_cls;
+};
+
+
+/**
+ * The leave message was transmitted, now complete the
+ * disconnection process.
+ *
+ * @param cls a `struct LeaveContext`
+ */
+static void
+leave_done_cont (void *cls)
+{
+  struct LeaveContext *lc = cls;
+
+  GNUNET_SOCIAL_guest_disconnect (lc->gst,
+                                  lc->disconnect_cb,
+                                  lc->disconnect_cb_cls);
+  GNUNET_free (lc);
+}
+
+
 /**
  * Leave a place temporarily or permanently.
  *
@@ -2078,10 +2121,27 @@ GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst,
                            GNUNET_ContinuationCallback disconnect_cb,
                            void *cls)
 {
+  struct GNUNET_MessageHeader *msg;
+  struct GNUNET_MQ_Envelope *envelope;
+  struct LeaveContext *lc;
+
   GNUNET_SOCIAL_guest_talk (gst, "_notice_place_leave", env, NULL, NULL,
                             GNUNET_SOCIAL_TALK_NONE);
-  place_leave (&gst->plc);
-  GNUNET_SOCIAL_guest_disconnect (gst, disconnect_cb, cls);
+
+
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "social_api: place_leave\n");
+  envelope = GNUNET_MQ_msg (msg,
+                            GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
+  lc = GNUNET_new (struct LeaveContext);
+  lc->gst = gst;
+  lc->disconnect_cb = disconnect_cb;
+  lc->disconnect_cb_cls = cls;
+  GNUNET_MQ_notify_sent (envelope,
+                         &leave_done_cont,
+                         lc);
+  GNUNET_MQ_send (gst->plc.mq,
+                  envelope);
 }
 
 
index d3657057a2275d4139253691f0714f2c5782922a..52ed20c6b32339fae129018720bfb987233a8639 100644 (file)
@@ -1,3 +1,5 @@
+@INLINE@ ../../contrib/no_forcestart.conf
+
 [social]
 AUTOSTART = YES
 FORCESTART = YES
index 5523b261cb150d8dfbf121cebd5f5d212305bf4a..c7ed5330eda3b8fef63dca5f02f6d9c9b0bf9237 100644 (file)
@@ -61,7 +61,7 @@ struct GNUNET_MQ_Envelope
   GNUNET_SCHEDULER_TaskCallback sent_cb;
 
   /**
-   * Closure for @e send_cb
+   * Closure for @e sent_cb
    */
   void *sent_cls;
 
index fcdf45a5181325ee142d0c0b13a1b3bd7953320a..10dc93fafe5257d82b151c712069bc1d3314c6c8 100644 (file)
@@ -2431,6 +2431,7 @@ resume_client_receive (void *cls)
 void
 GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c)
 {
+  GNUNET_assert (NULL == c->drop_task);
   GNUNET_assert (GNUNET_YES == c->needs_continue);
   GNUNET_assert (NULL == c->recv_task);
   c->needs_continue = GNUNET_NO;