diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-19 12:53:29 +0200 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-19 12:53:29 +0200 |
commit | 7ef64b65a42cdb65ef2e36649ff84fcf4bb00c66 (patch) | |
tree | 975a7cebf0ed685ab776152db1be67d01171c6e5 /src/messenger/messenger_api_message.h | |
parent | 39e327905f421c470b9cbd5c1ea548261bcae026 (diff) | |
download | gnunet-7ef64b65a42cdb65ef2e36649ff84fcf4bb00c66.tar.gz gnunet-7ef64b65a42cdb65ef2e36649ff84fcf4bb00c66.zip |
BUILD: Move messenger to service
Diffstat (limited to 'src/messenger/messenger_api_message.h')
-rw-r--r-- | src/messenger/messenger_api_message.h | 250 |
1 files changed, 0 insertions, 250 deletions
diff --git a/src/messenger/messenger_api_message.h b/src/messenger/messenger_api_message.h deleted file mode 100644 index 0c2d4acf2..000000000 --- a/src/messenger/messenger_api_message.h +++ /dev/null | |||
@@ -1,250 +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_message.h | ||
23 | * @brief messenger api: client and service implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_MESSENGER_API_MESSAGE_H | ||
27 | #define GNUNET_MESSENGER_API_MESSAGE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_identity_service.h" | ||
32 | #include "gnunet_signatures.h" | ||
33 | |||
34 | #include "gnunet_messenger_service.h" | ||
35 | |||
36 | #include "messenger_api_ego.h" | ||
37 | |||
38 | #define GNUNET_MESSENGER_MAX_MESSAGE_SIZE (GNUNET_MAX_MESSAGE_SIZE - GNUNET_MIN_MESSAGE_SIZE) | ||
39 | |||
40 | #define GNUNET_MESSENGER_PADDING_MIN (sizeof(uint16_t) + sizeof(char)) | ||
41 | #define GNUNET_MESSENGER_PADDING_LEVEL0 (512) | ||
42 | #define GNUNET_MESSENGER_PADDING_LEVEL1 (4096) | ||
43 | #define GNUNET_MESSENGER_PADDING_LEVEL2 (32768) | ||
44 | |||
45 | /** | ||
46 | * Creates and allocates a new message with a specific <i>kind</i>. | ||
47 | * | ||
48 | * @param[in] kind Kind of message | ||
49 | * @return New message | ||
50 | */ | ||
51 | struct GNUNET_MESSENGER_Message* | ||
52 | create_message (enum GNUNET_MESSENGER_MessageKind kind); | ||
53 | |||
54 | /** | ||
55 | * Creates and allocates a copy of a given <i>message</i>. | ||
56 | * | ||
57 | * @param[in] message Message | ||
58 | * @return New message | ||
59 | */ | ||
60 | struct GNUNET_MESSENGER_Message* | ||
61 | copy_message (const struct GNUNET_MESSENGER_Message *message); | ||
62 | |||
63 | /** | ||
64 | * Frees the messages body memory. | ||
65 | * | ||
66 | * @param[in,out] message Message | ||
67 | */ | ||
68 | void | ||
69 | cleanup_message (struct GNUNET_MESSENGER_Message *message); | ||
70 | |||
71 | /** | ||
72 | * Destroys a message and frees its memory fully. | ||
73 | * | ||
74 | * @param[in,out] message Message | ||
75 | */ | ||
76 | void | ||
77 | destroy_message (struct GNUNET_MESSENGER_Message *message); | ||
78 | |||
79 | /** | ||
80 | * Returns if the message should be bound to a member session. | ||
81 | * | ||
82 | * @param[in] message Message | ||
83 | * @return #GNUNET_YES or #GNUNET_NO | ||
84 | */ | ||
85 | int | ||
86 | is_message_session_bound (const struct GNUNET_MESSENGER_Message *message); | ||
87 | |||
88 | /** | ||
89 | * Returns the minimal size in bytes to encode a message of a specific <i>kind</i>. | ||
90 | * | ||
91 | * @param[in] kind Kind of message | ||
92 | * @param[in] include_header Flag to include header | ||
93 | * @return Minimal size to encode | ||
94 | */ | ||
95 | uint16_t | ||
96 | get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind, | ||
97 | int include_header); | ||
98 | |||
99 | /** | ||
100 | * Returns the exact size in bytes to encode a given <i>message</i>. | ||
101 | * | ||
102 | * @param[in] message Message | ||
103 | * @param[in] include_header Flag to include header | ||
104 | * @return Size to encode | ||
105 | */ | ||
106 | uint16_t | ||
107 | get_message_size (const struct GNUNET_MESSENGER_Message *message, | ||
108 | int include_header); | ||
109 | |||
110 | /** | ||
111 | * Encodes a given <i>message</i> into a <i>buffer</i> of a maximal <i>length</i> in bytes. | ||
112 | * | ||
113 | * @param[in] message Message | ||
114 | * @param[in] length Maximal length to encode | ||
115 | * @param[out] buffer Buffer | ||
116 | * @param[in] include_header Flag to include header | ||
117 | */ | ||
118 | void | ||
119 | encode_message (const struct GNUNET_MESSENGER_Message *message, | ||
120 | uint16_t length, | ||
121 | char *buffer, | ||
122 | int include_header); | ||
123 | |||
124 | /** | ||
125 | * Decodes a <i>message</i> from a given <i>buffer</i> of a maximal <i>length</i> in bytes. | ||
126 | * | ||
127 | * If the buffer is too small for a message of its decoded kind the function fails with | ||
128 | * resulting #GNUNET_NO after decoding only the messages header. | ||
129 | * | ||
130 | * On success the function returns #GNUNET_YES. | ||
131 | * | ||
132 | * @param[out] message Message | ||
133 | * @param[in] length Maximal length to decode | ||
134 | * @param[in] buffer Buffer | ||
135 | * @param[in] include_header Flag to include header | ||
136 | * @param[out] padding Padding | ||
137 | * @return #GNUNET_YES on success, otherwise #GNUNET_NO | ||
138 | */ | ||
139 | int | ||
140 | decode_message (struct GNUNET_MESSENGER_Message *message, | ||
141 | uint16_t length, | ||
142 | const char *buffer, | ||
143 | int include_header, | ||
144 | uint16_t *padding); | ||
145 | |||
146 | /** | ||
147 | * Calculates a <i>hash</i> of a given <i>buffer</i> with a <i>length</i> in bytes | ||
148 | * from a <i>message</i>. | ||
149 | * | ||
150 | * @param[in] message Message | ||
151 | * @param[in] length Length of buffer | ||
152 | * @param[in] buffer Buffer | ||
153 | * @param[out] hash Hash | ||
154 | */ | ||
155 | void | ||
156 | hash_message (const struct GNUNET_MESSENGER_Message *message, | ||
157 | uint16_t length, | ||
158 | const char *buffer, | ||
159 | struct GNUNET_HashCode *hash); | ||
160 | |||
161 | /** | ||
162 | * Signs the <i>hash</i> of a <i>message</i> with a given <i>ego</i> and writes the signature | ||
163 | * into the <i>buffer</i> as well. | ||
164 | * | ||
165 | * @param[in,out] message Message | ||
166 | * @param[in] length Length of buffer | ||
167 | * @param[out] buffer Buffer | ||
168 | * @param[in] hash Hash of message | ||
169 | * @param[in] ego EGO | ||
170 | */ | ||
171 | void | ||
172 | sign_message (struct GNUNET_MESSENGER_Message *message, | ||
173 | uint16_t length, | ||
174 | char *buffer, | ||
175 | const struct GNUNET_HashCode *hash, | ||
176 | const struct GNUNET_MESSENGER_Ego *ego); | ||
177 | |||
178 | /** | ||
179 | * Verifies the signature of a given <i>message</i> and its <i>hash</i> with a specific | ||
180 | * public key. The function returns #GNUNET_OK if the signature was valid, otherwise | ||
181 | * #GNUNET_SYSERR. | ||
182 | * | ||
183 | * @param[in] message Message | ||
184 | * @param[in] hash Hash of message | ||
185 | * @param[in] key Public key of EGO | ||
186 | * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR | ||
187 | */ | ||
188 | int | ||
189 | verify_message (const struct GNUNET_MESSENGER_Message *message, | ||
190 | const struct GNUNET_HashCode *hash, | ||
191 | const struct GNUNET_CRYPTO_PublicKey *key); | ||
192 | |||
193 | /** | ||
194 | * Encrypts a <i>message</i> using a given public <i>key</i> and replaces its body | ||
195 | * and kind with the now private encrypted <i>message</i>. The function returns | ||
196 | * #GNUNET_YES if the operation succeeded, otherwise #GNUNET_NO. | ||
197 | * | ||
198 | * @param[in,out] message Message | ||
199 | * @param[in] key Public key of EGO | ||
200 | * @return #GNUNET_YES on success, otherwise #GNUNET_NO | ||
201 | */ | ||
202 | int | ||
203 | encrypt_message (struct GNUNET_MESSENGER_Message *message, | ||
204 | const struct GNUNET_CRYPTO_PublicKey *key); | ||
205 | |||
206 | /** | ||
207 | * Decrypts a private <i>message</i> using a given private <i>key</i> and replaces its body | ||
208 | * and kind with the inner encrypted message. The function returns #GNUNET_YES if the | ||
209 | * operation succeeded, otherwise #GNUNET_NO. | ||
210 | * | ||
211 | * @param[in,out] message Message | ||
212 | * @param[in] key Private key of EGO | ||
213 | * @return #GNUNET_YES on success, otherwise #GNUNET_NO | ||
214 | */ | ||
215 | int | ||
216 | decrypt_message (struct GNUNET_MESSENGER_Message *message, | ||
217 | const struct GNUNET_CRYPTO_PrivateKey *key); | ||
218 | |||
219 | #define GNUNET_MESSENGER_PACK_MODE_ENVELOPE 0x1 | ||
220 | #define GNUNET_MESSENGER_PACK_MODE_UNKNOWN 0x0 | ||
221 | |||
222 | /** | ||
223 | * Encodes the <i>message</i> to pack it into a newly allocated envelope if <i>mode</i> | ||
224 | * is equal to #GNUNET_MESSENGER_PACK_MODE_ENVELOPE. Independent of the mode the message | ||
225 | * will be hashed if <i>hash</i> is not NULL and it will be signed if the <i>ego</i> is | ||
226 | * not NULL. | ||
227 | * | ||
228 | * @param[out] message Message | ||
229 | * @param[out] hash Hash of message | ||
230 | * @param[in] ego EGO to sign | ||
231 | * @param[in] mode Mode of packing | ||
232 | * @return Envelope or NULL | ||
233 | */ | ||
234 | struct GNUNET_MQ_Envelope* | ||
235 | pack_message (struct GNUNET_MESSENGER_Message *message, | ||
236 | struct GNUNET_HashCode *hash, | ||
237 | const struct GNUNET_MESSENGER_Ego *ego, | ||
238 | int mode); | ||
239 | |||
240 | /** | ||
241 | * Returns if a specific kind of message should be sent by a client. The function returns | ||
242 | * #GNUNET_YES or #GNUNET_NO for recommendations and #GNUNET_SYSERR for specific kinds | ||
243 | * of messages which should not be sent manually at all. | ||
244 | * | ||
245 | * @param[in] message Message | ||
246 | */ | ||
247 | int | ||
248 | filter_message_sending (const struct GNUNET_MESSENGER_Message *message); | ||
249 | |||
250 | #endif //GNUNET_MESSENGER_API_MESSAGE_H | ||