GNUnet 0.21.1
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_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 43 of file gnunet-service-messenger.c.

45{
46 struct GNUNET_MESSENGER_Client *msg_client = cls;
47
48 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handle created\n");
49
51}
#define GNUNET_log(kind,...)
@ 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:2408
struct GNUNET_SERVICE_Client * client

References GNUNET_MESSENGER_Client::client, 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 55 of file gnunet-service-messenger.c.

57{
58 struct GNUNET_MESSENGER_Client *msg_client = cls;
59
60 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handle destroyed\n");
61
63}
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2489

References GNUNET_MESSENGER_Client::client, 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 67 of file gnunet-service-messenger.c.

68{
69 const uint16_t full_length = ntohs (msg->header.size);
70
71 if (full_length < sizeof(*msg))
72 return GNUNET_NO;
73
74 const uint16_t msg_length = full_length - sizeof(*msg);
75 const char *msg_buffer = ((const char*) msg) + sizeof(*msg);
76
77 if (0 == msg_length)
78 return GNUNET_OK;
79
81 size_t key_len;
82
84 msg_length,
85 &key, &key_len))
86 return GNUNET_NO;
87
88 return key_len == msg_length ? GNUNET_OK : GNUNET_NO;
89}
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:103
@ GNUNET_OK
@ GNUNET_NO
An identity key as per LSD0001.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

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

95{
97
98 const uint16_t full_length = ntohs (msg->header.size);
99 const uint16_t msg_length = full_length - sizeof(*msg);
100 const char *msg_buffer = ((const char*) msg) + sizeof(*msg);
101
102 if (msg_length > 0)
103 {
105 size_t key_len;
106
108 msg_length,
109 &key,
110 &key_len))
112 else
114 "Initialization failed while reading invalid key!\n");
115 }
116 else
117 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Initialization is missing key!\n");
118}
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
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ 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 122 of file gnunet-service-messenger.c.

124{
126}
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 130 of file gnunet-service-messenger.c.

132{
133 struct GNUNET_MESSENGER_Client *msg_client = cls;
134
135 initialize_handle_via_key (msg_client->handle, msg);
136
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening room: %s\n", GNUNET_h2s (
138 &(msg->key)));
139
140 if (GNUNET_YES == open_srv_handle_room (msg_client->handle, &(msg->key)))
141 {
142 struct GNUNET_HashCode prev;
143 sync_srv_handle_messages (msg_client->handle, &(msg->key), &(msg->previous),
144 &prev);
145
146 const struct GNUNET_ShortHashCode *member_id = get_srv_handle_member_id (
147 msg_client->handle, &(msg->key));
148
149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening room with member id: %s\n",
150 GNUNET_sh2s (member_id));
151
153 struct GNUNET_MQ_Envelope *env;
154
156 GNUNET_memcpy (&(response->key), &(msg->key), sizeof(response->key));
157 GNUNET_memcpy (&(response->previous), &prev, sizeof(response->previous));
158 GNUNET_MQ_send (msg_client->handle->mq, env);
159 }
160 else
161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Opening room failed: %s\n",
162 GNUNET_h2s (&(msg->key)));
163
165}
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:304
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#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_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 169 of file gnunet-service-messenger.c.

171{
173}

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

179{
180 struct GNUNET_MESSENGER_Client *msg_client = cls;
181
182 initialize_handle_via_key (msg_client->handle, msg);
183
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entering room: %s, %s\n", GNUNET_h2s (
185 &(msg->key)), GNUNET_i2s (&(msg->door)));
186
187 if (GNUNET_YES == entry_srv_handle_room (msg_client->handle, &(msg->door),
188 &(msg->key)))
189 {
190 struct GNUNET_HashCode prev;
191 sync_srv_handle_messages (msg_client->handle, &(msg->key), &(msg->previous),
192 &prev);
193
194 const struct GNUNET_ShortHashCode *member_id = get_srv_handle_member_id (
195 msg_client->handle, &(msg->key));
196
197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entering room with member id: %s\n",
198 GNUNET_sh2s (member_id));
199
201 struct GNUNET_MQ_Envelope *env;
202
204 GNUNET_memcpy (&(response->door), &(msg->door), sizeof(response->door));
205 GNUNET_memcpy (&(response->key), &(msg->key), sizeof(response->key));
206 GNUNET_memcpy (&(response->previous), &prev, sizeof(response->previous));
207 GNUNET_MQ_send (msg_client->handle->mq, env);
208 }
209 else
210 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Entrance into room failed: %s, %s\n",
211 GNUNET_h2s (&(msg->key)),
212 GNUNET_i2s (&(msg->door)));
213
215}
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_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 219 of file gnunet-service-messenger.c.

221{
222 struct GNUNET_MESSENGER_Client *msg_client = cls;
223
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Closing room: %s\n", GNUNET_h2s (
225 &(msg->key)));
226
227 if (GNUNET_YES == close_srv_handle_room (msg_client->handle, &(msg->key)))
228 {
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Closing room succeeded: %s\n",
230 GNUNET_h2s (&(msg->key)));
231
233 struct GNUNET_MQ_Envelope *env;
234
236 GNUNET_memcpy (&(response->key), &(msg->key), sizeof(response->key));
237 GNUNET_memcpy (&(response->previous), &(msg->previous),
238 sizeof(response->previous));
239 GNUNET_MQ_send (msg_client->handle->mq, env);
240 }
241 else
242 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Closing room failed: %s\n",
243 GNUNET_h2s (&(msg->key)));
244
246}
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_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 250 of file gnunet-service-messenger.c.

252{
253 struct GNUNET_MESSENGER_Client *msg_client = cls;
254
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Syncing room: %s\n", GNUNET_h2s (
256 &(msg->key)));
257
258 struct GNUNET_HashCode prev;
259 sync_srv_handle_messages (msg_client->handle, &(msg->key), &(msg->previous),
260 &prev);
261
263 struct GNUNET_MQ_Envelope *env;
264
266 GNUNET_memcpy (&(response->key), &(msg->key), sizeof(response->key));
267 GNUNET_memcpy (&(response->previous), &prev, sizeof(response->previous));
268 GNUNET_MQ_send (msg_client->handle->mq, env);
269
271}
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC

References GNUNET_MESSENGER_Client::client, env, 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 275 of file gnunet-service-messenger.c.

277{
278 const uint16_t full_length = ntohs (msg->header.size);
279
280 if (full_length < sizeof(*msg))
281 return GNUNET_NO;
282
283 const uint16_t msg_length = full_length - sizeof(*msg);
284 const char *msg_buffer = ((const char*) msg) + sizeof(*msg);
285
286 struct GNUNET_MESSENGER_Message message;
287
289 GNUNET_YES))
290 return GNUNET_NO;
291
292 if (GNUNET_YES != decode_message (&message, msg_length, msg_buffer,
294 NULL))
295 return GNUNET_NO;
296
297 enum GNUNET_GenericReturnValue allowed;
298 allowed = filter_message_sending (&message);
299
300 cleanup_message (&message);
301 return GNUNET_SYSERR != allowed? GNUNET_OK : GNUNET_NO;
302}
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_SYSERR
@ 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_MESSENGER_KIND_UNKNOWN, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, 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 306 of file gnunet-service-messenger.c.

308{
309 struct GNUNET_MESSENGER_Client *msg_client = cls;
310
311 const struct GNUNET_HashCode *key = &(msg->key);
312 const char *msg_buffer = ((const char*) msg) + sizeof(*msg);
313 const uint16_t msg_length = ntohs (msg->header.size) - sizeof(*msg);
314
315 struct GNUNET_MESSENGER_Message message;
316 decode_message (&message, msg_length, msg_buffer, GNUNET_YES, NULL);
317
318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message: %s to %s (by %s)\n",
319 GNUNET_MESSENGER_name_of_kind (message.header.kind),
320 GNUNET_h2s (key),
321 GNUNET_sh2s (&(message.header.sender_id)));
322
323 if (GNUNET_YES != send_srv_handle_message (msg_client->handle, key, &message))
324 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sending message failed: %s to %s\n",
325 GNUNET_MESSENGER_name_of_kind (message.header.kind),
326 GNUNET_h2s (key));
327
328 cleanup_message (&message);
329
331}
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.
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
Definition: messenger_api.c:43

References cleanup_message(), GNUNET_MESSENGER_Client::client, decode_message(), 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 335 of file gnunet-service-messenger.c.

339{
340 struct GNUNET_MESSENGER_Client *msg_client = cls;
341
342 if (! message)
343 {
345 struct GNUNET_MQ_Envelope *env;
346
349 GNUNET_memcpy (&(response->key), &(room->key), sizeof(room->key));
350 GNUNET_memcpy (&(response->hash), hash, sizeof(*hash));
351 GNUNET_MQ_send (msg_client->handle->mq, env);
352 return;
353 }
354
355 struct GNUNET_MESSENGER_SenderSession session;
356
357 if (GNUNET_YES == is_peer_message (message))
358 {
360
361 session.peer = get_store_peer_of (store, message, hash);
362
363 if (! session.peer)
364 {
366 "Peer session from sender of message (%s) unknown!\n",
367 GNUNET_h2s (hash));
368 return;
369 }
370 }
371 else
372 {
374 room);
376 message);
377
378 if (! member)
379 {
380 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sender of message (%s) unknown!\n",
381 GNUNET_h2s (hash));
382 return;
383 }
384
385 session.member = get_member_session_of (member, message, hash);
386
387 if (! session.member)
388 {
390 "Member session from sender of message (%s) unknown!\n",
391 GNUNET_h2s (hash));
392 return;
393 }
394 }
395
396 notify_srv_handle_message (msg_client->handle, room, &session, message,
397 hash, GNUNET_NO);
398}
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_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, GNUNET_MESSENGER_MemberStore::room, 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 402 of file gnunet-service-messenger.c.

404{
405 struct GNUNET_MESSENGER_Client *msg_client = cls;
406
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting message from room: %s\n",
408 GNUNET_h2s (&(msg->key)));
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requested message: %s\n",
410 GNUNET_h2s (&(msg->hash)));
411
413 &(msg->key));
414
415 if (! room)
416 {
417 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Room not found: %s\n", GNUNET_h2s (
418 &(msg->key)));
419 goto end_handling;
420 }
421
422 struct GNUNET_MESSENGER_MemberStore *member_store =
424
425 const struct GNUNET_ShortHashCode *member_id;
426 member_id = get_srv_handle_member_id (msg_client->handle,
427 &(msg->key));
428
429 struct GNUNET_MESSENGER_Member *member = get_store_member (member_store,
430 member_id);
431
432 if (! member)
433 {
435 "Member not valid to request a message! (%s)\n",
436 GNUNET_sh2s (member_id));
437 goto end_handling;
438 }
439
441 msg_client->handle);
442
443 if (! pubkey)
444 {
446 "Handle needs to have a public key to request a message! (%s)\n",
447 GNUNET_sh2s (member_id));
448 goto end_handling;
449 }
450
452 pubkey);
453
454 if (! session)
455 {
457 "Session not valid to request a message! (%s)\n",
458 GNUNET_sh2s (member_id));
459 goto end_handling;
460 }
461
462 request_srv_room_message (room, &(msg->hash), session, callback_found_message,
463 msg_client);
464
465end_handling:
467}
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_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_log, GNUNET_SERVICE_client_continue(), GNUNET_sh2s(), GNUNET_MESSENGER_Client::handle, GNUNET_MESSENGER_MemberSession::member, 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 471 of file gnunet-service-messenger.c.

474{
475 struct GNUNET_MESSENGER_Client *msg_client = GNUNET_new (struct
477
478 msg_client->client = client;
479 msg_client->handle = add_service_handle (messenger, mq);
480
481 return msg_client;
482}
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_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 486 of file gnunet-service-messenger.c.

489{
490 struct GNUNET_MESSENGER_Client *msg_client = internal_cls;
491
493
494 GNUNET_free (msg_client);
495}
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_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 506 of file gnunet-service-messenger.c.

509{
511
512 if (! messenger)
514}
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_SCHEDULER_shutdown(), messenger, and service.

Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

Variable Documentation

◆ messenger