diff options
Diffstat (limited to 'src/service/messenger/gnunet-service-messenger_handle.h')
-rw-r--r-- | src/service/messenger/gnunet-service-messenger_handle.h | 213 |
1 files changed, 213 insertions, 0 deletions
diff --git a/src/service/messenger/gnunet-service-messenger_handle.h b/src/service/messenger/gnunet-service-messenger_handle.h new file mode 100644 index 000000000..4963d9247 --- /dev/null +++ b/src/service/messenger/gnunet-service-messenger_handle.h | |||
@@ -0,0 +1,213 @@ | |||
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/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_util_lib.h" | ||
32 | #include "gnunet_identity_service.h" | ||
33 | |||
34 | #include "gnunet-service-messenger_service.h" | ||
35 | #include "gnunet-service-messenger_sender_session.h" | ||
36 | |||
37 | #include "messenger_api_message.h" | ||
38 | |||
39 | struct GNUNET_MESSENGER_SrvHandle | ||
40 | { | ||
41 | struct GNUNET_MESSENGER_Service *service; | ||
42 | struct GNUNET_MQ_Handle *mq; | ||
43 | |||
44 | struct GNUNET_CRYPTO_PublicKey *key; | ||
45 | |||
46 | struct GNUNET_CONTAINER_MultiHashMap *member_ids; | ||
47 | struct GNUNET_CONTAINER_MultiHashMap *next_ids; | ||
48 | |||
49 | struct GNUNET_SCHEDULER_Task *notify; | ||
50 | }; | ||
51 | |||
52 | /** | ||
53 | * Creates and allocates a new handle related to a <i>service</i> and using a given <i>mq</i> (message queue). | ||
54 | * | ||
55 | * @param[in,out] service MESSENGER Service | ||
56 | * @param[in,out] mq Message queue | ||
57 | * @return New handle | ||
58 | */ | ||
59 | struct GNUNET_MESSENGER_SrvHandle* | ||
60 | create_srv_handle (struct GNUNET_MESSENGER_Service *service, | ||
61 | struct GNUNET_MQ_Handle *mq); | ||
62 | |||
63 | /** | ||
64 | * Destroys a handle and frees its memory fully. | ||
65 | * | ||
66 | * @param[in,out] handle Handle | ||
67 | */ | ||
68 | void | ||
69 | destroy_srv_handle (struct GNUNET_MESSENGER_SrvHandle *handle); | ||
70 | |||
71 | /** | ||
72 | * Sets the public key from the EGO of a given <i>handle</i>. | ||
73 | * | ||
74 | * @param[out] handle Handle | ||
75 | * @param[in] key Public key of EGO | ||
76 | */ | ||
77 | void | ||
78 | set_srv_handle_key (struct GNUNET_MESSENGER_SrvHandle *handle, | ||
79 | const struct GNUNET_CRYPTO_PublicKey *key); | ||
80 | |||
81 | /** | ||
82 | * Returns the public key from the EGO of a given <i>handle</i>. | ||
83 | * | ||
84 | * @param[in] handle Handle | ||
85 | * @return Public key of handles EGO | ||
86 | */ | ||
87 | const struct GNUNET_CRYPTO_PublicKey* | ||
88 | get_srv_handle_key (const struct GNUNET_MESSENGER_SrvHandle *handle); | ||
89 | |||
90 | /** | ||
91 | * Writes the path of the directory for a given <i>handle</i> using a specific <i>name</i> to the parameter | ||
92 | * <i>dir</i>. This directory will be used to store data regarding the handle and its messages. | ||
93 | * | ||
94 | * @param[in] handle Handle | ||
95 | * @param[in] name Potential name of the handle | ||
96 | * @param[out] dir Path to store data | ||
97 | */ | ||
98 | void | ||
99 | get_srv_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, | ||
100 | const char *name, | ||
101 | char **dir); | ||
102 | |||
103 | /** | ||
104 | * Returns the member id of a given <i>handle</i> in a specific <i>room</i>. | ||
105 | * | ||
106 | * If the handle is not a member of the specific <i>room</i>, NULL gets returned. | ||
107 | * | ||
108 | * @param[in] handle Handle | ||
109 | * @param[in] key Key of a room | ||
110 | * @return Member id or NULL | ||
111 | */ | ||
112 | const struct GNUNET_ShortHashCode* | ||
113 | get_srv_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, | ||
114 | const struct GNUNET_HashCode *key); | ||
115 | |||
116 | /** | ||
117 | * Changes the member id of a given <i>handle</i> in a specific <i>room</i> to match a <i>unique_id</i> | ||
118 | * and returns GNUNET_OK on success. | ||
119 | * | ||
120 | * The client connected to the <i>handle</i> will be informed afterwards automatically. | ||
121 | * | ||
122 | * @param[in,out] handle Handle | ||
123 | * @param[in] key Key of a room | ||
124 | * @param[in] unique_id Unique member id | ||
125 | * @return GNUNET_OK on success, otherwise GNUNET_SYSERR | ||
126 | */ | ||
127 | int | ||
128 | change_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, | ||
129 | const struct GNUNET_HashCode *key, | ||
130 | const struct GNUNET_ShortHashCode *unique_id); | ||
131 | |||
132 | /** | ||
133 | * Makes a given <i>handle</i> a member of the room using a specific <i>key</i> and opens the | ||
134 | * room from the handles service. | ||
135 | * | ||
136 | * @param[in,out] handle Handle | ||
137 | * @param[in] key Key of a room | ||
138 | * @return #GNUNET_YES on success, otherwise #GNUNET_NO | ||
139 | */ | ||
140 | int | ||
141 | open_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, | ||
142 | const struct GNUNET_HashCode *key); | ||
143 | |||
144 | /** | ||
145 | * Makes a given <i>handle</i> a member of the room using a specific <i>key</i> and enters the room | ||
146 | * through a tunnel to a peer identified by a given <i>door</i> (peer identity). | ||
147 | * | ||
148 | * @param[in,out] handle Handle | ||
149 | * @param[in] door Peer identity | ||
150 | * @param[in] key Key of a room | ||
151 | * @return #GNUNET_YES on success, otherwise #GNUNET_NO | ||
152 | */ | ||
153 | int | ||
154 | entry_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, | ||
155 | const struct GNUNET_PeerIdentity *door, | ||
156 | const struct GNUNET_HashCode *key); | ||
157 | |||
158 | /** | ||
159 | * Removes the membership of the room using a specific <i>key</i> and closes it if no other handle | ||
160 | * from this service is still a member of it. | ||
161 | * | ||
162 | * @param[in,out] handle Handle | ||
163 | * @param[in] key Key of a room | ||
164 | * @return #GNUNET_YES on success, otherwise #GNUNET_NO | ||
165 | */ | ||
166 | int | ||
167 | close_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, | ||
168 | const struct GNUNET_HashCode *key); | ||
169 | |||
170 | /** | ||
171 | * Sends a <i>message</i> from a given <i>handle</i> to the room using a specific <i>key</i>. | ||
172 | * | ||
173 | * @param[in,out] handle Handle | ||
174 | * @param[in] key Key of a room | ||
175 | * @param[in] message Message | ||
176 | * @return #GNUNET_YES on success, #GNUNET_NO or #GNUNET_SYSERR otherwise. | ||
177 | */ | ||
178 | int | ||
179 | send_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, | ||
180 | const struct GNUNET_HashCode *key, | ||
181 | const struct GNUNET_MESSENGER_Message *message); | ||
182 | |||
183 | /** | ||
184 | * Notifies the handle that a new message was received or sent. | ||
185 | * | ||
186 | * @param[in,out] handle Handle | ||
187 | * @param[in] room Room of the message | ||
188 | * @param[in] session Sender session | ||
189 | * @param[in] message Message | ||
190 | * @param[in] hash Hash of message | ||
191 | */ | ||
192 | void | ||
193 | notify_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, | ||
194 | struct GNUNET_MESSENGER_SrvRoom *room, | ||
195 | const struct GNUNET_MESSENGER_SenderSession *session, | ||
196 | const struct GNUNET_MESSENGER_Message *message, | ||
197 | const struct GNUNET_HashCode *hash); | ||
198 | |||
199 | /** | ||
200 | * Notifies the handle that a new member id needs to be used. | ||
201 | * | ||
202 | * @param[in,out] handle Handle | ||
203 | * @param[in] room Room of the member | ||
204 | * @param[in] member_id Member id | ||
205 | * @param[in] reset Reset member session with join message | ||
206 | */ | ||
207 | void | ||
208 | notify_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, | ||
209 | struct GNUNET_MESSENGER_SrvRoom *room, | ||
210 | const struct GNUNET_ShortHashCode *member_id, | ||
211 | enum GNUNET_GenericReturnValue reset); | ||
212 | |||
213 | #endif //GNUNET_SERVICE_MESSENGER_HANDLE_H | ||