GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
messenger_api_message_control.c File Reference
Include dependency graph for messenger_api_message_control.c:

Go to the source code of this file.

Functions

struct GNUNET_MESSENGER_MessageControlcreate_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_HashCode *epoch, 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_HashCode *epoch, const struct GNUNET_MESSENGER_Message *message, enum GNUNET_MESSENGER_MessageFlags flags)
 
static void task_message_control (void *cls)
 
static enum GNUNET_GenericReturnValue iterate_message_control (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
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_HashCode *epoch, 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 flags using a selected message control.
 

Function Documentation

◆ create_message_control()

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.

Parameters
[in,out]roomRoom
Returns
New message control

Definition at line 38 of file messenger_api_message_control.c.

39{
40 struct GNUNET_MESSENGER_MessageControl *control;
41
43
45 control->room = room;
46
49 GNUNET_NO);
50
51 control->head = NULL;
52 control->tail = NULL;
53
54 return control;
55}
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).
@ 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.
struct GNUNET_CONTAINER_MultiShortmap * member_messages
struct GNUNET_MESSENGER_MessageControlQueue * head
struct GNUNET_CONTAINER_MultiShortmap * peer_messages
struct GNUNET_MESSENGER_MessageControlQueue * tail

References GNUNET_assert, GNUNET_CONTAINER_multishortmap_create(), GNUNET_new, GNUNET_NO, GNUNET_MESSENGER_MessageControl::head, GNUNET_MESSENGER_MessageControl::member_messages, GNUNET_MESSENGER_MessageControl::peer_messages, GNUNET_MESSENGER_MessageControl::room, and GNUNET_MESSENGER_MessageControl::tail.

Referenced by create_room().

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

◆ destroy_message_control()

void destroy_message_control ( struct GNUNET_MESSENGER_MessageControl control)

Destroys a message control and frees its memory fully from the client API.

Parameters
[in,out]controlMessage control

Definition at line 59 of file messenger_api_message_control.c.

60{
61 GNUNET_assert (control);
62
63 while (control->head)
64 {
67
68 if (queue->task)
70
71 destroy_message (queue->message);
72
75 }
76
79
81}
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash map.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_MESSENGER_MessageControl * control

References GNUNET_MESSENGER_MessageControlQueue::control, destroy_message(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_MESSENGER_MessageControl::head, GNUNET_MESSENGER_MessageControl::member_messages, GNUNET_MESSENGER_MessageControl::peer_messages, queue(), and GNUNET_MESSENGER_MessageControl::tail.

Referenced by destroy_room().

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

◆ enqueue_message_control()

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_HashCode epoch,
const struct GNUNET_MESSENGER_Message message,
enum GNUNET_MESSENGER_MessageFlags  flags 
)
static

Definition at line 85 of file messenger_api_message_control.c.

92{
95
96 GNUNET_assert ((control) && (sender) && (context) && (hash) && (message));
97
100 else
102
104 queue->control = control;
105
106 GNUNET_memcpy (&(queue->sender), sender, sizeof (queue->sender));
107 GNUNET_memcpy (&(queue->context), context, sizeof (queue->context));
108 GNUNET_memcpy (&(queue->hash), hash, sizeof (queue->hash));
109 GNUNET_memcpy (&(queue->epoch), epoch, sizeof (queue->epoch));
110
111 queue->message = copy_message (message);
112 queue->flags = flags;
113 queue->task = NULL;
114
116
119 queue,
121}
static pa_context * context
Pulseaudio context.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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.
@ 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_YES
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...
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.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_MESSENGER_MessageHeader header
Header.

References context, GNUNET_MESSENGER_MessageControlQueue::control, copy_message(), GNUNET_MESSENGER_MessageControlQueue::epoch, GNUNET_MESSENGER_MessageControlQueue::flags, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multishortmap_put(), GNUNET_memcpy, GNUNET_new, GNUNET_YES, GNUNET_MESSENGER_MessageControlQueue::hash, GNUNET_MESSENGER_MessageControl::head, GNUNET_MESSENGER_Message::header, is_peer_message(), map, GNUNET_MESSENGER_MessageControl::member_messages, GNUNET_MESSENGER_MessageControlQueue::message, GNUNET_MESSENGER_MessageControl::peer_messages, queue(), GNUNET_MESSENGER_MessageControlQueue::sender, GNUNET_MESSENGER_MessageHeader::sender_id, and GNUNET_MESSENGER_MessageControl::tail.

