GNUnet  0.11.x
Functions
gnunet-service-messenger_message_kind.c File Reference

GNUnet MESSENGER service. More...

#include "gnunet-service-messenger_message_kind.h"
#include "gnunet-service-messenger_util.h"
Include dependency graph for gnunet-service-messenger_message_kind.c:

Go to the source code of this file.

Functions

struct GNUNET_MESSENGER_Messagecreate_message_info (struct GNUNET_MESSENGER_Ego *ego, struct GNUNET_CONTAINER_MultiShortmap *members)
 Creates and allocates a new info message containing the hosts public key and a newly generated unique member id. More...
 
struct GNUNET_MESSENGER_Messagecreate_message_join (struct GNUNET_MESSENGER_Ego *ego)
 Creates and allocates a new join message containing the clients public key. More...
 
struct GNUNET_MESSENGER_Messagecreate_message_leave ()
 Creates and allocates a new leave message. More...
 
struct GNUNET_MESSENGER_Messagecreate_message_name (const char *name)
 Creates and allocates a new name message containing the name to change to. More...
 
struct GNUNET_MESSENGER_Messagecreate_message_key (const struct GNUNET_IDENTITY_PrivateKey *key)
 Creates and allocates a new key message containing the public key to change to derived from its private counterpart. More...
 
struct GNUNET_MESSENGER_Messagecreate_message_peer (const struct GNUNET_MESSENGER_Service *service)
 Creates and allocates a new peer message containing a services peer identity. More...
 
struct GNUNET_MESSENGER_Messagecreate_message_id (const struct GNUNET_ShortHashCode *unique_id)
 Creates and allocates a new id message containing the unique member id to change to. More...
 
struct GNUNET_MESSENGER_Messagecreate_message_miss (const struct GNUNET_PeerIdentity *peer)
 Creates and allocates a new miss message containing the missing peer identity. More...
 
struct GNUNET_MESSENGER_Messagecreate_message_merge (const struct GNUNET_HashCode *previous)
 Creates and allocates a new merge message containing the hash of a second previous message besides the regular previous message mentioned in a messages header. More...
 
struct GNUNET_MESSENGER_Messagecreate_message_request (const struct GNUNET_HashCode *hash)
 Creates and allocates a new request message containing the hash of a missing message. More...
 
