GNUnet 0.21.2
messenger_api_message.c File Reference
#include "messenger_api_message.h"
#include "gnunet_common.h"
#include "gnunet_messenger_service.h"
#include "gnunet_signatures.h"
Include dependency graph for messenger_api_message.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_MessageSignature
 
struct  GNUNET_MESSENGER_ShortMessage
 

Macros

#define member_size(type, member)   sizeof(((type*) NULL)->member)
 
#define max(x, y)   (x > y? x : y)
 
#define min(x, y)   (x < y? x : y)
 
#define encode_step_ext(dst, offset, src, size)
 
#define encode_step(dst, offset, src)
 
#define encode_step_key(dst, offset, src, length)
 
#define encode_step_signature(dst, offset, src, length)
 
#define decode_step_ext(src, offset, dst, size)
 
#define decode_step(src, offset, dst)
 
#define decode_step_malloc(src, offset, dst, size, zero)
 
#define decode_step_key(src, offset, dst, length)
 

Typedefs

typedef uint32_t kind_t
 

Functions

struct GNUNET_MESSENGER_Messagecreate_message (enum GNUNET_MESSENGER_MessageKind kind)
 Creates and allocates a new message with a specific kind. More...
 
struct GNUNET_MESSENGER_Messagecopy_message (const struct GNUNET_MESSENGER_Message *message)
 Creates and allocates a copy of a given message. More...
 
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. More...
 
static void destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)
 
void cleanup_message (struct GNUNET_MESSENGER_Message *message)
 Frees the messages body memory. More...
 
void destroy_message (struct GNUNET_MESSENGER_Message *message)
 Destroys a message and frees its memory fully. More...
 
enum GNUNET_GenericReturnValue is_message_session_bound (const struct GNUNET_MESSENGER_Message *message)
 Returns if the message should be bound to a member session. More...
 
static void fold_short_message (const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_ShortMessage *shortened)
 
static void unfold_short_message (struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message)
 
static uint16_t get_message_body_kind_size (enum GNUNET_MESSENGER_MessageKind kind)
 
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. More...
 
static uint16_t get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body)
 
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. More...
 
static uint16_t get_short_message_size (const struct GNUNET_MESSENGER_ShortMessage *message, enum GNUNET_GenericReturnValue include_body)
 
static uint16_t calc_usual_padding ()
 
static uint16_t calc_padded_length (uint16_t length)
 
static void encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, char *buffer, uint16_t offset)
 
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. More...
 
static void encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, char *buffer)
 
static uint16_t decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, const char *buffer, uint16_t offset)
 
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. More...
 
static enum GNUNET_GenericReturnValue decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer)
 
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. More...
 
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. More...
 
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 the buffer as well. More...
 
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. More...
 
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. More...
 
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 encrypted message. More...
 
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 encrypted message. More...
 
struct GNUNET_MESSENGER_Messagetranscribe_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 encrypted message content. More...
 
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 encrypted message. More...
 
struct GNUNET_MQ_Envelopepack_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_PACK_MODE_ENVELOPE. More...
 
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 private key. More...
 
enum GNUNET_GenericReturnValue is_service_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message contains service critical information. More...
 
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. More...
 
const struct GNUNET_ShortHashCodeget_message_discourse (const struct GNUNET_MESSENGER_Message *message)
 Returns the discourse hash of a message depending on its kind. More...
 

Macro Definition Documentation

◆ member_size

#define member_size (   type,
  member 
)    sizeof(((type*) NULL)->member)

Definition at line 276 of file messenger_api_message.c.

◆ max

#define max (   x,
 
)    (x > y? x : y)

Definition at line 476 of file messenger_api_message.c.

◆ min

#define min (   x,
 
)    (x < y? x : y)

Definition at line 505 of file messenger_api_message.c.

◆ encode_step_ext

#define encode_step_ext (   dst,
  offset,
  src,
  size 
)
Value:
do { \
GNUNET_memcpy (dst + offset, src, size); \
offset += size; \
} while (0)
static unsigned int size
Size of the "table".
Definition: peer.c:68

Definition at line 507 of file messenger_api_message.c.

◆ encode_step

#define encode_step (   dst,
  offset,
  src 
)
Value:
do { \
encode_step_ext (dst, offset, src, sizeof(*src)); \
} while (0)

Definition at line 512 of file messenger_api_message.c.

◆ encode_step_key

#define encode_step_key (   dst,
  offset,
  src,
  length 
)
Value:
do { \
src, dst + offset, length - offset \
); \
if (result < 0) \
GNUNET_break (0); \
else \
offset += result; \
} while (0)
static int result
Global testing status.
ssize_t GNUNET_CRYPTO_write_public_key_to_buffer(const struct GNUNET_CRYPTO_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_PublicKey to a compact buffer.
Definition: crypto_pkey.c:145

Definition at line 516 of file messenger_api_message.c.

◆ encode_step_signature

#define encode_step_signature (   dst,
  offset,
  src,
  length 
)
Value:
do { \
src, dst + offset, length - offset \
); \
if (result < 0) \
GNUNET_break (0); \
else \
offset += result; \
} while (0)
ssize_t GNUNET_CRYPTO_write_signature_to_buffer(const struct GNUNET_CRYPTO_Signature *sig, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_Signature to a compact buffer.
Definition: crypto_pkey.c:263

Definition at line 526 of file messenger_api_message.c.

◆ decode_step_ext

#define decode_step_ext (   src,
  offset,
  dst,
  size 
)
Value:
do { \
GNUNET_memcpy (dst, src + offset, size); \
offset += size; \
} while (0)

Definition at line 733 of file messenger_api_message.c.

◆ decode_step

#define decode_step (   src,
  offset,
  dst 
)
Value:
do { \
decode_step_ext (src, offset, dst, sizeof(*dst)); \
} while (0)

Definition at line 738 of file messenger_api_message.c.

◆ decode_step_malloc

#define decode_step_malloc (   src,
  offset,
  dst,
  size,
  zero 
)
Value:
do { \
dst = GNUNET_malloc (size + zero); \
if (zero) dst[size] = 0; \
decode_step_ext (src, offset, dst, size); \
} while (0)
static const struct GNUNET_CRYPTO_PrivateKey zero
Public key of all zeros.
#define GNUNET_malloc(size)
Wrapper around malloc.

Definition at line 742 of file messenger_api_message.c.

◆ decode_step_key

#define decode_step_key (   src,
  offset,
  dst,
  length 
)
Value:
do { \
size_t read; \
src + offset, length - offset, dst, &read \
); \
GNUNET_break (0); \
else \
offset += read; \
} while (0)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_public_key_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_PublicKey *key, size_t *read)
Reads a GNUNET_CRYPTO_PublicKey from a compact buffer.
Definition: crypto_pkey.c:120
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_SYSERR

Definition at line 748 of file messenger_api_message.c.

Typedef Documentation

◆ kind_t

typedef uint32_t kind_t

Definition at line 355 of file messenger_api_message.c.

Function Documentation

◆ create_message()

struct GNUNET_MESSENGER_Message * create_message ( enum GNUNET_MESSENGER_MessageKind  kind)

Creates and allocates a new message with a specific kind.

Parameters
[in]kindKind of message
Returns
New message

Definition at line 45 of file messenger_api_message.c.

