diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2023-11-17 00:55:56 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2023-11-17 00:55:56 +0100 |
commit | 70de9fb2ce39ac74ed7e59a6c448ecb98c830073 (patch) | |
tree | cfabf0603debfce2fbe4a6281f88f77cb6abd981 | |
parent | dd96dc544f1007a430f000c6a47d760e8bf20638 (diff) | |
download | gnunet-70de9fb2ce39ac74ed7e59a6c448ecb98c830073.tar.gz gnunet-70de9fb2ce39ac74ed7e59a6c448ecb98c830073.zip |
MESSENGER: Fix handle id initialization and add local contact id
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/include/gnunet_messenger_service.h | 9 | ||||
-rw-r--r-- | src/service/messenger/gnunet-service-messenger.c | 2 | ||||
-rw-r--r-- | src/service/messenger/gnunet-service-messenger_handle.c | 74 | ||||
-rw-r--r-- | src/service/messenger/gnunet-service-messenger_service.c | 73 | ||||
-rw-r--r-- | src/service/messenger/messenger_api.c | 11 | ||||
-rw-r--r-- | src/service/messenger/messenger_api_contact.c | 13 | ||||
-rw-r--r-- | src/service/messenger/messenger_api_contact.h | 14 | ||||
-rw-r--r-- | src/service/messenger/messenger_api_contact_store.c | 4 | ||||
-rw-r--r-- | src/service/messenger/messenger_api_contact_store.h | 2 |
9 files changed, 124 insertions, 78 deletions
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h index 9e389350a..dbe2d6ced 100644 --- a/src/include/gnunet_messenger_service.h +++ b/src/include/gnunet_messenger_service.h | |||
@@ -784,6 +784,15 @@ const struct GNUNET_CRYPTO_PublicKey* | |||
784 | GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact); | 784 | GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact); |
785 | 785 | ||
786 | /** | 786 | /** |
787 | * Get the locally unique id of the <i>contact</i>. | ||
788 | * | ||
789 | * @param[in] contact Contact handle | ||
790 | * @return Locally unique contact id or zero | ||
791 | */ | ||
792 | size_t | ||
793 | GNUNET_MESSENGER_contact_get_id (const struct GNUNET_MESSENGER_Contact *contact); | ||
794 | |||
795 | /** | ||
787 | * Send a <i>message</i> into a <i>room</i>. If you opened the <i>room</i> all entered members will receive the | 796 | * Send a <i>message</i> into a <i>room</i>. If you opened the <i>room</i> all entered members will receive the |
788 | * <i>message</i>. If you entered the <i>room</i> through a <b>door</b> all so entered <b>doors</b> will receive the | 797 | * <i>message</i>. If you entered the <i>room</i> through a <b>door</b> all so entered <b>doors</b> will receive the |
789 | * <i>message</i> as well. All members receiving the <i>message</i> will also propagate this <i>message</i> recursively | 798 | * <i>message</i> as well. All members receiving the <i>message</i> will also propagate this <i>message</i> recursively |
diff --git a/src/service/messenger/gnunet-service-messenger.c b/src/service/messenger/gnunet-service-messenger.c index 8e9805ff0..2d10c60e2 100644 --- a/src/service/messenger/gnunet-service-messenger.c +++ b/src/service/messenger/gnunet-service-messenger.c | |||
@@ -114,7 +114,7 @@ initialize_handle_via_key (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
114 | "Initialization failed while reading invalid key!\n"); | 114 | "Initialization failed while reading invalid key!\n"); |
115 | } | 115 | } |
116 | else | 116 | else |
117 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Initialization is missing key!\n"); | 117 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Initialization is missing key!\n"); |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
diff --git a/src/service/messenger/gnunet-service-messenger_handle.c b/src/service/messenger/gnunet-service-messenger_handle.c index f5d918636..5a50c9c22 100644 --- a/src/service/messenger/gnunet-service-messenger_handle.c +++ b/src/service/messenger/gnunet-service-messenger_handle.c | |||
@@ -213,84 +213,12 @@ change_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
213 | } | 213 | } |
214 | 214 | ||
215 | 215 | ||
216 | struct RoomInitializationClosure | ||
217 | { | ||
218 | struct GNUNET_MESSENGER_SrvHandle *handle; | ||
219 | const struct GNUNET_HashCode *key; | ||
220 | const struct GNUNET_CRYPTO_PublicKey *pubkey; | ||
221 | }; | ||
222 | |||
223 | static int | ||
224 | find_member_session_in_room (void *cls, | ||
225 | const struct GNUNET_CRYPTO_PublicKey *public_key, | ||
226 | struct GNUNET_MESSENGER_MemberSession *session) | ||
227 | { | ||
228 | struct RoomInitializationClosure *init = cls; | ||
229 | |||
230 | if (! public_key) | ||
231 | return GNUNET_YES; | ||
232 | |||
233 | const struct GNUNET_CRYPTO_PublicKey *pubkey = get_srv_handle_key ( | ||
234 | init->handle); | ||
235 | |||
236 | if (0 != GNUNET_memcmp (pubkey, public_key)) | ||
237 | return GNUNET_YES; | ||
238 | |||
239 | const struct GNUNET_ShortHashCode *id = get_member_session_id (session); | ||
240 | |||
241 | if (! id) | ||
242 | { | ||
243 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialitation: Missing member id!"); | ||
244 | return GNUNET_NO; | ||
245 | } | ||
246 | |||
247 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
248 | "Initialitation: Matching member found (%s)!\n", | ||
249 | GNUNET_sh2s (id)); | ||
250 | |||
251 | change_srv_handle_member_id (init->handle, init->key, id); | ||
252 | return GNUNET_NO; | ||
253 | } | ||
254 | |||
255 | |||
256 | static void | ||
257 | initialize_srv_handle_via_matching_member (struct | ||
258 | GNUNET_MESSENGER_SrvHandle *handle, | ||
259 | const struct GNUNET_HashCode *key) | ||
260 | { | ||
261 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (handle->service, | ||
262 | key); | ||
263 | if (! room) | ||
264 | return; | ||
265 | |||
266 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store (room); | ||
267 | if (! store) | ||
268 | return; | ||
269 | |||
270 | const struct GNUNET_CRYPTO_PublicKey *pubkey = get_srv_handle_key (handle); | ||
271 | if ((! pubkey) || (0 == GNUNET_memcmp (pubkey, get_anonymous_public_key ()))) | ||
272 | return; | ||
273 | |||
274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
275 | "Initialize member id of handle via matching member in room!\n"); | ||
276 | |||
277 | struct RoomInitializationClosure init; | ||
278 | init.handle = handle; | ||
279 | init.key = key; | ||
280 | init.pubkey = pubkey; | ||
281 | |||
282 | iterate_store_members (store, find_member_session_in_room, &init); | ||
283 | } | ||
284 | |||
285 | |||
286 | int | 216 | int |
287 | open_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, | 217 | open_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, |
288 | const struct GNUNET_HashCode *key) | 218 | const struct GNUNET_HashCode *key) |
289 | { | 219 | { |
290 | GNUNET_assert ((handle) && (key)); | 220 | GNUNET_assert ((handle) && (key)); |
291 | 221 | ||
292 | initialize_srv_handle_via_matching_member (handle, key); | ||
293 | |||
294 | if ((! get_srv_handle_member_id (handle, key)) && (GNUNET_YES != | 222 | if ((! get_srv_handle_member_id (handle, key)) && (GNUNET_YES != |
295 | create_handle_member_id ( | 223 | create_handle_member_id ( |
296 | handle, key))) | 224 | handle, key))) |
@@ -307,8 +235,6 @@ entry_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
307 | { | 235 | { |
308 | GNUNET_assert ((handle) && (door) && (key)); | 236 | GNUNET_assert ((handle) && (door) && (key)); |
309 | 237 | ||
310 | initialize_srv_handle_via_matching_member (handle, key); | ||
311 | |||
312 | if ((! get_srv_handle_member_id (handle, key)) && (GNUNET_YES != | 238 | if ((! get_srv_handle_member_id (handle, key)) && (GNUNET_YES != |
313 | create_handle_member_id ( | 239 | create_handle_member_id ( |
314 | handle, key))) | 240 | handle, key))) |
diff --git a/src/service/messenger/gnunet-service-messenger_service.c b/src/service/messenger/gnunet-service-messenger_service.c index 63d487db9..981223be5 100644 --- a/src/service/messenger/gnunet-service-messenger_service.c +++ b/src/service/messenger/gnunet-service-messenger_service.c | |||
@@ -228,6 +228,72 @@ get_service_room (const struct GNUNET_MESSENGER_Service *service, | |||
228 | } | 228 | } |
229 | 229 | ||
230 | 230 | ||
231 | struct HandleInitializationClosure | ||
232 | { | ||
233 | struct GNUNET_MESSENGER_SrvHandle *handle; | ||
234 | struct GNUNET_MESSENGER_SrvRoom *room; | ||
235 | const struct GNUNET_CRYPTO_PublicKey *pubkey; | ||
236 | }; | ||
237 | |||
238 | static int | ||
239 | find_member_session_in_room (void *cls, | ||
240 | const struct GNUNET_CRYPTO_PublicKey *public_key, | ||
241 | struct GNUNET_MESSENGER_MemberSession *session) | ||
242 | { | ||
243 | struct HandleInitializationClosure *init = cls; | ||
244 | |||
245 | if (! public_key) | ||
246 | return GNUNET_YES; | ||
247 | |||
248 | const struct GNUNET_CRYPTO_PublicKey *pubkey = get_srv_handle_key ( | ||
249 | init->handle); | ||
250 | |||
251 | if (0 != GNUNET_memcmp (pubkey, public_key)) | ||
252 | return GNUNET_YES; | ||
253 | |||
254 | const struct GNUNET_ShortHashCode *id = get_member_session_id (session); | ||
255 | |||
256 | if (! id) | ||
257 | { | ||
258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialitation: Missing member id!"); | ||
259 | return GNUNET_NO; | ||
260 | } | ||
261 | |||
262 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
263 | "Initialitation: Matching member found (%s)!\n", | ||
264 | GNUNET_sh2s (id)); | ||
265 | |||
266 | change_srv_handle_member_id (init->handle, get_srv_room_key(init->room), id); | ||
267 | return GNUNET_NO; | ||
268 | } | ||
269 | |||
270 | |||
271 | static void | ||
272 | initialize_service_handle (struct GNUNET_MESSENGER_SrvHandle *handle, | ||
273 | struct GNUNET_MESSENGER_SrvRoom *room) | ||
274 | { | ||
275 | GNUNET_assert ((handle) && (room)); | ||
276 | |||
277 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store (room); | ||
278 | if (! store) | ||
279 | return; | ||
280 | |||
281 | const struct GNUNET_CRYPTO_PublicKey *pubkey = get_srv_handle_key (handle); | ||
282 | if ((! pubkey) || (0 == GNUNET_memcmp (pubkey, get_anonymous_public_key ()))) | ||
283 | return; | ||
284 | |||
285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
286 | "Initialize member id of handle via matching member in room!\n"); | ||
287 | |||
288 | struct HandleInitializationClosure init; | ||
289 | init.handle = handle; | ||
290 | init.room = room; | ||
291 | init.pubkey = pubkey; | ||
292 | |||
293 | iterate_store_members (store, find_member_session_in_room, &init); | ||
294 | } | ||
295 | |||
296 | |||
231 | int | 297 | int |
232 | open_service_room (struct GNUNET_MESSENGER_Service *service, | 298 | open_service_room (struct GNUNET_MESSENGER_Service *service, |
233 | struct GNUNET_MESSENGER_SrvHandle *handle, | 299 | struct GNUNET_MESSENGER_SrvHandle *handle, |
@@ -238,9 +304,13 @@ open_service_room (struct GNUNET_MESSENGER_Service *service, | |||
238 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); | 304 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); |
239 | 305 | ||
240 | if (room) | 306 | if (room) |
307 | { | ||
308 | initialize_service_handle (handle, room); | ||
241 | return open_srv_room (room, handle); | 309 | return open_srv_room (room, handle); |
310 | } | ||
242 | 311 | ||
243 | room = create_srv_room (handle, key); | 312 | room = create_srv_room (handle, key); |
313 | initialize_service_handle (handle, room); | ||
244 | 314 | ||
245 | if ((GNUNET_YES == open_srv_room (room, handle)) && | 315 | if ((GNUNET_YES == open_srv_room (room, handle)) && |
246 | (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (service->rooms, | 316 | (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (service->rooms, |
@@ -265,6 +335,8 @@ entry_service_room (struct GNUNET_MESSENGER_Service *service, | |||
265 | 335 | ||
266 | if (room) | 336 | if (room) |
267 | { | 337 | { |
338 | initialize_service_handle (handle, room); | ||
339 | |||
268 | if (GNUNET_YES == enter_srv_room_at (room, handle, door)) | 340 | if (GNUNET_YES == enter_srv_room_at (room, handle, door)) |
269 | return GNUNET_YES; | 341 | return GNUNET_YES; |
270 | else | 342 | else |
@@ -272,6 +344,7 @@ entry_service_room (struct GNUNET_MESSENGER_Service *service, | |||
272 | } | 344 | } |
273 | 345 | ||
274 | room = create_srv_room (handle, key); | 346 | room = create_srv_room (handle, key); |
347 | initialize_service_handle (handle, room); | ||
275 | 348 | ||
276 | if ((GNUNET_YES == enter_srv_room_at (room, handle, door)) && | 349 | if ((GNUNET_YES == enter_srv_room_at (room, handle, door)) && |
277 | (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (service->rooms, | 350 | (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (service->rooms, |
diff --git a/src/service/messenger/messenger_api.c b/src/service/messenger/messenger_api.c index e796e4bad..d7cca918a 100644 --- a/src/service/messenger/messenger_api.c +++ b/src/service/messenger/messenger_api.c | |||
@@ -1027,6 +1027,17 @@ GNUNET_MESSENGER_contact_get_key (const struct | |||
1027 | } | 1027 | } |
1028 | 1028 | ||
1029 | 1029 | ||
1030 | size_t | ||
1031 | GNUNET_MESSENGER_contact_get_id (const struct | ||
1032 | GNUNET_MESSENGER_Contact *contact) | ||
1033 | { | ||
1034 | if (! contact) | ||
1035 | return 0; | ||
1036 | |||
1037 | return get_contact_id(contact); | ||
1038 | } | ||
1039 | |||
1040 | |||
1030 | void | 1041 | void |
1031 | GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, | 1042 | GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, |
1032 | struct GNUNET_MESSENGER_Message *message, | 1043 | struct GNUNET_MESSENGER_Message *message, |
diff --git a/src/service/messenger/messenger_api_contact.c b/src/service/messenger/messenger_api_contact.c index 848a27b8f..47733fe07 100644 --- a/src/service/messenger/messenger_api_contact.c +++ b/src/service/messenger/messenger_api_contact.c | |||
@@ -27,7 +27,8 @@ | |||
27 | #include "messenger_api_contact.h" | 27 | #include "messenger_api_contact.h" |
28 | 28 | ||
29 | struct GNUNET_MESSENGER_Contact* | 29 | struct GNUNET_MESSENGER_Contact* |
30 | create_contact (const struct GNUNET_CRYPTO_PublicKey *key) | 30 | create_contact (const struct GNUNET_CRYPTO_PublicKey *key, |
31 | size_t unique_id) | ||
31 | { | 32 | { |
32 | GNUNET_assert (key); | 33 | GNUNET_assert (key); |
33 | 34 | ||
@@ -36,6 +37,7 @@ create_contact (const struct GNUNET_CRYPTO_PublicKey *key) | |||
36 | 37 | ||
37 | contact->name = NULL; | 38 | contact->name = NULL; |
38 | contact->rc = 0; | 39 | contact->rc = 0; |
40 | contact->id = unique_id; | ||
39 | 41 | ||
40 | GNUNET_memcpy (&(contact->public_key), key, sizeof(contact->public_key)); | 42 | GNUNET_memcpy (&(contact->public_key), key, sizeof(contact->public_key)); |
41 | 43 | ||
@@ -107,6 +109,15 @@ decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact) | |||
107 | } | 109 | } |
108 | 110 | ||
109 | 111 | ||
112 | size_t | ||
113 | get_contact_id (const struct GNUNET_MESSENGER_Contact *contact) | ||
114 | { | ||
115 | GNUNET_assert (contact); | ||
116 | |||
117 | return contact->id; | ||
118 | } | ||
119 | |||
120 | |||
110 | void | 121 | void |
111 | get_context_from_member (const struct GNUNET_HashCode *key, | 122 | get_context_from_member (const struct GNUNET_HashCode *key, |
112 | const struct GNUNET_ShortHashCode *id, | 123 | const struct GNUNET_ShortHashCode *id, |
diff --git a/src/service/messenger/messenger_api_contact.h b/src/service/messenger/messenger_api_contact.h index 4463aa746..b2e3fc364 100644 --- a/src/service/messenger/messenger_api_contact.h +++ b/src/service/messenger/messenger_api_contact.h | |||
@@ -34,6 +34,7 @@ struct GNUNET_MESSENGER_Contact | |||
34 | { | 34 | { |
35 | char *name; | 35 | char *name; |
36 | size_t rc; | 36 | size_t rc; |
37 | size_t id; | ||
37 | 38 | ||
38 | struct GNUNET_CRYPTO_PublicKey public_key; | 39 | struct GNUNET_CRYPTO_PublicKey public_key; |
39 | }; | 40 | }; |
@@ -42,10 +43,12 @@ struct GNUNET_MESSENGER_Contact | |||
42 | * Creates and allocates a new contact with a given public <i>key</i> from an EGO. | 43 | * Creates and allocates a new contact with a given public <i>key</i> from an EGO. |
43 | * | 44 | * |
44 | * @param[in] key Public key | 45 | * @param[in] key Public key |
46 | * @param[in] unique_id Locally unique identifier | ||
45 | * @return New contact | 47 | * @return New contact |
46 | */ | 48 | */ |
47 | struct GNUNET_MESSENGER_Contact* | 49 | struct GNUNET_MESSENGER_Contact* |
48 | create_contact (const struct GNUNET_CRYPTO_PublicKey *key); | 50 | create_contact (const struct GNUNET_CRYPTO_PublicKey *key, |
51 | size_t unique_id); | ||
49 | 52 | ||
50 | /** | 53 | /** |
51 | * Destroys a contact and frees its memory fully. | 54 | * Destroys a contact and frees its memory fully. |
@@ -102,6 +105,15 @@ int | |||
102 | decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact); | 105 | decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact); |
103 | 106 | ||
104 | /** | 107 | /** |
108 | * Returns the locally unique identifier of a given <i>contact</i>. | ||
109 | * | ||
110 | * @param[in] contact contact Contact | ||
111 | * @return Locally unique identifier of contact | ||
112 | */ | ||
113 | size_t | ||
114 | get_contact_id (const struct GNUNET_MESSENGER_Contact *contact); | ||
115 | |||
116 | /** | ||
105 | * Calculates the context <i>hash</i> of a member in a room and returns it. | 117 | * Calculates the context <i>hash</i> of a member in a room and returns it. |
106 | * | 118 | * |
107 | * @param[in] key Key of room | 119 | * @param[in] key Key of room |
diff --git a/src/service/messenger/messenger_api_contact_store.c b/src/service/messenger/messenger_api_contact_store.c index 8bcfb24ff..60bd2974f 100644 --- a/src/service/messenger/messenger_api_contact_store.c +++ b/src/service/messenger/messenger_api_contact_store.c | |||
@@ -36,6 +36,8 @@ init_contact_store (struct GNUNET_MESSENGER_ContactStore *store) | |||
36 | 36 | ||
37 | store->anonymous = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 37 | store->anonymous = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); |
38 | store->contacts = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 38 | store->contacts = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); |
39 | |||
40 | store->counter = 0; | ||
39 | } | 41 | } |
40 | 42 | ||
41 | 43 | ||
@@ -136,7 +138,7 @@ get_store_contact (struct GNUNET_MESSENGER_ContactStore *store, | |||
136 | return contact; | 138 | return contact; |
137 | } | 139 | } |
138 | 140 | ||
139 | contact = create_contact (pubkey); | 141 | contact = create_contact (pubkey, ++(store->counter)); |
140 | 142 | ||
141 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (map, &hash, contact, | 143 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (map, &hash, contact, |
142 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 144 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
diff --git a/src/service/messenger/messenger_api_contact_store.h b/src/service/messenger/messenger_api_contact_store.h index 03912e985..4520e0a47 100644 --- a/src/service/messenger/messenger_api_contact_store.h +++ b/src/service/messenger/messenger_api_contact_store.h | |||
@@ -36,6 +36,8 @@ struct GNUNET_MESSENGER_ContactStore | |||
36 | { | 36 | { |
37 | struct GNUNET_CONTAINER_MultiHashMap *anonymous; | 37 | struct GNUNET_CONTAINER_MultiHashMap *anonymous; |
38 | struct GNUNET_CONTAINER_MultiHashMap *contacts; | 38 | struct GNUNET_CONTAINER_MultiHashMap *contacts; |
39 | |||
40 | size_t counter; | ||
39 | }; | 41 | }; |
40 | 42 | ||
41 | /** | 43 | /** |