aboutsummaryrefslogtreecommitdiff
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)
downloadlibgnunetchat-d4d29038712cc96ed85f136ba9f6ac4a2a255ed3.tar.gz
libgnunetchat-d4d29038712cc96ed85f136ba9f6ac4a2a255ed3.zip
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,
42 context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; 42 context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN;
43 context->nick = NULL; 43 context->nick = NULL;
44 context->topic = NULL; 44 context->topic = NULL;
45 context->deleted = GNUNET_NO;
45 46
46 context->timestamps = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); 47 context->timestamps = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO);
47 context->messages = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); 48 context->messages = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO);
@@ -57,6 +58,8 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle,
57 8, GNUNET_NO 58 8, GNUNET_NO
58 ); 59 );
59 60
61 context->query = NULL;
62
60 return context; 63 return context;
61} 64}
62 65
@@ -73,6 +76,7 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle,
73 context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; 76 context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT;
74 context->nick = NULL; 77 context->nick = NULL;
75 context->topic = NULL; 78 context->topic = NULL;
79 context->deleted = GNUNET_NO;
76 80
77 context->timestamps = GNUNET_CONTAINER_multishortmap_create(4, GNUNET_NO); 81 context->timestamps = GNUNET_CONTAINER_multishortmap_create(4, GNUNET_NO);
78 context->messages = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO); 82 context->messages = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO);
@@ -88,6 +92,8 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle,
88 8, GNUNET_NO 92 8, GNUNET_NO
89 ); 93 );
90 94
95 context->query = NULL;
96
91 return context; 97 return context;
92} 98}
93 99
@@ -100,6 +106,9 @@ context_destroy (struct GNUNET_CHAT_Context *context)
100 (context->invites) && 106 (context->invites) &&
101 (context->files)); 107 (context->files));
102 108
109 if (context->query)
110 GNUNET_NAMESTORE_cancel(context->query);
111
103 GNUNET_CONTAINER_multishortmap_iterate( 112 GNUNET_CONTAINER_multishortmap_iterate(
104 context->timestamps, it_destroy_context_timestamps, NULL 113 context->timestamps, it_destroy_context_timestamps, NULL
105 ); 114 );
@@ -292,14 +301,21 @@ context_write_records (struct GNUNET_CHAT_Context *context)
292 topic = NULL; 301 topic = NULL;
293 } 302 }
294 303
295 unsigned int count = 1; 304 char *label;
305 util_get_context_label(context->type, hash, &label);
296 306
307 unsigned int count = 0;
297 struct GNUNET_GNSRECORD_Data data [3]; 308 struct GNUNET_GNSRECORD_Data data [3];
309
310 if (GNUNET_YES == context->deleted)
311 goto skip_record_data;
312
298 data[0].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY; 313 data[0].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY;
299 data[0].data = &room; 314 data[0].data = &room;
300 data[0].data_size = sizeof(room); 315 data[0].data_size = sizeof(room);
301 data[0].expiration_time = expiration.abs_value_us; 316 data[0].expiration_time = expiration.abs_value_us;
302 data[0].flags = GNUNET_GNSRECORD_RF_PRIVATE; 317 data[0].flags = GNUNET_GNSRECORD_RF_PRIVATE;
318 count++;
303 319
304 if (nick) 320 if (nick)
305 { 321 {
@@ -329,9 +345,7 @@ context_write_records (struct GNUNET_CHAT_Context *context)
329 count++; 345 count++;
330 } 346 }
331 347
332 char *label; 348skip_record_data:
333 util_get_context_label(context->type, hash, &label);
334
335 GNUNET_NAMESTORE_records_store( 349 GNUNET_NAMESTORE_records_store(
336 context->handle->namestore, 350 context->handle->namestore,
337 zone, 351 zone,
@@ -348,52 +362,8 @@ context_write_records (struct GNUNET_CHAT_Context *context)
348void 362void
349context_delete_records (struct GNUNET_CHAT_Context *context) 363context_delete_records (struct GNUNET_CHAT_Context *context)
350{ 364{
351 GNUNET_assert((context) && 365 GNUNET_assert(context);
352 (context->handle) &&
353 (context->room));
354
355 const struct GNUNET_IDENTITY_PrivateKey *zone = handle_get_key(
356 context->handle
357 );
358
359 if (!zone)
360 return;
361
362 const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key(
363 context->room
364 );
365
366 const char *type_string = "chat";
367
368 switch (context->type)
369 {
370 case GNUNET_CHAT_CONTEXT_TYPE_CONTACT:
371 type_string = "contact";
372 break;
373 case GNUNET_CHAT_CONTEXT_TYPE_GROUP:
374 type_string = "group";
375 break;
376 default:
377 break;
378 }
379
380 char *label;
381 GNUNET_asprintf (
382 &label,
383 "%s_%s",
384 type_string,
385 GNUNET_h2s(hash)
386 );
387
388 GNUNET_NAMESTORE_records_store(
389 context->handle->namestore,
390 zone,
391 label,
392 0,
393 NULL,
394 cont_context_write_records,
395 context
396 );
397 366
398 GNUNET_free(label); 367 context->deleted = GNUNET_YES;
368 context_write_records(context);
399} 369}
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
44 enum GNUNET_CHAT_ContextType type; 44 enum GNUNET_CHAT_ContextType type;
45 char *nick; 45 char *nick;
46 char *topic; 46 char *topic;
47 int deleted;
47 48
48 struct GNUNET_CONTAINER_MultiShortmap *timestamps; 49 struct GNUNET_CONTAINER_MultiShortmap *timestamps;
49 struct GNUNET_CONTAINER_MultiHashMap *messages; 50 struct GNUNET_CONTAINER_MultiHashMap *messages;
@@ -56,6 +57,8 @@ struct GNUNET_CHAT_Context
56 void *user_pointer; 57 void *user_pointer;
57 58
58 struct GNUNET_CONTAINER_MultiShortmap *member_pointers; 59 struct GNUNET_CONTAINER_MultiShortmap *member_pointers;
60
61 struct GNUNET_NAMESTORE_QueueEntry *query;
59}; 62};
60 63
61struct GNUNET_CHAT_Context* 64struct 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,
70{ 70{
71 struct GNUNET_CHAT_Context *context = cls; 71 struct GNUNET_CHAT_Context *context = cls;
72 72
73 GNUNET_assert(context);
74
75 context->query = NULL;
76
73 if (emsg) 77 if (emsg)
74 handle_send_internal_message( 78 handle_send_internal_message(
75 context->handle, 79 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)
41 lobby->op_create = NULL; 41 lobby->op_create = NULL;
42 lobby->op_delete = NULL; 42 lobby->op_delete = NULL;
43 43
44 lobby->query = NULL;
45
44 lobby->expiration = GNUNET_TIME_absolute_get_forever_(); 46 lobby->expiration = GNUNET_TIME_absolute_get_forever_();
45 lobby->callback = NULL; 47 lobby->callback = NULL;
46 lobby->cls = NULL; 48 lobby->cls = NULL;
@@ -59,6 +61,9 @@ lobby_destroy (struct GNUNET_CHAT_Lobby *lobby)
59 if (lobby->op_delete) 61 if (lobby->op_delete)
60 GNUNET_IDENTITY_cancel(lobby->op_delete); 62 GNUNET_IDENTITY_cancel(lobby->op_delete);
61 63
64 if (lobby->query)
65 GNUNET_NAMESTORE_cancel(lobby->query);
66
62 if (lobby->uri) 67 if (lobby->uri)
63 uri_destroy(lobby->uri); 68 uri_destroy(lobby->uri);
64 69
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
46 struct GNUNET_IDENTITY_Operation *op_create; 46 struct GNUNET_IDENTITY_Operation *op_create;
47 struct GNUNET_IDENTITY_Operation *op_delete; 47 struct GNUNET_IDENTITY_Operation *op_delete;
48 48
49 struct GNUNET_NAMESTORE_QueueEntry *query;
50
49 struct GNUNET_TIME_Absolute expiration; 51 struct GNUNET_TIME_Absolute expiration;
50 GNUNET_CHAT_LobbyCallback callback; 52 GNUNET_CHAT_LobbyCallback callback;
51 void *cls; 53 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 @@
25#include "gnunet_chat_context.h" 25#include "gnunet_chat_context.h"
26 26
27void 27void
28cont_lobby_write_records (void *cls, 28cont_lobby_identity_delete (void *cls,
29 GNUNET_UNUSED int32_t success, 29 const char *emsg)
30 const char *emsg)
31{ 30{
32 struct GNUNET_CHAT_Lobby *lobby = cls; 31 struct GNUNET_CHAT_Lobby *lobby = cls;
33 32
33 GNUNET_assert(lobby);
34
35 lobby->op_delete = NULL;
36
34 if (!emsg) 37 if (!emsg)
35 goto call_cb; 38 return;
36 39
37 handle_send_internal_message( 40 handle_send_internal_message(
38 lobby->handle, 41 lobby->handle,
@@ -40,25 +43,40 @@ cont_lobby_write_records (void *cls,
40 GNUNET_CHAT_FLAG_WARNING, 43 GNUNET_CHAT_FLAG_WARNING,
41 emsg 44 emsg
42 ); 45 );
43
44 if (lobby->uri)
45 uri_destroy(lobby->uri);
46
47 lobby->uri = NULL;
48
49call_cb:
50 if (lobby->callback)
51 lobby->callback(lobby->cls, lobby->uri);
52} 46}
53 47
54void 48void
55cont_lobby_identity_delete (void *cls, 49cont_lobby_write_records (void *cls,
56 const char *emsg) 50 GNUNET_UNUSED int32_t success,
51 const char *emsg)
57{ 52{
58 struct GNUNET_CHAT_Lobby *lobby = cls; 53 struct GNUNET_CHAT_Lobby *lobby = cls;
59 54
55 GNUNET_assert(lobby);
56
57 lobby->query = NULL;
58
59 const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(
60 lobby->context->room
61 );
62
63 char *name;
64 util_lobby_name(key, &name);
65
66 lobby->op_delete = GNUNET_IDENTITY_delete(
67 lobby->handle->identity,
68 name,
69 cont_lobby_identity_delete,
70 lobby
71 );
72
73 GNUNET_free(name);
74
60 if (!emsg) 75 if (!emsg)
61 return; 76 {
77 context_write_records(lobby->context);
78 goto call_cb;
79 }
62 80
63 handle_send_internal_message( 81 handle_send_internal_message(
64 lobby->handle, 82 lobby->handle,
@@ -66,6 +84,15 @@ cont_lobby_identity_delete (void *cls,
66 GNUNET_CHAT_FLAG_WARNING, 84 GNUNET_CHAT_FLAG_WARNING,
67 emsg 85 emsg
68 ); 86 );
87
88 if (lobby->uri)
89 uri_destroy(lobby->uri);
90
91 lobby->uri = NULL;
92
93call_cb:
94 if (lobby->callback)
95 lobby->callback(lobby->cls, lobby->uri);
69} 96}
70 97
71void 98void
@@ -75,6 +102,10 @@ cont_lobby_identity_create (void *cls,
75{ 102{
76 struct GNUNET_CHAT_Lobby *lobby = cls; 103 struct GNUNET_CHAT_Lobby *lobby = cls;
77 104
105 GNUNET_assert(lobby);
106
107 lobby->op_create = NULL;
108
78 if (emsg) 109 if (emsg)
79 { 110 {
80 handle_send_internal_message( 111 handle_send_internal_message(
@@ -114,7 +145,7 @@ cont_lobby_identity_create (void *cls,
114 lobby->uri = uri_create(&public_zone, label); 145 lobby->uri = uri_create(&public_zone, label);
115 GNUNET_free(label); 146 GNUNET_free(label);
116 147
117 GNUNET_NAMESTORE_records_store( 148 lobby->query = GNUNET_NAMESTORE_records_store(
118 lobby->handle->namestore, 149 lobby->handle->namestore,
119 zone, 150 zone,
120 lobby->uri->label, 151 lobby->uri->label,
@@ -123,18 +154,4 @@ cont_lobby_identity_create (void *cls,
123 cont_lobby_write_records, 154 cont_lobby_write_records,
124 lobby 155 lobby
125 ); 156 );
126
127 context_write_records(lobby->context);
128
129 char *name;
130 util_lobby_name(key, &name);
131
132 lobby->op_delete = GNUNET_IDENTITY_delete(
133 lobby->handle->identity,
134 name,
135 cont_lobby_identity_delete,
136 lobby
137 );
138
139 GNUNET_free(name);
140} 157}