GNUnet 0.22.2
messenger_api_message.c File Reference
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...
 

Variables

const uint16_t encryption_overhead
 

Macro Definition Documentation

◆ member_size

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

Definition at line 283 of file messenger_api_message.c.

◆ max

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

Definition at line 495 of file messenger_api_message.c.

◆ min

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

Definition at line 525 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 527 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 532 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 536 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:248

Definition at line 546 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 768 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 773 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 777 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:102
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_SYSERR

Definition at line 783 of file messenger_api_message.c.

Typedef Documentation

◆ kind_t

typedef uint32_t kind_t

Definition at line 364 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 48 of file messenger_api_message.c.

49{
50 struct GNUNET_MESSENGER_Message *message;
51
52 message = GNUNET_new (struct GNUNET_MESSENGER_Message);
53 message->header.kind = kind;
54
55 switch (message->header.kind)
56 {
58 message->body.name.name = NULL;
59 break;
61 message->body.text.text = NULL;
62 break;
64 message->body.file.uri = NULL;
65 break;
67 message->body.privacy.length = 0;
68 message->body.privacy.data = NULL;
69 break;
71 message->body.ticket.identifier = NULL;
72 break;
74 message->body.transcript.length = 0;
75 message->body.transcript.data = NULL;
76 break;
78 message->body.tag.tag = NULL;
79 break;
81 message->body.talk.length = 0;
82 message->body.talk.data = NULL;
83 break;
84 default:
85 break;
86 }
87
88 return message;
89}
#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 93 of file messenger_api_message.c.

94{
95 struct GNUNET_MESSENGER_Message *copy;
96
97 GNUNET_assert (message);
98
100 GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
101
102 switch (message->header.kind)
103 {
105 copy->body.name.name = message->body.name.name? GNUNET_strdup (
106 message->body.name.name) : NULL;
107 break;
109 copy->body.text.text = message->body.text.text? GNUNET_strdup (
110 message->body.text.text) : NULL;
111 break;
113 copy->body.file.uri = message->body.file.uri? GNUNET_strdup (
114 message->body.file.uri) : NULL;
115 break;
118 copy->body.privacy.length) : NULL;
119
120 if (copy->body.privacy.data)
121 GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data,
122 copy->body.privacy.length);
123
124 break;
126 copy->body.ticket.identifier = message->body.ticket.identifier?
128 message->body.ticket.identifier) : NULL;
129 break;
132 copy->body.transcript.length) : NULL;
133
134 if (copy->body.transcript.data)
136 copy->body.transcript.length);
137
138 break;
140 copy->body.tag.tag = message->body.tag.tag? GNUNET_strdup (
141 message->body.tag.tag) : NULL;
142 break;
144 copy->body.talk.data = copy->body.talk.length ? GNUNET_malloc (
145 copy->body.talk.length) : NULL;
146
147 if (copy->body.talk.data)
148 GNUNET_memcpy (copy->body.talk.data, message->body.talk.data,
149 copy->body.talk.length);
150
151 break;
152 default:
153 break;
154 }
155
156 return copy;
157}
#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 161 of file messenger_api_message.c.

163{
165
166 GNUNET_assert ((message) && (header));
167
168 kind = message->header.kind;
169
170 GNUNET_memcpy (&(message->header), header,
171 sizeof(struct GNUNET_MESSENGER_MessageHeader));
172
173 message->header.kind = kind;
174}
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 178 of file messenger_api_message.c.

180{
181 GNUNET_assert (body);
182
183 switch (kind)
184 {
186 if (body->name.name)
187 GNUNET_free (body->name.name);
188 break;
190 if (body->text.text)
191 GNUNET_free (body->text.text);
192 break;
194 if (body->file.uri)
195 GNUNET_free (body->file.uri);
196 break;
198 if (body->privacy.data)
199 GNUNET_free (body->privacy.data);
200 break;
202 if (body->ticket.identifier)
204 break;
206 if (body->transcript.data)
208 break;
210 if (body->tag.tag)
211 GNUNET_free (body->tag.tag);
212 break;
214 if (body->talk.data)
215 GNUNET_free (body->talk.data);
216 break;
217 default:
218 break;
219 }
220}
#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_assert, 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 224 of file messenger_api_message.c.

225{
226 GNUNET_assert (message);
227
228 destroy_message_body (message->header.kind, &(message->body));
229}
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 233 of file messenger_api_message.c.