46{
47 struct GNUNET_MESSENGER_Message *message = GNUNET_new (struct
49
50 message->header.kind = kind;
51
52 switch (message->header.kind)
53 {
55 message->body.name.name = NULL;
56 break;
58 message->body.text.text = NULL;
59 break;
61 message->body.file.uri = NULL;
62 break;
64 message->body.privacy.length = 0;
65 message->body.privacy.data = NULL;
66 break;
68 message->body.ticket.identifier = NULL;
69 break;
71 message->body.transcript.length = 0;
72 message->body.transcript.data = NULL;
73 break;
75 message->body.tag.tag = NULL;
76 break;
78 message->body.talk.length = 0;
79 message->body.talk.data = NULL;
80 break;
81 default:
82 break;
83 }
84
85 return message;
86}
#define GNUNET_new(type)
Allocate a struct or union of the given type.
@ GNUNET_MESSENGER_KIND_PRIVATE
The private kind.
@ GNUNET_MESSENGER_KIND_TAG
The tag kind.
@ GNUNET_MESSENGER_KIND_FILE
The file kind.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
@ GNUNET_MESSENGER_KIND_TALK
The talk kind.
@ GNUNET_MESSENGER_KIND_TRANSCRIPT
The transcript kind.
@ GNUNET_MESSENGER_KIND_TEXT
The text kind.
@ GNUNET_MESSENGER_KIND_TICKET
The ticket kind.
struct GNUNET_MESSENGER_MessagePrivate privacy
struct GNUNET_MESSENGER_MessageText text
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageTranscript transcript
struct GNUNET_MESSENGER_MessageTalk talk
struct GNUNET_MESSENGER_MessageFile file
struct GNUNET_MESSENGER_MessageTag tag
struct GNUNET_MESSENGER_MessageTicket ticket
char * uri
The uri of the encrypted file.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
char * name
The new name which replaces the current senders name.
uint16_t length
The length of the encrypted message.
char * data
The data of the encrypted message.
uint16_t length
The length of the talk message data.
char * data
The data of the talk message.
char * text
The containing text.
char * identifier
The identifier of a ticket.
uint16_t length
The length of the transcribed message.
char * data
The data of the transcribed message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_new, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by create_message_connection(), create_message_delete(), create_message_id(), create_message_info(), create_message_join(), create_message_key(), create_message_leave(), create_message_merge(), create_message_miss(), create_message_name(), create_message_peer(), create_message_request(), create_message_subscribe(), get_store_message(), and transcribe_message().

Here is the caller graph for this function:

◆ copy_message()

struct GNUNET_MESSENGER_Message * copy_message ( const struct GNUNET_MESSENGER_Message message)

Creates and allocates a copy of a given message.

Parameters
[in]messageMessage
Returns
New message

Definition at line 90 of file messenger_api_message.c.

91{
92 GNUNET_assert (message);
93
94 struct GNUNET_MESSENGER_Message *copy = GNUNET_new (struct
96
97 GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
98
99 switch (message->header.kind)
100 {
102 copy->body.name.name = message->body.name.name? GNUNET_strdup (
103 message->body.name.name) : NULL;
104 break;
106 copy->body.text.text = message->body.text.text? GNUNET_strdup (
107 message->body.text.text) : NULL;
108 break;
110 copy->body.file.uri = message->body.file.uri? GNUNET_strdup (
111 message->body.file.uri) : NULL;
112 break;
115 copy->body.privacy.length) : NULL;
116
117 if (copy->body.privacy.data)
118 GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data,
119 copy->body.privacy.length);
120
121 break;
123 copy->body.ticket.identifier = message->body.ticket.identifier?
125 message->body.ticket.identifier) : NULL;
126 break;
129 copy->body.transcript.length) : NULL;
130
131 if (copy->body.transcript.data)
133 copy->body.transcript.length);
134
135 break;
137 copy->body.tag.tag = message->body.tag.tag? GNUNET_strdup (
138 message->body.tag.tag) : NULL;
139 break;
141 copy->body.talk.data = copy->body.talk.length ? GNUNET_malloc (
142 copy->body.talk.length) : NULL;
143
144 if (copy->body.talk.data)
145 GNUNET_memcpy (copy->body.talk.data, message->body.talk.data,
146 copy->body.talk.length);
147
148 break;
149 default:
150 break;
151 }
152
153 return copy;
154}
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageBody::file, GNUNET_assert, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_new, GNUNET_strdup, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by enqueue_message_control(), forward_tunnel_message(), GNUNET_MESSENGER_send_message(), handle_private_message(), handle_room_message(), handle_transcript_message(), handle_tunnel_message(), and send_srv_handle_message().

Here is the caller graph for this function:

◆ copy_message_header()

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.

Parameters
[in,out]messageMessage
[in]headerMessage header

Definition at line 158 of file messenger_api_message.c.

160{
161 GNUNET_assert ((message) && (header));
162
163 enum GNUNET_MESSENGER_MessageKind kind = message->header.kind;
164
165 GNUNET_memcpy (&(message->header), header,
166 sizeof(struct GNUNET_MESSENGER_MessageHeader));
167
168 message->header.kind = kind;
169}
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
The header of a GNUNET_MESSENGER_Message.

References GNUNET_assert, GNUNET_memcpy, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by handle_room_message(), and handle_transcript_message().

Here is the caller graph for this function:

◆ destroy_message_body()

static void destroy_message_body ( enum GNUNET_MESSENGER_MessageKind  kind,
struct GNUNET_MESSENGER_MessageBody body 
)
static

Definition at line 173 of file messenger_api_message.c.

175{
176 switch (kind)
177 {
179 if (body->name.name)
180 GNUNET_free (body->name.name);
181 break;
183 if (body->text.text)
184 GNUNET_free (body->text.text);
185 break;
187 if (body->file.uri)
188 GNUNET_free (body->file.uri);
189 break;
191 if (body->privacy.data)
192 GNUNET_free (body->privacy.data);
193 break;
195 if (body->ticket.identifier)
197 break;
199 if (body->transcript.data)
201 break;
203 if (body->tag.tag)
204 GNUNET_free (body->tag.tag);
205 break;
207 if (body->talk.data)
208 GNUNET_free (body->talk.data);
209 break;
210 default:
211 break;
212 }
213}
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageBody::file, GNUNET_free, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by cleanup_message(), destroy_message(), encrypt_message(), and unfold_short_message().

Here is the caller graph for this function:

◆ cleanup_message()

void cleanup_message ( struct GNUNET_MESSENGER_Message message)

Frees the messages body memory.

Parameters
[in,out]messageMessage

Definition at line 217 of file messenger_api_message.c.

218{
219 GNUNET_assert (message);
220
221 destroy_message_body (message->header.kind, &(message->body));
222}
static void destroy_message_body(enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)

References GNUNET_MESSENGER_Message::body, destroy_message_body(), GNUNET_assert, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by check_recv_message(), check_send_message(), handle_recv_message(), handle_send_message(), and handle_tunnel_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_message()

void destroy_message ( struct GNUNET_MESSENGER_Message message)

Destroys a message and frees its memory fully.

Parameters
[in,out]messageMessage

Definition at line 226 of file messenger_api_message.c.

227{
228 GNUNET_assert (message);
229
230 destroy_message_body (message->header.kind, &(message->body));
231
232 GNUNET_free (message);
233}

References GNUNET_MESSENGER_Message::body, destroy_message_body(), GNUNET_assert, GNUNET_free, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by clear_queue_messages(), create_message_peer(), dequeue_from_messages(), dequeue_message_from_room(), destroy_message_control(), enqueue_to_messages(), forward_tunnel_message(), get_store_message(), handle_delete_message(), handle_discourse_subscription(), handle_private_message(), handle_transcript_message(), iterate_destroy_message(), iterate_destroy_messages(), iterate_destroy_subscription(), iterate_flag_for_cleanup_discourse_message(), keep_subscription_alive(), send_message_to_room_with_key(), send_tunnel_message(), task_message_control(), and update_room_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_message_session_bound()

enum GNUNET_GenericReturnValue is_message_session_bound ( const struct GNUNET_MESSENGER_Message message)

Returns if the message should be bound to a member session.

Parameters
[in]messageMessage
Returns
GNUNET_YES or GNUNET_NO

Definition at line 237 of file messenger_api_message.c.

238{
239 GNUNET_assert (message);
240
241 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) ||
243 (GNUNET_MESSENGER_KIND_NAME == message->header.kind) ||
244 (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
246 return GNUNET_YES;
247 else
248 return GNUNET_NO;
249}
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.

References GNUNET_assert, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_NAME, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by enqueue_message_to_room(), and update_member_session_history().

Here is the caller graph for this function:

◆ fold_short_message()

static void fold_short_message ( const struct GNUNET_MESSENGER_Message message,
struct GNUNET_MESSENGER_ShortMessage shortened 
)
static

Definition at line 253 of file messenger_api_message.c.

