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  enum GNUNET_MQ_Error error)
302 {
303  if (NULL == mq->error_handler)
304  {
306  "Got error %d, but no handler installed\n",
307  (int) error);
308  return;
309  }
311  error);
312 }
313 
314 
322 void
324 {
325  GNUNET_assert (NULL == ev->parent_queue);
326  GNUNET_free (ev);
327 }
328 
329 
336 unsigned int
338 {
339  if (GNUNET_YES != mq->in_flight)
340  {
341  return mq->queue_length;
342  }
343  return mq->queue_length - 1;
344 }
345 
346 
354 void
356  struct GNUNET_MQ_Envelope *ev)
357 {
358  GNUNET_assert (NULL != mq);
359  GNUNET_assert (NULL == ev->parent_queue);
360 
361  mq->queue_length++;
362  if (mq->queue_length >= 10000)
363  {
364  /* This would seem like a bug... */
366  "MQ with %u entries extended by message of type %u (FC broken?)\n",
367  (unsigned int) mq->queue_length,
368  (unsigned int) ntohs (ev->mh->type));
369  }
370  ev->parent_queue = mq;
371  /* is the implementation busy? queue it! */
372  if ((NULL != mq->current_envelope) || (NULL != mq->send_task))
373  {
375  mq->envelope_tail,
376  ev);
377  return;
378  }
379  GNUNET_assert (NULL == mq->envelope_head);
380  mq->current_envelope = ev;
381 
383  "sending message of type %u, queue empty (MQ: %p)\n",
384  ntohs (ev->mh->type),
385  mq);
386 
387  mq->send_impl (mq,
388  ev->mh,
389  mq->impl_state);
390 }
391 
392 
400 struct GNUNET_MQ_Envelope *
402 {
403  struct GNUNET_MQ_Envelope *env;
404 
405  env = mq->envelope_head;
407  mq->queue_length--;
408  env->parent_queue = NULL;
409  return env;
410 }
411 
412 
420 struct GNUNET_MQ_Envelope *
422 {
423  GNUNET_assert (NULL == env->next);
424  GNUNET_assert (NULL == env->parent_queue);
425  GNUNET_assert (NULL == env->sent_cb);
427  return GNUNET_MQ_msg_copy (env->mh);
428 }
429 
430 
438 void
440  const struct GNUNET_MQ_Envelope *ev)
441 {
442  struct GNUNET_MQ_Envelope *env;
443  uint16_t msize;
444 
445  msize = ntohs (ev->mh->size);
446  env = GNUNET_malloc (sizeof(struct GNUNET_MQ_Envelope) + msize);
447  env->mh = (struct GNUNET_MessageHeader *) &env[1];
448  env->sent_cb = ev->sent_cb;
449  env->sent_cls = ev->sent_cls;
450  GNUNET_memcpy (&env[1], ev->mh, msize);
451  GNUNET_MQ_send (mq, env);
452 }
453 
454 
462 static void
464 {
465  struct GNUNET_MQ_Handle *mq = cls;
466 
467  mq->send_task = NULL;
468  /* call is only valid if we're actually currently sending
469  * a message */
470  if (NULL == mq->envelope_head)
471  return;
474  mq->envelope_tail,
475  mq->current_envelope);
476 
478  "sending message of type %u from queue\n",
479  ntohs (mq->current_envelope->mh->type));
480 
481  mq->send_impl (mq,
482  mq->current_envelope->mh,
483  mq->impl_state);
484 }
485 
486 
494 void
496 {
497  struct GNUNET_MQ_Envelope *current_envelope;
499 
500  GNUNET_assert (0 < mq->queue_length);
501  mq->queue_length--;
502  mq->in_flight = GNUNET_NO;
503  current_envelope = mq->current_envelope;
504  current_envelope->parent_queue = NULL;
505  mq->current_envelope = NULL;
506  GNUNET_assert (NULL == mq->send_task);
508  if (NULL != (cb = current_envelope->sent_cb))
509  {
510  current_envelope->sent_cb = NULL;
511  cb (current_envelope->sent_cls);
512  }
513  GNUNET_free (current_envelope);
514 }
515 
516 
527 void
529 {
530  struct GNUNET_MQ_Envelope *current_envelope;
532 
533  mq->in_flight = GNUNET_YES;
534  /* call is only valid if we're actually currently sending
535  * a message */
536  current_envelope = mq->current_envelope;
537  GNUNET_assert (NULL != current_envelope);
538  /* can't call cancel from now on anymore */
539  current_envelope->parent_queue = NULL;
540  if (NULL != (cb = current_envelope->sent_cb))
541  {
542  current_envelope->sent_cb = NULL;
543  cb (current_envelope->sent_cls);
544  }
545 }
546 
547 
560 struct GNUNET_MQ_Handle *
563  GNUNET_MQ_CancelImpl cancel,
564  void *impl_state,
565  const struct GNUNET_MQ_MessageHandler *handlers,
567  void *error_handler_cls)
568 {
569  struct GNUNET_MQ_Handle *mq;
570 
571  mq = GNUNET_new (struct GNUNET_MQ_Handle);
572  mq->send_impl = send;
573  mq->destroy_impl = destroy;
574  mq->cancel_impl = cancel;
575  mq->handlers = GNUNET_MQ_copy_handlers (handlers);
578  mq->impl_state = impl_state;
579 
580  return mq;
581 }
582 
583 
591 void
593 {
594  if (NULL == mq->handlers)
595  return;
596  for (unsigned int i = 0; NULL != mq->handlers[i].cb; i++)
597  mq->handlers[i].cls = handlers_cls;
598 }
599 
600 
610 const struct GNUNET_MessageHeader *
612 {
613  GNUNET_assert (NULL != mq->current_envelope);
614  GNUNET_assert (NULL != mq->current_envelope->mh);
615  return mq->current_envelope->mh;
616 }
617 
618 
633 void *
635 {
636  return mq->impl_state;
637 }
638 
639 
640 struct GNUNET_MQ_Envelope *
641 GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type)
642 {
643  struct GNUNET_MQ_Envelope *ev;
644 
645  ev = GNUNET_malloc (size + sizeof(struct GNUNET_MQ_Envelope));
646  ev->mh = (struct GNUNET_MessageHeader *) &ev[1];
647  ev->mh->size = htons (size);
648  ev->mh->type = htons (type);
649  if (NULL != mhp)
650  *mhp = ev->mh;
651  return ev;
652 }
653 
654 
661 struct GNUNET_MQ_Envelope *
663 {
664  struct GNUNET_MQ_Envelope *mqm;
665  uint16_t size = ntohs (hdr->size);
666 
667  mqm = GNUNET_malloc (sizeof(*mqm) + size);
668  mqm->mh = (struct GNUNET_MessageHeader *) &mqm[1];
669  GNUNET_memcpy (mqm->mh, hdr, size);
670  return mqm;
671 }
672 
673 
683 struct GNUNET_MQ_Envelope *
685  uint16_t base_size,
686  uint16_t type,
687  const struct GNUNET_MessageHeader *nested_mh)
688 {
689  struct GNUNET_MQ_Envelope *mqm;
690  uint16_t size;
691 
692  if (NULL == nested_mh)
693  return GNUNET_MQ_msg_ (mhp, base_size, type);
694 
695  size = base_size + ntohs (nested_mh->size);
696 
697  /* check for uint16_t overflow */
698  if (size < base_size)
699  return NULL;
700 
701  mqm = GNUNET_MQ_msg_ (mhp, size, type);
702  GNUNET_memcpy ((char *) mqm->mh + base_size,
703  nested_mh,
704  ntohs (nested_mh->size));
705 
706  return mqm;
707 }
708 
709 
716 uint32_t
717 GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data)
718 {
719  uint32_t id;
720 
721  if (NULL == mq->assoc_map)
722  {
724  mq->assoc_id = 1;
725  }
726  id = mq->assoc_id++;
729  mq->assoc_map,
730  id,
731  assoc_data,
733  return id;
734 }
735 
736 
744 void *
745 GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
746 {
747  if (NULL == mq->assoc_map)
748  return NULL;
749  return GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id);
750 }
751 
752 
760 void *
761 GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
762 {
763  void *val;
764 
765  if (NULL == mq->assoc_map)
766  return NULL;
767  val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id);
769  return val;
770 }
771 
772 
782 void
785  void *cb_cls)
786 {
787  /* allow setting *OR* clearing callback */
788  GNUNET_assert ((NULL == ev->sent_cb) || (NULL == cb));
789  ev->sent_cb = cb;
790  ev->sent_cls = cb_cls;
791 }
792 
793 
799 {
804 
809 
814 
819 
823  void *cb_cls;
824 };
825 
826 
832 void
834 {
836 
837  if (NULL != mq->destroy_impl)
838  {
839  mq->destroy_impl (mq, mq->impl_state);
840  }
841  if (NULL != mq->send_task)
842  {
844  mq->send_task = NULL;
845  }
846  while (NULL != mq->envelope_head)
847  {
848  struct GNUNET_MQ_Envelope *ev;
849 
850  ev = mq->envelope_head;
851  ev->parent_queue = NULL;
853  GNUNET_assert (0 < mq->queue_length);
854  mq->queue_length--;
856  "MQ destroy drops message of type %u\n",
857  ntohs (ev->mh->type));
858  GNUNET_MQ_discard (ev);
859  }
860  if (NULL != mq->current_envelope)
861  {
862  /* we can only discard envelopes that
863  * are not queued! */
864  mq->current_envelope->parent_queue = NULL;
866  "MQ destroy drops current message of type %u\n",
867  ntohs (mq->current_envelope->mh->type));
869  mq->current_envelope = NULL;
870  GNUNET_assert (0 < mq->queue_length);
871  mq->queue_length--;
872  }
873  GNUNET_assert (0 == mq->queue_length);
874  while (NULL != (dnh = mq->dnh_head))
875  {
876  dnh->cb (dnh->cb_cls);
878  }
879  if (NULL != mq->assoc_map)
880  {
882  mq->assoc_map = NULL;
883  }
885  GNUNET_free (mq);
886 }
887 
888 
889 const struct GNUNET_MessageHeader *
891  uint16_t base_size)
892 {
893  uint16_t whole_size;
894  uint16_t nested_size;
895  const struct GNUNET_MessageHeader *nested_msg;
896 
897  whole_size = ntohs (mh->size);
898  GNUNET_assert (whole_size >= base_size);
899  nested_size = whole_size - base_size;
900  if (0 == nested_size)
901  return NULL;
902  if (nested_size < sizeof(struct GNUNET_MessageHeader))
903  {
904  GNUNET_break_op (0);
905  return NULL;
906  }
907  nested_msg = (const struct GNUNET_MessageHeader *) ((char *) mh + base_size);
908  if (ntohs (nested_msg->size) != nested_size)
909  {
910  GNUNET_break_op (0);
911  return NULL;
912  }
913  return nested_msg;
914 }
915 
916 
924 void
926 {
927  struct GNUNET_MQ_Handle *mq = ev->parent_queue;
928 
929  GNUNET_assert (NULL != mq);
930  GNUNET_assert (NULL != mq->cancel_impl);
931 
933 
934  if (mq->current_envelope == ev)
935  {
936  /* complex case, we already started with transmitting
937  the message using the callbacks. */
939  GNUNET_assert (0 < mq->queue_length);
940  mq->queue_length--;
941  mq->cancel_impl (mq,
942  mq->impl_state);
943  /* continue sending the next message, if any */
945  if (NULL != mq->current_envelope)
946  {
948  mq->envelope_tail,
949  mq->current_envelope);
950 
952  "sending canceled message of type %u queue\n",
953  ntohs (ev->mh->type));
954  mq->send_impl (mq,
955  mq->current_envelope->mh,
956  mq->impl_state);
957  }
958  }
959  else
960  {
961  /* simple case, message is still waiting in the queue */
963  mq->envelope_tail,
964  ev);
965  GNUNET_assert (0 < mq->queue_length);
966  mq->queue_length--;
967  }
968 
969  if (GNUNET_YES != mq->evacuate_called)
970  {
971  ev->parent_queue = NULL;
972  ev->mh = NULL;
973  /* also frees ev */
974  GNUNET_free (ev);
975  }
976 }
977 
978 
986 struct GNUNET_MQ_Envelope *
988 {
989  return mq->current_envelope;
990 }
991 
992 
999 struct GNUNET_MQ_Envelope *
1001 {
1002  if (NULL != mq->envelope_tail)
1003  return mq->envelope_tail;
1004 
1005  return mq->current_envelope;
1006 }
1007 
1008 
1017 void
1020 {
1021  env->priority = pp;
1023 }
1024 
1025 
1034 {
1035  struct GNUNET_MQ_Handle *mq = env->parent_queue;
1036 
1037  if (GNUNET_YES == env->have_custom_options)
1038  return env->priority;
1039  if (NULL == mq)
1040  return 0;
1041  return mq->priority;
1042 }
1043 
1044 
1056 {
1058 
1059  ret = GNUNET_MAX (p1 & GNUNET_MQ_PRIORITY_MASK, p2 & GNUNET_MQ_PRIORITY_MASK);
1060  ret |= ((p1 & GNUNET_MQ_PREF_UNRELIABLE) & (p2 & GNUNET_MQ_PREF_UNRELIABLE));
1061  ret |=
1063  ret |=
1065  ret |= ((p1 & GNUNET_MQ_PREF_GOODPUT) & (p2 & GNUNET_MQ_PREF_GOODPUT));
1066  ret |=
1068  return ret;
1069 }
1070 
1071 
1078 void
1081 {
1082  mq->priority = pp;
1083 }
1084 
1085 
1092 const struct GNUNET_MessageHeader *
1094 {
1095  return env->mh;
1096 }
1097 
1098 
1105 const struct GNUNET_MQ_Envelope *
1107 {
1108  return env->next;
1109 }
1110 
1111 
1124  void *cb_cls)
1125 {
1127 
1129  dnh->mq = mq;
1130  dnh->cb = cb;
1131  dnh->cb_cls = cb_cls;
1133  return dnh;
1134 }
1135 
1136 
1142 void
1145 {
1146  struct GNUNET_MQ_Handle *mq = dnh->mq;
1147 
1149  GNUNET_free (dnh);
1150 }
1151 
1152 
1165 void
1167  struct GNUNET_MQ_Envelope **env_tail,
1168  struct GNUNET_MQ_Envelope *env)
1169 {
1170  GNUNET_CONTAINER_DLL_insert (*env_head, *env_tail, env);
1171 }
1172 
1173 
1186 void
1188  struct GNUNET_MQ_Envelope **env_tail,
1189  struct GNUNET_MQ_Envelope *env)
1190 {
1191  GNUNET_CONTAINER_DLL_insert_tail (*env_head, *env_tail, env);
1192 }
1193 
1194 
1207 void
1209  struct GNUNET_MQ_Envelope **env_tail,
1210  struct GNUNET_MQ_Envelope *env)
1211 {
1212  GNUNET_CONTAINER_DLL_remove (*env_head, *env_tail, env);
1213 }
1214 
1215 
1226 struct GNUNET_MQ_MessageHandler *
1228 {
1229  struct GNUNET_MQ_MessageHandler *copy;
1230  unsigned int count;
1231 
1232  if (NULL == handlers)
1233  return NULL;
1234 
1235  count = GNUNET_MQ_count_handlers (handlers);
1236  copy = GNUNET_new_array (count + 1, struct GNUNET_MQ_MessageHandler);
1237  GNUNET_memcpy (copy,
1238  handlers,
1239  count * sizeof(struct GNUNET_MQ_MessageHandler));
1240  return copy;
1241 }
1242 
1243 
1256 struct GNUNET_MQ_MessageHandler *
1258  GNUNET_MQ_MessageCallback agpl_handler,
1259  void *agpl_cls)
1260 {
1261  struct GNUNET_MQ_MessageHandler *copy;
1262  unsigned int count;
1263 
1264  if (NULL == handlers)
1265  return NULL;
1266  count = GNUNET_MQ_count_handlers (handlers);
1267  copy = GNUNET_new_array (count + 2, struct GNUNET_MQ_MessageHandler);
1268  GNUNET_memcpy (copy,
1269  handlers,
1270  count * sizeof(struct GNUNET_MQ_MessageHandler));
1271  copy[count].mv = NULL;
1272  copy[count].cb = agpl_handler;
1273  copy[count].cls = agpl_cls;
1274  copy[count].type = GNUNET_MESSAGE_TYPE_REQUEST_AGPL;
1275  copy[count].expected_size = sizeof(struct GNUNET_MessageHeader);
1276  return copy;
1277 }
1278 
1279 
1286 unsigned int
1288 {
1289  unsigned int i;
1290 
1291  if (NULL == handlers)
1292  return 0;
1293 
1294  for (i = 0; NULL != handlers[i].cb; i++)
1295  ;
1296 
1297  return i;
1298 }
1299 
1300 
1307 const char *
1309 {
1310  switch (type)
1311  {
1313  return "NONE";
1314 
1316  return "BANDWIDTH";
1317 
1319  return "LATENCY";
1320 
1322  return "RELIABILITY";
1323  }
1324  ;
1325  return NULL;
1326 }
1327 
1328 
1329 /* 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:1187
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:1054
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:1000
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:1166
Handle we return for callbacks registered to be notified when GNUNET_MQ_destroy() is called on a queu...
Definition: mq.c:798
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:662
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:1122
const struct GNUNET_MessageHeader * GNUNET_MQ_env_get_msg(const struct GNUNET_MQ_Envelope *env)
Obtain message contained in envelope.
Definition: mq.c:1093
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:717
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:1227
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:1018
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
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.
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:611
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:1106
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:1033
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:592
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:528
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:561
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:783
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:684
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:337
GNUNET_SCHEDULER_TaskCallback cb
Function to call.
Definition: mq.c:818
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:95
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:1298
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:634
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:1257
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:641
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:1208
unsigned int GNUNET_MQ_count_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Count the handlers in a handler array.
Definition: mq.c:1287
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:323
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
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_MQ_Handle * mq
Queue to notify about.
Definition: mq.c:813
#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:463
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:1079
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:1308
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:761
struct GNUNET_MQ_DestroyNotificationHandle * next
Kept in a DLL.
Definition: mq.c:808
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:439
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:1143
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:890
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:987
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:833
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:355
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:401
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:421
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:495
void GNUNET_MQ_send_cancel(struct GNUNET_MQ_Envelope *ev)
Cancel sending the message.
Definition: mq.c:925
struct GNUNET_MQ_DestroyNotificationHandle * prev
Kept in a DLL.
Definition: mq.c:803
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:823
#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:745
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:974
The preferred transmission for this envelope foces on reliability.