GNUnet 0.28.0-dev.3-20-gf1136b0b8
 
Loading...
Searching...
No Matches
messenger_api_queue_messages.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2023--2024, 2026 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
27
29#include "gnunet_util_lib.h"
31
32void
34{
35 GNUNET_assert (messages);
36
37 messages->head = NULL;
38 messages->tail = NULL;
39}
40
41
42void
44{
45 GNUNET_assert (messages);
46
47 while (messages->head)
48 {
49 struct GNUNET_MESSENGER_QueueMessage *element;
50 element = messages->head;
51
52 GNUNET_CONTAINER_DLL_remove (messages->head, messages->tail, element);
53
54 if (element->message)
55 destroy_message (element->message);
56
57 if (element->transcript)
58 destroy_message (element->transcript);
59
60 GNUNET_free (element);
61 }
62
63 messages->head = NULL;
64 messages->tail = NULL;
65}
66
67
68void
72 const struct GNUNET_HashCode *epoch,
75{
76 struct GNUNET_MESSENGER_QueueMessage *element;
78
80 (messages) && (sender) && (transcript_key) && (epoch) &&
81 (message));
82
84 if (! element)
85 return;
86
87 kind = message->header.kind;
88
89 element->message = message;
90 element->transcript = transcript;
91
92 GNUNET_memcpy (&(element->sender), sender, sizeof (element->sender));
94 sizeof (element->transcript_key));
95 GNUNET_memcpy (&(element->epoch), epoch, sizeof (element->epoch));
96
98 GNUNET_CONTAINER_DLL_insert (messages->head, messages->tail, element);
100 {
101 struct GNUNET_MESSENGER_QueueMessage *other;
102
103 other = messages->head;
104 while (other)
105 {
107 break;
108
109 other = other->next;
110 }
111
112 GNUNET_CONTAINER_DLL_insert_before (messages->head, messages->tail, other,
113 element);
114 }
115 else
116 GNUNET_CONTAINER_DLL_insert_tail (messages->head, messages->tail, element);
117}
118
119
123 struct GNUNET_CRYPTO_HpkePublicKey *transcript_key,
124 struct GNUNET_HashCode *epoch,
125 struct GNUNET_MESSENGER_Message **transcript)
126{
127 struct GNUNET_MESSENGER_QueueMessage *element;
128 struct GNUNET_MESSENGER_Message *message;
129
130 GNUNET_assert (messages);
131
132 element = messages->head;
133 if (! element)
134 {
135 if (transcript)
136 *transcript = NULL;
137
138 return NULL;
139 }
140
141 message = element->message;
142
143 if (transcript)
144 *transcript = element->transcript;
145 else if (element->transcript)
146 destroy_message (element->transcript);
147
148 GNUNET_CONTAINER_DLL_remove (messages->head, messages->tail, element);
149
150 if (sender)
151 GNUNET_memcpy (sender, &(element->sender), sizeof (*sender));
152
153 if (transcript_key)
154 GNUNET_memcpy (transcript_key, &(element->transcript_key),
155 sizeof (*transcript_key));
156
157 if (epoch)
158 GNUNET_memcpy (epoch, &(element->epoch), sizeof (*epoch));
159
160 GNUNET_free (element);
161 return message;
162}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#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_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
@ GNUNET_MESSENGER_KIND_TALK
The talk kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBTION
The subscription kind.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
void enqueue_to_messages(struct GNUNET_MESSENGER_QueueMessages *messages, const struct GNUNET_CRYPTO_BlindablePrivateKey *sender, const struct GNUNET_CRYPTO_HpkePublicKey *transcript_key, const struct GNUNET_HashCode *epoch, struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_Message *transcript)
Adds a specific message to the end or the beginning of the queue.
void init_queue_messages(struct GNUNET_MESSENGER_QueueMessages *messages)
Initializes queue of messages as empty queue.
void clear_queue_messages(struct GNUNET_MESSENGER_QueueMessages *messages)
Clears the queue of messages.
struct GNUNET_MESSENGER_Message * dequeue_from_messages(struct GNUNET_MESSENGER_QueueMessages *messages, struct GNUNET_CRYPTO_BlindablePrivateKey *sender, struct GNUNET_CRYPTO_HpkePublicKey *transcript_key, struct GNUNET_HashCode *epoch, struct GNUNET_MESSENGER_Message **transcript)
Remove the message from the front of the queue and returns it.
A private key for an identity as per LSD0001.
A public key used for encryption.
A 512-bit hashcode.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_Message * message
struct GNUNET_CRYPTO_HpkePublicKey transcript_key
struct GNUNET_CRYPTO_BlindablePrivateKey sender
struct GNUNET_MESSENGER_Message * transcript
struct GNUNET_MESSENGER_QueueMessage * next
struct GNUNET_MESSENGER_QueueMessage * tail
struct GNUNET_MESSENGER_QueueMessage * head