255{
256 shortened->kind = message->header.kind;
257
258 GNUNET_memcpy (&(shortened->body), &(message->body), sizeof(struct
260}
The unified body of a GNUNET_MESSENGER_Message.
struct GNUNET_MESSENGER_MessageBody body
enum GNUNET_MESSENGER_MessageKind kind

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_ShortMessage::body, GNUNET_memcpy, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by encrypt_message(), and transcribe_message().

Here is the caller graph for this function:

◆ unfold_short_message()

static void unfold_short_message ( struct GNUNET_MESSENGER_ShortMessage shortened,
struct GNUNET_MESSENGER_Message message 
)
static

Definition at line 264 of file messenger_api_message.c.

266{
267 destroy_message_body (message->header.kind, &(message->body));
268
269 message->header.kind = shortened->kind;
270
271 GNUNET_memcpy (&(message->body), &(shortened->body),
272 sizeof(struct GNUNET_MESSENGER_MessageBody));
273}

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_ShortMessage::body, destroy_message_body(), GNUNET_memcpy, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by decrypt_message(), encrypt_message(), and read_transcript_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_message_body_kind_size()

static uint16_t get_message_body_kind_size ( enum GNUNET_MESSENGER_MessageKind  kind)
static

Definition at line 279 of file messenger_api_message.c.

280{
281 uint16_t length = 0;
282
283 switch (kind)
284 {
286 length += member_size (struct GNUNET_MESSENGER_Message,
287 body.info.messenger_version);
288 break;
290 length += member_size (struct GNUNET_MESSENGER_Message, body.peer.peer);
291 break;
293 length += member_size (struct GNUNET_MESSENGER_Message, body.id.id);
294 break;
296 length += member_size (struct GNUNET_MESSENGER_Message, body.miss.peer);
297 break;
299 length += member_size (struct GNUNET_MESSENGER_Message,
300 body.merge.previous);
301 break;
303 length += member_size (struct GNUNET_MESSENGER_Message, body.request.hash);
304 break;
306 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.door);
307 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.key);
308 break;
310 length += member_size (struct GNUNET_MESSENGER_Message, body.file.key);
311 length += member_size (struct GNUNET_MESSENGER_Message, body.file.hash);
312 length += member_size (struct GNUNET_MESSENGER_Message, body.file.name);
313 break;
315 length += member_size (struct GNUNET_MESSENGER_Message, body.privacy.key);
316 break;
318 length += member_size (struct GNUNET_MESSENGER_Message, body.deletion.hash);
319 length += member_size (struct GNUNET_MESSENGER_Message,
320 body.deletion.delay);
321 break;
323 length += member_size (struct GNUNET_MESSENGER_Message,
324 body.connection.amount);
325 length += member_size (struct GNUNET_MESSENGER_Message,
326 body.connection.flags);
327 break;
329 length += member_size (struct GNUNET_MESSENGER_Message,
330 body.transcript.hash);
331 break;
333 length += member_size (struct GNUNET_MESSENGER_Message, body.tag.hash);
334 break;
336 length += member_size (struct GNUNET_MESSENGER_Message,
337 body.subscribe.discourse);
338 length += member_size (struct GNUNET_MESSENGER_Message,
339 body.subscribe.time);
340 length += member_size (struct GNUNET_MESSENGER_Message,
341 body.subscribe.flags);
342 break;
344 length += member_size (struct GNUNET_MESSENGER_Message,
345 body.talk.discourse);
346 break;
347 default:
348 break;
349 }
350
351 return length;
352}
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_INVITE
The invite kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBE
The subscribe kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_DELETE
The delete kind.
@ GNUNET_MESSENGER_KIND_CONNECTION
The connection kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
#define member_size(type, member)

References GNUNET_MESSENGER_MessageConnection::amount, GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageBody::connection, GNUNET_MESSENGER_MessageDelete::delay, GNUNET_MESSENGER_MessageBody::deletion, GNUNET_MESSENGER_MessageSubscribe::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_MESSENGER_MessageInvite::door, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::flags, GNUNET_MESSENGER_MessageSubscribe::flags, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETE, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_SUBSCRIBE, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageFile::hash, GNUNET_MESSENGER_MessageDelete::hash, GNUNET_MESSENGER_MessageTranscript::hash, GNUNET_MESSENGER_MessageTag::hash, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageFile::key, GNUNET_MESSENGER_MessagePrivate::key, member_size, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageInfo::messenger_version, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessageFile::name, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::request, GNUNET_MESSENGER_MessageBody::subscribe, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageSubscribe::time, and GNUNET_MESSENGER_MessageBody::transcript.

Referenced by get_message_kind_size(), and get_short_message_size().

Here is the caller graph for this function:

◆ get_message_kind_size()

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.

Parameters
[in]kindKind of message
[in]include_headerFlag to include header
Returns
Minimal size to encode

Definition at line 358 of file messenger_api_message.c.

360{
361 uint16_t length = 0;
362
363 if (GNUNET_YES == include_header)
364 {
365 length += member_size (struct GNUNET_MESSENGER_Message, header.timestamp);
366 length += member_size (struct GNUNET_MESSENGER_Message, header.sender_id);
367 length += member_size (struct GNUNET_MESSENGER_Message, header.previous);
368 }
369
370 length += sizeof(kind_t);
371
372 return length + get_message_body_kind_size (kind);
373}
static uint16_t get_message_body_kind_size(enum GNUNET_MESSENGER_MessageKind kind)
uint32_t kind_t

References get_message_body_kind_size(), GNUNET_YES, GNUNET_MESSENGER_Message::header, member_size, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageHeader::sender_id, and GNUNET_MESSENGER_MessageHeader::timestamp.

Referenced by calc_usual_padding(), check_recv_message(), check_send_message(), check_tunnel_message(), decode_message(), get_message_size(), and get_store_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_message_body_size()

static uint16_t get_message_body_size ( enum GNUNET_MESSENGER_MessageKind  kind,
const struct GNUNET_MESSENGER_MessageBody body 
)
static

Definition at line 377 of file messenger_api_message.c.

379{
380 uint16_t length = 0;
381
382 switch (kind)
383 {
385 length += GNUNET_CRYPTO_public_key_get_length (&(body->join.key));
386 break;
388 length += (body->name.name ? strlen (body->name.name) : 0);
389 break;
391 length += GNUNET_CRYPTO_public_key_get_length (&(body->key.key));
392 break;
394 length += (body->text.text ? strlen (body->text.text) : 0);
395 break;
397 length += (body->file.uri ? strlen (body->file.uri) : 0);
398 break;
400 length += body->privacy.length;
401 break;
403 length += (body->ticket.identifier ? strlen (body->ticket.identifier) : 0);
404 break;
407 length += body->transcript.length;
408 break;
410 length += (body->tag.tag ? strlen (body->tag.tag) : 0);
411 break;
413 length += body->talk.length;
414 break;
415 default:
416 break;
417 }
418
419 return length;
420}
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
Definition: crypto_pkey.c:85
struct GNUNET_MESSENGER_MessageKey key
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_CRYPTO_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_CRYPTO_PublicKey key
The new public key which replaces the current senders public key.
struct GNUNET_CRYPTO_PublicKey key
The key from the recipient of the original message.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageBody::file, GNUNET_CRYPTO_public_key_get_length(), GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageTranscript::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by get_message_size(), and get_short_message_size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_message_size()

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.

Parameters
[in]messageMessage
[in]include_headerFlag to include header
Returns
Size to encode

Definition at line 424 of file messenger_api_message.c.

426{
427 GNUNET_assert (message);
428
429 uint16_t length = 0;
430
431 if (GNUNET_YES == include_header)
433 &(message->header.signature));
434
435 length += get_message_kind_size (message->header.kind, include_header);
436 length += get_message_body_size (message->header.kind, &(message->body));
437
438 return length;
439}
ssize_t GNUNET_CRYPTO_signature_get_length(const struct GNUNET_CRYPTO_Signature *sig)
Get the compacted length of a GNUNET_CRYPTO_Signature.
Definition: crypto_pkey.c:206
static uint16_t get_message_body_size(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body)
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_CRYPTO_Signature signature
The signature of the senders private key.

References GNUNET_MESSENGER_Message::body, get_message_body_size(), get_message_kind_size(), GNUNET_assert, GNUNET_CRYPTO_signature_get_length(), GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, and GNUNET_MESSENGER_MessageHeader::signature.

Referenced by iterate_save_messages(), notify_srv_handle_message(), pack_message(), and send_message_to_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_short_message_size()

static uint16_t get_short_message_size ( const struct GNUNET_MESSENGER_ShortMessage message,
enum GNUNET_GenericReturnValue  include_body 
)
static

