GNUnet 0.28.1-dev.3-2-g4c5d45bb5
 
Loading...
Searching...
No Matches
mq.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-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 */
20
27#include "platform.h"
28#include "gnunet_util_lib.h"
29
30#define LOG(kind, ...) GNUNET_log_from (kind, "util-mq", __VA_ARGS__)
31
32
81
82
184
185
186void
202
203
216 const struct GNUNET_MessageHeader *mh,
217 bool log_unhandled)
218{
219 bool handled = false;
220 uint16_t msize = ntohs (mh->size);
221 uint16_t mtype = ntohs (mh->type);
222
224 "Received message of type %u and size %u\n",
225 mtype,
226 msize);
227 if (NULL == handlers)
228 goto done;
229 for (const struct GNUNET_MQ_MessageHandler *handler = handlers;
230 NULL != handler->cb;
231 handler++)
232 {
233 if (handler->type == mtype)
234 {
235 handled = true;
236 if ( (handler->expected_size > msize) ||
237 ( (handler->expected_size != msize) &&
238 (NULL == handler->mv) ) )
239 {
240 /* Too small, or not an exact size and
241 no 'mv' handler to check rest */
243 "Received malformed message of type %u\n",
244 (unsigned int) handler->type);
245 return GNUNET_SYSERR;
246 }
247 if ( (NULL == handler->mv) ||
248 (GNUNET_OK ==
249 handler->mv (handler->cls,
250 mh)) )
251 {
252 /* message well-formed, pass to handler */
253 handler->cb (handler->cls, mh);
254 }
255 else
256 {
257 /* Message rejected by check routine */
259 "Received malformed message of type %u\n",
260 (unsigned int) handler->type);
261 return GNUNET_SYSERR;
262 }
263 break;
264 }
265 }
266done:
267 if (! handled)
268 {
269 if (log_unhandled)
271 "No handler for message of type %u and size %u\n",
272 mtype,
273 msize);
274 return GNUNET_NO;
275 }
276 return GNUNET_OK;
277}
278
279
282 const struct GNUNET_MessageHeader *mh)
283{
284 return handle_message (handlers,
285 mh,
286 true);
287}
288
289
292 const struct GNUNET_MessageHeader *mh)
293{
294 return handle_message (handlers,
295 mh,
296 false);
297}
298
299
300void
302 enum GNUNET_MQ_Error error)
303{
304 if (NULL == mq->error_handler)
305 {
307 "Got error %d, but no handler installed\n",
308 (int) error);
309 return;
310 }
312 error);
313}
314
315
316void
318{
319 GNUNET_assert (NULL == ev->parent_queue);
320 GNUNET_free (ev);
321}
322
323
324unsigned int
326{
327 if (! mq->in_flight)
328 {
329 return mq->queue_length;
330 }
332 return mq->queue_length - 1;
333}
334
335
336void
338 struct GNUNET_MQ_Envelope *ev)
339{
340 GNUNET_assert (NULL != mq);
341 GNUNET_assert (NULL == ev->parent_queue);
342
343 mq->queue_length++;
344 if (mq->queue_length >= 10000000)
345 {
346 /* This would seem like a bug... */
348 "MQ with %u entries extended by message of type %u (FC broken?)\n",
349 (unsigned int) mq->queue_length,
350 (unsigned int) ntohs (ev->mh->type));
351 }
352 ev->parent_queue = mq;
353 /* is the implementation busy? queue it! */
354 if ((NULL != mq->current_envelope) || (NULL != mq->send_task))
355 {
358 ev);
359 return;
360 }
361 else if (NULL != mq->envelope_head)
362 {
365 ev);
366
367 ev = mq->envelope_head;
370 ev);
371 }
372 mq->current_envelope = ev;
373
375 "sending message of type %u and size %u, queue empty (MQ: %p)\n",
376 ntohs (ev->mh->type),
377 ntohs (ev->mh->size),
378 mq);
379
380 mq->send_impl (mq,
381 ev->mh,
382 mq->impl_state);
383}
384
385
386struct GNUNET_MQ_Envelope *
402
403
404struct GNUNET_MQ_Envelope *
413
414
415void
417 const struct GNUNET_MQ_Envelope *ev)
418{
419 struct GNUNET_MQ_Envelope *env;
420 uint16_t msize;
421 GNUNET_assert (NULL != ev);
422
423 msize = ntohs (ev->mh->size);
424 env = GNUNET_malloc (sizeof(struct GNUNET_MQ_Envelope) + msize);
425 env->mh = (struct GNUNET_MessageHeader *) &env[1];
426 env->sent_cb = ev->sent_cb;
427 env->sent_cls = ev->sent_cls;
428 GNUNET_memcpy (&env[1], ev->mh, msize);
430}
431
432
440static void
442{
443 struct GNUNET_MQ_Handle *mq = cls;
444 GNUNET_assert (NULL != mq->send_task);
445
446 mq->send_task = NULL;
447 /* call is only valid if we're actually currently sending
448 * a message */
449 if (NULL == mq->envelope_head)
450 return;
455
457 "sending message of type %u and size %u from queue (MQ: %p)\n",
458 ntohs (mq->current_envelope->mh->type),
459 ntohs (mq->current_envelope->mh->size),
460 mq);
461
462 mq->send_impl (mq,
464 mq->impl_state);
465}
466
467
468void
470{
471 struct GNUNET_MQ_Envelope *current_envelope;
473
475 mq->queue_length--;
476 mq->in_flight = false;
477 current_envelope = mq->current_envelope;
478 GNUNET_assert (NULL != current_envelope);
479 current_envelope->parent_queue = NULL;
480 mq->current_envelope = NULL;
481 GNUNET_assert (NULL == mq->send_task);
483 if (NULL != (cb = current_envelope->sent_cb))
484 {
485 current_envelope->sent_cb = NULL;
486 cb (current_envelope->sent_cls);
487 }
488 GNUNET_free (current_envelope);
489}
490
491
492void
494{
495 struct GNUNET_MQ_Envelope *current_envelope;
497
498 mq->in_flight = true;
499 /* call is only valid if we're actually currently sending
500 * a message */
501 current_envelope = mq->current_envelope;
502 GNUNET_assert (NULL != current_envelope);
503 /* can't call cancel from now on anymore */
504 current_envelope->parent_queue = NULL;
505 if (NULL != (cb = current_envelope->sent_cb))
506 {
507 current_envelope->sent_cb = NULL;
508 cb (current_envelope->sent_cls);
509 }
510}
511
512
513struct GNUNET_MQ_Handle *
535
536
537void
539 void *handlers_cls)
540{
541 if (NULL == mq->handlers)
542 return;
543 for (unsigned int i = 0; NULL != mq->handlers[i].cb; i++)
544 mq->handlers[i].cls = handlers_cls;
545}
546
547
548const struct GNUNET_MessageHeader *
555
556
557void *
559{
560 return mq->impl_state;
561}
562
563
564struct GNUNET_MQ_Envelope *
566 uint16_t size,
567 uint16_t type)
568{
569 struct GNUNET_MQ_Envelope *ev;
570
571 ev = GNUNET_malloc (size + sizeof(struct GNUNET_MQ_Envelope));
572 ev->mh = (struct GNUNET_MessageHeader *) &ev[1];
573 ev->mh->size = htons (size);
574 ev->mh->type = htons (type);
575 if (NULL != mhp)
576 *mhp = ev->mh;
577 return ev;
578}
579
580
581struct GNUNET_MQ_Envelope *
583{
584 struct GNUNET_MQ_Envelope *mqm;
585 uint16_t size = ntohs (hdr->size);
586
587 mqm = GNUNET_malloc (sizeof(*mqm) + size);
588 mqm->mh = (struct GNUNET_MessageHeader *) &mqm[1];
589 GNUNET_memcpy (mqm->mh,
590 hdr,
591 size);
592 return mqm;
593}
594
595
596struct GNUNET_MQ_Envelope *
598 uint16_t base_size,
599 uint16_t type,
600 const struct GNUNET_MessageHeader *nested_mh)
601{
602 struct GNUNET_MQ_Envelope *mqm;
603 uint16_t size;
604
605 if (NULL == nested_mh)
606 return GNUNET_MQ_msg_ (mhp,
607 base_size,
608 type);
609 size = base_size + ntohs (nested_mh->size);
610 /* check for uint16_t overflow */
611 if (size < base_size)
612 return NULL;
613 mqm = GNUNET_MQ_msg_ (mhp,
614 size,
615 type);
616 GNUNET_memcpy ((char *) mqm->mh + base_size,
617 nested_mh,
618 ntohs (nested_mh->size));
619 return mqm;
620}
621
622
623uint32_t
625 void *assoc_data)
626{
627 uint32_t id;
628
629 if (NULL == mq->assoc_map)
630 {
632 mq->assoc_id = 1;
633 }
634 id = mq->assoc_id++;
637 mq->assoc_map,
638 id,
639 assoc_data,
641 return id;
642}
643
644
652void *
654 uint32_t request_id)
655{
656 if (NULL == mq->assoc_map)
657 return NULL;
659 request_id);
660}
661
662
670void *
672 uint32_t request_id)
673{
674 void *val;
675
676 if (NULL == mq->assoc_map)
677 return NULL;
679 request_id);
681 request_id);
682 return val;
683}
684
685
686void
689 void *cb_cls)
690{
691 /* allow setting *OR* clearing callback */
692 GNUNET_assert ((NULL == ev->sent_cb) || (NULL == cb));
693 ev->sent_cb = cb;
694 ev->sent_cls = cb_cls;
695}
696
697
729
730
731void
733{
735
736 if (NULL != mq->destroy_impl)
737 {
739 }
740 if (NULL != mq->send_task)
741 {
743 mq->send_task = NULL;
744 }
745 while (NULL != mq->envelope_head)
746 {
747 struct GNUNET_MQ_Envelope *ev;
748
749 ev = mq->envelope_head;
750 ev->parent_queue = NULL;
753 mq->queue_length--;
755 "MQ destroy drops message of type %u\n",
756 ntohs (ev->mh->type));
758 }
759 if (NULL != mq->current_envelope)
760 {
761 /* we can only discard envelopes that
762 * are not queued! */
765 "MQ destroy drops current message of type %u\n",
766 ntohs (mq->current_envelope->mh->type));
768 mq->current_envelope = NULL;
770 mq->queue_length--;
771 }
773 while (NULL != (dnh = mq->dnh_head))
774 {
775 dnh->cb (dnh->cb_cls);
777 }
778 if (NULL != mq->assoc_map)
779 {
781 mq->assoc_map = NULL;
782 }
784 GNUNET_free (mq);
785}
786
787
788const struct GNUNET_MessageHeader *
790 uint16_t base_size)
791{
792 uint16_t whole_size;
793 uint16_t nested_size;
794 const struct GNUNET_MessageHeader *nested_msg;
795
796 whole_size = ntohs (mh->size);
797 GNUNET_assert (whole_size >= base_size);
798 nested_size = whole_size - base_size;
799 if (0 == nested_size)
800 return NULL;
801 if (nested_size < sizeof(struct GNUNET_MessageHeader))
802 {
803 GNUNET_break_op (0);
804 return NULL;
805 }
806 nested_msg = (const struct GNUNET_MessageHeader *) ((char *) mh + base_size);
807 if (ntohs (nested_msg->size) != nested_size)
808 {
809 GNUNET_break_op (0);
810 return NULL;
811 }
812 return nested_msg;
813}
814
815
816void
818{
819 struct GNUNET_MQ_Handle *mq = ev->parent_queue;
820
821 GNUNET_assert (NULL != mq);
822 GNUNET_assert (NULL != mq->cancel_impl);
824 mq->queue_length--;
825 if (mq->current_envelope == ev)
826 {
827 /* complex case, we already started with transmitting
828 the message using the callbacks. */
830 mq->cancel_impl (mq,
831 mq->impl_state);
832 /* continue sending the next message, if any */
834 if (NULL != mq->current_envelope)
835 {
840 "sending canceled message of type %u queue\n",
841 ntohs (ev->mh->type));
842 mq->send_impl (mq,
844 mq->impl_state);
845 }
846 }
847 else
848 {
849 /* simple case, message is still waiting in the queue */
852 ev);
853 }
854 ev->parent_queue = NULL;
855 ev->mh = NULL;
856 /* also frees ev */
857 GNUNET_free (ev);
858}
859
860
861struct GNUNET_MQ_Envelope *
866
867
868struct GNUNET_MQ_Envelope *
870{
871 if (NULL != mq->envelope_tail)
872 return mq->envelope_tail;
873
874 return mq->current_envelope;
875}
876
877
878void
885
886
889{
891
893 return env->priority;
894 if (NULL == mq)
895 return 0;
896 return mq->priority;
897}
898
899
917
918
919void
925
926
927const struct GNUNET_MessageHeader *
929{
930 return env->mh;
931}
932
933
934const struct GNUNET_MQ_Envelope *
936{
937 return env->next;
938}
939
940
944 void *cb_cls)
945{
947
949 dnh->mq = mq;
950 dnh->cb = cb;
951 dnh->cb_cls = cb_cls;
953 mq->dnh_tail,
954 dnh);
955 return dnh;
956}
957
958
959void
970
971
972void
974 struct GNUNET_MQ_Envelope **env_tail,
975 struct GNUNET_MQ_Envelope *env)
976{
978 *env_tail,
979 env);
980}
981
982
983void
985 struct GNUNET_MQ_Envelope **env_tail,
986 struct GNUNET_MQ_Envelope *env)
987{
989 *env_tail,
990 env);
991}
992
993
994void
996 struct GNUNET_MQ_Envelope **env_tail,
997 struct GNUNET_MQ_Envelope *env)
998{
1000 *env_tail,
1001 env);
1002}
1003
1004
1007{
1008 struct GNUNET_MQ_MessageHandler *copy;
1009 unsigned int count;
1010
1011 if (NULL == handlers)
1012 return NULL;
1014 copy = GNUNET_new_array (count + 1,
1016 GNUNET_memcpy (copy,
1017 handlers,
1018 count * sizeof(struct GNUNET_MQ_MessageHandler));
1019 return copy;
1020}
1021
1022
1025 GNUNET_MQ_MessageCallback agpl_handler,
1026 void *agpl_cls)
1027{
1028 struct GNUNET_MQ_MessageHandler *copy;
1029 unsigned int count;
1030
1031 if (NULL == handlers)
1032 return NULL;
1034 copy = GNUNET_new_array (count + 2,
1036 GNUNET_memcpy (copy,
1037 handlers,
1038 count * sizeof(struct GNUNET_MQ_MessageHandler));
1039 copy[count].mv = NULL;
1040 copy[count].cb = agpl_handler;
1041 copy[count].cls = agpl_cls;
1043 copy[count].expected_size = sizeof(struct GNUNET_MessageHeader);
1044 return copy;
1045}
1046
1047
1048unsigned int
1050{
1051 unsigned int i;
1052
1053 if (NULL == handlers)
1054 return 0;
1055 for (i = 0; NULL != handlers[i].cb; i++)
1056 ;
1057 return i;
1058}
1059
1060
1061const char *
1063{
1064 switch (type)
1065 {
1067 return "NONE";
1069 return "BANDWIDTH";
1071 return "LATENCY";
1073 return "RELIABILITY";
1074 }
1075 return NULL;
1076}
1077
1078
1079/* end of mq.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition 003.c:1
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
Function called on connection trouble.
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_CADET_Handle * mh
Cadet handle.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
static uint32_t type
Type string converted to DNS type value.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#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.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_put(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
void * GNUNET_CONTAINER_multihashmap32_get(const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
Given a key find a value in the map matching the key.
void GNUNET_CONTAINER_multihashmap32_destroy(struct GNUNET_CONTAINER_MultiHashMap32 *map)
Destroy a 32-bit key hash map.
int GNUNET_CONTAINER_multihashmap32_remove_all(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
Remove all entries for the given key from the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
#define GNUNET_MAX(a, b)
uint16_t expected_size
Expected size of messages of this type.
GNUNET_MQ_MessageCallback cb
Callback, called every time a new message of the specified type has been received.
void * cls
Closure for mv and cb.
GNUNET_MQ_MessageValidationCallback mv
Callback to validate a message of the specified type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
uint16_t type
Type of the message this handler covers, in host byte order.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_send_copy(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MQ_Envelope *ev)
Send a copy of a message with the given message queue.
Definition mq.c:416
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition mq.c:582
struct GNUNET_MQ_Envelope * GNUNET_MQ_env_copy(struct GNUNET_MQ_Envelope *env)
Function to copy an envelope.
Definition mq.c:405
void GNUNET_MQ_set_options(struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_PriorityPreferences pp)
Set application-specific options for this queue.
Definition mq.c:920
void GNUNET_MQ_send_cancel(struct GNUNET_MQ_Envelope *ev)
Cancel sending the message.
Definition mq.c:817
void GNUNET_MQ_dll_remove(struct GNUNET_MQ_Envelope **env_head, struct GNUNET_MQ_Envelope **env_tail, struct GNUNET_MQ_Envelope *env)
Remove env from the envelope DLL starting at env_head.
Definition mq.c:995
void GNUNET_MQ_env_set_options(struct GNUNET_MQ_Envelope *env, enum GNUNET_MQ_PriorityPreferences pp)
Set application-specific options for this envelope.
Definition mq.c:879
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition mq.c:325
const struct GNUNET_MessageHeader * GNUNET_MQ_extract_nested_mh_(const struct GNUNET_MessageHeader *mh, uint16_t base_size)
Implementation of the #GNUNET_MQ_extract_nexted_mh macro.
Definition mq.c:789
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_MQ_Envelope * GNUNET_MQ_unsent_head(struct GNUNET_MQ_Handle *mq)
Remove the first envelope that has not yet been sent from the message queue and return it.
Definition mq.c:387
void GNUNET_MQ_inject_error(struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_Error error)
Call the error handler of a message queue with the given error code.
Definition mq.c:301
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue for the specified handlers.
Definition mq.c:514
void(* GNUNET_MQ_ErrorHandler)(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
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:337
void(* GNUNET_MQ_DestroyImpl)(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
void GNUNET_MQ_dll_insert_head(struct GNUNET_MQ_Envelope **env_head, struct GNUNET_MQ_Envelope **env_tail, struct GNUNET_MQ_Envelope *env)
Insert env into the envelope DLL starting at env_head Note that env must not be in any MQ while this ...
Definition mq.c:973
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *ev)
Discard the message queue message, free all allocated resources.
Definition mq.c:317
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers2(const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_MessageCallback agpl_handler, void *agpl_cls)
Copy an array of handlers, appending AGPL handler.
Definition mq.c:1024
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
Definition mq.c:1006
GNUNET_MQ_PreferenceKind
Enum defining all known preference categories.
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition mq.c:469
const char * GNUNET_MQ_preference_to_string(enum GNUNET_MQ_PreferenceKind type)
Convert an enum GNUNET_MQ_PreferenceType to a string.
Definition mq.c:1062
void * GNUNET_MQ_assoc_get(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
Get the data associated with a request_id in a queue.
Definition mq.c:653
struct GNUNET_MQ_DestroyNotificationHandle * GNUNET_MQ_destroy_notify(struct GNUNET_MQ_Handle *mq, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Register function to be called whenever mq is being destroyed.
Definition mq.c:942
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_combine_options(enum GNUNET_MQ_PriorityPreferences p1, enum GNUNET_MQ_PriorityPreferences p2)
Combine performance preferences set for different envelopes that are being combined into one larger e...
Definition mq.c:901
const struct GNUNET_MQ_Envelope * GNUNET_MQ_env_next(const struct GNUNET_MQ_Envelope *env)
Return next envelope in queue.
Definition mq.c:935
void GNUNET_MQ_inject_message(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given m...
Definition mq.c:187
GNUNET_MQ_PriorityPreferences
Per envelope preferences and priorities.
enum GNUNET_GenericReturnValue GNUNET_MQ_handle_message(const struct GNUNET_MQ_MessageHandler *handlers, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given h...
Definition mq.c:281
void GNUNET_MQ_destroy_notify_cancel(struct GNUNET_MQ_DestroyNotificationHandle *dnh)
Cancel registration from GNUNET_MQ_destroy_notify().
Definition mq.c:960
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:687
uint32_t GNUNET_MQ_assoc_add(struct GNUNET_MQ_Handle *mq, void *assoc_data)
Associate the assoc_data in mq with a unique request id.
Definition mq.c:624
void(* GNUNET_MQ_MessageCallback)(void *cls, const struct GNUNET_MessageHeader *msg)
Called when a message has been received.
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_(struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type)
Create a new envelope.
Definition mq.c:565
const struct GNUNET_MessageHeader * GNUNET_MQ_env_get_msg(const struct GNUNET_MQ_Envelope *env)
Obtain message contained in envelope.
Definition mq.c:928
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_get_options(struct GNUNET_MQ_Envelope *env)
Get performance preferences set for this envelope.
Definition mq.c:888
void GNUNET_MQ_impl_send_in_flight(struct GNUNET_MQ_Handle *mq)
Call the send notification for the current message, but do not try to send the next message until #gn...
Definition mq.c:493
void * GNUNET_MQ_assoc_remove(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
Remove the association for a request_id.
Definition mq.c:671
const struct GNUNET_MessageHeader * GNUNET_MQ_impl_current(struct GNUNET_MQ_Handle *mq)
Get the message that should currently be sent.
Definition mq.c:549
enum GNUNET_GenericReturnValue GNUNET_MQ_try_handle_message(const struct GNUNET_MQ_MessageHandler *handlers, const struct GNUNET_MessageHeader *mh)
Same as GNUNET_MQ_handle_message(), except that a message for which no handler is registered is not l...
Definition mq.c:291
void GNUNET_MQ_set_handlers_closure(struct GNUNET_MQ_Handle *mq, void *handlers_cls)
Change the closure argument in all of the handlers of the mq.
Definition mq.c:538
struct GNUNET_MQ_Envelope * GNUNET_MQ_get_last_envelope(struct GNUNET_MQ_Handle *mq)
Function to obtain the last envelope in the queue.
Definition mq.c:869
void * GNUNET_MQ_impl_state(struct GNUNET_MQ_Handle *mq)
Get the implementation state associated with the message queue.
Definition mq.c:558
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_nested_mh_(struct GNUNET_MessageHeader **mhp, uint16_t base_size, uint16_t type, const struct GNUNET_MessageHeader *nested_mh)
Implementation of the GNUNET_MQ_msg_nested_mh macro.
Definition mq.c:597
void GNUNET_MQ_dll_insert_tail(struct GNUNET_MQ_Envelope **env_head, struct GNUNET_MQ_Envelope **env_tail, struct GNUNET_MQ_Envelope *env)
Insert env into the envelope DLL starting at env_head Note that env must not be in any MQ while this ...
Definition mq.c:984
void(* GNUNET_MQ_CancelImpl)(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
void(* GNUNET_MQ_SendImpl)(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue.
unsigned int GNUNET_MQ_count_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Count the handlers in a handler array.
Definition mq.c:1049
struct GNUNET_MQ_Envelope * GNUNET_MQ_get_current_envelope(struct GNUNET_MQ_Handle *mq)
Function to obtain the current envelope from within GNUNET_MQ_SendImpl implementations.
Definition mq.c:862
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition mq.c:732
@ GNUNET_MQ_ERROR_MALFORMED
We received a message that was malformed and thus could not be passed to its handler.
@ GNUNET_MQ_PREFERENCE_RELIABILITY
The preferred transmission for this envelope foces on reliability.
@ GNUNET_MQ_PREFERENCE_NONE
No preference was expressed.
@ GNUNET_MQ_PREFERENCE_LATENCY
The preferred transmission for this envelope foces on minimizing latency.
@ GNUNET_MQ_PREFERENCE_BANDWIDTH
The preferred transmission for this envelope focuses on maximizing bandwidth.
@ GNUNET_MQ_PREF_OUT_OF_ORDER
Flag to indicate that out-of-order delivery is OK.
@ GNUNET_MQ_PRIORITY_MASK
Bit mask to apply to extract the priority bits.
@ GNUNET_MQ_PREF_CORK_ALLOWED
Flag to indicate that CORKing is acceptable.
@ GNUNET_MQ_PREF_UNRELIABLE
Flag to indicate that unreliable delivery is acceptable.
@ GNUNET_MQ_PREF_GOODPUT
Flag to indicate that high bandwidth is desired.
@ GNUNET_MQ_PREF_LOW_LATENCY
Flag to indicate that low latency is important.
#define GNUNET_MESSAGE_TYPE_REQUEST_AGPL
Message to request source code link.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
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:1310
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
static void destroy(void *cls)
Function to destroy a microphone.
Definition microphone.c:155
static enum GNUNET_GenericReturnValue handle_message(const struct GNUNET_MQ_MessageHandler *handlers, const struct GNUNET_MessageHeader *mh, bool log_unhandled)
Call the message handler registered for the type of mh in the given handlers list.
Definition mq.c:215
static void impl_send_continue(void *cls)
Task run to call the send implementation for the next queued message, if any.
Definition mq.c:441
#define LOG(kind,...)
Definition mq.c:30
static unsigned int size
Size of the "table".
Definition peer.c:68
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
Internal representation of the hash map.
Handle we return for callbacks registered to be notified when GNUNET_MQ_destroy() is called on a queu...
Definition mq.c:703
struct GNUNET_MQ_DestroyNotificationHandle * next
Kept in a DLL.
Definition mq.c:712
struct GNUNET_MQ_DestroyNotificationHandle * prev
Kept in a DLL.
Definition mq.c:707
GNUNET_SCHEDULER_TaskCallback cb
Function to call.
Definition mq.c:722
void * cb_cls
Closure for cb.
Definition mq.c:727
struct GNUNET_MQ_Handle * mq
Queue to notify about.
Definition mq.c:717
struct GNUNET_MQ_Handle * parent_queue
Queue the message is queued in, NULL if message is not queued.
Definition mq.c:57
void * sent_cls
Closure for send_cb.
Definition mq.c:67
int have_custom_options
Did the application call GNUNET_MQ_env_set_options()?
Definition mq.c:79
struct GNUNET_MessageHeader * mh
Actual allocated message header.
Definition mq.c:52
struct GNUNET_MQ_Envelope * next
Messages are stored in a linked list.
Definition mq.c:39
GNUNET_SCHEDULER_TaskCallback sent_cb
Called after the message was sent irrevocably.
Definition mq.c:62
struct GNUNET_MQ_Envelope * prev
Messages are stored in a linked list Each queue has its own list of envelopes.
Definition mq.c:45
enum GNUNET_MQ_PriorityPreferences priority
Flags that were set for this envelope by GNUNET_MQ_env_set_options().
Definition mq.c:74
Handle to a message queue.
Definition mq.c:87
GNUNET_MQ_DestroyImpl destroy_impl
Implementation-dependent queue destruction function.
Definition mq.c:102
enum GNUNET_MQ_PriorityPreferences priority
Flags that were set for this queue by GNUNET_MQ_set_options().
Definition mq.c:165
uint32_t assoc_id
Next id that should be used for the assoc_map, initialized lazily to a random value together with ass...
Definition mq.c:172
struct GNUNET_MQ_DestroyNotificationHandle * dnh_head
Functions to call on queue destruction; kept in a DLL.
Definition mq.c:154
struct GNUNET_MQ_Envelope * envelope_head
Linked list of messages pending to be sent.
Definition mq.c:132
struct GNUNET_MQ_Envelope * current_envelope
Message that is currently scheduled to be sent.
Definition mq.c:144
GNUNET_MQ_CancelImpl cancel_impl
Implementation-dependent send cancel function.
Definition mq.c:107
GNUNET_MQ_ErrorHandler error_handler
Callback will be called when an error occurs.
Definition mq.c:117
struct GNUNET_MQ_DestroyNotificationHandle * dnh_tail
Functions to call on queue destruction; kept in a DLL.
Definition mq.c:159
unsigned int queue_length
Number of entries we have in the envelope-DLL.
Definition mq.c:177
void * impl_state
Implementation-specific state.
Definition mq.c:112
struct GNUNET_MQ_MessageHandler * handlers
Handlers array, or NULL if the queue should not receive messages.
Definition mq.c:91
struct GNUNET_SCHEDULER_Task * send_task
Task to asynchronously run impl_send_continue().
Definition mq.c:127
void * error_handler_cls
Closure for the error handler.
Definition mq.c:122
GNUNET_MQ_SendImpl send_impl
Actual implementation of message sending, called when a message is added.
Definition mq.c:97
struct GNUNET_MQ_Envelope * envelope_tail
Linked list of messages pending to be sent.
Definition mq.c:137
struct GNUNET_CONTAINER_MultiHashMap32 * assoc_map
Map of associations, lazily allocated.
Definition mq.c:149
bool in_flight
True if GNUNET_MQ_impl_send_in_flight() was called.
Definition mq.c:182
Message handler for a specific message type.
Header for all communications.
Entry in list of pending tasks.
Definition scheduler.c:141