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