Definition at line 443 of file messenger_api_message.c.

445{
446 const uint16_t minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t);
447
448 if (message)
449 return minimum_size + get_message_body_kind_size (message->kind)
450 + (include_body == GNUNET_YES?
451 get_message_body_size (message->kind, &(message->body)) : 0);
452 else
453 return minimum_size;
454}
A 512-bit hashcode.

References GNUNET_MESSENGER_ShortMessage::body, get_message_body_kind_size(), get_message_body_size(), GNUNET_YES, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by decode_short_message(), encrypt_message(), and transcribe_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calc_usual_padding()

static uint16_t calc_usual_padding ( )
static

Definition at line 458 of file messenger_api_message.c.

459{
460 uint16_t padding = 0;
461 uint16_t kind_size;
462
463 for (unsigned int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++)
464 {
466 GNUNET_YES);
467
468 if (kind_size > padding)
469 padding = kind_size;
470 }
471
472 return padding + GNUNET_MESSENGER_PADDING_MIN;
473}
#define GNUNET_MESSENGER_KIND_MAX
#define GNUNET_MESSENGER_PADDING_MIN

References get_message_kind_size(), GNUNET_MESSENGER_KIND_MAX, GNUNET_MESSENGER_PADDING_MIN, and GNUNET_YES.

Referenced by calc_padded_length().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calc_padded_length()

static uint16_t calc_padded_length ( uint16_t  length)
static

Definition at line 479 of file messenger_api_message.c.

480{
481 static uint16_t usual_padding = 0;
482
483 if (! usual_padding)
484 usual_padding = calc_usual_padding ();
485
486 const uint16_t padded_length = max (
488 usual_padding
489 );
490
491 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0)
493
494 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL1)
496
497 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL2)
499
501
502}
static uint16_t calc_usual_padding()
#define max(x, y)
#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE
#define GNUNET_MESSENGER_PADDING_LEVEL0
#define GNUNET_MESSENGER_PADDING_LEVEL2
#define GNUNET_MESSENGER_PADDING_LEVEL1

References calc_usual_padding(), GNUNET_MESSENGER_MAX_MESSAGE_SIZE, GNUNET_MESSENGER_PADDING_LEVEL0, GNUNET_MESSENGER_PADDING_LEVEL1, GNUNET_MESSENGER_PADDING_LEVEL2, GNUNET_MESSENGER_PADDING_MIN, and max.

Referenced by encrypt_message(), and pack_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_message_body()

static void encode_message_body ( enum GNUNET_MESSENGER_MessageKind  kind,
const struct GNUNET_MESSENGER_MessageBody body,
uint16_t  length,
char *  buffer,
uint16_t  offset 
)
static

Definition at line 537 of file messenger_api_message.c.

542{
543 uint32_t value0, value1;
544 switch (kind)
545 {
547 value0 = GNUNET_htobe32 (body->info.messenger_version);
548
549 encode_step (buffer, offset, &value0);
550 break;
552 encode_step_key (buffer, offset, &(body->join.key), length);
553 break;
555 break;
557 if (body->name.name)
558 encode_step_ext (buffer, offset, body->name.name, min (length - offset,
559 strlen (
560 body->name.name))
561 );
562 break;
564 encode_step_key (buffer, offset, &(body->key.key), length);
565 break;
567 encode_step (buffer, offset, &(body->peer.peer));
568 break;
570 encode_step (buffer, offset, &(body->id.id));
571 break;
573 encode_step (buffer, offset, &(body->miss.peer));
574 break;
576 encode_step (buffer, offset, &(body->merge.previous));
577 break;
579 encode_step (buffer, offset, &(body->request.hash));
580 break;
582 encode_step (buffer, offset, &(body->invite.door));
583 encode_step (buffer, offset, &(body->invite.key));
584 break;
586 if (body->text.text)
587 encode_step_ext (buffer, offset, body->text.text, min (length - offset,
588 strlen (
589 body->text.text))
590 );
591 break;
593 encode_step (buffer, offset, &(body->file.key));
594 encode_step (buffer, offset, &(body->file.hash));
595 encode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
596 if (body->file.uri)
597 encode_step_ext (buffer, offset, body->file.uri, min (length - offset,
598 strlen (
599 body->file.uri)));
600 break;
602 encode_step (buffer, offset, &(body->privacy.key));
603
604 if (body->privacy.data)
605 encode_step_ext (buffer, offset, body->privacy.data, min (length - offset,
606 body->privacy.
607 length));
608 break;
610 encode_step (buffer, offset, &(body->deletion.hash));
611 encode_step (buffer, offset, &(body->deletion.delay));
612 break;
614 value0 = GNUNET_htobe32 (body->connection.amount);
615 value1 = GNUNET_htobe32 (body->connection.flags);
616
617 encode_step (buffer, offset, &value0);
618 encode_step (buffer, offset, &value1);
619 break;
621 encode_step_ext (buffer, offset, body->ticket.identifier,
622 min (length - offset, strlen (body->ticket.identifier)));
623 break;
625 encode_step (buffer, offset, &(body->transcript.hash));
626 encode_step_key (buffer, offset, &(body->transcript.key), length);
627
628 if (body->transcript.data)
629 encode_step_ext (buffer, offset, body->transcript.data, min (length
630 - offset,
631 body->
632 transcript.
633 length));
634 break;
636 encode_step (buffer, offset, &(body->tag.hash));
637
638 if (body->tag.tag)
639 encode_step_ext (buffer, offset, body->tag.tag, min (length - offset,
640 strlen (
641 body->tag.tag)));
642 break;
644 value0 = GNUNET_htobe32 (body->subscribe.flags);
645
646 encode_step (buffer, offset, &(body->subscribe.discourse));
647 encode_step (buffer, offset, &(body->subscribe.time));
648 encode_step (buffer, offset, &value0);
649 break;
651 encode_step (buffer, offset, &(body->talk.discourse));
652
653 if (body->talk.data)
654 encode_step_ext (buffer, offset, body->talk.data, min (length - offset,
655 body->talk.
656 length));
657 break;
658 default:
659 break;
660 }
661
662 if (offset >= length)
663 return;
664
665 const uint16_t padding = length - offset;
666 const uint16_t used_padding = sizeof(padding) + sizeof(char);
667
668 GNUNET_assert (padding >= used_padding);
669
670 buffer[offset++] = '\0';
671
672 if (padding > used_padding)
674 padding - used_padding);
675
676 GNUNET_memcpy (buffer + length - sizeof(padding), &padding, sizeof(padding));
677}
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_htobe32(x)
#define encode_step_ext(dst, offset, src, size)
#define encode_step(dst, offset, src)
#define min(x, y)
#define encode_step_key(dst, offset, src, length)
struct GNUNET_MESSENGER_MessageConnection connection
struct GNUNET_MESSENGER_MessageSubscribe subscribe
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_MessageInvite invite
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_MESSENGER_MessagePeer peer
struct GNUNET_MESSENGER_MessageDelete deletion
struct GNUNET_MESSENGER_MessageInfo info
uint32_t amount
The amount of connections of a peer.
uint32_t flags
The flags about the connections of a peer.
struct GNUNET_HashCode hash
The hash of the message to delete.
struct GNUNET_TIME_RelativeNBO delay
The delay of the delete operation to get processed.
struct GNUNET_HashCode hash
The hash of the original file.
struct GNUNET_CRYPTO_SymmetricSessionKey key
The symmetric key to decrypt the file.
char name[NAME_MAX]
The name of the original file.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
uint32_t messenger_version
The version of GNUnet Messenger API.
struct GNUNET_HashCode key
The hash identifying the port of the room.
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
struct GNUNET_CRYPTO_EcdhePublicKey key
The ECDH key to decrypt the message.
struct GNUNET_HashCode hash
The hash of the requested message.
uint32_t flags
The flags about the subscription to a discourse.
struct GNUNET_TIME_RelativeNBO time
The time window of the subscription.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscribe.
struct GNUNET_HashCode hash
The hash of the message to tag.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to talk.
struct GNUNET_HashCode hash
The hash of the original message.

