GNUnet 0.21.1
messenger_api_message.h
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2024 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 "gnunet_util_lib.h"
30
32
33#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE (GNUNET_MAX_MESSAGE_SIZE \
34 - GNUNET_MIN_MESSAGE_SIZE)
35
36#define GNUNET_MESSENGER_PADDING_MIN (sizeof(uint16_t) + sizeof(char))
37#define GNUNET_MESSENGER_PADDING_LEVEL0 (512)
38#define GNUNET_MESSENGER_PADDING_LEVEL1 (4096)
39#define GNUNET_MESSENGER_PADDING_LEVEL2 (32768)
40
49
57copy_message (const struct GNUNET_MESSENGER_Message *message);
58
66void
69
75void
77
83void
85
94
102uint16_t
104 enum GNUNET_GenericReturnValue include_header);
105
113uint16_t
114get_message_size (const struct GNUNET_MESSENGER_Message *message,
115 enum GNUNET_GenericReturnValue include_header);
116
125void
126encode_message (const struct GNUNET_MESSENGER_Message *message,
127 uint16_t length,
128 char *buffer,
129 enum GNUNET_GenericReturnValue include_header);
130
148 uint16_t length,
149 const char *buffer,
150 enum GNUNET_GenericReturnValue include_header,
151 uint16_t *padding);
152
162void
163hash_message (const struct GNUNET_MESSENGER_Message *message,
164 uint16_t length,
165 const char *buffer,
166 struct GNUNET_HashCode *hash);
167
178void
180 uint16_t length,
181 char *buffer,
182 const struct GNUNET_HashCode *hash,
183 const struct GNUNET_CRYPTO_PrivateKey *key);
184
195void
197 uint16_t length,
198 char *buffer,
199 const struct GNUNET_HashCode *hash,
200 const struct GNUNET_CONFIGURATION_Handle *cfg);
201
213verify_message (const struct GNUNET_MESSENGER_Message *message,
214 const struct GNUNET_HashCode *hash,
215 const struct GNUNET_CRYPTO_PublicKey *key);
216
229 const struct GNUNET_HashCode *hash,
230 const struct GNUNET_PeerIdentity *identity);
231
243 const struct GNUNET_CRYPTO_PublicKey *key);
244
256 const struct GNUNET_CRYPTO_PrivateKey *key);
257
267transcribe_message (const struct GNUNET_MESSENGER_Message *message,
268 const struct GNUNET_CRYPTO_PublicKey *key);
269
280
282 const void *cls,
283 struct GNUNET_MESSENGER_Message *message,
284 uint16_t length,
285 char *buffer,
286 const struct GNUNET_HashCode *hash
287 );
288
290{
293};
294
308struct GNUNET_MQ_Envelope*
310 struct GNUNET_HashCode *hash,
313 const void *cls);
314
324is_peer_message (const struct GNUNET_MESSENGER_Message *message);
325
338is_service_message (const struct GNUNET_MESSENGER_Message *message);
339
350
351#endif //GNUNET_MESSENGER_API_MESSAGE_H
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
static enum @44 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
GNUNET_GenericReturnValue
Named constants for return values.
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
enum GNUNET_GenericReturnValue verify_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_PublicKey *key)
Verifies the signature of a given message and its hash with a specific public key.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
Encodes a given message into a buffer of a maximal length in bytes.
void sign_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_PrivateKey *key)
Signs the hash of a message with a given private key and writes the signature into the buffer as well...
enum GNUNET_GenericReturnValue is_service_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message contains service critical information.
enum GNUNET_GenericReturnValue encrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_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.
GNUNET_MESSENGER_PackMode
@ GNUNET_MESSENGER_PACK_MODE_UNKNOWN
@ GNUNET_MESSENGER_PACK_MODE_ENVELOPE
enum GNUNET_GenericReturnValue filter_message_sending(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message should be sent by a client.
enum GNUNET_GenericReturnValue is_peer_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message can be sent by the service without usage of a clients priv...
enum GNUNET_GenericReturnValue verify_message_by_peer(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_PeerIdentity *identity)
Verifies the signature of a given message and its hash with a specific peer's identity.
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.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_MQ_Envelope * pack_message(struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, const GNUNET_MESSENGER_SignFunction sign, enum GNUNET_MESSENGER_PackMode mode, const void *cls)
Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_P...
enum GNUNET_GenericReturnValue decrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PrivateKey *key)
Decrypts a private message using a given private key and replaces its body and kind with the inner en...
void copy_message_header(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_MESSENGER_MessageHeader *header)
Copy message header details from another message to a given message.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
void(* GNUNET_MESSENGER_SignFunction)(const void *cls, struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash)
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind, enum GNUNET_GenericReturnValue include_header)
Returns the minimal size in bytes to encode a message of a specific kind.
struct GNUNET_MESSENGER_Message * transcribe_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
Transcribes a message as a new transcript message using a given public key from the recipient of the ...
void sign_message_by_peer(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CONFIGURATION_Handle *cfg)
Signs the hash of a message with the peer identity of a given config and writes the signature into th...
enum GNUNET_GenericReturnValue read_transcript_message(struct GNUNET_MESSENGER_Message *message)
Read the original message from a transcript message and replaces its body and kind with the inner enc...
enum GNUNET_GenericReturnValue is_message_session_bound(const struct GNUNET_MESSENGER_Message *message)
Returns if the message should be bound to a member session.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, enum GNUNET_GenericReturnValue include_header)
Returns the exact size in bytes to encode a given message.
enum GNUNET_GenericReturnValue decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, enum GNUNET_GenericReturnValue include_header, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
void cleanup_message(struct GNUNET_MESSENGER_Message *message)
Frees the messages body memory.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
A 512-bit hashcode.
The header of a GNUNET_MESSENGER_Message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
The identity of the host (wraps the signing key of the peer).