commit 1cef77e04ce307e4375501e8f2f078779b8d316b
parent f1b39ac37e9215dfff1c6a3a68325bda8f790dbe
Author: Jacki <jacki@thejackimonster.de>
Date: Fri, 28 Jun 2024 22:55:33 +0200
Destroy lobby and contact via scheduled task from API call
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
7 files changed, 86 insertions(+), 46 deletions(-)
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
@@ -933,10 +933,9 @@ GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle,
* Leaves the private chat with a specific <i>contact</i> and frees the
* regarding memory of the contact if there remains no common chat with it.
*
- * @param[in,out] contact Cntact
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+ * @param[in,out] contact Contact
*/
-enum GNUNET_GenericReturnValue
+void
GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact);
/**
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
@@ -46,6 +46,8 @@ contact_create_from_member (struct GNUNET_CHAT_Handle *handle,
contact->handle = handle;
contact->context = NULL;
+ contact->destruction = NULL;
+
contact->member = member;
contact->joined = GNUNET_CONTAINER_multihashmap_create(
initial_map_size_of_contact, GNUNET_NO);
@@ -389,6 +391,9 @@ contact_destroy (struct GNUNET_CHAT_Contact* contact)
{
GNUNET_assert(contact);
+ if (contact->destruction)
+ GNUNET_SCHEDULER_cancel(contact->destruction);
+
struct GNUNET_CHAT_InternalTickets *tickets;
while (contact->tickets_head)
{
diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h
@@ -49,6 +49,8 @@ struct GNUNET_CHAT_Contact
struct GNUNET_CHAT_Handle *handle;
struct GNUNET_CHAT_Context *context;
+ struct GNUNET_SCHEDULER_Task *destruction;
+
const struct GNUNET_MESSENGER_Contact *member;
struct GNUNET_CONTAINER_MultiHashMap *joined;
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -628,29 +628,13 @@ GNUNET_CHAT_lobby_close (struct GNUNET_CHAT_Lobby *lobby)
{
GNUNET_CHAT_VERSION_ASSERT();
- if (!lobby)
+ if ((!lobby) || (lobby->destruction))
return;
- struct GNUNET_CHAT_InternalLobbies *lobbies = lobby->handle->lobbies_head;
-
- while (lobbies)
- {
- if (lobbies->lobby == lobby)
- {
- GNUNET_CONTAINER_DLL_remove(
- lobby->handle->lobbies_head,
- lobby->handle->lobbies_tail,
- lobbies
- );
-
- GNUNET_free(lobbies);
- break;
- }
-
- lobbies = lobbies->next;
- }
-
- lobby_destroy(lobby);
+ lobby->destruction = GNUNET_SCHEDULER_add_now(
+ task_lobby_destruction,
+ lobby
+ );
}
@@ -1082,34 +1066,18 @@ GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle,
}
-enum GNUNET_GenericReturnValue
+void
GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact)
{
GNUNET_CHAT_VERSION_ASSERT();
- if (!contact)
- return GNUNET_SYSERR;
-
- struct GNUNET_ShortHashCode shorthash;
- util_shorthash_from_member(contact->member, &shorthash);
-
- GNUNET_CONTAINER_multishortmap_remove(
- contact->handle->contacts, &shorthash, contact
- );
-
- const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(
- contact->context->room
- );
+ if ((!contact) || (contact->destruction))
+ return;
- GNUNET_CONTAINER_multihashmap_remove(
- contact->handle->contexts, key, contact->context
+ contact->destruction = GNUNET_SCHEDULER_add_now(
+ task_contact_destruction,
+ contact
);
-
- context_delete(contact->context, GNUNET_YES);
-
- context_destroy(contact->context);
- contact_destroy(contact);
- return GNUNET_OK;
}
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
@@ -283,6 +283,66 @@ it_room_find_contact (void *cls,
}
void
+task_lobby_destruction (void *cls)
+{
+ GNUNET_assert(cls);
+
+ struct GNUNET_CHAT_Lobby *lobby = (struct GNUNET_CHAT_Lobby*) cls;
+ struct GNUNET_CHAT_InternalLobbies *lobbies = lobby->handle->lobbies_head;
+
+ while (lobbies)
+ {
+ if (lobbies->lobby == lobby)
+ {
+ GNUNET_CONTAINER_DLL_remove(
+ lobby->handle->lobbies_head,
+ lobby->handle->lobbies_tail,
+ lobbies
+ );
+
+ GNUNET_free(lobbies);
+ break;
+ }
+
+ lobbies = lobbies->next;
+ }
+
+ lobby->destruction = NULL;
+
+ lobby_destroy(lobby);
+}
+
+void
+task_contact_destruction (void *cls)
+{
+ GNUNET_assert(cls);
+
+ struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) cls;
+ struct GNUNET_ShortHashCode shorthash;
+
+ util_shorthash_from_member(contact->member, &shorthash);
+
+ GNUNET_CONTAINER_multishortmap_remove(
+ contact->handle->contacts, &shorthash, contact
+ );
+
+ const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(
+ contact->context->room
+ );
+
+ GNUNET_CONTAINER_multihashmap_remove(
+ contact->handle->contexts, key, contact->context
+ );
+
+ context_delete(contact->context, GNUNET_YES);
+ context_destroy(contact->context);
+
+ contact->destruction = NULL;
+
+ contact_destroy(contact);
+}
+
+void
task_group_destruction (void *cls)
{
GNUNET_assert(cls);
diff --git a/src/gnunet_chat_lobby.c b/src/gnunet_chat_lobby.c
@@ -35,6 +35,7 @@ lobby_create (struct GNUNET_CHAT_Handle *handle)
struct GNUNET_CHAT_Lobby *lobby = GNUNET_new(struct GNUNET_CHAT_Lobby);
lobby->handle = handle;
+ lobby->destruction = NULL;
lobby->context = NULL;
lobby->uri = NULL;
@@ -53,6 +54,9 @@ lobby_destroy (struct GNUNET_CHAT_Lobby *lobby)
{
GNUNET_assert(lobby);
+ if (lobby->destruction)
+ GNUNET_SCHEDULER_cancel(lobby->destruction);
+
if ((!(lobby->op)) && (!(lobby->query)))
goto skip_deletion;
diff --git a/src/gnunet_chat_lobby.h b/src/gnunet_chat_lobby.h
@@ -38,6 +38,8 @@ struct GNUNET_CHAT_Lobby
{
struct GNUNET_CHAT_Handle *handle;
+ struct GNUNET_SCHEDULER_Task *destruction;
+
struct GNUNET_CHAT_Context *context;
struct GNUNET_CHAT_Uri *uri;