References GNUNET_MESSENGER_MessageConnection::amount, GNUNET_MESSENGER_MessageBody::connection, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageDelete::delay, GNUNET_MESSENGER_MessageBody::deletion, GNUNET_MESSENGER_MessageSubscribe::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_MESSENGER_MessageInvite::door, encode_step, encode_step_ext, encode_step_key, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::flags, GNUNET_MESSENGER_MessageSubscribe::flags, GNUNET_assert, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block(), GNUNET_htobe32, GNUNET_memcpy, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETE, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_SUBSCRIBE, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageFile::hash, GNUNET_MESSENGER_MessageDelete::hash, GNUNET_MESSENGER_MessageTranscript::hash, GNUNET_MESSENGER_MessageTag::hash, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageFile::key, GNUNET_MESSENGER_MessagePrivate::key, GNUNET_MESSENGER_MessageTranscript::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageInfo::messenger_version, min, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageFile::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::request, GNUNET_MESSENGER_MessageBody::subscribe, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageSubscribe::time, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by encode_message(), and encode_short_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_message()

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.

Parameters
[in]messageMessage
[in]lengthMaximal length to encode
[out]bufferBuffer
[in]include_headerFlag to include header

Definition at line 681 of file messenger_api_message.c.

685{
686 GNUNET_assert ((message) && (buffer));
687
688 uint16_t offset = 0;
689
690 if (GNUNET_YES == include_header)
691 encode_step_signature (buffer, offset, &(message->header.signature),
692 length);
693
694 const kind_t kind = GNUNET_htobe32 ((kind_t) message->header.kind);
695
696 if (GNUNET_YES == include_header)
697 {
698 encode_step (buffer, offset, &(message->header.timestamp));
699 encode_step (buffer, offset, &(message->header.sender_id));
700 encode_step (buffer, offset, &(message->header.previous));
701 }
702
703 encode_step (buffer, offset, &kind);
704
705 encode_message_body (message->header.kind, &(message->body),
706 length, buffer, offset);
707}
static void encode_message_body(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, char *buffer, uint16_t offset)
#define encode_step_signature(dst, offset, src, length)
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.

References GNUNET_MESSENGER_Message::body, encode_message_body(), encode_step, encode_step_signature, GNUNET_assert, GNUNET_htobe32, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageHeader::sender_id, GNUNET_MESSENGER_MessageHeader::signature, and GNUNET_MESSENGER_MessageHeader::timestamp.

Referenced by iterate_save_messages(), notify_srv_handle_message(), pack_message(), and send_message_to_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_short_message()

static void encode_short_message ( const struct GNUNET_MESSENGER_ShortMessage message,
uint16_t  length,
char *  buffer 
)
static

Definition at line 711 of file messenger_api_message.c.

714{
715 struct GNUNET_HashCode hash;
716 uint16_t offset = sizeof(hash);
717
718 const kind_t kind = GNUNET_htobe32 ((kind_t) message->kind);
719
720 encode_step (buffer, offset, &kind);
721
722 encode_message_body (message->kind, &(message->body), length, buffer, offset);
723
725 buffer + sizeof(hash),
726 length - sizeof(hash),
727 &hash);
728
729 GNUNET_memcpy (buffer, &hash, sizeof(hash));
730}
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41

References GNUNET_MESSENGER_ShortMessage::body, encode_message_body(), encode_step, GNUNET_CRYPTO_hash(), GNUNET_htobe32, GNUNET_memcpy, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by encrypt_message(), and transcribe_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_message_body()

static uint16_t decode_message_body ( enum GNUNET_MESSENGER_MessageKind kind,
struct GNUNET_MESSENGER_MessageBody body,
uint16_t  length,
const char *  buffer,
uint16_t  offset 
)
static

Definition at line 761 of file messenger_api_message.c.

766{
767 uint16_t padding = 0;
768
769 GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding));
770
771 if (padding > length - offset)
772 padding = 0;
773
774 const uint16_t end_zero = length - padding;
775
776 if ((padding) && (buffer[end_zero] != '\0'))
777 padding = 0;
778
779 length -= padding;
780
781 uint32_t value0, value1;
782 switch (*kind)
783 {
785 decode_step (buffer, offset, &value0);
786
787 body->info.messenger_version = GNUNET_be32toh (value0);
788 break;
790 decode_step_key (buffer, offset, &(body->join.key), length);
791 break;
793 break;
795 if (length > offset)
796 decode_step_malloc (buffer, offset, body->name.name, length - offset, 1);
797 else
798 body->name.name = NULL;
799 break;
801 decode_step_key (buffer, offset, &(body->key.key), length);
802 break;
804 decode_step (buffer, offset, &(body->peer.peer));
805 break;
807 decode_step (buffer, offset, &(body->id.id));
808 break;
810 decode_step (buffer, offset, &(body->miss.peer));
811 break;
813 decode_step (buffer, offset, &(body->merge.previous));
814 break;
816 decode_step (buffer, offset, &(body->request.hash));
817 break;
819 decode_step (buffer, offset, &(body->invite.door));
820 decode_step (buffer, offset, &(body->invite.key));
821 break;
823 if (length > offset)
824 decode_step_malloc (buffer, offset, body->text.text, length - offset, 1);
825 else
826 body->text.text = NULL;
827 break;
829 decode_step (buffer, offset, &(body->file.key));
830 decode_step (buffer, offset, &(body->file.hash));
831 decode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
832 if (length > offset)
833 decode_step_malloc (buffer, offset, body->file.uri, length - offset, 1);
834 else
835 body->file.uri = NULL;
836 break;
838 decode_step (buffer, offset, &(body->privacy.key));
839
840 if (length > offset)
841 {
842 body->privacy.length = (length - offset);
843 decode_step_malloc (buffer, offset, body->privacy.data, length - offset,
844 0);
845 }
846 else
847 {
848 body->privacy.length = 0;
849 body->privacy.data = NULL;
850 }
851
852 break;
854 decode_step (buffer, offset, &(body->deletion.hash));
855 decode_step (buffer, offset, &(body->deletion.delay));
856 break;
858 decode_step (buffer, offset, &value0);
859 decode_step (buffer, offset, &value1);
860
861 body->connection.amount = GNUNET_be32toh (value0);
862 body->connection.flags = GNUNET_be32toh (value1);
863 break;
865 if (length > offset)
866 decode_step_malloc (buffer, offset, body->ticket.identifier, length
867 - offset, 1);
868 else
869 body->ticket.identifier = NULL;
870 break;
872 decode_step (buffer, offset, &(body->transcript.hash));
873 decode_step_key (buffer, offset, &(body->transcript.key), length);
874
875 if (length > offset)
876 {
877 body->transcript.length = (length - offset);
878 decode_step_malloc (buffer, offset, body->transcript.data,
879 length - offset, 0);
880 }
881 else
882 {
883 body->transcript.length = 0;
884 body->transcript.data = NULL;
885 }
886
887 break;
889 decode_step (buffer, offset, &(body->tag.hash));
890 if (length > offset)
891 decode_step_malloc (buffer, offset, body->tag.tag, length - offset, 1);
892 else
893 body->tag.tag = NULL;
894 break;
896 decode_step (buffer, offset, &(body->subscribe.discourse));
897 decode_step (buffer, offset, &(body->subscribe.time));
898 decode_step (buffer, offset, &value0);
899
900 body->subscribe.flags = GNUNET_be32toh (value0);
901 break;
903 decode_step (buffer, offset, &(body->talk.discourse));
904
905 if (length > offset)
906 {
907 body->talk.length = (length - offset);
908 decode_step_malloc (buffer, offset, body->talk.data, length - offset,
909 0);
910 }
911 else
912 {
913 body->talk.length = 0;
914 body->talk.data = NULL;
915 }
916
917 break;
918 default:
920 break;
921 }
922
923 return padding;
924}
#define GNUNET_be32toh(x)
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
#define decode_step(src, offset, dst)
#define decode_step_key(src, offset, dst, length)
#define decode_step_malloc(src, offset, dst, size, zero)
#define decode_step_ext(src, offset, dst, size)

