GNUnet  0.20.0
messenger_api_message.h
Go to the documentation of this file.
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  */
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"
32 #include "gnunet_signatures.h"
33 
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 
53 
61 copy_message (const struct GNUNET_MESSENGER_Message *message);
62 
68 void
70 
76 void
78 
85 int
87 
95 uint16_t
97  int include_header);
98 
106 uint16_t
107 get_message_size (const struct GNUNET_MESSENGER_Message *message,
108  int include_header);
109 
118 void
119 encode_message (const struct GNUNET_MESSENGER_Message *message,
120  uint16_t length,
121  char *buffer,
122  int include_header);
123 
139 int
141  uint16_t length,
142  const char *buffer,
143  int include_header,
144  uint16_t *padding);
145 
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 
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 
188 int
189 verify_message (const struct GNUNET_MESSENGER_Message *message,
190  const struct GNUNET_HashCode *hash,
191  const struct GNUNET_IDENTITY_PublicKey *key);
192 
202 int
204  const struct GNUNET_IDENTITY_PublicKey *key);
205 
215 int
217  const struct GNUNET_IDENTITY_PrivateKey *key);
218 
219 #define GNUNET_MESSENGER_PACK_MODE_ENVELOPE 0x1
220 #define GNUNET_MESSENGER_PACK_MODE_UNKNOWN 0x0
221 
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 
247 int
248 filter_message_sending (const struct GNUNET_MESSENGER_Message *message);
249 
250 #endif //GNUNET_MESSENGER_API_MESSAGE_H
struct GNUNET_HashCode key
The key used in the DHT.
static enum @8 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
Identity service; implements identity management for GNUnet.
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
GNUnet MESSENGER service.
int decrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key)
Decrypts a private message using a given private key and replaces its body and kind with the inner en...
void sign_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego)
Signs the hash of a message with a given ego and writes the signature into the buffer as well.
struct GNUNET_MQ_Envelope * pack_message(struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego, int mode)
Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_P...
int filter_message_sending(const struct GNUNET_MESSENGER_Message *message)
Returns if a specific kind of message should be sent by a client.
int encrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PublicKey *key)
Encrypts a message using a given public key and replaces its body and kind with the now private encry...
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
int is_message_session_bound(const struct GNUNET_MESSENGER_Message *message)
Returns if the message should be bound to a member session.
void hash_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer with a length in bytes from a message.
int verify_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_IDENTITY_PublicKey *key)
Verifies the signature of a given message and its hash with a specific public key.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, int include_header)
Encodes a given message into a buffer of a maximal length in bytes.
int decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, int include_header, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind, int include_header)
Returns the minimal size in bytes to encode a message of a specific kind.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, int include_header)
Returns the exact size in bytes to encode a given message.
void cleanup_message(struct GNUNET_MESSENGER_Message *message)
Frees the messages body memory.
A 512-bit hashcode.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.