diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2024-01-29 20:19:38 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2024-01-29 20:19:38 +0100 |
commit | dd7e1c8d1776c2f6023f080836befb8c4e4fffa5 (patch) | |
tree | ccb9ff7d302297a9cbf9c0b864e5955ad3422897 /src | |
parent | 8e69ae4231ca7b5bd985393b498c92de4a348c91 (diff) | |
download | gnunet-dd7e1c8d1776c2f6023f080836befb8c4e4fffa5.tar.gz gnunet-dd7e1c8d1776c2f6023f080836befb8c4e4fffa5.zip |
MESSENGER: Implement linked deletion of transcript and private message
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_protocols.h | 16 | ||||
-rw-r--r-- | src/service/messenger/gnunet-service-messenger.h | 37 | ||||
-rw-r--r-- | src/service/messenger/messenger_api.c | 89 | ||||
-rw-r--r-- | src/service/messenger/messenger_api_room.c | 106 | ||||
-rw-r--r-- | src/service/messenger/messenger_api_room.h | 36 |
5 files changed, 223 insertions, 61 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 17aeff63f..42524d490 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2001--2020 GNUnet e.V. | 3 | Copyright (C) 2001--2024 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 |
@@ -3560,17 +3560,9 @@ extern "C" { | |||
3560 | 3560 | ||
3561 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE 1600 | 3561 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE 1600 |
3562 | 3562 | ||
3563 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE 1601 | 3563 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY 1601 |
3564 | 3564 | ||
3565 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY 1602 | 3565 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID 1602 |
3566 | |||
3567 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME 1603 | ||
3568 | |||
3569 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME 1604 | ||
3570 | |||
3571 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY 1605 | ||
3572 | |||
3573 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID 1606 | ||
3574 | 3566 | ||
3575 | /************************************ Room *************************************/ | 3567 | /************************************ Room *************************************/ |
3576 | 3568 | ||
@@ -3588,6 +3580,8 @@ extern "C" { | |||
3588 | 3580 | ||
3589 | #define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC 1617 | 3581 | #define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC 1617 |
3590 | 3582 | ||
3583 | #define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_LINK 1618 | ||
3584 | |||
3591 | /*********************************************************************************/ | 3585 | /*********************************************************************************/ |
3592 | 3586 | ||
3593 | /*********************************************************************************/ | 3587 | /*********************************************************************************/ |
diff --git a/src/service/messenger/gnunet-service-messenger.h b/src/service/messenger/gnunet-service-messenger.h index c3e762734..4d629d2e1 100644 --- a/src/service/messenger/gnunet-service-messenger.h +++ b/src/service/messenger/gnunet-service-messenger.h | |||
@@ -27,6 +27,7 @@ | |||
27 | #define GNUNET_SERVICE_MESSENGER_H | 27 | #define GNUNET_SERVICE_MESSENGER_H |
28 | 28 | ||
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include <stdint.h> | ||
30 | 31 | ||
31 | /** | 32 | /** |
32 | * Message to create a handle for a client | 33 | * Message to create a handle for a client |
@@ -37,14 +38,6 @@ struct GNUNET_MESSENGER_CreateMessage | |||
37 | }; | 38 | }; |
38 | 39 | ||
39 | /** | 40 | /** |
40 | * Message to update the handle (its public key) for a client | ||
41 | */ | ||
42 | struct GNUNET_MESSENGER_UpdateMessage | ||
43 | { | ||
44 | struct GNUNET_MessageHeader header; | ||
45 | }; | ||
46 | |||
47 | /** | ||
48 | * Message to destroy the handle for a client | 41 | * Message to destroy the handle for a client |
49 | */ | 42 | */ |
50 | struct GNUNET_MESSENGER_DestroyMessage | 43 | struct GNUNET_MESSENGER_DestroyMessage |
@@ -53,22 +46,6 @@ struct GNUNET_MESSENGER_DestroyMessage | |||
53 | }; | 46 | }; |
54 | 47 | ||
55 | /** | 48 | /** |
56 | * Message to receive the current name of a handle | ||
57 | */ | ||
58 | struct GNUNET_MESSENGER_NameMessage | ||
59 | { | ||
60 | struct GNUNET_MessageHeader header; | ||
61 | }; | ||
62 | |||
63 | /** | ||
64 | * Message to receive the current public key of a handle | ||
65 | */ | ||
66 | struct GNUNET_MESSENGER_KeyMessage | ||
67 | { | ||
68 | struct GNUNET_MessageHeader header; | ||
69 | }; | ||
70 | |||
71 | /** | ||
72 | * General message to confirm interaction with a room | 49 | * General message to confirm interaction with a room |
73 | */ | 50 | */ |
74 | struct GNUNET_MESSENGER_RoomMessage | 51 | struct GNUNET_MESSENGER_RoomMessage |
@@ -127,4 +104,16 @@ struct GNUNET_MESSENGER_RecvMessage | |||
127 | uint32_t flags; | 104 | uint32_t flags; |
128 | }; | 105 | }; |
129 | 106 | ||
107 | /** | ||
108 | * Message to link something in a room | ||
109 | */ | ||
110 | struct GNUNET_MESSENGER_LinkMessage | ||
111 | { | ||
112 | struct GNUNET_MessageHeader header; | ||
113 | |||
114 | struct GNUNET_HashCode key; | ||
115 | struct GNUNET_HashCode hashes [2]; | ||
116 | uint32_t bidirectional; | ||
117 | }; | ||
118 | |||
130 | #endif //GNUNET_SERVICE_MESSENGER_H | 119 | #endif //GNUNET_SERVICE_MESSENGER_H |
diff --git a/src/service/messenger/messenger_api.c b/src/service/messenger/messenger_api.c index e69309573..240a5e018 100644 --- a/src/service/messenger/messenger_api.c +++ b/src/service/messenger/messenger_api.c | |||
@@ -225,6 +225,12 @@ handle_member_id (void *cls, | |||
225 | } | 225 | } |
226 | 226 | ||
227 | 227 | ||
228 | static void | ||
229 | delete_message_in_room (struct GNUNET_MESSENGER_Room *room, | ||
230 | const struct GNUNET_HashCode *hash, | ||
231 | const struct GNUNET_TIME_Relative delay); | ||
232 | |||
233 | |||
228 | static enum GNUNET_GenericReturnValue | 234 | static enum GNUNET_GenericReturnValue |
229 | check_recv_message (void *cls, | 235 | check_recv_message (void *cls, |
230 | const struct GNUNET_MESSENGER_RecvMessage *msg) | 236 | const struct GNUNET_MESSENGER_RecvMessage *msg) |
@@ -285,6 +291,8 @@ handle_recv_message (void *cls, | |||
285 | decode_message (&message, length, buffer, GNUNET_YES, NULL); | 291 | decode_message (&message, length, buffer, GNUNET_YES, NULL); |
286 | 292 | ||
287 | struct GNUNET_MESSENGER_Message *private_message = NULL; | 293 | struct GNUNET_MESSENGER_Message *private_message = NULL; |
294 | const struct GNUNET_MESSENGER_Message *handle_msg = &message; | ||
295 | |||
288 | if (GNUNET_MESSENGER_KIND_PRIVATE == message.header.kind) | 296 | if (GNUNET_MESSENGER_KIND_PRIVATE == message.header.kind) |
289 | { | 297 | { |
290 | private_message = copy_message (&message); | 298 | private_message = copy_message (&message); |
@@ -351,8 +359,25 @@ handle_recv_message (void *cls, | |||
351 | recipient = get_store_contact(store, context, recipient_key); | 359 | recipient = get_store_contact(store, context, recipient_key); |
352 | 360 | ||
353 | skip_recipient: | 361 | skip_recipient: |
354 | contact = handle_room_message (room, contact, recipient, private_message ? | 362 | if (private_message) |
355 | private_message : &message, hash, flags); | 363 | handle_msg = private_message; |
364 | |||
365 | if (GNUNET_MESSENGER_KIND_DELETE == handle_msg->header.kind) | ||
366 | { | ||
367 | struct GNUNET_TIME_Relative delay; | ||
368 | struct GNUNET_TIME_Absolute action; | ||
369 | |||
370 | delay = GNUNET_TIME_relative_ntoh (handle_msg->body.deletion.delay); | ||
371 | |||
372 | action = GNUNET_TIME_absolute_ntoh (handle_msg->header.timestamp); | ||
373 | action = GNUNET_TIME_absolute_add (action, delay); | ||
374 | |||
375 | delay = GNUNET_TIME_absolute_get_difference (GNUNET_TIME_absolute_get (), action); | ||
376 | |||
377 | link_room_deletion (room, &(handle_msg->body.deletion.hash), delay, delete_message_in_room); | ||
378 | } | ||
379 | |||
380 | contact = handle_room_message (room, contact, recipient, handle_msg, hash, flags); | ||
356 | 381 | ||
357 | const struct GNUNET_MESSENGER_Message *stored_message = get_room_message ( | 382 | const struct GNUNET_MESSENGER_Message *stored_message = get_room_message ( |
358 | room, hash); | 383 | room, hash); |
@@ -693,8 +718,8 @@ GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle) | |||
693 | static void | 718 | static void |
694 | send_message_to_room (struct GNUNET_MESSENGER_Room *room, | 719 | send_message_to_room (struct GNUNET_MESSENGER_Room *room, |
695 | struct GNUNET_MESSENGER_Message *message, | 720 | struct GNUNET_MESSENGER_Message *message, |
696 | struct GNUNET_MESSENGER_Message *transcript, | 721 | const struct GNUNET_CRYPTO_PrivateKey *key, |
697 | const struct GNUNET_CRYPTO_PrivateKey *key) | 722 | struct GNUNET_HashCode *hash) |
698 | { | 723 | { |
699 | const struct GNUNET_ShortHashCode *sender_id = get_room_sender_id (room); | 724 | const struct GNUNET_ShortHashCode *sender_id = get_room_sender_id (room); |
700 | 725 | ||
@@ -723,14 +748,10 @@ send_message_to_room (struct GNUNET_MESSENGER_Room *room, | |||
723 | char *msg_buffer = ((char*) msg) + sizeof(*msg); | 748 | char *msg_buffer = ((char*) msg) + sizeof(*msg); |
724 | encode_message (message, msg_length, msg_buffer, GNUNET_YES); | 749 | encode_message (message, msg_length, msg_buffer, GNUNET_YES); |
725 | 750 | ||
726 | struct GNUNET_HashCode hash; | 751 | hash_message (message, msg_length, msg_buffer, hash); |
727 | hash_message (message, msg_length, msg_buffer, &hash); | 752 | sign_message (message, msg_length, msg_buffer, hash, key); |
728 | sign_message (message, msg_length, msg_buffer, &hash, key); | ||
729 | |||
730 | if (transcript) | ||
731 | GNUNET_memcpy (&(transcript->body.transcript.hash), &hash, sizeof(hash)); | ||
732 | 753 | ||
733 | GNUNET_memcpy (&(room->last_message), &hash, sizeof(room->last_message)); | 754 | GNUNET_memcpy (&(room->last_message), hash, sizeof(room->last_message)); |
734 | 755 | ||
735 | GNUNET_MQ_send (room->handle->mq, env); | 756 | GNUNET_MQ_send (room->handle->mq, env); |
736 | 757 | ||
@@ -772,13 +793,14 @@ enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, | |||
772 | static enum GNUNET_GenericReturnValue | 793 | static enum GNUNET_GenericReturnValue |
773 | dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room) | 794 | dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room) |
774 | { | 795 | { |
796 | if (GNUNET_YES != is_room_available (room)) | ||
797 | return room->queue.head ? GNUNET_NO : GNUNET_YES; | ||
798 | |||
775 | struct GNUNET_MESSENGER_Message *message = NULL; | 799 | struct GNUNET_MESSENGER_Message *message = NULL; |
776 | struct GNUNET_MESSENGER_Message *transcript = NULL; | 800 | struct GNUNET_MESSENGER_Message *transcript = NULL; |
777 | struct GNUNET_CRYPTO_PublicKey pubkey; | 801 | struct GNUNET_CRYPTO_PublicKey pubkey; |
778 | struct GNUNET_CRYPTO_PrivateKey key; | 802 | struct GNUNET_CRYPTO_PrivateKey key; |
779 | 803 | struct GNUNET_HashCode hash, other; | |
780 | if (GNUNET_YES != is_room_available (room)) | ||
781 | return room->queue.head ? GNUNET_NO : GNUNET_YES; | ||
782 | 804 | ||
783 | do { | 805 | do { |
784 | if (message) | 806 | if (message) |
@@ -792,15 +814,21 @@ dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room) | |||
792 | continue; | 814 | continue; |
793 | } | 815 | } |
794 | 816 | ||
795 | send_message_to_room (room, message, transcript, &key); | 817 | send_message_to_room (room, message, &key, &hash); |
796 | 818 | ||
797 | if (!transcript) | 819 | if (!transcript) |
798 | continue; | 820 | continue; |
799 | 821 | ||
800 | GNUNET_CRYPTO_key_get_public(&key, &pubkey); | 822 | GNUNET_memcpy (&(transcript->body.transcript.hash), &hash, sizeof(hash)); |
823 | GNUNET_CRYPTO_key_get_public (&key, &pubkey); | ||
801 | 824 | ||
802 | if (GNUNET_YES == encrypt_message(transcript, &pubkey)) | 825 | if (GNUNET_YES == encrypt_message(transcript, &pubkey)) |
803 | send_message_to_room (room, transcript, NULL, &key); | 826 | { |
827 | send_message_to_room (room, transcript, &key, &other); | ||
828 | |||
829 | link_room_message(room, &hash, &other); | ||
830 | link_room_message(room, &other, &hash); | ||
831 | } | ||
804 | else | 832 | else |
805 | { | 833 | { |
806 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 834 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1210,19 +1238,16 @@ GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, | |||
1210 | else | 1238 | else |
1211 | public_key = NULL; | 1239 | public_key = NULL; |
1212 | 1240 | ||
1213 | send_message_to_room_with_key (room, copy_message(message), public_key); | 1241 | send_message_to_room_with_key (room, copy_message (message), public_key); |
1214 | } | 1242 | } |
1215 | 1243 | ||
1216 | 1244 | ||
1217 | void | 1245 | static void |
1218 | GNUNET_MESSENGER_delete_message (struct GNUNET_MESSENGER_Room *room, | 1246 | delete_message_in_room (struct GNUNET_MESSENGER_Room *room, |
1219 | const struct GNUNET_HashCode *hash, | 1247 | const struct GNUNET_HashCode *hash, |
1220 | const struct GNUNET_TIME_Relative delay) | 1248 | const struct GNUNET_TIME_Relative delay) |
1221 | { | 1249 | { |
1222 | if ((! room) || (! hash)) | 1250 | struct GNUNET_MESSENGER_Message *message = create_message_delete (hash, delay); |
1223 | return; | ||
1224 | |||
1225 | struct GNUNET_MESSENGER_Message *message = create_message_delete(hash, delay); | ||
1226 | 1251 | ||
1227 | if (! message) | 1252 | if (! message) |
1228 | { | 1253 | { |
@@ -1235,6 +1260,18 @@ GNUNET_MESSENGER_delete_message (struct GNUNET_MESSENGER_Room *room, | |||
1235 | } | 1260 | } |
1236 | 1261 | ||
1237 | 1262 | ||
1263 | void | ||
1264 | GNUNET_MESSENGER_delete_message (struct GNUNET_MESSENGER_Room *room, | ||
1265 | const struct GNUNET_HashCode *hash, | ||
1266 | const struct GNUNET_TIME_Relative delay) | ||
1267 | { | ||
1268 | if ((! room) || (! hash)) | ||
1269 | return; | ||
1270 | |||
1271 | delete_message_in_room (room, hash, delay); | ||
1272 | } | ||
1273 | |||
1274 | |||
1238 | const struct GNUNET_MESSENGER_Message* | 1275 | const struct GNUNET_MESSENGER_Message* |
1239 | GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, | 1276 | GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, |
1240 | const struct GNUNET_HashCode *hash) | 1277 | const struct GNUNET_HashCode *hash) |
diff --git a/src/service/messenger/messenger_api_room.c b/src/service/messenger/messenger_api_room.c index e7de430ae..c66f0e594 100644 --- a/src/service/messenger/messenger_api_room.c +++ b/src/service/messenger/messenger_api_room.c | |||
@@ -25,6 +25,7 @@ | |||
25 | 25 | ||
26 | #include "messenger_api_room.h" | 26 | #include "messenger_api_room.h" |
27 | 27 | ||
28 | #include "gnunet_time_lib.h" | ||
28 | #include "messenger_api_handle.h" | 29 | #include "messenger_api_handle.h" |
29 | #include "messenger_api_message.h" | 30 | #include "messenger_api_message.h" |
30 | 31 | ||
@@ -52,6 +53,7 @@ create_room (struct GNUNET_MESSENGER_Handle *handle, | |||
52 | 53 | ||
53 | room->messages = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 54 | room->messages = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); |
54 | room->members = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_NO); | 55 | room->members = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_NO); |
56 | room->links = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | ||
55 | 57 | ||
56 | init_queue_messages (&(room->queue)); | 58 | init_queue_messages (&(room->queue)); |
57 | 59 | ||
@@ -73,6 +75,17 @@ iterate_destroy_message (void *cls, | |||
73 | } | 75 | } |
74 | 76 | ||
75 | 77 | ||
78 | static enum GNUNET_GenericReturnValue | ||
79 | iterate_destroy_link (void *cls, | ||
80 | const struct GNUNET_HashCode *key, | ||
81 | void *value) | ||
82 | { | ||
83 | struct GNUNET_HashCode *hash = value; | ||
84 | GNUNET_free (hash); | ||
85 | return GNUNET_YES; | ||
86 | } | ||
87 | |||
88 | |||
76 | void | 89 | void |
77 | destroy_room (struct GNUNET_MESSENGER_Room *room) | 90 | destroy_room (struct GNUNET_MESSENGER_Room *room) |
78 | { | 91 | { |
@@ -92,6 +105,14 @@ destroy_room (struct GNUNET_MESSENGER_Room *room) | |||
92 | if (room->members) | 105 | if (room->members) |
93 | GNUNET_CONTAINER_multishortmap_destroy (room->members); | 106 | GNUNET_CONTAINER_multishortmap_destroy (room->members); |
94 | 107 | ||
108 | if (room->links) | ||
109 | { | ||
110 | GNUNET_CONTAINER_multihashmap_iterate (room->links, | ||
111 | iterate_destroy_link, NULL); | ||
112 | |||
113 | GNUNET_CONTAINER_multihashmap_destroy (room->links); | ||
114 | } | ||
115 | |||
95 | if (room->sender_id) | 116 | if (room->sender_id) |
96 | GNUNET_free (room->sender_id); | 117 | GNUNET_free (room->sender_id); |
97 | 118 | ||
@@ -513,3 +534,88 @@ find_room_member (const struct GNUNET_MESSENGER_Room *room, | |||
513 | 534 | ||
514 | return find.result; | 535 | return find.result; |
515 | } | 536 | } |
537 | |||
538 | |||
539 | static enum GNUNET_GenericReturnValue | ||
540 | find_linked_hash (void *cls, | ||
541 | const struct GNUNET_HashCode *key, | ||
542 | void *value) | ||
543 | { | ||
544 | const struct GNUNET_HashCode **result = cls; | ||
545 | struct GNUNET_HashCode *hash = value; | ||
546 | |||
547 | if (0 == GNUNET_CRYPTO_hash_cmp (hash, *result)) | ||
548 | { | ||
549 | *result = NULL; | ||
550 | return GNUNET_NO; | ||
551 | } | ||
552 | |||
553 | return GNUNET_YES; | ||
554 | } | ||
555 | |||
556 | |||
557 | void | ||
558 | link_room_message (struct GNUNET_MESSENGER_Room *room, | ||
559 | const struct GNUNET_HashCode *hash, | ||
560 | const struct GNUNET_HashCode *other) | ||
561 | { | ||
562 | GNUNET_assert ((room) && (hash) && (other)); | ||
563 | |||
564 | const struct GNUNET_HashCode **result = &other; | ||
565 | GNUNET_CONTAINER_multihashmap_get_multiple (room->links, hash, | ||
566 | find_linked_hash, result); | ||
567 | |||
568 | if (! *result) | ||
569 | return; | ||
570 | |||
571 | struct GNUNET_HashCode *value = GNUNET_memdup(other, sizeof(struct GNUNET_HashCode)); | ||
572 | if (! value) | ||
573 | return; | ||
574 | |||
575 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (room->links, hash, value, | ||
576 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)) | ||
577 | GNUNET_free (value); | ||
578 | } | ||
579 | |||
580 | |||
581 | struct GNUNET_MESSENGER_RoomLinkDeletionInfo | ||
582 | { | ||
583 | struct GNUNET_MESSENGER_Room *room; | ||
584 | struct GNUNET_TIME_Relative delay; | ||
585 | GNUNET_MESSENGER_RoomLinkDeletion deletion; | ||
586 | }; | ||
587 | |||
588 | |||
589 | static enum GNUNET_GenericReturnValue | ||
590 | delete_linked_hash (void *cls, | ||
591 | const struct GNUNET_HashCode *key, | ||
592 | void *value) | ||
593 | { | ||
594 | struct GNUNET_MESSENGER_RoomLinkDeletionInfo *info = cls; | ||
595 | struct GNUNET_HashCode *hash = value; | ||
596 | |||
597 | if (info->deletion) | ||
598 | info->deletion (info->room, hash, info->delay); | ||
599 | |||
600 | GNUNET_free (hash); | ||
601 | return GNUNET_YES; | ||
602 | } | ||
603 | |||
604 | |||
605 | void | ||
606 | link_room_deletion (struct GNUNET_MESSENGER_Room *room, | ||
607 | const struct GNUNET_HashCode *hash, | ||
608 | const struct GNUNET_TIME_Relative delay, | ||
609 | GNUNET_MESSENGER_RoomLinkDeletion deletion) | ||
610 | { | ||
611 | GNUNET_assert ((room) && (hash)); | ||
612 | |||
613 | struct GNUNET_MESSENGER_RoomLinkDeletionInfo info; | ||
614 | info.room = room; | ||
615 | info.delay = delay; | ||
616 | info.deletion = deletion; | ||
617 | |||
618 | GNUNET_CONTAINER_multihashmap_get_multiple (room->links, hash, | ||
619 | delete_linked_hash, &info); | ||
620 | GNUNET_CONTAINER_multihashmap_remove_all (room->links, hash); | ||
621 | } | ||
diff --git a/src/service/messenger/messenger_api_room.h b/src/service/messenger/messenger_api_room.h index 855405337..79571bc2e 100644 --- a/src/service/messenger/messenger_api_room.h +++ b/src/service/messenger/messenger_api_room.h | |||
@@ -26,6 +26,8 @@ | |||
26 | #ifndef GNUNET_MESSENGER_API_ROOM_H | 26 | #ifndef GNUNET_MESSENGER_API_ROOM_H |
27 | #define GNUNET_MESSENGER_API_ROOM_H | 27 | #define GNUNET_MESSENGER_API_ROOM_H |
28 | 28 | ||
29 | #include "gnunet_common.h" | ||
30 | #include "gnunet_time_lib.h" | ||
29 | #include "gnunet_util_lib.h" | 31 | #include "gnunet_util_lib.h" |
30 | 32 | ||
31 | #include "gnunet_messenger_service.h" | 33 | #include "gnunet_messenger_service.h" |
@@ -58,10 +60,15 @@ struct GNUNET_MESSENGER_Room | |||
58 | 60 | ||
59 | struct GNUNET_CONTAINER_MultiHashMap *messages; | 61 | struct GNUNET_CONTAINER_MultiHashMap *messages; |
60 | struct GNUNET_CONTAINER_MultiShortmap *members; | 62 | struct GNUNET_CONTAINER_MultiShortmap *members; |
63 | struct GNUNET_CONTAINER_MultiHashMap *links; | ||
61 | 64 | ||
62 | struct GNUNET_MESSENGER_QueueMessages queue; | 65 | struct GNUNET_MESSENGER_QueueMessages queue; |
63 | }; | 66 | }; |
64 | 67 | ||
68 | typedef void (*GNUNET_MESSENGER_RoomLinkDeletion) (struct GNUNET_MESSENGER_Room *room, | ||
69 | const struct GNUNET_HashCode *hash, | ||
70 | const struct GNUNET_TIME_Relative delay); | ||
71 | |||
65 | /** | 72 | /** |
66 | * Creates and allocates a new room for a <i>handle</i> with a given <i>key</i> for the client API. | 73 | * Creates and allocates a new room for a <i>handle</i> with a given <i>key</i> for the client API. |
67 | * | 74 | * |
@@ -194,4 +201,33 @@ enum GNUNET_GenericReturnValue | |||
194 | find_room_member (const struct GNUNET_MESSENGER_Room *room, | 201 | find_room_member (const struct GNUNET_MESSENGER_Room *room, |
195 | const struct GNUNET_MESSENGER_Contact *contact); | 202 | const struct GNUNET_MESSENGER_Contact *contact); |
196 | 203 | ||
204 | /** | ||
205 | * Links a message identified by its <i>hash</i> inside a given <i>room</i> with another | ||
206 | * message identified by its <i>other</i> hash. Linked messages will be deleted automatically, | ||
207 | * if any linked message to it gets deleted. | ||
208 | * | ||
209 | * @param[in,out] room Room | ||
210 | * @param[in] hash Hash of message | ||
211 | * @param[in] other Hash of other message | ||
212 | */ | ||
213 | void | ||
214 | link_room_message (struct GNUNET_MESSENGER_Room *room, | ||
215 | const struct GNUNET_HashCode *hash, | ||
216 | const struct GNUNET_HashCode *other); | ||
217 | |||
218 | /** | ||
219 | * Delete all remaining links to a certain message identified by its <i>hash</i> inside a given | ||
220 | * <i>room</i> and cause a <i>deletion</i> process to all of the linked messages. | ||
221 | * | ||
222 | * @param[in,out] room Room | ||
223 | * @param[in] hash Hash of message | ||
224 | * @param[in] delay Delay for linked deletion | ||
225 | * @param[in] deletion Function called for each linked deletion | ||
226 | */ | ||
227 | void | ||
228 | link_room_deletion (struct GNUNET_MESSENGER_Room *room, | ||
229 | const struct GNUNET_HashCode *hash, | ||
230 | const struct GNUNET_TIME_Relative delay, | ||
231 | GNUNET_MESSENGER_RoomLinkDeletion deletion); | ||
232 | |||
197 | #endif //GNUNET_MESSENGER_API_ROOM_H | 233 | #endif //GNUNET_MESSENGER_API_ROOM_H |