aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/messenger_api_message.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/messenger_api_message.h')
-rw-r--r--src/messenger/messenger_api_message.h119
1 files changed, 77 insertions, 42 deletions
diff --git a/src/messenger/messenger_api_message.h b/src/messenger/messenger_api_message.h
index 0f0a97e9c..7ce30dc92 100644
--- a/src/messenger/messenger_api_message.h
+++ b/src/messenger/messenger_api_message.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2020 GNUnet e.V. 3 Copyright (C) 2020--2021 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -36,10 +36,17 @@
36 36
37#include "messenger_api_ego.h" 37#include "messenger_api_ego.h"
38 38
39#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE (GNUNET_MAX_MESSAGE_SIZE - GNUNET_MIN_MESSAGE_SIZE)
40
41#define GNUNET_MESSENGER_PADDING_MIN (sizeof(uint16_t) + sizeof(char))
42#define GNUNET_MESSENGER_PADDING_LEVEL0 (512)
43#define GNUNET_MESSENGER_PADDING_LEVEL1 (4096)
44#define GNUNET_MESSENGER_PADDING_LEVEL2 (32768)
45
39/** 46/**
40 * Creates and allocates a new message with a specific <i>kind</i>. 47 * Creates and allocates a new message with a specific <i>kind</i>.
41 * 48 *
42 * @param kind Kind of message 49 * @param[in] kind Kind of message
43 * @return New message 50 * @return New message
44 */ 51 */
45struct GNUNET_MESSENGER_Message* 52struct GNUNET_MESSENGER_Message*
@@ -48,7 +55,7 @@ create_message (enum GNUNET_MESSENGER_MessageKind kind);
48/** 55/**
49 * Creates and allocates a copy of a given <i>message</i>. 56 * Creates and allocates a copy of a given <i>message</i>.
50 * 57 *
51 * @param message Message 58 * @param[in] message Message
52 * @return New message 59 * @return New message
53 */ 60 */
54struct GNUNET_MESSENGER_Message* 61struct GNUNET_MESSENGER_Message*
@@ -57,15 +64,24 @@ copy_message (const struct GNUNET_MESSENGER_Message *message);
57/** 64/**
58 * Destroys a message and frees its memory fully. 65 * Destroys a message and frees its memory fully.
59 * 66 *
60 * @param message Message 67 * @param[in/out] message Message
61 */ 68 */
62void 69void
63destroy_message (struct GNUNET_MESSENGER_Message *message); 70destroy_message (struct GNUNET_MESSENGER_Message *message);
64 71
65/** 72/**
73 * Returns if the message should be bound to a member session.
74 *
75 * @param[in] message Message
76 * @return #GNUNET_YES or #GNUNET_NO
77 */
78int
79is_message_session_bound (const struct GNUNET_MESSENGER_Message *message);
80
81/**
66 * Returns the minimal size in bytes to encode a message of a specific <i>kind</i>. 82 * Returns the minimal size in bytes to encode a message of a specific <i>kind</i>.
67 * 83 *
68 * @param kind Kind of message 84 * @param[in] kind Kind of message
69 * @return Minimal size to encode 85 * @return Minimal size to encode
70 */ 86 */
71uint16_t 87uint16_t
@@ -74,57 +90,66 @@ get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind);
74/** 90/**
75 * Returns the exact size in bytes to encode a given <i>message</i>. 91 * Returns the exact size in bytes to encode a given <i>message</i>.
76 * 92 *
77 * @param message Message 93 * @param[in] message Message
94 * @param[in] encode_signature Flag to include signature
78 * @return Size to encode 95 * @return Size to encode
79 */ 96 */
80uint16_t 97uint16_t
81get_message_size (const struct GNUNET_MESSENGER_Message *message); 98get_message_size (const struct GNUNET_MESSENGER_Message *message,
99 int include_signature);
82 100
83/** 101/**
84 * Encodes a given <i>message</i> into a <i>buffer</i> of a maximal <i>length</i> in bytes. 102 * Encodes a given <i>message</i> into a <i>buffer</i> of a maximal <i>length</i> in bytes.
85 * 103 *
86 * @param message Message 104 * @param[in] message Message
87 * @param length Maximal length to encode 105 * @param[in] length Maximal length to encode
88 * @param[out] buffer Buffer 106 * @param[out] buffer Buffer
107 * @param[in] encode_signature Flag to include signature
89 */ 108 */
90void 109void
91encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer); 110encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer,
111 int include_signature);
92 112
93/** 113/**
94 * Decodes a <i>message</i> from a given <i>buffer</i> of a maximal <i>length</i> in bytes. 114 * Decodes a <i>message</i> from a given <i>buffer</i> of a maximal <i>length</i> in bytes.
95 * 115 *
96 * If the buffer is too small for a message of its decoded kind the function fails with 116 * If the buffer is too small for a message of its decoded kind the function fails with
97 * resulting GNUNET_NO after decoding only the messages header. 117 * resulting #GNUNET_NO after decoding only the messages header.
98 * 118 *
99 * On success the function returns GNUNET_YES. 119 * On success the function returns #GNUNET_YES.
100 * 120 *
101 * @param[out] message Message 121 * @param[out] message Message
102 * @param length Maximal length to decode 122 * @param[in] length Maximal length to decode
103 * @param buffer Buffer 123 * @param[in] buffer Buffer
104 * @return GNUNET_YES on success, otherwise GNUNET_NO 124 * @param[out] padding Padding
125 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
105 */ 126 */
106int 127int
107decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer); 128decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer,
129 int include_signature, uint16_t *padding);
108 130
109/** 131/**
110 * Calculates a <i>hash</i> of a given <i>buffer</i> of a <i>length</i> in bytes. 132 * Calculates a <i>hash</i> of a given <i>buffer</i> with a <i>length</i> in bytes
133 * from a <i>message</i>.
111 * 134 *
112 * @param length Length of buffer 135 * @param[in] message Message
113 * @param buffer Buffer 136 * @param[in] length Length of buffer
137 * @param[in] buffer Buffer
114 * @param[out] hash Hash 138 * @param[out] hash Hash
115 */ 139 */
116void 140void
117hash_message (uint16_t length, const char *buffer, struct GNUNET_HashCode *hash); 141hash_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer,
142 struct GNUNET_HashCode *hash);
118 143
119/** 144/**
120 * Signs the <i>hash</i> of a <i>message</i> with a given <i>ego</i> and writes the signature 145 * Signs the <i>hash</i> of a <i>message</i> with a given <i>ego</i> and writes the signature
121 * into the <i>buffer</i> as well. 146 * into the <i>buffer</i> as well.
122 * 147 *
123 * @param[out] message Message 148 * @param[in/out] message Message
124 * @param length Length of buffer 149 * @param[in] length Length of buffer
125 * @param[out] buffer Buffer 150 * @param[out] buffer Buffer
126 * @param hash Hash of message 151 * @param[in] hash Hash of message
127 * @param ego EGO 152 * @param[in] ego EGO
128 */ 153 */
129void 154void
130sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, 155sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer,
@@ -132,13 +157,13 @@ sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *b
132 157
133/** 158/**
134 * Verifies the signature of a given <i>message</i> and its <i>hash</i> with a specific 159 * Verifies the signature of a given <i>message</i> and its <i>hash</i> with a specific
135 * public key. The function returns GNUNET_OK if the signature was valid, otherwise 160 * public key. The function returns #GNUNET_OK if the signature was valid, otherwise
136 * GNUNET_SYSERR. 161 * #GNUNET_SYSERR.
137 * 162 *
138 * @param message Message 163 * @param[in] message Message
139 * @param hash Hash of message 164 * @param[in] hash Hash of message
140 * @param key Public key of EGO 165 * @param[in] key Public key of EGO
141 * @return GNUNET_OK on success, otherwise GNUNET_SYSERR 166 * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR
142 */ 167 */
143int 168int
144verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, 169verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash,
@@ -147,23 +172,23 @@ verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNU
147/** 172/**
148 * Encrypts a <i>message</i> using a given public <i>key</i> and replaces its body 173 * Encrypts a <i>message</i> using a given public <i>key</i> and replaces its body
149 * and kind with the now private encrypted <i>message</i>. The function returns 174 * and kind with the now private encrypted <i>message</i>. The function returns
150 * GNUNET_YES if the operation succeeded, otherwise GNUNET_NO. 175 * #GNUNET_YES if the operation succeeded, otherwise #GNUNET_NO.
151 * 176 *
152 * @param message Message 177 * @param[in/out] message Message
153 * @param key Public key of EGO 178 * @param[in] key Public key of EGO
154 * @return GNUNET_YES on success, otherwise GNUNET_NO 179 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
155 */ 180 */
156int 181int
157encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PublicKey *key); 182encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PublicKey *key);
158 183
159/** 184/**
160 * Decrypts a private <i>message</i> using a given private <i>key</i> and replaces its body 185 * Decrypts a private <i>message</i> using a given private <i>key</i> and replaces its body
161 * and kind with the inner encrypted message. The function returns GNUNET_YES if the 186 * and kind with the inner encrypted message. The function returns #GNUNET_YES if the
162 * operation succeeded, otherwise GNUNET_NO. 187 * operation succeeded, otherwise #GNUNET_NO.
163 * 188 *
164 * @param message Message 189 * @param[in/out] message Message
165 * @param key Private key of EGO 190 * @param[in] key Private key of EGO
166 * @return GNUNET_YES on success, otherwise GNUNET_NO 191 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
167 */ 192 */
168int 193int
169decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key); 194decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key);
@@ -173,18 +198,28 @@ decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_I
173 198
174/** 199/**
175 * Encodes the <i>message</i> to pack it into a newly allocated envelope if <i>mode</i> 200 * Encodes the <i>message</i> to pack it into a newly allocated envelope if <i>mode</i>
176 * is equal to GNUNET_MESSENGER_PACK_MODE_ENVELOPE. Independent of the mode the message 201 * is equal to #GNUNET_MESSENGER_PACK_MODE_ENVELOPE. Independent of the mode the message
177 * will be hashed if <i>hash</i> is not NULL and it will be signed if the <i>ego</i> is 202 * will be hashed if <i>hash</i> is not NULL and it will be signed if the <i>ego</i> is
178 * not NULL. 203 * not NULL.
179 * 204 *
180 * @param[out] message Message 205 * @param[out] message Message
181 * @param[out] hash Hash of message 206 * @param[out] hash Hash of message
182 * @param ego EGO to sign 207 * @param[in] ego EGO to sign
183 * @param mode Mode of packing 208 * @param[in] mode Mode of packing
184 * @return Envelope or NULL 209 * @return Envelope or NULL
185 */ 210 */
186struct GNUNET_MQ_Envelope* 211struct GNUNET_MQ_Envelope*
187pack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, 212pack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash,
188 const struct GNUNET_MESSENGER_Ego *ego, int mode); 213 const struct GNUNET_MESSENGER_Ego *ego, int mode);
189 214
215/**
216 * Returns if a specific kind of message should be sent by a client. The function returns
217 * #GNUNET_YES or #GNUNET_NO for recommendations and #GNUNET_SYSERR for specific kinds
218 * of messages which should not be sent manually at all.
219 *
220 * @param[in] message Message
221 */
222int
223filter_message_sending (const struct GNUNET_MESSENGER_Message *message);
224
190#endif //GNUNET_MESSENGER_API_MESSAGE_H 225#endif //GNUNET_MESSENGER_API_MESSAGE_H