aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-03-18 02:05:54 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-03-18 02:05:54 +0100
commit89d4e01123cc5d9130f6b0a20591081ddb66288d (patch)
treec28f12d30bd75ef8f4af97bc34a5309d39ec8112
parent856414dca654422cc1d0786a5cc883d6f720df54 (diff)
downloadlibgnunetchat-89d4e01123cc5d9130f6b0a20591081ddb66288d.tar.gz
libgnunetchat-89d4e01123cc5d9130f6b0a20591081ddb66288d.zip
Adjusted namestore calls
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/gnunet_chat_context.c33
-rw-r--r--src/gnunet_chat_context_intern.c65
-rw-r--r--src/gnunet_chat_lobby.c9
-rw-r--r--src/gnunet_chat_lobby.h3
-rw-r--r--src/gnunet_chat_lobby_intern.c133
5 files changed, 170 insertions, 73 deletions
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c
index fe15307..e0d7082 100644
--- a/src/gnunet_chat_context.c
+++ b/src/gnunet_chat_context.c
@@ -276,9 +276,9 @@ context_write_records (struct GNUNET_CHAT_Context *context)
276 context->handle->namestore, 276 context->handle->namestore,
277 zone, 277 zone,
278 label, 278 label,
279 error_context_write_records, 279 error_context_open_records,
280 context, 280 context,
281 monitor_context_write_records, 281 monitor_context_open_records,
282 context 282 context
283 ); 283 );
284 284
@@ -303,35 +303,16 @@ context_delete_records (struct GNUNET_CHAT_Context *context)
303 context->room 303 context->room
304 ); 304 );
305 305
306 const char *type_string = "chat";
307
308 switch (context->type)
309 {
310 case GNUNET_CHAT_CONTEXT_TYPE_CONTACT:
311 type_string = "contact";
312 break;
313 case GNUNET_CHAT_CONTEXT_TYPE_GROUP:
314 type_string = "group";
315 break;
316 default:
317 break;
318 }
319
320 char *label; 306 char *label;
321 GNUNET_asprintf ( 307 util_get_context_label(context->type, hash, &label);
322 &label,
323 "%s_%s",
324 type_string,
325 GNUNET_h2s(hash)
326 );
327 308
328 GNUNET_NAMESTORE_records_store( 309 GNUNET_NAMESTORE_records_open(
329 context->handle->namestore, 310 context->handle->namestore,
330 zone, 311 zone,
331 label, 312 label,
332 0, 313 error_context_open_records,
333 NULL, 314 context,
334 cont_context_write_records, 315 monitor_context_delete_records,
335 context 316 context
336 ); 317 );
337 318
diff --git a/src/gnunet_chat_context_intern.c b/src/gnunet_chat_context_intern.c
index f8c61e1..79c09a2 100644
--- a/src/gnunet_chat_context_intern.c
+++ b/src/gnunet_chat_context_intern.c
@@ -64,43 +64,50 @@ it_destroy_context_invites (GNUNET_UNUSED void *cls,
64} 64}
65 65
66void 66void
67cont_context_write_records (void *cls, 67cont_context_commit_records (void *cls,
68 GNUNET_UNUSED int32_t success, 68 GNUNET_UNUSED int32_t success,
69 const char *emsg) 69 const char *emsg)
70{ 70{
71 struct GNUNET_CHAT_Context *context = cls; 71 struct GNUNET_CHAT_Context *context = cls;
72 72
73 if (emsg) 73 if ((!emsg) || (!(context->handle)))
74 handle_send_internal_message( 74 return;
75 context->handle, 75
76 context, 76 handle_send_internal_message(
77 GNUNET_CHAT_FLAG_WARNING, 77 context->handle,
78 emsg 78 context,
79 ); 79 GNUNET_CHAT_FLAG_WARNING,
80 emsg
81 );
80} 82}
81 83
82void 84void
83error_context_write_records (void *cls) 85error_context_open_records (void *cls)
84{ 86{
85 struct GNUNET_CHAT_Context *context = cls; 87 struct GNUNET_CHAT_Context *context = cls;
86 88
89 if (!(context->handle))
90 return;
91
87 handle_send_internal_message( 92 handle_send_internal_message(
88 context->handle, 93 context->handle,
89 context, 94 context,
90 GNUNET_CHAT_FLAG_WARNING, 95 GNUNET_CHAT_FLAG_WARNING,
91 _("Failed opening records!") 96 _("Namestore busy!")
92 ); 97 );
93} 98}
94 99
95void 100void
96monitor_context_write_records (void *cls, 101monitor_context_open_records (void *cls,
97 const struct GNUNET_IDENTITY_PrivateKey *zone, 102 const struct GNUNET_IDENTITY_PrivateKey *zone,
98 const char *label, 103 const char *label,
99 GNUNET_UNUSED unsigned int rd_count, 104 GNUNET_UNUSED unsigned int rd_count,
100 GNUNET_UNUSED const struct GNUNET_GNSRECORD_Data *rd) 105 GNUNET_UNUSED const struct GNUNET_GNSRECORD_Data *rd)
101{ 106{
102 struct GNUNET_CHAT_Context *context = cls; 107 struct GNUNET_CHAT_Context *context = cls;
103 108
109 GNUNET_assert((context) && (context->handle));
110
104 const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key( 111 const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key(
105 context->room 112 context->room
106 ); 113 );
@@ -171,7 +178,29 @@ monitor_context_write_records (void *cls,
171 label, 178 label,
172 count, 179 count,
173 data, 180 data,
174 cont_context_write_records, 181 cont_context_commit_records,
182 context
183 );
184}
185
186void
187monitor_context_delete_records (void *cls,
188 const struct GNUNET_IDENTITY_PrivateKey *zone,
189 const char *label,
190 GNUNET_UNUSED unsigned int rd_count,
191 GNUNET_UNUSED const struct GNUNET_GNSRECORD_Data *rd)
192{
193 struct GNUNET_CHAT_Context *context = cls;
194
195 GNUNET_assert((context) && (context->handle));
196
197 GNUNET_NAMESTORE_records_commit(
198 context->handle->namestore,
199 zone,
200 label,
201 0,
202 NULL,
203 cont_context_commit_records,
175 context 204 context
176 ); 205 );
177} 206}
diff --git a/src/gnunet_chat_lobby.c b/src/gnunet_chat_lobby.c
index 23c6d32..385fae8 100644
--- a/src/gnunet_chat_lobby.c
+++ b/src/gnunet_chat_lobby.c
@@ -41,6 +41,9 @@ 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_open = NULL;
45 lobby->query_commit = NULL;
46
44 lobby->expiration = GNUNET_TIME_absolute_get_forever_(); 47 lobby->expiration = GNUNET_TIME_absolute_get_forever_();
45 lobby->callback = NULL; 48 lobby->callback = NULL;
46 lobby->cls = NULL; 49 lobby->cls = NULL;
@@ -59,6 +62,12 @@ lobby_destroy (struct GNUNET_CHAT_Lobby *lobby)
59 if (lobby->op_delete) 62 if (lobby->op_delete)
60 GNUNET_IDENTITY_cancel(lobby->op_delete); 63 GNUNET_IDENTITY_cancel(lobby->op_delete);
61 64
65 if (lobby->query_open)
66 GNUNET_NAMESTORE_cancel(lobby->query_open);
67
68 if (lobby->query_commit)
69 GNUNET_NAMESTORE_cancel(lobby->query_commit);
70
62 if (lobby->uri) 71 if (lobby->uri)
63 uri_destroy(lobby->uri); 72 uri_destroy(lobby->uri);
64 73
diff --git a/src/gnunet_chat_lobby.h b/src/gnunet_chat_lobby.h
index e913134..6248a05 100644
--- a/src/gnunet_chat_lobby.h
+++ b/src/gnunet_chat_lobby.h
@@ -46,6 +46,9 @@ 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_open;
50 struct GNUNET_NAMESTORE_QueueEntry *query_commit;
51
49 struct GNUNET_TIME_Absolute expiration; 52 struct GNUNET_TIME_Absolute expiration;
50 GNUNET_CHAT_LobbyCallback callback; 53 GNUNET_CHAT_LobbyCallback callback;
51 void *cls; 54 void *cls;
diff --git a/src/gnunet_chat_lobby_intern.c b/src/gnunet_chat_lobby_intern.c
index 31d1673..c66800c 100644
--- a/src/gnunet_chat_lobby_intern.c
+++ b/src/gnunet_chat_lobby_intern.c
@@ -25,21 +25,28 @@
25#include "gnunet_chat_context.h" 25#include "gnunet_chat_context.h"
26 26
27void 27void
28cont_lobby_write_records (void *cls, 28cont_lobby_commit_records (void *cls,
29 GNUNET_UNUSED int32_t success, 29 GNUNET_UNUSED int32_t success,
30 const char *emsg) 30 const char *emsg)
31{ 31{
32 struct GNUNET_CHAT_Lobby *lobby = cls; 32 struct GNUNET_CHAT_Lobby *lobby = cls;
33 33
34 GNUNET_assert((lobby) &&
35 (lobby->handle) &&
36 (lobby->context));
37
38 lobby->query_commit = NULL;
39
34 if (!emsg) 40 if (!emsg)
35 goto call_cb; 41 goto call_cb;
36 42
37 handle_send_internal_message( 43 if (lobby->handle)
38 lobby->handle, 44 handle_send_internal_message(
39 lobby->context, 45 lobby->handle,
40 GNUNET_CHAT_FLAG_WARNING, 46 lobby->context,
41 emsg 47 GNUNET_CHAT_FLAG_WARNING,
42 ); 48 emsg
49 );
43 50
44 if (lobby->uri) 51 if (lobby->uri)
45 uri_destroy(lobby->uri); 52 uri_destroy(lobby->uri);
@@ -52,40 +59,41 @@ call_cb:
52} 59}
53 60
54void 61void
55cont_lobby_identity_delete (void *cls, 62error_lobby_open_records (void *cls)
56 const char *emsg)
57{ 63{
58 struct GNUNET_CHAT_Lobby *lobby = cls; 64 struct GNUNET_CHAT_Lobby *lobby = cls;
59 65
60 if (!emsg) 66 GNUNET_assert((lobby) &&
67 (lobby->handle) &&
68 (lobby->context));
69
70 lobby->query_open = NULL;
71
72 if (!(lobby->handle))
61 return; 73 return;
62 74
63 handle_send_internal_message( 75 handle_send_internal_message(
64 lobby->handle, 76 lobby->handle,
65 lobby->context, 77 lobby->context,
66 GNUNET_CHAT_FLAG_WARNING, 78 GNUNET_CHAT_FLAG_WARNING,
67 emsg 79 _("Namestore busy!")
68 ); 80 );
69} 81}
70 82
71void 83void
72cont_lobby_identity_create (void *cls, 84monitor_lobby_open_records (void *cls,
73 const struct GNUNET_IDENTITY_PrivateKey *zone, 85 const struct GNUNET_IDENTITY_PrivateKey *zone,
74 const char *emsg) 86 const char *label,
87 GNUNET_UNUSED unsigned int rd_count,
88 GNUNET_UNUSED const struct GNUNET_GNSRECORD_Data *rd)
75{ 89{
76 struct GNUNET_CHAT_Lobby *lobby = cls; 90 struct GNUNET_CHAT_Lobby *lobby = cls;
77 91
78 if (emsg) 92 GNUNET_assert((lobby) &&
79 { 93 (lobby->handle) &&
80 handle_send_internal_message( 94 (lobby->context));
81 lobby->handle,
82 lobby->context,
83 GNUNET_CHAT_FLAG_WARNING,
84 emsg
85 );
86 95
87 return; 96 lobby->query_open = NULL;
88 }
89 97
90 const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( 98 const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(
91 lobby->context->room 99 lobby->context->room
@@ -102,6 +110,73 @@ cont_lobby_identity_create (void *cls,
102 data[0].expiration_time = lobby->expiration.abs_value_us; 110 data[0].expiration_time = lobby->expiration.abs_value_us;
103 data[0].flags = GNUNET_GNSRECORD_RF_NONE; 111 data[0].flags = GNUNET_GNSRECORD_RF_NONE;
104 112
113 lobby->query_commit = GNUNET_NAMESTORE_records_commit(
114 lobby->handle->namestore,
115 zone,
116 label,
117 1,
118 data,
119 cont_lobby_commit_records,
120 lobby
121 );
122}
123
124void
125cont_lobby_identity_delete (void *cls,
126 const char *emsg)
127{
128 struct GNUNET_CHAT_Lobby *lobby = cls;
129
130 GNUNET_assert((lobby) &&
131 (lobby->handle) &&
132 (lobby->context));
133
134 lobby->op_delete = NULL;
135
136 if ((!emsg) || (!(lobby->handle)))
137 return;
138
139 handle_send_internal_message(
140 lobby->handle,
141 lobby->context,
142 GNUNET_CHAT_FLAG_WARNING,
143 emsg
144 );
145}
146
147void
148cont_lobby_identity_create (void *cls,
149 const struct GNUNET_IDENTITY_PrivateKey *zone,
150 const char *emsg)
151{
152 struct GNUNET_CHAT_Lobby *lobby = cls;
153
154 GNUNET_assert((lobby) &&
155 (lobby->handle) &&
156 (lobby->context));
157
158 const struct GNUNET_HashCode *key;
159
160 lobby->op_create = NULL;
161
162 if (!emsg)
163 goto continue_with_lobby;
164
165 if (lobby->handle)
166 handle_send_internal_message(
167 lobby->handle,
168 lobby->context,
169 GNUNET_CHAT_FLAG_WARNING,
170 emsg
171 );
172
173 return;
174
175continue_with_lobby:
176 key = GNUNET_MESSENGER_room_get_key(
177 lobby->context->room
178 );
179
105 if (lobby->uri) 180 if (lobby->uri)
106 uri_destroy(lobby->uri); 181 uri_destroy(lobby->uri);
107 182
@@ -114,13 +189,13 @@ cont_lobby_identity_create (void *cls,
114 lobby->uri = uri_create(&public_zone, label); 189 lobby->uri = uri_create(&public_zone, label);
115 GNUNET_free(label); 190 GNUNET_free(label);
116 191
117 GNUNET_NAMESTORE_records_store( 192 lobby->query_open = GNUNET_NAMESTORE_records_open(
118 lobby->handle->namestore, 193 lobby->handle->namestore,
119 zone, 194 zone,
120 lobby->uri->label, 195 lobby->uri->label,
121 1, 196 error_lobby_open_records,
122 data, 197 lobby,
123 cont_lobby_write_records, 198 monitor_lobby_open_records,
124 lobby 199 lobby
125 ); 200 );
126 201