Referenced by process_message_control().

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

◆ handle_message_control()

static void handle_message_control ( struct GNUNET_MESSENGER_MessageControl control,
struct GNUNET_MESSENGER_Contact contact,
const struct GNUNET_HashCode hash,
const struct GNUNET_HashCode epoch,
const struct GNUNET_MESSENGER_Message message,
enum GNUNET_MESSENGER_MessageFlags  flags 
)
static

Definition at line 125 of file messenger_api_message_control.c.

131{
132 GNUNET_assert ((control) && (hash) && (message));
133
134 handle_room_message (control->room, contact, message, hash, epoch, flags);
135
136 if ((flags & GNUNET_MESSENGER_FLAG_RECENT) &&
137 (! get_message_discourse (message)))
138 update_room_last_message (control->room, hash, epoch);
139
140 callback_room_message (control->room, hash);
141}
@ GNUNET_MESSENGER_FLAG_RECENT
The recent flag.
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 handle_room_message(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_HashCode *epoch, 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, const struct GNUNET_HashCode *epoch)
Updates the last message hash and its epoch of a room for the client API so that new messages can poi...
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.

References callback_room_message(), GNUNET_MESSENGER_MessageControlQueue::control, GNUNET_MESSENGER_MessageControlQueue::epoch, GNUNET_MESSENGER_MessageControlQueue::flags, get_message_discourse(), GNUNET_assert, GNUNET_MESSENGER_FLAG_RECENT, handle_room_message(), GNUNET_MESSENGER_MessageControlQueue::hash, GNUNET_MESSENGER_MessageControlQueue::message, GNUNET_MESSENGER_MessageControl::room, and update_room_last_message().

Referenced by process_message_control(), and task_message_control().

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

◆ task_message_control()

static void task_message_control ( void *  cls)
static

Definition at line 145 of file messenger_api_message_control.c.

146{
148 struct GNUNET_MESSENGER_MessageControl *control;
149 struct GNUNET_MESSENGER_Contact *contact;
151
152 GNUNET_assert (cls);
153
154 queue = cls;
155 control = queue->control;
156
157 queue->task = NULL;
158
159 {
161 struct GNUNET_MESSENGER_ContactStore *store;
162
163 handle = get_room_handle (control->room);
165
166 contact = get_store_contact_raw (
167 store, &(queue->context), &(queue->sender));
168 }
169
170 if (GNUNET_YES == is_peer_message (queue->message))
171 map = control->peer_messages;
172 else
173 map = control->member_messages;
174
176 &(queue->message->header.sender_id),
177 queue);
178
179 GNUNET_CONTAINER_DLL_remove (control->head, control->tail, queue);
180
181 handle_message_control (control,
182 contact,
183 &(queue->hash),
184 &(queue->epoch),
185 queue->message,
186 queue->flags);
187
188 destroy_message (queue->message);
189
191}
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition gnunet-vpn.c:35
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.
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.
static void handle_message_control(struct GNUNET_MESSENGER_MessageControl *control, struct GNUNET_MESSENGER_Contact *contact, const struct GNUNET_HashCode *hash, const struct GNUNET_HashCode *epoch, const struct GNUNET_MESSENGER_Message *message, enum GNUNET_MESSENGER_MessageFlags flags)
struct GNUNET_MESSENGER_Handle * get_room_handle(struct GNUNET_MESSENGER_Room *room)
Returns the messenger handle of the room.

References destroy_message(), get_handle_contact_store(), get_room_handle(), get_store_contact_raw(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multishortmap_remove(), GNUNET_free, GNUNET_YES, handle, handle_message_control(), GNUNET_MESSENGER_MessageControl::head, is_peer_message(), map, GNUNET_MESSENGER_MessageControl::member_messages, GNUNET_MESSENGER_MessageControl::peer_messages, queue(), GNUNET_MESSENGER_MessageControl::room, and GNUNET_MESSENGER_MessageControl::tail.

Referenced by iterate_message_control().

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

◆ iterate_message_control()

static enum GNUNET_GenericReturnValue iterate_message_control ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 195 of file messenger_api_message_control.c.

198{
200
201 GNUNET_assert ((key) && (value));
202
203 queue = value;
204
205 if (queue->task)
206 return GNUNET_YES;
207
211 queue);
212
213 return GNUNET_YES;
214}
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
@ GNUNET_SCHEDULER_PRIORITY_DEFAULT
Run with the default priority (normal P2P operations).
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 task_message_control(void *cls)

References GNUNET_assert, GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_YES, key, queue(), task_message_control(), and value.

Referenced by process_message_control().

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

◆ process_message_control()

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_HashCode epoch,
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 flags using a selected message control.

The message control will ensure order of messages so that senders of messages can be identified via previously processed messages.

Parameters
[in,out]controlMessage control
[in]senderSender hash
[in]contextContext hash
[in]hashMessage hash
[in]epochEpoch hash
[in]messageMessage
[in]flagsMessage flags

Definition at line 218 of file messenger_api_message_control.c.

225{
226 struct GNUNET_MESSENGER_Contact *contact;
228 const struct GNUNET_ShortHashCode *id;
229
230 GNUNET_assert ((control) && (sender) && (context) && (hash) && (message));
231
232 {
234 struct GNUNET_MESSENGER_ContactStore *store;
235
236 handle = get_room_handle (control->room);
238
239 contact = get_store_contact_raw (store, context, sender);
240 }
241
242 if ((! contact) &&
243 (GNUNET_MESSENGER_KIND_JOIN != message->header.kind) &&
245 enqueue_message_control (control, sender, context, hash, epoch, message,
246 flags);
247 else
248 {
249 if ((! contact) && (GNUNET_MESSENGER_KIND_JOIN == message->header.kind))
251
252 handle_message_control (control, contact, hash, epoch, message, flags);
253 }
254
255 map = NULL;
256 id = &(message->header.sender_id);
257
258 if (GNUNET_YES == is_peer_message (message))
259 map = control->peer_messages;
260
261 switch (message->header.kind)
262 {
264 map = control->member_messages;
265 break;
267 map = control->peer_messages;
268 break;
270 map = control->member_messages;
271 id = &(message->body.id.id);
272 break;
273 default:
274 break;
275 }
276
277 if (! map)
278 return;
279
281 id,
283 NULL);
284}
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
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.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
@ GNUNET_MESSENGER_FLAG_MEMBER
The member flag.
static enum GNUNET_GenericReturnValue iterate_message_control(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
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_HashCode *epoch, const struct GNUNET_MESSENGER_Message *message, enum GNUNET_MESSENGER_MessageFlags flags)
struct GNUNET_MESSENGER_MessageId id
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
struct GNUNET_MESSENGER_MessageBody body
Body.
A 256-bit hashcode.

References GNUNET_MESSENGER_Message::body, context, enqueue_message_control(), get_handle_contact_store(), get_room_handle(), get_store_contact_raw(), GNUNET_assert, GNUNET_CONTAINER_multishortmap_get_multiple(), GNUNET_MESSENGER_FLAG_MEMBER, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_PEER, GNUNET_YES, handle, handle_message_control(), GNUNET_MESSENGER_Message::header, id, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, is_peer_message(), iterate_message_control(), GNUNET_MESSENGER_MessageHeader::kind, map, GNUNET_MESSENGER_MessageControl::member_messages, GNUNET_MESSENGER_MessageControl::peer_messages, GNUNET_MESSENGER_MessageControl::room, and GNUNET_MESSENGER_MessageHeader::sender_id.

Referenced by handle_recv_message().

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