GNUnet 0.22.2
messenger_api.c File Reference
Include dependency graph for messenger_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_RoomFind
 

Functions

const char * GNUNET_MESSENGER_name_of_kind (enum GNUNET_MESSENGER_MessageKind kind)
 Get the name of a message kind. More...
 
static void dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room)
 
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 void handle_room_sync (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
 
static void handle_member_id (void *cls, const struct GNUNET_MESSENGER_MemberMessage *msg)
 
static enum GNUNET_GenericReturnValue check_recv_message (void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg)
 
static void handle_recv_message (void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg)
 
static void handle_miss_message (void *cls, const struct GNUNET_MESSENGER_GetMessage *msg)
 
static void reconnect (struct GNUNET_MESSENGER_Handle *handle)
 
static void send_open_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
 
static void send_enter_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_PeerIdentity *door)
 
static void send_close_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
 
static void send_sync_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
 
static enum GNUNET_GenericReturnValue iterate_reset_room (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static void callback_reconnect (void *cls)
 
static enum GNUNET_GenericReturnValue iterate_close_room (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static void callback_mq_error (void *cls, enum GNUNET_MQ_Error error)
 
struct GNUNET_MESSENGER_HandleGNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, const struct GNUNET_CRYPTO_PrivateKey *key, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls)
 Set up a handle for the messenger related functions and connects to all necessary services. More...
 
void GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle)
 Disconnect all of the messengers used services and clears up its used memory. More...
 
static void callback_leave_message_sent (void *cls)
 
static void keep_subscription_alive (void *cls)
 
static void handle_discourse_subscription (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Message *message)
 
static void send_message_to_room (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PrivateKey *key, struct GNUNET_HashCode *hash)
 
void enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_Message *transcript)
 
static void dequeue_message_from_room (void *cls)
 
const char * GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle)
 Get the name (if specified, otherwise NULL) used by the messenger. More...
 
static enum GNUNET_GenericReturnValue iterate_send_name_to_room (void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)
 
enum GNUNET_GenericReturnValue GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, const char *name)
 Set the name for the messenger handle and sends messages renaming your contact in currently open rooms. More...
 
static const struct GNUNET_CRYPTO_PublicKeyget_non_anonymous_key (const struct GNUNET_CRYPTO_PublicKey *public_key)
 
const struct GNUNET_CRYPTO_PublicKeyGNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle)
 Get the public key used by the messenger or NULL if the anonymous key was used. More...
 
static enum GNUNET_GenericReturnValue iterate_send_key_to_room (void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)
 
enum GNUNET_GenericReturnValue GNUNET_MESSENGER_set_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_CRYPTO_PrivateKey *key)
 Set the private key used by the messenger or NULL if the anonymous key should be used instead. More...
 
struct GNUNET_MESSENGER_RoomGNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
 Open a room to send and receive messages. More...
 
struct GNUNET_MESSENGER_RoomGNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
 Enter a room to send and receive messages through a door opened using GNUNET_MESSENGER_open_room. More...
 
void GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room)
 Close a room which was entered, opened or both in various order and variety. More...
 
static enum GNUNET_GenericReturnValue iterate_find_room (void *cls, const struct GNUNET_HashCode *key, void *value)
 
int GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_MESSENGER_Contact *contact, GNUNET_MESSENGER_MemberCallback callback, void *cls)
 Searches for a specific contact in a given room and calls a selected callback with a given closure for each of them containing the contact as a member. More...
 
const struct GNUNET_HashCodeGNUNET_MESSENGER_room_get_key (const struct GNUNET_MESSENGER_Room *room)
 Get the key of a given room. More...
 
const struct GNUNET_MESSENGER_ContactGNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
 Get the contact of a member in a room which sent a specific message identified with a given hash. More...
 
const struct GNUNET_MESSENGER_ContactGNUNET_MESSENGER_get_recipient (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
 Get the contact of a member in a room which has been targeted as recipient of a specific message identified with a given hash. More...
 
const char * GNUNET_MESSENGER_contact_get_name (const struct GNUNET_MESSENGER_Contact *contact)
 Get the name used by the contact. More...
 
const struct GNUNET_CRYPTO_PublicKeyGNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact)
 Get the public key used by the contact or NULL if the anonymous key was used. More...
 
size_t GNUNET_MESSENGER_contact_get_id (const struct GNUNET_MESSENGER_Contact *contact)
 Get the locally unique id of the contact. More...
 
static void send_message_to_room_with_key (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *public_key)
 
void GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_MESSENGER_Contact *contact)
 Send a message into a room. More...
 
void GNUNET_MESSENGER_delete_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay)
 Delete a message identified by its hash from a room. More...
 
const struct GNUNET_MESSENGER_MessageGNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
 Get the message in a room identified by its hash. More...
 
int GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback, void *cls)
 Iterates through all members of a given room and calls a selected callback for each of them with a provided closure. More...
 

Function Documentation

◆ dequeue_messages_from_room()

static void dequeue_messages_from_room ( struct GNUNET_MESSENGER_Room room)
static

Definition at line 1036 of file messenger_api.c.

1037{
1038 if ((GNUNET_YES != is_room_available (room)) || (!(room->handle)))
1039 return;
1040
1041 if (room->handle->mq)
1043 else if (!(room->queue_task))
1046}
@ GNUNET_SCHEDULER_PRIORITY_HIGH
Run with high priority (important requests).
@ GNUNET_YES
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition: scheduler.c:1231
static void dequeue_message_from_room(void *cls)
enum GNUNET_GenericReturnValue is_room_available(const struct GNUNET_MESSENGER_Room *room)
Checks whether a room is available to send messages.
struct GNUNET_MQ_Handle * mq
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_SCHEDULER_Task * queue_task

References dequeue_message_from_room(), GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_YES, GNUNET_MESSENGER_Room::handle, is_room_available(), GNUNET_MESSENGER_Handle::mq, and GNUNET_MESSENGER_Room::queue_task.

Referenced by enqueue_message_to_room(), handle_room_entry(), handle_room_open(), and handle_room_sync().

Here is the call graph for this function:
Here is the caller 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 messenger_api.c.

