GNUnet 0.21.0
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...
 

Macro Definition Documentation

◆ member_size

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

Definition at line 245 of file messenger_api_message.c.

◆ max

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

Definition at line 431 of file messenger_api_message.c.

◆ min

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

Definition at line 460 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 462 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 467 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:128

Definition at line 471 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:246

Definition at line 481 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 663 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 668 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 672 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:103
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_SYSERR

Definition at line 678 of file messenger_api_message.c.

Typedef Documentation

◆ kind_t

typedef uint32_t kind_t

Definition at line 316 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.transcript.length = 0;
69 message->body.transcript.data = NULL;
70 break;
72 message->body.tag.tag = NULL;
73 break;
74 default:
75 break;
76 }
77
78 return message;
79}
#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_TRANSCRIPT
The transcript kind.
@ GNUNET_MESSENGER_KIND_TEXT
The text kind.
struct GNUNET_MESSENGER_MessagePrivate privacy
struct GNUNET_MESSENGER_MessageText text
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageTranscript transcript
struct GNUNET_MESSENGER_MessageFile file
struct GNUNET_MESSENGER_MessageTag tag
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.
char * text
The containing text.
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_MessageBody::file, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_new, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, 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_invite(), 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_text(), create_message_ticket(), 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 83 of file messenger_api_message.c.

84{
85 GNUNET_assert (message);
86
87 struct GNUNET_MESSENGER_Message *copy = GNUNET_new (struct
89
90 GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
91
92 switch (message->header.kind)
93 {
95 copy->body.name.name = message->body.name.name? GNUNET_strdup (
96 message->body.name.name) : NULL;
97 break;
99 copy->body.text.text = message->body.text.text? GNUNET_strdup (
100 message->body.text.text) : NULL;
101 break;
103 copy->body.file.uri = message->body.file.uri? GNUNET_strdup (
104 message->body.file.uri) : NULL;
105 break;
108 copy->body.privacy.length) : NULL;
109
110 if (copy->body.privacy.data)
111 GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data,
112 copy->body.privacy.length);
113
114 break;
117 copy->body.transcript.length) : NULL;
118
119 if (copy->body.transcript.data)
121 copy->body.transcript.length);
122
123 break;
125 copy->body.tag.tag = message->body.tag.tag? GNUNET_strdup (
126 message->body.tag.tag) : NULL;
127 break;
128 default:
129 break;
130 }
131
132 return copy;
133}
#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_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_TEXT, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_new, GNUNET_strdup, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, 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 137 of file messenger_api_message.c.

139{
140 GNUNET_assert ((message) && (header));
141
142 enum GNUNET_MESSENGER_MessageKind kind = message->header.kind;
143
144 GNUNET_memcpy (&(message->header), header,
145 sizeof(struct GNUNET_MESSENGER_MessageHeader));
146
147 message->header.kind = kind;
148}
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 152 of file messenger_api_message.c.

154{
155 switch (kind)
156 {
158 if (body->name.name)
159 GNUNET_free (body->name.name);
160 break;
162 if (body->text.text)
163 GNUNET_free (body->text.text);
164 break;
166 if (body->file.uri)
167 GNUNET_free (body->file.uri);
168 break;
170 GNUNET_free (body->privacy.data);
171 break;
174 break;
176 if (body->tag.tag)
177 GNUNET_free (body->tag.tag);
178 break;
179 default:
180 break;
181 }
182}
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::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_TEXT, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, 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 186 of file messenger_api_message.c.

187{
188 GNUNET_assert (message);
189
190 destroy_message_body (message->header.kind, &(message->body));
191}
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 195 of file messenger_api_message.c.

196{
197 GNUNET_assert (message);
198
199 destroy_message_body (message->header.kind, &(message->body));
200
201 GNUNET_free (message);
202}

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_messages_from_room(), destroy_message_control(), forward_tunnel_message(), get_store_message(), handle_delete_message(), handle_private_message(), handle_transcript_message(), iterate_destroy_message(), iterate_destroy_messages(), 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 206 of file messenger_api_message.c.