234{
235 GNUNET_assert (message);
236
237 destroy_message_body (message->header.kind, &(message->body));
238
239 GNUNET_free (message);
240}

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

245{
246 GNUNET_assert (message);
247
248 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) ||
250 (GNUNET_MESSENGER_KIND_NAME == message->header.kind) ||
251 (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
253 return GNUNET_YES;
254 else
255 return GNUNET_NO;
256}
@ 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 260 of file messenger_api_message.c.

262{
263 shortened->kind = message->header.kind;
264
265 GNUNET_memcpy (&(shortened->body), &(message->body), sizeof(struct
267}
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 271 of file messenger_api_message.c.

273{
274 destroy_message_body (message->header.kind, &(message->body));
275
276 message->header.kind = shortened->kind;
277
278 GNUNET_memcpy (&(message->body), &(shortened->body),
279 sizeof(struct GNUNET_MESSENGER_MessageBody));
280}

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

287{
288 uint16_t length;
289
290 length = 0;
291
292 switch (kind)
293 {
295 length += member_size (struct GNUNET_MESSENGER_Message,
296 body.info.messenger_version);
297 break;
299 length += member_size (struct GNUNET_MESSENGER_Message, body.peer.peer);
300 break;
302 length += member_size (struct GNUNET_MESSENGER_Message, body.id.id);
303 break;
305 length += member_size (struct GNUNET_MESSENGER_Message, body.miss.peer);
306 break;
308 length += member_size (struct GNUNET_MESSENGER_Message,
309 body.merge.previous);
310 break;
312 length += member_size (struct GNUNET_MESSENGER_Message, body.request.hash);
313 break;
315 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.door);
316 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.key);
317 break;
319 length += member_size (struct GNUNET_MESSENGER_Message, body.file.key);
320 length += member_size (struct GNUNET_MESSENGER_Message, body.file.hash);
321 length += member_size (struct GNUNET_MESSENGER_Message, body.file.name);
322 break;
324 length += member_size (struct GNUNET_MESSENGER_Message, body.privacy.key);
325 break;
327 length += member_size (struct GNUNET_MESSENGER_Message, body.deletion.hash);
328 length += member_size (struct GNUNET_MESSENGER_Message,
329 body.deletion.delay);
330 break;
332 length += member_size (struct GNUNET_MESSENGER_Message,
333 body.connection.amount);
334 length += member_size (struct GNUNET_MESSENGER_Message,
335 body.connection.flags);
336 break;
338 length += member_size (struct GNUNET_MESSENGER_Message,
339 body.transcript.hash);
340 break;
342 length += member_size (struct GNUNET_MESSENGER_Message, body.tag.hash);
343 break;
345 length += member_size (struct GNUNET_MESSENGER_Message,
346 body.subscribe.discourse);
347 length += member_size (struct GNUNET_MESSENGER_Message,
348 body.subscribe.time);
349 length += member_size (struct GNUNET_MESSENGER_Message,
350 body.subscribe.flags);
351 break;
353 length += member_size (struct GNUNET_MESSENGER_Message,
354 body.talk.discourse);
355 break;
356 default:
357 break;
358 }
359
360 return length;
361}
@ 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 367 of file messenger_api_message.c.

369{
370 uint16_t length;
371
372 length = 0;
373
374 if (GNUNET_YES == include_header)
375 {
376 length += member_size (struct GNUNET_MESSENGER_Message, header.timestamp);
377 length += member_size (struct GNUNET_MESSENGER_Message, header.sender_id);
378 length += member_size (struct GNUNET_MESSENGER_Message, header.previous);
379 }
380
381 length += sizeof(kind_t);
382
383 return length + get_message_body_kind_size (kind);
384}
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 388 of file messenger_api_message.c.

390{
391 uint16_t length;
392
393 length = 0;
394
395 switch (kind)
396 {
398 length += GNUNET_CRYPTO_public_key_get_length (&(body->join.key));
399 break;
401 length += (body->name.name ? strlen (body->name.name) : 0);
402 break;
404 length += GNUNET_CRYPTO_public_key_get_length (&(body->key.key));
405 break;
407 length += (body->text.text ? strlen (body->text.text) : 0);
408 break;
410 length += (body->file.uri ? strlen (body->file.uri) : 0);
411 break;
413 length += body->privacy.length;
414 break;
416 length += (body->ticket.identifier ? strlen (body->ticket.identifier) : 0);
417 break;
420 length += body->transcript.length;
421 break;
423 length += (body->tag.tag ? strlen (body->tag.tag) : 0);
424 break;
426 length += body->talk.length;
427 break;
428 default:
429 break;
430 }
431
432 return length;
433}
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 437 of file messenger_api_message.c.