102{
104 const struct GNUNET_HashCode *key;
105 const struct GNUNET_HashCode *prev;
106 struct GNUNET_MESSENGER_Room *room;
107
108 GNUNET_assert ((cls) && (msg));
109
110 handle = cls;
111
112 key = &(msg->key);
113 prev = &(msg->previous);
114
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key));
116
118
119 room = get_handle_room (handle, key);
120 if (! room)
121 return;
122
123 update_room_last_message (room, prev);
125}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
#define GNUNET_log(kind,...)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
static void dequeue_messages_from_room(struct GNUNET_MESSENGER_Room *room)
void open_handle_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Marks a room known to a handle identified by a given key as open.
struct GNUNET_MESSENGER_Room * get_handle_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Returns the room known to a handle identified by a given key.
void update_room_last_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
Updates the last message hash of a room for the client API so that new messages can point to the late...
A 512-bit hashcode.

References dequeue_messages_from_room(), get_handle_room(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, handle, key, msg, open_handle_room(), and update_room_last_message().

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 129 of file messenger_api.c.

131{
133 const struct GNUNET_PeerIdentity *door;
134 const struct GNUNET_HashCode *key;
135 const struct GNUNET_HashCode *prev;
136 struct GNUNET_MESSENGER_Room *room;
137
138 GNUNET_assert ((cls) && (msg));
139
140 handle = cls;
141
142 door = &(msg->door);
143 key = &(msg->key);
144 prev = &(msg->previous);
145
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entered room: %s\n", GNUNET_h2s (key));
147
149
150 room = get_handle_room (handle, key);
151 if (! room)
152 return;
153
154 update_room_last_message (room, prev);
156}
void entry_handle_room_at(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Adds a tunnel for a room known to a handle identified by a given key to a list of opened connections.
The identity of the host (wraps the signing key of the peer).

References dequeue_messages_from_room(), entry_handle_room_at(), get_handle_room(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, handle, key, msg, and update_room_last_message().

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 160 of file messenger_api.c.

162{
164 const struct GNUNET_HashCode *key;
165 const struct GNUNET_HashCode *prev;
166 struct GNUNET_MESSENGER_Room *room;
167
168 GNUNET_assert ((cls) && (msg));
169
170 handle = cls;
171
172 key = &(msg->key);
173 prev = &(msg->previous);
174
175 room = get_handle_room (handle, key);
176 if (room)
177 update_room_last_message (room, prev);
178
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Closed room: %s\n", GNUNET_h2s (key));
180
182}
void close_handle_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Destroys and so implicitly closes a room known to a handle identified by a given key.

References close_handle_room(), get_handle_room(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, handle, key, msg, and update_room_last_message().

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 186 of file messenger_api.c.

188{
190 const struct GNUNET_HashCode *key;
191 const struct GNUNET_HashCode *prev;
192 struct GNUNET_MESSENGER_Room *room;
193
194 GNUNET_assert ((cls) && (msg));
195
196 handle = cls;
197
198 key = &(msg->key);
199 prev = &(msg->previous);
200
201 room = get_handle_room (handle, key);
202 if (! room)
203 return;
204
205 update_room_last_message (room, prev);
206
207 room->wait_for_sync = GNUNET_NO;
209}
@ GNUNET_NO
enum GNUNET_GenericReturnValue wait_for_sync

References dequeue_messages_from_room(), get_handle_room(), GNUNET_assert, GNUNET_NO, handle, key, msg, update_room_last_message(), and GNUNET_MESSENGER_Room::wait_for_sync.

Here is the call graph for this function:

◆ handle_member_id()

static void handle_member_id ( void *  cls,
const struct GNUNET_MESSENGER_MemberMessage msg 
)
static

Definition at line 213 of file messenger_api.c.

215{
217 const struct GNUNET_HashCode *key;
218 const struct GNUNET_ShortHashCode *id;
219 struct GNUNET_MESSENGER_Room *room;
220 struct GNUNET_MESSENGER_Message *message;
221 uint32_t reset;
222
223 GNUNET_assert ((cls) && (msg));
224
225 handle = cls;
226
227 key = &(msg->key);
228 id = &(msg->id);
229 reset = msg->reset;
230
231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Changed member id in room: %s\n",
232 GNUNET_h2s (key));
233
234 room = get_handle_room (handle, key);
235 if (! room)
236 {
237 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Room is unknown to handle: %s\n",
238 GNUNET_h2s (key));
239 return;
240 }
241
242 if ((! get_room_sender_id (room)) || (GNUNET_YES == reset))
243 {
244 set_room_sender_id (room, id);
246 }
247 else
248 message = create_message_id (id);
249
250 if (! message)
251 return;
252
253 enqueue_message_to_room (room, message, NULL);
254}
static int reset
Reset argument.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
@ GNUNET_ERROR_TYPE_WARNING
void enqueue_message_to_room(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_Message *transcript)
const struct GNUNET_CRYPTO_PrivateKey * get_handle_key(const struct GNUNET_MESSENGER_Handle *handle)
Returns the private key of a given handle.
struct GNUNET_MESSENGER_Message * create_message_join(const struct GNUNET_CRYPTO_PrivateKey *key)
Creates and allocates a new join message containing the clients public key.
struct GNUNET_MESSENGER_Message * create_message_id(const struct GNUNET_ShortHashCode *unique_id)
Creates and allocates a new id message containing the unique member id to change to.
void set_room_sender_id(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_ShortHashCode *id)
Sets the member id of the room's sender to a specific id or NULL.
const struct GNUNET_ShortHashCode * get_room_sender_id(const struct GNUNET_MESSENGER_Room *room)
Returns the member id of the room's sender.
A 256-bit hashcode.

References create_message_id(), create_message_join(), enqueue_message_to_room(), get_handle_key(), get_handle_room(), get_room_sender_id(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_YES, handle, id, key, msg, reset, and set_room_sender_id().

Here is the call graph for this function:

◆ check_recv_message()

static enum GNUNET_GenericReturnValue check_recv_message ( void *  cls,
const struct GNUNET_MESSENGER_RecvMessage msg 
)
static

Definition at line 258 of file messenger_api.c.

260{
261 struct GNUNET_MESSENGER_Message message;
262 uint16_t full_length, length;
263 const char *buffer;
264
266
267 full_length = ntohs (msg->header.size);
268
269 if (full_length < sizeof(*msg))
270 {
272 "Receiving failed: Message invalid!\n");
273 return GNUNET_NO;
274 }
275
276 length = full_length - sizeof(*msg);
277 buffer = ((const char*) msg) + sizeof(*msg);
278
280 GNUNET_YES))
281 {
283 "Receiving failed: Message too short!\n");
284 return GNUNET_NO;
285 }
286
287 if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL))
288 {
290 "Receiving failed: Message decoding failed!\n");
291 return GNUNET_NO;
292 }
293
294 cleanup_message (&message);
295 return GNUNET_OK;
296}
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
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(), get_message_kind_size(), GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_NO, GNUNET_OK, GNUNET_YES, msg, and GNUNET_MessageHeader::size.

Here is the call graph for this function:

◆ handle_recv_message()

static void handle_recv_message ( void *  cls,
const struct GNUNET_MESSENGER_RecvMessage msg 
)
static

Definition at line 300 of file messenger_api.c.

302{
304 const struct GNUNET_HashCode *key;
305 const struct GNUNET_HashCode *sender;
306 const struct GNUNET_HashCode *context;
307 const struct GNUNET_HashCode *hash;
309 struct GNUNET_MESSENGER_Message message;
310 struct GNUNET_MESSENGER_Room *room;
311 uint16_t length;
312 const char *buffer;
313
314 GNUNET_assert ((cls) && (msg));
315
316 handle = cls;
317
318 key = &(msg->key);
319 sender = &(msg->sender);
320 context = &(msg->context);
321 hash = &(msg->hash);
322
323 flags = (enum GNUNET_MESSENGER_MessageFlags) (msg->flags);
324
325 length = ntohs (msg->header.size) - sizeof(*msg);
326 buffer = ((const char*) msg) + sizeof(*msg);
327
328 decode_message (&message, length, buffer, GNUNET_YES, NULL);
329
330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n",
331 GNUNET_MESSENGER_name_of_kind (message.header.kind));
332
333 room = get_handle_room (handle, key);
334 if (! room)
335 {
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n",
337 GNUNET_h2s (key));
338
339 goto skip_message;
340 }
341
343 "Raw contact from sender and context: (%s : %s)\n",
345
347 sender,
348 context,
349 hash,
350 &message,
351 flags);
352
353skip_message:
354 cleanup_message (&message);
355}
static pa_context * context
Pulseaudio context.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
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_MessageFlags
Enum for the different supported flags used by message handling.
void process_message_control(struct GNUNET_MESSENGER_MessageControl *control, const struct GNUNET_HashCode *sender, const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Message *message, enum GNUNET_MESSENGER_MessageFlags flags)
Processes a new message with its hash and regarding information about sender, context and message fla...
struct GNUNET_MESSENGER_MessageControl * control

References cleanup_message(), context, GNUNET_MESSENGER_Room::control, decode_message(), get_handle_room(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_h2s_full(), GNUNET_log, GNUNET_MESSENGER_name_of_kind(), GNUNET_YES, handle, GNUNET_MESSENGER_Message::header, key, GNUNET_MESSENGER_MessageHeader::kind, msg, process_message_control(), and GNUNET_MessageHeader::size.

Here is the call graph for this function:

◆ handle_miss_message()

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

Definition at line 359 of file messenger_api.c.

361{
363 const struct GNUNET_HashCode *key;
364 const struct GNUNET_HashCode *hash;
365 struct GNUNET_MESSENGER_Room *room;
366
367 GNUNET_assert ((cls) && (msg));
368
369 handle = cls;
370
371 key = &(msg->key);
372 hash = &(msg->hash);
373
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Missing message in room: %s\n",
375 GNUNET_h2s (hash));
376
377 room = get_handle_room (handle, key);
378 if (! room)
379 {
381 "Miss in unknown room for this client: %s\n", GNUNET_h2s (key));
382 return;
383 }
384
385 if (! get_room_sender_id (room))
386 return;
387
388 {
389 struct GNUNET_MESSENGER_Message *message;
390
391 message = create_message_request (hash);
392 if (! message)
393 return;
394
395 enqueue_message_to_room (room, message, NULL);
396 }
397}
struct GNUNET_MESSENGER_Message * create_message_request(const struct GNUNET_HashCode *hash)
Creates and allocates a new request message containing the hash of a missing message.

References create_message_request(), enqueue_message_to_room(), get_handle_room(), get_room_sender_id(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, handle, key, and msg.

Here is the call graph for this function:

◆ reconnect()

static void reconnect ( struct GNUNET_MESSENGER_Handle handle)
static

Definition at line 623 of file messenger_api.c.

624{
626
627 {
628 const struct GNUNET_MQ_MessageHandler handlers[] = {
630 member_id,
633 ),
635 room_open,
638 ),
640 room_entry,
643 ),
645 room_close,
648 ),
653 ),
655 miss_message,
658 ),
660 room_sync,
663 ),
665 };
666
670 handle);
671 }
672}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static enum GNUNET_GenericReturnValue recv_message(void *cls, const struct GNUNET_MessageHeader *msg)
We have received a full message, pass to the MQ dispatcher.
Definition: client.c:335
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1060
#define GNUNET_MESSENGER_SERVICE_NAME
Identifier of GNUnet MESSENGER Service.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY
static void callback_mq_error(void *cls, enum GNUNET_MQ_Error error)
Message to request something from a room.
Message to receive the current member id of a handle in room.
Message to receive something from a room.
General message to confirm interaction with a room.
Message handler for a specific message type.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Definition: vpn_api.c:39
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Definition: vpn_api.c:44

References callback_mq_error(), GNUNET_VPN_Handle::cfg, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID, 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_RECV_MESSAGE, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC, GNUNET_MESSENGER_SERVICE_NAME, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, handle, handlers, GNUNET_VPN_Handle::mq, and recv_message().

Referenced by callback_reconnect(), and GNUNET_MESSENGER_connect().

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

◆ send_open_room()

static void send_open_room ( struct GNUNET_MESSENGER_Handle handle,
struct GNUNET_MESSENGER_Room room 
)
static

Definition at line 404 of file messenger_api.c.

406{
407 const struct GNUNET_CRYPTO_PublicKey *key;
409 struct GNUNET_MQ_Envelope *env;
410 char *msg_buffer;
411 ssize_t len;
412
413 GNUNET_assert ((handle) && (handle->mq) && (room));
414
416
418 "Open room (%s) by member using key: %s\n",
419 GNUNET_h2s (&(room->key)),
421
423
424 env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0,
426 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
427 GNUNET_memcpy (&(msg->previous), &(room->last_message),
428 sizeof(msg->previous));
429
430 msg_buffer = ((char*) msg) + sizeof(*msg);
431
432 if (len > 0)
434
436}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
Definition: crypto_pkey.c:85
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
Definition: crypto_pkey.c:379
ssize_t GNUNET_CRYPTO_write_public_key_to_buffer(const struct GNUNET_CRYPTO_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_PublicKey to a compact buffer.
Definition: crypto_pkey.c:128
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:61
const struct GNUNET_CRYPTO_PublicKey * get_handle_pubkey(const struct GNUNET_MESSENGER_Handle *handle)
Returns the public key of a given handle.
An identity key as per LSD0001.
struct GNUNET_HashCode key
struct GNUNET_HashCode last_message

References env, get_handle_pubkey(), GNUNET_assert, GNUNET_CRYPTO_public_key_get_length(), GNUNET_CRYPTO_public_key_to_string(), GNUNET_CRYPTO_write_public_key_to_buffer(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), handle, key, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_Room::last_message, GNUNET_VPN_Handle::mq, and msg.

Referenced by GNUNET_MESSENGER_open_room(), and iterate_reset_room().

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

◆ send_enter_room()

static void send_enter_room ( struct GNUNET_MESSENGER_Handle handle,
struct GNUNET_MESSENGER_Room room,
const struct GNUNET_PeerIdentity door 
)
static

Definition at line 440 of file messenger_api.c.

443{
444 const struct GNUNET_CRYPTO_PublicKey *key;
446 struct GNUNET_MQ_Envelope *env;
447 char *msg_buffer;
448 ssize_t len;
449
450 GNUNET_assert ((handle) && (handle->mq) && (room) && (door));
451
453
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Enter room (%s) via door: %s (%s)\n",
455 GNUNET_h2s (&(room->key)),
456 GNUNET_i2s (door),
458
460
461 env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0,
463 GNUNET_memcpy (&(msg->door), door, sizeof(*door));
464 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
465 GNUNET_memcpy (&(msg->previous), &(room->last_message),
466 sizeof(msg->previous));
467
468 msg_buffer = ((char*) msg) + sizeof(*msg);
469
470 if (len > 0)
472
474}
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).

References env, get_handle_pubkey(), GNUNET_assert, GNUNET_CRYPTO_public_key_get_length(), GNUNET_CRYPTO_public_key_to_string(), GNUNET_CRYPTO_write_public_key_to_buffer(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), handle, key, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_Room::last_message, GNUNET_VPN_Handle::mq, and msg.

Referenced by GNUNET_MESSENGER_enter_room(), and iterate_reset_room().

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

◆ send_close_room()

static void send_close_room ( struct GNUNET_MESSENGER_Handle handle,
struct GNUNET_MESSENGER_Room room 
)
static

Definition at line 478 of file messenger_api.c.

480{
482 struct GNUNET_MQ_Envelope *env;
483
484 GNUNET_assert ((handle) && (handle->mq) && (room));
485
486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Close room (%s)!\n",
487 GNUNET_h2s (&(room->key)));
488
490
491 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
492 GNUNET_memcpy (&(msg->previous), &(room->last_message),
493 sizeof(msg->previous));
494
496}
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76

References env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, GNUNET_MQ_msg, GNUNET_MQ_send(), handle, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_Room::last_message, GNUNET_VPN_Handle::mq, and msg.

Referenced by callback_leave_message_sent(), and iterate_close_room().

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

◆ send_sync_room()

static void send_sync_room ( struct GNUNET_MESSENGER_Handle handle,
struct GNUNET_MESSENGER_Room room 
)
static

Definition at line 500 of file messenger_api.c.

502{
504 struct GNUNET_MQ_Envelope *env;
505
506 GNUNET_assert ((handle) && (handle->mq) && (room));
507
509
510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sync room (%s)!\n",
511 GNUNET_h2s (&(room->key)));
512
514
515 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
516 GNUNET_memcpy (&(msg->previous), &(room->last_message),
517 sizeof(msg->previous));
518
520}

References 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_YES, handle, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_Room::last_message, GNUNET_VPN_Handle::mq, msg, and GNUNET_MESSENGER_Room::wait_for_sync.

Referenced by enqueue_message_to_room().

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

◆ iterate_reset_room()

static enum GNUNET_GenericReturnValue iterate_reset_room ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 524 of file messenger_api.c.

527{
529 struct GNUNET_MESSENGER_Room *room;
530 struct GNUNET_MESSENGER_ListTunnel *entry;
531
532 GNUNET_assert ((cls) && (value));
533
534 handle = cls;
535 room = value;
536
537 if (GNUNET_YES == room->opened)
538 send_open_room (handle, room);
539
540 entry = room->entries.head;
541 while (entry)
542 {
543 struct GNUNET_PeerIdentity door;
544
545 GNUNET_PEER_resolve (entry->peer, &door);
546 send_enter_room (handle, room, &door);
547
548 entry = entry->next;
549 }
550
551 return GNUNET_YES;
552}
static char * value
Value of the record to add/remove.
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:220
static void send_enter_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_PeerIdentity *door)
static void send_open_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
struct GNUNET_MESSENGER_ListTunnel * next
struct GNUNET_MESSENGER_ListTunnel * head
enum GNUNET_GenericReturnValue opened
struct GNUNET_MESSENGER_ListTunnels entries

References GNUNET_MESSENGER_Room::entries, GNUNET_assert, GNUNET_PEER_resolve(), GNUNET_YES, handle, GNUNET_MESSENGER_ListTunnels::head, GNUNET_MESSENGER_ListTunnel::next, GNUNET_MESSENGER_Room::opened, GNUNET_MESSENGER_ListTunnel::peer, send_enter_room(), send_open_room(), and value.

Referenced by callback_reconnect().

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

◆ callback_reconnect()

static void callback_reconnect ( void *  cls)
static

Definition at line 556 of file messenger_api.c.

557{
559
560 GNUNET_assert (cls);
561
562 handle = cls;
563
564 handle->reconnect_task = NULL;
565 handle->reconnect_time = GNUNET_TIME_STD_BACKOFF (handle->reconnect_time);
566
567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnect messenger!\n");
568
570
572 handle);
573}
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static void reconnect(struct GNUNET_MESSENGER_Handle *handle)
static enum GNUNET_GenericReturnValue iterate_reset_room(void *cls, const struct GNUNET_HashCode *key, void *value)

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_TIME_STD_BACKOFF, handle, iterate_reset_room(), and reconnect().

Referenced by callback_mq_error().

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

◆ iterate_close_room()

static enum GNUNET_GenericReturnValue iterate_close_room ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 577 of file messenger_api.c.

580{
582 struct GNUNET_MESSENGER_Room *room;
583
584 GNUNET_assert ((cls) && (value));
585
586 handle = cls;
587 room = value;
588
589 send_close_room (handle, room);
590
591 return GNUNET_YES;
592}
static void send_close_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)

References GNUNET_assert, GNUNET_YES, handle, send_close_room(), and value.

Referenced by callback_mq_error().

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

◆ callback_mq_error()

static void callback_mq_error ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Definition at line 596 of file messenger_api.c.

598{
600
601 GNUNET_assert (cls);
602
603 handle = cls;
604
605 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MQ_Error: %u\n", error);
606
608 handle);
609
610 if (handle->mq)
611 {
613 handle->mq = NULL;
614 }
615
616 handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_time,
618 handle);
619}
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1277
static void callback_reconnect(void *cls)
static enum GNUNET_GenericReturnValue iterate_close_room(void *cls, const struct GNUNET_HashCode *key, void *value)

References callback_reconnect(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), handle, iterate_close_room(), and GNUNET_VPN_Handle::mq.

Referenced by reconnect().

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

◆ callback_leave_message_sent()

static void callback_leave_message_sent ( void *  cls)
static

Definition at line 733 of file messenger_api.c.

734{
735 struct GNUNET_MESSENGER_Room *room;
736
737 GNUNET_assert (cls);
738
739 room = cls;
740
741 room->opened = GNUNET_NO;
742 clear_list_tunnels (&(room->entries));
743
744 send_close_room (room->handle, room);
745}
void clear_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels)
Clears the list of tunnels peer identities.

References clear_list_tunnels(), GNUNET_MESSENGER_Room::entries, GNUNET_assert, GNUNET_NO, GNUNET_MESSENGER_Room::handle, GNUNET_MESSENGER_Room::opened, and send_close_room().

Referenced by send_message_to_room().

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

◆ keep_subscription_alive()

static void keep_subscription_alive ( void *  cls)
static

Definition at line 749 of file messenger_api.c.

750{
751 struct GNUNET_MESSENGER_RoomSubscription *subscription;
752 struct GNUNET_MESSENGER_Room *room;
753 struct GNUNET_MESSENGER_Message *message;
754 const struct GNUNET_ShortHashCode *discourse;
755
756 GNUNET_assert (cls);
757
758 subscription = cls;
759 subscription->task = NULL;
760
761 room = subscription->room;
762 message = subscription->message;
763
764 subscription->message = NULL;
765
766 discourse = &(message->body.subscribe.discourse);
767
769 discourse,
770 subscription))
771 {
772 destroy_message (message);
773 return;
774 }
775
776 GNUNET_free (subscription);
777
778 enqueue_message_to_room (room, message, NULL);
779}
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from the map.
#define GNUNET_free(ptr)
Wrapper around free.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_MESSENGER_MessageSubscribe subscribe
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscribe.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_SCHEDULER_Task * task
struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_Room * room
struct GNUNET_CONTAINER_MultiShortmap * subscriptions

References GNUNET_MESSENGER_Message::body, destroy_message(), GNUNET_MESSENGER_MessageSubscribe::discourse, enqueue_message_to_room(), GNUNET_assert, GNUNET_CONTAINER_multishortmap_remove(), GNUNET_free, GNUNET_YES, GNUNET_MESSENGER_RoomSubscription::message, GNUNET_MESSENGER_RoomSubscription::room, GNUNET_MESSENGER_MessageBody::subscribe, GNUNET_MESSENGER_Room::subscriptions, and GNUNET_MESSENGER_RoomSubscription::task.

Referenced by handle_discourse_subscription().

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

◆ handle_discourse_subscription()

static void handle_discourse_subscription ( struct GNUNET_MESSENGER_Room room,
struct GNUNET_MESSENGER_Message message 
)
static

Definition at line 783 of file messenger_api.c.

785{
786 const struct GNUNET_ShortHashCode *discourse;
787 struct GNUNET_MESSENGER_RoomSubscription *subscription;
788 struct GNUNET_TIME_Relative time;
789 uint32_t flags;
790
791 GNUNET_assert ((room) && (message));
792
793 flags = message->body.subscribe.flags;
794
795 discourse = &(message->body.subscribe.discourse);
796
798 discourse);
799
801 goto active_subscription;
802
803 if (! subscription)
804 return;
805
806 if (subscription->task)
807 GNUNET_SCHEDULER_cancel (subscription->task);
808
809 if (subscription->message)
810 destroy_message (subscription->message);
811
813 discourse,
814 subscription))
815 {
816 subscription->task = NULL;
817 subscription->message = NULL;
818 return;
819 }
820
821 GNUNET_free (subscription);
822 return;
823
824active_subscription:
826 return;
827
829
830 if (! subscription)
831 {
832 subscription = GNUNET_new (struct GNUNET_MESSENGER_RoomSubscription);
833
835 room->subscriptions, discourse, subscription,
837 {
838 GNUNET_free (subscription);
839 return;
840 }
841
842 subscription->room = room;
843 }
844 else
845 {
846 if (subscription->task)
847 GNUNET_SCHEDULER_cancel (subscription->task);
848
849 if (subscription->message)
850 destroy_message (subscription->message);
851 }
852
853 subscription->message = create_message_subscribe (discourse, time,
854 flags);
855
856 if (! subscription->message)
857 {
858 subscription->task = NULL;
859 return;
860 }
861
862 {
863 struct GNUNET_TIME_Relative delay;
864 delay = GNUNET_TIME_relative_multiply_double (time, 0.9);
865
868 keep_subscription_alive, subscription);
869 }
870}
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
#define GNUNET_new(type)
Allocate a struct or union of the given type.
@ GNUNET_MESSENGER_FLAG_SUBSCRIPTION_KEEP_ALIVE
The keep alive flag.
@ GNUNET_MESSENGER_FLAG_SUBSCRIPTION_UNSUBSCRIBE
The unsubscribe flag.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1207
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:630
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply_double(struct GNUNET_TIME_Relative rel, double factor)
Multiply relative time by a given factor.
Definition: time.c:506
static void keep_subscription_alive(void *cls)
struct GNUNET_MESSENGER_Message * create_message_subscribe(const struct GNUNET_ShortHashCode *discourse, const struct GNUNET_TIME_Relative time, uint32_t flags)
Creates and allocates a new subscribe message for a subscription of a given discourse with a specific...
uint32_t flags
The flags about the subscription to a discourse.
struct GNUNET_TIME_RelativeNBO time
The time window of the subscription.
Time for relative time used by GNUnet, in microseconds.

References GNUNET_MESSENGER_Message::body, create_message_subscribe(), destroy_message(), GNUNET_MESSENGER_MessageSubscribe::discourse, GNUNET_MESSENGER_MessageSubscribe::flags, GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_multishortmap_get(), GNUNET_CONTAINER_multishortmap_put(), GNUNET_CONTAINER_multishortmap_remove(), GNUNET_free, GNUNET_MESSENGER_FLAG_SUBSCRIPTION_KEEP_ALIVE, GNUNET_MESSENGER_FLAG_SUBSCRIPTION_UNSUBSCRIBE, GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_delayed_with_priority(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_TIME_relative_multiply_double(), GNUNET_TIME_relative_ntoh(), GNUNET_YES, keep_subscription_alive(), GNUNET_MESSENGER_RoomSubscription::message, GNUNET_MESSENGER_RoomSubscription::room, GNUNET_MESSENGER_MessageBody::subscribe, GNUNET_MESSENGER_Room::subscriptions, GNUNET_MESSENGER_RoomSubscription::task, and GNUNET_MESSENGER_MessageSubscribe::time.

Referenced by send_message_to_room().

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

◆ send_message_to_room()

static void send_message_to_room ( struct GNUNET_MESSENGER_Room room,
struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_PrivateKey key,
struct GNUNET_HashCode hash 
)
static

Definition at line 874 of file messenger_api.c.

878{
879 const struct GNUNET_ShortHashCode *sender_id;
881 struct GNUNET_MQ_Envelope *env;
882 uint16_t msg_length;
883 char *msg_buffer;
884
885 GNUNET_assert ((room) && (message) && (key) && (hash));
886
887 sender_id = get_room_sender_id (room);
888
891
892 GNUNET_memcpy (&(message->header.sender_id), sender_id,
893 sizeof(message->header.sender_id));
894 GNUNET_memcpy (&(message->header.previous), &(room->last_message),
895 sizeof(message->header.previous));
896
897 message->header.signature.type = key->type;
898
899 msg_length = get_message_size (message, GNUNET_YES);
900
902 msg, msg_length,
904 );
905
906 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
907
908 msg_buffer = ((char*) msg) + sizeof(*msg);
909 encode_message (message, msg_length, msg_buffer, GNUNET_YES);
910
911 hash_message (message, msg_length, msg_buffer, hash);
912 sign_message (message, msg_length, msg_buffer, hash, key);
913
914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send message (%s)!\n",
915 GNUNET_h2s (hash));
916
917 if (! get_message_discourse (message))
918 update_room_last_message (room, hash);
919
920 switch (message->header.kind)
921 {
924 break;
926 handle_discourse_subscription (room, message);
927 break;
928 default:
929 break;
930 }
931
932 GNUNET_MQ_send (room->handle->mq, env);
933}
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBE
The subscribe kind.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:655
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:640
static void callback_leave_message_sent(void *cls)
static void handle_discourse_subscription(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Message *message)
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
Encodes a given message into a buffer of a maximal length in bytes.
void sign_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_PrivateKey *key)
Signs the hash of a message with a given private key and writes the signature into the buffer as well...
const struct GNUNET_ShortHashCode * get_message_discourse(const struct GNUNET_MESSENGER_Message *message)
Returns the discourse hash of a message depending on its kind.
void hash_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer with a length in bytes from a message.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, enum GNUNET_GenericReturnValue include_header)
Returns the exact size in bytes to encode a given message.
uint32_t type
Type of signature.
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_CRYPTO_Signature signature
The signature of the senders private key.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_MESSENGER_MessageHeader header
Header.
Message to send something into a room.

References callback_leave_message_sent(), encode_message(), env, get_message_discourse(), get_message_size(), get_room_sender_id(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_SUBSCRIBE, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_hton(), GNUNET_YES, GNUNET_MESSENGER_Room::handle, handle_discourse_subscription(), hash_message(), GNUNET_MESSENGER_Message::header, key, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_Room::last_message, GNUNET_MESSENGER_Handle::mq, msg, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageHeader::sender_id, sign_message(), GNUNET_MESSENGER_MessageHeader::signature, GNUNET_MESSENGER_MessageHeader::timestamp, GNUNET_CRYPTO_Signature::type, and update_room_last_message().

Referenced by dequeue_message_from_room().

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

◆ enqueue_message_to_room()

void enqueue_message_to_room ( struct GNUNET_MESSENGER_Room room,
struct GNUNET_MESSENGER_Message message,
struct GNUNET_MESSENGER_Message transcript 
)

Definition at line 937 of file messenger_api.c.

940{
941 const struct GNUNET_CRYPTO_PrivateKey *key;
942
943 GNUNET_assert ((room) && (message));
944
945 key = get_handle_key (room->handle);
946
947 enqueue_to_messages (&(room->queue), key, message, transcript);
948
949 if (GNUNET_YES != is_room_available (room))
950 return;
951
952 if (GNUNET_YES == is_message_session_bound (message))
953 send_sync_room (room->handle, room);
954 else if (GNUNET_YES != room->wait_for_sync)
956}
static void send_sync_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
enum GNUNET_GenericReturnValue is_message_session_bound(const struct GNUNET_MESSENGER_Message *message)
Returns if the message should be bound to a member session.
void enqueue_to_messages(struct GNUNET_MESSENGER_QueueMessages *messages, const struct GNUNET_CRYPTO_PrivateKey *sender, struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_Message *transcript)
Adds a specific message to the end or the beginning of the queue depending on its priority.
A private key for an identity as per LSD0001.
struct GNUNET_MESSENGER_QueueMessages queue

References dequeue_messages_from_room(), enqueue_to_messages(), get_handle_key(), GNUNET_assert, GNUNET_YES, GNUNET_MESSENGER_Room::handle, is_message_session_bound(), is_room_available(), key, GNUNET_MESSENGER_Room::queue, send_sync_room(), and GNUNET_MESSENGER_Room::wait_for_sync.

Referenced by delete_room_message(), GNUNET_MESSENGER_close_room(), handle_member_id(), handle_miss_message(), iterate_send_key_to_room(), iterate_send_name_to_room(), keep_subscription_alive(), and send_message_to_room_with_key().

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

◆ dequeue_message_from_room()

static void dequeue_message_from_room ( void *  cls)
static

Definition at line 960 of file messenger_api.c.

961{
962 struct GNUNET_MESSENGER_Room *room;
963 struct GNUNET_MESSENGER_Message *message;
964 struct GNUNET_MESSENGER_Message *transcript;
966 struct GNUNET_HashCode hash;
968
969 GNUNET_assert (cls);
970
971 room = cls;
972
973 GNUNET_assert (room->handle);
974
975 room->queue_task = NULL;
976
977 if ((GNUNET_YES != is_room_available (room)) || (!(room->handle->mq)))
978 goto next_message;
979
980 message = NULL;
981 transcript = NULL;
982 memset (&key, 0, sizeof(key));
983
984 message = dequeue_from_messages (&(room->queue), &key, &transcript);
985
986 if (! message)
987 {
988 if (transcript)
989 destroy_message (transcript);
990
991 return;
992 }
993
994 send_message_to_room (room, message, &key, &hash);
995
996 if (! transcript)
997 {
999 goto next_message;
1000 }
1001
1002 GNUNET_memcpy (&(transcript->body.transcript.hash), &hash, sizeof(hash));
1003
1004 memset (&pubkey, 0, sizeof(pubkey));
1006
1007 if (GNUNET_YES == encrypt_message (transcript, &pubkey))
1008 {
1009 struct GNUNET_HashCode other;
1010 send_message_to_room (room, transcript, &key, &other);
1011
1013
1014 link_room_message (room, &hash, &other);
1015 link_room_message (room, &other, &hash);
1016 }
1017 else
1018 {
1020
1022 "Sending transcript aborted: Encryption failed!\n");
1023 }
1024
1025 destroy_message (transcript);
1026
1028 if (! room->queue.head)
1029 return;
1030
1033}
static struct GNUNET_CRYPTO_PublicKey pubkey
Public key of the zone to look in.
static struct GNUNET_NSE_FloodMessage next_message
Message for the next round, if we got any.
void GNUNET_CRYPTO_private_key_clear(struct GNUNET_CRYPTO_PrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_pkey.c:47
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public(const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: crypto_pkey.c:430
static void send_message_to_room(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PrivateKey *key, struct GNUNET_HashCode *hash)
enum GNUNET_GenericReturnValue encrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
Encrypts a message using a given public key and replaces its body and kind with the now private encry...
struct GNUNET_MESSENGER_Message * dequeue_from_messages(struct GNUNET_MESSENGER_QueueMessages *messages, struct GNUNET_CRYPTO_PrivateKey *sender, struct GNUNET_MESSENGER_Message **transcript)
Remove the message from the front of the queue and returns it.
void link_room_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash, const struct GNUNET_HashCode *other)
Links a message identified by its hash inside a given room with another message identified by its oth...
struct GNUNET_MESSENGER_MessageTranscript transcript
struct GNUNET_HashCode hash
The hash of the original message.
struct GNUNET_MESSENGER_QueueMessage * head

References GNUNET_MESSENGER_Message::body, dequeue_from_messages(), dequeue_message_from_room(), destroy_message(), encrypt_message(), GNUNET_assert, GNUNET_CRYPTO_key_get_public(), GNUNET_CRYPTO_private_key_clear(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_memcpy, GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_YES, GNUNET_MESSENGER_Room::handle, GNUNET_MESSENGER_MessageTranscript::hash, GNUNET_MESSENGER_QueueMessages::head, is_room_available(), key, link_room_message(), GNUNET_MESSENGER_Handle::mq, next_message, pubkey, GNUNET_MESSENGER_Room::queue, GNUNET_MESSENGER_Room::queue_task, send_message_to_room(), and GNUNET_MESSENGER_MessageBody::transcript.

Referenced by dequeue_message_from_room(), and dequeue_messages_from_room().

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

◆ iterate_send_name_to_room()

static enum GNUNET_GenericReturnValue iterate_send_name_to_room ( void *  cls,
struct GNUNET_MESSENGER_Room room,
const struct GNUNET_MESSENGER_Contact contact 
)
static

Definition at line 1060 of file messenger_api.c.

1063{
1064 const struct GNUNET_MESSENGER_Handle *handle;
1065 struct GNUNET_MESSENGER_Message *message;
1066 const char *name;
1067
1068 GNUNET_assert ((cls) && (room));
1069
1070 handle = cls;
1071
1072 if (GNUNET_YES != room->use_handle_name)
1073 return GNUNET_YES;
1074
1076 if (! name)
1077 return GNUNET_YES;
1078
1079 message = create_message_name (name);
1080 if (! message)
1081 return GNUNET_NO;
1082
1083 enqueue_message_to_room (room, message, NULL);
1084 return GNUNET_YES;
1085}
static char * name
Name (label) of the records to list.
const char * get_handle_name(const struct GNUNET_MESSENGER_Handle *handle)
Returns the current name of a given handle or NULL if no valid name was assigned yet.
struct GNUNET_MESSENGER_Message * create_message_name(const char *name)
Creates and allocates a new name message containing the name to change to.
enum GNUNET_GenericReturnValue use_handle_name

References create_message_name(), enqueue_message_to_room(), get_handle_name(), GNUNET_assert, GNUNET_NO, GNUNET_YES, handle, name, and GNUNET_MESSENGER_Room::use_handle_name.

Referenced by GNUNET_MESSENGER_set_name().

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

◆ get_non_anonymous_key()

static const struct GNUNET_CRYPTO_PublicKey * get_non_anonymous_key ( const struct GNUNET_CRYPTO_PublicKey public_key)
static

Definition at line 1102 of file messenger_api.c.

1103{
1104 if (0 == GNUNET_memcmp (public_key, get_anonymous_public_key ()))
1105 return NULL;
1106
1107 return public_key;
1108}
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
const struct GNUNET_CRYPTO_PublicKey * get_anonymous_public_key(void)
Returns the public identity key of GNUNET_IDENTITY_ego_get_anonymous() without recalculating it every...

References get_anonymous_public_key(), and GNUNET_memcmp.

Referenced by GNUNET_MESSENGER_contact_get_key(), GNUNET_MESSENGER_get_key(), and GNUNET_MESSENGER_send_message().

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

◆ iterate_send_key_to_room()

static enum GNUNET_GenericReturnValue iterate_send_key_to_room ( void *  cls,
struct GNUNET_MESSENGER_Room room,
const struct GNUNET_MESSENGER_Contact contact 
)
static

Definition at line 1122 of file messenger_api.c.

1125{
1126 const struct GNUNET_CRYPTO_PrivateKey *key;
1127 struct GNUNET_MESSENGER_Message *message;
1128
1129 GNUNET_assert ((cls) && (room));
1130
1131 key = cls;
1132
1133 message = create_message_key (key);
1134 if (! message)
1135 return GNUNET_NO;
1136
1137 enqueue_message_to_room (room, message, NULL);
1138 return GNUNET_YES;
1139}
struct GNUNET_MESSENGER_Message * create_message_key(const struct GNUNET_CRYPTO_PrivateKey *key)
Creates and allocates a new key message containing the public key to change to derived from its priva...

References create_message_key(), enqueue_message_to_room(), GNUNET_assert, GNUNET_NO, GNUNET_YES, and key.

Referenced by GNUNET_MESSENGER_set_key().

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

◆ iterate_find_room()

static enum GNUNET_GenericReturnValue iterate_find_room ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 1255 of file messenger_api.c.

1258{
1259 struct GNUNET_MESSENGER_RoomFind *find;
1260 struct GNUNET_MESSENGER_Room *room;
1261
1262 GNUNET_assert ((cls) && (value));
1263
1264 find = cls;
1265 room = value;
1266
1267 if ((find->counter > 0) && ((! find->contact) || (GNUNET_YES ==
1268 find_room_member (room,
1269 find->
1270 contact)))
1271 )
1272 {
1273 find->counter--;
1274
1275 if (! find->callback)
1276 return GNUNET_YES;
1277
1278 return find->callback (find->cls, room, find->contact);
1279 }
1280 else
1281 return GNUNET_NO;
1282}
enum GNUNET_GenericReturnValue find_room_member(const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)
Checks through all members of a given room if a specific contact is found and returns a result depend...
GNUNET_MESSENGER_MemberCallback callback
const struct GNUNET_MESSENGER_Contact * contact

References GNUNET_MESSENGER_RoomFind::callback, GNUNET_MESSENGER_RoomFind::cls, GNUNET_MESSENGER_RoomFind::contact, GNUNET_MESSENGER_RoomFind::counter, find_room_member(), GNUNET_assert, GNUNET_NO, GNUNET_YES, and value.

Referenced by GNUNET_MESSENGER_find_rooms().

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

◆ send_message_to_room_with_key()

static void send_message_to_room_with_key ( struct GNUNET_MESSENGER_Room room,
struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_PublicKey public_key 
)
static

Definition at line 1372 of file messenger_api.c.

1375{
1376 struct GNUNET_MESSENGER_Message *transcript;
1377 const struct GNUNET_CRYPTO_PublicKey *pubkey;
1378 const char *handle_name;
1379 char *original_name;
1380
1381 transcript = NULL;
1382
1383 if (GNUNET_MESSENGER_KIND_NAME != message->header.kind)
1384 goto skip_naming;
1385
1386 original_name = message->body.name.name;
1388 "Apply rule for using handle name in room: %s\n", GNUNET_h2s (
1389 &(room->key)));
1390
1391 handle_name = get_handle_name (room->handle);
1392
1393 if ((handle_name) && (GNUNET_YES == room->use_handle_name) &&
1394 ((! original_name) || (0 == strlen (original_name))))
1395 {
1396 if (original_name)
1397 GNUNET_free (original_name);
1398
1399 message->body.name.name = GNUNET_strdup (handle_name);
1400 }
1401
1402skip_naming:
1403 if (! public_key)
1404 goto skip_encryption;
1405
1407
1408 if (0 != GNUNET_memcmp (pubkey, public_key))
1409 transcript = transcribe_message (message, public_key);
1410
1411 if (GNUNET_YES != encrypt_message (message, public_key))
1412 {
1414 "Sending message aborted: Encryption failed!\n");
1415
1416 if (transcript)
1417 destroy_message (transcript);
1418
1419 destroy_message (message);
1420 return;
1421 }
1422
1423skip_encryption:
1424 enqueue_message_to_room (room, message, transcript);
1425}
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
struct GNUNET_MESSENGER_Message * transcribe_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
Transcribes a message as a new transcript message using a given public key from the recipient of the ...
struct GNUNET_MESSENGER_MessageName name
char * name
The new name which replaces the current senders name.

References GNUNET_MESSENGER_Message::body, destroy_message(), encrypt_message(), enqueue_message_to_room(), get_handle_name(), get_handle_pubkey(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_memcmp, GNUNET_MESSENGER_KIND_NAME, GNUNET_strdup, GNUNET_YES, GNUNET_MESSENGER_Room::handle, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, pubkey, transcribe_message(), and GNUNET_MESSENGER_Room::use_handle_name.

Referenced by GNUNET_MESSENGER_send_message().

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