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/gnunet-service-messenger_operation.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/gnunet-service-messenger_operation.c')
-rw-r--r-- | src/messenger/gnunet-service-messenger_operation.c | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/src/messenger/gnunet-service-messenger_operation.c b/src/messenger/gnunet-service-messenger_operation.c new file mode 100644 index 000000000..d0c378699 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_operation.c | |||
@@ -0,0 +1,214 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
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 | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @author Tobias Frisch | ||
22 | * @file src/messenger/gnunet-service-messenger_operation.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_operation.h" | ||
27 | |||
28 | #include "gnunet-service-messenger_operation_store.h" | ||
29 | |||
30 | struct GNUNET_MESSENGER_Operation* | ||
31 | create_operation (const struct GNUNET_HashCode *hash) | ||
32 | { | ||
33 | GNUNET_assert(hash); | ||
34 | |||
35 | struct GNUNET_MESSENGER_Operation *op = GNUNET_new(struct GNUNET_MESSENGER_Operation); | ||
36 | |||
37 | op->type = GNUNET_MESSENGER_OP_UNKNOWN; | ||
38 | GNUNET_memcpy(&(op->hash), hash, sizeof(*hash)); | ||
39 | op->timestamp = GNUNET_TIME_absolute_get_zero_(); | ||
40 | op->store = NULL; | ||
41 | op->task = NULL; | ||
42 | |||
43 | return op; | ||
44 | } | ||
45 | |||
46 | void | ||
47 | destroy_operation (struct GNUNET_MESSENGER_Operation *op) | ||
48 | { | ||
49 | GNUNET_assert(op); | ||
50 | |||
51 | if (op->task) | ||
52 | GNUNET_SCHEDULER_cancel(op->task); | ||
53 | |||
54 | GNUNET_free(op); | ||
55 | } | ||
56 | |||
57 | static void | ||
58 | callback_operation (void *cls); | ||
59 | |||
60 | struct GNUNET_MESSENGER_Operation* | ||
61 | load_operation (struct GNUNET_MESSENGER_OperationStore *store, const char *path) | ||
62 | { | ||
63 | GNUNET_assert((store) && (path)); | ||
64 | |||
65 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | ||
66 | struct GNUNET_MESSENGER_Operation* op = NULL; | ||
67 | |||
68 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse(cfg, path)) | ||
69 | goto destroy_config; | ||
70 | |||
71 | struct GNUNET_HashCode hash; | ||
72 | |||
73 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "operation", "hash", &hash, sizeof(hash))) | ||
74 | goto destroy_config; | ||
75 | |||
76 | op = create_operation(&hash); | ||
77 | |||
78 | unsigned long long type_number; | ||
79 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, "operation", "type", &type_number)) | ||
80 | switch (type_number) | ||
81 | { | ||
82 | case GNUNET_MESSENGER_OP_REQUEST: | ||
83 | op->type = GNUNET_MESSENGER_OP_REQUEST; | ||
84 | break; | ||
85 | case GNUNET_MESSENGER_OP_DELETE: | ||
86 | op->type = GNUNET_MESSENGER_OP_DELETE; | ||
87 | break; | ||
88 | case GNUNET_MESSENGER_OP_MERGE: | ||
89 | op->type = GNUNET_MESSENGER_OP_MERGE; | ||
90 | break; | ||
91 | default: | ||
92 | break; | ||
93 | } | ||
94 | |||
95 | if ((GNUNET_MESSENGER_OP_UNKNOWN == op->type) || | ||
96 | (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "operation", "timestamp", &(op->timestamp), sizeof(op->timestamp)))) | ||
97 | { | ||
98 | destroy_operation(op); | ||
99 | op = NULL; | ||
100 | goto destroy_config; | ||
101 | } | ||
102 | |||
103 | const struct GNUNET_TIME_Relative delay = GNUNET_TIME_absolute_get_remaining(op->timestamp); | ||
104 | |||
105 | op->task = GNUNET_SCHEDULER_add_delayed_with_priority( | ||
106 | delay, | ||
107 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | ||
108 | callback_operation, | ||
109 | op | ||
110 | ); | ||
111 | |||
112 | op->store = store; | ||
113 | |||
114 | destroy_config: | ||
115 | GNUNET_CONFIGURATION_destroy (cfg); | ||
116 | |||
117 | return op; | ||
118 | } | ||
119 | |||
120 | void | ||
121 | save_operation (const struct GNUNET_MESSENGER_Operation *op, const char *path) | ||
122 | { | ||
123 | GNUNET_assert((path) && (op)); | ||
124 | |||
125 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | ||
126 | |||
127 | char *hash_data; | ||
128 | hash_data = GNUNET_STRINGS_data_to_string_alloc (&(op->hash), sizeof(op->hash)); | ||
129 | |||
130 | if (hash_data) | ||
131 | { | ||
132 | GNUNET_CONFIGURATION_set_value_string (cfg, "operation", "hash", hash_data); | ||
133 | |||
134 | GNUNET_free(hash_data); | ||
135 | } | ||
136 | |||
137 | GNUNET_CONFIGURATION_set_value_number(cfg, "operation", "type", op->type); | ||
138 | |||
139 | char *timestamp_data; | ||
140 | timestamp_data = GNUNET_STRINGS_data_to_string_alloc (&(op->timestamp), sizeof(op->timestamp)); | ||
141 | |||
142 | if (timestamp_data) | ||
143 | { | ||
144 | GNUNET_CONFIGURATION_set_value_string (cfg, "operation", "timestamp", timestamp_data); | ||
145 | |||
146 | GNUNET_free(timestamp_data); | ||
147 | } | ||
148 | |||
149 | GNUNET_CONFIGURATION_write (cfg, path); | ||
150 | GNUNET_CONFIGURATION_destroy (cfg); | ||
151 | } | ||
152 | |||
153 | extern void | ||
154 | callback_store_operation (struct GNUNET_MESSENGER_OperationStore *store, | ||
155 | enum GNUNET_MESSENGER_OperationType type, | ||
156 | const struct GNUNET_HashCode *hash); | ||
157 | |||
158 | static void | ||
159 | callback_operation (void *cls) | ||
160 | { | ||
161 | struct GNUNET_MESSENGER_Operation *op = cls; | ||
162 | |||
163 | op->task = NULL; | ||
164 | |||
165 | callback_store_operation (op->store, op->type, &(op->hash)); | ||
166 | } | ||
167 | |||
168 | int | ||
169 | start_operation (struct GNUNET_MESSENGER_Operation *op, | ||
170 | enum GNUNET_MESSENGER_OperationType type, | ||
171 | struct GNUNET_MESSENGER_OperationStore *store, | ||
172 | struct GNUNET_TIME_Relative delay) | ||
173 | { | ||
174 | GNUNET_assert((op) && (store)); | ||
175 | |||
176 | if (op->task) | ||
177 | return GNUNET_SYSERR; | ||
178 | |||
179 | const struct GNUNET_TIME_Absolute timestamp = GNUNET_TIME_absolute_add( | ||
180 | GNUNET_TIME_absolute_get(), | ||
181 | delay | ||
182 | ); | ||
183 | |||
184 | op->task = GNUNET_SCHEDULER_add_delayed_with_priority( | ||
185 | delay, | ||
186 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | ||
187 | callback_operation, | ||
188 | op | ||
189 | ); | ||
190 | |||
191 | op->type = type; | ||
192 | op->timestamp = timestamp; | ||
193 | op->store = store; | ||
194 | |||
195 | return GNUNET_OK; | ||
196 | } | ||
197 | |||
198 | int | ||
199 | stop_operation (struct GNUNET_MESSENGER_Operation *op) | ||
200 | { | ||
201 | GNUNET_assert(op); | ||
202 | |||
203 | if (!op->task) | ||
204 | return GNUNET_SYSERR; | ||
205 | |||
206 | GNUNET_SCHEDULER_cancel(op->task); | ||
207 | op->task = NULL; | ||
208 | |||
209 | op->type = GNUNET_MESSENGER_OP_UNKNOWN; | ||
210 | op->timestamp = GNUNET_TIME_absolute_get_zero_(); | ||
211 | op->store = NULL; | ||
212 | |||
213 | return GNUNET_OK; | ||
214 | } | ||