GNUnet  0.11.x
Data Structures | Macros | Functions
messenger_api_message.c File Reference

messenger api: client and service implementation of GNUnet MESSENGER service More...

#include "messenger_api_message.h"
Include dependency graph for messenger_api_message.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_MessageSignature
 
struct  GNUNET_MESSENGER_ShortMessage
 

Macros

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

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...
 
static void destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)
 
void destroy_message (struct GNUNET_MESSENGER_Message *message)
 Destroys a message and frees its memory fully. 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)
 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)
 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)
 
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)
 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 void decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, const char *buffer, uint16_t offset)
 
int decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer)
 Decodes a message from a given buffer of a maximal length in bytes. More...
 
static int decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer)
 
void hash_message (uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
 Calculates a hash of a given buffer of a length in bytes. More...
 
void sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego)
 Signs the hash of a message with a given ego and writes the signature into the buffer as well. More...
 
int verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_IDENTITY_PublicKey *key)
 Verifies the signature of a given message and its hash with a specific public key. More...
 
int encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PublicKey *key)
 Encrypts a message using a given public key and replaces its body and kind with the now private encrypted message. More...
 
int decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key)
 Decrypts a private message using a given private key and replaces its body and kind with the inner encrypted message. More...
 
struct GNUNET_MQ_Envelopepack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego, int mode)
 Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_PACK_MODE_ENVELOPE. More...
 

Detailed Description

messenger api: client and service implementation of GNUnet MESSENGER service

Author
Tobias Frisch

Definition in file messenger_api_message.c.

Macro Definition Documentation

◆ member_size

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

Definition at line 151 of file messenger_api_message.c.

Referenced by get_message_body_kind_size(), and get_message_kind_size().

◆ min

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

◆ 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:67

Definition at line 268 of file messenger_api_message.c.

Referenced by encode_message_body().

◆ encode_step

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

Definition at line 273 of file messenger_api_message.c.

Referenced by encode_message(), encode_message_body(), and encode_short_message().

◆ decode_step_ext

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

Definition at line 360 of file messenger_api_message.c.

Referenced by decode_message_body().

◆ decode_step

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

Definition at line 365 of file messenger_api_message.c.

Referenced by decode_message(), decode_message_body(), and decode_short_message().

◆ 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 unsigned int size
Size of the "table".
Definition: peer.c:67
static const struct GNUNET_IDENTITY_PrivateKey zero
Public key of all zeros.
#define GNUNET_malloc(size)
Wrapper around malloc.

Definition at line 369 of file messenger_api_message.c.

Referenced by decode_message_body().

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
kindKind of message
Returns
New message

Definition at line 41 of file messenger_api_message.c.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_TEXT, GNUNET_new, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::private, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by create_message_id(), create_message_info(), create_message_invite(), create_message_join(), create_message_key(), create_message_leave(), create_message_merge(), create_message_miss(), create_message_name(), create_message_peer(), create_message_request(), create_message_text(), get_store_message(), and run().

