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 36c9e8cf5..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 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-service-messenger_contact.h"
37
38#include "gnunet_messenger_service.h"
39#include "gnunet-service-messenger_basement.h"
40#include "gnunet-service-messenger_handle.h"
41#include "gnunet-service-messenger_tunnel.h"
42
43#include "gnunet-service-messenger_list_messages.h"
44#include "messenger_api_list_tunnels.h"
45
46#include "gnunet-service-messenger_message_store.h"
47#include "messenger_api_ego.h"
48
49enum GNUNET_MESSENGER_MemberAccess
50{
51 GNUNET_MESSENGER_MEMBER_ALLOWED = 1,
52 GNUNET_MESSENGER_MEMBER_BLOCKED = 1,
53
54 GNUNET_MESSENGER_MEMBER_UNKNOWN = 0
55};
56
57struct GNUNET_MESSENGER_MemberInfo
58{
59 enum GNUNET_MESSENGER_MemberAccess access;
60
61 struct GNUNET_MESSENGER_ListMessages session_messages;
62};
63
64struct GNUNET_MESSENGER_SrvRoom
65{
66 struct GNUNET_MESSENGER_Service *service;
67 struct GNUNET_MESSENGER_SrvHandle *host;
68 struct GNUNET_CADET_Port *port;
69
70 struct GNUNET_HashCode key;
71
72 struct GNUNET_CONTAINER_MultiPeerMap *tunnels;
73 struct GNUNET_CONTAINER_MultiShortmap *members;
74 struct GNUNET_CONTAINER_MultiShortmap *member_infos;
75
76 struct GNUNET_MESSENGER_MessageStore store;
77 struct GNUNET_CONTAINER_MultiHashMap *requested;
78
79 struct GNUNET_MESSENGER_ListTunnels basement;
80 struct GNUNET_MESSENGER_ListMessages last_messages;
81
82 struct GNUNET_HashCode *peer_message;
83
84 struct GNUNET_MESSENGER_ListMessages handling;
85 struct GNUNET_SCHEDULER_Task *idle;
86
87 int strict_access;
88};
89
90/**
91 * Creates and allocates a new room for a <i>handle</i> with a given <i>key</i>.
92 *
93 * @param handle Handle
94 * @param key Key of room
95 * @return New room
96 */
97struct GNUNET_MESSENGER_SrvRoom*
98create_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key);
99
100/**
101 * Destroys a room and frees its memory fully.
102 *
103 * @param room Room
104 */
105void
106destroy_room (struct GNUNET_MESSENGER_SrvRoom *room);
107
108/**
109 * Returns the contact of a member in a <i>room</i> identified by a given <i>id</i>. If the <i>room</i>
110 * does not contain a member with the given <i>id</i>, NULL gets returned.
111 *
112 * @param room Room
113 * @param id Member id
114 * @return Contact or NULL
115 */
116struct GNUNET_MESSENGER_SrvContact*
117get_room_contact (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id);
118
119/**
120 * Adds a contact from the service to a <i>room</i> under a specific <i>id</i> with a given public key.
121 *
122 * @param room Room
123 * @param id Member id
124 * @param pubkey Public key of EGO
125 */
126void
127add_room_contact (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id,
128 const struct GNUNET_IDENTITY_PublicKey *pubkey);
129
130/**
131 * Returns the member information of a member in a <i>room</i> identified by a given <i>id</i>. If the <i>room</i>
132 * does not contain a member with the given <i>id</i>, NULL gets returned.
133 *
134 * @param room Room
135 * @param id Member id
136 * @return Member information or NULL
137 */
138struct GNUNET_MESSENGER_MemberInfo*
139get_room_member_info (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id);
140
141/**
142 * Tries to generate and allocate a new unique member id checking all current members for possible
143 * duplicates. If the function fails, NULL gets returned.
144 *
145 * @param room Room
146 * @return New member id or NULL
147 */
148struct GNUNET_ShortHashCode*
149generate_room_member_id (const struct GNUNET_MESSENGER_SrvRoom *room);
150
151/**
152 * Returns the member id of the member representing the handle currently hosting this <i>room</i>.
153 *
154 * @param room Room
155 * @return Host member id or NULL
156 */
157const struct GNUNET_ShortHashCode*
158get_room_host_id (const struct GNUNET_MESSENGER_SrvRoom *room);
159
160/**
161 * Changes the member id of the member representing the handle currently hosting this <i>room</i>.
162 *
163 * @param room Room
164 * @param unique_id Unique member id
165 */
166void
167change_room_host_id (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *unique_id);
168
169/**
170 * Tries to open a <i>room</i> for a given <i>handle</i>. If the room has already been opened, the handle
171 * will locally join the room.
172 *
173 * Calling this method should result in joining a room and sending a peer message as well for this peer.
174 *
175 * If the function returns GNUNET_YES the port for this room is guranteed to be open for incoming connections.
176 *
177 * @param room Room
178 * @param handle Handle
179 * @return GNUNET_YES on success, GNUNET_NO on failure.
180 */
181int
182open_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle);
183
184/**
185 * Connects a tunnel to a hosting peer of a <i>room</i> through a so called <i>door</i> which is represented by
186 * a peer identity of a hosting peer. During the connection the handle will join the room as a member, waiting for
187 * an info message from the selected host.
188 *
189 * @param room Room
190 * @param handle Handle
191 * @param door Peer identity
192 * @return GNUNET_YES on success, GNUNET_NO on failure.
193 */
194int
195entry_room_at (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
196 const struct GNUNET_PeerIdentity *door);
197
198/**
199 * Returns a tunnel granting a direct connection to a specific member in a <i>room</i>. The member gets identified
200 * by an <i>id</i>. If no tunnel has been linked to the selected id, NULL gets returned.
201 *
202 * @param room Room
203 * @param contact_id Member id
204 * @return Tunnel to the member or NULL
205 */
206struct GNUNET_MESSENGER_SrvTunnel*
207find_room_tunnel_to (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *contact_id);
208
209/**
210 * Packs a <i>message</i> depending on the selected <i>mode</i> into a newly allocated envelope. It will set the
211 * timestamp of the message, the sender id and the previous messages hash automatically before packing. The message
212 * will be signed by the handles EGO.
213 *
214 * If the optional <i>hash</i> parameter is a valid pointer, its value will be overriden by the signed messages hash.
215 *
216 * If <i>mode</i> is set to GNUNET_MESSENGER_PACK_MODE_ENVELOPE, the function returns a valid envelope to send
217 * through a message queue, otherwise NULL.
218 *
219 * @param room Room
220 * @param handle Handle
221 * @param message Message
222 * @param[out] hash Hash of message
223 * @param mode Packing mode
224 * @return New envelope or NULL
225 */
226struct GNUNET_MQ_Envelope*
227pack_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
228 struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, int mode);
229
230/**
231 * Sends a <i>message</i> from a given <i>handle</i> into a <i>room</i>. The <i>hash</i> parameter will be
232 * updated with the hash-value resulting from the sent message.
233 *
234 * The function handles packing the message automatically and will call linked message-events locally even if
235 * the message won't be sent to another peer.
236 *
237 * @param room Room
238 * @param handle Handle
239 * @param message Message
240 * @param[out] hash Hash of message
241 */
242void
243send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
244 struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash);
245
246/**
247 * Sends a <i>message</i> from a given <i>handle</i> into a <i>room</i> excluding one specific <i>tunnel</i>.
248 * The <i>hash</i> parameter will be updated with the hash-value resulting from the sent message.
249 *
250 * The function handles packing the message automatically and will call linked message-events locally even if
251 * the message won't be sent to another peer.
252 *
253 * @param room Room
254 * @param handle Handle
255 * @param message Message
256 * @param[out] hash Hash of message
257 * @param tunnel Tunnel
258 */
259void
260send_room_message_ext (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
261 struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash,
262 struct GNUNET_MESSENGER_SrvTunnel *tunnel);
263
264/**
265 * Forwards a <i>message</i> with a given <i>hash</i> to a specific <i>tunnel</i> inside of a <i>room</i>.
266 *
267 * @param room Room
268 * @param tunnel Tunnel
269 * @param message Message
270 * @param hash Hash of message
271 */
272void
273forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel,
274 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash);
275
276/**
277 * Reduces all current forks inside of the message history of a <i>room</i> to one remaining last message
278 * by merging them down. All merge messages will be sent from a given <i>handle</i>.
279 *
280 * @param room Room
281 * @param handle Handle
282 */
283void
284merge_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle);
285
286/**
287 * Returns the CADET handle from a rooms service.
288 *
289 * @param room Room
290 * @return CADET handle
291 */
292struct GNUNET_CADET_Handle*
293get_room_cadet (struct GNUNET_MESSENGER_SrvRoom *room);
294
295/**
296 * Returns the shared secret you need to access a <i>room</i>.
297 *
298 * @param room Room
299 * @return Shared secret
300 */
301struct GNUNET_HashCode*
302get_room_key (struct GNUNET_MESSENGER_SrvRoom *room);
303
304/**
305 * Returns a tunnel inside of a <i>room</i> leading towards a given <i>peer</i> if such a tunnel exists,
306 * otherwise NULL.
307 *
308 * @param room Room
309 * @param peer Peer identity
310 * @return Tunnel or NULL
311 */
312const struct GNUNET_MESSENGER_SrvTunnel*
313get_room_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *peer);
314
315/**
316 * Returns a message from a <i>room</i> identified by a given <i>hash</i>. If no matching message is
317 * found and <i>request</i> is set to GNUNET_YES, the <i>handle</i> will request the missing message
318 * automatically.
319 *
320 * The function uses the optimized check for a message via its hash from the message store.
321 * @see contains_store_message()
322 *
323 * If a message is missing independent of the following request, NULL gets returned instead of the
324 * matching message.
325 *
326 * @param room Room
327 * @param handle Handle
328 * @param hash Hash of message
329 * @param request Flag to request a message
330 * @return Message or NULL
331 */
332const struct GNUNET_MESSENGER_Message*
333get_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
334 const struct GNUNET_HashCode *hash, int request);
335
336/**
337 * Updates the last messages of a <i>room</i> by replacing them if the previous hash of a given <i>message</i>
338 * matches with one of the latest messages.
339 *
340 * @param room Room
341 * @param message Message
342 * @param hash Hash of message
343 */
344void
345update_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message,
346 const struct GNUNET_HashCode *hash);
347
348/**
349 * Changes an id of a current member from an old id to a new one and adds optionally the <i>hash</i> of an
350 * id message to the members information.
351 *
352 * @param room Room
353 * @param old_id Old member id
354 * @param new_id New member id
355 * @param hash Hash of id message
356 */
357void
358switch_room_member_id (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *old_id,
359 const struct GNUNET_ShortHashCode *new_id, const struct GNUNET_HashCode *hash);
360
361/**
362 * Rebuilds the decentralized structure for a <i>room</i> by ensuring all required connections are made
363 * depending on the amount of peers and this peers index in the list of them.
364 *
365 * @param room Room
366 */
367void
368rebuild_room_basement_structure (struct GNUNET_MESSENGER_SrvRoom *room);
369
370/**
371 * Handles all queued up messages of a room to handle in correct order.
372 *
373 * @param room Room
374 */
375void
376handle_room_messages (struct GNUNET_MESSENGER_SrvRoom *room);
377
378#endif //GNUNET_SERVICE_MESSENGER_ROOM_H