207{
208 GNUNET_assert (message);
209
210 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) ||
212 (GNUNET_MESSENGER_KIND_NAME == message->header.kind) ||
213 (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
215 return GNUNET_YES;
216 else
217 return GNUNET_NO;
218}
@ 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 222 of file messenger_api_message.c.

224{
225 shortened->kind = message->header.kind;
226
227 GNUNET_memcpy (&(shortened->body), &(message->body), sizeof(struct
229}
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 233 of file messenger_api_message.c.

235{
236 destroy_message_body (message->header.kind, &(message->body));
237
238 message->header.kind = shortened->kind;
239
240 GNUNET_memcpy (&(message->body), &(shortened->body),
241 sizeof(struct GNUNET_MESSENGER_MessageBody));
242}

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 248 of file messenger_api_message.c.

249{
250 uint16_t length = 0;
251
252 switch (kind)
253 {
255 length += member_size (struct GNUNET_MESSENGER_Message,
256 body.info.messenger_version);
257 break;
259 length += member_size (struct GNUNET_MESSENGER_Message, body.peer.peer);
260 break;
262 length += member_size (struct GNUNET_MESSENGER_Message, body.id.id);
263 break;
265 length += member_size (struct GNUNET_MESSENGER_Message, body.miss.peer);
266 break;
268 length += member_size (struct GNUNET_MESSENGER_Message,
269 body.merge.previous);
270 break;
272 length += member_size (struct GNUNET_MESSENGER_Message, body.request.hash);
273 break;
275 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.door);
276 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.key);
277 break;
279 length += member_size (struct GNUNET_MESSENGER_Message, body.file.key);
280 length += member_size (struct GNUNET_MESSENGER_Message, body.file.hash);
281 length += member_size (struct GNUNET_MESSENGER_Message, body.file.name);
282 break;
284 length += member_size (struct GNUNET_MESSENGER_Message, body.privacy.key);
285 break;
287 length += member_size (struct GNUNET_MESSENGER_Message, body.deletion.hash);
288 length += member_size (struct GNUNET_MESSENGER_Message,
289 body.deletion.delay);
290 break;
292 length += member_size (struct GNUNET_MESSENGER_Message,
293 body.connection.amount);
294 length += member_size (struct GNUNET_MESSENGER_Message,
295 body.connection.flags);
296 break;
298 length += member_size (struct GNUNET_MESSENGER_Message,
299 body.ticket.identifier);
300 break;
302 length += member_size (struct GNUNET_MESSENGER_Message,
303 body.transcript.hash);
304 break;
306 length += member_size (struct GNUNET_MESSENGER_Message, body.tag.hash);
307 break;
308 default:
309 break;
310 }
311
312 return length;
313}
@ 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_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_DELETE
The delete kind.
@ GNUNET_MESSENGER_KIND_CONNECTION
The connection kind.
@ GNUNET_MESSENGER_KIND_TICKET
The ticket 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_MessageInvite::door, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::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_TAG, 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_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::tag, GNUNET_MESSENGER_MessageBody::ticket, 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 319 of file messenger_api_message.c.

321{
322 uint16_t length = 0;
323
324 if (GNUNET_YES == include_header)
325 {
326 length += member_size (struct GNUNET_MESSENGER_Message, header.timestamp);
327 length += member_size (struct GNUNET_MESSENGER_Message, header.sender_id);
328 length += member_size (struct GNUNET_MESSENGER_Message, header.previous);
329 }
330
331 length += sizeof(kind_t);
332
333 return length + get_message_body_kind_size (kind);
334}
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 338 of file messenger_api_message.c.

340{
341 uint16_t length = 0;
342
343 switch (kind)
344 {
346 length += GNUNET_CRYPTO_public_key_get_length (&(body->join.key));
347 break;
349 length += (body->name.name ? strlen (body->name.name) : 0);
350 break;
352 length += GNUNET_CRYPTO_public_key_get_length (&(body->key.key));
353 break;
355 length += (body->text.text ? strlen (body->text.text) : 0);
356 break;
358 length += (body->file.uri ? strlen (body->file.uri) : 0);
359 break;
361 length += body->privacy.length;
362 break;
365 length += body->transcript.length;
366 break;
368 length += (body->tag.tag ? strlen (body->tag.tag) : 0);
369 break;
370 default:
371 break;
372 }
373
374 return length;
375}
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:68
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_TEXT, GNUNET_MESSENGER_KIND_TRANSCRIPT, 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_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, 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 379 of file messenger_api_message.c.

381{
382 GNUNET_assert (message);
383
384 uint16_t length = 0;
385
386 if (GNUNET_YES == include_header)
388 &(message->header.signature));
389
390 length += get_message_kind_size (message->header.kind, include_header);
391 length += get_message_body_size (message->header.kind, &(message->body));
392
393 return length;
394}
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:189
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 398 of file messenger_api_message.c.

400{
401 const uint16_t minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t);
402
403 if (message)
404 return minimum_size + get_message_body_kind_size (message->kind)
405 + (include_body == GNUNET_YES?
406 get_message_body_size (message->kind, &(message->body)) : 0);
407 else
408 return minimum_size;
409}
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 413 of file messenger_api_message.c.

414{
415 uint16_t padding = 0;
416 uint16_t kind_size;
417
418 for (unsigned int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++)
419 {
421 GNUNET_YES);
422
423 if (kind_size > padding)
424 padding = kind_size;
425 }
426
427 return padding + GNUNET_MESSENGER_PADDING_MIN;
428}
#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 434 of file messenger_api_message.c.

435{
436 static uint16_t usual_padding = 0;
437
438 if (! usual_padding)
439 usual_padding = calc_usual_padding ();
440
441 const uint16_t padded_length = max (
443 usual_padding
444 );
445
446 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0)
448
449 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL1)
451
452 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL2)
454
456
457}
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 492 of file messenger_api_message.c.

497{
498 uint32_t value0, value1;
499 switch (kind)
500 {
502 value0 = GNUNET_htobe32 (body->info.messenger_version);
503
504 encode_step (buffer, offset, &value0);
505 break;
507 encode_step_key (buffer, offset, &(body->join.key), length);
508 break;
510 if (body->name.name)
511 encode_step_ext (buffer, offset, body->name.name, min (length - offset,
512 strlen (
513 body->name.name)));
514 break;
516 encode_step_key (buffer, offset, &(body->key.key), length);
517 break;
519 encode_step (buffer, offset, &(body->peer.peer));
520 break;
522 encode_step (buffer, offset, &(body->id.id));
523 break;
525 encode_step (buffer, offset, &(body->miss.peer));
526 break;
528 encode_step (buffer, offset, &(body->merge.previous));
529 break;
531 encode_step (buffer, offset, &(body->request.hash));
532 break;
534 encode_step (buffer, offset, &(body->invite.door));
535 encode_step (buffer, offset, &(body->invite.key));
536 break;
538 if (body->text.text)
539 encode_step_ext (buffer, offset, body->text.text, min (length - offset,
540 strlen (
541 body->text.text)));
542 break;
544 encode_step (buffer, offset, &(body->file.key));
545 encode_step (buffer, offset, &(body->file.hash));
546 encode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
547 if (body->file.uri)
548 encode_step_ext (buffer, offset, body->file.uri, min (length - offset,
549 strlen (
550 body->file.uri)));
551 break;
553 encode_step (buffer, offset, &(body->privacy.key));
554 encode_step_ext (buffer, offset, body->privacy.data, min (length - offset,
555 body->privacy.
556 length));
557 break;
559 encode_step (buffer, offset, &(body->deletion.hash));
560 encode_step (buffer, offset, &(body->deletion.delay));
561 break;
563 value0 = GNUNET_htobe32 (body->connection.amount);
564 value1 = GNUNET_htobe32 (body->connection.flags);
565
566 encode_step (buffer, offset, &value0);
567 encode_step (buffer, offset, &value1);
568 break;
570 encode_step (buffer, offset, &(body->ticket.identifier));
571 break;
573 encode_step (buffer, offset, &(body->transcript.hash));
574 encode_step_key (buffer, offset, &(body->transcript.key), length);
575 encode_step_ext (buffer, offset, body->transcript.data, min (length
576 - offset,
577 body->
578 transcript.
579 length));
580 break;
582 encode_step (buffer, offset, &(body->tag.hash));
583 if (body->tag.tag)
584 encode_step_ext (buffer, offset, body->tag.tag, min (length - offset,
585 strlen (
586 body->tag.tag)));
587 break;
588 default:
589 break;
590 }
591
592 if (offset >= length)
593 return;
594
595 const uint16_t padding = length - offset;
596 const uint16_t used_padding = sizeof(padding) + sizeof(char);
597
598 GNUNET_assert (padding >= used_padding);
599
600 buffer[offset++] = '\0';
601
602 if (padding > used_padding)
604 padding - used_padding);
605
606 GNUNET_memcpy (buffer + length - sizeof(padding), &padding, sizeof(padding));
607}
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_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_MessageTicket ticket
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.
struct GNUNET_HashCode hash
The hash of the message to tag.
struct GNUNET_RECLAIM_Identifier identifier
The identifier of a RECLAIM ticket.
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_MessageDelete::delay, GNUNET_MESSENGER_MessageBody::deletion, GNUNET_MESSENGER_MessageInvite::door, encode_step, encode_step_ext, encode_step_key, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::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_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_TAG, 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_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, 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 611 of file messenger_api_message.c.

615{
616 GNUNET_assert ((message) && (buffer));
617
618 uint16_t offset = 0;
619
620 if (GNUNET_YES == include_header)
621 encode_step_signature (buffer, offset, &(message->header.signature),
622 length);
623
624 const kind_t kind = GNUNET_htobe32 ((kind_t) message->header.kind);
625
626 if (GNUNET_YES == include_header)
627 {
628 encode_step (buffer, offset, &(message->header.timestamp));
629 encode_step (buffer, offset, &(message->header.sender_id));
630 encode_step (buffer, offset, &(message->header.previous));
631 }
632
633 encode_step (buffer, offset, &kind);
634
635 encode_message_body (message->header.kind, &(message->body),
636 length, buffer, offset);
637}
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 641 of file messenger_api_message.c.

644{
645 struct GNUNET_HashCode hash;
646 uint16_t offset = sizeof(hash);
647
648 const kind_t kind = GNUNET_htobe32 ((kind_t) message->kind);
649
650 encode_step (buffer, offset, &kind);
651
652 encode_message_body (message->kind, &(message->body), length, buffer, offset);
653
655 buffer + sizeof(hash),
656 length - sizeof(hash),
657 &hash);
658
659 GNUNET_memcpy (buffer, &hash, sizeof(hash));
660}
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 691 of file messenger_api_message.c.