439{
440 uint16_t length;
441
442 GNUNET_assert (message);
443
444 length = 0;
445
446 if (GNUNET_YES == include_header)
448 &(message->header.signature));
449
450 length += get_message_kind_size (message->header.kind, include_header);
451 length += get_message_body_size (message->header.kind, &(message->body));
452
453 return length;
454}
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:190
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 458 of file messenger_api_message.c.

460{
461 uint16_t minimum_size;
462
463 minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t);
464
465 if (message)
466 return minimum_size + get_message_body_kind_size (message->kind)
467 + (include_body == GNUNET_YES?
468 get_message_body_size (message->kind, &(message->body)) : 0);
469 else
470 return minimum_size;
471}
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 475 of file messenger_api_message.c.

476{
477 uint16_t padding;
478 uint16_t kind_size;
479
480 padding = 0;
481
482 for (unsigned int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++)
483 {
485 GNUNET_YES);
486
487 if (kind_size > padding)
488 padding = kind_size;
489 }
490
491 return padding + GNUNET_MESSENGER_PADDING_MIN;
492}
#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 498 of file messenger_api_message.c.

499{
500 static uint16_t usual_padding = 0;
501 uint16_t padded_length;
502
503 if (! usual_padding)
504 usual_padding = calc_usual_padding ();
505
506 padded_length = max (
508 usual_padding
509 );
510
511 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0)
513
514 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL1)
516
517 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL2)
519
521
522}
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 557 of file messenger_api_message.c.

562{
563 uint32_t value0, value1;
564
565 GNUNET_assert ((body) && (buffer));
566
567 switch (kind)
568 {
570 value0 = GNUNET_htobe32 (body->info.messenger_version);
571
572 encode_step (buffer, offset, &value0);
573 break;
575 encode_step_key (buffer, offset, &(body->join.key), length);
576 break;
578 break;
580 if (body->name.name)
581 encode_step_ext (buffer, offset, body->name.name, min (length - offset,
582 strlen (
583 body->name.name))
584 );
585 break;
587 encode_step_key (buffer, offset, &(body->key.key), length);
588 break;
590 encode_step (buffer, offset, &(body->peer.peer));
591 break;
593 encode_step (buffer, offset, &(body->id.id));
594 break;
596 encode_step (buffer, offset, &(body->miss.peer));
597 break;
599 encode_step (buffer, offset, &(body->merge.previous));
600 break;
602 encode_step (buffer, offset, &(body->request.hash));
603 break;
605 encode_step (buffer, offset, &(body->invite.door));
606 encode_step (buffer, offset, &(body->invite.key));
607 break;
609 if (body->text.text)
610 encode_step_ext (buffer, offset, body->text.text, min (length - offset,
611 strlen (
612 body->text.text))
613 );
614 break;
616 encode_step (buffer, offset, &(body->file.key));
617 encode_step (buffer, offset, &(body->file.hash));
618 encode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
619 if (body->file.uri)
620 encode_step_ext (buffer, offset, body->file.uri, min (length - offset,
621 strlen (
622 body->file.uri)));
623 break;
625 encode_step (buffer, offset, &(body->privacy.key));
626
627 if (body->privacy.data)
628 encode_step_ext (buffer, offset, body->privacy.data, min (length - offset,
629 body->privacy.
630 length));
631 break;
633 encode_step (buffer, offset, &(body->deletion.hash));
634 encode_step (buffer, offset, &(body->deletion.delay));
635 break;
637 value0 = GNUNET_htobe32 (body->connection.amount);
638 value1 = GNUNET_htobe32 (body->connection.flags);
639
640 encode_step (buffer, offset, &value0);
641 encode_step (buffer, offset, &value1);
642 break;
644 encode_step_ext (buffer, offset, body->ticket.identifier,
645 min (length - offset, strlen (body->ticket.identifier)));
646 break;
648 encode_step (buffer, offset, &(body->transcript.hash));
649 encode_step_key (buffer, offset, &(body->transcript.key), length);
650
651 if (body->transcript.data)
652 encode_step_ext (buffer, offset, body->transcript.data, min (length
653 - offset,
654 body->
655 transcript.
656 length));
657 break;
659 encode_step (buffer, offset, &(body->tag.hash));
660
661 if (body->tag.tag)
662 encode_step_ext (buffer, offset, body->tag.tag, min (length - offset,
663 strlen (
664 body->tag.tag)));
665 break;
667 value0 = GNUNET_htobe32 (body->subscribe.flags);
668
669 encode_step (buffer, offset, &(body->subscribe.discourse));
670 encode_step (buffer, offset, &(body->subscribe.time));
671 encode_step (buffer, offset, &value0);
672 break;
674 encode_step (buffer, offset, &(body->talk.discourse));
675
676 if (body->talk.data)
677 encode_step_ext (buffer, offset, body->talk.data, min (length - offset,
678 body->talk.
679 length));
680 break;
681 default:
682 break;
683 }
684
685 if (offset >= length)
686 return;
687
688 {
689 uint16_t padding;
690 uint16_t used_padding;
691
692 padding = length - offset;
693 used_padding = sizeof(padding) + sizeof(char);
694
695 GNUNET_assert (padding >= used_padding);
696
697 buffer[offset++] = '\0';
698
699 if (padding > used_padding)
701 padding - used_padding);
702
703 GNUNET_memcpy (buffer + length - sizeof(padding), &padding, sizeof(padding));
704 }
705}
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 709 of file messenger_api_message.c.