References GNUNET_MESSENGER_MessageConnection::amount, GNUNET_MESSENGER_MessageBody::connection, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, decode_step, decode_step_ext, decode_step_key, decode_step_malloc, GNUNET_MESSENGER_MessageDelete::delay, GNUNET_MESSENGER_MessageBody::deletion, GNUNET_MESSENGER_MessageSubscribe::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_MESSENGER_MessageInvite::door, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::flags, GNUNET_MESSENGER_MessageSubscribe::flags, GNUNET_be32toh, GNUNET_memcpy, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETE, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_SUBSCRIBE, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageFile::hash, GNUNET_MESSENGER_MessageDelete::hash, GNUNET_MESSENGER_MessageTranscript::hash, GNUNET_MESSENGER_MessageTag::hash, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageFile::key, GNUNET_MESSENGER_MessagePrivate::key, GNUNET_MESSENGER_MessageTranscript::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageInfo::messenger_version, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageFile::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::request, GNUNET_MESSENGER_MessageBody::subscribe, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageSubscribe::time, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by decode_message(), and decode_short_message().

Here is the caller graph for this function:

◆ decode_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.

If the buffer is too small for a message of its decoded kind the function fails with resulting GNUNET_NO after decoding only the messages header.

On success the function returns GNUNET_YES.

Parameters
[out]messageMessage
[in]lengthMaximal length to decode
[in]bufferBuffer
[in]include_headerFlag to include header
[out]paddingPadding
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 928 of file messenger_api_message.c.

933{
935 (message) &&
936 (buffer) &&
938 include_header))
939 );
940
941 uint16_t offset = 0;
942
943 if (GNUNET_YES == include_header)
944 {
946 &(message->header.signature), buffer, length - offset
947 );
948
949 if (result < 0)
950 return GNUNET_NO;
951 else
952 offset += result;
953 }
954
955 const uint16_t count = length - offset;
956
958 include_header))
959 return GNUNET_NO;
960
961 kind_t kind;
962
963 if (GNUNET_YES == include_header)
964 {
965 decode_step (buffer, offset, &(message->header.timestamp));
966 decode_step (buffer, offset, &(message->header.sender_id));
967 decode_step (buffer, offset, &(message->header.previous));
968 }
969
970 decode_step (buffer, offset, &kind);
971
973 kind);
974
975 if (count < get_message_kind_size (message->header.kind, include_header))
976 return GNUNET_NO;
977
978 const uint16_t result = decode_message_body (&(message->header.kind),
979 &(message->body), length, buffer,
980 offset);
981
982 if (padding)
983 *padding = result;
984
985 return GNUNET_YES;
986}
ssize_t GNUNET_CRYPTO_read_signature_from_buffer(struct GNUNET_CRYPTO_Signature *sig, const void *buffer, size_t len)
Reads a GNUNET_CRYPTO_Signature from a compact buffer.
Definition: crypto_pkey.c:243
static uint16_t decode_message_body(enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, const char *buffer, uint16_t offset)

References GNUNET_MESSENGER_Message::body, decode_message_body(), decode_step, get_message_kind_size(), GNUNET_assert, GNUNET_be32toh, GNUNET_CRYPTO_read_signature_from_buffer(), GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageHeader::previous, result, GNUNET_MESSENGER_MessageHeader::sender_id, GNUNET_MESSENGER_MessageHeader::signature, and GNUNET_MESSENGER_MessageHeader::timestamp.

Referenced by check_recv_message(), check_send_message(), check_tunnel_message(), get_store_message(), handle_recv_message(), handle_send_message(), and handle_tunnel_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_short_message()

static enum GNUNET_GenericReturnValue decode_short_message ( struct GNUNET_MESSENGER_ShortMessage message,
uint16_t  length,
const char *  buffer 
)
static

Definition at line 990 of file messenger_api_message.c.

993{
994 struct GNUNET_HashCode expected, hash;
995 uint16_t offset = sizeof(hash);
996
997 if (length < get_short_message_size (NULL, GNUNET_NO))
998 return GNUNET_NO;
999
1000 GNUNET_memcpy (&hash, buffer, sizeof(hash));
1001
1003 buffer + sizeof(hash),
1004 length - sizeof(hash),
1005 &expected
1006 );
1007
1008 if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected))
1009 return GNUNET_NO;
1010
1011 kind_t kind;
1012
1013 decode_step (buffer, offset, &kind);
1014
1015 message->kind = (enum GNUNET_MESSENGER_MessageKind) GNUNET_be32toh (kind);
1016
1017 if (length < get_short_message_size (message, GNUNET_NO))
1018 return GNUNET_NO;
1019
1020 decode_message_body (&(message->kind), &(message->body), length, buffer,
1021 offset);
1022
1023 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind)
1024 return GNUNET_NO;
1025
1026 return GNUNET_YES;
1027}
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
Definition: crypto_hash.c:221
static uint16_t get_short_message_size(const struct GNUNET_MESSENGER_ShortMessage *message, enum GNUNET_GenericReturnValue include_body)

References GNUNET_MESSENGER_ShortMessage::body, decode_message_body(), decode_step, get_short_message_size(), GNUNET_be32toh, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_cmp(), GNUNET_memcpy, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_NO, GNUNET_YES, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by decrypt_message(), and read_transcript_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hash_message()

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.

Parameters
[in]messageMessage
[in]lengthLength of buffer
[in]bufferBuffer
[out]hashHash

Definition at line 1031 of file messenger_api_message.c.

1035{
1036 GNUNET_assert ((message) && (buffer) && (hash));
1037
1038 const ssize_t offset = GNUNET_CRYPTO_signature_get_length (
1039 &(message->header.signature)
1040 );
1041
1042 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1043}

References GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_signature_get_length(), GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::signature.

Referenced by check_tunnel_message(), get_store_message(), handle_tunnel_message(), pack_message(), and send_message_to_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sign_message()

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.

Parameters
[in,out]messageMessage
[in]lengthLength of buffer
[out]bufferBuffer
[in]hashHash of message
[in]keyPrivate key

Definition at line 1047 of file messenger_api_message.c.

1052{
1053 GNUNET_assert ((message) && (buffer) && (hash) && (key));
1054
1055 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1056 GNUNET_h2s (hash));
1057
1058 struct GNUNET_MESSENGER_MessageSignature signature;
1059
1061 signature.purpose.size = htonl (sizeof(signature));
1062
1063 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1064 GNUNET_CRYPTO_sign (key, &signature, &(message->header.signature));
1065
1066 message->header.signature.type = key->type;
1067
1068 uint16_t offset = 0;
1069 encode_step_signature (buffer, offset, &(message->header.signature), length);
1070}
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_log(kind,...)
#define GNUNET_CRYPTO_sign(priv, ps, sig)
Sign a given block with GNUNET_CRYPTO_PrivateKey.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE
Signature of a chat message.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
uint32_t type
Type of signature.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose

References encode_step_signature, GNUNET_assert, GNUNET_CRYPTO_sign, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, and GNUNET_CRYPTO_Signature::type.

Referenced by send_message_to_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sign_message_by_peer()

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 the buffer as well.

Parameters
[in,out]messageMessage
[in]lengthLength of buffer
[out]bufferBuffer
[in]hashHash of message
[in]cfgPeer configuration

Definition at line 1074 of file messenger_api_message.c.

1079{
1080 GNUNET_assert ((message) && (buffer) && (hash) && (cfg));
1081
1082 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
1083 GNUNET_h2s (hash));
1084
1085 struct GNUNET_MESSENGER_MessageSignature signature;
1086
1088 signature.purpose.size = htonl (sizeof(signature));
1089
1090 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1091 GNUNET_CRYPTO_sign_by_peer_identity (cfg, &(signature.purpose),
1092 &(message->header.signature.
1093 eddsa_signature));
1094
1096
1097 uint16_t offset = 0;
1098 encode_step_signature (buffer, offset, &(message->header.signature), length);
1099}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_by_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
Sign a given block with a specific purpose using the host's peer identity.
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.

References cfg, encode_step_signature, GNUNET_assert, GNUNET_CRYPTO_sign_by_peer_identity(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, and GNUNET_CRYPTO_Signature::type.

Referenced by sign_srv_room_message_by_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_message()

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.

The function returns GNUNET_OK if the signature was valid, otherwise GNUNET_SYSERR.

Parameters
[in]messageMessage
[in]hashHash of message
[in]keyPublic key
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 1103 of file messenger_api_message.c.

1106{
1107 GNUNET_assert ((message) && (hash) && (key));
1108
1109 if (key->type != message->header.signature.type)
1110 return GNUNET_SYSERR;
1111
1112 struct GNUNET_MESSENGER_MessageSignature signature;
1113
1115 signature.purpose.size = htonl (sizeof(signature));
1116
1117 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1118
1121 &(message->header.signature), key);
1122}
#define GNUNET_CRYPTO_signature_verify(purp, ps, sig, pub)
Verify a given signature with GNUNET_CRYPTO_PublicKey.

