diff options
Diffstat (limited to 'src/messenger/gnunet-service-messenger_room.h')
-rw-r--r-- | src/messenger/gnunet-service-messenger_room.h | 380 |
1 files changed, 0 insertions, 380 deletions
diff --git a/src/messenger/gnunet-service-messenger_room.h b/src/messenger/gnunet-service-messenger_room.h deleted file mode 100644 index a6ae45275..000000000 --- a/src/messenger/gnunet-service-messenger_room.h +++ /dev/null | |||
@@ -1,380 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020--2022 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_room.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_ROOM_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_ROOM_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_cadet_service.h" | ||
31 | #include "gnunet_container_lib.h" | ||
32 | #include "gnunet_crypto_lib.h" | ||
33 | #include "gnunet_identity_service.h" | ||
34 | #include "gnunet_mq_lib.h" | ||
35 | |||
36 | #include "gnunet_messenger_service.h" | ||
37 | #include "gnunet-service-messenger_basement.h" | ||
38 | #include "gnunet-service-messenger_handle.h" | ||
39 | #include "gnunet-service-messenger_message_state.h" | ||
40 | #include "gnunet-service-messenger_list_messages.h" | ||
41 | |||
42 | #include "messenger_api_list_tunnels.h" | ||
43 | |||
44 | #include "gnunet-service-messenger_member_store.h" | ||
45 | #include "gnunet-service-messenger_message_store.h" | ||
46 | #include "gnunet-service-messenger_operation_store.h" | ||
47 | #include "messenger_api_ego.h" | ||
48 | |||
49 | #define GNUNET_MESSENGER_IDLE_DELAY GNUNET_TIME_relative_multiply \ | ||
50 | (GNUNET_TIME_relative_get_second_ (), 5) | ||
51 | |||
52 | #define GNUNET_MESSENGER_REQUEST_DELAY GNUNET_TIME_relative_multiply \ | ||
53 | (GNUNET_TIME_relative_get_minute_ (), 5) | ||
54 | |||
55 | #define GNUNET_MESSENGER_MERGE_DELAY GNUNET_TIME_relative_multiply \ | ||
56 | (GNUNET_TIME_relative_get_second_ (), 30) | ||
57 | |||
58 | struct GNUNET_MESSENGER_SrvTunnel; | ||
59 | struct GNUNET_MESSENGER_MemberSession; | ||
60 | |||
61 | struct GNUNET_MESSENGER_SrvRoom | ||
62 | { | ||
63 | struct GNUNET_MESSENGER_Service *service; | ||
64 | struct GNUNET_MESSENGER_SrvHandle *host; | ||
65 | struct GNUNET_CADET_Port *port; | ||
66 | |||
67 | struct GNUNET_HashCode key; | ||
68 | |||
69 | struct GNUNET_CONTAINER_MultiPeerMap *tunnels; | ||
70 | |||
71 | struct GNUNET_MESSENGER_MemberStore member_store; | ||
72 | struct GNUNET_MESSENGER_MessageStore message_store; | ||
73 | struct GNUNET_MESSENGER_OperationStore operation_store; | ||
74 | |||
75 | struct GNUNET_MESSENGER_ListTunnels basement; | ||
76 | struct GNUNET_MESSENGER_MessageState state; | ||
77 | |||
78 | struct GNUNET_HashCode *peer_message; | ||
79 | |||
80 | struct GNUNET_MESSENGER_ListMessages handling; | ||
81 | struct GNUNET_SCHEDULER_Task *idle; | ||
82 | }; | ||
83 | |||
84 | /** | ||
85 | * Creates and allocates a new room for a <i>handle</i> with a given <i>key</i>. | ||
86 | * | ||
87 | * @param[in/out] handle Handle | ||
88 | * @param[in] key Key of room | ||
89 | * @return New room | ||
90 | */ | ||
91 | struct GNUNET_MESSENGER_SrvRoom* | ||
92 | create_srv_room (struct GNUNET_MESSENGER_SrvHandle *handle, | ||
93 | const struct GNUNET_HashCode *key); | ||
94 | |||
95 | /** | ||
96 | * Destroys a room and frees its memory fully. | ||
97 | * | ||
98 | * The <i>deletion</i> flag should only be set to #GNUNET_YES if the | ||
99 | * room gets dropped by the service, otherwise #GNUNET_NO. | ||
100 | * | ||
101 | * @param[in/out] room Room | ||
102 | * @param[in] deletion Flag to indicate context of destruction | ||
103 | */ | ||
104 | void | ||
105 | destroy_srv_room (struct GNUNET_MESSENGER_SrvRoom *room, | ||
106 | int deletion); | ||
107 | |||
108 | /** | ||
109 | * Returns the used member store of a given <i>room</i>. | ||
110 | * | ||
111 | * @param[in/out] room Room | ||
112 | * @return Member store | ||
113 | */ | ||
114 | struct GNUNET_MESSENGER_MemberStore* | ||
115 | get_srv_room_member_store (struct GNUNET_MESSENGER_SrvRoom *room); | ||
116 | |||
117 | /** | ||
118 | * Returns the used message store of a given <i>room</i>. | ||
119 | * | ||
120 | * @param[in/out] room Room | ||
121 | * @return Message store | ||
122 | */ | ||
123 | struct GNUNET_MESSENGER_MessageStore* | ||
124 | get_srv_room_message_store (struct GNUNET_MESSENGER_SrvRoom *room); | ||
125 | |||
126 | /** | ||
127 | * Returns the used operation store of a given <i>room</i>. | ||
128 | * | ||
129 | * @param[in/out] room Room | ||
130 | * @return Operation store | ||
131 | */ | ||
132 | struct GNUNET_MESSENGER_OperationStore* | ||
133 | get_srv_room_operation_store (struct GNUNET_MESSENGER_SrvRoom *room); | ||
134 | |||
135 | /** | ||
136 | * Tries to open a <i>room</i> for a given <i>handle</i>. If the room has already been opened, the handle | ||
137 | * will locally join the room. | ||
138 | * | ||
139 | * Calling this method should result in joining a room and sending a peer message as well for this peer. | ||
140 | * | ||
141 | * If the function returns #GNUNET_YES the port for this room is guaranteed to be open for incoming connections. | ||
142 | * | ||
143 | * @param[in/out] room Room | ||
144 | * @param[in/out] handle Handle | ||
145 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. | ||
146 | */ | ||
147 | int | ||
148 | open_srv_room (struct GNUNET_MESSENGER_SrvRoom *room, | ||
149 | struct GNUNET_MESSENGER_SrvHandle *handle); | ||
150 | |||
151 | /** | ||
152 | * Connects a tunnel to a hosting peer of a <i>room</i> through a so called <i>door</i> which is represented by | ||
153 | * a peer identity of a hosting peer. During the connection the handle will join the room as a member, waiting for | ||
154 | * an info message from the selected host. | ||
155 | * | ||
156 | * @param[in/out] room Room | ||
157 | * @param[in/out] handle Handle | ||
158 | * @param[in] door Peer identity | ||
159 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. | ||
160 | */ | ||
161 | int | ||
162 | enter_srv_room_at (struct GNUNET_MESSENGER_SrvRoom *room, | ||
163 | struct GNUNET_MESSENGER_SrvHandle *handle, | ||
164 | const struct GNUNET_PeerIdentity *door); | ||
165 | |||
166 | /** | ||
167 | * Packs a <i>message</i> depending on the selected <i>mode</i> into a newly allocated envelope. It will set the | ||
168 | * timestamp of the message, the sender id and the previous messages hash automatically before packing. The message | ||
169 | * will be signed by the handles EGO. | ||
170 | * | ||
171 | * If the optional <i>hash</i> parameter is a valid pointer, its value will be overridden by the signed messages hash. | ||
172 | * | ||
173 | * If <i>mode</i> is set to #GNUNET_MESSENGER_PACK_MODE_ENVELOPE, the function returns a valid envelope to send | ||
174 | * through a message queue, otherwise NULL. | ||
175 | * | ||
176 | * @param[in] room Room | ||
177 | * @param[in] handle Handle | ||
178 | * @param[in/out] message Message | ||
179 | * @param[out] hash Hash of message | ||
180 | * @param[in] mode Packing mode | ||
181 | * @return New envelope or NULL | ||
182 | */ | ||
183 | struct GNUNET_MQ_Envelope* | ||
184 | pack_srv_room_message (const struct GNUNET_MESSENGER_SrvRoom *room, | ||
185 | const struct GNUNET_MESSENGER_SrvHandle *handle, | ||
186 | struct GNUNET_MESSENGER_Message *message, | ||
187 | struct GNUNET_HashCode *hash, | ||
188 | int mode); | ||
189 | |||
190 | /** | ||
191 | * Sends a <i>message</i> from a given <i>handle</i> into a <i>room</i>. The <i>hash</i> parameter will be | ||
192 | * updated with the hash-value resulting from the sent message. | ||
193 | * | ||
194 | * The function handles packing the message automatically and will call linked message-events locally even if | ||
195 | * the message won't be sent to another peer. | ||
196 | * | ||
197 | * The function returns #GNUNET_YES on success, #GNUNET_NO if message is null and | ||
198 | * #GNUNET_SYSERR if the message was known already. | ||
199 | * | ||
200 | * @param[in/out] room Room | ||
201 | * @param[in/out] handle Handle | ||
202 | * @param[in/out] message Message | ||
203 | * @return #GNUNET_YES on success, #GNUNET_NO or #GNUNET_SYSERR otherwise. | ||
204 | */ | ||
205 | int | ||
206 | send_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | ||
207 | struct GNUNET_MESSENGER_SrvHandle *handle, | ||
208 | struct GNUNET_MESSENGER_Message *message); | ||
209 | |||
210 | /** | ||
211 | * Forwards a <i>message</i> with a given <i>hash</i> to a specific <i>tunnel</i> inside of a <i>room</i>. | ||
212 | * | ||
213 | * @param[in/out] room Room | ||
214 | * @param[in/out] tunnel Tunnel | ||
215 | * @param[in/out] message Message | ||
216 | * @param[in] hash Hash of message | ||
217 | */ | ||
218 | void | ||
219 | forward_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | ||
220 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
221 | struct GNUNET_MESSENGER_Message *message, | ||
222 | const struct GNUNET_HashCode *hash); | ||
223 | |||
224 | /** | ||
225 | * Checks the current state of opening a given <i>room</i> from this peer and re-publishes it | ||
226 | * if necessary to a selected <i>tunnel</i> or to all connected tunnels if necessary or if the | ||
227 | * selected tunnel is NULL. | ||
228 | * | ||
229 | * @param[in/out] room Room | ||
230 | * @param[in/out] tunnel Tunnel | ||
231 | */ | ||
232 | void | ||
233 | check_srv_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, | ||
234 | struct GNUNET_MESSENGER_SrvTunnel *tunnel); | ||
235 | |||
236 | /** | ||
237 | * Reduces all current forks inside of the message history of a <i>room</i> to one remaining last message | ||
238 | * by merging them down. All merge messages will be sent from a given <i>handle</i>. | ||
239 | * | ||
240 | * @param[in/out] room Room | ||
241 | * @param[in/out] handle Handle | ||
242 | */ | ||
243 | void | ||
244 | merge_srv_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, | ||
245 | struct GNUNET_MESSENGER_SrvHandle *handle); | ||
246 | |||
247 | /** | ||
248 | * Deletes a message from the <i>room</i> with a given <i>hash</i> in a specific <i>delay</i> if | ||
249 | * the provided member by its session is permitted to do so. | ||
250 | * | ||
251 | * @param[in/out] room Room | ||
252 | * @param[in/out] session Member session | ||
253 | * @param[in] hash Hash of message | ||
254 | * @param[in] delay Delay of deletion | ||
255 | * @return #GNUNET_YES on success, #GNUNET_NO if permission gets denied, #GNUNET_SYSERR on operation failure | ||
256 | */ | ||
257 | int | ||
258 | delete_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | ||
259 | struct GNUNET_MESSENGER_MemberSession *session, | ||
260 | const struct GNUNET_HashCode *hash, | ||
261 | const struct GNUNET_TIME_Relative delay); | ||
262 | |||
263 | /** | ||
264 | * Returns the CADET handle from a rooms service. | ||
265 | * | ||
266 | * @param[in/out] room Room | ||
267 | * @return CADET handle | ||
268 | */ | ||
269 | struct GNUNET_CADET_Handle* | ||
270 | get_srv_room_cadet (struct GNUNET_MESSENGER_SrvRoom *room); | ||
271 | |||
272 | /** | ||
273 | * Returns the shared secret you need to access a <i>room</i>. | ||
274 | * | ||
275 | * @param[in] room Room | ||
276 | * @return Shared secret | ||
277 | */ | ||
278 | const struct GNUNET_HashCode* | ||
279 | get_srv_room_key (const struct GNUNET_MESSENGER_SrvRoom *room); | ||
280 | |||
281 | /** | ||
282 | * Returns a tunnel inside of a <i>room</i> leading towards a given <i>peer</i> if such a tunnel exists, | ||
283 | * otherwise NULL. | ||
284 | * | ||
285 | * @param[in] room Room | ||
286 | * @param[in] peer Peer identity | ||
287 | * @return Tunnel or NULL | ||
288 | */ | ||
289 | const struct GNUNET_MESSENGER_SrvTunnel* | ||
290 | get_srv_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, | ||
291 | const struct GNUNET_PeerIdentity *peer); | ||
292 | |||
293 | /** | ||
294 | * Method called whenever a <i>message</i> is found during a request in a <i>room</i>. | ||
295 | * | ||
296 | * @param[in/out] cls Closure from #request_room_message | ||
297 | * @param[in/out] room Room | ||
298 | * @param[in] message Message or NULL | ||
299 | * @param[in] hash Hash of message | ||
300 | */ | ||
301 | typedef void (GNUNET_MESSENGER_MessageRequestCallback) ( | ||
302 | void *cls, | ||
303 | struct GNUNET_MESSENGER_SrvRoom *room, | ||
304 | const struct GNUNET_MESSENGER_Message *message, | ||
305 | const struct GNUNET_HashCode *hash | ||
306 | ); | ||
307 | |||
308 | /** | ||
309 | * Requests a message from a <i>room</i> identified by a given <i>hash</i>. If the message is found, | ||
310 | * the selected <i>callback</i> will be called with it and the provided closure. If no matching message | ||
311 | * is found but it wasn't deleted the selected callback will be called with #NULL as message instead. | ||
312 | * In case of deletion the next available previous message will be used to call the callback. | ||
313 | * | ||
314 | * It is also possible that the given callback will not be called if the requesting session is not | ||
315 | * permitted! | ||
316 | * | ||
317 | * @param[in/out] room Room | ||
318 | * @param[in] hash Hash of message | ||
319 | * @param[in] callback Callback to process result | ||
320 | * @param[in] cls Closure for the <i>callback</i> | ||
321 | * @return #GNUNET_YES if the request could be processed, otherwise #GNUNET_NO | ||
322 | */ | ||
323 | int | ||
324 | request_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | ||
325 | const struct GNUNET_HashCode *hash, | ||
326 | const struct GNUNET_MESSENGER_MemberSession *session, | ||
327 | GNUNET_MESSENGER_MessageRequestCallback callback, | ||
328 | void* cls); | ||
329 | |||
330 | /** | ||
331 | * Checks for potential collisions with member ids and solves them changing active handles ids if they | ||
332 | * use an already used member id (comparing public key and timestamp). | ||
333 | * | ||
334 | * @param[in/out] room Room | ||
335 | * @param[in] public_key Public key of EGO | ||
336 | * @param[in] member_id Member ID | ||
337 | * @param[in] timestamp Timestamp | ||
338 | */ | ||
339 | void | ||
340 | solve_srv_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room, | ||
341 | const struct GNUNET_IDENTITY_PublicKey *public_key, | ||
342 | const struct GNUNET_ShortHashCode *member_id, | ||
343 | struct GNUNET_TIME_Absolute timestamp); | ||
344 | |||
345 | /** | ||
346 | * Rebuilds the decentralized structure for a <i>room</i> by ensuring all required connections are made | ||
347 | * depending on the amount of peers and this peers index in the list of them. | ||
348 | * | ||
349 | * @param[in/out] room Room | ||
350 | */ | ||
351 | void | ||
352 | rebuild_srv_room_basement_structure (struct GNUNET_MESSENGER_SrvRoom *room); | ||
353 | |||
354 | /** | ||
355 | * Loads the local configuration for a given <i>room</i> of a service which contains the last messages hash | ||
356 | * and the ruleset for general access of new members. | ||
357 | * | ||
358 | * @param[out] room Room | ||
359 | */ | ||
360 | void | ||
361 | load_srv_room (struct GNUNET_MESSENGER_SrvRoom *room); | ||
362 | |||
363 | /** | ||
364 | * Saves the configuration for a given <i>room</i> of a service which contains the last messages hash | ||
365 | * and the ruleset for general access of new members locally. | ||
366 | * | ||
367 | * @param[in] room Room | ||
368 | */ | ||
369 | void | ||
370 | save_srv_room (struct GNUNET_MESSENGER_SrvRoom *room); | ||
371 | |||
372 | /** | ||
373 | * Removes the configuration for a given <i>room</i> of a service. | ||
374 | * | ||
375 | * @param[in] room Room | ||
376 | */ | ||
377 | void | ||
378 | remove_srv_room (struct GNUNET_MESSENGER_SrvRoom *room); | ||
379 | |||
380 | #endif //GNUNET_SERVICE_MESSENGER_ROOM_H | ||