713{
714 uint16_t offset;
715 kind_t kind;
716
717 GNUNET_assert ((message) && (buffer));
718
719 offset = 0;
720
721 if (GNUNET_YES == include_header)
722 encode_step_signature (buffer, offset, &(message->header.signature),
723 length);
724
725 kind = GNUNET_htobe32 ((kind_t) message->header.kind);
726
727 if (GNUNET_YES == include_header)
728 {
729 encode_step (buffer, offset, &(message->header.timestamp));
730 encode_step (buffer, offset, &(message->header.sender_id));
731 encode_step (buffer, offset, &(message->header.previous));
732 }
733
734 encode_step (buffer, offset, &kind);
735
736 encode_message_body (message->header.kind, &(message->body),
737 length, buffer, offset);
738}
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 742 of file messenger_api_message.c.

745{
746 struct GNUNET_HashCode hash;
747 uint16_t offset;
748 kind_t kind;
749
750 GNUNET_assert ((message) && (buffer));
751
752 offset = sizeof(hash);
753 kind = GNUNET_htobe32 ((kind_t) message->kind);
754
755 encode_step (buffer, offset, &kind);
756
757 encode_message_body (message->kind, &(message->body), length, buffer, offset);
758
760 buffer + sizeof(hash),
761 length - sizeof(hash),
762 &hash);
763
764 GNUNET_memcpy (buffer, &hash, sizeof(hash));
765}
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_assert, 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 796 of file messenger_api_message.c.

