what is the proper way to ensure identity service is running?
[oweals/gnunet.git] / src / social / social_api.c
index bcd263d03f8e76b746e936c1878e69910a4cadf3..e590f7856b8a169948225e0f66bd918c34fc442b 100644 (file)
@@ -102,13 +102,8 @@ struct GNUNET_SOCIAL_App
   GNUNET_SOCIAL_AppEgoCallback ego_cb;
   GNUNET_SOCIAL_AppHostPlaceCallback host_cb;
   GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb;
+  GNUNET_SOCIAL_AppConnectedCallback connected_cb;
   void *cb_cls;
-
-  /**
-   * Is this place in the process of disconnecting from the service?
-   * #GNUNET_YES or #GNUNET_NO
-   */
-  uint8_t is_disconnecting;
 };
 
 
@@ -182,12 +177,6 @@ struct GNUNET_SOCIAL_Place
    * Does this place belong to a host (#GNUNET_YES) or guest (#GNUNET_NO)?
    */
   uint8_t is_host;
-
-  /**
-   * Is this place in the process of disconnecting from the service?
-   * #GNUNET_YES or #GNUNET_NO
-   */
-  uint8_t is_disconnecting;
 };
 
 
@@ -443,7 +432,7 @@ host_recv_notice_place_leave_modifier (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
               "Host received modifier for _notice_place_leave message with ID %" PRIu64 ":\n"
               "%c%s: %.*s\n",
-              message_id, oper, name, value_size, value);
+              message_id, oper, name, value_size, (const char *) value);
 
   /* skip _nym, it's added later in eom() */
   if (0 == memcmp (name, "_nym", sizeof ("_nym"))
@@ -848,7 +837,7 @@ host_recv_enter_request (void *cls,
 
     struct GNUNET_SOCIAL_Nym *nym = nym_get_or_create (&req->slave_pub_key);
     hst->answer_door_cb (hst->cb_cls, nym, method_name, env,
-                         data_size, data);
+                         data, data_size);
   } while (0);
 
   if (NULL != env)
@@ -871,7 +860,8 @@ guest_recv_enter_ack (void *cls,
     cres = (struct GNUNET_PSYC_CountersResultMessage *) msg;
   int32_t result = ntohl (cres->result_code);
   if (NULL != gst->enter_cb)
-    gst->enter_cb (gst->cb_cls, result, GNUNET_ntohll (cres->max_message_id));
+    gst->enter_cb (gst->cb_cls, result, &gst->plc.pub_key,
+                   GNUNET_ntohll (cres->max_message_id));
 }
 
 
@@ -935,6 +925,16 @@ app_recv_ego (void *cls,
 }
 
 
+static void
+app_recv_ego_end (void *cls,
+                  struct GNUNET_CLIENT_MANAGER_Connection *client,
+                  const struct GNUNET_MessageHeader *msg)
+{
+  struct GNUNET_SOCIAL_App *
+    app = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*app));
+}
+
+
 static void
 app_recv_place (void *cls,
                 struct GNUNET_CLIENT_MANAGER_Connection *client,
@@ -957,6 +957,8 @@ app_recv_place (void *cls,
     ego = GNUNET_CONTAINER_multihashmap_get (app->egos, &ego_pub_hash);
   if (NULL == ego)
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Failure to obtain ego. Is identity service running?\n");
     GNUNET_break (0);
     return;
   }
@@ -966,18 +968,33 @@ app_recv_place (void *cls,
     struct GNUNET_SOCIAL_HostConnection *hconn = GNUNET_malloc (sizeof (*hconn));
     hconn->app = app;
     hconn->plc_msg = *pmsg;
-    app->host_cb (app->cb_cls, hconn, ego, &pmsg->place_pub_key, pmsg->place_state);
+    if (NULL != app->host_cb)
+      app->host_cb (app->cb_cls, hconn, ego, &pmsg->place_pub_key, pmsg->place_state);
   }
   else
   {
     struct GNUNET_SOCIAL_GuestConnection *gconn = GNUNET_malloc (sizeof (*gconn));
     gconn->app = app;
     gconn->plc_msg = *pmsg;
-    app->guest_cb (app->cb_cls, gconn, ego, &pmsg->place_pub_key, pmsg->place_state);
+    if (NULL != app->guest_cb)
+      app->guest_cb (app->cb_cls, gconn, ego, &pmsg->place_pub_key, pmsg->place_state);
   }
 }
 
 
