use namestore API for zone import instead of using plugin directly
[oweals/gnunet.git] / src / include / gnunet_mq_lib.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2012-2016 GNUnet e.V.
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @author Florian Dold
23  * @author Christian Grothoff
24  *
25  * @file
26  * General-purpose message queue
27  *
28  * @defgroup mq  MQ library
29  * General-purpose message queue
30  *
31  * @see [Documentation](https://gnunet.org/message-queue-api)
32  *
33  * @{
34  */
35 #ifndef GNUNET_MQ_LIB_H
36 #define GNUNET_MQ_LIB_H
37
38 #include "gnunet_scheduler_lib.h"
39
40 /**
41  * Allocate an envelope, with extra space allocated after the space needed
42  * by the message struct.
43  * The allocated message will already have the type and size field set.
44  *
45  * @param mvar variable to store the allocated message in;
46  *             must have a header field;
47  *             can be NULL
48  * @param esize extra space to allocate after the message
49  * @param type type of the message
50  * @return the MQ message
51  */
52 #define GNUNET_MQ_msg_extra(mvar, esize, type) GNUNET_MQ_msg_(((struct GNUNET_MessageHeader**) &(mvar)), (esize) + sizeof *(mvar), (type))
53
54 /**
55  * Allocate a GNUNET_MQ_Envelope.
56  * The contained message will already have the type and size field set.
57  *
58  * @param mvar variable to store the allocated message in;
59  *             must have a header field;
60  *             can be NULL
61  * @param type type of the message
62  * @return the allocated envelope
63  */
64 #define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra(mvar, 0, type)
65
66
67 /**
68  * Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
69  * The allocated message will already have the type and size field set.
70  *
71  * @param type type of the message
72  */
73 #define GNUNET_MQ_msg_header(type) GNUNET_MQ_msg_ (NULL, sizeof (struct GNUNET_MessageHeader), type)
74
75
76 /**
77  * Allocate a GNUNET_MQ_Envelope, where the message only consists of a header and extra space.
78  * The allocated message will already have the type and size field set.
79  *
80  * @param mh pointer that will changed to point at to the allocated message header
81  * @param esize extra space to allocate after the message header
82  * @param type type of the message
83  */
84 #define GNUNET_MQ_msg_header_extra(mh, esize, type) GNUNET_MQ_msg_ (&mh, (esize) + sizeof (struct GNUNET_MessageHeader), type)
85
86
87 /**
88  * Allocate a GNUNET_MQ_Envelope, and append a payload message after the given
89  * message struct.
90  *
91  * @param mvar pointer to a message struct, will be changed to point at the newly allocated message,
92  *        whose size is 'sizeof(*mvar) + ntohs (mh->size)'
93  * @param type message type of the allocated message, has no effect on the nested message
94  * @param mh message to nest
95  * @return a newly allocated 'struct GNUNET_MQ_Envelope *'
96  */
97 #define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \
98   ({struct GNUNET_MQ_Envelope *_ev;\
99     _ev = GNUNET_MQ_msg_nested_mh_((struct GNUNET_MessageHeader**) &(mvar),\
100                                    sizeof (*(mvar)),\
101                                    (type),\
102                                    (mh));\
103    (void)(mvar)->header; /* type check */\
104    _ev;})
105
106
107 /**
108  * Return a pointer to the message at the end of the given message.
109  *
110  * @param var pointer to a message struct, the type of the expression determines the base size,
111  *        the space after the base size is the nested message
112  * @return a 'struct GNUNET_MessageHeader *' that points at the nested message of the given message,
113  *         or NULL if the given message in @a var does not have any space after the message struct
114  */
115 #define GNUNET_MQ_extract_nested_mh(var) GNUNET_MQ_extract_nested_mh_ ((struct GNUNET_MessageHeader *) (var), sizeof (*(var)))
116
117
118 /**
119  * Implementation of the #GNUNET_MQ_extract_nexted_mh macro.
120  *
121  * @param mh message header to extract nested message header from
122  * @param base_size size of the message before the nested message's header appears
123  * @return pointer to the nested message, does not copy the message
124  *         OR NULL in case of a malformed message.
125  */
126 const struct GNUNET_MessageHeader *
127 GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh,
128                               uint16_t base_size);
129
130
131 /**
132  * Opaque handle to an envelope.
133  */
134 struct GNUNET_MQ_Envelope;
135
136
137 /**
138  * Implementation of the #GNUNET_MQ_msg_nested_mh macro.
139  *
140  * @param mhp pointer to the message header pointer that will be changed to allocate at
141  *        the newly allocated space for the message.
142  * @param base_size size of the data before the nested message
143  * @param type type of the message in the envelope
144  * @param nested_mh the message to append to the message after base_size
145  */
146 struct GNUNET_MQ_Envelope *
147 GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp,
148                           uint16_t base_size,
149                           uint16_t type,
150                           const struct GNUNET_MessageHeader *nested_mh);
151
152
153 /**
154  * Opaque handle to a message queue.
155  */
156 struct GNUNET_MQ_Handle;
157
158
159 /**
160  * Error codes for the queue.
161  */
162 enum GNUNET_MQ_Error
163 {
164   /**
165    * Failed to read message from the network.
166    * FIXME: Likely not properly distinguished
167    * from TIMEOUT case in the code!
168    */
169   GNUNET_MQ_ERROR_READ = 1,
170
171   /**
172    * FIXME: document!
173    */
174   GNUNET_MQ_ERROR_WRITE = 2,
175
176   /**
177    * FIXME: document!
178    */
179   GNUNET_MQ_ERROR_TIMEOUT = 4,
180
181   /**
182    * We received a message that was malformed and thus
183    * could not be passed to its handler.
184    */
185   GNUNET_MQ_ERROR_MALFORMED = 8,
186
187   /**
188    * We received a message for which we have no matching
189    * handler.
190    */
191   GNUNET_MQ_ERROR_NO_MATCH = 16
192 };
193
194
195 /**
196  * Called when a message has been received.
197  *
198  * @param cls closure
199  * @param msg the received message
200  */
201 typedef void
202 (*GNUNET_MQ_MessageCallback) (void *cls,
203                               const struct GNUNET_MessageHeader *msg);
204
205
206 /**
207  * Called when a message needs to be validated.
208  *
209  * @param cls closure
210  * @param msg the received message
211  * @return #GNUNET_OK if the message is well-formed,
212  *         #GNUNET_SYSERR if not
213  */
214 typedef int
215 (*GNUNET_MQ_MessageValidationCallback) (void *cls,
216                                         const struct GNUNET_MessageHeader *msg);
217
218
219 /**
220  * Signature of functions implementing the
221  * sending functionality of a message queue.
222  *
223  * @param mq the message queue
224  * @param msg the message to send
225  * @param impl_state state of the implementation
226  */
227 typedef void
228 (*GNUNET_MQ_SendImpl) (struct GNUNET_MQ_Handle *mq,
229                        const struct GNUNET_MessageHeader *msg,
230                        void *impl_state);
231
232
233 /**
234  * Signature of functions implementing the
235  * destruction of a message queue.
236  * Implementations must not free @a mq, but should
237  * take care of @a impl_state.
238  *
239  * @param mq the message queue to destroy
240  * @param impl_state state of the implementation
241  */
242 typedef void
243 (*GNUNET_MQ_DestroyImpl) (struct GNUNET_MQ_Handle *mq,
244                           void *impl_state);
245
246
247 /**
248  * Implementation function that cancels the currently sent message.
249  *
250  * @param mq message queue
251  * @param impl_state state specific to the implementation
252  */
253 typedef void
254 (*GNUNET_MQ_CancelImpl) (struct GNUNET_MQ_Handle *mq,
255                          void *impl_state);
256
257
258 /**
259  * Generic error handler, called with the appropriate
260  * error code and the same closure specified at the creation of
261  * the message queue.
262  * Not every message queue implementation supports an error handler.
263  *
264  * @param cls closure
265  * @param error error code
266  */
267 typedef void
268 (*GNUNET_MQ_ErrorHandler) (void *cls,
269                            enum GNUNET_MQ_Error error);
270
271
272 /**
273  * Insert @a env into the envelope DLL starting at @a env_head
274  * Note that @a env must not be in any MQ while this function
275  * is used with DLLs defined outside of the MQ module.  This
276  * is just in case some application needs to also manage a
277  * FIFO of envelopes independent of MQ itself and wants to
278  * re-use the pointers internal to @a env.  Use with caution.
279  *
280  * @param[in|out] env_head of envelope DLL
281  * @param[in|out] env_tail tail of envelope DLL
282  * @param[in|out] env element to insert at the tail
283  */
284 void
285 GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head,
286                            struct GNUNET_MQ_Envelope **env_tail,
287                            struct GNUNET_MQ_Envelope *env);
288
289
290 /**
291  * Remove @a env from the envelope DLL starting at @a env_head.
292  * Note that @a env must not be in any MQ while this function
293  * is used with DLLs defined outside of the MQ module. This
294  * is just in case some application needs to also manage a
295  * FIFO of envelopes independent of MQ itself and wants to
296  * re-use the pointers internal to @a env.  Use with caution.
297  *
298  * @param[in|out] env_head of envelope DLL
299  * @param[in|out] env_tail tail of envelope DLL
300  * @param[in|out] env element to remove from the DLL
301  */
302 void
303 GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope **env_head,
304                       struct GNUNET_MQ_Envelope **env_tail,
305                       struct GNUNET_MQ_Envelope *env);
306
307
308 /**
309  * Copy an array of handlers.
310  *
311  * Useful if the array has been delared in local memory and needs to be
312  * persisted for future use.
313  *
314  * @param handlers Array of handlers to be copied.
315  * @return A newly allocated array of handlers.
316  *         Needs to be freed with #GNUNET_free.
317  */
318 struct GNUNET_MQ_MessageHandler *
319 GNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers);
320
321
322 /**
323  * Count the handlers in a handler array.
324  *
325  * @param handlers Array of handlers to be counted.
326  * @return The number of handlers in the array.
327  */
328 unsigned int
329 GNUNET_MQ_count_handlers (const struct GNUNET_MQ_MessageHandler *handlers);
330
331
332 /**
333  * Message handler for a specific message type.
334  */
335 struct GNUNET_MQ_MessageHandler
336 {
337   /**
338    * Callback to validate a message of the specified @e type.
339    * The closure given to @e mv will be this struct (not @e ctx).
340    * Using NULL means only size-validation using
341    * @e expected_size.  In this case, @e expected_size must
342    * be non-zero.
343    */
344   GNUNET_MQ_MessageValidationCallback mv;
345
346   /**
347    * Callback, called every time a new message of
348    * the specified @e type has been receied.
349    * The closure given to @e mv will be this struct (not @e ctx).
350    */
351   GNUNET_MQ_MessageCallback cb;
352
353   /**
354    * Closure for @e mv and @e cb.
355    */
356   void *cls;
357
358   /**
359    * Type of the message this handler covers, in host byte order.
360    */
361   uint16_t type;
362
363   /**
364    * Expected size of messages of this type.  Minimum size of the
365    * message if @e mv is non-NULL.  Messages of the given type will be
366    * discarded (and the connection closed with an error reported to
367    * the application) if they do not have the right size.
368    */
369   uint16_t expected_size;
370 };
371
372
373 /**
374  * End-marker for the handlers array
375  */
376 #define GNUNET_MQ_handler_end() { NULL, NULL, NULL, 0, 0 }
377
378
379 /**
380  * Defines a static function @a name which takes as a single argument
381  * a message handler for fixed-sized messages of type @a code and with
382  * a message type argument of @a str.  Given such an argument, the
383  * function @name will return a `struct GNUNET_MQ_MessageHandler`
384  * for the given message type.
385  *
386  * The macro is to be used as follows:
387  * <code>
388  * struct GNUNET_MessageTest { ... }; // must be fixed size
389  * static void
390  * handle_test_message (void *cls,
391  *                      const struct GNUNET_MessageTest *msg)
392  * { ... }
393  *
394  * struct GNUNET_MQ_MessageHandler handlers[] = {
395  *   GNUNET_MQ_hd_fixed_size(test_message,
396  *                           GNUNET_MESSAGE_TYPE_TEST,
397  *                           struct GNUNET_MessageTest,
398  *                           "context"),
399  *   GNUNET_MQ_handler_end()
400  * };
401  *
402  * @param name unique basename for the functions
403  * @param code message type constant
404  * @param str type of the message (a struct)
405  * @param ctx context for the callbacks
406  */
407 #define GNUNET_MQ_hd_fixed_size(name,code,str,ctx)           \
408   ({                                                         \
409     void (*_cb)(void *cls, const str *msg) = &handle_##name; \
410     ((struct GNUNET_MQ_MessageHandler) {                     \
411       NULL, (GNUNET_MQ_MessageCallback) _cb,                 \
412       (ctx), (code), sizeof (str) });                        \
413   })
414
415
416 /**
417  * Defines a static function @a name which takes two arguments and a
418  * context-pointer for validating and handling variable-sized messages
419  * of type @a code and with a message type argument of @a str.  Given
420  * such arguments, the function @name will return a `struct
421  * GNUNET_MQ_MessageHandler` for the given message type.
422  *
423  * The macro is to be used as follows:
424  * <code>
425  * struct GNUNET_MessageTest { ... }; // can be variable size
426  * static int
427  * check_test (void *cls,
428  *             const struct GNUNET_MessageTest *msg)
429  * {
430  *   const char *ctx = cls;
431  *   GNUNET_assert (0 == strcmp ("context", ctx));
432  *   // ...
433  * }
434  * static void
435  * handle_test (void *cls,
436  *              const struct GNUNET_MessageTest *msg)
437  * {
438  *   const char *ctx = cls;
439  *   GNUNET_assert (0 == strcmp ("context", ctx));
440  *   // ...
441  * }
442  *
443  * struct GNUNET_MQ_MessageHandler handlers[] = {
444  *   GNUNET_MQ_hd_var_size(test_message,
445  *                         GNUNET_MESSAGE_TYPE_TEST,
446  *                         struct GNUNET_MessageTest,
447  *                         "context"),
448  *   GNUNET_MQ_handler_end()
449  * };
450  *
451  * @param name unique basename for the functions
452  * @param code message type constant
453  * @param str type of the message (a struct)
454  * @param ctx context for the callbacks
455  */
456 #define GNUNET_MQ_hd_var_size(name,code,str,ctx)             \
457   __extension__ ({                                           \
458     int (*_mv)(void *cls, const str *msg) = &check_##name;   \
459     void (*_cb)(void *cls, const str *msg) = &handle_##name; \
460     ((struct GNUNET_MQ_MessageHandler)                       \
461       { (GNUNET_MQ_MessageValidationCallback) _mv,           \
462         (GNUNET_MQ_MessageCallback) _cb,                     \
463         (ctx), (code), sizeof (str) });                      \
464   })
465
466
467 /**
468  * Create a new envelope.
469  *
470  * @param mhp message header to store the allocated message header in, can be NULL
471  * @param size size of the message to allocate
472  * @param type type of the message, will be set in the allocated message
473  * @return the allocated MQ message
474  */
475 struct GNUNET_MQ_Envelope *
476 GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp,
477                 uint16_t size,
478                 uint16_t type);
479
480
481 /**
482  * Create a new envelope by copying an existing message.
483  *
484  * @param hdr header of the message to copy
485  * @return envelope containing @a hdr
486  */
487 struct GNUNET_MQ_Envelope *
488 GNUNET_MQ_msg_copy (const struct GNUNET_MessageHeader *hdr);
489
490
491 /**
492  * Discard the message queue message, free all
493  * allocated resources. Must be called in the event
494  * that a message is created but should not actually be sent.
495  *
496  * @param mqm the message to discard
497  */
498 void
499 GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm);
500
501
502 /**
503  * Function to obtain the current envelope
504  * from within #GNUNET_MQ_SendImpl implementations.
505  *
506  * @param mq message queue to interrogate
507  * @return the current envelope
508  */
509 struct GNUNET_MQ_Envelope *
510 GNUNET_MQ_get_current_envelope (struct GNUNET_MQ_Handle *mq);
511
512
513 /**
514  * Function to copy an envelope.  The envelope must not yet
515  * be in any queue or have any options or callbacks set.
516  *
517  * @param env envelope to copy
518  * @return copy of @a env
519  */
520 struct GNUNET_MQ_Envelope *
521 GNUNET_MQ_env_copy (struct GNUNET_MQ_Envelope *env);
522
523
524 /**
525  * Function to obtain the last envelope in the queue.
526  *
527  * @param mq message queue to interrogate
528  * @return the last envelope in the queue
529  */
530 struct GNUNET_MQ_Envelope *
531 GNUNET_MQ_get_last_envelope (struct GNUNET_MQ_Handle *mq);
532
533
534 /**
535  * Set application-specific options for this envelope.
536  * Overrides the options set for the queue with
537  * #GNUNET_MQ_set_options() for this message only.
538  *
539  * @param env message to set options for
540  * @param flags flags to use (meaning is queue-specific)
541  * @param extra additional buffer for further data (also queue-specific)
542  */
543 void
544 GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env,
545                            uint64_t flags,
546                            const void *extra);
547
548
549 /**
550  * Get application-specific options for this envelope.
551  *
552  * @param env message to set options for
553  * @param[out] flags set to flags to use (meaning is queue-specific)
554  * @return extra additional buffer for further data (also queue-specific)
555  */
556 const void *
557 GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env,
558                            uint64_t *flags);
559
560
561 /**
562  * Remove the first envelope that has not yet been sent from the message
563  * queue and return it.
564  *
565  * @param mq queue to remove envelope from
566  * @return NULL if queue is empty (or has no envelope that is not under transmission)
567  */
568 struct GNUNET_MQ_Envelope *
569 GNUNET_MQ_unsent_head (struct GNUNET_MQ_Handle *mq);
570
571
572 /**
573  * Set application-specific options for this queue.
574  *
575  * @param mq message queue to set options for
576  * @param flags flags to use (meaning is queue-specific)
577  * @param extra additional buffer for further data (also queue-specific)
578  */
579 void
580 GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq,
581                        uint64_t flags,
582                        const void *extra);
583
584
585 /**
586  * Obtain the current length of the message queue.
587  *
588  * @param mq queue to inspect
589  * @return number of queued, non-transmitted messages
590  */
591 unsigned int
592 GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq);
593
594
595 /**
596  * Send a message with the given message queue.
597  * May only be called once per message.
598  *
599  * @param mq message queue
600  * @param ev the envelope with the message to send.
601  */
602 void
603 GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq,
604                 struct GNUNET_MQ_Envelope *ev);
605
606
607 /**
608  * Send a copy of a message with the given message queue.
609  * Can be called repeatedly on the same envelope.
610  *
611  * @param mq message queue
612  * @param ev the envelope with the message to send.
613  */
614 void
615 GNUNET_MQ_send_copy (struct GNUNET_MQ_Handle *mq,
616                      const struct GNUNET_MQ_Envelope *ev);
617
618
619 /**
620  * Cancel sending the message. Message must have been sent with
621  * #GNUNET_MQ_send before.  May not be called after the notify sent
622  * callback has been called
623  *
624  * @param ev queued envelope to cancel
625  */
626 void
627 GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev);
628
629
630 /**
631  * Associate the assoc_data in @a mq with a unique request id.
632  *
633  * @param mq message queue, id will be unique for the queue
634  * @param assoc_data to associate
635  */
636 uint32_t
637 GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
638                      void *assoc_data);
639
640
641 /**
642  * Get the data associated with a @a request_id in a queue
643  *
644  * @param mq the message queue with the association
645  * @param request_id the request id we are interested in
646  * @return the associated data
647  */
648 void *
649 GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq,
650                      uint32_t request_id);
651
652
653 /**
654  * Remove the association for a @a request_id
655  *
656  * @param mq the message queue with the association
657  * @param request_id the request id we want to remove
658  * @return the associated data
659  */
660 void *
661 GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq,
662                         uint32_t request_id);
663
664
665 /**
666  * Create a message queue for the specified handlers.
667  *
668  * @param send function the implements sending messages
669  * @param destroy function that implements destroying the queue
670  * @param cancel function that implements canceling a message
671  * @param impl_state for the queue, passed to @a send, @a destroy and @a cancel
672  * @param handlers array of message handlers
673  * @param error_handler handler for read and write errors
674  * @param cls closure for message handlers and error handler
675  * @return a new message queue
676  */
677 struct GNUNET_MQ_Handle *
678 GNUNET_MQ_queue_for_callbacks (GNUNET_MQ_SendImpl send,
679                                GNUNET_MQ_DestroyImpl destroy,
680                                GNUNET_MQ_CancelImpl cancel,
681                                void *impl_state,
682                                const struct GNUNET_MQ_MessageHandler *handlers,
683                                GNUNET_MQ_ErrorHandler error_handler,
684                                void *cls);
685
686
687 /**
688  * Change the closure argument in all of the `handlers` of the
689  * @a mq.
690  *
691  * @param mq to modify
692  * @param handlers_cls new closure to use
693  */
694 void
695 GNUNET_MQ_set_handlers_closure (struct GNUNET_MQ_Handle *mq,
696                                 void *handlers_cls);
697
698
699 /**
700  * Call a callback once the envelope has been sent, that is,
701  * sending it can not be canceled anymore.
702  * There can be only one notify sent callback per envelope.
703  *
704  * @param ev message to call the notify callback for
705  * @param cb the notify callback
706  * @param cb_cls closure for the callback
707  */
708 void
709 GNUNET_MQ_notify_sent (struct GNUNET_MQ_Envelope *ev,
710                        GNUNET_SCHEDULER_TaskCallback cb,
711                        void *cb_cls);
712
713
714 /**
715  * Destroy the message queue.
716  *
717  * @param mq message queue to destroy
718  */
719 void
720 GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq);
721
722
723 /**
724  * Handle we return for callbacks registered to be
725  * notified when #GNUNET_MQ_destroy() is called on a queue.
726  */
727 struct GNUNET_MQ_DestroyNotificationHandle;
728
729
730 /**
731  * Register function to be called whenever @a mq is being
732  * destroyed.
733  *
734  * @param mq message queue to watch
735  * @param cb function to call on @a mq destruction
736  * @param cb_cls closure for @a cb
737  * @return handle for #GNUNET_MQ_destroy_notify_cancel().
738  */
739 struct GNUNET_MQ_DestroyNotificationHandle *
740 GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
741                           GNUNET_SCHEDULER_TaskCallback cb,
742                           void *cb_cls);
743
744 /**
745  * Cancel registration from #GNUNET_MQ_destroy_notify().
746  *
747  * @param dnh handle for registration to cancel
748  */
749 void
750 GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle *dnh);
751
752
753 /**
754  * Call the message message handler that was registered
755  * for the type of the given message in the given message queue.
756  *
757  * This function is indended to be used for the implementation
758  * of message queues.
759  *
760  * @param mq message queue with the handlers
761  * @param mh message to dispatch
762  */
763 void
764 GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq,
765                           const struct GNUNET_MessageHeader *mh);
766
767
768 /**
769  * Call the error handler of a message queue with the given
770  * error code.  If there is no error handler, log a warning.
771  *
772  * This function is intended to be used for the implementation
773  * of message queues.
774  *
775  * @param mq message queue
776  * @param error the error type
777  */
778 void
779 GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq,
780                         enum GNUNET_MQ_Error error);
781
782
783 /**
784  * Call the send implementation for the next queued message, if any.
785  * Calls the send notification for the current message unless
786  * #GNUNET_MQ_impl_send_in_flight was called for this envelope.
787  *
788  * Only useful for implementing message queues, results in undefined
789  * behavior if not used carefully.
790  *
791  * @param mq message queue to send the next message with
792  */
793 void
794 GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq);
795
796
797 /**
798  * Call the send notification for the current message, but do not
799  * try to send the next message until #gnunet_mq_impl_send_continue
800  * is called.
801  *
802  * Only useful for implementing message queues, results in undefined
803  * behavior if not used carefully.
804  *
805  * @param mq message queue to send the next message with
806  */
807 void
808 GNUNET_MQ_impl_send_in_flight (struct GNUNET_MQ_Handle *mq);
809
810
811 /**
812  * Get the implementation state associated with the
813  * message queue.
814  *
815  * While the GNUNET_MQ_Impl* callbacks receive the
816  * implementation state, continuations that are scheduled
817  * by the implementation function often only have one closure
818  * argument, with this function it is possible to get at the
819  * implementation state when only passing the `struct GNUNET_MQ_Handle`
820  * as closure.
821  *
822  * @param mq message queue with the current message
823  * @return message to send, never NULL
824  */
825 void *
826 GNUNET_MQ_impl_state (struct GNUNET_MQ_Handle *mq);
827
828
829 /**
830  * Get the message that should currently be sent.
831  * Fails if there is no current message.
832  * Only useful for implementing message queues,
833  * results in undefined behavior if not used carefully.
834  *
835  * @param mq message queue with the current message
836  * @return message to send, never NULL
837  */
838 const struct GNUNET_MessageHeader *
839 GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq);
840
841
842 #endif
843
844 /** @} */ /* end of group mq */