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;
}
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");
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);
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);
}
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);
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);
c->tmit_msg = NULL;
ret = psyc_transmit_message (plc);
}
-
+ else
+ {
+ ret = GNUNET_SYSERR;
+ }
if (GNUNET_OK != ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
if (NULL != basename)
basename++;
- if (NULL == basename || '\0' == basename)
+ if (NULL == basename || '\0' == *basename)
return NULL;
return basename;
}
-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);
}
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;
}
+/**
+ * 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.
*
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);
}
}
+/**
+ * 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.
*
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);
}