From e429bb239daae8d0c241176252280caa94143312 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 28 Oct 2017 11:21:55 +0200 Subject: misc social hacking with Lurchi --- src/social/gnunet-service-social.c | 30 +++++---- src/social/social_api.c | 132 +++++++++++++++++++++++++++---------- src/social/test_social.conf | 2 + src/util/mq.c | 2 +- src/util/service.c | 1 + 5 files changed, 117 insertions(+), 50 deletions(-) diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c index 4541a4e06..f9e70a25d 100644 --- a/src/social/gnunet-service-social.c +++ b/src/social/gnunet-service-social.c @@ -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; diff --git a/src/social/social_api.c b/src/social/social_api.c index 923ab5e33..fc649fcde 100644 --- a/src/social/social_api.c +++ b/src/social/social_api.c @@ -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); } diff --git a/src/social/test_social.conf b/src/social/test_social.conf index d3657057a..52ed20c6b 100644 --- a/src/social/test_social.conf +++ b/src/social/test_social.conf @@ -1,3 +1,5 @@ +@INLINE@ ../../contrib/no_forcestart.conf + [social] AUTOSTART = YES FORCESTART = YES diff --git a/src/util/mq.c b/src/util/mq.c index 5523b261c..c7ed5330e 100644 --- a/src/util/mq.c +++ b/src/util/mq.c @@ -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; diff --git a/src/util/service.c b/src/util/service.c index fcdf45a51..10dc93faf 100644 --- a/src/util/service.c +++ b/src/util/service.c @@ -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; -- cgit v1.2.3