42 {
44 
45  message->header.kind = kind;
46 
47  switch (message->header.kind)
48  {
50  message->body.name.name = NULL;
51  break;
53  message->body.text.text = NULL;
54  break;
56  message->body.file.uri = NULL;
57  break;
59  message->body.private.length = 0;
60  message->body.private.data = NULL;
61  break;
62  default:
63  break;
64  }
65 
66  return message;
67 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
char * uri
The uri of the encrypted file.
struct GNUNET_MESSENGER_MessageText text
#define GNUNET_new(type)
Allocate a struct or union of the given type.
char * text
The containing text.
struct GNUNET_MESSENGER_MessageBody body
Body.
uint16_t length
The length of the encrypted message.
struct GNUNET_MESSENGER_MessageName name
char * data
The data of the encrypted message.
struct GNUNET_MESSENGER_MessagePrivate private
char * name
The new name which replaces the current senders name.
struct GNUNET_MESSENGER_MessageFile file
enum GNUNET_MESSENGER_MessageKind kind
The kind of the 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
messageMessage
Returns
New message

Definition at line 70 of file messenger_api_message.c.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageBody::file, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_TEXT, GNUNET_new, GNUNET_strdup, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::private, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by forward_room_message(), forward_tunnel_message(), handle_room_message(), handle_tunnel_message(), iterate_send_room_message(), send_room_message(), send_room_message_ext(), and send_tunnel_message().

71 {
73 
74  GNUNET_memcpy(copy, message, sizeof(struct GNUNET_MESSENGER_Message));
75 
76  switch (message->header.kind)
77  {
79  copy->body.name.name = GNUNET_strdup(message->body.name.name);
80  break;
82  copy->body.text.text = GNUNET_strdup(message->body.text.text);
83  break;
85  copy->body.file.uri = GNUNET_strdup(message->body.file.uri);
86  break;
88  copy->body.private.data = copy->body.private.length ? GNUNET_malloc(copy->body.private.length) : NULL;
89 
90  if (copy->body.private.data)
91  {
92  GNUNET_memcpy(copy->body.private.data, message->body.private.data, copy->body.private.length);
93  }
94 
95  break;
96  default:
97  break;
98  }
99 
100  return copy;
101 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
char * uri
The uri of the encrypted file.
struct GNUNET_MESSENGER_MessageText text
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
char * text
The containing text.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_MESSENGER_MessageBody body
Body.
uint16_t length
The length of the encrypted message.
struct GNUNET_MESSENGER_MessageName name
char * data
The data of the encrypted message.
struct GNUNET_MESSENGER_MessagePrivate private
char * name
The new name which replaces the current senders name.
struct GNUNET_MESSENGER_MessageFile file
#define GNUNET_malloc(size)
Wrapper around malloc.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the 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 104 of file messenger_api_message.c.

References GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageBody::file, GNUNET_free, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::private, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, and GNUNET_MESSENGER_MessageFile::uri.

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

105 {
106  switch (kind)
107  {
109  GNUNET_free(body->name.name);
110  break;
112  GNUNET_free(body->text.text);
113  break;
115  GNUNET_free(body->file.uri);
116  break;
118  GNUNET_free(body->private.data);
119  break;
120  default:
121  break;
122  }
123 }
char * uri
The uri of the encrypted file.
struct GNUNET_MESSENGER_MessageText text
char * text
The containing text.
struct GNUNET_MESSENGER_MessageName name
char * data
The data of the encrypted message.
struct GNUNET_MESSENGER_MessagePrivate private
char * name
The new name which replaces the current senders name.
struct GNUNET_MESSENGER_MessageFile file
#define GNUNET_free(ptr)
Wrapper around free.
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
messageMessage

Definition at line 126 of file messenger_api_message.c.

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

Referenced by callback_ego_create(), callback_room_disconnect(), close_service_room(), create_message_info(), create_message_peer(), get_room_message(), get_store_message(), handle_room_message(), iterate_destroy_message(), iterate_destroy_messages(), join_room(), merge_room_last_messages(), open_room(), recv_message_info(), send_room_info(), and set_handle_name().

127 {
128  destroy_message_body (message->header.kind, &(message->body));
129 
130  GNUNET_free(message);
131 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
static void destroy_message_body(enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:
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 134 of file messenger_api_message.c.

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

Referenced by encrypt_message().

135 {
136  shortened->kind = message->header.kind;
137 
138  GNUNET_memcpy(&(shortened->body), &(message->body), sizeof(struct GNUNET_MESSENGER_MessageBody));
139 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
enum GNUNET_MESSENGER_MessageKind kind
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
The unified body of a GNUNET_MESSENGER_Message.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageBody body
enum GNUNET_MESSENGER_MessageKind kind
The kind of the 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 142 of file messenger_api_message.c.

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

Referenced by decrypt_message(), and encrypt_message().

143 {
144  destroy_message_body (message->header.kind, &(message->body));
145 
146  message->header.kind = shortened->kind;
147 
148  GNUNET_memcpy(&(message->body), &(shortened->body), sizeof(struct GNUNET_MESSENGER_MessageBody));
149 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
enum GNUNET_MESSENGER_MessageKind kind
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
The unified body of a GNUNET_MESSENGER_Message.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageBody body
static void destroy_message_body(enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)
enum GNUNET_MESSENGER_MessageKind kind
The kind of the 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 154 of file messenger_api_message.c.

References GNUNET_MESSENGER_MessageInvite::door, GNUNET_MESSENGER_MessageBody::file, 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_TEXT, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageFile::hash, GNUNET_MESSENGER_MessageInfo::host_key, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageFile::key, GNUNET_MESSENGER_MessagePrivate::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessageJoin::key, member_size, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageBody::private, GNUNET_MESSENGER_MessageBody::request, and GNUNET_MESSENGER_MessageInfo::unique_id.

Referenced by get_message_kind_size(), and get_short_message_size().

155 {
156  uint16_t length = 0;
157 
158  switch (kind)
159  {
163  break;
165  length += member_size(struct GNUNET_MESSENGER_Message, body.join.key);
166  break;
168  break;
170  break;
172  length += member_size(struct GNUNET_MESSENGER_Message, body.key.key);
173  break;
176  break;
178  length += member_size(struct GNUNET_MESSENGER_Message, body.id.id);
179  break;
182  break;
185  break;
188  break;
192  break;
194  break;
196  length += member_size(struct GNUNET_MESSENGER_Message, body.file.key);
198  length += NAME_MAX;
199  break;
202  break;
203  default:
204  break;
205  }
206 
207  return length;
208 }
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
struct GNUNET_ShortHashCode unique_id
The new unique id for the receiver in a room.
struct GNUNET_IDENTITY_PublicKey host_key
The senders key to verify its signatures.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
struct GNUNET_HashCode hash
The hash of the requested message.
struct GNUNET_MESSENGER_MessageKey key
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_IDENTITY_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_MESSENGER_MessageInvite invite
struct GNUNET_IDENTITY_PublicKey key
The new public key which replaces the current senders public key.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_CRYPTO_SymmetricSessionKey key
The symmetric key to decrypt the file.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_HashCode hash
The hash of the original file.
struct GNUNET_MESSENGER_MessageInfo info
struct GNUNET_CRYPTO_EcdhePublicKey key
The ECDH key to decrypt the message.
struct GNUNET_MESSENGER_MessagePeer peer
struct GNUNET_MESSENGER_MessagePrivate private
struct GNUNET_HashCode key
The hash identifying the port of the room.
#define member_size(type, member)
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_MESSENGER_MessageFile file
struct GNUNET_MESSENGER_MessageId id
Here is the caller graph for this function:

◆ get_message_kind_size()

uint16_t get_message_kind_size ( enum GNUNET_MESSENGER_MessageKind  kind)

Returns the minimal size in bytes to encode a message of a specific kind.

Parameters
kindKind of message
Returns
Minimal size to encode

Definition at line 211 of file messenger_api_message.c.

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

Referenced by decode_message(), and get_message_size().

212 {
213  uint16_t length = 0;
214 
219  length += member_size(struct GNUNET_MESSENGER_Message, header.kind);
220 
221  return length + get_message_body_kind_size (kind);
222 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
static uint16_t get_message_body_kind_size(enum GNUNET_MESSENGER_MessageKind kind)
struct GNUNET_IDENTITY_Signature signature
The signature of the senders private key.
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
#define member_size(type, member)
enum GNUNET_MESSENGER_MessageKind kind
The kind of the 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 225 of file messenger_api_message.c.

References GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::private, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by get_message_size(), and get_short_message_size().

226 {
227  uint16_t length = 0;
228 
229  switch (kind)
230  {
232  length += (body->name.name? strlen (body->name.name) : 0);
233  break;
235  length += strlen (body->text.text);
236  break;
238  length += strlen (body->file.uri);
239  break;
241  length += body->private.length;
242  break;
243  default:
244  break;
245  }
246 
247  return length;
248 }
char * uri
The uri of the encrypted file.
struct GNUNET_MESSENGER_MessageText text
char * text
The containing text.
uint16_t length
The length of the encrypted message.
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessagePrivate private
char * name
The new name which replaces the current senders name.
struct GNUNET_MESSENGER_MessageFile file
Here is the caller graph for this function:

◆ get_message_size()

uint16_t get_message_size ( const struct GNUNET_MESSENGER_Message message)

Returns the exact size in bytes to encode a given message.

Parameters
messageMessage
Returns
Size to encode

Definition at line 251 of file messenger_api_message.c.

References GNUNET_MESSENGER_Message::body, get_message_body_size(), get_message_kind_size(), GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by GNUNET_MESSENGER_send_message(), handle_service_message(), iterate_save_messages(), and pack_message().

252 {
253  return get_message_kind_size (message->header.kind) + get_message_body_size (message->header.kind, &(message->body));
254 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
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)
Returns the minimal size in bytes to encode a message of a specific kind.
struct GNUNET_MESSENGER_MessageBody body
Body.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
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)
static

Definition at line 257 of file messenger_api_message.c.

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

Referenced by decode_short_message(), and encrypt_message().

258 {
259  if (message)
260  return sizeof(message->kind) + get_message_body_kind_size (message->kind)
261  + get_message_body_size (message->kind, &(message->body));
262  else
263  return sizeof(message->kind);
264 }
enum GNUNET_MESSENGER_MessageKind kind
static uint16_t get_message_body_size(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body)
static uint16_t get_message_body_kind_size(enum GNUNET_MESSENGER_MessageKind kind)
struct GNUNET_MESSENGER_MessageBody body
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 278 of file messenger_api_message.c.

References GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageInvite::door, encode_step, encode_step_ext, GNUNET_MESSENGER_MessageBody::file, 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_TEXT, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageFile::hash, GNUNET_MESSENGER_MessageInfo::host_key, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageFile::key, GNUNET_MESSENGER_MessagePrivate::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageBody::merge, min, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageFile::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageBody::private, GNUNET_MESSENGER_MessageBody::request, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageInfo::unique_id, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by encode_message(), and encode_short_message().

280 {
281  switch (kind)
282  {
284  encode_step(buffer, offset, &(body->info.host_key));
285  encode_step(buffer, offset, &(body->info.unique_id));
286  break;
288  encode_step(buffer, offset, &(body->join.key));
289  break;
291  break;
293  if (body->name.name)
294  encode_step_ext(buffer, offset, body->name.name, min(length - offset, strlen(body->name.name)));
295  break;
297  encode_step(buffer, offset, &(body->key.key));
298  break;
300  encode_step(buffer, offset, &(body->peer.peer));
301  break;
303  encode_step(buffer, offset, &(body->id.id));
304  break;
306  encode_step(buffer, offset, &(body->miss.peer));
307  break;
309  encode_step(buffer, offset, &(body->merge.previous));
310  break;
312  encode_step(buffer, offset, &(body->request.hash));
313  break;
315  encode_step(buffer, offset, &(body->invite.door));
316  encode_step(buffer, offset, &(body->invite.key));
317  break;
319  encode_step_ext(buffer, offset, body->text.text, min(length - offset, strlen(body->text.text)));
320  break;
322  encode_step(buffer, offset, &(body->file.key));
323  encode_step(buffer, offset, &(body->file.hash));
324  encode_step_ext(buffer, offset, body->file.name, NAME_MAX);
325  encode_step_ext(buffer, offset, body->file.uri, min(length - offset, strlen(body->file.uri)));
326  break;
328  encode_step(buffer, offset, &(body->private.key));
329  encode_step_ext(buffer, offset, body->private.data, min(length - offset, body->private.length));
330  break;
331  default:
332  break;
333  }
334 }
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
struct GNUNET_ShortHashCode unique_id
The new unique id for the receiver in a room.
char * uri
The uri of the encrypted file.
struct GNUNET_IDENTITY_PublicKey host_key
The senders key to verify its signatures.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
struct GNUNET_MESSENGER_MessageText text
struct GNUNET_HashCode hash
The hash of the requested message.
struct GNUNET_MESSENGER_MessageKey key
#define encode_step(dst, offset, src)
char name[NAME_MAX]
The name of the original file.
char * text
The containing text.
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_IDENTITY_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_MESSENGER_MessageInvite invite
struct GNUNET_IDENTITY_PublicKey key
The new public key which replaces the current senders public key.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_CRYPTO_SymmetricSessionKey key
The symmetric key to decrypt the file.
uint16_t length
The length of the encrypted message.
struct GNUNET_MESSENGER_MessageMerge merge
#define encode_step_ext(dst, offset, src, size)
struct GNUNET_HashCode hash
The hash of the original file.
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageInfo info
struct GNUNET_CRYPTO_EcdhePublicKey key
The ECDH key to decrypt the message.
struct GNUNET_MESSENGER_MessagePeer peer
#define min(x, y)
char * data
The data of the encrypted message.
struct GNUNET_MESSENGER_MessagePrivate private
char * name
The new name which replaces the current senders name.
struct GNUNET_HashCode key
The hash identifying the port of the room.
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_MESSENGER_MessageFile file
struct GNUNET_MESSENGER_MessageId id
Here is the caller graph for this function:

◆ encode_message()

void encode_message ( const struct GNUNET_MESSENGER_Message message,
uint16_t  length,
char *  buffer 
)

Encodes a given message into a buffer of a maximal length in bytes.

Parameters
messageMessage
lengthMaximal length to encode
[out]bufferBuffer

Definition at line 337 of file messenger_api_message.c.

References GNUNET_MESSENGER_Message::body, encode_message_body(), encode_step, 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 GNUNET_MESSENGER_send_message(), handle_service_message(), iterate_save_messages(), and pack_message().

338 {
339  uint16_t offset = 0;
340 
341  encode_step(buffer, offset, &(message->header.signature));
342  encode_step(buffer, offset, &(message->header.timestamp));
343  encode_step(buffer, offset, &(message->header.sender_id));
344  encode_step(buffer, offset, &(message->header.previous));
345  encode_step(buffer, offset, &(message->header.kind));
346 
347  encode_message_body (message->header.kind, &(message->body), length, buffer, offset);
348 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
#define encode_step(dst, offset, src)
static void encode_message_body(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, char *buffer, uint16_t offset)
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_IDENTITY_Signature signature
The signature of the senders private key.
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
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 351 of file messenger_api_message.c.

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

Referenced by encrypt_message().

352 {
353  uint16_t offset = 0;
354 
355  encode_step(buffer, offset, &(message->kind));
356 
357  encode_message_body (message->kind, &(message->body), length, buffer, offset);
358 }
enum GNUNET_MESSENGER_MessageKind kind
#define encode_step(dst, offset, src)
static void encode_message_body(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, char *buffer, uint16_t offset)
struct GNUNET_MESSENGER_MessageBody body
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_message_body()

static void 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 376 of file messenger_api_message.c.

References GNUNET_MESSENGER_MessagePrivate::data, decode_step, decode_step_ext, decode_step_malloc, GNUNET_MESSENGER_MessageInvite::door, GNUNET_MESSENGER_MessageBody::file, 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_TEXT, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageFile::hash, GNUNET_MESSENGER_MessageInfo::host_key, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageFile::key, GNUNET_MESSENGER_MessagePrivate::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageFile::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageBody::private, GNUNET_MESSENGER_MessageBody::request, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageInfo::unique_id, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by decode_message(), and decode_short_message().

378 {
379  switch (*kind)
380  {
382  decode_step(buffer, offset, &(body->info.host_key));
383  decode_step(buffer, offset, &(body->info.unique_id));
384  break;
386  decode_step(buffer, offset, &(body->join.key));
387  break;
389  break;
391  if (length - offset > 0)
392  decode_step_malloc(buffer, offset, body->name.name, length - offset, 1);
393  else
394  body->name.name = NULL;
395  break;
397  decode_step(buffer, offset, &(body->key.key));
398  break;
400  decode_step(buffer, offset, &(body->peer.peer));
401  break;
403  decode_step(buffer, offset, &(body->id.id));
404  break;
406  decode_step(buffer, offset, &(body->miss.peer));
407  break;
409  decode_step(buffer, offset, &(body->merge.previous));
410  break;
412  decode_step(buffer, offset, &(body->request.hash));
413  break;
415  decode_step(buffer, offset, &(body->invite.door));
416  decode_step(buffer, offset, &(body->invite.key));
417  break;
419  decode_step_malloc(buffer, offset, body->text.text, length - offset, 1);
420  break;
422  decode_step(buffer, offset, &(body->file.key));
423  decode_step(buffer, offset, &(body->file.hash));
424  decode_step_ext(buffer, offset, body->file.name, NAME_MAX);
425  decode_step_malloc(buffer, offset, body->file.uri, length - offset, 1);
426  break;
428  decode_step(buffer, offset, &(body->private.key));
429 
430  body->private.length = (length - offset);
431  decode_step_malloc(buffer, offset, body->private.data, length - offset, 0);
432  break;
433  default:
435  break;
436  }
437 }
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
struct GNUNET_ShortHashCode unique_id
The new unique id for the receiver in a room.
char * uri
The uri of the encrypted file.
struct GNUNET_IDENTITY_PublicKey host_key
The senders key to verify its signatures.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
struct GNUNET_MESSENGER_MessageText text
struct GNUNET_HashCode hash
The hash of the requested message.
struct GNUNET_MESSENGER_MessageKey key
char name[NAME_MAX]
The name of the original file.
char * text
The containing text.
struct GNUNET_MESSENGER_MessageRequest request
#define decode_step(src, offset, dst)
struct GNUNET_IDENTITY_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_MESSENGER_MessageInvite invite
struct GNUNET_IDENTITY_PublicKey key
The new public key which replaces the current senders public key.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_CRYPTO_SymmetricSessionKey key
The symmetric key to decrypt the file.
uint16_t length
The length of the encrypted message.
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_HashCode hash
The hash of the original file.
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageInfo info
struct GNUNET_CRYPTO_EcdhePublicKey key
The ECDH key to decrypt the message.
struct GNUNET_MESSENGER_MessagePeer peer
char * data
The data of the encrypted message.
#define decode_step_ext(src, offset, dst, size)
struct GNUNET_MESSENGER_MessagePrivate private
char * name
The new name which replaces the current senders name.
struct GNUNET_HashCode key
The hash identifying the port of the room.
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_MESSENGER_MessageFile file
struct GNUNET_MESSENGER_MessageId id
#define decode_step_malloc(src, offset, dst, size, zero)
Here is the caller graph for this function:

◆ decode_message()

int decode_message ( struct GNUNET_MESSENGER_Message message,
uint16_t  length,
const char *  buffer 
)

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
lengthMaximal length to decode
bufferBuffer
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 440 of file messenger_api_message.c.

References GNUNET_MESSENGER_Message::body, decode_message_body(), decode_step, get_message_kind_size(), GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_NO, 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 check_recv_message(), check_send_message(), check_tunnel_message(), get_store_message(), handle_recv_message(), handle_send_message(), and handle_tunnel_message().

441 {
442  uint16_t offset = 0;
443 
445  return GNUNET_NO;
446 
447  decode_step(buffer, offset, &(message->header.signature));
448  decode_step(buffer, offset, &(message->header.timestamp));
449  decode_step(buffer, offset, &(message->header.sender_id));
450  decode_step(buffer, offset, &(message->header.previous));
451  decode_step(buffer, offset, &(message->header.kind));
452 
453  if (length < get_message_kind_size (message->header.kind))
454  return GNUNET_NO;
455 
456  decode_message_body (&(message->header.kind), &(message->body), length, buffer, offset);
457 
458  return GNUNET_YES;
459 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
static void decode_message_body(enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, const char *buffer, uint16_t offset)
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
#define decode_step(src, offset, dst)
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind)
Returns the minimal size in bytes to encode a message of a specific kind.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_IDENTITY_Signature signature
The signature of the senders private key.
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_short_message()

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

Definition at line 462 of file messenger_api_message.c.

References GNUNET_MESSENGER_ShortMessage::body, decode_message_body(), decode_step, get_short_message_size(), GNUNET_NO, GNUNET_YES, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by decrypt_message().

463 {
464  uint16_t offset = 0;
465 
466  if (length < get_short_message_size (NULL))
467  return GNUNET_NO;
468 
469  decode_step(buffer, offset, &(message->kind));
470 
471  if (length < get_short_message_size (message))
472  return GNUNET_NO;
473 
474  decode_message_body (&(message->kind), &(message->body), length, buffer, offset);
475 
476  return GNUNET_YES;
477 }
static void decode_message_body(enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, const char *buffer, uint16_t offset)
enum GNUNET_MESSENGER_MessageKind kind
static uint16_t get_short_message_size(const struct GNUNET_MESSENGER_ShortMessage *message)
#define decode_step(src, offset, dst)
struct GNUNET_MESSENGER_MessageBody body
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hash_message()

void hash_message ( uint16_t  length,
const char *  buffer,
struct GNUNET_HashCode hash 
)

Calculates a hash of a given buffer of a length in bytes.

Parameters
lengthLength of buffer
bufferBuffer
[out]hashHash

Definition at line 480 of file messenger_api_message.c.

References GNUNET_CRYPTO_hash().

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

481 {
482  GNUNET_CRYPTO_hash (buffer + sizeof(struct GNUNET_CRYPTO_EcdsaSignature),
483  length - sizeof(struct GNUNET_CRYPTO_EcdsaSignature), hash);
484 }
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
an ECC signature using ECDSA
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_MESSENGER_Ego ego 
)

Signs the hash of a message with a given ego and writes the signature into the buffer as well.

Parameters
[out]messageMessage
lengthLength of buffer
[out]bufferBuffer
hashHash of message
egoEGO

Definition at line 487 of file messenger_api_message.c.

References GNUNET_IDENTITY_sign, GNUNET_memcpy, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_Ego::priv, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by pack_message().

489 {
490  struct GNUNET_MESSENGER_MessageSignature signature;
491 
493  signature.purpose.size = htonl (sizeof(signature));
494 
495  GNUNET_memcpy(&(signature.hash), hash, sizeof(struct GNUNET_HashCode));
496 
497  GNUNET_IDENTITY_sign(&(ego->priv), &signature, &(message->header.signature));
498  GNUNET_memcpy(buffer, &(message->header.signature), sizeof(struct GNUNET_CRYPTO_EcdsaSignature));
499 }
#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE
Signature of a chat message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_IDENTITY_sign(priv, ps, sig)
Sign a given block with GNUNET_IDENTITY_PrivateKey.
an ECC signature using ECDSA
struct GNUNET_IDENTITY_Signature signature
The signature of the senders private key.
A 512-bit hashcode.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
struct GNUNET_IDENTITY_PrivateKey priv
Here is the caller graph for this function:

◆ verify_message()

int verify_message ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash,
const struct GNUNET_IDENTITY_PublicKey key 
)

Verifies the signature of a given message and its hash with a specific public key.

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

Parameters
messageMessage
hashHash of message
keyPublic key of EGO
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 502 of file messenger_api_message.c.

References GNUNET_IDENTITY_signature_verify, GNUNET_memcpy, 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, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by callback_verify_room_message().

504 {
505  struct GNUNET_MESSENGER_MessageSignature signature;
506 
508  signature.purpose.size = htonl (sizeof(signature));
509 
510  GNUNET_memcpy(&(signature.hash), hash, sizeof(struct GNUNET_HashCode));
511 
513  &(message->header.signature), key);
514 }
#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE
Signature of a chat message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_IDENTITY_signature_verify(purp, ps, sig, pub)
Verify a given signature with GNUNET_IDENTITY_PublicKey.
struct GNUNET_IDENTITY_Signature signature
The signature of the senders private key.
A 512-bit hashcode.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Here is the caller graph for this function:

◆ encrypt_message()

int encrypt_message ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_IDENTITY_PublicKey key 
)

Encrypts a message using a given public key and replaces its body and kind with the now private encrypted message.

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

Parameters
messageMessage
keyPublic key of EGO
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 517 of file messenger_api_message.c.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_ShortMessage::body, GNUNET_MESSENGER_MessagePrivate::data, destroy_message_body(), encode_short_message(), fold_short_message(), get_short_message_size(), GNUNET_IDENTITY_encrypt(), GNUNET_malloc, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessagePrivate::key, GNUNET_MESSENGER_ShortMessage::kind, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageBody::private, and unfold_short_message().

518 {
519  struct GNUNET_MESSENGER_ShortMessage shortened;
520 
521  fold_short_message (message, &shortened);
522 
523  const uint16_t length = get_short_message_size (&shortened);
524 
526  message->body.private.data = GNUNET_malloc(length);
527 
528  encode_short_message (&shortened, length, message->body.private.data);
529 
530  if (GNUNET_IDENTITY_encrypt (message->body.private.data, length, key, &(message->body.private.key),
531  message->body.private.data)
532  == length)
533  {
534  destroy_message_body (shortened.kind, &(shortened.body));
535  return GNUNET_YES;
536  }
537  else
538  {
539  unfold_short_message (&shortened, message);
540  return GNUNET_NO;
541  }
542 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
ssize_t GNUNET_IDENTITY_encrypt(const void *block, size_t size, const struct GNUNET_IDENTITY_PublicKey *pub, struct GNUNET_CRYPTO_EcdhePublicKey *ecc, void *result)
Encrypt a block with GNUNET_IDENTITY_PublicKey and derives a GNUNET_CRYPTO_EcdhePublicKey which is re...
static uint16_t get_short_message_size(const struct GNUNET_MESSENGER_ShortMessage *message)
static void unfold_short_message(struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message)
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_CRYPTO_EcdhePublicKey key
The ECDH key to decrypt the message.
char * data
The data of the encrypted message.
static void fold_short_message(const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_ShortMessage *shortened)
static void encode_short_message(const struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, char *buffer)
struct GNUNET_MESSENGER_MessagePrivate private
static void destroy_message_body(enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)
#define GNUNET_malloc(size)
Wrapper around malloc.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:

◆ decrypt_message()

int decrypt_message ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_IDENTITY_PrivateKey key 
)

Decrypts a private message using a given private key and replaces its body and kind with the inner encrypted message.

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

Parameters
messageMessage
keyPrivate key of EGO
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 545 of file messenger_api_message.c.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, decode_short_message(), GNUNET_IDENTITY_decrypt(), GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_MessagePrivate::key, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageBody::private, and unfold_short_message().

546 {
547  if (message->body.private.length != GNUNET_IDENTITY_decrypt (message->body.private.data,
548  message->body.private.length, key,
549  &(message->body.private.key),
550  message->body.private.data))
551  return GNUNET_NO;
552 
553  struct GNUNET_MESSENGER_ShortMessage shortened;
554 
555  if (GNUNET_YES != decode_short_message (&shortened, message->body.private.length, message->body.private.data))
556  return GNUNET_NO;
557 
558  unfold_short_message (&shortened, message);
559  return GNUNET_YES;
560 }
static void unfold_short_message(struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message)
ssize_t GNUNET_IDENTITY_decrypt(const void *block, size_t size, const struct GNUNET_IDENTITY_PrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *ecc, void *result)
Decrypt a given block with GNUNET_IDENTITY_PrivateKey and a given GNUNET_CRYPTO_EcdhePublicKey using ...
struct GNUNET_MESSENGER_MessageBody body
Body.
uint16_t length
The length of the encrypted message.
static int decode_short_message(struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer)
struct GNUNET_CRYPTO_EcdhePublicKey key
The ECDH key to decrypt the message.
char * data
The data of the encrypted message.
struct GNUNET_MESSENGER_MessagePrivate private
Here is the call graph for this function:

◆ pack_message()

struct GNUNET_MQ_Envelope* pack_message ( struct GNUNET_MESSENGER_Message message,
struct GNUNET_HashCode hash,
const struct GNUNET_MESSENGER_Ego ego,
int  mode 
)

Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_PACK_MODE_ENVELOPE.

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

Parameters
[out]messageMessage
[out]hashHash of message
egoEGO to sign
modeMode of packing
Returns
Envelope or NULL

Definition at line 563 of file messenger_api_message.c.

References encode_message(), env, get_message_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_MESSAGE_TYPE_CADET_CLI, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, GNUNET_MQ_msg_extra, hash_message(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, and sign_message().

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

565 {
566  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Packing message: %u\n", message->header.kind);
567 
568  struct GNUNET_MessageHeader *header;
569 
570  uint16_t length = get_message_size (message);
571 
572  struct GNUNET_MQ_Envelope *env;
573  char *buffer;
574 
576  {
577  env = GNUNET_MQ_msg_extra(header, length, GNUNET_MESSAGE_TYPE_CADET_CLI);
578 
579  buffer = (char*) &(header[1]);
580  }
581  else
582  {
583  env = NULL;
584 
585  buffer = GNUNET_malloc(length);
586  }
587 
588  encode_message (message, length, buffer);
589 
590  if (hash)
591  {
592  hash_message (length, buffer, hash);
593 
594  if (ego)
595  sign_message (message, length, buffer, hash, ego);
596  }
597 
599  GNUNET_free(buffer);
600 
601  return env;
602 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
void hash_message(uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer of a length in bytes.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message)
Returns the exact size in bytes to encode a given message.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer)
Encodes a given message into a buffer of a maximal length in bytes.
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
static enum @8 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
#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:52
#define GNUNET_MESSENGER_PACK_MODE_ENVELOPE
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_log(kind,...)
Header for all communications.
void sign_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego)
Signs the hash of a message with a given ego and writes the signature into the buffer as well...
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:
Here is the caller graph for this function: