summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-03-21 10:47:20 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-03-21 10:47:20 +0100
commitd4d29038712cc96ed85f136ba9f6ac4a2a255ed3 (patch)
tree13381c91b45bcae993f364cc16154e16e762e627
parenteec5d26ea19d234de7abe167ab42785620f1bd55 (diff)
Cleanup namestore calls and reduce codebase for deletion
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/gnunet_chat_context.c72
-rw-r--r--src/gnunet_chat_context.h3
-rw-r--r--src/gnunet_chat_context_intern.c4
-rw-r--r--src/gnunet_chat_lobby.c5
-rw-r--r--src/gnunet_chat_lobby.h2
-rw-r--r--src/gnunet_chat_lobby_intern.c79
6 files changed, 83 insertions, 82 deletions
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c
index a4f3db0..c1e792c 100644
--- a/src/gnunet_chat_context.c
+++ b/src/gnunet_chat_context.c
@@ -42,6 +42,7 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle,
context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN;
context->nick = NULL;
context->topic = NULL;
+ context->deleted = GNUNET_NO;
context->timestamps = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO);
context->messages = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO);
@@ -57,6 +58,8 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle,
8, GNUNET_NO
);
+ context->query = NULL;
+
return context;
}
@@ -73,6 +76,7 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle,
context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT;
context->nick = NULL;
context->topic = NULL;
+ context->deleted = GNUNET_NO;
context->timestamps = GNUNET_CONTAINER_multishortmap_create(4, GNUNET_NO);
context->messages = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO);
@@ -88,6 +92,8 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle,
8, GNUNET_NO
);
+ context->query = NULL;
+
return context;
}
@@ -100,6 +106,9 @@ context_destroy (struct GNUNET_CHAT_Context *context)
(context->invites) &&
(context->files));
+ if (context->query)
+ GNUNET_NAMESTORE_cancel(context->query);
+
GNUNET_CONTAINER_multishortmap_iterate(
context->timestamps, it_destroy_context_timestamps, NULL
);
@@ -292,14 +301,21 @@ context_write_records (struct GNUNET_CHAT_Context *context)
topic = NULL;
}
- unsigned int count = 1;
+ char *label;
+ util_get_context_label(context->type, hash, &label);
+ unsigned int count = 0;
struct GNUNET_GNSRECORD_Data data [3];
+
+ if (GNUNET_YES == context->deleted)
+ goto skip_record_data;
+
data[0].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY;
data[0].data = &room;
data[0].data_size = sizeof(room);
data[0].expiration_time = expiration.abs_value_us;
data[0].flags = GNUNET_GNSRECORD_RF_PRIVATE;
+ count++;
if (nick)
{
@@ -329,9 +345,7 @@ context_write_records (struct GNUNET_CHAT_Context *context)
count++;
}
- char *label;
- util_get_context_label(context->type, hash, &label);
-
+skip_record_data:
GNUNET_NAMESTORE_records_store(
context->handle->namestore,
zone,
@@ -348,52 +362,8 @@ context_write_records (struct GNUNET_CHAT_Context *context)
void
context_delete_records (struct GNUNET_CHAT_Context *context)
{
- GNUNET_assert((context) &&
- (context->handle) &&
- (context->room));
-
- const struct GNUNET_IDENTITY_PrivateKey *zone = handle_get_key(
- context->handle
- );
-
- if (!zone)
- return;
-
- const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key(
- context->room
- );
-
- const char *type_string = "chat";
-
- switch (context->type)
- {
- case GNUNET_CHAT_CONTEXT_TYPE_CONTACT:
- type_string = "contact";
- break;
- case GNUNET_CHAT_CONTEXT_TYPE_GROUP:
- type_string = "group";
- break;
- default:
- break;
- }
-
- char *label;
- GNUNET_asprintf (
- &label,
- "%s_%s",
- type_string,
- GNUNET_h2s(hash)
- );
-
- GNUNET_NAMESTORE_records_store(
- context->handle->namestore,
- zone,
- label,
- 0,
- NULL,
- cont_context_write_records,
- context
- );
+ GNUNET_assert(context);
- GNUNET_free(label);
+ context->deleted = GNUNET_YES;
+ context_write_records(context);
}
diff --git a/src/gnunet_chat_context.h b/src/gnunet_chat_context.h
index 37d9bc8..cc6d5cc 100644
--- a/src/gnunet_chat_context.h
+++ b/src/gnunet_chat_context.h
@@ -44,6 +44,7 @@ struct GNUNET_CHAT_Context
enum GNUNET_CHAT_ContextType type;
char *nick;
char *topic;
+ int deleted;
struct GNUNET_CONTAINER_MultiShortmap *timestamps;
struct GNUNET_CONTAINER_MultiHashMap *messages;
@@ -56,6 +57,8 @@ struct GNUNET_CHAT_Context
void *user_pointer;
struct GNUNET_CONTAINER_MultiShortmap *member_pointers;
+
+ struct GNUNET_NAMESTORE_QueueEntry *query;
};
struct GNUNET_CHAT_Context*
diff --git a/src/gnunet_chat_context_intern.c b/src/gnunet_chat_context_intern.c
index c4a3d5b..b9fca1d 100644
--- a/src/gnunet_chat_context_intern.c
+++ b/src/gnunet_chat_context_intern.c
@@ -70,6 +70,10 @@ cont_context_write_records (void *cls,
{
struct GNUNET_CHAT_Context *context = cls;
+ GNUNET_assert(context);
+
+ context->query = NULL;
+
if (emsg)
handle_send_internal_message(
context->handle,
diff --git a/src/gnunet_chat_lobby.c b/src/gnunet_chat_lobby.c
index 23c6d32..dcc33bb 100644
--- a/src/gnunet_chat_lobby.c
+++ b/src/gnunet_chat_lobby.c
@@ -41,6 +41,8 @@ lobby_create (struct GNUNET_CHAT_Handle *handle)
lobby->op_create = NULL;
lobby->op_delete = NULL;
+ lobby->query = NULL;
+
lobby->expiration = GNUNET_TIME_absolute_get_forever_();
lobby->callback = NULL;
lobby->cls = NULL;
@@ -59,6 +61,9 @@ lobby_destroy (struct GNUNET_CHAT_Lobby *lobby)
if (lobby->op_delete)
GNUNET_IDENTITY_cancel(lobby->op_delete);
+ if (lobby->query)
+ GNUNET_NAMESTORE_cancel(lobby->query);
+
if (lobby->uri)
uri_destroy(lobby->uri);
diff --git a/src/gnunet_chat_lobby.h b/src/gnunet_chat_lobby.h
index e913134..bc37cfc 100644
--- a/src/gnunet_chat_lobby.h
+++ b/src/gnunet_chat_lobby.h
@@ -46,6 +46,8 @@ struct GNUNET_CHAT_Lobby
struct GNUNET_IDENTITY_Operation *op_create;
struct GNUNET_IDENTITY_Operation *op_delete;
+ struct GNUNET_NAMESTORE_QueueEntry *query;
+
struct GNUNET_TIME_Absolute expiration;
GNUNET_CHAT_LobbyCallback callback;
void *cls;
diff --git a/src/gnunet_chat_lobby_intern.c b/src/gnunet_chat_lobby_intern.c
index 31d1673..0c5a647 100644
--- a/src/gnunet_chat_lobby_intern.c
+++ b/src/gnunet_chat_lobby_intern.c
@@ -25,14 +25,17 @@
#include "gnunet_chat_context.h"
void
-cont_lobby_write_records (void *cls,
- GNUNET_UNUSED int32_t success,
- const char *emsg)
+cont_lobby_identity_delete (void *cls,
+ const char *emsg)
{
struct GNUNET_CHAT_Lobby *lobby = cls;
+ GNUNET_assert(lobby);
+
+ lobby->op_delete = NULL;
+
if (!emsg)
- goto call_cb;
+ return;
handle_send_internal_message(
lobby->handle,
@@ -40,25 +43,40 @@ cont_lobby_write_records (void *cls,
GNUNET_CHAT_FLAG_WARNING,
emsg
);
-
- if (lobby->uri)
- uri_destroy(lobby->uri);
-
- lobby->uri = NULL;
-
-call_cb:
- if (lobby->callback)
- lobby->callback(lobby->cls, lobby->uri);
}
void
-cont_lobby_identity_delete (void *cls,
- const char *emsg)
+cont_lobby_write_records (void *cls,
+ GNUNET_UNUSED int32_t success,
+ const char *emsg)
{
struct GNUNET_CHAT_Lobby *lobby = cls;
+ GNUNET_assert(lobby);
+
+ lobby->query = NULL;
+
+ const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(
+ lobby->context->room
+ );
+
+ char *name;
+ util_lobby_name(key, &name);
+
+ lobby->op_delete = GNUNET_IDENTITY_delete(
+ lobby->handle->identity,
+ name,
+ cont_lobby_identity_delete,
+ lobby
+ );
+
+ GNUNET_free(name);
+
if (!emsg)
- return;
+ {
+ context_write_records(lobby->context);
+ goto call_cb;
+ }
handle_send_internal_message(
lobby->handle,
@@ -66,6 +84,15 @@ cont_lobby_identity_delete (void *cls,
GNUNET_CHAT_FLAG_WARNING,
emsg
);
+
+ if (lobby->uri)
+ uri_destroy(lobby->uri);
+
+ lobby->uri = NULL;
+
+call_cb:
+ if (lobby->callback)
+ lobby->callback(lobby->cls, lobby->uri);
}
void
@@ -75,6 +102,10 @@ cont_lobby_identity_create (void *cls,
{
struct GNUNET_CHAT_Lobby *lobby = cls;
+ GNUNET_assert(lobby);
+
+ lobby->op_create = NULL;
+
if (emsg)
{
handle_send_internal_message(
@@ -114,7 +145,7 @@ cont_lobby_identity_create (void *cls,
lobby->uri = uri_create(&public_zone, label);
GNUNET_free(label);
- GNUNET_NAMESTORE_records_store(
+ lobby->query = GNUNET_NAMESTORE_records_store(
lobby->handle->namestore,
zone,
lobby->uri->label,
@@ -123,18 +154,4 @@ cont_lobby_identity_create (void *cls,
cont_lobby_write_records,
lobby
);
-
- context_write_records(lobby->context);
-
- char *name;
- util_lobby_name(key, &name);
-
- lobby->op_delete = GNUNET_IDENTITY_delete(
- lobby->handle->identity,
- name,
- cont_lobby_identity_delete,
- lobby
- );
-
- GNUNET_free(name);
}