diff options
Diffstat (limited to 'src/messenger/messenger_api_handle.c')
-rw-r--r-- | src/messenger/messenger_api_handle.c | 271 |
1 files changed, 0 insertions, 271 deletions
diff --git a/src/messenger/messenger_api_handle.c b/src/messenger/messenger_api_handle.c deleted file mode 100644 index 7d5b55a06..000000000 --- a/src/messenger/messenger_api_handle.c +++ /dev/null | |||
@@ -1,271 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020--2023 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.c | ||
23 | * @brief messenger api: client implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "platform.h" | ||
27 | #include "messenger_api_handle.h" | ||
28 | |||
29 | #include "messenger_api_room.h" | ||
30 | #include "messenger_api_util.h" | ||
31 | |||
32 | struct GNUNET_MESSENGER_Handle* | ||
33 | create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
34 | GNUNET_MESSENGER_MessageCallback msg_callback, | ||
35 | void *msg_cls) | ||
36 | { | ||
37 | GNUNET_assert (cfg); | ||
38 | |||
39 | struct GNUNET_MESSENGER_Handle *handle = GNUNET_new (struct | ||
40 | GNUNET_MESSENGER_Handle); | ||
41 | |||
42 | handle->cfg = cfg; | ||
43 | handle->mq = NULL; | ||
44 | |||
45 | handle->msg_callback = msg_callback; | ||
46 | handle->msg_cls = msg_cls; | ||
47 | |||
48 | handle->name = NULL; | ||
49 | handle->key = NULL; | ||
50 | handle->pubkey = NULL; | ||
51 | |||
52 | handle->reconnect_time = GNUNET_TIME_relative_get_zero_ (); | ||
53 | handle->reconnect_task = NULL; | ||
54 | |||
55 | handle->rooms = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | ||
56 | |||
57 | init_contact_store (get_handle_contact_store (handle)); | ||
58 | |||
59 | return handle; | ||
60 | } | ||
61 | |||
62 | |||
63 | static int | ||
64 | iterate_destroy_room (void *cls, | ||
65 | const struct GNUNET_HashCode *key, | ||
66 | void *value) | ||
67 | { | ||
68 | struct GNUNET_MESSENGER_Room *room = value; | ||
69 | |||
70 | destroy_room (room); | ||
71 | |||
72 | return GNUNET_YES; | ||
73 | } | ||
74 | |||
75 | |||
76 | void | ||
77 | destroy_handle (struct GNUNET_MESSENGER_Handle *handle) | ||
78 | { | ||
79 | GNUNET_assert (handle); | ||
80 | |||
81 | if (handle->reconnect_task) | ||
82 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | ||
83 | |||
84 | if (handle->mq) | ||
85 | GNUNET_MQ_destroy (handle->mq); | ||
86 | |||
87 | if (handle->name) | ||
88 | GNUNET_free (handle->name); | ||
89 | |||
90 | if (handle->key) | ||
91 | GNUNET_free (handle->key); | ||
92 | |||
93 | if (handle->pubkey) | ||
94 | GNUNET_free (handle->pubkey); | ||
95 | |||
96 | if (handle->rooms) | ||
97 | { | ||
98 | GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_destroy_room, | ||
99 | NULL); | ||
100 | |||
101 | GNUNET_CONTAINER_multihashmap_destroy (handle->rooms); | ||
102 | } | ||
103 | |||
104 | clear_contact_store (get_handle_contact_store (handle)); | ||
105 | |||
106 | GNUNET_free (handle); | ||
107 | } | ||
108 | |||
109 | |||
110 | void | ||
111 | set_handle_name (struct GNUNET_MESSENGER_Handle *handle, | ||
112 | const char *name) | ||
113 | { | ||
114 | GNUNET_assert (handle); | ||
115 | |||
116 | if (handle->name) | ||
117 | GNUNET_free (handle->name); | ||
118 | |||
119 | handle->name = name ? GNUNET_strdup (name) : NULL; | ||
120 | } | ||
121 | |||
122 | |||
123 | const char* | ||
124 | get_handle_name (const struct GNUNET_MESSENGER_Handle *handle) | ||
125 | { | ||
126 | GNUNET_assert (handle); | ||
127 | |||
128 | return handle->name; | ||
129 | } | ||
130 | |||
131 | |||
132 | void | ||
133 | set_handle_key (struct GNUNET_MESSENGER_Handle *handle, | ||
134 | const struct GNUNET_IDENTITY_PrivateKey *key) | ||
135 | { | ||
136 | GNUNET_assert (handle); | ||
137 | |||
138 | if (! key) | ||
139 | { | ||
140 | if (handle->key) | ||
141 | GNUNET_free (handle->key); | ||
142 | |||
143 | if (handle->pubkey) | ||
144 | GNUNET_free (handle->pubkey); | ||
145 | |||
146 | handle->key = NULL; | ||
147 | handle->pubkey = NULL; | ||
148 | return; | ||
149 | } | ||
150 | |||
151 | if (! handle->key) | ||
152 | handle->key = GNUNET_new (struct GNUNET_IDENTITY_PrivateKey); | ||
153 | |||
154 | if (! handle->pubkey) | ||
155 | handle->pubkey = GNUNET_new (struct GNUNET_IDENTITY_PublicKey); | ||
156 | |||
157 | GNUNET_memcpy (handle->key, key, sizeof(*key)); | ||
158 | GNUNET_IDENTITY_key_get_public (key, handle->pubkey); | ||
159 | } | ||
160 | |||
161 | |||
162 | const struct GNUNET_IDENTITY_PrivateKey* | ||
163 | get_handle_key (const struct GNUNET_MESSENGER_Handle *handle) | ||
164 | { | ||
165 | GNUNET_assert (handle); | ||
166 | |||
167 | if (handle->key) | ||
168 | return handle->key; | ||
169 | |||
170 | return get_anonymous_private_key (); | ||
171 | } | ||
172 | |||
173 | |||
174 | const struct GNUNET_IDENTITY_PublicKey* | ||
175 | get_handle_pubkey (const struct GNUNET_MESSENGER_Handle *handle) | ||
176 | { | ||
177 | GNUNET_assert (handle); | ||
178 | |||
179 | if (handle->pubkey) | ||
180 | return handle->pubkey; | ||
181 | |||
182 | return get_anonymous_public_key (); | ||
183 | } | ||
184 | |||
185 | |||
186 | struct GNUNET_MESSENGER_ContactStore* | ||
187 | get_handle_contact_store (struct GNUNET_MESSENGER_Handle *handle) | ||
188 | { | ||
189 | GNUNET_assert (handle); | ||
190 | |||
191 | return &(handle->contact_store); | ||
192 | } | ||
193 | |||
194 | |||
195 | struct GNUNET_MESSENGER_Contact* | ||
196 | get_handle_contact (struct GNUNET_MESSENGER_Handle *handle, | ||
197 | const struct GNUNET_HashCode *key) | ||
198 | { | ||
199 | GNUNET_assert ((handle) && (key)); | ||
200 | |||
201 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get ( | ||
202 | handle->rooms, key); | ||
203 | |||
204 | if (! room) | ||
205 | return NULL; | ||
206 | |||
207 | const struct GNUNET_ShortHashCode *contact_id = get_room_sender_id (room); | ||
208 | |||
209 | if (! contact_id) | ||
210 | return NULL; | ||
211 | |||
212 | struct GNUNET_HashCode context; | ||
213 | get_context_from_member (key, contact_id, &context); | ||
214 | |||
215 | return get_store_contact (get_handle_contact_store (handle), &context, | ||
216 | get_handle_pubkey (handle)); | ||
217 | } | ||
218 | |||
219 | |||
220 | void | ||
221 | open_handle_room (struct GNUNET_MESSENGER_Handle *handle, | ||
222 | const struct GNUNET_HashCode *key) | ||
223 | { | ||
224 | GNUNET_assert ((handle) && (key)); | ||
225 | |||
226 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get ( | ||
227 | handle->rooms, key); | ||
228 | |||
229 | if (room) | ||
230 | room->opened = GNUNET_YES; | ||
231 | } | ||
232 | |||
233 | |||
234 | void | ||
235 | entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, | ||
236 | const struct GNUNET_PeerIdentity *door, | ||
237 | const struct GNUNET_HashCode *key) | ||
238 | { | ||
239 | GNUNET_assert ((handle) && (door) && (key)); | ||
240 | |||
241 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get ( | ||
242 | handle->rooms, key); | ||
243 | |||
244 | if (room) | ||
245 | add_to_list_tunnels (&(room->entries), door, NULL); | ||
246 | } | ||
247 | |||
248 | |||
249 | void | ||
250 | close_handle_room (struct GNUNET_MESSENGER_Handle *handle, | ||
251 | const struct GNUNET_HashCode *key) | ||
252 | { | ||
253 | GNUNET_assert ((handle) && (key)); | ||
254 | |||
255 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get ( | ||
256 | handle->rooms, key); | ||
257 | |||
258 | if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove ( | ||
259 | handle->rooms, key, room))) | ||
260 | destroy_room (room); | ||
261 | } | ||
262 | |||
263 | |||
264 | struct GNUNET_MESSENGER_Room* | ||
265 | get_handle_room (struct GNUNET_MESSENGER_Handle *handle, | ||
266 | const struct GNUNET_HashCode *key) | ||
267 | { | ||
268 | GNUNET_assert ((handle) && (key)); | ||
269 | |||
270 | return GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | ||
271 | } | ||