696{
697 uint16_t padding = 0;
698
699 GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding));
700
701 if (padding > length - offset)
702 padding = 0;
703
704 const uint16_t end_zero = length - padding;
705
706 if ((padding) && (buffer[end_zero] != '\0'))
707 padding = 0;
708
709 length -= padding;
710
711 uint32_t value0, value1;
712 switch (*kind)
713 {
715 decode_step (buffer, offset, &value0);
716
717 body->info.messenger_version = GNUNET_be32toh (value0);
718 break;
720 decode_step_key (buffer, offset, &(body->join.key), length);
721 break;
723 if (length > offset)
724 decode_step_malloc (buffer, offset, body->name.name, length - offset, 1);
725 else
726 body->name.name = NULL;
727 break;
729 decode_step_key (buffer, offset, &(body->key.key), length);
730 break;
732 decode_step (buffer, offset, &(body->peer.peer));
733 break;
735 decode_step (buffer, offset, &(body->id.id));
736 break;
738 decode_step (buffer, offset, &(body->miss.peer));
739 break;
741 decode_step (buffer, offset, &(body->merge.previous));
742 break;
744 decode_step (buffer, offset, &(body->request.hash));
745 break;
747 decode_step (buffer, offset, &(body->invite.door));
748 decode_step (buffer, offset, &(body->invite.key));
749 break;
751 if (length > offset)
752 decode_step_malloc (buffer, offset, body->text.text, length - offset, 1);
753 else
754 body->text.text = NULL;
755 break;
757 decode_step (buffer, offset, &(body->file.key));
758 decode_step (buffer, offset, &(body->file.hash));
759 decode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
760 if (length > offset)
761 decode_step_malloc (buffer, offset, body->file.uri, length - offset, 1);
762 else
763 body->file.uri = NULL;
764 break;
766 decode_step (buffer, offset, &(body->privacy.key));
767
768 body->privacy.length = (length - offset);
769 decode_step_malloc (buffer, offset, body->privacy.data, length - offset, 0);
770 break;
772 decode_step (buffer, offset, &(body->deletion.hash));
773 decode_step (buffer, offset, &(body->deletion.delay));
774 break;
776 decode_step (buffer, offset, &value0);
777 decode_step (buffer, offset, &value1);
778
779 body->connection.amount = GNUNET_be32toh (value0);
780 body->connection.flags = GNUNET_be32toh (value1);
781 break;
783 decode_step (buffer, offset, &(body->ticket.identifier));
784 break;
786 decode_step (buffer, offset, &(body->transcript.hash));
787 decode_step_key (buffer, offset, &(body->transcript.key), length);
788
789 body->transcript.length = (length - offset);
790 decode_step_malloc (buffer, offset, body->transcript.data, length - offset,
791 0);
792 break;
794 decode_step (buffer, offset, &(body->tag.hash));
795 if (length > offset)
796 decode_step_malloc (buffer, offset, body->tag.tag, length - offset, 1);
797 else
798 body->tag.tag = NULL;
799 break;
800 default:
802 break;
803 }
804
805 return padding;
806}
#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, decode_step, decode_step_ext, decode_step_key, decode_step_malloc, GNUNET_MESSENGER_MessageDelete::delay, GNUNET_MESSENGER_MessageBody::deletion, GNUNET_MESSENGER_MessageInvite::door, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::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_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_TAG, 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_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_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, 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 810 of file messenger_api_message.c.

815{
817 (message) &&
818 (buffer) &&
820 include_header))
821 );
822
823 uint16_t offset = 0;
824
825 if (GNUNET_YES == include_header)
826 {
828 &(message->header.signature), buffer, length - offset
829 );
830
831 if (result < 0)
832 return GNUNET_NO;
833 else
834 offset += result;
835 }
836
837 const uint16_t count = length - offset;
838
840 include_header))
841 return GNUNET_NO;
842
843 kind_t kind;
844
845 if (GNUNET_YES == include_header)
846 {
847 decode_step (buffer, offset, &(message->header.timestamp));
848 decode_step (buffer, offset, &(message->header.sender_id));
849 decode_step (buffer, offset, &(message->header.previous));
850 }
851
852 decode_step (buffer, offset, &kind);
853
855 kind);
856
857 if (count < get_message_kind_size (message->header.kind, include_header))
858 return GNUNET_NO;
859
860 const uint16_t result = decode_message_body (&(message->header.kind),
861 &(message->body), length, buffer,
862 offset);
863
864 if (padding)
865 *padding = result;
866
867 return GNUNET_YES;
868}
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:226
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 872 of file messenger_api_message.c.

