aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/messenger_api_handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/messenger_api_handle.c')
-rw-r--r--src/messenger/messenger_api_handle.c207
1 files changed, 0 insertions, 207 deletions
diff --git a/src/messenger/messenger_api_handle.c b/src/messenger/messenger_api_handle.c
deleted file mode 100644
index 242389040..000000000
--- a/src/messenger/messenger_api_handle.c
+++ /dev/null
@@ -1,207 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2021 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 "messenger_api_handle.h"
27
28#include "messenger_api_util.h"
29
30struct GNUNET_MESSENGER_Handle*
31create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg,
32 GNUNET_MESSENGER_IdentityCallback identity_callback,
33 void *identity_cls,
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 GNUNET_MESSENGER_Handle);
40
41 handle->cfg = cfg;
42 handle->mq = NULL;
43
44 handle->identity_callback = identity_callback;
45 handle->identity_cls = identity_cls;
46
47 handle->msg_callback = msg_callback;
48 handle->msg_cls = msg_cls;
49
50 handle->name = NULL;
51 handle->pubkey = NULL;
52
53 handle->reconnect_time = GNUNET_TIME_relative_get_zero_ ();
54 handle->reconnect_task = NULL;
55
56 handle->rooms = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
57
58 init_contact_store(get_handle_contact_store(handle));
59
60 return handle;
61}
62
63static int
64iterate_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
75void
76destroy_handle (struct GNUNET_MESSENGER_Handle *handle)
77{
78 GNUNET_assert(handle);
79
80 if (handle->reconnect_task)
81 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
82
83 if (handle->mq)
84 GNUNET_MQ_destroy (handle->mq);
85
86 if (handle->name)
87 GNUNET_free(handle->name);
88
89 if (handle->pubkey)
90 GNUNET_free(handle->pubkey);
91
92 if (handle->rooms)
93 {
94 GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_destroy_room, NULL);
95
96 GNUNET_CONTAINER_multihashmap_destroy (handle->rooms);
97 }
98
99 clear_contact_store(get_handle_contact_store(handle));
100
101 GNUNET_free(handle);
102}
103
104void
105set_handle_name (struct GNUNET_MESSENGER_Handle *handle,
106 const char *name)
107{
108 GNUNET_assert(handle);
109
110 if (handle->name)
111 GNUNET_free(handle->name);
112
113 handle->name = name ? GNUNET_strdup(name) : NULL;
114}
115
116const char*
117get_handle_name (const struct GNUNET_MESSENGER_Handle *handle)
118{
119 GNUNET_assert(handle);
120
121 return handle->name;
122}
123
124void
125set_handle_key (struct GNUNET_MESSENGER_Handle *handle,
126 const struct GNUNET_IDENTITY_PublicKey *pubkey)
127{
128 GNUNET_assert(handle);
129
130 if (!handle->pubkey)
131 handle->pubkey = GNUNET_new(struct GNUNET_IDENTITY_PublicKey);
132
133 GNUNET_memcpy(handle->pubkey, pubkey, sizeof(*pubkey));
134}
135
136const struct GNUNET_IDENTITY_PublicKey*
137get_handle_key (const struct GNUNET_MESSENGER_Handle *handle)
138{
139 GNUNET_assert(handle);
140
141 if (handle->pubkey)
142 return handle->pubkey;
143
144 return get_anonymous_public_key ();
145}
146
147struct GNUNET_MESSENGER_ContactStore*
148get_handle_contact_store (struct GNUNET_MESSENGER_Handle *handle)
149{
150 GNUNET_assert(handle);
151
152 return &(handle->contact_store);
153}
154
155struct GNUNET_MESSENGER_Contact*
156get_handle_contact (struct GNUNET_MESSENGER_Handle *handle,
157 const struct GNUNET_HashCode *key)
158{
159 GNUNET_assert((handle) && (key));
160
161 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
162
163 if ((!room) || (!(room->contact_id)))
164 return NULL;
165
166 struct GNUNET_HashCode context;
167 get_context_from_member (key, room->contact_id, &context);
168
169 return get_store_contact(get_handle_contact_store(handle), &context, get_handle_key(handle));
170}
171
172void
173open_handle_room (struct GNUNET_MESSENGER_Handle *handle,
174 const struct GNUNET_HashCode *key)
175{
176 GNUNET_assert((handle) && (key));
177
178 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
179
180 if (room)
181 room->opened = GNUNET_YES;
182}
183
184void
185entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle,
186 const struct GNUNET_PeerIdentity *door,
187 const struct GNUNET_HashCode *key)
188{
189 GNUNET_assert((handle) && (door) && (key));
190
191 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
192
193 if (room)
194 add_to_list_tunnels (&(room->entries), door);
195}
196
197void
198close_handle_room (struct GNUNET_MESSENGER_Handle *handle,
199 const struct GNUNET_HashCode *key)
200{
201 GNUNET_assert((handle) && (key));
202
203 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
204
205 if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->rooms, key, room)))
206 destroy_room (room);
207}