diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-17 14:20:17 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-17 14:20:17 +0100 |
commit | 856414dca654422cc1d0786a5cc883d6f720df54 (patch) | |
tree | 88e11ba38570dd23caef5834ba1f426676b95c9d | |
parent | ae0d27195aacfe0a5695218c42580d1b37a1c42b (diff) | |
download | libgnunetchat-856414dca654422cc1d0786a5cc883d6f720df54.tar.gz libgnunetchat-856414dca654422cc1d0786a5cc883d6f720df54.zip |
Usage of new open and commit API for namestore records
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/gnunet_chat_context.c | 68 | ||||
-rw-r--r-- | src/gnunet_chat_context_intern.c | 97 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 18 |
3 files changed, 118 insertions, 65 deletions
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c index a4f3db0..fe15307 100644 --- a/src/gnunet_chat_context.c +++ b/src/gnunet_chat_context.c | |||
@@ -269,76 +269,16 @@ context_write_records (struct GNUNET_CHAT_Context *context) | |||
269 | context->room | 269 | context->room |
270 | ); | 270 | ); |
271 | 271 | ||
272 | struct GNUNET_TIME_Absolute expiration = GNUNET_TIME_absolute_get_forever_(); | ||
273 | |||
274 | struct GNUNET_MESSENGER_RoomEntryRecord room; | ||
275 | GNUNET_CRYPTO_get_peer_identity(context->handle->cfg, &(room.door)); | ||
276 | |||
277 | GNUNET_memcpy( | ||
278 | &(room.key), | ||
279 | hash, | ||
280 | sizeof(room.key) | ||
281 | ); | ||
282 | |||
283 | const char *nick = context->nick; | ||
284 | const char *topic = context->topic; | ||
285 | |||
286 | if (topic) | ||
287 | { | ||
288 | struct GNUNET_HashCode topic_hash; | ||
289 | GNUNET_CRYPTO_hash(topic, strlen(topic), &topic_hash); | ||
290 | |||
291 | if (0 != GNUNET_CRYPTO_hash_cmp(&topic_hash, hash)) | ||
292 | topic = NULL; | ||
293 | } | ||
294 | |||
295 | unsigned int count = 1; | ||
296 | |||
297 | struct GNUNET_GNSRECORD_Data data [3]; | ||
298 | data[0].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY; | ||
299 | data[0].data = &room; | ||
300 | data[0].data_size = sizeof(room); | ||
301 | data[0].expiration_time = expiration.abs_value_us; | ||
302 | data[0].flags = GNUNET_GNSRECORD_RF_PRIVATE; | ||
303 | |||
304 | if (nick) | ||
305 | { | ||
306 | data[count].record_type = GNUNET_GNSRECORD_TYPE_NICK; | ||
307 | data[count].data = nick; | ||
308 | data[count].data_size = strlen(nick); | ||
309 | data[count].expiration_time = expiration.abs_value_us; | ||
310 | data[count].flags = ( | ||
311 | GNUNET_GNSRECORD_RF_PRIVATE | | ||
312 | GNUNET_GNSRECORD_RF_SUPPLEMENTAL | ||
313 | ); | ||
314 | |||
315 | count++; | ||
316 | } | ||
317 | |||
318 | if (topic) | ||
319 | { | ||
320 | data[count].record_type = GNUNET_DNSPARSER_TYPE_TXT; | ||
321 | data[count].data = topic; | ||
322 | data[count].data_size = strlen(topic); | ||
323 | data[count].expiration_time = expiration.abs_value_us; | ||
324 | data[count].flags = ( | ||
325 | GNUNET_GNSRECORD_RF_PRIVATE | | ||
326 | GNUNET_GNSRECORD_RF_SUPPLEMENTAL | ||
327 | ); | ||
328 | |||
329 | count++; | ||
330 | } | ||
331 | |||
332 | char *label; | 272 | char *label; |
333 | util_get_context_label(context->type, hash, &label); | 273 | util_get_context_label(context->type, hash, &label); |
334 | 274 | ||
335 | GNUNET_NAMESTORE_records_store( | 275 | GNUNET_NAMESTORE_records_open( |
336 | context->handle->namestore, | 276 | context->handle->namestore, |
337 | zone, | 277 | zone, |
338 | label, | 278 | label, |
339 | count, | 279 | error_context_write_records, |
340 | data, | 280 | context, |
341 | cont_context_write_records, | 281 | monitor_context_write_records, |
342 | context | 282 | context |
343 | ); | 283 | ); |
344 | 284 | ||
diff --git a/src/gnunet_chat_context_intern.c b/src/gnunet_chat_context_intern.c index c4a3d5b..f8c61e1 100644 --- a/src/gnunet_chat_context_intern.c +++ b/src/gnunet_chat_context_intern.c | |||
@@ -78,3 +78,100 @@ cont_context_write_records (void *cls, | |||
78 | emsg | 78 | emsg |
79 | ); | 79 | ); |
80 | } | 80 | } |
81 | |||
82 | void | ||
83 | error_context_write_records (void *cls) | ||
84 | { | ||
85 | struct GNUNET_CHAT_Context *context = cls; | ||
86 | |||
87 | handle_send_internal_message( | ||
88 | context->handle, | ||
89 | context, | ||
90 | GNUNET_CHAT_FLAG_WARNING, | ||
91 | _("Failed opening records!") | ||
92 | ); | ||
93 | } | ||
94 | |||
95 | void | ||
96 | monitor_context_write_records (void *cls, | ||
97 | const struct GNUNET_IDENTITY_PrivateKey *zone, | ||
98 | const char *label, | ||
99 | GNUNET_UNUSED unsigned int rd_count, | ||
100 | GNUNET_UNUSED const struct GNUNET_GNSRECORD_Data *rd) | ||
101 | { | ||
102 | struct GNUNET_CHAT_Context *context = cls; | ||
103 | |||
104 | const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key( | ||
105 | context->room | ||
106 | ); | ||
107 | |||
108 | struct GNUNET_MESSENGER_RoomEntryRecord room; | ||
109 | GNUNET_CRYPTO_get_peer_identity(context->handle->cfg, &(room.door)); | ||
110 | |||
111 | GNUNET_memcpy( | ||
112 | &(room.key), | ||
113 | hash, | ||
114 | sizeof(room.key) | ||
115 | ); | ||
116 | |||
117 | struct GNUNET_TIME_Absolute expiration = GNUNET_TIME_absolute_get_forever_(); | ||
118 | |||
119 | const char *nick = context->nick; | ||
120 | const char *topic = context->topic; | ||
121 | |||
122 | if (topic) | ||
123 | { | ||
124 | struct GNUNET_HashCode topic_hash; | ||
125 | GNUNET_CRYPTO_hash(topic, strlen(topic), &topic_hash); | ||
126 | |||
127 | if (0 != GNUNET_CRYPTO_hash_cmp(&topic_hash, hash)) | ||
128 | topic = NULL; | ||
129 | } | ||
130 | |||
131 | unsigned int count = 1; | ||
132 | |||
133 | struct GNUNET_GNSRECORD_Data data [3]; | ||
134 | data[0].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY; | ||
135 | data[0].data = &room; | ||
136 | data[0].data_size = sizeof(room); | ||
137 | data[0].expiration_time = expiration.abs_value_us; | ||
138 | data[0].flags = GNUNET_GNSRECORD_RF_PRIVATE; | ||
139 | |||
140 | if (nick) | ||
141 | { | ||
142 | data[count].record_type = GNUNET_GNSRECORD_TYPE_NICK; | ||
143 | data[count].data = nick; | ||
144 | data[count].data_size = strlen(nick); | ||
145 | data[count].expiration_time = expiration.abs_value_us; | ||
146 | data[count].flags = ( | ||
147 | GNUNET_GNSRECORD_RF_PRIVATE | | ||
148 | GNUNET_GNSRECORD_RF_SUPPLEMENTAL | ||
149 | ); | ||
150 | |||
151 | count++; | ||
152 | } | ||
153 | |||
154 | if (topic) | ||
155 | { | ||
156 | data[count].record_type = GNUNET_DNSPARSER_TYPE_TXT; | ||
157 | data[count].data = topic; | ||
158 | data[count].data_size = strlen(topic); | ||
159 | data[count].expiration_time = expiration.abs_value_us; | ||
160 | data[count].flags = ( | ||
161 | GNUNET_GNSRECORD_RF_PRIVATE | | ||
162 | GNUNET_GNSRECORD_RF_SUPPLEMENTAL | ||
163 | ); | ||
164 | |||
165 | count++; | ||
166 | } | ||
167 | |||
168 | GNUNET_NAMESTORE_records_commit( | ||
169 | context->handle->namestore, | ||
170 | zone, | ||
171 | label, | ||
172 | count, | ||
173 | data, | ||
174 | cont_context_write_records, | ||
175 | context | ||
176 | ); | ||
177 | } | ||
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index fd82ba3..7b2303f 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -569,6 +569,13 @@ GNUNET_CHAT_contact_set_name (struct GNUNET_CHAT_Contact *contact, | |||
569 | 569 | ||
570 | if (contact->context->room) | 570 | if (contact->context->room) |
571 | context_write_records(contact->context); | 571 | context_write_records(contact->context); |
572 | |||
573 | handle_send_internal_message( | ||
574 | contact->handle, | ||
575 | contact->context, | ||
576 | GNUNET_CHAT_FLAG_UPDATE, | ||
577 | NULL | ||
578 | ); | ||
572 | } | 579 | } |
573 | 580 | ||
574 | 581 | ||
@@ -684,7 +691,16 @@ GNUNET_CHAT_group_set_name (struct GNUNET_CHAT_Group *group, | |||
684 | return; | 691 | return; |
685 | 692 | ||
686 | context_update_nick(group->context, name); | 693 | context_update_nick(group->context, name); |
687 | context_write_records(group->context); | 694 | |
695 | if (group->context->room) | ||
696 | context_write_records(group->context); | ||
697 | |||
698 | handle_send_internal_message( | ||
699 | group->handle, | ||
700 | group->context, | ||
701 | GNUNET_CHAT_FLAG_UPDATE, | ||
702 | NULL | ||
703 | ); | ||
688 | } | 704 | } |
689 | 705 | ||
690 | 706 | ||