+static void
+app_recv_place_end (void *cls,
+                  struct GNUNET_CLIENT_MANAGER_Connection *client,
+                  const struct GNUNET_MessageHeader *msg)
+{
+  struct GNUNET_SOCIAL_App *
+    app = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*app));
+
+  if (NULL != app->connected_cb)
+    app->connected_cb (app->cb_cls);
+}
+
+
 static struct GNUNET_CLIENT_MANAGER_MessageHandler host_handlers[] =
 {
   { host_recv_enter_ack, NULL,
@@ -1060,10 +1077,18 @@ static struct GNUNET_CLIENT_MANAGER_MessageHandler app_handlers[] =
     GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO,
     sizeof (struct AppEgoMessage), GNUNET_YES },
 
+  { app_recv_ego_end, NULL,
+    GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END,
+    sizeof (struct GNUNET_MessageHeader), GNUNET_NO },
+
   { app_recv_place, NULL,
     GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE,
     sizeof (struct AppPlaceMessage), GNUNET_NO },
 
+  { app_recv_place_end, NULL,
+    GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END,
+    sizeof (struct GNUNET_MessageHeader), GNUNET_NO },
+
   { app_recv_result, NULL,
     GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE,
     sizeof (struct GNUNET_OperationResultMessage), GNUNET_YES },
@@ -1508,7 +1533,6 @@ place_disconnect (struct GNUNET_SOCIAL_Place *plc,
                   GNUNET_ContinuationCallback disconnect_cb,
                   void *disconnect_cls)
 {
-  plc->is_disconnecting = GNUNET_YES;
   plc->disconnect_cb = disconnect_cb;
   plc->disconnect_cls = disconnect_cls;
 
@@ -1539,7 +1563,7 @@ GNUNET_SOCIAL_host_disconnect (struct GNUNET_SOCIAL_Host *hst,
 /**
  * Stop hosting the home.
  *
- * Sends a _notice_place_closed announcement to the home.
+ * Sends a _notice_place_closing announcement to the home.
  * Invalidates host handle.
  *
  * @param hst
@@ -1559,7 +1583,7 @@ GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *hst,
                           GNUNET_ContinuationCallback disconnect_cb,
                           void *cls)
 {
-  GNUNET_SOCIAL_host_announce (hst, "_notice_place_closed", env, NULL, NULL,
+  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);
@@ -1962,7 +1986,7 @@ GNUNET_SOCIAL_guest_get_place (struct GNUNET_SOCIAL_Guest *gst)
  * @return Public key of the place.
  */
 const struct GNUNET_CRYPTO_EddsaPublicKey *
-GNUNET_SOCIAL_place_get_key (struct GNUNET_SOCIAL_Place *plc)
+GNUNET_SOCIAL_place_get_pub_key (const struct GNUNET_SOCIAL_Place *plc)
 {
   return &plc->pub_key;
 }
@@ -2438,6 +2462,7 @@ GNUNET_SOCIAL_app_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
                            GNUNET_SOCIAL_AppEgoCallback ego_cb,
                            GNUNET_SOCIAL_AppHostPlaceCallback host_cb,
                            GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb,
+                           GNUNET_SOCIAL_AppConnectedCallback connected_cb,
                            void *cls)
 {
   uint16_t app_id_size = strnlen (id, GNUNET_SOCIAL_APP_MAX_ID_SIZE);
@@ -2450,6 +2475,7 @@ GNUNET_SOCIAL_app_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
   app->ego_cb = ego_cb;
   app->host_cb = host_cb;
   app->guest_cb = guest_cb;
+  app->connected_cb = connected_cb;
   app->cb_cls = cls;
   app->egos = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
   app->client = GNUNET_CLIENT_MANAGER_connect (cfg, "social",
@@ -2478,9 +2504,12 @@ GNUNET_SOCIAL_app_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
  *        Application handle.
  */
 void
-GNUNET_SOCIAL_app_disconnect (struct GNUNET_SOCIAL_App *app)
+GNUNET_SOCIAL_app_disconnect (struct GNUNET_SOCIAL_App *app,
+                              GNUNET_ContinuationCallback disconnect_cb,
+                              void *disconnect_cls)
 {
-  GNUNET_CLIENT_MANAGER_disconnect (app->client, GNUNET_NO, NULL, NULL);
+  GNUNET_CLIENT_MANAGER_disconnect (app->client, GNUNET_NO,
+                                    disconnect_cb, disconnect_cls);
 }