801{
802 uint16_t padding;
803 uint32_t value0, value1;
804
805 GNUNET_assert ((kind) && (body) && (buffer));
806
807 padding = 0;
808
809 GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding));
810
811 if (padding > length - offset)
812 padding = 0;
813
814 {
815 uint16_t end_zero;
816 end_zero = length - padding;
817
818 if ((padding) && (buffer[end_zero] != '\0'))
819 padding = 0;
820 }
821
822 length -= padding;
823
824 switch (*kind)
825 {
827 decode_step (buffer, offset, &value0);
828
829 body->info.messenger_version = GNUNET_be32toh (value0);
830 break;
832 decode_step_key (buffer, offset, &(body->join.key), length);
833 break;
835 break;
837 if (length > offset)
838 decode_step_malloc (buffer, offset, body->name.name, length - offset, 1);
839 else
840 body->name.name = NULL;
841 break;
843 decode_step_key (buffer, offset, &(body->key.key), length);
844 break;
846 decode_step (buffer, offset, &(body->peer.peer));
847 break;
849 decode_step (buffer, offset, &(body->id.id));
850 break;
852 decode_step (buffer, offset, &(body->miss.peer));
853 break;
855 decode_step (buffer, offset, &(body->merge.previous));
856 break;
858 decode_step (buffer, offset, &(body->request.hash));
859 break;
861 decode_step (buffer, offset, &(body->invite.door));
862 decode_step (buffer, offset, &(body->invite.key));
863 break;
865 if (length > offset)
866 decode_step_malloc (buffer, offset, body->text.text, length - offset, 1);
867 else
868 body->text.text = NULL;
869 break;
871 decode_step (buffer, offset, &(body->file.key));
872 decode_step (buffer, offset, &(body->file.hash));
873 decode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
874 if (length > offset)
875 decode_step_malloc (buffer, offset, body->file.uri, length - offset, 1);
876 else
877 body->file.uri = NULL;
878 break;
880 decode_step (buffer, offset, &(body->privacy.key));
881
882 if (length > offset)
883 {
884 body->privacy.length = (length - offset);
885 decode_step_malloc (buffer, offset, body->privacy.data, length - offset,
886 0);
887 }
888 else
889 {
890 body->privacy.length = 0;
891 body->privacy.data = NULL;
892 }
893
894 break;
896 decode_step (buffer, offset, &(body->deletion.hash));
897 decode_step (buffer, offset, &(body->deletion.delay));
898 break;
900 decode_step (buffer, offset, &value0);
901 decode_step (buffer, offset, &value1);
902
903 body->connection.amount = GNUNET_be32toh (value0);
904 body->connection.flags = GNUNET_be32toh (value1);
905 break;
907 if (length > offset)
908 decode_step_malloc (buffer, offset, body->ticket.identifier, length
909 - offset, 1);
910 else
911 body->ticket.identifier = NULL;
912 break;
914 decode_step (buffer, offset, &(body->transcript.hash));
915 decode_step_key (buffer, offset, &(body->transcript.key), length);
916
917 if (length > offset)
918 {
919 body->transcript.length = (length - offset);
920 decode_step_malloc (buffer, offset, body->transcript.data,
921 length - offset, 0);
922 }
923 else
924 {
925 body->transcript.length = 0;
926 body->transcript.data = NULL;
927 }
928
929 break;
931 decode_step (buffer, offset, &(body->tag.hash));
932 if (length > offset)
933 decode_step_malloc (buffer, offset, body->tag.tag, length - offset, 1);
934 else
935 body->tag.tag = NULL;
936 break;
938 decode_step (buffer, offset, &(body->subscribe.discourse));
939 decode_step (buffer, offset, &(body->subscribe.time));
940 decode_step (buffer, offset, &value0);
941
942 body->subscribe.flags = GNUNET_be32toh (value0);
943 break;
945 decode_step (buffer, offset, &(body->talk.discourse));
946
947 if (length > offset)
948 {
949 body->talk.length = (length - offset);
950 decode_step_malloc (buffer, offset, body->talk.data, length - offset,
951 0);
952 }
953 else
954 {
955 body->talk.length = 0;
956 body->talk.data = NULL;
957 }
958
959 break;
960 default:
962 break;
963 }
964
965 return padding;
966}
#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_assert, 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 970 of file messenger_api_message.c.

975{
976 uint16_t offset;
977 uint16_t count;
978 kind_t kind;
979
981 (message) &&
982 (buffer) &&
984 include_header))
985 );
986
987 offset = 0;
988
989 if (GNUNET_YES == include_header)
990 {
991 ssize_t result;
992
994 &(message->header.signature), buffer, length - offset);
995
996 if (result < 0)
997 return GNUNET_NO;
998 else
999 offset += result;
1000 }
1001
1002 count = length - offset;
1004 include_header))
1005 return GNUNET_NO;
1006
1007 if (GNUNET_YES == include_header)
1008 {
1009 decode_step (buffer, offset, &(message->header.timestamp));
1010 decode_step (buffer, offset, &(message->header.sender_id));
1011 decode_step (buffer, offset, &(message->header.previous));
1012 }
1013
1014 decode_step (buffer, offset, &kind);
1015 kind = GNUNET_be32toh (kind);
1016
1017 message->header.kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1018
1019 if (count < get_message_kind_size (message->header.kind, include_header))
1020 return GNUNET_NO;
1021
1022 {
1023 uint16_t result;
1024 result = decode_message_body (&(message->header.kind),
1025 &(message->body), length, buffer, offset);
1026
1027 if (padding)
1028 *padding = result;
1029 }
1030
1031 return GNUNET_YES;
1032}
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:227
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 1036 of file messenger_api_message.c.

