diff options
Diffstat (limited to 'src/service/messenger/gnunet-service-messenger_service.h')
-rw-r--r-- | src/service/messenger/gnunet-service-messenger_service.h | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/src/service/messenger/gnunet-service-messenger_service.h b/src/service/messenger/gnunet-service-messenger_service.h new file mode 100644 index 000000000..69486b415 --- /dev/null +++ b/src/service/messenger/gnunet-service-messenger_service.h | |||
@@ -0,0 +1,200 @@ | |||
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_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_util_lib.h" | ||
32 | #include "gnunet_identity_service.h" | ||
33 | |||
34 | #include "gnunet-service-messenger_list_handles.h" | ||
35 | |||
36 | #include "messenger_api_contact_store.h" | ||
37 | |||
38 | #include "gnunet-service-messenger_room.h" | ||
39 | #include "gnunet-service-messenger_sender_session.h" | ||
40 | |||
41 | struct GNUNET_MESSENGER_Service | ||
42 | { | ||
43 | const struct GNUNET_CONFIGURATION_Handle *config; | ||
44 | struct GNUNET_SERVICE_Handle *service; | ||
45 | |||
46 | struct GNUNET_SCHEDULER_Task *shutdown; | ||
47 | |||
48 | struct GNUNET_PeerIdentity *peer; | ||
49 | char *dir; | ||
50 | |||
51 | struct GNUNET_CADET_Handle *cadet; | ||
52 | |||
53 | struct GNUNET_MESSENGER_ContactStore contact_store; | ||
54 | |||
55 | struct GNUNET_MESSENGER_ListHandles handles; | ||
56 | |||
57 | struct GNUNET_CONTAINER_MultiHashMap *rooms; | ||
58 | }; | ||
59 | |||
60 | /** | ||
61 | * Creates and allocates a new service using a given <i>config</i> and a GNUnet service handle. | ||
62 | * | ||
63 | * @param[in] config Configuration | ||
64 | * @param[in,out] service_handle GNUnet service handle | ||
65 | * @return New service | ||
66 | */ | ||
67 | struct GNUNET_MESSENGER_Service* | ||
68 | create_service (const struct GNUNET_CONFIGURATION_Handle *config, | ||
69 | struct GNUNET_SERVICE_Handle *service_handle); | ||
70 | |||
71 | /** | ||
72 | * Destroys a <i>service</i> and frees its memory fully. | ||
73 | * | ||
74 | * @param[in,out] service Service | ||
75 | */ | ||
76 | void | ||
77 | destroy_service (struct GNUNET_MESSENGER_Service *service); | ||
78 | |||
79 | /** | ||
80 | * Returns the used contact store of a given <i>service</i>. | ||
81 | * | ||
82 | * @param[in,out] service Service | ||
83 | * @return Contact store | ||
84 | */ | ||
85 | struct GNUNET_MESSENGER_ContactStore* | ||
86 | get_service_contact_store (struct GNUNET_MESSENGER_Service *service); | ||
87 | |||
88 | /** | ||
89 | * Creates and adds a new handle to a <i>service</i> using a given message queue. | ||
90 | * | ||
91 | * @param[in,out] service Service | ||
92 | * @param[in,out] mq Message queue | ||
93 | * @return New handle | ||
94 | */ | ||
95 | struct GNUNET_MESSENGER_SrvHandle* | ||
96 | add_service_handle (struct GNUNET_MESSENGER_Service *service, | ||
97 | struct GNUNET_MQ_Handle *mq); | ||
98 | |||
99 | /** | ||
100 | * Removes a <i>handle</i> from a <i>service</i> and destroys it. | ||
101 | * | ||
102 | * @param[in,out] service Service | ||
103 | * @param[in,out] handle Handle | ||
104 | */ | ||
105 | void | ||
106 | remove_service_handle (struct GNUNET_MESSENGER_Service *service, | ||
107 | struct GNUNET_MESSENGER_SrvHandle *handle); | ||
108 | |||
109 | /** | ||
110 | * Tries to write the peer identity of the peer running a <i>service</i> on to the <i>peer</i> | ||
111 | * parameter. The functions returns #GNUNET_OK on success, otherwise #GNUNET_SYSERR. | ||
112 | * | ||
113 | * @param[in,out] service Service | ||
114 | * @param[out] peer Peer identity | ||
115 | * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR | ||
116 | */ | ||
117 | int | ||
118 | get_service_peer_identity (struct GNUNET_MESSENGER_Service *service, | ||
119 | struct GNUNET_PeerIdentity *peer); | ||
120 | |||
121 | /** | ||
122 | * Returns the room identified by a given <i>key</i> for a <i>service</i>. If the service doesn't know any room | ||
123 | * using the given key, NULL gets returned. | ||
124 | * | ||
125 | * @param[in] service Service | ||
126 | * @param[in] key Key of room | ||
127 | * @return Room or NULL | ||
128 | */ | ||
129 | struct GNUNET_MESSENGER_SrvRoom* | ||
130 | get_service_room (const struct GNUNET_MESSENGER_Service *service, | ||
131 | const struct GNUNET_HashCode *key); | ||
132 | |||
133 | /** | ||
134 | * 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 | ||
135 | * created if necessary. If the function is successful, it returns #GNUNET_YES, otherwise #GNUNET_NO. | ||
136 | * | ||
137 | * @param[in,out] service Service | ||
138 | * @param[in,out] handle Handle | ||
139 | * @param[in] key Key of room | ||
140 | * @return #GNUNET_YES on success, otherwise #GNUNET_NO | ||
141 | */ | ||
142 | int | ||
143 | open_service_room (struct GNUNET_MESSENGER_Service *service, | ||
144 | struct GNUNET_MESSENGER_SrvHandle *handle, | ||
145 | const struct GNUNET_HashCode *key); | ||
146 | |||
147 | /** | ||
148 | * 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 | ||
149 | * be created if necessary. If the function is successful, it returns #GNUNET_YES, otherwise #GNUNET_NO. | ||
150 | * | ||
151 | * The room will be entered through the peer identitied by the peer identity provided as <i>door</i> parameter and | ||
152 | * a new connection will be made. | ||
153 | * | ||
154 | * @param[in,out] service Service | ||
155 | * @param[in,out] handle Handle | ||
156 | * @param[in] door Peer identity | ||
157 | * @param[in] key Key of room | ||
158 | * @return #GNUNET_YES on success, otherwise #GNUNET_NO | ||
159 | */ | ||
160 | int | ||
161 | entry_service_room (struct GNUNET_MESSENGER_Service *service, | ||
162 | struct GNUNET_MESSENGER_SrvHandle *handle, | ||
163 | const struct GNUNET_PeerIdentity *door, | ||
164 | const struct GNUNET_HashCode *key); | ||
165 | |||
166 | /** | ||
167 | * 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 | ||
168 | * be created if necessary. If the function is successful, it returns #GNUNET_YES, otherwise #GNUNET_NO. | ||
169 | * | ||
170 | * If the specific handle is currently the host of the room for this service, a new handle which is a member will | ||
171 | * take its place. Otherwise the room will be destroyed for this service. | ||
172 | * | ||
173 | * @param[in,out] service Service | ||
174 | * @param[in,out] handle Handle | ||
175 | * @param[in] key Key of room | ||
176 | * @return #GNUNET_YES on success, otherwise #GNUNET_NO | ||
177 | */ | ||
178 | int | ||
179 | close_service_room (struct GNUNET_MESSENGER_Service *service, | ||
180 | struct GNUNET_MESSENGER_SrvHandle *handle, | ||
181 | const struct GNUNET_HashCode *key); | ||
182 | |||
183 | /** | ||
184 | * Sends a received or sent <i>message</i> with a given <i>hash</i> to each handle of a <i>service</i> which | ||
185 | * is currently member of a specific <i>room</i> for handling it in the client API. | ||
186 | * | ||
187 | * @param[in,out] service Service | ||
188 | * @param[in,out] room Room | ||
189 | * @param[in] session Sender session | ||
190 | * @param[in] message Message | ||
191 | * @param[in] hash Hash of message | ||
192 | */ | ||
193 | void | ||
194 | handle_service_message (struct GNUNET_MESSENGER_Service *service, | ||
195 | struct GNUNET_MESSENGER_SrvRoom *room, | ||
196 | const struct GNUNET_MESSENGER_SenderSession *session, | ||
197 | const struct GNUNET_MESSENGER_Message *message, | ||
198 | const struct GNUNET_HashCode *hash); | ||
199 | |||
200 | #endif //GNUNET_SERVICE_MESSENGER_SERVICE_H | ||