aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_lib.c
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-12-03 22:40:43 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2021-12-03 22:40:43 +0100
commit5f187deccd1685385b03e20d7f3b55f600adf6ac (patch)
tree20fff12d3aa02d98a6a9a7ab4aca326aae79c50c /src/gnunet_chat_lib.c
parent1edfdc77b42d647384c7ef09e2a2b0a59e69633a (diff)
downloadlibgnunetchat-5f187deccd1685385b03e20d7f3b55f600adf6ac.tar.gz
libgnunetchat-5f187deccd1685385b03e20d7f3b55f600adf6ac.zip
Adjusted invitations to groups to check for common contexts
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/gnunet_chat_lib.c')
-rw-r--r--src/gnunet_chat_lib.c60
1 files changed, 7 insertions, 53 deletions
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index 01a9c78..1d12bdd 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -293,58 +293,7 @@ GNUNET_CHAT_contact_get_context (struct GNUNET_CHAT_Contact *contact)
293 if (!contact) 293 if (!contact)
294 return NULL; 294 return NULL;
295 295
296 if (contact->context) 296 return contact_find_context(contact);
297 return contact->context;
298
299 struct GNUNET_CHAT_ContactFindRoom find;
300 find.room = NULL;
301 GNUNET_MESSENGER_find_rooms(
302 contact->handle->messenger,
303 contact->member,
304 it_contact_find_room,
305 &find
306 );
307
308 // TODO: Check if the found room is a group or not
309
310 if (!(find.room))
311 return NULL;
312
313 struct GNUNET_HashCode key;
314 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, &key, sizeof(key));
315
316 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(
317 contact->handle->contexts, &key))
318 return NULL;
319
320 struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_open_room(
321 contact->handle->messenger, &key
322 );
323
324 if (!room)
325 return NULL;
326
327 struct GNUNET_CHAT_Context *context = context_create_from_room(
328 contact->handle, room
329 );
330
331 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(
332 contact->handle->contexts, &key, context,
333 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
334 {
335 context_destroy(context);
336 return NULL;
337 }
338
339 struct GNUNET_MESSENGER_Message msg;
340 msg.header.kind = GNUNET_MESSENGER_KIND_INVITE;
341 GNUNET_CRYPTO_get_peer_identity(contact->handle->cfg, &(msg.body.invite.door));
342 GNUNET_memcpy(&(msg.body.invite.key), &key, sizeof(msg.body.invite.key));
343
344 GNUNET_MESSENGER_send_message(find.room, &msg, contact->member);
345
346 contact->context = context;
347 return contact->context;
348} 297}
349 298
350 299
@@ -444,6 +393,11 @@ GNUNET_CHAT_group_invite_contact (struct GNUNET_CHAT_Group *group,
444 if ((!group) || (!contact)) 393 if ((!group) || (!contact))
445 return; 394 return;
446 395
396 struct GNUNET_CHAT_Context *context = contact_find_context(contact);
397
398 if (!context)
399 return;
400
447 const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( 401 const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(
448 group->context->room 402 group->context->room
449 ); 403 );
@@ -457,7 +411,7 @@ GNUNET_CHAT_group_invite_contact (struct GNUNET_CHAT_Group *group,
457 GNUNET_CRYPTO_get_peer_identity(group->handle->cfg, &(msg.body.invite.door)); 411 GNUNET_CRYPTO_get_peer_identity(group->handle->cfg, &(msg.body.invite.door));
458 GNUNET_memcpy(&(msg.body.invite.key), key, sizeof(msg.body.invite.key)); 412 GNUNET_memcpy(&(msg.body.invite.key), key, sizeof(msg.body.invite.key));
459 413
460 GNUNET_MESSENGER_send_message(contact->context->room, &msg, contact->member); 414 GNUNET_MESSENGER_send_message(context->room, &msg, contact->member);
461} 415}
462 416
463 417