diff options
Diffstat (limited to 'src/messenger/gnunet-service-messenger_room.h')
-rw-r--r-- | src/messenger/gnunet-service-messenger_room.h | 367 |
1 files changed, 0 insertions, 367 deletions
diff --git a/src/messenger/gnunet-service-messenger_room.h b/src/messenger/gnunet-service-messenger_room.h deleted file mode 100644 index 4b3811104..000000000 --- a/src/messenger/gnunet-service-messenger_room.h +++ /dev/null | |||
@@ -1,367 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020--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_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_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 | * @param[in/out] room Room | ||
99 | */ | ||
100 | void | ||
101 | destroy_room (struct GNUNET_MESSENGER_SrvRoom *room); | ||
102 | |||
103 | /** | ||
104 | * Returns the used member store of a given <i>room</i>. | ||
105 | * | ||
106 | * @param[in/out] room Room | ||
107 | * @return Member store | ||
108 | */ | ||
109 | struct GNUNET_MESSENGER_MemberStore* | ||
110 | get_room_member_store (struct GNUNET_MESSENGER_SrvRoom *room); | ||
111 | |||
112 | /** | ||
113 | * Returns the used message store of a given <i>room</i>. | ||
114 | * | ||
115 | * @param[in/out] room Room | ||
116 | * @return Message store | ||
117 | */ | ||
118 | struct GNUNET_MESSENGER_MessageStore* | ||
119 | get_room_message_store (struct GNUNET_MESSENGER_SrvRoom *room); | ||
120 | |||
121 | /** | ||
122 | * Returns the used operation store of a given <i>room</i>. | ||
123 | * | ||
124 | * @param[in/out] room Room | ||
125 | * @return Operation store | ||
126 | */ | ||
127 | struct GNUNET_MESSENGER_OperationStore* | ||
128 | get_room_operation_store (struct GNUNET_MESSENGER_SrvRoom *room); | ||
129 | |||
130 | /** | ||
131 | * Tries to open a <i>room</i> for a given <i>handle</i>. If the room has already been opened, the handle | ||
132 | * will locally join the room. | ||
133 | * | ||
134 | * Calling this method should result in joining a room and sending a peer message as well for this peer. | ||
135 | * | ||
136 | * If the function returns #GNUNET_YES the port for this room is guaranteed to be open for incoming connections. | ||
137 | * | ||
138 | * @param[in/out] room Room | ||
139 | * @param[in/out] handle Handle | ||
140 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. | ||
141 | */ | ||
142 | int | ||
143 | open_room (struct GNUNET_MESSENGER_SrvRoom *room, | ||
144 | struct GNUNET_MESSENGER_SrvHandle *handle); | ||
145 | |||
146 | /** | ||
147 | * Connects a tunnel to a hosting peer of a <i>room</i> through a so called <i>door</i> which is represented by | ||
148 | * a peer identity of a hosting peer. During the connection the handle will join the room as a member, waiting for | ||
149 | * an info message from the selected host. | ||
150 | * | ||
151 | * @param[in/out] room Room | ||
152 | * @param[in/out] handle Handle | ||
153 | * @param[in] door Peer identity | ||
154 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. | ||
155 | */ | ||
156 | int | ||
157 | enter_room_at (struct GNUNET_MESSENGER_SrvRoom *room, | ||
158 | struct GNUNET_MESSENGER_SrvHandle *handle, | ||
159 | const struct GNUNET_PeerIdentity *door); | ||
160 | |||
161 | /** | ||
162 | * Packs a <i>message</i> depending on the selected <i>mode</i> into a newly allocated envelope. It will set the | ||
163 | * timestamp of the message, the sender id and the previous messages hash automatically before packing. The message | ||
164 | * will be signed by the handles EGO. | ||
165 | * | ||
166 | * If the optional <i>hash</i> parameter is a valid pointer, its value will be overridden by the signed messages hash. | ||
167 | * | ||
168 | * If <i>mode</i> is set to #GNUNET_MESSENGER_PACK_MODE_ENVELOPE, the function returns a valid envelope to send | ||
169 | * through a message queue, otherwise NULL. | ||
170 | * | ||
171 | * @param[in] room Room | ||
172 | * @param[in] handle Handle | ||
173 | * @param[in/out] message Message | ||
174 | * @param[out] hash Hash of message | ||
175 | * @param[in] mode Packing mode | ||
176 | * @return New envelope or NULL | ||
177 | */ | ||
178 | struct GNUNET_MQ_Envelope* | ||
179 | pack_room_message (const struct GNUNET_MESSENGER_SrvRoom *room, | ||
180 | const struct GNUNET_MESSENGER_SrvHandle *handle, | ||
181 | struct GNUNET_MESSENGER_Message *message, | ||
182 | struct GNUNET_HashCode *hash, | ||
183 | int mode); | ||
184 | |||
185 | /** | ||
186 | * Sends a <i>message</i> from a given <i>handle</i> into a <i>room</i>. The <i>hash</i> parameter will be | ||
187 | * updated with the hash-value resulting from the sent message. | ||
188 | * | ||
189 | * The function handles packing the message automatically and will call linked message-events locally even if | ||
190 | * the message won't be sent to another peer. | ||
191 | * | ||
192 | * The function returns #GNUNET_YES on success, #GNUNET_NO if message is null and | ||
193 | * #GNUNET_SYSERR if the message was known already. | ||
194 | * | ||
195 | * @param[in/out] room Room | ||
196 | * @param[in/out] handle Handle | ||
197 | * @param[in/out] message Message | ||
198 | * @return #GNUNET_YES on success, #GNUNET_NO or #GNUNET_SYSERR otherwise. | ||
199 | */ | ||
200 | int | ||
201 | send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | ||
202 | struct GNUNET_MESSENGER_SrvHandle *handle, | ||
203 | struct GNUNET_MESSENGER_Message *message); | ||
204 | |||
205 | /** | ||
206 | * Forwards a <i>message</i> with a given <i>hash</i> to a specific <i>tunnel</i> inside of a <i>room</i>. | ||
207 | * | ||
208 | * @param[in/out] room Room | ||
209 | * @param[in/out] tunnel Tunnel | ||
210 | * @param[in/out] message Message | ||
211 | * @param[in] hash Hash of message | ||
212 | */ | ||
213 | void | ||
214 | forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | ||
215 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
216 | struct GNUNET_MESSENGER_Message *message, | ||
217 | const struct GNUNET_HashCode *hash); | ||
218 | |||
219 | /** | ||
220 | * Checks the current state of opening a given <i>room</i> from this peer and re-publishes it | ||
221 | * if necessary to a selected <i>tunnel</i> or to all connected tunnels if necessary or if the | ||
222 | * selected tunnel is NULL. | ||
223 | * | ||
224 | * @param[in/out] room Room | ||
225 | * @param[in/out] tunnel Tunnel | ||
226 | */ | ||
227 | void | ||
228 | check_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, | ||
229 | struct GNUNET_MESSENGER_SrvTunnel *tunnel); | ||
230 | |||
231 | /** | ||
232 | * Reduces all current forks inside of the message history of a <i>room</i> to one remaining last message | ||
233 | * by merging them down. All merge messages will be sent from a given <i>handle</i>. | ||
234 | * | ||
235 | * @param[in/out] room Room | ||
236 | * @param[in/out] handle Handle | ||
237 | */ | ||
238 | void | ||
239 | merge_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, | ||
240 | struct GNUNET_MESSENGER_SrvHandle *handle); | ||
241 | |||
242 | /** | ||
243 | * Deletes a message from the <i>room</i> with a given <i>hash</i> in a specific <i>delay</i> if | ||
244 | * the provided member by its session is permitted to do so. | ||
245 | * | ||
246 | * @param[in/out] room Room | ||
247 | * @param[in/out] session Member session | ||
248 | * @param[in] hash Hash of message | ||
249 | * @param[in] delay Delay of deletion | ||
250 | * @return #GNUNET_YES on success, #GNUNET_NO if permission gets denied, #GNUNET_SYSERR on operation failure | ||
251 | */ | ||
252 | int | ||
253 | delete_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | ||
254 | struct GNUNET_MESSENGER_MemberSession *session, | ||
255 | const struct GNUNET_HashCode *hash, | ||
256 | const struct GNUNET_TIME_Relative delay); | ||
257 | |||
258 | /** | ||
259 | * Returns the CADET handle from a rooms service. | ||
260 | * | ||
261 | * @param[in/out] room Room | ||
262 | * @return CADET handle | ||
263 | */ | ||
264 | struct GNUNET_CADET_Handle* | ||
265 | get_room_cadet (struct GNUNET_MESSENGER_SrvRoom *room); | ||
266 | |||
267 | /** | ||
268 | * Returns the shared secret you need to access a <i>room</i>. | ||
269 | * | ||
270 | * @param[in] room Room | ||
271 | * @return Shared secret | ||
272 | */ | ||
273 | const struct GNUNET_HashCode* | ||
274 | get_room_key (const struct GNUNET_MESSENGER_SrvRoom *room); | ||
275 | |||
276 | /** | ||
277 | * Returns a tunnel inside of a <i>room</i> leading towards a given <i>peer</i> if such a tunnel exists, | ||
278 | * otherwise NULL. | ||
279 | * | ||
280 | * @param[in] room Room | ||
281 | * @param[in] peer Peer identity | ||
282 | * @return Tunnel or NULL | ||
283 | */ | ||
284 | const struct GNUNET_MESSENGER_SrvTunnel* | ||
285 | get_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, | ||
286 | const struct GNUNET_PeerIdentity *peer); | ||
287 | |||
288 | /** | ||
289 | * Method called whenever a <i>message</i> is found during a request in a <i>room</i>. | ||
290 | * | ||
291 | * @param[in/out] cls Closure from #request_room_message | ||
292 | * @param[in/out] room Room | ||
293 | * @param[in] message Message or NULL | ||
294 | * @param[in] hash Hash of message | ||
295 | */ | ||
296 | typedef void (GNUNET_MESSENGER_MessageRequestCallback) ( | ||
297 | void *cls, | ||
298 | struct GNUNET_MESSENGER_SrvRoom *room, | ||
299 | const struct GNUNET_MESSENGER_Message *message, | ||
300 | const struct GNUNET_HashCode *hash | ||
301 | ); | ||
302 | |||
303 | /** | ||
304 | * Requests a message from a <i>room</i> identified by a given <i>hash</i>. If the message is found, | ||
305 | * the selected <i>callback</i> will be called with it and the provided closure. If no matching message | ||
306 | * is found but it wasn't deleted the selected callback will be called with #NULL as message instead. | ||
307 | * In case of deletion the next available previous message will be used to call the callback. | ||
308 | * | ||
309 | * It is also possible that the given callback will not be called if the requesting session is not | ||
310 | * permitted! | ||
311 | * | ||
312 | * @param[in/out] room Room | ||
313 | * @param[in] hash Hash of message | ||
314 | * @param[in] callback Callback to process result | ||
315 | * @param[in] cls Closure for the <i>callback</i> | ||
316 | * @return #GNUNET_YES if the request could be processed, otherwise #GNUNET_NO | ||
317 | */ | ||
318 | int | ||
319 | request_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | ||
320 | const struct GNUNET_HashCode *hash, | ||
321 | const struct GNUNET_MESSENGER_MemberSession *session, | ||
322 | GNUNET_MESSENGER_MessageRequestCallback callback, | ||
323 | void* cls); | ||
324 | |||
325 | /** | ||
326 | * Checks for potential collisions with member ids and solves them changing active handles ids if they | ||
327 | * use an already used member id (comparing public key and timestamp). | ||
328 | * | ||
329 | * @param[in/out] room Room | ||
330 | * @param[in] public_key Public key of EGO | ||
331 | * @param[in] member_id Member ID | ||
332 | * @param[in] timestamp Timestamp | ||
333 | */ | ||
334 | void | ||
335 | solve_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room, | ||
336 | const struct GNUNET_IDENTITY_PublicKey *public_key, | ||
337 | const struct GNUNET_ShortHashCode *member_id, | ||
338 | struct GNUNET_TIME_Absolute timestamp); | ||
339 | |||
340 | /** | ||
341 | * Rebuilds the decentralized structure for a <i>room</i> by ensuring all required connections are made | ||
342 | * depending on the amount of peers and this peers index in the list of them. | ||
343 | * | ||
344 | * @param[in/out] room Room | ||
345 | */ | ||
346 | void | ||
347 | rebuild_room_basement_structure (struct GNUNET_MESSENGER_SrvRoom *room); | ||
348 | |||
349 | /** | ||
350 | * Loads the local configuration for a given <i>room</i> of a service which contains the last messages hash | ||
351 | * and the ruleset for general access of new members. | ||
352 | * | ||
353 | * @param[out] room Room | ||
354 | */ | ||
355 | void | ||
356 | load_room (struct GNUNET_MESSENGER_SrvRoom *room); | ||
357 | |||
358 | /** | ||
359 | * Saves the configuration for a given <i>room</i> of a service which contains the last messages hash | ||
360 | * and the ruleset for general access of new members locally. | ||
361 | * | ||
362 | * @param[in] room Room | ||
363 | */ | ||
364 | void | ||
365 | save_room (struct GNUNET_MESSENGER_SrvRoom *room); | ||
366 | |||
367 | #endif //GNUNET_SERVICE_MESSENGER_ROOM_H | ||