aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/Makefile.am1
-rw-r--r--src/include/gnunet_messenger_service.h436
-rw-r--r--src/include/gnunet_protocols.h43
3 files changed, 1 insertions, 479 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index fc3d745a6..202abb7ac 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -62,7 +62,6 @@ gnunetinclude_HEADERS = \
62 gnunet_json_lib.h \ 62 gnunet_json_lib.h \
63 gnunet_load_lib.h \ 63 gnunet_load_lib.h \
64 gnunet_cadet_service.h \ 64 gnunet_cadet_service.h \
65 gnunet_messenger_service.h \
66 gnunet_mhd_compat.h \ 65 gnunet_mhd_compat.h \
67 gnunet_microphone_lib.h \ 66 gnunet_microphone_lib.h \
68 gnunet_mst_lib.h \ 67 gnunet_mst_lib.h \
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h
deleted file mode 100644
index 8f5315c30..000000000
--- a/src/include/gnunet_messenger_service.h
+++ /dev/null
@@ -1,436 +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 *
23 * @file
24 * MESSENGER service; manages decentralized chat groups
25 *
26 * @defgroup messenger MESSENGER service
27 * Instant messaging based on the CADET subsystem
28 *
29 * @{
30 */
31
32#ifndef GNUNET_MESSENGER_SERVICE_H
33#define GNUNET_MESSENGER_SERVICE_H
34
35#ifdef __cplusplus
36extern "C" {
37#if 0 /* keep Emacsens' auto-indent happy */
38}
39#endif
40#endif
41
42#include "platform.h"
43#include "gnunet_configuration_lib.h"
44#include "gnunet_crypto_lib.h"
45#include "gnunet_identity_service.h"
46#include "gnunet_mq_lib.h"
47#include "gnunet_protocols.h"
48#include "gnunet_scheduler_lib.h"
49#include "gnunet_time_lib.h"
50
51#define GNUNET_MESSENGER_SERVICE_NAME "messenger"
52
53/**
54 * Opaque handle to the messenger
55 */
56struct GNUNET_MESSENGER_Handle;
57
58/**
59 * Opaque handle to a room
60 */
61struct GNUNET_MESSENGER_Room;
62
63/**
64 * Opaque handle to a contact
65 */
66struct GNUNET_MESSENGER_Contact;
67
68/**
69 * Enum for the different supported kinds of messages
70 */
71enum GNUNET_MESSENGER_MessageKind
72{
73 GNUNET_MESSENGER_KIND_INFO = 1,
74
75 GNUNET_MESSENGER_KIND_JOIN = 2,
76 GNUNET_MESSENGER_KIND_LEAVE = 3,
77
78 GNUNET_MESSENGER_KIND_NAME = 4,
79 GNUNET_MESSENGER_KIND_KEY = 5,
80 GNUNET_MESSENGER_KIND_PEER = 6,
81 GNUNET_MESSENGER_KIND_ID = 7,
82
83 GNUNET_MESSENGER_KIND_MISS = 8,
84 GNUNET_MESSENGER_KIND_MERGE = 9,
85 GNUNET_MESSENGER_KIND_REQUEST = 10,
86
87 GNUNET_MESSENGER_KIND_INVITE = 11,
88 GNUNET_MESSENGER_KIND_TEXT = 12,
89 GNUNET_MESSENGER_KIND_FILE = 13,
90
91 GNUNET_MESSENGER_KIND_PRIVATE = 14,
92
93 GNUNET_MESSENGER_KIND_UNKNOWN = 0
94}__attribute__((__packed__));
95
96/**
97 * Get the name of a message <i>kind</i>.
98 *
99 * @param kind Kind of a message
100 * @return Name of that kind
101 */
102const char*
103GNUNET_MESSENGER_name_of_kind (enum GNUNET_MESSENGER_MessageKind kind);
104
105struct GNUNET_MESSENGER_MessageHeader
106{
107 struct GNUNET_IDENTITY_Signature signature;
108
109 struct GNUNET_TIME_AbsoluteNBO timestamp;
110
111 struct GNUNET_ShortHashCode sender_id;
112 struct GNUNET_HashCode previous;
113
114 enum GNUNET_MESSENGER_MessageKind kind;
115};
116
117struct GNUNET_MESSENGER_MessageInfo
118{
119 struct GNUNET_IDENTITY_PublicKey host_key;
120 struct GNUNET_ShortHashCode unique_id;
121};
122
123struct GNUNET_MESSENGER_MessageJoin
124{
125 struct GNUNET_IDENTITY_PublicKey key;
126};
127
128struct GNUNET_MESSENGER_MessageLeave
129{
130};
131
132struct GNUNET_MESSENGER_MessageName
133{
134 char *name;
135};
136
137struct GNUNET_MESSENGER_MessageKey
138{
139 struct GNUNET_IDENTITY_PublicKey key;
140};
141
142struct GNUNET_MESSENGER_MessagePeer
143{
144 struct GNUNET_PeerIdentity peer;
145};
146
147struct GNUNET_MESSENGER_MessageId
148{
149 struct GNUNET_ShortHashCode id;
150};
151
152struct GNUNET_MESSENGER_MessageMiss
153{
154 struct GNUNET_PeerIdentity peer;
155};
156
157struct GNUNET_MESSENGER_MessageMerge
158{
159 struct GNUNET_HashCode previous;
160};
161
162struct GNUNET_MESSENGER_MessageRequest
163{
164 struct GNUNET_HashCode hash;
165};
166
167struct GNUNET_MESSENGER_MessageInvite
168{
169 struct GNUNET_PeerIdentity door;
170 struct GNUNET_HashCode key;
171};
172
173struct GNUNET_MESSENGER_MessageText
174{
175 char *text;
176};
177
178struct GNUNET_MESSENGER_MessageFile
179{
180 struct GNUNET_CRYPTO_SymmetricSessionKey key;
181 struct GNUNET_HashCode hash;
182 char name[NAME_MAX];
183 char *uri;
184};
185
186struct GNUNET_MESSENGER_MessagePrivate
187{
188 struct GNUNET_CRYPTO_EcdhePublicKey key;
189
190 uint16_t length;
191 char *data;
192};
193
194struct GNUNET_MESSENGER_MessageBody
195{
196 union
197 {
198 struct GNUNET_MESSENGER_MessageInfo info;
199
200 struct GNUNET_MESSENGER_MessageJoin join;
201 struct GNUNET_MESSENGER_MessageLeave leave;
202
203 struct GNUNET_MESSENGER_MessageName name;
204 struct GNUNET_MESSENGER_MessageKey key;
205 struct GNUNET_MESSENGER_MessagePeer peer;
206 struct GNUNET_MESSENGER_MessageId id;
207
208 struct GNUNET_MESSENGER_MessageMiss miss;
209 struct GNUNET_MESSENGER_MessageMerge merge;
210 struct GNUNET_MESSENGER_MessageRequest request;
211
212 struct GNUNET_MESSENGER_MessageInvite invite;
213 struct GNUNET_MESSENGER_MessageText text;
214 struct GNUNET_MESSENGER_MessageFile file;
215
216 struct GNUNET_MESSENGER_MessagePrivate private;
217 };
218};
219
220/**
221 * Struct to a message
222 */
223struct GNUNET_MESSENGER_Message
224{
225 struct GNUNET_MESSENGER_MessageHeader header;
226 struct GNUNET_MESSENGER_MessageBody body;
227};
228
229/**
230 * Method called whenever the EGO of a <i>handle</i> changes or if the first connection fails
231 * to load a valid EGO and the anonymous keypair will be used instead.
232 *
233 * @param cls Closure from <i>GNUNET_MESSENGER_connect</i>
234 * @param handle Messenger handle
235 */
236typedef void
237(*GNUNET_MESSENGER_IdentityCallback) (void *cls, struct GNUNET_MESSENGER_Handle *handle);
238
239/**
240 * Method called whenever a message is sent or received from a <i>room</i>.
241 *
242 * @param cls Closure from <i>GNUNET_MESSENGER_connect</i>
243 * @param room Room handle
244 * @param message Newly received or sent message
245 * @param hash Hash identifying the message
246 */
247typedef void
248(*GNUNET_MESSENGER_MessageCallback) (void *cls, const struct GNUNET_MESSENGER_Room *room,
249 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash);
250
251/**
252 * Set up a handle for the messenger related functions and connects to all necessary services. It will look up the ego
253 * key identified by its <i>name</i> and use it for signing all messages from the handle.
254 *
255 * @param cfg Configuration to use
256 * @param name Name to look up an ego or NULL to stay anonymous
257 * @param identity_callback Function called when the EGO of the handle changes
258 * @param identity_cls Closure for the <i>identity_callback</i> handler
259 * @param msg_callback Function called when a new message is sent or received
260 * @param msg_cls Closure for the <i>msg_callback</i> handler
261 * @return Messenger handle to use, NULL on error
262 */
263struct GNUNET_MESSENGER_Handle*
264GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name,
265 GNUNET_MESSENGER_IdentityCallback identity_callback, void *identity_cls,
266 GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls);
267
268/**
269 * Update a handle of the messenger to use a different ego key and replace the old one with a newly generated one. All
270 * participated rooms get informed about the key renewal. The handle requires a set name for this function to work and
271 * it needs to be unused by other egos.
272 *
273 * Keep in mind that this will fully delete the old ego key (if any is used) even if any other service wants to use it
274 * as default.
275 *
276 * @param handle Messenger handle to use
277 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
278 */
279int
280GNUNET_MESSENGER_update (struct GNUNET_MESSENGER_Handle *handle);
281
282/**
283 * Disconnect all of the messengers used services and clears up its used memory.
284 *
285 * @param handle Messenger handle to use
286 */
287void
288GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle);
289
290/**
291 * Get the name (if specified, otherwise NULL) used by the messenger.
292 *
293 * @param handle Messenger handle to use
294 * @return Name used by the messenger or NULL
295 */
296const char*
297GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle);
298
299/**
300 * Set the name for the messenger. This will rename the currently used ego and move all stored files related to the current
301 * name to its new directory. If anything fails during this process the function returns GNUNET_NO and the name for
302 * the messenger won't change as specified.
303 *
304 * @param handle Messenger handle to use
305 * @param name Name for the messenger to change to
306 * @return GNUNET_YES on success, GNUNET_NO on failure and GNUNET_SYSERR if <i>handle</i> is NULL
307 */
308int
309GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, const char *name);
310
311/**
312 * Get the public key used by the messenger.
313 *
314 * @param handle Messenger handle to use
315 * @return Used ego's public key
316 */
317const struct GNUNET_IDENTITY_PublicKey*
318GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle);
319
320/**
321 * Open a room to send and receive messages. The room will use the specified <i>key</i> as port for the underlying cadet
322 * service. Opening a room results in opening the port for incoming connections as possible <b>door</b>.
323 *
324 * Notice that there can only be one room related to a specific <i>key</i>. So trying to open two rooms with the same
325 * <i>key</i> will result in opening the room once but returning the handle both times because the room stays open.
326 *
327 * You can also open a room after entering it through a <b>door</b> using <i>GNUNET_MESSENGER_entry_room(...)</i>. This
328 * will notify all entered <b>doors</b> to list you as new <b>door</b>.
329 *
330 * ( All <b>doors</b> form a ring structured network to shorten the latency sending and receiving messages. )
331 *
332 * @param handle Messenger handle to use
333 * @param key Hash identifying the port
334 * @return Room handle, NULL on error
335 */
336struct GNUNET_MESSENGER_Room*
337GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key);
338
339/**
340 * Enter a room to send and receive messages through a <b>door</b> opened using <i>GNUNET_MESSENGER_open_room(...)</i>.
341 *
342 * Notice that there can only be one room related to a specific <i>key</i>. So trying to enter two rooms with the same
343 * <i>key</i> will result in entering the room once but returning the handle both times because the room stays entered.
344 * You can however enter a room through multiple <b>doors</b> in parallel which results in connecting both ends. But
345 * entering the room through the same <b>door</b> won't have any effect after the first time.
346 *
347 * You can also enter a room through a <b>door</b> after opening it using <i>GNUNET_MESSENGER_open_room(...)</i>. But the
348 * <b>door</b> may not be your own peer identity.
349 *
350 * ( All <b>doors</b> form a ring structured network to shorten the latency sending and receiving messages. )
351 *
352 * @param handle Messenger handle to use
353 * @param door Peer identity of an open <b>door</b>
354 * @param key Hash identifying the port
355 * @return Room handle, NULL on error
356 */
357struct GNUNET_MESSENGER_Room*
358GNUNET_MESSENGER_entry_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door,
359 const struct GNUNET_HashCode *key);
360
361/**
362 * Close a room which was entered, opened or both in various order and variety. Closing a room will destroy all connections
363 * from your peer to another and the other way around.
364 *
365 * ( After a member closes a <b>door</b>, all members entered through that specific <b>door</b> have to use another one
366 * or open the room on their own. )
367 *
368 * @param room Room handle
369 */
370void
371GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room);
372
373/**
374 * Get the contact of a member in a <i>room</i> identified by their <i>id</i>.
375 *
376 * Notice that contacts are independent of rooms but will be removed if all rooms containing these contacts get closed.
377 *
378 * @param room Room handle
379 * @param id Hash identifying a member
380 * @return Contact handle, NULL if <i>id</i> is not in use
381 */
382struct GNUNET_MESSENGER_Contact*
383GNUNET_MESSENGER_get_member (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_ShortHashCode *id);
384
385/**
386 * Get the name used by the <i>contact</i>.
387 *
388 * @param contact Contact handle
389 * @return Name of <i>contact</i> or NULL
390 */
391const char*
392GNUNET_MESSENGER_contact_get_name (const struct GNUNET_MESSENGER_Contact *contact);
393
394/**
395 * Get the public key used by the <i>contact</i>.
396 *
397 * @param contact Contact handle
398 * @return Public key of the ego used by <i>contact</i>
399 */
400const struct GNUNET_IDENTITY_PublicKey*
401GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact);
402
403/**
404 * Send a <i>message</i> into a </i>room</i>. If you opened the <i>room</i> all entered members will receive the
405 * <i>message</i>. If you entered the <i>room</i> through a <b>door</b> all so entered <b>doors</b> will receive the
406 * <i>message</i> as well. All members receiving the <i>message</i> will also propagate this <i>message</i> recursively
407 * as long as the <i>message</i> is unknown to them.
408 *
409 * Notice that all messages sent and received are also stored and can be propagated to new members entering the room.
410 *
411 * @param room Room handle
412 * @param message New message to send
413 */
414void
415GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message);
416
417/**
418 * Get the message in a <i>room</i> identified by its <i>hash</i>.
419 *
420 * @param room Room handle
421 * @param hash Hash identifying a message
422 * @return Message struct or NULL if no message with that hash is known
423 */
424const struct GNUNET_MESSENGER_Message*
425GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash);
426
427#if 0 /* keep Emacsens' auto-indent happy */
428{
429#endif
430#ifdef __cplusplus
431}
432#endif
433
434#endif //GNUNET_MESSENGER_SERVICE_H
435
436/** @} *//* end of group */
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 3bdebeb50..d9821ffe8 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001--2020 GNUnet e.V. 3 Copyright (C) 2001--2018 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -20,7 +20,6 @@
20 20
21/** 21/**
22 * @author Christian Grothoff 22 * @author Christian Grothoff
23 * @author Tobias Frisch
24 * 23 *
25 * @file 24 * @file
26 * Constants for network protocols 25 * Constants for network protocols
@@ -3519,46 +3518,6 @@ extern "C" {
3519#define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT 1501 3518#define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT 1501
3520 3519
3521 3520
3522/*********************************************************************************/
3523/********************************** MESSENGER **********************************/
3524/*********************************************************************************/
3525/* MESSENGER: message types 1600-1629
3526 * 1600-1609 Connection-level Messages
3527 * 1610-1619 Room-level Messages
3528 */
3529
3530/********************************* Connection **********************************/
3531
3532#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE 1600
3533
3534#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE 1601
3535
3536#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY 1602
3537
3538#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME 1603
3539
3540#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME 1604
3541
3542#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY 1605
3543
3544#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID 1606
3545
3546/************************************ Room *************************************/
3547
3548#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN 1610
3549
3550#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY 1611
3551
3552#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE 1612
3553
3554#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE 1614
3555
3556#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE 1615
3557
3558#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE 1616
3559
3560/*********************************************************************************/
3561
3562/** 3521/**
3563 * Type used to match 'all' message types. 3522 * Type used to match 'all' message types.
3564 */ 3523 */