GNUnet  0.19.5
mq.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2012-2019 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 
34 {
40 
46 
53 
58 
63 
67  void *sent_cls;
68 
75 
80 };
81 
82 
87 {
92 
98 
103 
108 
112  void *impl_state;
113 
118 
123 
128 
133 
138 
145 
150 
155 
160 
166 
172  uint32_t assoc_id;
173 
177  unsigned int queue_length;
178 
182  bool in_flight;
183 };
184 
185 
186 void
188  const struct GNUNET_MessageHeader *mh)
189 {
191 
193  mh);
194  if (GNUNET_SYSERR == ret)
195  {
196  GNUNET_break_op (0);
199  return;
200  }
201 }
202 
203 
206  const struct GNUNET_MessageHeader *mh)
207 {
208  bool handled = false;
209  uint16_t msize = ntohs (mh->size);
210  uint16_t mtype = ntohs (mh->type);
211 
213  "Received message of type %u and size %u\n",
214  mtype,
215  msize);
216  if (NULL == handlers)
217  goto done;
218  for (const struct GNUNET_MQ_MessageHandler *handler = handlers;
219  NULL != handler->cb;
220  handler++)
221  {
222  if (handler->type == mtype)
223  {
224  handled = true;
225  if ( (handler->expected_size > msize) ||
226  ( (handler->expected_size != msize) &&
227  (NULL == handler->mv) ) )
228  {
229  /* Too small, or not an exact size and
230  no 'mv' handler to check rest */
232  "Received malformed message of type %u\n",
233  (unsigned int) handler->type);
234  return GNUNET_SYSERR;
235  }
236  if ( (NULL == handler->mv) ||
237  (GNUNET_OK ==
238  handler->mv (handler->cls,
239  mh)) )
240  {
241  /* message well-formed, pass to handler */
242  handler->cb (handler->cls, mh);
243  }
244  else
245  {
246  /* Message rejected by check routine */
248  "Received malformed message of type %u\n",
249  (unsigned int) handler->type);
250  return GNUNET_SYSERR;
251  }
252  break;
253  }
254  }
255 done:
256  if (! handled)
257  {
259  "No handler for message of type %u and size %u\n",
260  mtype,
261  msize);
262  return GNUNET_NO;
263  }
264  return GNUNET_OK;
265 }
266 
267 
268 void
270  enum GNUNET_MQ_Error error)
271 {
272  if (NULL == mq->error_handler)
273  {
275  "Got error %d, but no handler installed\n",
276  (int) error);
277  return;
278  }
280  error);
281 }
282 
283 
284 void
286 {
287  GNUNET_assert (NULL == ev->parent_queue);
288  GNUNET_free (ev);
289 }
290 
291 
292 unsigned int
294 {
295  if (! mq->in_flight)
296  {
297  return mq->queue_length;
298  }
299  return mq->queue_length - 1;
300 }
301 
302 
303 void
305  struct GNUNET_MQ_Envelope *ev)
306 {
307  GNUNET_assert (NULL != mq);
308  GNUNET_assert (NULL == ev->parent_queue);
309 
310  mq->queue_length++;
311  if (mq->queue_length >= 10000000)
312  {
313  /* This would seem like a bug... */
315  "MQ with %u entries extended by message of type %u (FC broken?)\n",
316  (unsigned int) mq->queue_length,
317  (unsigned int) ntohs (ev->mh->type));
318  }
319  ev->parent_queue = mq;
320  /* is the implementation busy? queue it! */
321  if ((NULL != mq->current_envelope) || (NULL != mq->send_task))
322  {
324  mq->envelope_tail,
325  ev);
326  return;
327  }
328  GNUNET_assert (NULL == mq->envelope_head);
329  mq->current_envelope = ev;
330 
332  "sending message of type %u and size %u, queue empty (MQ: %p)\n",
333  ntohs (ev->mh->type),
334  ntohs (ev->mh->size),
335  mq);
336 
337  mq->send_impl (mq,
338  ev->mh,
339  mq->impl_state);
340 }
341 
342 
343 struct GNUNET_MQ_Envelope *
345 {
346  struct GNUNET_MQ_Envelope *env;
347 
348  env = mq->envelope_head;
350  mq->envelope_tail,
351  env);
352  mq->queue_length--;
353  env->parent_queue = NULL;
354  return env;
355 }
356 
357 
358 struct GNUNET_MQ_Envelope *
360 {
361  GNUNET_assert (NULL == env->next);
362  GNUNET_assert (NULL == env->parent_queue);
363  GNUNET_assert (NULL == env->sent_cb);
365  return GNUNET_MQ_msg_copy (env->mh);
366 }
367 
368 
369 void
371  const struct GNUNET_MQ_Envelope *ev)
372 {
373  struct GNUNET_MQ_Envelope *env;
374  uint16_t msize;
375 
376  msize = ntohs (ev->mh->size);
377  env = GNUNET_malloc (sizeof(struct GNUNET_MQ_Envelope) + msize);
378  env->mh = (struct GNUNET_MessageHeader *) &env[1];
379  env->sent_cb = ev->sent_cb;
380  env->sent_cls = ev->sent_cls;
381  GNUNET_memcpy (&env[1], ev->mh, msize);
382  GNUNET_MQ_send (mq, env);
383 }
384 
385 
393 static void
395 {
396  struct GNUNET_MQ_Handle *mq = cls;
397 
398  mq->send_task = NULL;
399  /* call is only valid if we're actually currently sending
400  * a message */
401  if (NULL == mq->envelope_head)
402  return;
405  mq->envelope_tail,
407 
409  "sending message of type %u and size %u from queue (MQ: %p)\n",
410  ntohs (mq->current_envelope->mh->type),
411  ntohs (mq->current_envelope->mh->size),
412  mq);
413 
414  mq->send_impl (mq,
416  mq->impl_state);
417 }
418 
419 
420 void
422 {
423  struct GNUNET_MQ_Envelope *current_envelope;
425 
427  mq->queue_length--;
428  mq->in_flight = false;
429  current_envelope = mq->current_envelope;
430  current_envelope->parent_queue = NULL;
431  mq->current_envelope = NULL;
432  GNUNET_assert (NULL == mq->send_task);
434  if (NULL != (cb = current_envelope->sent_cb))
435  {
436  current_envelope->sent_cb = NULL;
437  cb (current_envelope->sent_cls);
438  }
439  GNUNET_free (current_envelope);
440 }
441 
442 
443 void
445 {
446  struct GNUNET_MQ_Envelope *current_envelope;
448 
449  mq->in_flight = true;
450  /* call is only valid if we're actually currently sending
451  * a message */
452  current_envelope = mq->current_envelope;
453  GNUNET_assert (NULL != current_envelope);
454  /* can't call cancel from now on anymore */
455  current_envelope->parent_queue = NULL;
456  if (NULL != (cb = current_envelope->sent_cb))
457  {
458  current_envelope->sent_cb = NULL;
459  cb (current_envelope->sent_cls);
460  }
461 }
462 
463 
464 struct GNUNET_MQ_Handle *
467  GNUNET_MQ_CancelImpl cancel,
468  void *impl_state,
469  const struct GNUNET_MQ_MessageHandler *handlers,
471  void *error_handler_cls)
472 {
473  struct GNUNET_MQ_Handle *mq;
474 
475  mq = GNUNET_new (struct GNUNET_MQ_Handle);
476  mq->send_impl = send;
478  mq->cancel_impl = cancel;
483 
484  return mq;
485 }
486 
487 
488 void
490  void *handlers_cls)
491 {
492  if (NULL == mq->handlers)
493  return;
494  for (unsigned int i = 0; NULL != mq->handlers[i].cb; i++)
495  mq->handlers[i].cls = handlers_cls;
496 }
497 
498 
499 const struct GNUNET_MessageHeader *
501 {
502  GNUNET_assert (NULL != mq->current_envelope);
503  GNUNET_assert (NULL != mq->current_envelope->mh);
504  return mq->current_envelope->mh;
505 }
506 
507 
508 void *
510 {
511  return mq->impl_state;
512 }
513 
514 
515 struct GNUNET_MQ_Envelope *
517  uint16_t size,
518  uint16_t type)
519 {
520  struct GNUNET_MQ_Envelope *ev;
521 
522  ev = GNUNET_malloc (size + sizeof(struct GNUNET_MQ_Envelope));
523  ev->mh = (struct GNUNET_MessageHeader *) &ev[1];
524  ev->mh->size = htons (size);
525  ev->mh->type = htons (type);
526  if (NULL != mhp)
527  *mhp = ev->mh;
528  return ev;
529 }
530 
531 
532 struct GNUNET_MQ_Envelope *
534 {
535  struct GNUNET_MQ_Envelope *mqm;
536  uint16_t size = ntohs (hdr->size);
537 
538  mqm = GNUNET_malloc (sizeof(*mqm) + size);
539  mqm->mh = (struct GNUNET_MessageHeader *) &mqm[1];
540  GNUNET_memcpy (mqm->mh,
541  hdr,
542  size);
543  return mqm;
544 }
545 
546 
547 struct GNUNET_MQ_Envelope *
549  uint16_t base_size,
550  uint16_t type,
551  const struct GNUNET_MessageHeader *nested_mh)
552 {
553  struct GNUNET_MQ_Envelope *mqm;
554  uint16_t size;
555 
556  if (NULL == nested_mh)
557  return GNUNET_MQ_msg_ (mhp,
558  base_size,
559  type);
560  size = base_size + ntohs (nested_mh->size);
561  /* check for uint16_t overflow */
562  if (size < base_size)
563  return NULL;
564  mqm = GNUNET_MQ_msg_ (mhp,
565  size,
566  type);
567  GNUNET_memcpy ((char *) mqm->mh + base_size,
568  nested_mh,
569  ntohs (nested_mh->size));
570  return mqm;
571 }
572 
573 
574 uint32_t
576  void *assoc_data)
577 {
578  uint32_t id;
579 
580  if (NULL == mq->assoc_map)
581  {
583  mq->assoc_id = 1;
584  }
585  id = mq->assoc_id++;
588  mq->assoc_map,
589  id,
590  assoc_data,
592  return id;
593 }
594 
595 
603 void *
605  uint32_t request_id)
606 {
607  if (NULL == mq->assoc_map)
608  return NULL;
610  request_id);
611 }
612 
613 
621 void *
623  uint32_t request_id)
624 {
625  void *val;
626 
627  if (NULL == mq->assoc_map)
628  return NULL;
630  request_id);
632  request_id);
633  return val;
634 }
635 
636 
637 void
640  void *cb_cls)
641 {
642  /* allow setting *OR* clearing callback */
643  GNUNET_assert ((NULL == ev->sent_cb) || (NULL == cb));
644  ev->sent_cb = cb;
645  ev->sent_cls = cb_cls;
646 }
647 
648 
654 {
659 
664 
669 
674 
678  void *cb_cls;
679 };
680 
681 
682 void
684 {
686 
687  if (NULL != mq->destroy_impl)
688  {
690  }
691  if (NULL != mq->send_task)
692  {
694  mq->send_task = NULL;
695  }
696  while (NULL != mq->envelope_head)
697  {
698  struct GNUNET_MQ_Envelope *ev;
699 
700  ev = mq->envelope_head;
701  ev->parent_queue = NULL;
704  mq->queue_length--;
706  "MQ destroy drops message of type %u\n",
707  ntohs (ev->mh->type));
708  GNUNET_MQ_discard (ev);
709  }
710  if (NULL != mq->current_envelope)
711  {
712  /* we can only discard envelopes that
713  * are not queued! */
716  "MQ destroy drops current message of type %u\n",
717  ntohs (mq->current_envelope->mh->type));
719  mq->current_envelope = NULL;
721  mq->queue_length--;
722  }
723  GNUNET_assert (0 == mq->queue_length);
724  while (NULL != (dnh = mq->dnh_head))
725  {
726  dnh->cb (dnh->cb_cls);
728  }
729  if (NULL != mq->assoc_map)
730  {
732  mq->assoc_map = NULL;
733  }
735  GNUNET_free (mq);
736 }
737 
738 
739 const struct GNUNET_MessageHeader *
741  uint16_t base_size)
742 {
743  uint16_t whole_size;
744  uint16_t nested_size;
745  const struct GNUNET_MessageHeader *nested_msg;
746 
747  whole_size = ntohs (mh->size);
748  GNUNET_assert (whole_size >= base_size);
749  nested_size = whole_size - base_size;
750  if (0 == nested_size)
751  return NULL;
752  if (nested_size < sizeof(struct GNUNET_MessageHeader))
753  {
754  GNUNET_break_op (0);
755  return NULL;
756  }
757  nested_msg = (const struct GNUNET_MessageHeader *) ((char *) mh + base_size);
758  if (ntohs (nested_msg->size) != nested_size)
759  {
760  GNUNET_break_op (0);
761  return NULL;
762  }
763  return nested_msg;
764 }
765 
766 
767 void
769 {
770  struct GNUNET_MQ_Handle *mq = ev->parent_queue;
771 
772  GNUNET_assert (NULL != mq);
773  GNUNET_assert (NULL != mq->cancel_impl);
775  mq->queue_length--;
776  if (mq->current_envelope == ev)
777  {
778  /* complex case, we already started with transmitting
779  the message using the callbacks. */
781  mq->cancel_impl (mq,
782  mq->impl_state);
783  /* continue sending the next message, if any */
785  if (NULL != mq->current_envelope)
786  {
788  mq->envelope_tail,
791  "sending canceled message of type %u queue\n",
792  ntohs (ev->mh->type));
793  mq->send_impl (mq,
795  mq->impl_state);
796  }
797  }
798  else
799  {
800  /* simple case, message is still waiting in the queue */
802  mq->envelope_tail,
803  ev);
804  }
805  ev->parent_queue = NULL;
806  ev->mh = NULL;
807  /* also frees ev */
808  GNUNET_free (ev);
809 }
810 
811 
812 struct GNUNET_MQ_Envelope *
814 {
815  return mq->current_envelope;
816 }
817 
818 
819 struct GNUNET_MQ_Envelope *
821 {
822  if (NULL != mq->envelope_tail)
823  return mq->envelope_tail;
824 
825  return mq->current_envelope;
826 }
827 
828 
829 void
832 {
833  env->priority = pp;
835 }
836 
837 
840 {
841  struct GNUNET_MQ_Handle *mq = env->parent_queue;
842 
844  return env->priority;
845  if (NULL == mq)
846  return 0;
847  return mq->priority;
848 }
849 
850 
854 {
856 
859  ret |=
861  ret |=
864  ret |=
866  return ret;
867 }
868 
869 
870 void
873 {
874  mq->priority = pp;
875 }
876 
877 
878 const struct GNUNET_MessageHeader *
880 {
881  return env->mh;
882 }
883 
884 
885 const struct GNUNET_MQ_Envelope *
887 {
888  return env->next;
889 }
890 
891 
895  void *cb_cls)
896 {
898 
900  dnh->mq = mq;
901  dnh->cb = cb;
902  dnh->cb_cls = cb_cls;
904  mq->dnh_tail,
905  dnh);
906  return dnh;
907 }
908 
909 
910 void
913 {
914  struct GNUNET_MQ_Handle *mq = dnh->mq;
915 
917  mq->dnh_tail,
918  dnh);
919  GNUNET_free (dnh);
920 }
921 
922 
923 void
925  struct GNUNET_MQ_Envelope **env_tail,
926  struct GNUNET_MQ_Envelope *env)
927 {
928  GNUNET_CONTAINER_DLL_insert (*env_head,
929  *env_tail,
930  env);
931 }
932 
933 
934 void
936  struct GNUNET_MQ_Envelope **env_tail,
937  struct GNUNET_MQ_Envelope *env)
938 {
940  *env_tail,
941  env);
942 }
943 
944 
945 void
947  struct GNUNET_MQ_Envelope **env_tail,
948  struct GNUNET_MQ_Envelope *env)
949 {
950  GNUNET_CONTAINER_DLL_remove (*env_head,
951  *env_tail,
952  env);
953 }
954 
955 
958 {
959  struct GNUNET_MQ_MessageHandler *copy;
960  unsigned int count;
961 
962  if (NULL == handlers)
963  return NULL;
965  copy = GNUNET_new_array (count + 1,
966  struct GNUNET_MQ_MessageHandler);
967  GNUNET_memcpy (copy,
968  handlers,
969  count * sizeof(struct GNUNET_MQ_MessageHandler));
970  return copy;
971 }
972 
973 
976  GNUNET_MQ_MessageCallback agpl_handler,
977  void *agpl_cls)
978 {
979  struct GNUNET_MQ_MessageHandler *copy;
980  unsigned int count;
981 
982  if (NULL == handlers)
983  return NULL;
985  copy = GNUNET_new_array (count + 2,
986  struct GNUNET_MQ_MessageHandler);
987  GNUNET_memcpy (copy,
988  handlers,
989  count * sizeof(struct GNUNET_MQ_MessageHandler));
990  copy[count].mv = NULL;
991  copy[count].cb = agpl_handler;
992  copy[count].cls = agpl_cls;
994  copy[count].expected_size = sizeof(struct GNUNET_MessageHeader);
995  return copy;
996 }
997 
998 
999 unsigned int
1001 {
1002  unsigned int i;
1003 
1004  if (NULL == handlers)
1005  return 0;
1006  for (i = 0; NULL != handlers[i].cb; i++)
1007  ;
1008  return i;
1009 }
1010 
1011 
1012 const char *
1014 {
1015  switch (type)
1016  {
1018  return "NONE";
1020  return "BANDWIDTH";
1022  return "LATENCY";
1024  return "RELIABILITY";
1025  }
1026  return NULL;
1027 }
1028 
1029 
1030 /* end of mq.c */
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
We encountered an error handling the MQ to the ATS service.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static void done()
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
static void destroy(void *cls)
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
#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...
#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 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:370
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_(struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type)
Create a new envelope.
Definition: mq.c:516
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:740
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:871
void GNUNET_MQ_send_cancel(struct GNUNET_MQ_Envelope *ev)
Cancel sending the message.
Definition: mq.c:768
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:946
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:830
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:293
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:893
const struct GNUNET_MQ_Envelope * GNUNET_MQ_env_next(const struct GNUNET_MQ_Envelope *env)
Return next envelope in queue.
Definition: mq.c:886
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:344
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:269
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:304
void(* GNUNET_MQ_DestroyImpl)(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
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:820
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:924
void * GNUNET_MQ_impl_state(struct GNUNET_MQ_Handle *mq)
Get the implementation state associated with the message queue.
Definition: mq.c:509
const char * GNUNET_MQ_preference_to_string(enum GNUNET_MQ_PreferenceKind type)
Convert an enum GNUNET_MQ_PreferenceType to a string.
Definition: mq.c:1013
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *ev)
Discard the message queue message, free all allocated resources.
Definition: mq.c:285
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:465
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:421
void * GNUNET_MQ_assoc_remove(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
Remove the association for a request_id.
Definition: mq.c:622
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:852
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.
void GNUNET_MQ_destroy_notify_cancel(struct GNUNET_MQ_DestroyNotificationHandle *dnh)
Cancel registration from GNUNET_MQ_destroy_notify().
Definition: mq.c:911
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:638
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:533
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:575
void(* GNUNET_MQ_MessageCallback)(void *cls, const struct GNUNET_MessageHeader *msg)
Called when a message has been received.
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:205
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:604
const struct GNUNET_MessageHeader * GNUNET_MQ_impl_current(struct GNUNET_MQ_Handle *mq)
Get the message that should currently be sent.
Definition: mq.c:500
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_get_options(struct GNUNET_MQ_Envelope *env)
Get performance preferences set for this envelope.
Definition: mq.c:839
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:444
struct GNUNET_MQ_Envelope * GNUNET_MQ_env_copy(struct GNUNET_MQ_Envelope *env)
Function to copy an envelope.
Definition: mq.c:359
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:489
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:975
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:935
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.
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
Definition: mq.c:957
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:813
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:548
unsigned int GNUNET_MQ_count_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Count the handlers in a handler array.
Definition: mq.c:1000
const struct GNUNET_MessageHeader * GNUNET_MQ_env_get_msg(const struct GNUNET_MQ_Envelope *env)
Obtain message contained in envelope.
Definition: mq.c:879
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
@ 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.
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:1299
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
static void impl_send_continue(void *cls)
Task run to call the send implementation for the next queued message, if any.
Definition: mq.c:394
#define LOG(kind,...)
Definition: mq.c:30
static unsigned int size
Size of the "table".
Definition: peer.c:68
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:654
struct GNUNET_MQ_DestroyNotificationHandle * next
Kept in a DLL.
Definition: mq.c:663
struct GNUNET_MQ_DestroyNotificationHandle * prev
Kept in a DLL.
Definition: mq.c:658
GNUNET_SCHEDULER_TaskCallback cb
Function to call.
Definition: mq.c:673
void * cb_cls
Closure for cb.
Definition: mq.c:678
struct GNUNET_MQ_Handle * mq
Queue to notify about.
Definition: mq.c:668
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.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Entry in list of pending tasks.
Definition: scheduler.c:136
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model