GNUnet 0.22.2
gnunet-service-messenger.c File Reference
Include dependency graph for gnunet-service-messenger.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_Client
 

Functions

static void handle_create (void *cls, const struct GNUNET_MESSENGER_CreateMessage *msg)
 
static void handle_destroy (void *cls, const struct GNUNET_MESSENGER_DestroyMessage *msg)
 
static enum GNUNET_GenericReturnValue check_room_initial_key (const struct GNUNET_MESSENGER_RoomMessage *msg)
 
static void initialize_handle_via_key (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_RoomMessage *msg)
 
static enum GNUNET_GenericReturnValue check_room_open (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
 
static void handle_room_open (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
 
static enum GNUNET_GenericReturnValue check_room_entry (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 void handle_room_sync (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
 
static enum GNUNET_GenericReturnValue 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 callback_found_message (void *cls, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
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_OS_project_data_gnunet(), GNUNET_MESSENGER_SERVICE_NAME, GNUNET_SERVICE_OPTION_NONE, &run, &callback_client_connect, &callback_client_disconnect, NULL, GNUNET_MQ_hd_fixed_size(create, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE, struct GNUNET_MESSENGER_CreateMessage, NULL), GNUNET_MQ_hd_fixed_size(destroy, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY, struct GNUNET_MESSENGER_DestroyMessage, NULL), GNUNET_MQ_hd_var_size(room_open, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, struct GNUNET_MESSENGER_RoomMessage, NULL), GNUNET_MQ_hd_var_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_hd_fixed_size(room_sync, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC, struct GNUNET_MESSENGER_RoomMessage, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro. More...
 

Variables

struct GNUNET_MESSENGER_Servicemessenger
 

Function Documentation

◆ handle_create()

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

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

44{
45 struct GNUNET_MESSENGER_Client *msg_client;
46
47 GNUNET_assert (cls);
48
49 msg_client = cls;
50
51 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handle created\n");
52
54}
#define GNUNET_log(kind,...)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2389
struct GNUNET_SERVICE_Client * client

References GNUNET_MESSENGER_Client::client, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and GNUNET_SERVICE_client_continue().

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 58 of file gnunet-service-messenger.c.

60{
61 struct GNUNET_MESSENGER_Client *msg_client;
62
63 GNUNET_assert (cls);
64
65 msg_client = cls;
66
67 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handle destroyed\n");
68
70}
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2418

References GNUNET_MESSENGER_Client::client, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and GNUNET_SERVICE_client_drop().

Here is the call graph for this function:

◆ check_room_initial_key()

static enum GNUNET_GenericReturnValue check_room_initial_key ( const struct GNUNET_MESSENGER_RoomMessage msg)
static

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

75{
76 uint16_t full_length;
77 uint16_t msg_length;
78 const char *msg_buffer;
79
81
82 full_length = ntohs (msg->header.size);
83
84 if (full_length < sizeof(*msg))
85 return GNUNET_NO;
86
87 msg_length = full_length - sizeof(*msg);
88 msg_buffer = ((const char*) msg) + sizeof(*msg);
89
90 if (0 == msg_length)
91 return GNUNET_OK;
92
93 {
95 size_t key_len;
96
98 msg_length,
99 &key, &key_len))
100 return GNUNET_NO;
101
102 return key_len == msg_length ? GNUNET_OK : GNUNET_NO;
103 }
104}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_HashCode key
The key used in the DHT.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_public_key_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_PublicKey *key, size_t *read)
Reads a GNUNET_CRYPTO_PublicKey from a compact buffer.
Definition: crypto_pkey.c:102
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_NO
An identity key as per LSD0001.

References GNUNET_assert, GNUNET_CRYPTO_read_public_key_from_buffer(), GNUNET_NO, GNUNET_OK, key, msg, and GNUNET_MessageHeader::size.

Referenced by check_room_entry(), and check_room_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize_handle_via_key()

static void initialize_handle_via_key ( struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_MESSENGER_RoomMessage msg 
)
static

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

110{
111 uint16_t full_length;
112 uint16_t msg_length;
113 const char *msg_buffer;
114
115 GNUNET_assert ((handle) && (msg));
116
117 full_length = ntohs (msg->header.size);
118 msg_length = full_length - sizeof(*msg);
119 msg_buffer = ((const char*) msg) + sizeof(*msg);
120
121 if (msg_length > 0)
122 {
124 size_t key_len;
125
127 msg_length,
128 &key,
129 &key_len))
131 else
133 "Initialization failed while reading invalid key!\n");
134 }
135 else
136 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Initialization is missing key!\n");
137}
void set_srv_handle_key(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_CRYPTO_PublicKey *key)
Sets the public key of a given handle.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR

References GNUNET_assert, GNUNET_CRYPTO_read_public_key_from_buffer(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_OK, handle, key, msg, set_srv_handle_key(), and GNUNET_MessageHeader::size.

Referenced by handle_room_entry(), and handle_room_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_room_open()

static enum GNUNET_GenericReturnValue check_room_open ( void *  cls,
const struct GNUNET_MESSENGER_RoomMessage msg 
)
static

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

143{
145}
static enum GNUNET_GenericReturnValue check_room_initial_key(const struct GNUNET_MESSENGER_RoomMessage *msg)

References check_room_initial_key(), and msg.

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 149 of file gnunet-service-messenger.c.

151{
152 struct GNUNET_MESSENGER_Client *msg_client;
153
154 GNUNET_assert ((cls) && (msg));
155
156 msg_client = cls;
157
158 initialize_handle_via_key (msg_client->handle, msg);
159
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening room: %s\n", GNUNET_h2s (
161 &(msg->key)));
162
163 if (GNUNET_YES == open_srv_handle_room (msg_client->handle, &(msg->key)))
164 {
165 struct GNUNET_HashCode prev;
166 const struct GNUNET_ShortHashCode *member_id;
168 struct GNUNET_MQ_Envelope *env;
169
170 sync_srv_handle_messages (msg_client->handle, &(msg->key), &(msg->previous),
171 &prev);
172
173 member_id = get_srv_handle_member_id (msg_client->handle, &(msg->key));
174
175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening room with member id: %s\n",
176 GNUNET_sh2s (member_id));
177
179 GNUNET_memcpy (&(response->key), &(msg->key), sizeof(response->key));
180 GNUNET_memcpy (&(response->previous), &prev, sizeof(response->previous));
181 GNUNET_MQ_send (msg_client->handle->mq, env);
182 }
183 else
184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Opening room failed: %s\n",
185 GNUNET_h2s (&(msg->key)));
186
188}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct MHD_Response * response
Our canonical response.
static void initialize_handle_via_key(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_RoomMessage *msg)
void sync_srv_handle_messages(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, const struct GNUNET_HashCode *prev, struct GNUNET_HashCode *hash)
Returns the latest merged hash from a room of a given handle using a specific key and the handles own...
const struct GNUNET_ShortHashCode * get_srv_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.
enum GNUNET_GenericReturnValue open_srv_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...
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_YES
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
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:305
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN
A 512-bit hashcode.
struct GNUNET_MESSENGER_SrvHandle * handle
General message to confirm interaction with a room.
struct GNUNET_MQ_Envelope * prev
Messages are stored in a linked list Each queue has its own list of envelopes.
Definition: mq.c:45
A 256-bit hashcode.

References GNUNET_MESSENGER_Client::client, env, get_srv_handle_member_id(), GNUNET_assert, 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, initialize_handle_via_key(), GNUNET_MESSENGER_SrvHandle::mq, msg, open_srv_handle_room(), GNUNET_MQ_Envelope::prev, response, and sync_srv_handle_messages().

Here is the call graph for this function:

◆ check_room_entry()

static enum GNUNET_GenericReturnValue check_room_entry ( void *  cls,
const struct GNUNET_MESSENGER_RoomMessage msg 
)
static

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

194{
196}

References check_room_initial_key(), and msg.

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 200 of file gnunet-service-messenger.c.

202{
203 struct GNUNET_MESSENGER_Client *msg_client;
204
205 GNUNET_assert ((cls) && (msg));
206
207 msg_client = cls;
208
209 initialize_handle_via_key (msg_client->handle, msg);
210
211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entering room: %s, %s\n", GNUNET_h2s (
212 &(msg->key)), GNUNET_i2s (&(msg->door)));
213
214 if (GNUNET_YES == entry_srv_handle_room (msg_client->handle, &(msg->door),
215 &(msg->key)))
216 {
217 struct GNUNET_HashCode prev;
218 const struct GNUNET_ShortHashCode *member_id;
220 struct GNUNET_MQ_Envelope *env;
221
222 sync_srv_handle_messages (msg_client->handle, &(msg->key), &(msg->previous),
223 &prev);
224
225 member_id = get_srv_handle_member_id (msg_client->handle, &(msg->key));
226
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entering room with member id: %s\n",
228 GNUNET_sh2s (member_id));
229
231 GNUNET_memcpy (&(response->door), &(msg->door), sizeof(response->door));
232 GNUNET_memcpy (&(response->key), &(msg->key), sizeof(response->key));
233 GNUNET_memcpy (&(response->previous), &prev, sizeof(response->previous));
234 GNUNET_MQ_send (msg_client->handle->mq, env);
235 }
236 else
237 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Entrance into room failed: %s, %s\n",
238 GNUNET_h2s (&(msg->key)),
239 GNUNET_i2s (&(msg->door)));
240
242}
enum GNUNET_GenericReturnValue entry_srv_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).
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY

References GNUNET_MESSENGER_Client::client, entry_srv_handle_room(), env, get_srv_handle_member_id(), GNUNET_assert, 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, initialize_handle_via_key(), GNUNET_MESSENGER_SrvHandle::mq, msg, GNUNET_MQ_Envelope::prev, response, and sync_srv_handle_messages().

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 246 of file gnunet-service-messenger.c.

248{
249 struct GNUNET_MESSENGER_Client *msg_client;
250
251 GNUNET_assert (cls);
252
253 msg_client = cls;
254
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Closing room: %s\n", GNUNET_h2s (
256 &(msg->key)));
257
258 if (GNUNET_YES == close_srv_handle_room (msg_client->handle, &(msg->key)))
259 {
261 struct GNUNET_MQ_Envelope *env;
262
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Closing room succeeded: %s\n",
264 GNUNET_h2s (&(msg->key)));
265
267 GNUNET_memcpy (&(response->key), &(msg->key), sizeof(response->key));
268 GNUNET_memcpy (&(response->previous), &(msg->previous),
269 sizeof(response->previous));
270 GNUNET_MQ_send (msg_client->handle->mq, env);
271 }
272 else
273 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Closing room failed: %s\n",
274 GNUNET_h2s (&(msg->key)));
275
277}
enum GNUNET_GenericReturnValue close_srv_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

References GNUNET_MESSENGER_Client::client, close_srv_handle_room(), env, GNUNET_assert, 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_YES, GNUNET_MESSENGER_Client::handle, GNUNET_MESSENGER_SrvHandle::mq, msg, and response.

Here is the call graph for this function:

◆ handle_room_sync()

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

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

283{
284 struct GNUNET_MESSENGER_Client *msg_client;
285
286 GNUNET_assert (cls);
287
288 msg_client = cls;
289
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Syncing room: %s\n", GNUNET_h2s (
291 &(msg->key)));
292
293 {
294 struct GNUNET_HashCode prev;
296 struct GNUNET_MQ_Envelope *env;
297
298 sync_srv_handle_messages (msg_client->handle, &(msg->key), &(msg->previous),
299 &prev);
300
302 GNUNET_memcpy (&(response->key), &(msg->key), sizeof(response->key));
303 GNUNET_memcpy (&(response->previous), &prev, sizeof(response->previous));
304 GNUNET_MQ_send (msg_client->handle->mq, env);
305 }
306
308}
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC

References GNUNET_MESSENGER_Client::client, env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_SERVICE_client_continue(), GNUNET_MESSENGER_Client::handle, GNUNET_MESSENGER_SrvHandle::mq, msg, GNUNET_MQ_Envelope::prev, response, and sync_srv_handle_messages().

Here is the call graph for this function:

◆ check_send_message()

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

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

314{
315 uint16_t full_length;
316 uint16_t msg_length;
317 const char *msg_buffer;
318 struct GNUNET_MESSENGER_Message message;
319
321
322 full_length = ntohs (msg->header.size);
323
324 if (full_length < sizeof(*msg))
325 return GNUNET_NO;
326
327 msg_length = full_length - sizeof(*msg);
328 msg_buffer = ((const char*) msg) + sizeof(*msg);
329
331 GNUNET_YES))
332 {
333 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Too short message: %s\n", GNUNET_h2s (
334 &(msg->key)));
335 return GNUNET_NO;
336 }
337
338 if (GNUNET_YES != decode_message (&message, msg_length, msg_buffer,
340 NULL))
341 {
342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Decoding message failed: %s\n",
343 GNUNET_h2s (
344 &(msg->key)));
345 return GNUNET_NO;
346 }
347
348 {
349 enum GNUNET_GenericReturnValue allowed;
350 allowed = filter_message_sending (&message);
351
352 if (GNUNET_SYSERR == allowed)
354 "Sending message not allowed: %s to %s\n",
355 GNUNET_MESSENGER_name_of_kind (message.header.kind),
356 GNUNET_h2s (&(msg->key)));
357
358 cleanup_message (&message);
359 return GNUNET_SYSERR != allowed? GNUNET_OK : GNUNET_NO;
360 }
361}
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_SYSERR
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
Definition: messenger_api.c:44
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
enum GNUNET_GenericReturnValue filter_message_sending(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message should be sent by a client.
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind, enum GNUNET_GenericReturnValue include_header)
Returns the minimal size in bytes to encode a message of a specific kind.
enum GNUNET_GenericReturnValue decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, enum GNUNET_GenericReturnValue include_header, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
void cleanup_message(struct GNUNET_MESSENGER_Message *message)
Frees the messages body memory.

References cleanup_message(), decode_message(), filter_message_sending(), get_message_kind_size(), GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_MESSENGER_name_of_kind(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, msg, and GNUNET_MessageHeader::size.

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 365 of file gnunet-service-messenger.c.

367{
368 struct GNUNET_MESSENGER_Client *msg_client;
369 const struct GNUNET_HashCode *key;
370 const char *msg_buffer;
371 uint16_t msg_length;
372
373 GNUNET_assert ((cls) && (msg));
374
375 msg_client = cls;
376
377 key = &(msg->key);
378 msg_buffer = ((const char*) msg) + sizeof(*msg);
379 msg_length = ntohs (msg->header.size) - sizeof(*msg);
380
381 {
382 struct GNUNET_MESSENGER_Message message;
383 decode_message (&message, msg_length, msg_buffer, GNUNET_YES, NULL);
384
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message: %s to %s (by %s)\n",
386 GNUNET_MESSENGER_name_of_kind (message.header.kind),
387 GNUNET_h2s (key),
388 GNUNET_sh2s (&(message.header.sender_id)));
389
390 if (GNUNET_YES != send_srv_handle_message (msg_client->handle, key, &message
391 ))
392 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sending message failed: %s to %s\n",
393 GNUNET_MESSENGER_name_of_kind (message.header.kind),
394 GNUNET_h2s (key));
395
396 cleanup_message (&message);
397 }
398
400}
enum GNUNET_GenericReturnValue send_srv_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.

References cleanup_message(), GNUNET_MESSENGER_Client::client, decode_message(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_name_of_kind(), GNUNET_SERVICE_client_continue(), GNUNET_sh2s(), GNUNET_YES, GNUNET_MESSENGER_Client::handle, GNUNET_MESSENGER_Message::header, key, GNUNET_MESSENGER_MessageHeader::kind, msg, send_srv_handle_message(), GNUNET_MESSENGER_MessageHeader::sender_id, and GNUNET_MessageHeader::size.

Here is the call graph for this function:

◆ callback_found_message()

static void callback_found_message ( void *  cls,
struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

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

408{
409 struct GNUNET_MESSENGER_Client *msg_client;
410 struct GNUNET_MESSENGER_SenderSession session;
411
412 GNUNET_assert ((cls) && (room) && (hash));
413
414 msg_client = cls;
415
416 if (! message)
417 {
419 struct GNUNET_MQ_Envelope *env;
420
422 "Notifying client about missing message: %s\n",
423 GNUNET_h2s (hash));
424
427 GNUNET_memcpy (&(response->key), &(room->key), sizeof(room->key));
428 GNUNET_memcpy (&(response->hash), hash, sizeof(*hash));
429 GNUNET_MQ_send (msg_client->handle->mq, env);
430 return;
431 }
432
433 if (GNUNET_YES == is_peer_message (message))
434 {
435 struct GNUNET_MESSENGER_PeerStore *store;
436
437 store = get_srv_room_peer_store (room);
438 session.peer = get_store_peer_of (store, message, hash);
439
440 if (! session.peer)
441 {
443 "Peer session from sender of message (%s) unknown!\n",
444 GNUNET_h2s (hash));
445 return;
446 }
447 }
448 else
449 {
450 struct GNUNET_MESSENGER_MemberStore *store;
451 struct GNUNET_MESSENGER_Member *member;
452
454 member = get_store_member_of (store, message);
455
456 if (! member)
457 {
458 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sender of message (%s) unknown!\n",
459 GNUNET_h2s (hash));
460 return;
461 }
462
463 session.member = get_member_session_of (member, message, hash);
464
465 if (! session.member)
466 {
468 "Member session from sender of message (%s) unknown!\n",
469 GNUNET_h2s (hash));
470 return;
471 }
472 }
473
474 notify_srv_handle_message (msg_client->handle, room, &session, message,
475 hash, GNUNET_NO);
476}
void notify_srv_handle_message(struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, enum GNUNET_GenericReturnValue recent)
Notifies the handle that a new message was received or sent.
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...
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.
struct GNUNET_PeerIdentity * get_store_peer_of(struct GNUNET_MESSENGER_PeerStore *store, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Returns the peer identity inside the store which verifies the signature of a given message as valid.
struct GNUNET_MESSENGER_PeerStore * get_srv_room_peer_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used peer store of a given room.
struct GNUNET_MESSENGER_MemberStore * get_srv_room_member_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used member store of a given room.
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE
enum GNUNET_GenericReturnValue is_peer_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message can be sent by the service without usage of a clients priv...
Message to request something from a room.
struct GNUNET_MESSENGER_MemberStore * store

References env, get_member_session_of(), get_srv_room_member_store(), get_srv_room_peer_store(), get_store_member_of(), get_store_peer_of(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Client::handle, is_peer_message(), GNUNET_MESSENGER_SrvRoom::key, GNUNET_MESSENGER_SenderSession::member, GNUNET_MESSENGER_SrvHandle::mq, notify_srv_handle_message(), GNUNET_MESSENGER_SenderSession::peer, response, and GNUNET_MESSENGER_Member::store.

Referenced by handle_get_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_get_message()

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

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

482{
483 struct GNUNET_MESSENGER_Client *msg_client;
484 struct GNUNET_MESSENGER_SrvRoom *room;
485 const struct GNUNET_ShortHashCode *member_id;
486 struct GNUNET_MESSENGER_Member *member;
487 const struct GNUNET_CRYPTO_PublicKey *pubkey;
488 struct GNUNET_MESSENGER_MemberSession *session;
489
490 GNUNET_assert ((cls) && (msg));
491
492 msg_client = cls;
493
494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting message from room: %s\n",
495 GNUNET_h2s (&(msg->key)));
496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requested message: %s\n",
497 GNUNET_h2s (&(msg->hash)));
498
499 room = get_service_room (messenger, &(msg->key));
500
501 if (! room)
502 {
503 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Room not found: %s\n", GNUNET_h2s (
504 &(msg->key)));
505 goto end_handling;
506 }
507
508 {
509 struct GNUNET_MESSENGER_MemberStore *member_store;
510 member_store = get_srv_room_member_store (room);
511
512
513 member_id = get_srv_handle_member_id (msg_client->handle,
514 &(msg->key));
515
516 member = get_store_member (member_store, member_id);
517 }
518
519 if (! member)
520 {
522 "Member not valid to request a message! (%s)\n",
523 GNUNET_sh2s (member_id));
524 goto end_handling;
525 }
526
527 pubkey = get_srv_handle_key (msg_client->handle);
528
529 if (! pubkey)
530 {
532 "Handle needs to have a public key to request a message! (%s)\n",
533 GNUNET_sh2s (member_id));
534 goto end_handling;
535 }
536
537 session = get_member_session (member, pubkey);
538
539 if (! session)
540 {
542 "Session not valid to request a message! (%s)\n",
543 GNUNET_sh2s (member_id));
544 goto end_handling;
545 }
546
548 msg_client);
549
550end_handling:
552}
static struct GNUNET_CRYPTO_PublicKey pubkey
Public key of the zone to look in.
struct GNUNET_MESSENGER_Service * messenger
static void callback_found_message(void *cls, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
const struct GNUNET_CRYPTO_PublicKey * get_srv_handle_key(const struct GNUNET_MESSENGER_SrvHandle *handle)
Returns the public key of a given handle.
struct GNUNET_MESSENGER_MemberSession * get_member_session(const struct GNUNET_MESSENGER_Member *member, const struct GNUNET_CRYPTO_PublicKey *public_key)
Returns the member session of a member identified by a given public key.
struct GNUNET_MESSENGER_Member * get_store_member(const struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id)
Returns the member in a store identified by a given id.
enum GNUNET_GenericReturnValue request_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_MemberSession *session, GNUNET_MESSENGER_MessageRequestCallback callback, void *cls)
Requests a message from a room identified by a given hash.
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.

References callback_found_message(), GNUNET_MESSENGER_Client::client, get_member_session(), get_service_room(), get_srv_handle_key(), get_srv_handle_member_id(), get_srv_room_member_store(), get_store_member(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_log, GNUNET_SERVICE_client_continue(), GNUNET_sh2s(), GNUNET_MESSENGER_Client::handle, messenger, msg, pubkey, request_srv_room_message(), and GNUNET_MESSENGER_MemberStore::room.

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 556 of file gnunet-service-messenger.c.

559{
560 struct GNUNET_MESSENGER_Client *msg_client;
561
562 GNUNET_assert ((client) && (mq));
563
564 msg_client = GNUNET_new (struct GNUNET_MESSENGER_Client);
565
566 msg_client->client = client;
567 msg_client->handle = add_service_handle (messenger, mq);
568
569 return msg_client;
570}
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.

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

Here is the call 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 574 of file gnunet-service-messenger.c.

577{
578 struct GNUNET_MESSENGER_Client *msg_client;
579
580 GNUNET_assert (internal_cls);
581
582 msg_client = internal_cls;
583
585
586 GNUNET_free (msg_client);
587}
void remove_service_handle(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle)
Removes a handle from a service and destroys it.
#define GNUNET_free(ptr)
Wrapper around free.

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

Here is the call 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
[in/out]cls closure
[in]configconfiguration to use
[in/out]service the initialized service

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

601{
603
605
606 if (! messenger)
608}
const struct GNUNET_CONFIGURATION_Handle * config
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
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.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567

References config, create_service(), GNUNET_assert, GNUNET_SCHEDULER_shutdown(), messenger, and service.

Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

Variable Documentation

◆ messenger