References GNUNET_assert, GNUNET_CRYPTO_signature_verify, GNUNET_memcpy, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_SYSERR, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, and GNUNET_CRYPTO_Signature::type.

Referenced by verify_member_session_as_sender().

Here is the caller graph for this function:

◆ verify_message_by_peer()

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.

The function returns GNUNET_OK if the signature was valid, otherwise GNUNET_SYSERR.

Parameters
[in]messageMessage
[in]hashHash of message
[in]identityPeer identity
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 1126 of file messenger_api_message.c.

1129{
1130 GNUNET_assert ((message) && (hash) && (identity));
1131
1132 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1133 return GNUNET_SYSERR;
1134
1135 struct GNUNET_MESSENGER_MessageSignature signature;
1136
1138 signature.purpose.size = htonl (sizeof(signature));
1139
1140 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1141
1143 GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &(signature.purpose),
1144 &(message->header.signature.
1145 eddsa_signature), identity);
1146}
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_verify_peer_identity(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_PeerIdentity *identity)
Verify a given signature with a peer's identity.

References GNUNET_assert, GNUNET_CRYPTO_verify_peer_identity(), GNUNET_memcpy, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_SYSERR, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, identity, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, and GNUNET_CRYPTO_Signature::type.

Referenced by get_store_peer_of(), and verify_store_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encrypt_message()

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 encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]messageMessage
[in]keyPublic key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1150 of file messenger_api_message.c.

1152{
1153 struct GNUNET_CRYPTO_EcdhePublicKey hpke_key;
1154 GNUNET_assert ((message) && (key));
1155
1156 if (GNUNET_YES == is_service_message (message))
1157 return GNUNET_NO;
1158
1159 struct GNUNET_MESSENGER_ShortMessage shortened;
1160
1161 fold_short_message (message, &shortened);
1162
1163 const uint16_t length = get_short_message_size (&shortened, GNUNET_YES);
1164 const uint16_t padded_length = calc_padded_length (
1166 );
1167
1169 message->body.privacy.data = GNUNET_malloc (padded_length);
1170 message->body.privacy.length = padded_length;
1171
1173 const uint16_t encoded_length = (
1175 );
1176
1177 encode_short_message (&shortened, encoded_length, message->body.privacy.data);
1178
1180 (uint8_t*) "messenger",
1181 strlen ("messenger"),
1182 NULL, 0,
1183 (uint8_t*) message->body.
1184 privacy.data,
1185 encoded_length,
1186 (uint8_t*) message->body.
1187 privacy.data,
1188 NULL))
1189 {
1190 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1191
1192 unfold_short_message (&shortened, message);
1193 return GNUNET_NO;
1194 }
1195
1196 destroy_message_body (shortened.kind, &(shortened.body));
1197 return GNUNET_YES;
1198}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal_oneshot(const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, unsigned long long *ct_len)
RFC9180 HPKE encryption.
Definition: crypto_hpke.c:899
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_pk_to_x25519(const struct GNUNET_CRYPTO_PublicKey *pk, struct GNUNET_CRYPTO_EcdhePublicKey *x25519)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
Definition: crypto_hpke.c:951
#define GNUNET_CRYPTO_HPKE_SEAL_ONESHOT_OVERHEAD_BYTES
@ GNUNET_OK
@ GNUNET_ERROR_TYPE_WARNING
enum GNUNET_GenericReturnValue is_service_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message contains service critical information.
static void fold_short_message(const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_ShortMessage *shortened)
static uint16_t calc_padded_length(uint16_t length)
static void encode_short_message(const struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, char *buffer)
static void unfold_short_message(struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message)
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_ShortMessage::body, calc_padded_length(), GNUNET_MESSENGER_MessagePrivate::data, destroy_message_body(), encode_short_message(), fold_short_message(), get_short_message_size(), GNUNET_assert, GNUNET_CRYPTO_hpke_pk_to_x25519(), GNUNET_CRYPTO_hpke_seal_oneshot(), GNUNET_CRYPTO_HPKE_SEAL_ONESHOT_OVERHEAD_BYTES, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_malloc, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, is_service_message(), key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_ShortMessage::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageBody::privacy, and unfold_short_message().

Referenced by dequeue_message_from_room(), and send_message_to_room_with_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrypt_message()

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 encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]messageMessage
[in]keyPrivate key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1202 of file messenger_api_message.c.

1204{
1205 struct GNUNET_CRYPTO_EcdhePrivateKey hpke_key;
1206 GNUNET_assert ((message) && (key));
1207
1208 const uint16_t padded_length = message->body.privacy.length;
1209
1211 {
1213 "Message length too short to decrypt!\n");
1214
1215 return GNUNET_NO;
1216 }
1217
1219 const uint16_t encoded_length = (
1221 );
1222
1223 if (GNUNET_OK !=
1225 (uint8_t*) "messenger",
1226 strlen ("messenger"),
1227 NULL, 0,
1228 (uint8_t*) message->body.privacy.data,
1229 padded_length,
1230 (uint8_t*) message->body.privacy.data,
1231 NULL))
1232 {
1233 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Decrypting message failed!\n");
1234
1235 return GNUNET_NO;
1236 }
1237
1238 struct GNUNET_MESSENGER_ShortMessage shortened;
1239
1240 if (GNUNET_YES != decode_short_message (&shortened,
1241 encoded_length,
1242 message->body.privacy.data))
1243 {
1245 "Decoding decrypted message failed!\n");
1246
1247 return GNUNET_NO;
1248 }
1249
1250 unfold_short_message (&shortened, message);
1251 return GNUNET_YES;
1252}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_open_oneshot(const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, uint8_t *pt, unsigned long long *pt_len)
RFC9180 HPKE encryption.
Definition: crypto_hpke.c:924
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sk_to_x25519(const struct GNUNET_CRYPTO_PrivateKey *sk, struct GNUNET_CRYPTO_EcdhePrivateKey *x25519)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
Definition: crypto_hpke.c:973
@ GNUNET_ERROR_TYPE_INFO
static enum GNUNET_GenericReturnValue decode_short_message(struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer)
Private ECC key encoded for transmission.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, decode_short_message(), GNUNET_assert, GNUNET_CRYPTO_hpke_open_oneshot(), GNUNET_CRYPTO_HPKE_SEAL_ONESHOT_OVERHEAD_BYTES, GNUNET_CRYPTO_hpke_sk_to_x25519(), GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_YES, key, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageBody::privacy, and unfold_short_message().

Referenced by handle_private_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ transcribe_message()

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 encrypted message content.

Parameters
[in]messageMessage
[in]keyPublic key
Returns
Message transcript

Definition at line 1256 of file messenger_api_message.c.

1258{
1259 GNUNET_assert ((message) && (key));
1260
1261 if (GNUNET_YES == is_service_message (message))
1262 return NULL;
1263
1264 struct GNUNET_MESSENGER_Message *transcript = create_message (
1266
1267 if (! transcript)
1268 {
1269 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1270 return NULL;
1271 }
1272
1273 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1274 sizeof(transcript->body.transcript.key));
1275
1276 struct GNUNET_MESSENGER_ShortMessage shortened;
1277
1278 fold_short_message (message, &shortened);
1279
1280 const uint16_t data_length = get_short_message_size (
1281 &shortened, GNUNET_YES);
1282
1283 transcript->body.transcript.data = GNUNET_malloc (data_length);
1284 transcript->body.transcript.length = data_length;
1285
1286 encode_short_message (&shortened, data_length,
1287 transcript->body.transcript.data);
1288
1289 return transcript;
1290}
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.

References GNUNET_MESSENGER_Message::body, create_message(), GNUNET_MESSENGER_MessageTranscript::data, encode_short_message(), fold_short_message(), get_short_message_size(), GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_YES, is_service_message(), key, GNUNET_MESSENGER_MessageTranscript::key, GNUNET_MESSENGER_MessageTranscript::length, and GNUNET_MESSENGER_MessageBody::transcript.

Referenced by send_message_to_room_with_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_transcript_message()

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 encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]transcriptMessage transcript
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1294 of file messenger_api_message.c.