1039{
1040 struct GNUNET_HashCode expected, hash;
1041 uint16_t offset;
1042 kind_t kind;
1043
1044 GNUNET_assert ((message) && (buffer));
1045
1046 offset = sizeof(hash);
1047
1048 if (length < get_short_message_size (NULL, GNUNET_NO))
1049 return GNUNET_NO;
1050
1051 GNUNET_memcpy (&hash, buffer, sizeof(hash));
1052
1054 buffer + sizeof(hash),
1055 length - sizeof(hash),
1056 &expected);
1057
1058 if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected))
1059 return GNUNET_NO;
1060
1061 decode_step (buffer, offset, &kind);
1062 kind = GNUNET_be32toh (kind);
1063
1064 message->kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1065
1066 if (length < get_short_message_size (message, GNUNET_NO))
1067 return GNUNET_NO;
1068
1069 decode_message_body (&(message->kind), &(message->body), length, buffer,
1070 offset);
1071
1072 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind)
1073 return GNUNET_NO;
1074
1075 return GNUNET_YES;
1076}
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:218
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_assert, 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 1080 of file messenger_api_message.c.

1084{
1085 ssize_t offset;
1086
1087 GNUNET_assert ((message) && (buffer) && (hash));
1088
1090
1091 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1092}

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

1101{
1102 GNUNET_assert ((message) && (buffer) && (hash) && (key));
1103
1104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1105 GNUNET_h2s (hash));
1106
1107 {
1108 struct GNUNET_MESSENGER_MessageSignature signature;
1109
1111 signature.purpose.size = htonl (sizeof(signature));
1112
1113 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1114 GNUNET_CRYPTO_sign (key, &signature, &(message->header.signature));
1115 }
1116
1117 message->header.signature.type = key->type;
1118
1119 {
1120 uint16_t offset = 0;
1121 encode_step_signature (buffer, offset, &(message->header.signature), length);
1122 }
1123}
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE
Signature of a chat message.
#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
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 1127 of file messenger_api_message.c.

1132{
1133 GNUNET_assert ((message) && (buffer) && (hash) && (cfg));
1134
1135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
1136 GNUNET_h2s (hash));
1137
1138 {
1139 struct GNUNET_MESSENGER_MessageSignature signature;
1141 signature.purpose.size = htonl (sizeof(signature));
1142
1143 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1144 GNUNET_CRYPTO_sign_by_peer_identity (cfg, &(signature.purpose),
1145 &(message->header.signature.
1146 eddsa_signature));
1147 }
1148
1150
1151 {
1152 uint16_t offset = 0;
1153 encode_step_signature (buffer, offset, &(message->header.signature), length);
1154 }
1155}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
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 1159 of file messenger_api_message.c.

1162{
1163 struct GNUNET_MESSENGER_MessageSignature signature;
1164
1165 GNUNET_assert ((message) && (hash) && (key));
1166
1167 if (key->type != message->header.signature.type)
1168 return GNUNET_SYSERR;
1169
1170 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1171 signature.purpose.size = htonl (sizeof(signature));
1172
1173 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1174
1177 &(message->header.signature), key);
1178}
#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 1182 of file messenger_api_message.c.

1185{
1186 struct GNUNET_MESSENGER_MessageSignature signature;
1187
1188 GNUNET_assert ((message) && (hash) && (identity));
1189
1190 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1191 return GNUNET_SYSERR;
1192
1193 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1194 signature.purpose.size = htonl (sizeof(signature));
1195
1196 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1197
1199 GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &(signature.purpose),
1200 &(message->header.signature.
1201 eddsa_signature), identity);
1202}
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 1206 of file messenger_api_message.c.

