aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_contact.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_contact.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_contact.c')
-rw-r--r--src/gnunet_chat_contact.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
index a955088..190c13a 100644
--- a/src/gnunet_chat_contact.c
+++ b/src/gnunet_chat_contact.c
@@ -23,6 +23,10 @@
23 */ 23 */
24 24
25#include "gnunet_chat_contact.h" 25#include "gnunet_chat_contact.h"
26#include "gnunet_chat_context.h"
27#include "gnunet_chat_handle.h"
28
29#include "gnunet_chat_contact_intern.c"
26 30
27struct GNUNET_CHAT_Contact* 31struct GNUNET_CHAT_Contact*
28contact_create_from_member (struct GNUNET_CHAT_Handle *handle, 32contact_create_from_member (struct GNUNET_CHAT_Handle *handle,
@@ -64,6 +68,65 @@ contact_update_key (struct GNUNET_CHAT_Contact *contact)
64 contact->public_key = GNUNET_IDENTITY_public_key_to_string(pubkey); 68 contact->public_key = GNUNET_IDENTITY_public_key_to_string(pubkey);
65} 69}
66 70
71struct GNUNET_CHAT_Context*
72contact_find_context (struct GNUNET_CHAT_Contact *contact)
73{
74 GNUNET_assert(contact);
75
76 if (contact->context)
77 return contact->context;
78
79 struct GNUNET_CHAT_ContactFindRoom find;
80 find.room = NULL;
81 GNUNET_MESSENGER_find_rooms(
82 contact->handle->messenger,
83 contact->member,
84 it_contact_find_room,
85 &find
86 );
87
88 // TODO: Check if the found room is a group or not
89
90 if (!(find.room))
91 return NULL;
92
93 struct GNUNET_HashCode key;
94 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, &key, sizeof(key));
95
96 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(
97 contact->handle->contexts, &key))
98 return NULL;
99
100 struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_open_room(
101 contact->handle->messenger, &key
102 );
103
104 if (!room)
105 return NULL;
106
107 struct GNUNET_CHAT_Context *context = context_create_from_room(
108 contact->handle, room
109 );
110
111 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(
112 contact->handle->contexts, &key, context,
113 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
114 {
115 context_destroy(context);
116 return NULL;
117 }
118
119 struct GNUNET_MESSENGER_Message msg;
120 msg.header.kind = GNUNET_MESSENGER_KIND_INVITE;
121 GNUNET_CRYPTO_get_peer_identity(contact->handle->cfg, &(msg.body.invite.door));
122 GNUNET_memcpy(&(msg.body.invite.key), &key, sizeof(msg.body.invite.key));
123
124 GNUNET_MESSENGER_send_message(find.room, &msg, contact->member);
125
126 contact->context = context;
127 return contact->context;
128}
129
67void 130void
68contact_destroy (struct GNUNET_CHAT_Contact* contact) 131contact_destroy (struct GNUNET_CHAT_Contact* contact)
69{ 132{