aboutsummaryrefslogtreecommitdiff
path: root/src/service/messenger/messenger_api_handle.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/messenger/messenger_api_handle.h')
-rw-r--r--src/service/messenger/messenger_api_handle.h190
1 files changed, 190 insertions, 0 deletions
diff --git a/src/service/messenger/messenger_api_handle.h b/src/service/messenger/messenger_api_handle.h
new file mode 100644
index 000000000..1a2763020
--- /dev/null
+++ b/src/service/messenger/messenger_api_handle.h
@@ -0,0 +1,190 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2024 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/messenger_api_handle.h
23 * @brief messenger api: client implementation of GNUnet MESSENGER service
24 */
25
26#ifndef GNUNET_MESSENGER_API_HANDLE_H
27#define GNUNET_MESSENGER_API_HANDLE_H
28
29#include "gnunet_util_lib.h"
30
31#include "gnunet_messenger_service.h"
32
33#include "messenger_api_contact_store.h"
34
35struct GNUNET_MESSENGER_Handle
36{
37 const struct GNUNET_CONFIGURATION_Handle *cfg;
38
39 struct GNUNET_MQ_Handle *mq;
40
41 GNUNET_MESSENGER_MessageCallback msg_callback;
42 void *msg_cls;
43
44 char *name;
45 struct GNUNET_CRYPTO_PrivateKey *key;
46 struct GNUNET_CRYPTO_PublicKey *pubkey;
47
48 struct GNUNET_TIME_Relative reconnect_time;
49 struct GNUNET_SCHEDULER_Task *reconnect_task;
50
51 struct GNUNET_MESSENGER_ContactStore contact_store;
52
53 struct GNUNET_CONTAINER_MultiHashMap *rooms;
54};
55
56/**
57 * Creates and allocates a new handle using a given configuration and a custom message callback
58 * with a given closure for the client API.
59 *
60 * @param[in] cfg Configuration
61 * @param[in] msg_callback Message callback
62 * @param[in,out] msg_cls Closure
63 * @return New handle
64 */
65struct GNUNET_MESSENGER_Handle*
66create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg,
67 GNUNET_MESSENGER_MessageCallback msg_callback,
68 void *msg_cls);
69
70/**
71 * Destroys a <i>handle</i> and frees its memory fully from the client API.
72 *
73 * @param[in,out] handle Handle
74 */
75void
76destroy_handle (struct GNUNET_MESSENGER_Handle *handle);
77
78/**
79 * Sets the name of a <i>handle</i> to a specific <i>name</i>.
80 *
81 * @param[in,out] handle Handle
82 * @param[in] name New name
83 */
84void
85set_handle_name (struct GNUNET_MESSENGER_Handle *handle,
86 const char *name);
87
88/**
89 * Returns the current name of a given <i>handle</i> or NULL if no valid name was assigned yet.
90 *
91 * @param[in] handle Handle
92 * @return Name of the handle or NULL
93 */
94const char*
95get_handle_name (const struct GNUNET_MESSENGER_Handle *handle);
96
97/**
98 * Sets the keypair of a given <i>handle</i> to the keypair of a specific private <i>key</i>.
99 *
100 * @param[in,out] handle Handle
101 * @param[in] key Private key or NULL
102 */
103void
104set_handle_key (struct GNUNET_MESSENGER_Handle *handle,
105 const struct GNUNET_CRYPTO_PrivateKey *key);
106
107/**
108 * Returns the private key of a given <i>handle</i>.
109 *
110 * @param[in] handle Handle
111 * @return Private key of the handle
112 */
113const struct GNUNET_CRYPTO_PrivateKey*
114get_handle_key (const struct GNUNET_MESSENGER_Handle *handle);
115
116/**
117 * Returns the public key of a given <i>handle</i>.
118 *
119 * @param[in] handle Handle
120 * @return Public key of the handle
121 */
122const struct GNUNET_CRYPTO_PublicKey*
123get_handle_pubkey (const struct GNUNET_MESSENGER_Handle *handle);
124
125/**
126 * Returns the used contact store of a given <i>handle</i>.
127 *
128 * @param[in,out] handle Handle
129 * @return Contact store
130 */
131struct GNUNET_MESSENGER_ContactStore*
132get_handle_contact_store (struct GNUNET_MESSENGER_Handle *handle);
133
134/**
135 * Returns the contact of a given <i>handle</i> in a room identified by a
136 * given <i>key</i>.
137 *
138 * @param[in,out] handle Handle
139 * @param[in] key Key of room
140 * @return Contact
141 */
142struct GNUNET_MESSENGER_Contact*
143get_handle_contact (struct GNUNET_MESSENGER_Handle *handle,
144 const struct GNUNET_HashCode *key);
145
146/**
147 * Marks a room known to a <i>handle</i> identified by a given <i>key</i> as open.
148 *
149 * @param[in,out] handle Handle
150 * @param[in] key Key of room
151 */
152void
153open_handle_room (struct GNUNET_MESSENGER_Handle *handle,
154 const struct GNUNET_HashCode *key);
155
156/**
157 * Adds a tunnel for a room known to a <i>handle</i> identified by a given <i>key</i> to a
158 * list of opened connections.
159 *
160 * @param[in,out] handle Handle
161 * @param[in] door Peer identity
162 * @param[in] key Key of room
163 */
164void
165entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle,
166 const struct GNUNET_PeerIdentity *door,
167 const struct GNUNET_HashCode *key);
168
169/**
170 * Destroys and so implicitly closes a room known to a <i>handle</i> identified by a given <i>key</i>.
171 *
172 * @param[in,out] handle Handle
173 * @param[in] key Key of room
174 */
175void
176close_handle_room (struct GNUNET_MESSENGER_Handle *handle,
177 const struct GNUNET_HashCode *key);
178
179/**
180 * Returns the room known to a <i>handle</i> identified by a given <i>key</i>.
181 *
182 * @param[in,out] handle handle Handle
183 * @param[in] key Key of room
184 * @return Room or NULL
185 */
186struct GNUNET_MESSENGER_Room*
187get_handle_room (struct GNUNET_MESSENGER_Handle *handle,
188 const struct GNUNET_HashCode *key);
189
190#endif //GNUNET_MESSENGER_API_HANDLE_H