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