diff options
Diffstat (limited to 'src/messenger/gnunet-service-messenger_handle.h')
-rw-r--r-- | src/messenger/gnunet-service-messenger_handle.h | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/src/messenger/gnunet-service-messenger_handle.h b/src/messenger/gnunet-service-messenger_handle.h new file mode 100644 index 000000000..81cf377a8 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_handle.h | |||
@@ -0,0 +1,216 @@ | |||
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_handle.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_HANDLE_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_HANDLE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_cadet_service.h" | ||
31 | #include "gnunet_container_lib.h" | ||
32 | #include "gnunet_crypto_lib.h" | ||
33 | #include "gnunet_identity_service.h" | ||
34 | #include "gnunet_peer_lib.h" | ||
35 | #include "gnunet_mq_lib.h" | ||
36 | |||
37 | #include "gnunet-service-messenger_service.h" | ||
38 | |||
39 | #include "messenger_api_ego.h" | ||
40 | #include "messenger_api_message.h" | ||
41 | |||
42 | struct GNUNET_MESSENGER_SrvHandle | ||
43 | { | ||
44 | struct GNUNET_MESSENGER_Service *service; | ||
45 | struct GNUNET_MQ_Handle *mq; | ||
46 | |||
47 | char *name; | ||
48 | |||
49 | struct GNUNET_IDENTITY_Operation *operation; | ||
50 | |||
51 | struct GNUNET_MESSENGER_Ego *ego; | ||
52 | |||
53 | struct GNUNET_CONTAINER_MultiHashMap *member_ids; | ||
54 | }; | ||
55 | |||
56 | /** | ||
57 | * Creates and allocates a new handle related to a <i>service</i> and using a given <i>mq</i> (message queue). | ||
58 | * | ||
59 | * @param service MESSENGER Service | ||
60 | * @param mq Message queue | ||
61 | * @return New handle | ||
62 | */ | ||
63 | struct GNUNET_MESSENGER_SrvHandle* | ||
64 | create_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq); | ||
65 | |||
66 | /** | ||
67 | * Destroys a handle and frees its memory fully. | ||
68 | * | ||
69 | * @param handle Handle | ||
70 | */ | ||
71 | void | ||
72 | destroy_handle (struct GNUNET_MESSENGER_SrvHandle *handle); | ||
73 | |||
74 | /** | ||
75 | * Writes the path of the directory for a given <i>handle</i> using a specific <i>name</i> to the parameter | ||
76 | * <i>dir</i>. This directory will be used to store data regarding the handle and its messages. | ||
77 | * | ||
78 | * @param handle Handle | ||
79 | * @param name Potential name of the handle | ||
80 | * @param dir[out] Path to store data | ||
81 | */ | ||
82 | void | ||
83 | get_handle_data_subdir (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name, char **dir); | ||
84 | |||
85 | /** | ||
86 | * Returns the member id of a given <i>handle</i> in a specific <i>room</i>. | ||
87 | * | ||
88 | * If the handle is not a member of the specific <i>room</i>, NULL gets returned. | ||
89 | * | ||
90 | * @param handle Handle | ||
91 | * @param key Key of a room | ||
92 | * @return Member id or NULL | ||
93 | */ | ||
94 | const struct GNUNET_ShortHashCode* | ||
95 | get_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); | ||
96 | |||
97 | /** | ||
98 | * Changes the member id of a given <i>handle</i> in a specific <i>room</i> to match a <i>unique_id</i>. | ||
99 | * | ||
100 | * The client connected to the <i>handle</i> will be informed afterwards automatically. | ||
101 | * | ||
102 | * @param handle Handle | ||
103 | * @param key Key of a room | ||
104 | * @param unique_id Unique member id | ||
105 | */ | ||
106 | void | ||
107 | change_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, | ||
108 | const struct GNUNET_ShortHashCode *unique_id); | ||
109 | |||
110 | /** | ||
111 | * Returns the EGO used by a given <i>handle</i>. | ||
112 | * | ||
113 | * @param handle Handle | ||
114 | * @return EGO keypair | ||
115 | */ | ||
116 | struct GNUNET_MESSENGER_Ego* | ||
117 | get_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle); | ||
118 | |||
119 | /** | ||
120 | * Tries to set the name and EGO key of a <i>handle</i> initially by looking up a specific <i>name</i>. | ||
121 | * | ||
122 | * @param handle Handle | ||
123 | * @param name Name (optionally: valid EGO name) | ||
124 | */ | ||
125 | void | ||
126 | setup_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name); | ||
127 | |||
128 | /** | ||
129 | * Tries to change the keypair of an EGO of a <i>handle</i> under the same name and informs all rooms | ||
130 | * about the change automatically. | ||
131 | * | ||
132 | * @param handle Handle | ||
133 | * @return GNUNET_OK on success, otherwise GNUNET_SYSERR | ||
134 | */ | ||
135 | int | ||
136 | update_handle (struct GNUNET_MESSENGER_SrvHandle *handle); | ||
137 | |||
138 | /** | ||
139 | * Tries to rename the handle which implies renaming the EGO its using and moving all related data into | ||
140 | * the directory fitting to the changed <i>name</i>. | ||
141 | * | ||
142 | * The client connected to the <i>handle</i> will be informed afterwards automatically. | ||
143 | * | ||
144 | * @param handle Handle | ||
145 | * @param name New name | ||
146 | * @return GNUNET_OK on success, otherwise GNUNET_NO | ||
147 | */ | ||
148 | int | ||
149 | set_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name); | ||
150 | |||
151 | /** | ||
152 | * Makes a given <i>handle</i> a member of the room using a specific <i>key</i> and opens the | ||
153 | * room from the handles service. | ||
154 | * | ||
155 | * @param handle Handle | ||
156 | * @param key Key of a room | ||
157 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
158 | */ | ||
159 | int | ||
160 | open_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); | ||
161 | |||
162 | /** | ||
163 | * Makes a given <i>handle</i> a member of the room using a specific <i>key</i> and enters the room | ||
164 | * through a tunnel to a peer identified by a given <i>door</i> (peer identity). | ||
165 | * | ||
166 | * @param handle Handle | ||
167 | * @param door Peer identity | ||
168 | * @param key Key of a room | ||
169 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
170 | */ | ||
171 | int | ||
172 | entry_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, | ||
173 | const struct GNUNET_HashCode *key); | ||
174 | |||
175 | /** | ||
176 | * Removes the membership of the room using a specific <i>key</i> and closes it if no other handle | ||
177 | * from this service is still a member of it. | ||
178 | * | ||
179 | * @param handle Handle | ||
180 | * @param key Key of a room | ||
181 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
182 | */ | ||
183 | int | ||
184 | close_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); | ||
185 | |||
186 | /** | ||
187 | * Sends a <i>message</i> from a given <i>handle</i> to the room using a specific <i>key</i>. | ||
188 | * | ||
189 | * @param handle Handle | ||
190 | * @param key Key of a room | ||
191 | * @param message Message | ||
192 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
193 | */ | ||
194 | int | ||
195 | send_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, | ||
196 | struct GNUNET_MESSENGER_Message *message); | ||
197 | |||
198 | /** | ||
199 | * Loads member ids and other potential configuration from a given <i>handle</i> which | ||
200 | * depends on the given name the <i>handle</i> uses. | ||
201 | * | ||
202 | * @param handle Handle | ||
203 | */ | ||
204 | void | ||
205 | load_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle); | ||
206 | |||
207 | /** | ||
208 | * Saves member ids and other potential configuration from a given <i>handle</i> which | ||
209 | * depends on the given name the <i>handle</i> uses. | ||
210 | * | ||
211 | * @param handle Handle | ||
212 | */ | ||
213 | void | ||
214 | save_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle); | ||
215 | |||
216 | #endif //GNUNET_SERVICE_MESSENGER_HANDLE_H | ||