875{
876 struct GNUNET_HashCode expected, hash;
877 uint16_t offset = sizeof(hash);
878
879 if (length < get_short_message_size (NULL, GNUNET_NO))
880 return GNUNET_NO;
881
882 GNUNET_memcpy (&hash, buffer, sizeof(hash));
883
885 buffer + sizeof(hash),
886 length - sizeof(hash),
887 &expected
888 );
889
890 if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected))
891 return GNUNET_NO;
892
893 kind_t kind;
894
895 decode_step (buffer, offset, &kind);
896
897 message->kind = (enum GNUNET_MESSENGER_MessageKind) GNUNET_be32toh (kind);
898
899 if (length < get_short_message_size (message, GNUNET_NO))
900 return GNUNET_NO;
901
902 decode_message_body (&(message->kind), &(message->body), length, buffer,
903 offset);
904
905 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind)
906 return GNUNET_NO;
907
908 return GNUNET_YES;
909}
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 913 of file messenger_api_message.c.

917{
918 GNUNET_assert ((message) && (buffer) && (hash));
919
920 const ssize_t offset = GNUNET_CRYPTO_signature_get_length (
921 &(message->header.signature)
922 );
923
924 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
925}

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 929 of file messenger_api_message.c.

934{
935 GNUNET_assert ((message) && (buffer) && (hash) && (key));
936
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
938 GNUNET_h2s (hash));
939
940 struct GNUNET_MESSENGER_MessageSignature signature;
941
943 signature.purpose.size = htonl (sizeof(signature));
944
945 GNUNET_memcpy (&(signature.hash), hash, sizeof(struct GNUNET_HashCode));
946 GNUNET_CRYPTO_sign (key, &signature, &(message->header.signature));
947
948 message->header.signature.type = key->type;
949
950 uint16_t offset = 0;
951 encode_step_signature (buffer, offset, &(message->header.signature), length);
952}
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 956 of file messenger_api_message.c.

961{
962 GNUNET_assert ((message) && (buffer) && (hash) && (cfg));
963
964 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
965 GNUNET_h2s (hash));
966
967 struct GNUNET_MESSENGER_MessageSignature signature;
968
970 signature.purpose.size = htonl (sizeof(signature));
971
972 GNUNET_memcpy (&(signature.hash), hash, sizeof(struct GNUNET_HashCode));
973 GNUNET_CRYPTO_sign_by_peer_identity (cfg, &signature.purpose,
974 &(message->header.signature.
975 eddsa_signature));
976
978
979 uint16_t offset = 0;
980 encode_step_signature (buffer, offset, &(message->header.signature), length);
981}
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 985 of file messenger_api_message.c.

988{
989 GNUNET_assert ((message) && (hash) && (key));
990
991 if (key->type != message->header.signature.type)
992 return GNUNET_SYSERR;
993
994 struct GNUNET_MESSENGER_MessageSignature signature;
995
997 signature.purpose.size = htonl (sizeof(signature));
998
999 GNUNET_memcpy (&(signature.hash), hash, sizeof(struct GNUNET_HashCode));
1000
1003 &(message->header.signature), key);
1004}
#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 1008 of file messenger_api_message.c.

1011{
1012 GNUNET_assert ((message) && (hash) && (identity));
1013
1014 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1015 return GNUNET_SYSERR;
1016
1017 struct GNUNET_MESSENGER_MessageSignature signature;
1018
1020 signature.purpose.size = htonl (sizeof(signature));
1021
1022 GNUNET_memcpy (&(signature.hash), hash, sizeof(struct GNUNET_HashCode));
1023
1025 GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &signature.purpose,
1026 &(message->header.signature.
1027 eddsa_signature), identity);
1028}
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 1032 of file messenger_api_message.c.