1208{
1209 struct GNUNET_CRYPTO_EcdhePublicKey hpke_key;
1211 struct GNUNET_MESSENGER_ShortMessage shortened;
1212 uint16_t length, padded_length, encoded_length;
1213 uint8_t *data;
1214
1215 GNUNET_assert ((message) && (key));
1216
1217 if (GNUNET_YES == is_service_message (message))
1218 return GNUNET_NO;
1219
1220 fold_short_message (message, &shortened);
1221
1222 length = get_short_message_size (&shortened, GNUNET_YES);
1223 padded_length = calc_padded_length (length + encryption_overhead);
1224
1225 GNUNET_assert (padded_length >= length + encryption_overhead);
1226
1228 message->body.privacy.data = GNUNET_malloc (padded_length);
1229 message->body.privacy.length = padded_length;
1230
1232 encoded_length = (padded_length - encryption_overhead);
1233
1234 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1235
1236 result = GNUNET_NO;
1237 data = GNUNET_malloc (encoded_length);
1238
1239 encode_short_message (&shortened, encoded_length, (char *) data);
1240
1242 (uint8_t*) "messenger",
1243 strlen ("messenger"),
1244 NULL, 0,
1245 (uint8_t*) data,
1246 encoded_length,
1247 (uint8_t*) message->body.
1248 privacy.data,
1249 NULL))
1250 {
1251 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1252
1253 unfold_short_message (&shortened, message);
1254 goto cleanup;
1255 }
1256
1257 destroy_message_body (shortened.kind, &(shortened.body));
1259
1260cleanup:
1261 GNUNET_free (data);
1262 return result;
1263}
static char * data
The data to insert into the dht.
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:131
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:929
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:989
@ 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)
const uint16_t encryption_overhead
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(), cleanup(), data, GNUNET_MESSENGER_MessagePrivate::data, destroy_message_body(), encode_short_message(), encryption_overhead, fold_short_message(), get_short_message_size(), GNUNET_assert, GNUNET_CRYPTO_hpke_pk_to_x25519(), GNUNET_CRYPTO_hpke_seal_oneshot(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, 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, result, 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 1267 of file messenger_api_message.c.

1269{
1270 struct GNUNET_CRYPTO_EcdhePrivateKey hpke_key;
1272 uint16_t padded_length, encoded_length;
1273 uint8_t *data;
1274
1275 GNUNET_assert ((message) && (key));
1276
1277 padded_length = message->body.privacy.length;
1278
1279 if (padded_length < encryption_overhead)
1280 {
1282 "Message length too short to decrypt!\n");
1283
1284 return GNUNET_NO;
1285 }
1286
1288 encoded_length = (padded_length - encryption_overhead);
1289
1290 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1291
1292 result = GNUNET_NO;
1293 data = GNUNET_malloc (encoded_length);
1294
1295 if (GNUNET_OK !=
1297 (uint8_t*) "messenger",
1298 strlen ("messenger"),
1299 NULL, 0,
1300 (uint8_t*) message->body.privacy.data,
1301 padded_length,
1302 (uint8_t*) data,
1303 NULL))
1304 {
1305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1306
1307 goto cleanup;
1308 }
1309
1310 {
1311 struct GNUNET_MESSENGER_ShortMessage shortened;
1312 if (GNUNET_YES != decode_short_message (&shortened,
1313 encoded_length,
1314 (char*) data))
1315 {
1317 "Decoding decrypted message failed!\n");
1318
1319 goto cleanup;
1320 }
1321
1322 unfold_short_message (&shortened, message);
1324 }
1325
1326cleanup:
1327 GNUNET_free (data);
1328 return result;
1329}
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:958
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:1013
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, cleanup(), data, GNUNET_MESSENGER_MessagePrivate::data, decode_short_message(), encryption_overhead, GNUNET_assert, GNUNET_CRYPTO_hpke_open_oneshot(), GNUNET_CRYPTO_hpke_sk_to_x25519(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_NO, GNUNET_OK, GNUNET_YES, key, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageBody::privacy, result, 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 1333 of file messenger_api_message.c.

1335{
1336 struct GNUNET_MESSENGER_Message *transcript;
1337
1338 GNUNET_assert ((message) && (key));
1339
1340 if (GNUNET_YES == is_service_message (message))
1341 return NULL;
1342
1344
1345 if (! transcript)
1346 {
1347 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1348 return NULL;
1349 }
1350
1351 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1352 sizeof(transcript->body.transcript.key));
1353
1354 {
1355 struct GNUNET_MESSENGER_ShortMessage shortened;
1356 uint16_t data_length;
1357
1358 fold_short_message (message, &shortened);
1359
1360 data_length = get_short_message_size (&shortened, GNUNET_YES);
1361
1362 transcript->body.transcript.data = GNUNET_malloc (data_length);
1363 transcript->body.transcript.length = data_length;
1364
1365 encode_short_message (&shortened, data_length,
1366 transcript->body.transcript.data);
1367 }
1368
1369 return transcript;
1370}
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 1374 of file messenger_api_message.c.

1375{
1376 uint16_t data_length;
1377 struct GNUNET_MESSENGER_ShortMessage shortened;
1378
1379 GNUNET_assert (message);
1380
1382 return GNUNET_NO;
1383
1384 data_length = message->body.transcript.length;
1385
1386 if (GNUNET_YES != decode_short_message (&shortened,
1387 data_length,
1388 message->body.transcript.data))
1389 {
1391 "Decoding decrypted message failed!\n");
1392
1393 return GNUNET_NO;
1394 }
1395
1396 unfold_short_message (&shortened, message);
1397 return GNUNET_YES;
1398}

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

