diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-12-03 22:40:43 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-12-03 22:40:43 +0100 |
commit | 5f187deccd1685385b03e20d7f3b55f600adf6ac (patch) | |
tree | 20fff12d3aa02d98a6a9a7ab4aca326aae79c50c /src/gnunet_chat_contact.c | |
parent | 1edfdc77b42d647384c7ef09e2a2b0a59e69633a (diff) | |
download | libgnunetchat-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.c | 63 |
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 | ||
27 | struct GNUNET_CHAT_Contact* | 31 | struct GNUNET_CHAT_Contact* |
28 | contact_create_from_member (struct GNUNET_CHAT_Handle *handle, | 32 | contact_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 | ||
71 | struct GNUNET_CHAT_Context* | ||
72 | contact_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 | |||
67 | void | 130 | void |
68 | contact_destroy (struct GNUNET_CHAT_Contact* contact) | 131 | contact_destroy (struct GNUNET_CHAT_Contact* contact) |
69 | { | 132 | { |