diff options
author | Jacki <jacki@thejackimonster.de> | 2024-02-10 05:06:43 +0100 |
---|---|---|
committer | Jacki <jacki@thejackimonster.de> | 2024-02-10 05:06:43 +0100 |
commit | ff5b51e8b00440dcf7ee252451947ce0622fd9c1 (patch) | |
tree | 208ada9766122094850b02dca9f79c8f324618cb /src | |
parent | 8842c8b412921fe9318d2caf0a418257b72cf31d (diff) | |
download | libgnunetchat-ff5b51e8b00440dcf7ee252451947ce0622fd9c1.tar.gz libgnunetchat-ff5b51e8b00440dcf7ee252451947ce0622fd9c1.zip |
Add dependencies for messages to handle reverse order from requests
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/gnunet_chat_context.c | 70 | ||||
-rw-r--r-- | src/gnunet_chat_context.h | 1 | ||||
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 75 |
3 files changed, 102 insertions, 44 deletions
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c index ea188e7..128fe8b 100644 --- a/src/gnunet_chat_context.c +++ b/src/gnunet_chat_context.c | |||
@@ -32,39 +32,50 @@ | |||
32 | static const unsigned int initial_map_size_of_room = 8; | 32 | static const unsigned int initial_map_size_of_room = 8; |
33 | static const unsigned int initial_map_size_of_contact = 4; | 33 | static const unsigned int initial_map_size_of_contact = 4; |
34 | 34 | ||
35 | struct GNUNET_CHAT_Context* | 35 | static void |
36 | context_create_from_room (struct GNUNET_CHAT_Handle *handle, | 36 | init_new_context (struct GNUNET_CHAT_Context *context, |
37 | struct GNUNET_MESSENGER_Room *room) | 37 | unsigned int initial_map_size) |
38 | { | 38 | { |
39 | GNUNET_assert((handle) && (room)); | 39 | GNUNET_assert(context); |
40 | |||
41 | struct GNUNET_CHAT_Context* context = GNUNET_new(struct GNUNET_CHAT_Context); | ||
42 | |||
43 | context->handle = handle; | ||
44 | 40 | ||
45 | context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; | ||
46 | context->nick[0] = '\0'; | 41 | context->nick[0] = '\0'; |
47 | context->topic = NULL; | 42 | context->topic = NULL; |
48 | context->deleted = GNUNET_NO; | 43 | context->deleted = GNUNET_NO; |
49 | 44 | ||
50 | context->timestamps = GNUNET_CONTAINER_multishortmap_create( | 45 | context->timestamps = GNUNET_CONTAINER_multishortmap_create( |
51 | initial_map_size_of_room, GNUNET_NO); | 46 | initial_map_size, GNUNET_NO); |
47 | context->dependencies = GNUNET_CONTAINER_multihashmap_create( | ||
48 | initial_map_size, GNUNET_NO); | ||
52 | context->messages = GNUNET_CONTAINER_multihashmap_create( | 49 | context->messages = GNUNET_CONTAINER_multihashmap_create( |
53 | initial_map_size_of_room, GNUNET_NO); | 50 | initial_map_size, GNUNET_NO); |
54 | context->invites = GNUNET_CONTAINER_multihashmap_create( | 51 | context->invites = GNUNET_CONTAINER_multihashmap_create( |
55 | initial_map_size_of_room, GNUNET_NO); | 52 | initial_map_size, GNUNET_NO); |
56 | context->files = GNUNET_CONTAINER_multihashmap_create( | 53 | context->files = GNUNET_CONTAINER_multihashmap_create( |
57 | initial_map_size_of_room, GNUNET_NO); | 54 | initial_map_size, GNUNET_NO); |
58 | 55 | ||
59 | context->room = room; | ||
60 | context->contact = NULL; | ||
61 | |||
62 | context->user_pointer = NULL; | 56 | context->user_pointer = NULL; |
63 | 57 | ||
64 | context->member_pointers = GNUNET_CONTAINER_multishortmap_create( | 58 | context->member_pointers = GNUNET_CONTAINER_multishortmap_create( |
65 | initial_map_size_of_room, GNUNET_NO); | 59 | initial_map_size, GNUNET_NO); |
66 | 60 | ||
67 | context->query = NULL; | 61 | context->query = NULL; |
62 | } | ||
63 | |||
64 | struct GNUNET_CHAT_Context* | ||
65 | context_create_from_room (struct GNUNET_CHAT_Handle *handle, | ||
66 | struct GNUNET_MESSENGER_Room *room) | ||
67 | { | ||
68 | GNUNET_assert((handle) && (room)); | ||
69 | |||
70 | struct GNUNET_CHAT_Context* context = GNUNET_new(struct GNUNET_CHAT_Context); | ||
71 | |||
72 | context->handle = handle; | ||
73 | context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; | ||
74 | |||
75 | init_new_context(context, initial_map_size_of_room); | ||
76 | |||
77 | context->room = room; | ||
78 | context->contact = NULL; | ||
68 | 79 | ||
69 | return context; | 80 | return context; |
70 | } | 81 | } |
@@ -78,31 +89,13 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle, | |||
78 | struct GNUNET_CHAT_Context* context = GNUNET_new(struct GNUNET_CHAT_Context); | 89 | struct GNUNET_CHAT_Context* context = GNUNET_new(struct GNUNET_CHAT_Context); |
79 | 90 | ||
80 | context->handle = handle; | 91 | context->handle = handle; |
81 | |||
82 | context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; | 92 | context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; |
83 | context->nick[0] = '\0'; | ||
84 | context->topic = NULL; | ||
85 | context->deleted = GNUNET_NO; | ||
86 | 93 | ||
87 | context->timestamps = GNUNET_CONTAINER_multishortmap_create( | 94 | init_new_context(context, initial_map_size_of_contact); |
88 | initial_map_size_of_contact, GNUNET_NO); | ||
89 | context->messages = GNUNET_CONTAINER_multihashmap_create( | ||
90 | initial_map_size_of_contact, GNUNET_NO); | ||
91 | context->invites = GNUNET_CONTAINER_multihashmap_create( | ||
92 | initial_map_size_of_contact, GNUNET_NO); | ||
93 | context->files = GNUNET_CONTAINER_multihashmap_create( | ||
94 | initial_map_size_of_contact, GNUNET_NO); | ||
95 | 95 | ||
96 | context->room = NULL; | 96 | context->room = NULL; |
97 | context->contact = contact; | 97 | context->contact = contact; |
98 | 98 | ||
99 | context->user_pointer = NULL; | ||
100 | |||
101 | context->member_pointers = GNUNET_CONTAINER_multishortmap_create( | ||
102 | initial_map_size_of_contact, GNUNET_NO); | ||
103 | |||
104 | context->query = NULL; | ||
105 | |||
106 | return context; | 99 | return context; |
107 | } | 100 | } |
108 | 101 | ||
@@ -112,6 +105,7 @@ context_destroy (struct GNUNET_CHAT_Context *context) | |||
112 | GNUNET_assert( | 105 | GNUNET_assert( |
113 | (context) && | 106 | (context) && |
114 | (context->timestamps) && | 107 | (context->timestamps) && |
108 | (context->dependencies) && | ||
115 | (context->messages) && | 109 | (context->messages) && |
116 | (context->invites) && | 110 | (context->invites) && |
117 | (context->files) | 111 | (context->files) |
@@ -124,6 +118,7 @@ context_destroy (struct GNUNET_CHAT_Context *context) | |||
124 | context->timestamps, it_destroy_context_timestamps, NULL | 118 | context->timestamps, it_destroy_context_timestamps, NULL |
125 | ); | 119 | ); |
126 | 120 | ||
121 | GNUNET_CONTAINER_multihashmap_clear(context->dependencies); | ||
127 | GNUNET_CONTAINER_multihashmap_iterate( | 122 | GNUNET_CONTAINER_multihashmap_iterate( |
128 | context->messages, it_destroy_context_messages, NULL | 123 | context->messages, it_destroy_context_messages, NULL |
129 | ); | 124 | ); |
@@ -135,6 +130,7 @@ context_destroy (struct GNUNET_CHAT_Context *context) | |||
135 | GNUNET_CONTAINER_multishortmap_destroy(context->member_pointers); | 130 | GNUNET_CONTAINER_multishortmap_destroy(context->member_pointers); |
136 | 131 | ||
137 | GNUNET_CONTAINER_multishortmap_destroy(context->timestamps); | 132 | GNUNET_CONTAINER_multishortmap_destroy(context->timestamps); |
133 | GNUNET_CONTAINER_multihashmap_destroy(context->dependencies); | ||
138 | GNUNET_CONTAINER_multihashmap_destroy(context->messages); | 134 | GNUNET_CONTAINER_multihashmap_destroy(context->messages); |
139 | GNUNET_CONTAINER_multihashmap_destroy(context->invites); | 135 | GNUNET_CONTAINER_multihashmap_destroy(context->invites); |
140 | GNUNET_CONTAINER_multihashmap_destroy(context->files); | 136 | GNUNET_CONTAINER_multihashmap_destroy(context->files); |
diff --git a/src/gnunet_chat_context.h b/src/gnunet_chat_context.h index f0532d2..8ba05d5 100644 --- a/src/gnunet_chat_context.h +++ b/src/gnunet_chat_context.h | |||
@@ -43,6 +43,7 @@ struct GNUNET_CHAT_Context | |||
43 | int deleted; | 43 | int deleted; |
44 | 44 | ||
45 | struct GNUNET_CONTAINER_MultiShortmap *timestamps; | 45 | struct GNUNET_CONTAINER_MultiShortmap *timestamps; |
46 | struct GNUNET_CONTAINER_MultiHashMap *dependencies; | ||
46 | struct GNUNET_CONTAINER_MultiHashMap *messages; | 47 | struct GNUNET_CONTAINER_MultiHashMap *messages; |
47 | struct GNUNET_CONTAINER_MultiHashMap *invites; | 48 | struct GNUNET_CONTAINER_MultiHashMap *invites; |
48 | struct GNUNET_CONTAINER_MultiHashMap *files; | 49 | struct GNUNET_CONTAINER_MultiHashMap *files; |
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index 5be65af..91e5953 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <gnunet/gnunet_identity_service.h> | 36 | #include <gnunet/gnunet_identity_service.h> |
37 | #include <gnunet/gnunet_messenger_service.h> | 37 | #include <gnunet/gnunet_messenger_service.h> |
38 | #include <gnunet/gnunet_reclaim_service.h> | 38 | #include <gnunet/gnunet_reclaim_service.h> |
39 | #include <gnunet/gnunet_scheduler_lib.h> | ||
39 | #include <gnunet/gnunet_util_lib.h> | 40 | #include <gnunet/gnunet_util_lib.h> |
40 | #include <stdio.h> | 41 | #include <stdio.h> |
41 | #include <string.h> | 42 | #include <string.h> |
@@ -748,6 +749,23 @@ on_monitor_namestore_record(void *cls, | |||
748 | } | 749 | } |
749 | 750 | ||
750 | void | 751 | void |
752 | on_handle_message_callback(void *cls); | ||
753 | |||
754 | static enum GNUNET_GenericReturnValue | ||
755 | it_context_iterate_dependencies(void *cls, | ||
756 | const struct GNUNET_HashCode *key, | ||
757 | void *value) | ||
758 | { | ||
759 | struct GNUNET_CHAT_Message *message = (struct GNUNET_CHAT_Message*) value; | ||
760 | |||
761 | if ((message) && (!message->task)) | ||
762 | message->task = GNUNET_SCHEDULER_add_now( | ||
763 | on_handle_message_callback, message); | ||
764 | |||
765 | return GNUNET_YES; | ||
766 | } | ||
767 | |||
768 | void | ||
751 | on_handle_message_callback(void *cls) | 769 | on_handle_message_callback(void *cls) |
752 | { | 770 | { |
753 | struct GNUNET_CHAT_Message *message = (struct GNUNET_CHAT_Message*) cls; | 771 | struct GNUNET_CHAT_Message *message = (struct GNUNET_CHAT_Message*) cls; |
@@ -765,13 +783,13 @@ on_handle_message_callback(void *cls) | |||
765 | struct GNUNET_CHAT_Handle *handle = context->handle; | 783 | struct GNUNET_CHAT_Handle *handle = context->handle; |
766 | 784 | ||
767 | if (!(handle->msg_cb)) | 785 | if (!(handle->msg_cb)) |
768 | return; | 786 | goto clear_dependencies; |
769 | 787 | ||
770 | const struct GNUNET_MESSENGER_Contact *sender; | 788 | const struct GNUNET_MESSENGER_Contact *sender; |
771 | sender = GNUNET_MESSENGER_get_sender(context->room, &(message->hash)); | 789 | sender = GNUNET_MESSENGER_get_sender(context->room, &(message->hash)); |
772 | 790 | ||
773 | if (!sender) | 791 | if (!sender) |
774 | return; | 792 | goto clear_dependencies; |
775 | 793 | ||
776 | struct GNUNET_ShortHashCode shorthash; | 794 | struct GNUNET_ShortHashCode shorthash; |
777 | util_shorthash_from_member(sender, &shorthash); | 795 | util_shorthash_from_member(sender, &shorthash); |
@@ -781,9 +799,17 @@ on_handle_message_callback(void *cls) | |||
781 | ); | 799 | ); |
782 | 800 | ||
783 | if ((!contact) || (GNUNET_YES == contact->blocked)) | 801 | if ((!contact) || (GNUNET_YES == contact->blocked)) |
784 | return; | 802 | goto clear_dependencies; |
785 | 803 | ||
786 | handle->msg_cb(handle->msg_cls, context, message); | 804 | handle->msg_cb(handle->msg_cls, context, message); |
805 | |||
806 | clear_dependencies: | ||
807 | GNUNET_CONTAINER_multihashmap_get_multiple(context->dependencies, | ||
808 | &(message->hash), | ||
809 | it_context_iterate_dependencies, | ||
810 | NULL); | ||
811 | GNUNET_CONTAINER_multihashmap_remove_all(context->dependencies, | ||
812 | &(message->hash)); | ||
787 | } | 813 | } |
788 | 814 | ||
789 | void | 815 | void |
@@ -859,6 +885,9 @@ on_handle_message (void *cls, | |||
859 | *time = timestamp; | 885 | *time = timestamp; |
860 | } | 886 | } |
861 | 887 | ||
888 | struct GNUNET_SCHEDULER_Task *task = NULL; | ||
889 | const struct GNUNET_HashCode *dependency = NULL; | ||
890 | |||
862 | struct GNUNET_CHAT_Message *message = GNUNET_CONTAINER_multihashmap_get( | 891 | struct GNUNET_CHAT_Message *message = GNUNET_CONTAINER_multihashmap_get( |
863 | context->messages, hash | 892 | context->messages, hash |
864 | ); | 893 | ); |
@@ -883,7 +912,6 @@ on_handle_message (void *cls, | |||
883 | return; | 912 | return; |
884 | } | 913 | } |
885 | 914 | ||
886 | struct GNUNET_SCHEDULER_Task* task = NULL; | ||
887 | message = message_create_from_msg(context, hash, flags, msg); | 915 | message = message_create_from_msg(context, hash, flags, msg); |
888 | 916 | ||
889 | switch (msg->header.kind) | 917 | switch (msg->header.kind) |
@@ -1002,10 +1030,43 @@ on_handle_message (void *cls, | |||
1002 | } | 1030 | } |
1003 | 1031 | ||
1004 | handle_callback: | 1032 | handle_callback: |
1005 | if (!task) | 1033 | switch (msg->header.kind) |
1034 | { | ||
1035 | case GNUNET_MESSENGER_KIND_DELETE: | ||
1036 | { | ||
1037 | dependency = &(msg->body.deletion.hash); | ||
1038 | break; | ||
1039 | } | ||
1040 | case GNUNET_MESSENGER_KIND_TRANSCRIPT: | ||
1041 | { | ||
1042 | dependency = &(msg->body.transcript.hash); | ||
1043 | break; | ||
1044 | } | ||
1045 | case GNUNET_MESSENGER_KIND_TAG: | ||
1046 | { | ||
1047 | dependency = &(msg->body.tag.hash); | ||
1048 | break; | ||
1049 | } | ||
1050 | default: | ||
1051 | break; | ||
1052 | } | ||
1053 | |||
1054 | if ((dependency) && | ||
1055 | (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains(context->messages, dependency))) | ||
1056 | { | ||
1057 | GNUNET_CONTAINER_multihashmap_put( | ||
1058 | context->dependencies, | ||
1059 | dependency, | ||
1060 | message, | ||
1061 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE | ||
1062 | ); | ||
1063 | |||
1064 | GNUNET_MESSENGER_get_message(room, dependency); | ||
1065 | } | ||
1066 | else if (!task) | ||
1006 | on_handle_message_callback(message); | 1067 | on_handle_message_callback(message); |
1007 | else | 1068 | |
1008 | message->task = task; | 1069 | message->task = task; |
1009 | } | 1070 | } |
1010 | 1071 | ||
1011 | int | 1072 | int |