diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2020-11-01 22:57:28 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-03-06 01:30:37 +0100 |
commit | 2925310d67483aca6e055e1ce0593c6463cd6c72 (patch) | |
tree | 2cc8aacafc25563cdccde2eee9a90f9ca257d405 /src/messenger/messenger_api_handle.c | |
parent | 82b864a64679b0a735201724907cdf2b7e4e16c3 (diff) | |
download | gnunet-2925310d67483aca6e055e1ce0593c6463cd6c72.tar.gz gnunet-2925310d67483aca6e055e1ce0593c6463cd6c72.zip |
-added core functionality of the messenger service
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
formatting messenger code
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-completed core functionality of messenger service
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-code cleanup and reuse
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
+added structure to memberships of rooms
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-implemented member permission checks and deletion of messages
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-moved solving requests out of updating last messages (also forward before update)
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-reduced complexity of permisson check and changed load/save of rooms
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-added save/load for accessed keys and basement peers of a room
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-implemented save/load for members with their history and session
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-abstracted management of egos and contacts
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-fix warning
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-abstracted management of members
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-fixed and adjusted test case
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-separated handling of direct and anonymous contacts
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-messenger added member-sessions which fix multiple edge cases, also additional cleanup
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-updated docs and fixed memory leak
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-changed info messages and added protocol version exchange
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-adjusted client api to use contacts from sessions
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-added more logging and fixed wrong session usage
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-adjusted comm0 test case and removed adding members from checking messages
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-fixed test-case for peer exchange
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-getting multiple peers connected in test-case with cadet
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-fixed wrong assert and added tunnel version check
-simplified handling and forwarding
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-fixed merging last messages and cycling info messages
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-automated adding sessions and members
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-corrected use of identity keys and signatures
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-adding local joining on entering external room
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-fixed test-case comm0
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-added more test-cases with generic setup
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-fixed multiple simultaneous channels blocking each other
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-making test-cases more precise
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-added check of members in test-cases, reduced merge messages
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-unified delayed operations: requests, deletions and merges
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-finished handling of operations
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-fixed member session historystorage, added request permission check and padding for transmission
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-improved padding and removed automatic recursive requests
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-implemented filter for sending messages and added private messages to API level
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-wrong setups fixed with proper ego lookups
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-fixed problem with anonymous ego and changed to discrete-level padding
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-added links to replace deleted messages, added local deletion and fixed anonymous id changing
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-added session completion and removal through completion process
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/messenger/messenger_api_handle.c')
-rw-r--r-- | src/messenger/messenger_api_handle.c | 99 |
1 files changed, 41 insertions, 58 deletions
diff --git a/src/messenger/messenger_api_handle.c b/src/messenger/messenger_api_handle.c index 20ef77254..ab57f82cc 100644 --- a/src/messenger/messenger_api_handle.c +++ b/src/messenger/messenger_api_handle.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020 GNUnet e.V. | 3 | Copyright (C) 2020--2021 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -25,10 +25,14 @@ | |||
25 | 25 | ||
26 | #include "messenger_api_handle.h" | 26 | #include "messenger_api_handle.h" |
27 | 27 | ||
28 | #include "messenger_api_util.h" | ||
29 | |||
28 | struct GNUNET_MESSENGER_Handle* | 30 | struct GNUNET_MESSENGER_Handle* |
29 | create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_IdentityCallback identity_callback, | 31 | create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_IdentityCallback identity_callback, |
30 | void *identity_cls, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls) | 32 | void *identity_cls, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls) |
31 | { | 33 | { |
34 | GNUNET_assert(cfg); | ||
35 | |||
32 | struct GNUNET_MESSENGER_Handle *handle = GNUNET_new(struct GNUNET_MESSENGER_Handle); | 36 | struct GNUNET_MESSENGER_Handle *handle = GNUNET_new(struct GNUNET_MESSENGER_Handle); |
33 | 37 | ||
34 | handle->cfg = cfg; | 38 | handle->cfg = cfg; |
@@ -47,7 +51,8 @@ create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_I | |||
47 | handle->reconnect_task = NULL; | 51 | handle->reconnect_task = NULL; |
48 | 52 | ||
49 | handle->rooms = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 53 | handle->rooms = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); |
50 | handle->contacts = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 54 | |
55 | init_contact_store(get_handle_contact_store(handle)); | ||
51 | 56 | ||
52 | return handle; | 57 | return handle; |
53 | } | 58 | } |
@@ -62,19 +67,11 @@ iterate_destroy_room (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
62 | return GNUNET_YES; | 67 | return GNUNET_YES; |
63 | } | 68 | } |
64 | 69 | ||
65 | static int | ||
66 | iterate_destroy_contact (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
67 | { | ||
68 | struct GNUNET_MESSENGER_Contact *contact = value; | ||
69 | |||
70 | destroy_contact (contact); | ||
71 | |||
72 | return GNUNET_YES; | ||
73 | } | ||
74 | |||
75 | void | 70 | void |
76 | destroy_handle (struct GNUNET_MESSENGER_Handle *handle) | 71 | destroy_handle (struct GNUNET_MESSENGER_Handle *handle) |
77 | { | 72 | { |
73 | GNUNET_assert(handle); | ||
74 | |||
78 | if (handle->reconnect_task) | 75 | if (handle->reconnect_task) |
79 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | 76 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); |
80 | 77 | ||
@@ -94,12 +91,7 @@ destroy_handle (struct GNUNET_MESSENGER_Handle *handle) | |||
94 | GNUNET_CONTAINER_multihashmap_destroy (handle->rooms); | 91 | GNUNET_CONTAINER_multihashmap_destroy (handle->rooms); |
95 | } | 92 | } |
96 | 93 | ||
97 | if (handle->contacts) | 94 | clear_contact_store(get_handle_contact_store(handle)); |
98 | { | ||
99 | GNUNET_CONTAINER_multihashmap_iterate (handle->contacts, iterate_destroy_contact, NULL); | ||
100 | |||
101 | GNUNET_CONTAINER_multihashmap_destroy (handle->contacts); | ||
102 | } | ||
103 | 95 | ||
104 | GNUNET_free(handle->name); | 96 | GNUNET_free(handle->name); |
105 | } | 97 | } |
@@ -107,21 +99,27 @@ destroy_handle (struct GNUNET_MESSENGER_Handle *handle) | |||
107 | void | 99 | void |
108 | set_handle_name (struct GNUNET_MESSENGER_Handle *handle, const char *name) | 100 | set_handle_name (struct GNUNET_MESSENGER_Handle *handle, const char *name) |
109 | { | 101 | { |
102 | GNUNET_assert(handle); | ||
103 | |||
110 | if (handle->name) | 104 | if (handle->name) |
111 | GNUNET_free(handle->name); | 105 | GNUNET_free(handle->name); |
112 | 106 | ||
113 | handle->name = name? GNUNET_strdup(name) : NULL; | 107 | handle->name = name ? GNUNET_strdup(name) : NULL; |
114 | } | 108 | } |
115 | 109 | ||
116 | const char* | 110 | const char* |
117 | get_handle_name (const struct GNUNET_MESSENGER_Handle *handle) | 111 | get_handle_name (const struct GNUNET_MESSENGER_Handle *handle) |
118 | { | 112 | { |
113 | GNUNET_assert(handle); | ||
114 | |||
119 | return handle->name; | 115 | return handle->name; |
120 | } | 116 | } |
121 | 117 | ||
122 | void | 118 | void |
123 | set_handle_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *pubkey) | 119 | set_handle_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *pubkey) |
124 | { | 120 | { |
121 | GNUNET_assert(handle); | ||
122 | |||
125 | if (!handle->pubkey) | 123 | if (!handle->pubkey) |
126 | handle->pubkey = GNUNET_new(struct GNUNET_IDENTITY_PublicKey); | 124 | handle->pubkey = GNUNET_new(struct GNUNET_IDENTITY_PublicKey); |
127 | 125 | ||
@@ -131,62 +129,43 @@ set_handle_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_IDEN | |||
131 | const struct GNUNET_IDENTITY_PublicKey* | 129 | const struct GNUNET_IDENTITY_PublicKey* |
132 | get_handle_key (const struct GNUNET_MESSENGER_Handle *handle) | 130 | get_handle_key (const struct GNUNET_MESSENGER_Handle *handle) |
133 | { | 131 | { |
134 | if (!handle->pubkey) | 132 | GNUNET_assert(handle); |
135 | { | ||
136 | struct GNUNET_IDENTITY_Ego *anonymous = GNUNET_IDENTITY_ego_get_anonymous (); | ||
137 | static struct GNUNET_IDENTITY_PublicKey pubkey; | ||
138 | 133 | ||
139 | GNUNET_IDENTITY_ego_get_public_key (anonymous, &pubkey); | 134 | if (handle->pubkey) |
140 | 135 | return handle->pubkey; | |
141 | return &pubkey; | ||
142 | } | ||
143 | 136 | ||
144 | return handle->pubkey; | 137 | return get_anonymous_public_key (); |
145 | } | 138 | } |
146 | 139 | ||
147 | struct GNUNET_MESSENGER_Contact* | 140 | struct GNUNET_MESSENGER_ContactStore* |
148 | get_handle_contact_by_pubkey (const struct GNUNET_MESSENGER_Handle *handle, | 141 | get_handle_contact_store (struct GNUNET_MESSENGER_Handle *handle) |
149 | const struct GNUNET_IDENTITY_PublicKey *pubkey) | ||
150 | { | 142 | { |
151 | struct GNUNET_HashCode hash; | 143 | GNUNET_assert(handle); |
152 | |||
153 | GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash); | ||
154 | |||
155 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_CONTAINER_multihashmap_get (handle->contacts, &hash); | ||
156 | |||
157 | if (contact) | ||
158 | return contact; | ||
159 | |||
160 | contact = create_contact (pubkey); | ||
161 | |||
162 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (handle->contacts, &hash, contact, | ||
163 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
164 | return contact; | ||
165 | 144 | ||
166 | destroy_contact (contact); | 145 | return &(handle->contact_store); |
167 | return NULL; | ||
168 | } | 146 | } |
169 | 147 | ||
170 | void | 148 | struct GNUNET_MESSENGER_Contact* |
171 | swap_handle_contact_by_pubkey (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Contact *contact, | 149 | get_handle_contact (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) |
172 | const struct GNUNET_IDENTITY_PublicKey *pubkey) | ||
173 | { | 150 | { |
174 | const struct GNUNET_HashCode *hash = get_contact_id_from_key (contact); | 151 | GNUNET_assert((handle) && (key)); |
175 | 152 | ||
176 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->contacts, hash, contact)) | 153 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); |
177 | { | ||
178 | GNUNET_memcpy(&(contact->public_key), pubkey, sizeof(*pubkey)); | ||
179 | 154 | ||
180 | hash = get_contact_id_from_key (contact); | 155 | if ((!room) || (!(room->contact_id))) |
156 | return NULL; | ||
181 | 157 | ||
182 | GNUNET_CONTAINER_multihashmap_put (handle->contacts, hash, contact, | 158 | struct GNUNET_HashCode context; |
183 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 159 | get_context_from_member (key, room->contact_id, &context); |
184 | } | 160 | |
161 | return get_store_contact(get_handle_contact_store(handle), &context, get_handle_key(handle)); | ||
185 | } | 162 | } |
186 | 163 | ||
187 | void | 164 | void |
188 | open_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) | 165 | open_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) |
189 | { | 166 | { |
167 | GNUNET_assert((handle) && (key)); | ||
168 | |||
190 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | 169 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); |
191 | 170 | ||
192 | if (room) | 171 | if (room) |
@@ -197,6 +176,8 @@ void | |||
197 | entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, | 176 | entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, |
198 | const struct GNUNET_HashCode *key) | 177 | const struct GNUNET_HashCode *key) |
199 | { | 178 | { |
179 | GNUNET_assert((handle) && (door) && (key)); | ||
180 | |||
200 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | 181 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); |
201 | 182 | ||
202 | if (room) | 183 | if (room) |
@@ -206,6 +187,8 @@ entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNE | |||
206 | void | 187 | void |
207 | close_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) | 188 | close_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) |
208 | { | 189 | { |
190 | GNUNET_assert((handle) && (key)); | ||
191 | |||
209 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | 192 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); |
210 | 193 | ||
211 | if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->rooms, key, room))) | 194 | if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->rooms, key, room))) |