1034{
1035 GNUNET_assert ((message) && (key));
1036
1037 if (GNUNET_YES == is_service_message (message))
1038 return GNUNET_NO;
1039
1040 struct GNUNET_MESSENGER_ShortMessage shortened;
1041
1042 fold_short_message (message, &shortened);
1043
1044 const uint16_t length = get_short_message_size (&shortened, GNUNET_YES);
1045 const uint16_t padded_length = calc_padded_length (
1047 );
1048
1050 message->body.privacy.data = GNUNET_malloc (padded_length);
1051 message->body.privacy.length = padded_length;
1052
1053 const uint16_t encoded_length = (
1055 );
1056
1057 encode_short_message (&shortened, encoded_length, message->body.privacy.data);
1058
1060 encoded_length,
1061 key,
1062 message->body.privacy.data,
1063 padded_length))
1064 {
1065 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1066
1067 unfold_short_message (&shortened, message);
1068 return GNUNET_NO;
1069 }
1070
1071 destroy_message_body (shortened.kind, &(shortened.body));
1072 return GNUNET_YES;
1073}
#define GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_PublicKey *pub, void *result, size_t result_size)
Encrypt a block with GNUNET_CRYPTO_PublicKey and derives a GNUNET_CRYPTO_EcdhePublicKey which is requ...
Definition: crypto_pkey.c:416
@ 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)

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_encrypt(), GNUNET_CRYPTO_ENCRYPT_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_messages_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 1077 of file messenger_api_message.c.

1079{
1080 GNUNET_assert ((message) && (key));
1081
1082 const uint16_t padded_length = message->body.privacy.length;
1083
1084 if (padded_length < GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES)
1085 {
1087 "Message length too short to decrypt!\n");
1088
1089 return GNUNET_NO;
1090 }
1091
1092 const uint16_t encoded_length = (
1094 );
1095
1097 padded_length,
1098 key,
1099 message->body.privacy.data,
1100 encoded_length))
1101 {
1102 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Decrypting message failed!\n");
1103
1104 return GNUNET_NO;
1105 }
1106
1107 struct GNUNET_MESSENGER_ShortMessage shortened;
1108
1109 if (GNUNET_YES != decode_short_message (&shortened,
1110 encoded_length,
1111 message->body.privacy.data))
1112 {
1114 "Decoding decrypted message failed!\n");
1115
1116 return GNUNET_NO;
1117 }
1118
1119 unfold_short_message (&shortened, message);
1120 return GNUNET_YES;
1121}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_PrivateKey *priv, void *result, size_t result_size)
Decrypt a given block with GNUNET_CRYPTO_PrivateKey and a given GNUNET_CRYPTO_EcdhePublicKey using ec...
Definition: crypto_pkey.c:467
@ GNUNET_ERROR_TYPE_INFO
static enum GNUNET_GenericReturnValue decode_short_message(struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer)

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, decode_short_message(), GNUNET_assert, GNUNET_CRYPTO_decrypt(), GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES, 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 1125 of file messenger_api_message.c.

1127{
1128 GNUNET_assert ((message) && (key));
1129
1130 if (GNUNET_YES == is_service_message (message))
1131 return NULL;
1132
1133 struct GNUNET_MESSENGER_Message *transcript = create_message (
1135
1136 if (! transcript)
1137 {
1138 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1139 return NULL;
1140 }
1141
1142 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1143 sizeof(transcript->body.transcript.key));
1144
1145 struct GNUNET_MESSENGER_ShortMessage shortened;
1146
1147 fold_short_message (message, &shortened);
1148
1149 const uint16_t data_length = get_short_message_size (
1150 &shortened, GNUNET_YES);
1151
1152 transcript->body.transcript.data = GNUNET_malloc (data_length);
1153 transcript->body.transcript.length = data_length;
1154
1155 encode_short_message (&shortened, data_length,
1156 transcript->body.transcript.data);
1157
1158 return transcript;
1159}
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 1163 of file messenger_api_message.c.

1164{
1165 GNUNET_assert (message);
1166
1168 return GNUNET_NO;
1169
1170 const uint16_t data_length = message->body.transcript.length;
1171
1172 struct GNUNET_MESSENGER_ShortMessage shortened;
1173 if (GNUNET_YES != decode_short_message (&shortened,
1174 data_length,
1175 message->body.transcript.data))
1176 {
1178 "Decoding decrypted message failed!\n");
1179
1180 return GNUNET_NO;
1181 }
1182
1183 unfold_short_message (&shortened, message);
1184 return GNUNET_YES;
1185}

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 1189 of file messenger_api_message.c.

1194{
1195 GNUNET_assert (message);
1196
1198 "Packing message kind=%u and sender: %s\n",
1199 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
1200
1201 struct GNUNET_MessageHeader *header;
1202
1203 const uint16_t length = get_message_size (message, GNUNET_YES);
1204 const uint16_t padded_length = calc_padded_length (length);
1205
1206 struct GNUNET_MQ_Envelope *env;
1207 char *buffer;
1208
1210 {
1211 env = GNUNET_MQ_msg_extra (header, padded_length,
1213
1214 buffer = (char*) &(header[1]);
1215 }
1216 else
1217 {
1218 env = NULL;
1219
1220 buffer = GNUNET_malloc (padded_length);
1221 }
1222
1223 encode_message (message, padded_length, buffer, GNUNET_YES);
1224
1225 if (hash)
1226 {
1227 hash_message (message, length, buffer, hash);
1228
1229 if (sign)
1230 sign (cls, message, length, buffer, hash);
1231 }
1232
1234 GNUNET_free (buffer);
1235
1236 return env;
1237}
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 1241 of file messenger_api_message.c.

1242{
1243 switch (message->header.kind)
1244 {
1250 return GNUNET_YES;
1251 default:
1252 return GNUNET_NO;
1253 }
1254}

References 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 1258 of file messenger_api_message.c.

1259{
1260 if (GNUNET_YES == is_peer_message (message))
1261 return GNUNET_YES;
1262
1263 switch (message->header.kind)
1264 {
1266 return GNUNET_YES; // Reserved for connection handling only!
1268 return GNUNET_YES; // Reserved for member handling only!
1270 return GNUNET_YES; // Reserved for member handling only!
1272 return GNUNET_YES; // Reserved for member name handling only!
1274 return GNUNET_YES; // Reserved for member key handling only!
1276 return GNUNET_YES; // Reserved for connection handling only!
1278 return GNUNET_YES; // Reserved for member id handling only!
1280 return GNUNET_YES; // Reserved for connection handling only!
1282 return GNUNET_YES; // Reserved for peers only!
1284 return GNUNET_YES; // Requests should not apply individually! (inefficieny)
1286 return GNUNET_NO;
1288 return GNUNET_NO;
1290 return GNUNET_NO;
1292 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
1294 return GNUNET_YES; // Deletion should not apply individually! (inefficieny)
1296 return GNUNET_YES; // Reserved for connection handling only!
1298 return GNUNET_NO;
1300 return GNUNET_NO;
1302 return GNUNET_NO;
1303 default:
1304 return GNUNET_SYSERR;
1305 }
1306}
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_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_TAG, 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 1310 of file messenger_api_message.c.

1311{
1312 if (GNUNET_YES == is_peer_message (message))
1313 return GNUNET_SYSERR; // Requires signature of peer rather than member!
1314
1315 switch (message->header.kind)
1316 {
1318 return GNUNET_SYSERR; // Reserved for connection handling only!
1320 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
1322 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
1324 return GNUNET_YES;
1326 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
1328 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
1330 return GNUNET_NO; // Reserved for member id handling only!
1332 return GNUNET_SYSERR; // Reserved for connection handling only!
1334 return GNUNET_SYSERR; // Reserved for peers only!
1336 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
1338 return GNUNET_YES;
1340 return GNUNET_YES;
1342 return GNUNET_YES;
1344 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
1346 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
1348 return GNUNET_SYSERR; // Reserved for connection handling only!
1350 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_ticket(...) instead!
1352 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
1354 return GNUNET_YES;
1355 default:
1356 return GNUNET_SYSERR;
1357 }
1358}

References 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_TAG, 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: