GNUnet  0.11.x
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 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 
29 #define LOG(kind, ...) GNUNET_log_from (kind, "util-mq", __VA_ARGS__)
30 
31 
33 {
39 
45 
52 
57 
62 
66  void *sent_cls;
67 
74 
79 };
80 
81 
86 {
91 
97 
102 
107 
111  void *impl_state;
112 
117 
122 
127 
132 
137 
144 
149 
154 
159 
165 
171  uint32_t assoc_id;
172 
176  unsigned int queue_length;
177 
183 
188 };
189 
190 
201 void
203  const struct GNUNET_MessageHeader *mh)
204 {
205  int ret;
206 
207  ret = GNUNET_MQ_handle_message (mq->handlers, mh);
208  if (GNUNET_SYSERR == ret)
209  {
211  return;
212  }
213 }
214 
215 
228 int
230  const struct GNUNET_MessageHeader *mh)
231 {
232  const struct GNUNET_MQ_MessageHandler *handler;
233  int handled = GNUNET_NO;
234  uint16_t msize = ntohs (mh->size);
235  uint16_t mtype = ntohs (mh->type);
236 
238  "Received message of type %u and size %u\n",
239  mtype,
240  msize);
241 
242  if (NULL == handlers)
243  goto done;
244  for (handler = handlers; NULL != handler->cb; handler++)
245  {
246  if (handler->type == mtype)
247  {
248  handled = GNUNET_YES;
249  if ((handler->expected_size > msize) ||
250  ((handler->expected_size != msize) && (NULL == handler->mv)))
251  {
252  /* Too small, or not an exact size and
253  no 'mv' handler to check rest */
255  "Received malformed message of type %u\n",
256  (unsigned int) handler->type);
257  return GNUNET_SYSERR;
258  }
259  if ((NULL == handler->mv) ||
260  (GNUNET_OK == handler->mv (handler->cls, mh)))
261  {
262  /* message well-formed, pass to handler */
263  handler->cb (handler->cls, mh);
264  }
265  else
266  {
267  /* Message rejected by check routine */
269  "Received malformed message of type %u\n",
270  (unsigned int) handler->type);
271  return GNUNET_SYSERR;
272  }
273  break;
274  }
275  }
276 done:
277  if (GNUNET_NO == handled)
278  {
280  "No handler for message of type %u and size %u\n",
281  mtype,
282  msize);
283  return GNUNET_NO;
284  }
285  return GNUNET_OK;
286 }
287 
288 
299 void
301 {
302  if (NULL == mq->error_handler)
303  {
305  "Got error %d, but no handler installed\n",
306  (int) error);
307  return;
308  }
309  mq->error_handler (mq->error_handler_cls, error);
310 }
311 
312 
320 void
322 {
323  GNUNET_assert (NULL == ev->parent_queue);
324  GNUNET_free (ev);
325 }
326 
327 
334 unsigned int
336 {
337  if (GNUNET_YES != mq->in_flight)
338  {
339  return mq->queue_length;
340  }
341  return mq->queue_length - 1;
342 }
343 
344 
352 void
354 {
355  GNUNET_assert (NULL != mq);
356  GNUNET_assert (NULL == ev->parent_queue);
357 
358  mq->queue_length++;
359  if (mq->queue_length >= 10000)
360  {
361  /* This would seem like a bug... */
363  "MQ with %u entries extended by message of type %u (FC broken?)\n",
364  (unsigned int) mq->queue_length,
365  (unsigned int) ntohs (ev->mh->type));
366  }
367  ev->parent_queue = mq;
368  /* is the implementation busy? queue it! */
369  if ((NULL != mq->current_envelope) || (NULL != mq->send_task))
370  {
372  return;
373  }
374  GNUNET_assert (NULL == mq->envelope_head);
375  mq->current_envelope = ev;
376 
378  "sending message of type %u, queue empty (MQ: %p)\n",
379  ntohs (ev->mh->type),
380  mq);
381 
382  mq->send_impl (mq, ev->mh, mq->impl_state);
383 }
384 
385 
393 struct GNUNET_MQ_Envelope *
395 {
396  struct GNUNET_MQ_Envelope *env;
397 
398  env = mq->envelope_head;
400  mq->queue_length--;
401  env->parent_queue = NULL;
402  return env;
403 }
404 
405 
413 struct GNUNET_MQ_Envelope *
415 {
416  GNUNET_assert (NULL == env->next);
417  GNUNET_assert (NULL == env->parent_queue);
418  GNUNET_assert (NULL == env->sent_cb);
420  return GNUNET_MQ_msg_copy (env->mh);
421 }
422 
423 
431 void
433  const struct GNUNET_MQ_Envelope *ev)
434 {
435  struct GNUNET_MQ_Envelope *env;
436  uint16_t msize;
437 
438  msize = ntohs (ev->mh->size);
439  env = GNUNET_malloc (sizeof(struct GNUNET_MQ_Envelope) + msize);
440  env->mh = (struct GNUNET_MessageHeader *) &env[1];
441  env->sent_cb = ev->sent_cb;
442  env->sent_cls = ev->sent_cls;
443  GNUNET_memcpy (&env[1], ev->mh, msize);
444  GNUNET_MQ_send (mq, env);
445 }
446 
447 
455 static void
457 {
458  struct GNUNET_MQ_Handle *mq = cls;
459 
460  mq->send_task = NULL;
461  /* call is only valid if we're actually currently sending
462  * a message */
463  if (NULL == mq->envelope_head)
464  return;
467  mq->envelope_tail,
468  mq->current_envelope);
469 
471  "sending message of type %u from queue\n",
472  ntohs (mq->current_envelope->mh->type));
473 
474  mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state);
475 }
476 
477 
485 void
487 {
488  struct GNUNET_MQ_Envelope *current_envelope;
490 
491  GNUNET_assert (0 < mq->queue_length);
492  mq->queue_length--;
493  mq->in_flight = GNUNET_NO;
494  current_envelope = mq->current_envelope;
495  current_envelope->parent_queue = NULL;
496  mq->current_envelope = NULL;
497  GNUNET_assert (NULL == mq->send_task);
499  if (NULL != (cb = current_envelope->sent_cb))
500  {
501  current_envelope->sent_cb = NULL;
502  cb (current_envelope->sent_cls);
503  }
504  GNUNET_free (current_envelope);
505 }
506 
507 
518 void
520 {
521  struct GNUNET_MQ_Envelope *current_envelope;
523 
524  mq->in_flight = GNUNET_YES;
525  /* call is only valid if we're actually currently sending
526  * a message */
527  current_envelope = mq->current_envelope;
528  GNUNET_assert (NULL != current_envelope);
529  /* can't call cancel from now on anymore */
530  current_envelope->parent_queue = NULL;
531  if (NULL != (cb = current_envelope->sent_cb))
532  {
533  current_envelope->sent_cb = NULL;
534  cb (current_envelope->sent_cls);
535  }
536 }
537 
538 
551 struct GNUNET_MQ_Handle *
554  GNUNET_MQ_CancelImpl cancel,
555  void *impl_state,
556  const struct GNUNET_MQ_MessageHandler *handlers,
558  void *error_handler_cls)
559 {
560  struct GNUNET_MQ_Handle *mq;
561 
562  mq = GNUNET_new (struct GNUNET_MQ_Handle);
563  mq->send_impl = send;
564  mq->destroy_impl = destroy;
565  mq->cancel_impl = cancel;
566  mq->handlers = GNUNET_MQ_copy_handlers (handlers);
569  mq->impl_state = impl_state;
570 
571  return mq;
572 }
573 
574 
582 void
584 {
585  if (NULL == mq->handlers)
586  return;
587  for (unsigned int i = 0; NULL != mq->handlers[i].cb; i++)
588  mq->handlers[i].cls = handlers_cls;
589 }
590 
591 
601 const struct GNUNET_MessageHeader *
603 {
604  GNUNET_assert (NULL != mq->current_envelope);
605  GNUNET_assert (NULL != mq->current_envelope->mh);
606  return mq->current_envelope->mh;
607 }
608 
609 
624 void *
626 {
627  return mq->impl_state;
628 }
629 
630 
631 struct GNUNET_MQ_Envelope *
632 GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type)
633 {
634  struct GNUNET_MQ_Envelope *ev;
635 
636  ev = GNUNET_malloc (size + sizeof(struct GNUNET_MQ_Envelope));
637  ev->mh = (struct GNUNET_MessageHeader *) &ev[1];
638  ev->mh->size = htons (size);
639  ev->mh->type = htons (type);
640  if (NULL != mhp)
641  *mhp = ev->mh;
642  return ev;
643 }
644 
645 
652 struct GNUNET_MQ_Envelope *
654 {
655  struct GNUNET_MQ_Envelope *mqm;
656  uint16_t size = ntohs (hdr->size);
657 
658  mqm = GNUNET_malloc (sizeof(*mqm) + size);
659  mqm->mh = (struct GNUNET_MessageHeader *) &mqm[1];
660  GNUNET_memcpy (mqm->mh, hdr, size);
661  return mqm;
662 }
663 
664 
674 struct GNUNET_MQ_Envelope *
676  uint16_t base_size,
677  uint16_t type,
678  const struct GNUNET_MessageHeader *nested_mh)
679 {
680  struct GNUNET_MQ_Envelope *mqm;
681  uint16_t size;
682 
683  if (NULL == nested_mh)
684  return GNUNET_MQ_msg_ (mhp, base_size, type);
685 
686  size = base_size + ntohs (nested_mh->size);
687 
688  /* check for uint16_t overflow */
689  if (size < base_size)
690  return NULL;
691 
692  mqm = GNUNET_MQ_msg_ (mhp, size, type);
693  GNUNET_memcpy ((char *) mqm->mh + base_size,
694  nested_mh,
695  ntohs (nested_mh->size));
696 
697  return mqm;
698 }
699 
700 
707 uint32_t
708 GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data)
709 {
710  uint32_t id;
711 
712  if (NULL == mq->assoc_map)
713  {
715  mq->assoc_id = 1;
716  }
717  id = mq->assoc_id++;
720  mq->assoc_map,
721  id,
722  assoc_data,
724  return id;
725 }
726 
727 
735 void *
736 GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
737 {
738  if (NULL == mq->assoc_map)
739  return NULL;
740  return GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id);
741 }
742 
743 
751 void *
752 GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
753 {
754  void *val;
755 
756  if (NULL == mq->assoc_map)
757  return NULL;
758  val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id);
760  return val;
761 }
762 
763 
773 void
776  void *cb_cls)
777 {
778  /* allow setting *OR* clearing callback */
779  GNUNET_assert ((NULL == ev->sent_cb) || (NULL == cb));
780  ev->sent_cb = cb;
781  ev->sent_cls = cb_cls;
782 }
783 
784 
790 {
795 
800 
805 
810 
814  void *cb_cls;
815 };
816 
817 
823 void
825 {
827 
828  if (NULL != mq->destroy_impl)
829  {
830  mq->destroy_impl (mq, mq->impl_state);
831  }
832  if (NULL != mq->send_task)
833  {
835  mq->send_task = NULL;
836  }
837  while (NULL != mq->envelope_head)
838  {
839  struct GNUNET_MQ_Envelope *ev;
840 
841  ev = mq->envelope_head;
842  ev->parent_queue = NULL;
844  GNUNET_assert (0 < mq->queue_length);
845  mq->queue_length--;
847  "MQ destroy drops message of type %u\n",
848  ntohs (ev->mh->type));
849  GNUNET_MQ_discard (ev);
850  }
851  if (NULL != mq->current_envelope)
852  {
853  /* we can only discard envelopes that
854  * are not queued! */
855  mq->current_envelope->parent_queue = NULL;
857  "MQ destroy drops current message of type %u\n",
858  ntohs (mq->current_envelope->mh->type));
860  mq->current_envelope = NULL;
861  GNUNET_assert (0 < mq->queue_length);
862  mq->queue_length--;
863  }
864  GNUNET_assert (0 == mq->queue_length);
865  while (NULL != (dnh = mq->dnh_head))
866  {
867  dnh->cb (dnh->cb_cls);
869  }
870  if (NULL != mq->assoc_map)
871  {
873  mq->assoc_map = NULL;
874  }
876  GNUNET_free (mq);
877 }
878 
879 
880 const struct GNUNET_MessageHeader *
882  uint16_t base_size)
883 {
884  uint16_t whole_size;
885  uint16_t nested_size;
886  const struct GNUNET_MessageHeader *nested_msg;
887 
888  whole_size = ntohs (mh->size);
889  GNUNET_assert (whole_size >= base_size);
890  nested_size = whole_size - base_size;
891  if (0 == nested_size)
892  return NULL;
893  if (nested_size < sizeof(struct GNUNET_MessageHeader))
894  {
895  GNUNET_break_op (0);
896  return NULL;
897  }
898  nested_msg = (const struct GNUNET_MessageHeader *) ((char *) mh + base_size);
899  if (ntohs (nested_msg->size) != nested_size)
900  {
901  GNUNET_break_op (0);
902  return NULL;
903  }
904  return nested_msg;
905 }
906 
907 
915 void
917 {
918  struct GNUNET_MQ_Handle *mq = ev->parent_queue;
919 
920  GNUNET_assert (NULL != mq);
921  GNUNET_assert (NULL != mq->cancel_impl);
922 
924 
925  if (mq->current_envelope == ev)
926  {
927  /* complex case, we already started with transmitting
928  the message using the callbacks. */
930  GNUNET_assert (0 < mq->queue_length);
931  mq->queue_length--;
932  mq->cancel_impl (mq, mq->impl_state);
933  /* continue sending the next message, if any */
935  if (NULL != mq->current_envelope)
936  {
938  mq->envelope_tail,
939  mq->current_envelope);
940 
942  "sending canceled message of type %u queue\n",
943  ntohs (ev->mh->type));
944 
945  mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state);
946  }
947  }
948  else
949  {
950  /* simple case, message is still waiting in the queue */
952  GNUNET_assert (0 < mq->queue_length);
953  mq->queue_length--;
954  }
955 
956  if (GNUNET_YES != mq->evacuate_called)
957  {
958  ev->parent_queue = NULL;
959  ev->mh = NULL;
960  /* also frees ev */
961  GNUNET_free (ev);
962  }
963 }
964 
965 
973 struct GNUNET_MQ_Envelope *
975 {
976  return mq->current_envelope;
977 }
978 
979 
986 struct GNUNET_MQ_Envelope *
988 {
989  if (NULL != mq->envelope_tail)
990  return mq->envelope_tail;
991 
992  return mq->current_envelope;
993 }
994 
995 
1004 void
1007 {
1008  env->priority = pp;
1010 }
1011 
1012 
1021 {
1022  struct GNUNET_MQ_Handle *mq = env->parent_queue;
1023 
1024  if (GNUNET_YES == env->have_custom_options)
1025  return env->priority;
1026  if (NULL == mq)
1027  return 0;
1028  return mq->priority;
1029 }
1030 
1031 
1043 {
1045 
1046  ret = GNUNET_MAX (p1 & GNUNET_MQ_PRIORITY_MASK, p2 & GNUNET_MQ_PRIORITY_MASK);
1047  ret |= ((p1 & GNUNET_MQ_PREF_UNRELIABLE) & (p2 & GNUNET_MQ_PREF_UNRELIABLE));
1048  ret |=
1050  ret |=
1052  ret |= ((p1 & GNUNET_MQ_PREF_GOODPUT) & (p2 & GNUNET_MQ_PREF_GOODPUT));
1053  ret |=
1055  return ret;
1056 }
1057 
1058 
1065 void
1068 {
1069  mq->priority = pp;
1070 }
1071 
1072 
1079 const struct GNUNET_MessageHeader *
1081 {
1082  return env->mh;
1083 }
1084 
1085 
1092 const struct GNUNET_MQ_Envelope *
1094 {
1095  return env->next;
1096 }
1097 
1098 
1111  void *cb_cls)
1112 {
1114 
1116  dnh->mq = mq;
1117  dnh->cb = cb;
1118  dnh->cb_cls = cb_cls;
1120  return dnh;
1121 }
1122 
1123 
1129 void
1132 {
1133  struct GNUNET_MQ_Handle *mq = dnh->mq;
1134 
1136  GNUNET_free (dnh);
1137 }
1138 
1139 
1152 void
1154  struct GNUNET_MQ_Envelope **env_tail,
1155  struct GNUNET_MQ_Envelope *env)
1156 {
1157  GNUNET_CONTAINER_DLL_insert (*env_head, *env_tail, env);
1158 }
1159 
1160 
1173 void
1175  struct GNUNET_MQ_Envelope **env_tail,
1176  struct GNUNET_MQ_Envelope *env)
1177 {
1178  GNUNET_CONTAINER_DLL_insert_tail (*env_head, *env_tail, env);
1179 }
1180 
1181 
1194 void
1196  struct GNUNET_MQ_Envelope **env_tail,
1197  struct GNUNET_MQ_Envelope *env)
1198 {
1199  GNUNET_CONTAINER_DLL_remove (*env_head, *env_tail, env);
1200 }
1201 
1202 
1213 struct GNUNET_MQ_MessageHandler *
1215 {
1216  struct GNUNET_MQ_MessageHandler *copy;
1217  unsigned int count;
1218 
1219  if (NULL == handlers)
1220  return NULL;
1221 
1222  count = GNUNET_MQ_count_handlers (handlers);
1223  copy = GNUNET_new_array (count + 1, struct GNUNET_MQ_MessageHandler);
1224  GNUNET_memcpy (copy,
1225  handlers,
1226  count * sizeof(struct GNUNET_MQ_MessageHandler));
1227  return copy;
1228 }
1229 
1230 
1243 struct GNUNET_MQ_MessageHandler *
1245  GNUNET_MQ_MessageCallback agpl_handler,
1246  void *agpl_cls)
1247 {
1248  struct GNUNET_MQ_MessageHandler *copy;
1249  unsigned int count;
1250 
1251  if (NULL == handlers)
1252  return NULL;
1253  count = GNUNET_MQ_count_handlers (handlers);
1254  copy = GNUNET_new_array (count + 2, struct GNUNET_MQ_MessageHandler);
1255  GNUNET_memcpy (copy,
1256  handlers,
1257  count * sizeof(struct GNUNET_MQ_MessageHandler));
1258  copy[count].mv = NULL;
1259  copy[count].cb = agpl_handler;
1260  copy[count].cls = agpl_cls;
1261  copy[count].type = GNUNET_MESSAGE_TYPE_REQUEST_AGPL;
1262  copy[count].expected_size = sizeof(struct GNUNET_MessageHeader);
1263  return copy;
1264 }
1265 
1266 
1273 unsigned int
1275 {
1276  unsigned int i;
1277 
1278  if (NULL == handlers)
1279  return 0;
1280 
1281  for (i = 0; NULL != handlers[i].cb; i++)
1282  ;
1283 
1284  return i;
1285 }
1286 
1287 
1294 const char *
1296 {
1297  switch (type)
1298  {
1300  return "NONE";
1301 
1303  return "BANDWIDTH";
1304 
1306  return "LATENCY";
1307 
1309  return "RELIABILITY";
1310  }
1311  ;
1312  return NULL;
1313 }
1314 
1315 
1316 /* end of mq.c */
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
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:1174
struct GNUNET_MQ_MessageHandler * handlers
Handlers array, or NULL if the queue should not receive messages.
Definition: mq.c:90
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:1041
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:987
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:1153
Handle we return for callbacks registered to be notified when GNUNET_MQ_destroy() is called on a queu...
Definition: mq.c:789
struct GNUNET_MessageHeader * mh
Actual allocated message header.
Definition: mq.c:51
static void done()
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:653
void * impl_state
Implementation-specific state.
Definition: mq.c:111
unsigned int queue_length
Number of entries we have in the envelope-DLL.
Definition: mq.c:176
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:1109
const struct GNUNET_MessageHeader * GNUNET_MQ_env_get_msg(const struct GNUNET_MQ_Envelope *env)
Obtain message contained in envelope.
Definition: mq.c:1080
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:300
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_MQ_DestroyNotificationHandle * dnh_tail
Functions to call on queue destruction; kept in a DLL.
Definition: mq.c:158
uint16_t expected_size
Expected size of messages of this type.
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:708
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...
GNUNET_MQ_Error
Error codes for the queue.
int have_custom_options
Did the application call GNUNET_MQ_env_set_options()?
Definition: mq.c:78
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
Definition: mq.c:1214
int evacuate_called
GNUNET_YES if GNUNET_MQ_impl_evacuate was called.
Definition: mq.c:182
#define GNUNET_MESSAGE_TYPE_REQUEST_AGPL
Message to request source code link.
void GNUNET_MQ_env_set_options(struct GNUNET_MQ_Envelope *env, enum GNUNET_MQ_PriorityPreferences pp)
Set application-specific preferences for this envelope.
Definition: mq.c:1005
No preference was expressed.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
int 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:229
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
GNUNET_MQ_PriorityPreferences
Per envelope preferences and priorities.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
const struct GNUNET_MessageHeader * GNUNET_MQ_impl_current(struct GNUNET_MQ_Handle *mq)
Get the message that should currently be sent.
Definition: mq.c:602
int 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.
const struct GNUNET_MQ_Envelope * GNUNET_MQ_env_next(const struct GNUNET_MQ_Envelope *env)
Return next envelope in queue.
Definition: mq.c:1093
int GNUNET_CONTAINER_multihashmap32_remove_all(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
Remove all entries for the given key from the map.
struct GNUNET_MQ_Envelope * envelope_tail
Linked list of messages pending to be sent.
Definition: mq.c:136
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
GNUNET_MQ_SendImpl send_impl
Actual implementation of message sending, called when a message is added.
Definition: mq.c:96
Flag to indicate that low latency is important.
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_get_options(struct GNUNET_MQ_Envelope *env)
Get application-specific options for this envelope.
Definition: mq.c:1020
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:583
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 GNU...
Definition: mq.c:519
int in_flight
GNUNET_YES if GNUNET_MQ_impl_send_in_flight() was called.
Definition: mq.c:187
uint16_t type
Type of the message this handler covers, in host byte order.
Flag to indicate that high bandwidth is desired.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
GNUNET_MQ_ErrorHandler error_handler
Callback will be called when an error occurs.
Definition: mq.c:116
GNUNET_MQ_PreferenceKind
Enum defining all known preference categories.
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:552
void * cls
Closure for mv and cb.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
GNUNET_SCHEDULER_TaskCallback sent_cb
Called after the message was sent irrevocably.
Definition: mq.c:61
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:774
GNUNET_MQ_MessageValidationCallback mv
Callback to validate a message of the specified type.
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:675
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.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:335
GNUNET_SCHEDULER_TaskCallback cb
Function to call.
Definition: mq.c:809
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:82
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:1280
GNUNET_MQ_DestroyImpl destroy_impl
Implementation-dependent queue destruction function.
Definition: mq.c:101
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
The preferred transmission for this envelope focuses on maximizing bandwidth.
void * GNUNET_MQ_impl_state(struct GNUNET_MQ_Handle *mq)
Get the implementation state associated with the message queue.
Definition: mq.c:625
void(* GNUNET_MQ_DestroyImpl)(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
GNUNET_MQ_MessageCallback cb
Callback, called every time a new message of the specified type has been receied. ...
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:202
We received a message that was malformed and thus could not be passed to its handler.
enum GNUNET_MQ_PriorityPreferences priority
Flags that were set for this queue by GNUNET_MQ_set_options().
Definition: mq.c:164
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:1244
Internal representation of the hash map.
struct GNUNET_SCHEDULER_Task * send_task
Task to asynchronously run impl_send_continue().
Definition: mq.c:126
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_(struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type)
Create a new envelope.
Definition: mq.c:632
struct GNUNET_MQ_DestroyNotificationHandle * dnh_head
Functions to call on queue destruction; kept in a DLL.
Definition: mq.c:153
Message handler for a specific message type.
struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
struct GNUNET_MQ_Envelope * prev
Messages are stored in a linked list Each queue has its own list of envelopes.
Definition: mq.c:44
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:1195
unsigned int GNUNET_MQ_count_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Count the handlers in a handler array.
Definition: mq.c:1274
void GNUNET_CONTAINER_multihashmap32_destroy(struct GNUNET_CONTAINER_MultiHashMap32 *map)
Destroy a 32-bit key hash map.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *ev)
Discard the message queue message, free all allocated resources.
Definition: mq.c:321
void * sent_cls
Closure for send_cb.
Definition: mq.c:66
There must only be one value per key; storing a value should fail if a value under the same key alrea...
GNUNET_MQ_CancelImpl cancel_impl
Implementation-dependent send cancel function.
Definition: mq.c:106
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_MQ_Handle * mq
Queue to notify about.
Definition: mq.c:804
#define LOG(kind,...)
Definition: mq.c:29
struct GNUNET_MQ_Envelope * next
Messages are stored in a linked list.
Definition: mq.c:38
void * error_handler_cls
Closure for the error handler.
Definition: mq.c:121
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:171
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void(* GNUNET_MQ_CancelImpl)(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static void impl_send_continue(void *cls)
Task run to call the send implementation for the next queued message, if any.
Definition: mq.c:456
Bit mask to apply to extract the priority bits.
void(* GNUNET_MQ_MessageCallback)(void *cls, const struct GNUNET_MessageHeader *msg)
Called when a message has been received.
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
We encountered an error handling the MQ to the ATS service.
Handle to a message queue.
Definition: mq.c:85
struct GNUNET_MQ_Handle * parent_queue
Queue the message is queued in, NULL if message is not queued.
Definition: mq.c:56
void GNUNET_MQ_set_options(struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_PriorityPreferences pp)
Set application-specific default options for this queue.
Definition: mq.c:1066
struct GNUNET_CONTAINER_MultiHashMap32 * assoc_map
Map of associations, lazily allocated.
Definition: mq.c:148
const char * GNUNET_MQ_preference_to_string(enum GNUNET_MQ_PreferenceKind type)
Convert an enum GNUNET_MQ_PreferenceType to a string.
Definition: mq.c:1295
enum GNUNET_MQ_PriorityPreferences priority
Flags that were set for this envelope by GNUNET_MQ_env_set_options().
Definition: mq.c:73
void * GNUNET_MQ_assoc_remove(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
Remove the association for a request_id.
Definition: mq.c:752
struct GNUNET_MQ_DestroyNotificationHandle * next
Kept in a DLL.
Definition: mq.c:799
struct GNUNET_MQ_Envelope * current_envelope
Message that is currently scheduled to be sent.
Definition: mq.c:143
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. ...
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:432
The preferred transmission for this envelope foces on minimizing latency.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
Flag to indicate that out-of-order delivery is OK.
void GNUNET_MQ_destroy_notify_cancel(struct GNUNET_MQ_DestroyNotificationHandle *dnh)
Cancel registration from GNUNET_MQ_destroy_notify().
Definition: mq.c:1130
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:881
Flag to indicate that CORKing is acceptable.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Header for all communications.
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:974
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_YES
Definition: gnunet_common.h:77
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:353
Flag to indicate that unreliable delivery is acceptable.
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:394
static void destroy(void *cls)
struct GNUNET_MQ_Envelope * GNUNET_MQ_env_copy(struct GNUNET_MQ_Envelope *env)
Function to copy an envelope.
Definition: mq.c:414
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:486
void GNUNET_MQ_send_cancel(struct GNUNET_MQ_Envelope *ev)
Cancel sending the message.
Definition: mq.c:916
struct GNUNET_MQ_DestroyNotificationHandle * prev
Kept in a DLL.
Definition: mq.c:794
struct GNUNET_MQ_Envelope * envelope_head
Linked list of messages pending to be sent.
Definition: mq.c:131
void * cb_cls
Closure for cb.
Definition: mq.c:814
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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:736
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
The preferred transmission for this envelope foces on reliability.