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