1295{
1296 GNUNET_assert (message);
1297
1299 return GNUNET_NO;
1300
1301 const uint16_t data_length = message->body.transcript.length;
1302
1303 struct GNUNET_MESSENGER_ShortMessage shortened;
1304 if (GNUNET_YES != decode_short_message (&shortened,
1305 data_length,
1306 message->body.transcript.data))
1307 {
1309 "Decoding decrypted message failed!\n");
1310
1311 return GNUNET_NO;
1312 }
1313
1314 unfold_short_message (&shortened, message);
1315 return GNUNET_YES;
1316}

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageTranscript::data, decode_short_message(), GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageBody::transcript, and unfold_short_message().

Referenced by handle_transcript_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pack_message()

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_PACK_MODE_ENVELOPE.

Independent of the mode the message will be hashed if hash is not NULL and it will be signed if the sign function is not NULL.

Parameters
[out]messageMessage
[out]hashHash of message
[in]signFunction to sign
[in]modeMode of packing
[in,out]clsClosure for signing
Returns
Envelope or NULL

Definition at line 1320 of file messenger_api_message.c.

1325{
1326 GNUNET_assert (message);
1327
1329 "Packing message kind=%u and sender: %s\n",
1330 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
1331
1332 struct GNUNET_MessageHeader *header;
1333
1334 const uint16_t length = get_message_size (message, GNUNET_YES);
1335 const uint16_t padded_length = calc_padded_length (length);
1336
1337 struct GNUNET_MQ_Envelope *env;
1338 char *buffer;
1339
1341 {
1342 env = GNUNET_MQ_msg_extra (header, padded_length,
1344
1345 buffer = (char*) &(header[1]);
1346 }
1347 else
1348 {
1349 env = NULL;
1350
1351 buffer = GNUNET_malloc (padded_length);
1352 }
1353
1354 encode_message (message, padded_length, buffer, GNUNET_YES);
1355
1356 if (hash)
1357 {
1358 hash_message (message, length, buffer, hash);
1359
1360 if (sign)
1361 sign (cls, message, length, buffer, hash);
1362 }
1363
1365 GNUNET_free (buffer);
1366
1367 return env;
1368}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static enum @44 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
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 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.
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.
@ GNUNET_MESSENGER_PACK_MODE_ENVELOPE
Header for all communications.

References calc_padded_length(), encode_message(), env, get_message_size(), GNUNET_assert, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_MESSAGE_TYPE_CADET_CLI, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, GNUNET_MQ_msg_extra, GNUNET_sh2s(), GNUNET_YES, hash_message(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, mode, and GNUNET_MESSENGER_MessageHeader::sender_id.

Referenced by forward_tunnel_message(), iterate_send_room_message(), and pack_srv_room_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_peer_message()

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 private key.

The function returns GNUNET_YES if the kind of message can be signed via a peer's identity, otherwise GNUNET_NO.

Parameters
[in]messageMessage
Returns
GNUNET_YES if sending is allowed, GNUNET_NO otherwise

Definition at line 1372 of file messenger_api_message.c.

1373{
1374 GNUNET_assert (message);
1375
1376 switch (message->header.kind)
1377 {
1383 return GNUNET_YES;
1384 default:
1385 return GNUNET_NO;
1386 }
1387}

References GNUNET_assert, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_PEER, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by callback_found_message(), callback_room_handle_message(), enqueue_message_control(), filter_message_sending(), get_store_member_of(), get_store_peer_of(), handle_room_messages(), is_service_message(), notify_about_members(), notify_srv_handle_message(), pack_srv_room_message(), process_message_control(), and task_message_control().

Here is the caller graph for this function:

◆ is_service_message()

enum GNUNET_GenericReturnValue is_service_message ( const struct GNUNET_MESSENGER_Message message)

Returns whether a specific kind of message contains service critical information.

That kind of information should not be encrypted via private messages for example to guarantee the service to work properly. The function returns GNUNET_YES if the kind of message needs to be transferred accessible to all peers and their running service. It returns GNUNET_NO if the message can be encrypted to specific subgroups of members without issues. If the kind of message is unknown it returns GNUNET_SYSERR.

Parameters
[in]messageMessage
Returns
GNUNET_YES if encrypting is disallowed, GNUNET_NO or GNUNET_SYSERR otherwise

Definition at line 1391 of file messenger_api_message.c.

1392{
1393 GNUNET_assert (message);
1394
1395 if (GNUNET_YES == is_peer_message (message))
1396 return GNUNET_YES;
1397
1398 switch (message->header.kind)
1399 {
1401 return GNUNET_YES; // Reserved for connection handling only!
1403 return GNUNET_YES; // Reserved for member handling only!
1405 return GNUNET_YES; // Reserved for member handling only!
1407 return GNUNET_YES; // Reserved for member name handling only!
1409 return GNUNET_YES; // Reserved for member key handling only!
1411 return GNUNET_YES; // Reserved for connection handling only!
1413 return GNUNET_YES; // Reserved for member id handling only!
1415 return GNUNET_YES; // Reserved for connection handling only!
1417 return GNUNET_YES; // Reserved for peers only!
1419 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
1421 return GNUNET_NO;
1423 return GNUNET_NO;
1425 return GNUNET_NO;
1427 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
1429 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
1431 return GNUNET_YES; // Reserved for connection handling only!
1433 return GNUNET_NO;
1435 return GNUNET_NO;
1437 return GNUNET_NO;
1439 return GNUNET_YES; // Reserved for subscription handling only!
1441 return GNUNET_NO;
1442 default:
1443 return GNUNET_SYSERR;
1444 }
1445}
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...

References GNUNET_assert, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETE, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_SUBSCRIBE, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, is_peer_message(), and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by encrypt_message(), and transcribe_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filter_message_sending()

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.

The function returns GNUNET_YES or GNUNET_NO for recommendations and GNUNET_SYSERR for specific kinds of messages which should not be sent manually at all.

Parameters
[in]messageMessage
Returns
GNUNET_YES if sending is allowed, GNUNET_NO or GNUNET_SYSERR otherwise

Definition at line 1449 of file messenger_api_message.c.

1450{
1451 GNUNET_assert (message);
1452
1453 if (GNUNET_YES == is_peer_message (message))
1454 return GNUNET_SYSERR; // Requires signature of peer rather than member!
1455
1456 switch (message->header.kind)
1457 {
1459 return GNUNET_SYSERR; // Reserved for connection handling only!
1461 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
1463 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
1465 return GNUNET_YES;
1467 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
1469 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
1471 return GNUNET_NO; // Reserved for member id handling only!
1473 return GNUNET_SYSERR; // Reserved for connection handling only!
1475 return GNUNET_SYSERR; // Reserved for peers only!
1477 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
1479 return GNUNET_YES;
1481 return GNUNET_YES;
1483 return GNUNET_YES;
1485 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
1487 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
1489 return GNUNET_SYSERR; // Reserved for connection handling only!
1491 return GNUNET_YES;
1493 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
1495 return GNUNET_YES;
1497 return GNUNET_YES;
1499 return GNUNET_YES;
1500 default:
1501 return GNUNET_SYSERR;
1502 }
1503}

References GNUNET_assert, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETE, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_SUBSCRIBE, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, is_peer_message(), and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by check_send_message(), and GNUNET_MESSENGER_send_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_message_discourse()

const struct GNUNET_ShortHashCode * get_message_discourse ( const struct GNUNET_MESSENGER_Message message)

Returns the discourse hash of a message depending on its kind.

If a message contains a discourse hash it will not be stored locally on peers.

Parameters
[in]messageMessage
Returns
Discourse hash of message or NULL

Definition at line 1507 of file messenger_api_message.c.

1508{
1509 GNUNET_assert (message);
1510
1511 switch (message->header.kind)
1512 {
1514 return &(message->body.subscribe.discourse);
1516 return &(message->body.talk.discourse);
1517 default:
1518 return NULL;
1519 }
1520}

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageSubscribe::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_assert, GNUNET_MESSENGER_KIND_SUBSCRIBE, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageBody::subscribe, and GNUNET_MESSENGER_MessageBody::talk.

Referenced by handle_message_control(), iterate_flag_for_cleanup_discourse_message(), put_store_message(), send_message_to_room(), and update_message_state().

Here is the caller graph for this function: