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

Go to the source code of this file.

Functions

void init_queue_messages (struct GNUNET_MESSENGER_QueueMessages *messages)
 Initializes queue of messages as empty queue. More...
 
void clear_queue_messages (struct GNUNET_MESSENGER_QueueMessages *messages)
 Clears the queue of messages. More...
 
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. More...
 
struct GNUNET_MESSENGER_Messagedequeue_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. More...
 

Function Documentation

◆ init_queue_messages()

void init_queue_messages ( struct GNUNET_MESSENGER_QueueMessages messages)

Initializes queue of messages as empty queue.

Parameters
[out]messagesQueue of messages

Definition at line 32 of file messenger_api_queue_messages.c.

33{
34 GNUNET_assert (messages);
35
36 messages->head = NULL;
37 messages->tail = NULL;
38}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_QueueMessage * tail
struct GNUNET_MESSENGER_QueueMessage * head

References GNUNET_assert, GNUNET_MESSENGER_QueueMessages::head, and GNUNET_MESSENGER_QueueMessages::tail.

Referenced by create_room().

Here is the caller graph for this function:

◆ clear_queue_messages()

void clear_queue_messages ( struct GNUNET_MESSENGER_QueueMessages messages)

Clears the queue of messages.

Parameters
[in,out]messagesQueue of messages

Definition at line 42 of file messenger_api_queue_messages.c.

43{
44 GNUNET_assert (messages);
45
46 while (messages->head)
47 {
48 struct GNUNET_MESSENGER_QueueMessage *element;
49 element = messages->head;
50
51 GNUNET_CONTAINER_DLL_remove (messages->head, messages->tail, element);
52
53 if (element->message)
54 destroy_message (element->message);
55
56 if (element->transcript)
57 destroy_message (element->transcript);
58
59 GNUNET_free (element);
60 }
61
62 messages->head = NULL;
63 messages->tail = NULL;
64}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#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_Message * message
struct GNUNET_MESSENGER_Message * transcript

References destroy_message(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MESSENGER_QueueMessages::head, GNUNET_MESSENGER_QueueMessage::message, GNUNET_MESSENGER_QueueMessages::tail, and GNUNET_MESSENGER_QueueMessage::transcript.

Referenced by destroy_room().

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

◆ enqueue_to_messages()

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.

Parameters
[in,out]messagesQueue of messages
[in]senderPrivate sender key
[in]messageMessage
[in]transcriptMessage transcript

Definition at line 68 of file messenger_api_queue_messages.c.

72{
73 struct GNUNET_MESSENGER_QueueMessage *element;
75
76 GNUNET_assert ((messages) && (sender) && (message));
77
79 if (! element)
80 return;
81
82 kind = message->header.kind;
83
84 element->message = message;
85 element->transcript = transcript;
86
87 GNUNET_memcpy (&(element->sender), sender, sizeof (element->sender));
88
89 if (! element->message)
90 {
91 if (element->transcript)
92 destroy_message (element->transcript);
93
94 GNUNET_free (element);
95 return;
96 }
97
99 GNUNET_CONTAINER_DLL_insert (messages->head, messages->tail, element);
100 else if (GNUNET_MESSENGER_KIND_SUBSCRIBE == kind)
101 {
102 struct GNUNET_MESSENGER_QueueMessage *other;
103
104 other = messages->head;
105 while (other)
106 {
108 break;
109
110 other = other->next;
111 }
112
113 GNUNET_CONTAINER_DLL_insert_before (messages->head, messages->tail, other, element);
114 }
115 else
116 GNUNET_CONTAINER_DLL_insert_tail (messages->head, messages->tail, element);
117}
#define GNUNET_CONTAINER_DLL_insert_before(head, tail, other, element)
Insert an element into a DLL before the given other element.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
@ GNUNET_MESSENGER_KIND_SUBSCRIBE
The subscribe kind.
@ GNUNET_MESSENGER_KIND_TALK
The talk kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_CRYPTO_PrivateKey sender
struct GNUNET_MESSENGER_QueueMessage * next

References destroy_message(), GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_insert_before, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_free, GNUNET_memcpy, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_SUBSCRIBE, GNUNET_MESSENGER_KIND_TALK, GNUNET_new, GNUNET_MESSENGER_QueueMessages::head, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_QueueMessage::message, GNUNET_MESSENGER_QueueMessage::next, GNUNET_MESSENGER_QueueMessage::sender, GNUNET_MESSENGER_QueueMessages::tail, and GNUNET_MESSENGER_QueueMessage::transcript.

Referenced by enqueue_message_to_room().

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

◆ dequeue_from_messages()

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.

Parameters
[in,out]messagesQueue of messages
[out]senderPrivate sender key
[out]transcriptMessage transcript
Returns
Message from front or NULL

Definition at line 121 of file messenger_api_queue_messages.c.

124{
125 struct GNUNET_MESSENGER_QueueMessage *element;
126 struct GNUNET_MESSENGER_Message *message;
127
128 GNUNET_assert (messages);
129
130 element = messages->head;
131 if (! element)
132 {
133 if (transcript)
134 *transcript = NULL;
135
136 return NULL;
137 }
138
139 message = element->message;
140
141 if (transcript)
142 *transcript = element->transcript;
143 else if (element->transcript)
144 destroy_message (element->transcript);
145
146 GNUNET_CONTAINER_DLL_remove (messages->head, messages->tail, element);
147
148 if (sender)
149 GNUNET_memcpy (sender, &(element->sender), sizeof (*sender));
150
151 GNUNET_free (element);
152 return message;
153}

References destroy_message(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_memcpy, GNUNET_MESSENGER_QueueMessages::head, GNUNET_MESSENGER_QueueMessage::message, GNUNET_MESSENGER_QueueMessage::sender, GNUNET_MESSENGER_QueueMessages::tail, and GNUNET_MESSENGER_QueueMessage::transcript.

Referenced by dequeue_message_from_room().

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