diff options
Diffstat (limited to 'src/messenger/gnunet-service-messenger_service.h')
-rw-r--r-- | src/messenger/gnunet-service-messenger_service.h | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/src/messenger/gnunet-service-messenger_service.h b/src/messenger/gnunet-service-messenger_service.h new file mode 100644 index 000000000..246c74771 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_service.h | |||
@@ -0,0 +1,259 @@ | |||
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 | * @file src/messenger/gnunet-service-messenger_service.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_SERVICE_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_SERVICE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_configuration_lib.h" | ||
31 | #include "gnunet_crypto_lib.h" | ||
32 | #include "gnunet_container_lib.h" | ||
33 | #include "gnunet_disk_lib.h" | ||
34 | #include "gnunet_identity_service.h" | ||
35 | |||
36 | #include "messenger_api_ego.h" | ||
37 | |||
38 | #include "gnunet-service-messenger_list_handles.h" | ||
39 | |||
40 | #include "gnunet-service-messenger_contact.h" | ||
41 | #include "gnunet-service-messenger_room.h" | ||
42 | |||
43 | struct GNUNET_MESSENGER_Service | ||
44 | { | ||
45 | const struct GNUNET_CONFIGURATION_Handle *config; | ||
46 | struct GNUNET_SERVICE_Handle *service; | ||
47 | |||
48 | struct GNUNET_SCHEDULER_Task *shutdown; | ||
49 | |||
50 | char *dir; | ||
51 | |||
52 | struct GNUNET_CADET_Handle *cadet; | ||
53 | struct GNUNET_IDENTITY_Handle *identity; | ||
54 | |||
55 | struct GNUNET_CONTAINER_MultiHashMap *egos; | ||
56 | |||
57 | struct GNUNET_MESSENGER_ListHandles handles; | ||
58 | |||
59 | struct GNUNET_CONTAINER_MultiHashMap *contacts; | ||
60 | struct GNUNET_CONTAINER_MultiHashMap *rooms; | ||
61 | }; | ||
62 | |||
63 | /** | ||
64 | * Creates and allocates a new service using a given <i>config</i> and a GNUnet service handle. | ||
65 | * | ||
66 | * @param config Configuration | ||
67 | * @param service_handle GNUnet service handle | ||
68 | * @return New service | ||
69 | */ | ||
70 | struct GNUNET_MESSENGER_Service* | ||
71 | create_service (const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_SERVICE_Handle *service_handle); | ||
72 | |||
73 | /** | ||
74 | * Destroys a <i>service</i> and frees its memory fully. | ||
75 | * | ||
76 | * @param service Service | ||
77 | */ | ||
78 | void | ||
79 | destroy_service (struct GNUNET_MESSENGER_Service *service); | ||
80 | |||
81 | /** | ||
82 | * Lookups an EGO which was registered to a <i>service</i> under | ||
83 | * a specific <i>identifier</i>. | ||
84 | * | ||
85 | * @param service Service | ||
86 | * @param identifier Identifier string | ||
87 | * @return EGO or NULL | ||
88 | */ | ||
89 | struct GNUNET_MESSENGER_Ego* | ||
90 | lookup_service_ego (struct GNUNET_MESSENGER_Service *service, const char *identifier); | ||
91 | |||
92 | /** | ||
93 | * Updates the registration of an EGO to a <i>service</i> under | ||
94 | * a specific <i>identifier</i> with a new <i>key</i>. | ||
95 | * | ||
96 | * @param service Service | ||
97 | * @param identifier Identifier string | ||
98 | * @param key Private EGO key | ||
99 | */ | ||
100 | void | ||
101 | update_service_ego (struct GNUNET_MESSENGER_Service *service, const char *identifier, | ||
102 | const struct GNUNET_IDENTITY_PrivateKey* key); | ||
103 | |||
104 | /** | ||
105 | * Creates and adds a new handle to a <i>service</i> using a given message queue. | ||
106 | * | ||
107 | * @param service Service | ||
108 | * @param mq Message queue | ||
109 | * @return New handle | ||
110 | */ | ||
111 | struct GNUNET_MESSENGER_SrvHandle* | ||
112 | add_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq); | ||
113 | |||
114 | /** | ||
115 | * Removes a <i>handle</i> from a <i>service</i> and destroys it. | ||
116 | * | ||
117 | * @param service Service | ||
118 | * @param handle Handle | ||
119 | */ | ||
120 | void | ||
121 | remove_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle); | ||
122 | |||
123 | /** | ||
124 | * Tries to write the peer identity of the peer running a <i>service</i> on to the <i>peer</i> | ||
125 | * parameter. The functions returns GNUNET_OK on success, otherwise GNUNET_SYSERR. | ||
126 | * | ||
127 | * @param service Service | ||
128 | * @param[out] peer Peer identity | ||
129 | * @return GNUNET_OK on success, otherwise GNUNET_SYSERR | ||
130 | */ | ||
131 | int | ||
132 | get_service_peer_identity (const struct GNUNET_MESSENGER_Service *service, struct GNUNET_PeerIdentity *peer); | ||
133 | |||
134 | /** | ||
135 | * Returns a contact of a <i>service</i> identified by a given public key. If no matching contact exists, | ||
136 | * it will tried to create one with the specific public key. If the function still fails to do so, | ||
137 | * NULL gets returned. | ||
138 | * | ||
139 | * @param service Service | ||
140 | * @param pubkey Public key of EGO | ||
141 | * @return Contact | ||
142 | */ | ||
143 | struct GNUNET_MESSENGER_SrvContact* | ||
144 | get_service_contact_by_pubkey (struct GNUNET_MESSENGER_Service *service, const struct GNUNET_IDENTITY_PublicKey *pubkey); | ||
145 | |||
146 | /** | ||
147 | * Changes the public key for a <i>contact</i> known to a <i>service</i> to a specific public key and | ||
148 | * updates local map entries to access the contact by its updated key. | ||
149 | * | ||
150 | * @param service Service | ||
151 | * @param contact Contact | ||
152 | * @param pubkey Public key of EGO | ||
153 | */ | ||
154 | void | ||
155 | swap_service_contact_by_pubkey (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvContact *contact, | ||
156 | const struct GNUNET_IDENTITY_PublicKey *pubkey); | ||
157 | |||
158 | /** | ||
159 | * Tries to generate and allocate a new unique member id for a given room of a service identified by its <i>key</i>. | ||
160 | * If the generation fails caused by too many tries of duplicates, it returns NULL. | ||
161 | * | ||
162 | * @param service Service | ||
163 | * @param key Key of room | ||
164 | * @return Newly generated member id or NULL | ||
165 | */ | ||
166 | struct GNUNET_ShortHashCode* | ||
167 | generate_service_new_member_id (struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key); | ||
168 | |||
169 | /** | ||
170 | * Returns the room identified by a given <i>key</i> for a <i>service</i>. If the service doesn't know any room | ||
171 | * using the given key, NULL gets returned. | ||
172 | * | ||
173 | * @param service Service | ||
174 | * @param key Key of room | ||
175 | * @return Room or NULL | ||
176 | */ | ||
177 | struct GNUNET_MESSENGER_SrvRoom* | ||
178 | get_service_room (struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key); | ||
179 | |||
180 | /** | ||
181 | * Tries to open a room using a given <i>key</i> for a <i>service</i> by a specific <i>handle</i>. The room will be | ||
182 | * created if necessary. If the function is successful, it returns GNUNET_YES, otherwise GNUNET_NO. | ||
183 | * | ||
184 | * @param service Service | ||
185 | * @param handle Handle | ||
186 | * @param key Key of room | ||
187 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
188 | */ | ||
189 | int | ||
190 | open_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
191 | const struct GNUNET_HashCode *key); | ||
192 | |||
193 | /** | ||
194 | * Tries to enter a room using a given <i>key</i> for a <i>service</i> by a specific <i>handle</i>. The room will | ||
195 | * be created if necessary. If the function is successful, it returns GNUNET_YES, otherwise GNUNET_NO. | ||
196 | * | ||
197 | * The room will be entered through the peer identitied by the peer identity provided as <i>door</i> parameter and | ||
198 | * a new connection will be made. | ||
199 | * | ||
200 | * @param service Service | ||
201 | * @param handle Handle | ||
202 | * @param door Peer identity | ||
203 | * @param key Key of room | ||
204 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
205 | */ | ||
206 | int | ||
207 | entry_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
208 | const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key); | ||
209 | |||
210 | /** | ||
211 | * Tries to close a room using a given <i>key</i> for a <i>service</i> by a specific <i>handle</i>. The room will | ||
212 | * be created if necessary. If the function is successful, it returns GNUNET_YES, otherwise GNUNET_NO. | ||
213 | * | ||
214 | * If the specific handle is currently the host of the room for this service, a new handle which is a member will | ||
215 | * take its place. Otherwise the room will be destroyed for this service. | ||
216 | * | ||
217 | * @param service Service | ||
218 | * @param handle Handle | ||
219 | * @param key Key of room | ||
220 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
221 | */ | ||
222 | int | ||
223 | close_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
224 | const struct GNUNET_HashCode *key); | ||
225 | |||
226 | /** | ||
227 | * Loads the local configuration for a given <i>room</i> of a <i>service</i> which contains the last messages hash | ||
228 | * and the ruleset for general access of new members. | ||
229 | * | ||
230 | * @param service Service | ||
231 | * @param room Room | ||
232 | */ | ||
233 | void | ||
234 | load_service_room_and_messages (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room); | ||
235 | |||
236 | /** | ||
237 | * Saves the configuration for a given <i>room</i> of a <i>service</i> which contains the last messages hash | ||
238 | * and the ruleset for general access of new members locally. | ||
239 | * | ||
240 | * @param service Service | ||
241 | * @param room Room | ||
242 | */ | ||
243 | void | ||
244 | save_service_room_and_messages (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room); | ||
245 | |||
246 | /** | ||
247 | * Sends a received or sent <i>message</i> with a given <i>hash</i> to each handle of a <i>service</i> which | ||
248 | * is currently member of a specific <i>room</i> for handling it in the client API. | ||
249 | * | ||
250 | * @param service Service | ||
251 | * @param room Room | ||
252 | * @param message Message | ||
253 | * @param hash Hash of message | ||
254 | */ | ||
255 | void | ||
256 | handle_service_message (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, | ||
257 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
258 | |||
259 | #endif //GNUNET_SERVICE_MESSENGER_SERVICE_H | ||