GNUnet  0.11.x
Data Structures | Functions | Variables
gnunet-service-messenger.c File Reference

GNUnet MESSENGER service. More...

#include "gnunet-service-messenger.h"
#include "gnunet-service-messenger_service.h"
#include "messenger_api_message.h"
Include dependency graph for gnunet-service-messenger.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_Client
 

Functions

static int check_create (void *cls, const struct GNUNET_MESSENGER_CreateMessage *msg)
 
static void handle_create (void *cls, const struct GNUNET_MESSENGER_CreateMessage *msg)
 
static void handle_update (void *cls, const struct GNUNET_MESSENGER_UpdateMessage *msg)
 
static void handle_destroy (void *cls, const struct GNUNET_MESSENGER_DestroyMessage *msg)
 
static int check_set_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg)
 
static void handle_set_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg)
 
static void handle_room_open (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
 
static void handle_room_entry (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
 
static void handle_room_close (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
 
static int check_send_message (void *cls, const struct GNUNET_MESSENGER_SendMessage *msg)
 
static void handle_send_message (void *cls, const struct GNUNET_MESSENGER_SendMessage *msg)
 
static void handle_get_message (void *cls, const struct GNUNET_MESSENGER_GetMessage *msg)
 
static void * callback_client_connect (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
 
static void callback_client_disconnect (void *cls, struct GNUNET_SERVICE_Client *client, void *internal_cls)
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_SERVICE_Handle *service)
 Setup MESSENGER internals. More...
 
 GNUNET_SERVICE_MAIN (GNUNET_MESSENGER_SERVICE_NAME, GNUNET_SERVICE_OPTION_NONE, &run, &callback_client_connect, &callback_client_disconnect, NULL, GNUNET_MQ_hd_var_size(create, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE, struct GNUNET_MESSENGER_CreateMessage, NULL), GNUNET_MQ_hd_fixed_size(update, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE, struct GNUNET_MESSENGER_UpdateMessage, NULL), GNUNET_MQ_hd_fixed_size(destroy, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY, struct GNUNET_MESSENGER_DestroyMessage, NULL), GNUNET_MQ_hd_var_size(set_name, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME, struct GNUNET_MESSENGER_NameMessage, NULL), GNUNET_MQ_hd_fixed_size(room_open, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, struct GNUNET_MESSENGER_RoomMessage, NULL), GNUNET_MQ_hd_fixed_size(room_entry, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, struct GNUNET_MESSENGER_RoomMessage, NULL), GNUNET_MQ_hd_fixed_size(room_close, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, struct GNUNET_MESSENGER_RoomMessage, NULL), GNUNET_MQ_hd_var_size(send_message, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE, struct GNUNET_MESSENGER_SendMessage, NULL), GNUNET_MQ_hd_fixed_size(get_message, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE, struct GNUNET_MESSENGER_GetMessage, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro. More...
 

Variables

struct GNUNET_MESSENGER_Servicemessenger
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger.c.

Function Documentation

◆ check_create()

static int check_create ( void *  cls,
const struct GNUNET_MESSENGER_CreateMessage msg 
)
static

Definition at line 40 of file gnunet-service-messenger.c.

References GNUNET_MQ_check_zero_termination, and GNUNET_OK.

41 {
43  return GNUNET_OK;
44 }
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...

◆ handle_create()

static void handle_create ( void *  cls,
const struct GNUNET_MESSENGER_CreateMessage msg 
)
static

Definition at line 47 of file gnunet-service-messenger.c.

References GNUNET_MESSENGER_Client::client, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SERVICE_client_continue(), GNUNET_MESSENGER_Client::handle, name, and setup_handle_name().

48 {
49  struct GNUNET_MESSENGER_Client *msg_client = cls;
50 
51  const char *name = ((const char*) msg) + sizeof(*msg);
52 
53  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Handle created with name: %s\n", name);
54 
55  setup_handle_name (msg_client->handle, strlen (name) > 0 ? name : NULL);
56 
58 }
void setup_handle_name(struct GNUNET_MESSENGER_SrvHandle *handle, const char *name)
Tries to set the name and EGO key of a handle initially by looking up a specific name.
struct GNUNET_SERVICE_Client * client
const char * name
#define GNUNET_log(kind,...)
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
struct GNUNET_MESSENGER_SrvHandle * handle
Here is the call graph for this function:

◆ handle_update()

static void handle_update ( void *  cls,
const struct GNUNET_MESSENGER_UpdateMessage msg 
)
static

Definition at line 61 of file gnunet-service-messenger.c.

References GNUNET_MESSENGER_Client::client, GNUNET_SERVICE_client_continue(), GNUNET_MESSENGER_Client::handle, and update_handle().

62 {
63  struct GNUNET_MESSENGER_Client *msg_client = cls;
64 
65  update_handle (msg_client->handle);
66 
68 }
struct GNUNET_SERVICE_Client * client
void update_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Tries to change the keypair of an EGO of a handle under the same name and informs all rooms about the...
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
struct GNUNET_MESSENGER_SrvHandle * handle
Here is the call graph for this function:

◆ handle_destroy()

static void handle_destroy ( void *  cls,
const struct GNUNET_MESSENGER_DestroyMessage msg 
)
static

Definition at line 71 of file gnunet-service-messenger.c.

References GNUNET_MESSENGER_Client::client, and GNUNET_SERVICE_client_drop().

72 {
73  struct GNUNET_MESSENGER_Client *msg_client = cls;
74 
75  GNUNET_SERVICE_client_drop (msg_client->client);
76 }
struct GNUNET_SERVICE_Client * client
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2325
Here is the call graph for this function:

◆ check_set_name()

static int check_set_name ( void *  cls,
const struct GNUNET_MESSENGER_NameMessage msg 
)
static

Definition at line 79 of file gnunet-service-messenger.c.

References GNUNET_MQ_check_zero_termination, and GNUNET_OK.

80 {
82  return GNUNET_OK;
83 }
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...

◆ handle_set_name()

static void handle_set_name ( void *  cls,
const struct GNUNET_MESSENGER_NameMessage msg 
)
static

Definition at line 86 of file gnunet-service-messenger.c.

References GNUNET_MESSENGER_Client::client, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SERVICE_client_continue(), GNUNET_MESSENGER_Client::handle, name, and set_handle_name().

87 {
88  struct GNUNET_MESSENGER_Client *msg_client = cls;
89 
90  const char *name = ((const char*) msg) + sizeof(*msg);
91 
92  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Handles name is now: %s\n", name);
93 
94  set_handle_name (msg_client->handle, name);
95 
97 }
struct GNUNET_SERVICE_Client * client
const char * name
void set_handle_name(struct GNUNET_MESSENGER_SrvHandle *handle, const char *name)
Tries to rename the handle which implies renaming the EGO its using and moving all related data into ...
#define GNUNET_log(kind,...)
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
struct GNUNET_MESSENGER_SrvHandle * handle
Here is the call graph for this function:

◆ handle_room_open()

static void handle_room_open ( void *  cls,
const struct GNUNET_MESSENGER_RoomMessage msg 
)
static

Definition at line 100 of file gnunet-service-messenger.c.

References GNUNET_MESSENGER_Client::client, env, get_handle_member_id(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_SERVICE_client_continue(), GNUNET_sh2s(), GNUNET_YES, GNUNET_MESSENGER_Client::handle, GNUNET_MESSENGER_RoomMessage::key, GNUNET_MESSENGER_SrvHandle::mq, open_handle_room(), and response.

101 {
102  struct GNUNET_MESSENGER_Client *msg_client = cls;
103 
104  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opening room: %s\n", GNUNET_h2s (&(msg->key)));
105 
106  if (GNUNET_YES == open_handle_room (msg_client->handle, &(msg->key)))
107  {
108  const struct GNUNET_ShortHashCode *member_id = get_handle_member_id (msg_client->handle, &(msg->key));
109 
110  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opening room with member id: %s\n", GNUNET_sh2s (member_id));
111 
113  struct GNUNET_MQ_Envelope *env;
114 
116  GNUNET_memcpy(&(response->key), &(msg->key), sizeof(msg->key));
117  GNUNET_MQ_send (msg_client->handle->mq, env);
118  }
119  else
120  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Opening room failed: %s\n", GNUNET_h2s (&(msg->key)));
121 
123 }
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
struct GNUNET_SERVICE_Client * client
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
A 256-bit hashcode.
int open_handle_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Makes a given handle a member of the room using a specific key and opens the room from the handles se...
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN
#define GNUNET_log(kind,...)
static struct MHD_Response * response
Our canonical response.
const struct GNUNET_ShortHashCode * get_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns the member id of a given handle in a specific room.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
General message to confirm interaction with a room.
struct GNUNET_MESSENGER_SrvHandle * handle
Here is the call graph for this function:

◆ handle_room_entry()

static void handle_room_entry ( void *  cls,
const struct GNUNET_MESSENGER_RoomMessage msg 
)
static

Definition at line 126 of file gnunet-service-messenger.c.

References GNUNET_MESSENGER_Client::client, GNUNET_MESSENGER_RoomMessage::door, entry_handle_room(), env, get_handle_member_id(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_SERVICE_client_continue(), GNUNET_sh2s(), GNUNET_YES, GNUNET_MESSENGER_Client::handle, GNUNET_MESSENGER_RoomMessage::key, GNUNET_MESSENGER_SrvHandle::mq, and response.

127 {
128  struct GNUNET_MESSENGER_Client *msg_client = cls;
129 
130  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Entering room: %s, %s\n", GNUNET_h2s (&(msg->key)), GNUNET_i2s (&(msg->door)));
131 
132  if (GNUNET_YES == entry_handle_room (msg_client->handle, &(msg->door), &(msg->key)))
133  {
134  const struct GNUNET_ShortHashCode *member_id = get_handle_member_id (msg_client->handle, &(msg->key));
135 
136  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Entering room with member id: %s\n", GNUNET_sh2s (member_id));
137 
139  struct GNUNET_MQ_Envelope *env;
140 
142  GNUNET_memcpy(&(response->door), &(msg->door), sizeof(msg->door));
143  GNUNET_memcpy(&(response->key), &(msg->key), sizeof(msg->key));
144  GNUNET_MQ_send (msg_client->handle->mq, env);
145  }
146  else
147  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Entrance into room failed: %s, %s\n", GNUNET_h2s (&(msg->key)),
148  GNUNET_i2s (&(msg->door)));
149 
151 }
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
struct GNUNET_SERVICE_Client * client
struct GNUNET_PeerIdentity door
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
A 256-bit hashcode.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_log(kind,...)
static struct MHD_Response * response
Our canonical response.
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY
const struct GNUNET_ShortHashCode * get_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns the member id of a given handle in a specific room.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
int entry_handle_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Makes a given handle a member of the room using a specific key and enters the room through a tunnel t...
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
General message to confirm interaction with a room.
struct GNUNET_MESSENGER_SrvHandle * handle
Here is the call graph for this function:

◆ handle_room_close()

static void handle_room_close ( void *  cls,
const struct GNUNET_MESSENGER_RoomMessage msg 
)
static

Definition at line 154 of file gnunet-service-messenger.c.

References GNUNET_MESSENGER_Client::client, close_handle_room(), env, get_handle_member_id(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_SERVICE_client_continue(), GNUNET_sh2s(), GNUNET_YES, GNUNET_MESSENGER_Client::handle, GNUNET_MESSENGER_RoomMessage::key, GNUNET_MESSENGER_SrvHandle::mq, and response.

155 {
156  struct GNUNET_MESSENGER_Client *msg_client = cls;
157 
158  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Closing room: %s\n", GNUNET_h2s (&(msg->key)));
159 
160  if (GNUNET_YES == close_handle_room (msg_client->handle, &(msg->key)))
161  {
162  const struct GNUNET_ShortHashCode *member_id = get_handle_member_id (msg_client->handle, &(msg->key));
163 
164  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Closing room with member id: %s\n", GNUNET_sh2s (member_id));
165 
167  struct GNUNET_MQ_Envelope *env;
168 
170  GNUNET_memcpy(&(response->key), &(msg->key), sizeof(msg->key));
171  GNUNET_MQ_send (msg_client->handle->mq, env);
172  }
173  else
174  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Closing room failed: %s\n", GNUNET_h2s (&(msg->key)));
175 
177 }
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
struct GNUNET_SERVICE_Client * client
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
A 256-bit hashcode.
int close_handle_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Removes the membership of the room using a specific key and closes it if no other handle from this se...
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_log(kind,...)
static struct MHD_Response * response
Our canonical response.
const struct GNUNET_ShortHashCode * get_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns the member id of a given handle in a specific room.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
General message to confirm interaction with a room.
struct GNUNET_MESSENGER_SrvHandle * handle
Here is the call graph for this function:

◆ check_send_message()

static int check_send_message ( void *  cls,
const struct GNUNET_MESSENGER_SendMessage msg 
)
static

Definition at line 180 of file gnunet-service-messenger.c.

References decode_message(), filter_message_sending(), GNUNET_MESSENGER_SendMessage::flags, GNUNET_IDENTITY_read_key_from_buffer(), GNUNET_MESSENGER_FLAG_PRIVATE, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_SendMessage::header, key_length, and GNUNET_MessageHeader::size.

181 {
182  const uint16_t full_length = ntohs (msg->header.size);
183 
184  if (full_length < sizeof(*msg))
185  return GNUNET_NO;
186 
187  const enum GNUNET_MESSENGER_MessageFlags flags = (
189  );
190 
191  const uint16_t length = full_length - sizeof(*msg);
192  const char *buffer = ((const char*) msg) + sizeof(*msg);
193 
194  uint16_t key_length = 0;
195 
196  if (!(flags & GNUNET_MESSENGER_FLAG_PRIVATE))
197  goto check_for_message;
198 
199  struct GNUNET_IDENTITY_PublicKey public_key;
200 
201  key_length = GNUNET_IDENTITY_read_key_from_buffer(&public_key, buffer, length);
202 
203 check_for_message:
204  if (key_length < 0)
205  return GNUNET_NO;
206 
207  const uint16_t msg_length = length - key_length;
208  const char* msg_buffer = buffer + key_length;
209 
210  struct GNUNET_MESSENGER_Message message;
211 
212  if (GNUNET_YES != decode_message (&message, msg_length, msg_buffer, GNUNET_NO, NULL))
213  return GNUNET_NO;
214 
215  if (GNUNET_YES != filter_message_sending(&message))
216  return GNUNET_NO;
217 
218  return GNUNET_OK;
219 }
ssize_t GNUNET_IDENTITY_read_key_from_buffer(struct GNUNET_IDENTITY_PublicKey *key, const void *buffer, size_t len)
Reads a GNUNET_IDENTITY_PublicKey from a compact buffer.
Definition: identity_api.c:994
int decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, int include_signature, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
GNUNET_MESSENGER_MessageFlags
Enum for the different supported flags used by message handling.
struct GNUNET_MessageHeader header
int filter_message_sending(const struct GNUNET_MESSENGER_Message *message)
Returns if a specific kind of message should be sent by a client.
static const int key_length
Fixed size of the public/private keys.
Definition: gnunet-abd.c:211
An identity key as per LSD0001.
Here is the call graph for this function:

◆ handle_send_message()

static void handle_send_message ( void *  cls,
const struct GNUNET_MESSENGER_SendMessage msg 
)
static

Definition at line 222 of file gnunet-service-messenger.c.

References GNUNET_MESSENGER_Client::client, decode_message(), encrypt_message(), GNUNET_MESSENGER_SendMessage::flags, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_IDENTITY_read_key_from_buffer(), GNUNET_log, GNUNET_MESSENGER_FLAG_PRIVATE, GNUNET_MESSENGER_name_of_kind(), GNUNET_NO, GNUNET_SERVICE_client_continue(), GNUNET_YES, GNUNET_MESSENGER_Client::handle, GNUNET_MESSENGER_SendMessage::header, GNUNET_MESSENGER_Message::header, key, GNUNET_MESSENGER_SendMessage::key, key_length, GNUNET_MESSENGER_MessageHeader::kind, send_handle_message(), and GNUNET_MessageHeader::size.

223 {
224  struct GNUNET_MESSENGER_Client *msg_client = cls;
225 
226  const enum GNUNET_MESSENGER_MessageFlags flags = (
228  );
229 
230  const struct GNUNET_HashCode *key = &(msg->key);
231  const char *buffer = ((const char*) msg) + sizeof(*msg);
232 
233  const uint16_t length = ntohs (msg->header.size) - sizeof(*msg);
234  uint16_t key_length = 0;
235 
236  struct GNUNET_IDENTITY_PublicKey public_key;
237 
238  if (flags & GNUNET_MESSENGER_FLAG_PRIVATE)
240  &public_key, buffer, length
241  );
242 
243  const uint16_t msg_length = length - key_length;
244  const char* msg_buffer = buffer + key_length;
245 
246  struct GNUNET_MESSENGER_Message message;
247  decode_message (&message, msg_length, msg_buffer, GNUNET_NO, NULL);
248 
249  if ((flags & GNUNET_MESSENGER_FLAG_PRIVATE) &&
250  (GNUNET_YES != encrypt_message(&message, &public_key)))
251  {
252  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Encrypting message failed: Message got dropped!\n");
253 
254  goto end_handling;
255  }
256 
257  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending message: %s to %s\n",
258  GNUNET_MESSENGER_name_of_kind (message.header.kind), GNUNET_h2s (key));
259 
260  if (GNUNET_YES != send_handle_message (msg_client->handle, key, &message))
261  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sending message failed: %s to %s\n",
262  GNUNET_MESSENGER_name_of_kind (message.header.kind), GNUNET_h2s (key));
263 
264 end_handling:
266 }
struct GNUNET_SERVICE_Client * client
ssize_t GNUNET_IDENTITY_read_key_from_buffer(struct GNUNET_IDENTITY_PublicKey *key, const void *buffer, size_t len)
Reads a GNUNET_IDENTITY_PublicKey from a compact buffer.
Definition: identity_api.c:994
int decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, int include_signature, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
GNUNET_MESSENGER_MessageFlags
Enum for the different supported flags used by message handling.
struct GNUNET_MessageHeader header
static const int key_length
Fixed size of the public/private keys.
Definition: gnunet-abd.c:211
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
Definition: messenger_api.c:35
A 512-bit hashcode.
struct GNUNET_HashCode key
The key used in the DHT.
int send_handle_message(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, const struct GNUNET_MESSENGER_Message *message)
Sends a message from a given handle to the room using a specific key.
An identity key as per LSD0001.
#define GNUNET_log(kind,...)
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 encry...
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
struct GNUNET_MESSENGER_SrvHandle * handle
Here is the call graph for this function:

◆ handle_get_message()

static void handle_get_message ( void *  cls,
const struct GNUNET_MESSENGER_GetMessage msg 
)
static

Definition at line 269 of file gnunet-service-messenger.c.

References GNUNET_MESSENGER_Client::client, get_member_session_of(), get_room_key(), get_room_member_store(), get_room_message(), get_service_room(), get_store_member_of(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_log, GNUNET_SERVICE_client_continue(), GNUNET_YES, GNUNET_MESSENGER_Client::handle, GNUNET_MESSENGER_GetMessage::hash, GNUNET_MESSENGER_GetMessage::key, and notify_handle_message().

270 {
271  struct GNUNET_MESSENGER_Client *msg_client = cls;
272 
273  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Requesting message from room: %s\n", GNUNET_h2s (&(msg->key)));
274 
275  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (messenger, &(msg->key));
276 
277  if (!room)
278  {
279  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Room not found: %s\n", GNUNET_h2s (&(msg->key)));
280  goto end_handling;
281  }
282 
283  const struct GNUNET_MESSENGER_Message *message = get_room_message (room, msg_client->handle, &(msg->hash),
284  GNUNET_YES);
285 
286  if (!message)
287  goto end_handling;
288 
290 
291  struct GNUNET_MESSENGER_Member *member = get_store_member_of(store, message);
292 
293  if (!member)
294  {
295  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sender of message (%s) unknown!\n", GNUNET_h2s (&(msg->hash)));
296  goto end_handling;
297  }
298 
299  struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, &(msg->hash));
300 
301  if (session)
302  notify_handle_message (msg_client->handle, get_room_key(room), session, message, &(msg->hash));
303 
304 end_handling:
306 }
struct GNUNET_SERVICE_Client * client
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_MESSENGER_Service * messenger
struct GNUNET_MESSENGER_MemberStore * get_room_member_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used member store of a given room.
struct GNUNET_MESSENGER_SrvRoom * get_service_room(const struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key)
Returns the room identified by a given key for a service.
void notify_handle_message(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Notifies the handle that a new message was received or sent.
const struct GNUNET_MESSENGER_Message * get_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *hash, int request)
Returns a message from a room identified by a given hash.
struct GNUNET_MESSENGER_Member * get_store_member_of(struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_MESSENGER_Message *message)
Returns the member of a store using a sender id of a given message.
#define GNUNET_log(kind,...)
const struct GNUNET_HashCode * get_room_key(const struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
struct GNUNET_MESSENGER_MemberSession * get_member_session_of(struct GNUNET_MESSENGER_Member *member, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Returns the member session of a member using a public key which can verify the signature of a given m...
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
struct GNUNET_MESSENGER_SrvHandle * handle
Here is the call graph for this function:

◆ callback_client_connect()

static void* callback_client_connect ( void *  cls,
struct GNUNET_SERVICE_Client client,
struct GNUNET_MQ_Handle mq 
)
static

Definition at line 309 of file gnunet-service-messenger.c.

References add_service_handle(), GNUNET_MESSENGER_Client::client, GNUNET_new, and GNUNET_MESSENGER_Client::handle.

Referenced by run().

310 {
311  struct GNUNET_MESSENGER_Client *msg_client = GNUNET_new(struct GNUNET_MESSENGER_Client);
312 
313  msg_client->client = client;
314  msg_client->handle = add_service_handle (messenger, mq);
315 
316  return msg_client;
317 }
struct GNUNET_SERVICE_Client * client
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_MESSENGER_SrvHandle * add_service_handle(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq)
Creates and adds a new handle to a service using a given message queue.
struct GNUNET_MESSENGER_Service * messenger
struct GNUNET_MESSENGER_SrvHandle * handle
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_client_disconnect()

static void callback_client_disconnect ( void *  cls,
struct GNUNET_SERVICE_Client client,
void *  internal_cls 
)
static

Definition at line 320 of file gnunet-service-messenger.c.

References GNUNET_free, GNUNET_MESSENGER_Client::handle, and remove_service_handle().

Referenced by run().

321 {
322  struct GNUNET_MESSENGER_Client *msg_client = internal_cls;
323 
324  remove_service_handle (messenger, msg_client->handle);
325 
326  GNUNET_free(msg_client);
327 }
struct GNUNET_MESSENGER_Service * messenger
void remove_service_handle(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle)
Removes a handle from a service and destroys it.
struct GNUNET_MESSENGER_SrvHandle * handle
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle config,
struct GNUNET_SERVICE_Handle service 
)
static

Setup MESSENGER internals.

Parameters

Definition at line 337 of file gnunet-service-messenger.c.

References callback_client_connect(), callback_client_disconnect(), create_service(), destroy(), get_message(), GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE, GNUNET_MESSENGER_SERVICE_NAME, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_SCHEDULER_shutdown(), GNUNET_SERVICE_MAIN(), GNUNET_SERVICE_OPTION_NONE, and send_message().

338 {
339  messenger = create_service (config, service);
340 
341  if (!messenger)
343 }
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
struct GNUNET_MESSENGER_Service * messenger
struct GNUNET_MESSENGER_Service * create_service(const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_SERVICE_Handle *service_handle)
Creates and allocates a new service using a given config and a GNUnet service handle.
Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

Define "main" method using service macro.

Referenced by run().

Here is the caller graph for this function:

Variable Documentation

◆ messenger

struct GNUNET_MESSENGER_Service* messenger

Definition at line 37 of file gnunet-service-messenger.c.