1407{
1408 struct GNUNET_MessageHeader *header;
1409 uint16_t length, padded_length;
1410 struct GNUNET_MQ_Envelope *env;
1411 char *buffer;
1412
1413 GNUNET_assert (message);
1414
1416 "Packing message kind=%u and sender: %s\n",
1417 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
1418
1419 length = get_message_size (message, GNUNET_YES);
1420 padded_length = calc_padded_length (length);
1421
1423 {
1424 env = GNUNET_MQ_msg_extra (header, padded_length,
1426 buffer = (char*) &(header[1]);
1427 }
1428 else
1429 {
1430 env = NULL;
1431 buffer = GNUNET_malloc (padded_length);
1432 }
1433
1434 encode_message (message, padded_length, buffer, GNUNET_YES);
1435
1436 if (hash)
1437 {
1438 hash_message (message, length, buffer, hash);
1439
1440 if (sign)
1441 sign (cls, message, length, buffer, hash);
1442 }
1443
1445 GNUNET_free (buffer);
1446
1447 return env;
1448}
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:61
#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_DEBUG, 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 1452 of file messenger_api_message.c.

1453{
1454 GNUNET_assert (message);
1455
1456 switch (message->header.kind)
1457 {
1463 return GNUNET_YES;
1464 default:
1465 return GNUNET_NO;
1466 }
1467}

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

1472{
1473 GNUNET_assert (message);
1474
1475 if (GNUNET_YES == is_peer_message (message))
1476 return GNUNET_YES;
1477
1478 switch (message->header.kind)
1479 {
1481 return GNUNET_YES; // Reserved for connection handling only!
1483 return GNUNET_YES; // Reserved for member handling only!
1485 return GNUNET_YES; // Reserved for member handling only!
1487 return GNUNET_YES; // Reserved for member name handling only!
1489 return GNUNET_YES; // Reserved for member key handling only!
1491 return GNUNET_YES; // Reserved for connection handling only!
1493 return GNUNET_YES; // Reserved for member id handling only!
1495 return GNUNET_YES; // Reserved for connection handling only!
1497 return GNUNET_YES; // Reserved for peers only!
1499 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
1501 return GNUNET_NO;
1503 return GNUNET_NO;
1505 return GNUNET_NO;
1507 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
1509 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
1511 return GNUNET_YES; // Reserved for connection handling only!
1513 return GNUNET_NO;
1515 return GNUNET_NO;
1517 return GNUNET_NO;
1519 return GNUNET_YES; // Reserved for subscription handling only!
1521 return GNUNET_NO;
1522 default:
1523 return GNUNET_SYSERR;
1524 }
1525}
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 1529 of file messenger_api_message.c.

1530{
1531 GNUNET_assert (message);
1532
1533 if (GNUNET_YES == is_peer_message (message))
1534 return GNUNET_SYSERR; // Requires signature of peer rather than member!
1535
1536 switch (message->header.kind)
1537 {
1539 return GNUNET_SYSERR; // Reserved for connection handling only!
1541 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
1543 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
1545 return GNUNET_YES;
1547 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
1549 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
1551 return GNUNET_NO; // Reserved for member id handling only!
1553 return GNUNET_SYSERR; // Reserved for connection handling only!
1555 return GNUNET_SYSERR; // Reserved for peers only!
1557 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
1559 return GNUNET_YES;
1561 return GNUNET_YES;
1563 return GNUNET_YES;
1565 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
1567 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
1569 return GNUNET_SYSERR; // Reserved for connection handling only!
1571 return GNUNET_YES;
1573 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
1575 return GNUNET_YES;
1577 return GNUNET_YES;
1579 return GNUNET_YES;
1580 default:
1581 return GNUNET_SYSERR;
1582 }
1583}

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

1588{
1589 GNUNET_assert (message);
1590
1591 switch (message->header.kind)
1592 {
1594 return &(message->body.subscribe.discourse);
1596 return &(message->body.talk.discourse);
1597 default:
1598 return NULL;
1599 }
1600}

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:

Variable Documentation

◆ encryption_overhead

const uint16_t encryption_overhead
Initial value:

Definition at line 32 of file messenger_api_message.c.

Referenced by decrypt_message(), and encrypt_message().