GNUnet 0.21.2
messenger_api_message_control.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2024 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
28#include "gnunet_common.h"
35#include "messenger_api_room.h"
36
39{
41
42 struct GNUNET_MESSENGER_MessageControl *control;
43
45 control->room = room;
46
49 GNUNET_NO);
50
51 control->head = NULL;
52 control->tail = NULL;
53
54 return control;
55}
56
57
58void
60{
61 GNUNET_assert (control);
62
64 while (control->head)
65 {
67
68 if (queue->task)
70
71 destroy_message (queue->message);
72
75 }
76
79
81}
82
83
84static void
86 const struct GNUNET_HashCode *sender,
87 const struct GNUNET_HashCode *context,
88 const struct GNUNET_HashCode *hash,
91{
92 GNUNET_assert ((control) && (sender) && (context) && (hash) && (message));
93
95 if (GNUNET_YES == is_peer_message (message))
96 map = control->peer_messages;
97 else
98 map = control->member_messages;
99
101
103 queue->control = control;
104
105 GNUNET_memcpy (&(queue->sender), sender, sizeof (queue->sender));
106 GNUNET_memcpy (&(queue->context), context, sizeof (queue->context));
107 GNUNET_memcpy (&(queue->hash), hash, sizeof (queue->hash));
108
109 queue->message = copy_message (message);
110 queue->flags = flags;
111 queue->task = NULL;
112
114
117 queue,
119}
120
121
122static void
124 struct GNUNET_MESSENGER_Contact *contact,
125 const struct GNUNET_HashCode *hash,
126 const struct GNUNET_MESSENGER_Message *message,
128{
129 GNUNET_assert ((control) && (hash) && (message));
130
132
136
138}
139
140
141static void
143{
144 GNUNET_assert (cls);
145
147 struct GNUNET_MESSENGER_MessageControl *control = queue->control;
148
149 queue->task = NULL;
150
153 handle);
154
156 store, &(queue->context), &(queue->sender));
157
159 if (GNUNET_YES == is_peer_message (queue->message))
160 map = control->peer_messages;
161 else
162 map = control->member_messages;
163
165 &(queue->message->header.sender_id),
166 queue);
167
168 GNUNET_CONTAINER_DLL_remove (control->head, control->tail, queue);
169
170 handle_message_control (control,
171 contact,
172 &(queue->hash),
173 queue->message,
174 queue->flags);
175
176 destroy_message (queue->message);
177
179}
180
181
184 const struct GNUNET_ShortHashCode *key,
185 void *value)
186{
187 GNUNET_assert ((key) && (value));
188
190
191 if (queue->task)
192 return GNUNET_YES;
193
195 return GNUNET_YES;
196}
197
198
199void
201 const struct GNUNET_HashCode *sender,
202 const struct GNUNET_HashCode *context,
203 const struct GNUNET_HashCode *hash,
204 const struct GNUNET_MESSENGER_Message *message,
206{
207 GNUNET_assert ((control) && (sender) && (context) && (hash) && (message));
208
211 handle);
212
214 store, context, sender);
215
216 if ((! contact) &&
217 (GNUNET_MESSENGER_KIND_JOIN != message->header.kind) &&
219 enqueue_message_control (control, sender, context, hash, message, flags);
220 else
221 handle_message_control (control, contact, hash, message, flags);
222
223 struct GNUNET_CONTAINER_MultiShortmap *map = NULL;
224 const struct GNUNET_ShortHashCode *id = &(message->header.sender_id);
225
226 if (GNUNET_YES == is_peer_message (message))
227 map = control->peer_messages;
228
229 switch (message->header.kind)
230 {
232 map = control->member_messages;
233 break;
235 map = control->peer_messages;
236 break;
238 map = control->member_messages;
239 id = &(message->body.id.id);
240 break;
241 default:
242 break;
243 }
244
245 if (! map)
246 return;
247
249 id,
251 NULL);
252}
struct GNUNET_HashCode key
The key used in the DHT.
static pa_context * context
Pulseaudio context.
static char * value
Value of the record to add/remove.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
API to schedule computations using continuation passing style.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
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_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multishortmap_get_multiple(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_YES
@ GNUNET_NO
#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_MessageFlags
Enum for the different supported flags used by message handling.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
@ GNUNET_MESSENGER_FLAG_RECENT
The recent flag.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1305
struct GNUNET_MESSENGER_Contact * get_store_contact_raw(struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *key_hash)
Returns a contact using the hash of a specific public key.
struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store(struct GNUNET_MESSENGER_Handle *handle)
Returns the used contact store of a given handle.
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given 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...
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 destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
static enum GNUNET_GenericReturnValue iterate_message_control(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
struct GNUNET_MESSENGER_MessageControl * create_message_control(struct GNUNET_MESSENGER_Room *room)
Creates and allocates a new message control for a room of the client API.
void destroy_message_control(struct GNUNET_MESSENGER_MessageControl *control)
Destroys a message control and frees its memory fully from the client API.
static void enqueue_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)
static void handle_message_control(struct GNUNET_MESSENGER_MessageControl *control, struct GNUNET_MESSENGER_Contact *contact, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Message *message, enum GNUNET_MESSENGER_MessageFlags flags)
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...
static void task_message_control(void *cls)
void handle_room_message(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_MessageFlags flags)
Handles a message with a given hash in a room for the client API to update members and its informatio...
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...
void callback_room_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
Executes the message callback for a given hash in a room.
struct GNUNET_MESSENGER_Handle * get_room_handle(struct GNUNET_MESSENGER_Room *room)
Returns the messenger handle of the room.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:63
Internal representation of the hash map.
A 512-bit hashcode.
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_MessageControl * control
enum GNUNET_MESSENGER_MessageFlags flags
struct GNUNET_CONTAINER_MultiShortmap * member_messages
struct GNUNET_MESSENGER_MessageControlQueue * head
struct GNUNET_CONTAINER_MultiShortmap * peer_messages
struct GNUNET_MESSENGER_MessageControlQueue * tail
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
A 256-bit hashcode.