struct GNUNET_MESSENGER_Messagecreate_message_invite (const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
 Creates and allocates a new invite message containing the peer identity of an entrance peer to a room using a given key as shared secret for communication. More...
 
struct GNUNET_MESSENGER_Messagecreate_message_text (const char *text)
 Creates and allocates a new text message containing a string representing text. More...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_message_kind.c.

Function Documentation

◆ create_message_info()

struct GNUNET_MESSENGER_Message* create_message_info ( struct GNUNET_MESSENGER_Ego ego,
struct GNUNET_CONTAINER_MultiShortmap members 
)

Creates and allocates a new info message containing the hosts public key and a newly generated unique member id.

(all values are stored as copy)

Parameters
egoEGO of the host
membersMap of all assigned member ids
Returns
New message

Definition at line 30 of file gnunet-service-messenger_message_kind.c.

References GNUNET_MESSENGER_Message::body, create_message(), destroy_message(), generate_free_member_id(), GNUNET_memcpy, GNUNET_MESSENGER_KIND_INFO, GNUNET_YES, GNUNET_MESSENGER_MessageInfo::host_key, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_Ego::pub, and GNUNET_MESSENGER_MessageInfo::unique_id.

Referenced by send_room_info().

31 {
33 
34  if (!message)
35  return NULL;
36 
37  GNUNET_memcpy(&(message->body.info.host_key), &(ego->pub), sizeof(ego->pub));
38 
39  if (GNUNET_YES == generate_free_member_id (&(message->body.info.unique_id), members))
40  return message;
41  else
42  {
43  destroy_message (message);
44  return NULL;
45  }
46 }
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
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.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_IDENTITY_PublicKey pub
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageInfo info
int generate_free_member_id(struct GNUNET_ShortHashCode *id, const struct GNUNET_CONTAINER_MultiShortmap *members)
Tries to generate an unused member id and store it into the id parameter.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_message_join()

struct GNUNET_MESSENGER_Message* create_message_join ( struct GNUNET_MESSENGER_Ego ego)

Creates and allocates a new join message containing the clients public key.

(all values are stored as copy)

Parameters
egoEGO of the client
Returns
New message

Definition at line 49 of file gnunet-service-messenger_message_kind.c.

References GNUNET_MESSENGER_Message::body, create_message(), GNUNET_memcpy, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, and GNUNET_MESSENGER_Ego::pub.

Referenced by join_room(), and recv_message_info().

50 {
52 
53  if (!message)
54  return NULL;
55 
56  GNUNET_memcpy(&(message->body.join.key), &(ego->pub), sizeof(ego->pub));
57 
58  return message;
59 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_IDENTITY_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_IDENTITY_PublicKey pub
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageJoin join
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_message_leave()

struct GNUNET_MESSENGER_Message* create_message_leave ( )

Creates and allocates a new leave message.

Returns
New message

Definition at line 62 of file gnunet-service-messenger_message_kind.c.

References create_message(), and GNUNET_MESSENGER_KIND_LEAVE.

Referenced by close_service_room().

63 {
65 }
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_message_name()

struct GNUNET_MESSENGER_Message* create_message_name ( const char *  name)

Creates and allocates a new name message containing the name to change to.

(all values are stored as copy)

Parameters
nameNew name
Returns
New message

Definition at line 68 of file gnunet-service-messenger_message_kind.c.

References GNUNET_MESSENGER_Message::body, create_message(), GNUNET_MESSENGER_KIND_NAME, GNUNET_strdup, GNUNET_MESSENGER_MessageName::name, and GNUNET_MESSENGER_MessageBody::name.

Referenced by set_handle_name().

69 {
71 
72  if (!message)
73  return NULL;
74 
75  message->body.name.name = GNUNET_strdup(name);
76  return message;
77 }
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageName name
const char * name
char * name
The new name which replaces the current senders name.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_message_key()

struct GNUNET_MESSENGER_Message* create_message_key ( const struct GNUNET_IDENTITY_PrivateKey key)

Creates and allocates a new key message containing the public key to change to derived from its private counterpart.

(all values are stored as copy)

Parameters
keyPrivate key of EGO
Returns
New message

Definition at line 80 of file gnunet-service-messenger_message_kind.c.

References GNUNET_MESSENGER_Message::body, create_message(), GNUNET_IDENTITY_key_get_public(), GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_MessageKey::key, and GNUNET_MESSENGER_MessageBody::key.

Referenced by callback_ego_create().

81 {
83 
84  if (!message)
85  return NULL;
86 
87  GNUNET_IDENTITY_key_get_public (key, &(message->body.key.key));
88  return message;
89 }
struct GNUNET_MESSENGER_MessageKey key
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_IDENTITY_PublicKey key
The new public key which replaces the current senders public key.
struct GNUNET_MESSENGER_MessageBody body
Body.
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_key_get_public(const struct GNUNET_IDENTITY_PrivateKey *privkey, struct GNUNET_IDENTITY_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: identity_api.c:175
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_message_peer()

struct GNUNET_MESSENGER_Message* create_message_peer ( const struct GNUNET_MESSENGER_Service service)

Creates and allocates a new peer message containing a services peer identity.

(all values are stored as copy)

Parameters
serviceService
Returns
New message

Definition at line 92 of file gnunet-service-messenger_message_kind.c.

References GNUNET_MESSENGER_Message::body, create_message(), destroy_message(), get_service_peer_identity(), GNUNET_MESSENGER_KIND_PEER, GNUNET_OK, GNUNET_MESSENGER_MessagePeer::peer, and GNUNET_MESSENGER_MessageBody::peer.

Referenced by open_room().

93 {
95 
96  if (!message)
97  return NULL;
98 
99  if (GNUNET_OK == get_service_peer_identity (service, &(message->body.peer.peer)))
100  return message;
101  else
102  {
103  destroy_message (message);
104  return NULL;
105  }
106 }
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
int get_service_peer_identity(const struct GNUNET_MESSENGER_Service *service, struct GNUNET_PeerIdentity *peer)
Tries to write the peer identity of the peer running a service on to the peer parameter.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessagePeer peer
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_message_id()

struct GNUNET_MESSENGER_Message* create_message_id ( const struct GNUNET_ShortHashCode unique_id)

Creates and allocates a new id message containing the unique member id to change to.

(all values are stored as copy)

Parameters
unique_idUnique member id
Returns
New message

Definition at line 109 of file gnunet-service-messenger_message_kind.c.

References GNUNET_MESSENGER_Message::body, create_message(), GNUNET_memcpy, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_MessageId::id, and GNUNET_MESSENGER_MessageBody::id.

Referenced by recv_message_info().

110 {
112 
113  if (!message)
114  return NULL;
115 
116  GNUNET_memcpy(&(message->body.id.id), unique_id, sizeof(struct GNUNET_ShortHashCode));
117 
118  return message;
119 }
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
A 256-bit hashcode.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageId id
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_message_miss()

struct GNUNET_MESSENGER_Message* create_message_miss ( const struct GNUNET_PeerIdentity peer)

Creates and allocates a new miss message containing the missing peer identity.

(all values are stored as copy)

Parameters
peerMissing peer identity
Returns
New message

Definition at line 122 of file gnunet-service-messenger_message_kind.c.

References GNUNET_MESSENGER_Message::body, create_message(), GNUNET_memcpy, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_MessageBody::miss, and GNUNET_MESSENGER_MessageMiss::peer.

Referenced by callback_room_disconnect().

123 {
125 
126  if (!message)
127  {
128  return NULL;
129  }
130 
131  GNUNET_memcpy(&(message->body.miss.peer), peer, sizeof(struct GNUNET_PeerIdentity));
132 
133  return message;
134 }
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_MESSENGER_MessageBody body
Body.
The identity of the host (wraps the signing key of the peer).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_message_merge()

struct GNUNET_MESSENGER_Message* create_message_merge ( const struct GNUNET_HashCode previous)

Creates and allocates a new merge message containing the hash of a second previous message besides the regular previous message mentioned in a messages header.

(all values are stored as copy)

Parameters
previousHash of message
Returns
New message

Definition at line 137 of file gnunet-service-messenger_message_kind.c.

References GNUNET_MESSENGER_Message::body, create_message(), GNUNET_memcpy, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_MessageBody::merge, and GNUNET_MESSENGER_MessageMerge::previous.

Referenced by merge_room_last_messages().

138 {
140 
141  if (!message)
142  return NULL;
143 
144  GNUNET_memcpy(&(message->body.merge.previous), previous, sizeof(struct GNUNET_HashCode));
145 
146  return message;
147 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageMerge merge
A 512-bit hashcode.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_message_request()

struct GNUNET_MESSENGER_Message* create_message_request ( const struct GNUNET_HashCode hash)

Creates and allocates a new request message containing the hash of a missing message.

(all values are stored as copy)

Parameters
hashHash of message
Returns
New message

Definition at line 150 of file gnunet-service-messenger_message_kind.c.

References GNUNET_MESSENGER_Message::body, create_message(), GNUNET_CRYPTO_hash_cmp(), GNUNET_memcpy, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_MessageRequest::hash, and GNUNET_MESSENGER_MessageBody::request.

Referenced by get_room_message().

151 {
152  struct GNUNET_HashCode zero;
153  memset (&zero, 0, sizeof(zero));
154 
155  if (0 == GNUNET_CRYPTO_hash_cmp (hash, &zero))
156  return NULL;
157 
159 
160  if (!message)
161  return NULL;
162 
163  GNUNET_memcpy(&(message->body.request.hash), hash, sizeof(struct GNUNET_HashCode));
164 
165  return message;
166 }
struct GNUNET_HashCode hash
The hash of the requested message.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_MESSENGER_MessageBody body
Body.
A 512-bit hashcode.
static const struct GNUNET_IDENTITY_PrivateKey zero
Public key of all zeros.
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:311
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_message_invite()

struct GNUNET_MESSENGER_Message* create_message_invite ( const struct GNUNET_PeerIdentity door,
const struct GNUNET_HashCode key 
)

Creates and allocates a new invite message containing the peer identity of an entrance peer to a room using a given key as shared secret for communication.

(all values are stored as copy)

Parameters
doorPeer identity
keyShared secret of a room
Returns
New message

Definition at line 169 of file gnunet-service-messenger_message_kind.c.

References GNUNET_MESSENGER_Message::body, create_message(), GNUNET_MESSENGER_MessageInvite::door, GNUNET_memcpy, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_MessageBody::invite, and GNUNET_MESSENGER_MessageInvite::key.

170 {
172 
173  if (!message)
174  return NULL;
175 
176  GNUNET_memcpy(&(message->body.invite.door), door, sizeof(struct GNUNET_PeerIdentity));
177  GNUNET_memcpy(&(message->body.invite.key), key, sizeof(struct GNUNET_HashCode));
178 
179  return message;
180 }
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_MESSENGER_MessageInvite invite
struct GNUNET_MESSENGER_MessageBody body
Body.
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_HashCode key
The hash identifying the port of the room.
Here is the call graph for this function:

◆ create_message_text()

struct GNUNET_MESSENGER_Message* create_message_text ( const char *  text)

Creates and allocates a new text message containing a string representing text.

(all values are stored as copy)

Parameters
textText
Returns
New message

Definition at line 183 of file gnunet-service-messenger_message_kind.c.

References GNUNET_MESSENGER_Message::body, create_message(), GNUNET_MESSENGER_KIND_TEXT, GNUNET_strdup, GNUNET_MESSENGER_MessageText::text, and GNUNET_MESSENGER_MessageBody::text.

184 {
186 
187  if (!message)
188  return NULL;
189 
190  message->body.text.text = GNUNET_strdup(text);
191  return message;
192 }
struct GNUNET_MESSENGER_MessageText text
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
char * text
The containing text.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_MESSENGER_MessageBody body
Body.
Here is the call graph for this function: