along with this program. If not, see <http://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
/**
* @author Florian Dold
* @return the MQ message
*/
#define GNUNET_MQ_msg_extra(mvar, esize, type) \
- GNUNET_MQ_msg_ (((struct GNUNET_MessageHeader **) &(mvar)), \
- (esize) + sizeof *(mvar), \
- (type))
+ GNUNET_MQ_msg_(((struct GNUNET_MessageHeader **)&(mvar)), \
+ (esize) + sizeof *(mvar), \
+ (type))
/**
* Allocate a GNUNET_MQ_Envelope.
* @param type type of the message
* @return the allocated envelope
*/
-#define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra (mvar, 0, type)
+#define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra(mvar, 0, type)
/**
* @param type type of the message
*/
#define GNUNET_MQ_msg_header(type) \
- GNUNET_MQ_msg_ (NULL, sizeof (struct GNUNET_MessageHeader), type)
+ GNUNET_MQ_msg_(NULL, sizeof(struct GNUNET_MessageHeader), type)
/**
* @param type type of the message
*/
#define GNUNET_MQ_msg_header_extra(mh, esize, type) \
- GNUNET_MQ_msg_ (&mh, (esize) + sizeof (struct GNUNET_MessageHeader), type)
+ GNUNET_MQ_msg_(&mh, (esize) + sizeof(struct GNUNET_MessageHeader), type)
/**
#define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \
({ \
struct GNUNET_MQ_Envelope *_ev; \
- _ev = GNUNET_MQ_msg_nested_mh_ ((struct GNUNET_MessageHeader **) &(mvar), \
- sizeof (*(mvar)), \
- (type), \
- (mh)); \
- (void) (mvar)->header; /* type check */ \
+ _ev = GNUNET_MQ_msg_nested_mh_((struct GNUNET_MessageHeader **)&(mvar), \
+ sizeof(*(mvar)), \
+ (type), \
+ (mh)); \
+ (void)(mvar)->header; /* type check */ \
_ev; \
})
* or NULL if the given message in @a var does not have any space after the message struct
*/
#define GNUNET_MQ_extract_nested_mh(var) \
- GNUNET_MQ_extract_nested_mh_ ((struct GNUNET_MessageHeader *) (var), \
- sizeof (*(var)))
+ GNUNET_MQ_extract_nested_mh_((struct GNUNET_MessageHeader *)(var), \
+ sizeof(*(var)))
/**
* OR NULL in case of a malformed message.
*/
const struct GNUNET_MessageHeader *
-GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh,
- uint16_t base_size);
+GNUNET_MQ_extract_nested_mh_(const struct GNUNET_MessageHeader *mh,
+ uint16_t base_size);
/**
* @return message contained in the envelope
*/
const struct GNUNET_MessageHeader *
-GNUNET_MQ_env_get_msg (const struct GNUNET_MQ_Envelope *env);
+GNUNET_MQ_env_get_msg(const struct GNUNET_MQ_Envelope *env);
/**
* @return next one, or NULL
*/
const struct GNUNET_MQ_Envelope *
-GNUNET_MQ_env_next (const struct GNUNET_MQ_Envelope *env);
+GNUNET_MQ_env_next(const struct GNUNET_MQ_Envelope *env);
/**
* @param nested_mh the message to append to the message after base_size
*/
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);
+GNUNET_MQ_msg_nested_mh_(struct GNUNET_MessageHeader **mhp,
+ uint16_t base_size,
+ uint16_t type,
+ const struct GNUNET_MessageHeader *nested_mh);
/**
/**
* Error codes for the queue.
*/
-enum GNUNET_MQ_Error
-{
+enum GNUNET_MQ_Error {
/**
* Failed to read message from the network.
* FIXME: Likely not properly distinguished
/**
* Per envelope preferences and priorities.
*/
-enum GNUNET_MQ_PriorityPreferences
-{
-
+enum GNUNET_MQ_PriorityPreferences {
/**
* Lowest priority, i.e. background traffic (i.e. NSE, FS).
* This is the default!
* Flag to indicate that out-of-order delivery is OK.
*/
GNUNET_MQ_PREF_OUT_OF_ORDER = 256,
-
};
* @param[in|out] env element to insert at the tail
*/
void
-GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head,
- struct GNUNET_MQ_Envelope **env_tail,
- struct GNUNET_MQ_Envelope *env);
+GNUNET_MQ_dll_insert_head(struct GNUNET_MQ_Envelope **env_head,
+ struct GNUNET_MQ_Envelope **env_tail,
+ struct GNUNET_MQ_Envelope *env);
/**
* @param[in|out] env element to insert at the tail
*/
void
-GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head,
- struct GNUNET_MQ_Envelope **env_tail,
- struct GNUNET_MQ_Envelope *env);
+GNUNET_MQ_dll_insert_tail(struct GNUNET_MQ_Envelope **env_head,
+ struct GNUNET_MQ_Envelope **env_tail,
+ struct GNUNET_MQ_Envelope *env);
/**
* @param[in|out] env element to remove from the DLL
*/
void
-GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope **env_head,
- struct GNUNET_MQ_Envelope **env_tail,
- struct GNUNET_MQ_Envelope *env);
+GNUNET_MQ_dll_remove(struct GNUNET_MQ_Envelope **env_head,
+ struct GNUNET_MQ_Envelope **env_tail,
+ struct GNUNET_MQ_Envelope *env);
/**
* Needs to be freed with #GNUNET_free.
*/
struct GNUNET_MQ_MessageHandler *
-GNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers);
+GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers);
/**
* Needs to be freed with #GNUNET_free.
*/
struct GNUNET_MQ_MessageHandler *
-GNUNET_MQ_copy_handlers2 (const struct GNUNET_MQ_MessageHandler *handlers,
- GNUNET_MQ_MessageCallback agpl_handler,
- void *agpl_cls);
+GNUNET_MQ_copy_handlers2(const struct GNUNET_MQ_MessageHandler *handlers,
+ GNUNET_MQ_MessageCallback agpl_handler,
+ void *agpl_cls);
/**
* @return The number of handlers in the array.
*/
unsigned int
-GNUNET_MQ_count_handlers (const struct GNUNET_MQ_MessageHandler *handlers);
+GNUNET_MQ_count_handlers(const struct GNUNET_MQ_MessageHandler *handlers);
/**
* Message handler for a specific message type.
*/
-struct GNUNET_MQ_MessageHandler
-{
+struct GNUNET_MQ_MessageHandler {
/**
* Callback to validate a message of the specified @e type.
* The closure given to @e mv will be this struct (not @e ctx).
*/
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx) \
({ \
- void (*_cb) (void *cls, const str *msg) = &handle_##name; \
- ((struct GNUNET_MQ_MessageHandler){NULL, \
- (GNUNET_MQ_MessageCallback) _cb, \
- (ctx), \
- (code), \
- sizeof (str)}); \
+ void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \
+ ((struct GNUNET_MQ_MessageHandler){ NULL, \
+ (GNUNET_MQ_MessageCallback)_cb, \
+ (ctx), \
+ (code), \
+ sizeof(str) }); \
})
*/
#define GNUNET_MQ_hd_var_size(name, code, str, ctx) \
__extension__({ \
- int (*_mv) (void *cls, const str *msg) = &check_##name; \
- void (*_cb) (void *cls, const str *msg) = &handle_##name; \
- ((struct GNUNET_MQ_MessageHandler){(GNUNET_MQ_MessageValidationCallback) \
- _mv, \
- (GNUNET_MQ_MessageCallback) _cb, \
- (ctx), \
- (code), \
- sizeof (str)}); \
+ int (*_mv)(void *cls, const str *msg) = &check_ ## name; \
+ void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \
+ ((struct GNUNET_MQ_MessageHandler){ (GNUNET_MQ_MessageValidationCallback) \
+ _mv, \
+ (GNUNET_MQ_MessageCallback)_cb, \
+ (ctx), \
+ (code), \
+ sizeof(str) }); \
})
*/
#define GNUNET_MQ_check_zero_termination(m) \
{ \
- const char *str = (const char *) &m[1]; \
+ const char *str = (const char *)&m[1]; \
const struct GNUNET_MessageHeader *hdr = \
- (const struct GNUNET_MessageHeader *) m; \
- uint16_t slen = ntohs (hdr->size) - sizeof (*m); \
- if ((0 == slen) || (memchr (str, 0, slen) != &str[slen - 1])) \
- { \
- GNUNET_break (0); \
- return GNUNET_NO; \
- } \
+ (const struct GNUNET_MessageHeader *)m; \
+ uint16_t slen = ntohs(hdr->size) - sizeof(*m); \
+ if ((0 == slen) || (memchr(str, 0, slen) != &str[slen - 1])) \
+ { \
+ GNUNET_break(0); \
+ return GNUNET_NO; \
+ } \
}
#define GNUNET_MQ_check_boxed_message(m) \
{ \
const struct GNUNET_MessageHeader *inbox = \
- (const struct GNUNET_MessageHeader *) &m[1]; \
+ (const struct GNUNET_MessageHeader *)&m[1]; \
const struct GNUNET_MessageHeader *hdr = \
- (const struct GNUNET_MessageHeader *) m; \
- uint16_t slen = ntohs (hdr->size) - sizeof (*m); \
- if ((slen < sizeof (struct GNUNET_MessageHeader)) || \
- (slen != ntohs (inbox->size))) \
- { \
- GNUNET_break (0); \
- return GNUNET_NO; \
- } \
+ (const struct GNUNET_MessageHeader *)m; \
+ uint16_t slen = ntohs(hdr->size) - sizeof(*m); \
+ if ((slen < sizeof(struct GNUNET_MessageHeader)) || \
+ (slen != ntohs(inbox->size))) \
+ { \
+ GNUNET_break(0); \
+ return GNUNET_NO; \
+ } \
}
* #GNUNET_SYSERR if message was rejected by check function
*/
int
-GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers,
- const struct GNUNET_MessageHeader *mh);
+GNUNET_MQ_handle_message(const struct GNUNET_MQ_MessageHandler *handlers,
+ const struct GNUNET_MessageHeader *mh);
/**
* @return the allocated MQ message
*/
struct GNUNET_MQ_Envelope *
-GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp,
- uint16_t size,
- uint16_t type);
+GNUNET_MQ_msg_(struct GNUNET_MessageHeader **mhp,
+ uint16_t size,
+ uint16_t type);
/**
* @return envelope containing @a hdr
*/
struct GNUNET_MQ_Envelope *
-GNUNET_MQ_msg_copy (const struct GNUNET_MessageHeader *hdr);
+GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr);
/**
* @param mqm the message to discard
*/
void
-GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm);
+GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm);
/**
* @return the current envelope
*/
struct GNUNET_MQ_Envelope *
-GNUNET_MQ_get_current_envelope (struct GNUNET_MQ_Handle *mq);
+GNUNET_MQ_get_current_envelope(struct GNUNET_MQ_Handle *mq);
/**
* @return copy of @a env
*/
struct GNUNET_MQ_Envelope *
-GNUNET_MQ_env_copy (struct GNUNET_MQ_Envelope *env);
+GNUNET_MQ_env_copy(struct GNUNET_MQ_Envelope *env);
/**
* @return the last envelope in the queue
*/
struct GNUNET_MQ_Envelope *
-GNUNET_MQ_get_last_envelope (struct GNUNET_MQ_Handle *mq);
+GNUNET_MQ_get_last_envelope(struct GNUNET_MQ_Handle *mq);
/**
* @param pp priority and preferences to set for @a env
*/
void
-GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env,
- enum GNUNET_MQ_PriorityPreferences pp);
+GNUNET_MQ_env_set_options(struct GNUNET_MQ_Envelope *env,
+ enum GNUNET_MQ_PriorityPreferences pp);
/**
* @return priority and preferences to use
*/
enum GNUNET_MQ_PriorityPreferences
-GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env);
+GNUNET_MQ_env_get_options(struct GNUNET_MQ_Envelope *env);
/**
* @return combined priority and preferences to use
*/
enum GNUNET_MQ_PriorityPreferences
-GNUNET_MQ_env_combine_options (enum GNUNET_MQ_PriorityPreferences p1,
- enum GNUNET_MQ_PriorityPreferences p2);
+GNUNET_MQ_env_combine_options(enum GNUNET_MQ_PriorityPreferences p1,
+ enum GNUNET_MQ_PriorityPreferences p2);
/**
* @return NULL if queue is empty (or has no envelope that is not under transmission)
*/
struct GNUNET_MQ_Envelope *
-GNUNET_MQ_unsent_head (struct GNUNET_MQ_Handle *mq);
+GNUNET_MQ_unsent_head(struct GNUNET_MQ_Handle *mq);
/**
* @param pp priority and preferences to use by default
*/
void
-GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq,
- enum GNUNET_MQ_PriorityPreferences pp);
+GNUNET_MQ_set_options(struct GNUNET_MQ_Handle *mq,
+ enum GNUNET_MQ_PriorityPreferences pp);
/**
* @return number of queued, non-transmitted messages
*/
unsigned int
-GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq);
+GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq);
/**
* @param ev the envelope with the message to send.
*/
void
-GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev);
+GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev);
/**
* @param ev the envelope with the message to send.
*/
void
-GNUNET_MQ_send_copy (struct GNUNET_MQ_Handle *mq,
- const struct GNUNET_MQ_Envelope *ev);
+GNUNET_MQ_send_copy(struct GNUNET_MQ_Handle *mq,
+ const struct GNUNET_MQ_Envelope *ev);
/**
* @param ev queued envelope to cancel
*/
void
-GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev);
+GNUNET_MQ_send_cancel(struct GNUNET_MQ_Envelope *ev);
/**
* @param assoc_data to associate
*/
uint32_t
-GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data);
+GNUNET_MQ_assoc_add(struct GNUNET_MQ_Handle *mq, void *assoc_data);
/**
* @return the associated data
*/
void *
-GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id);
+GNUNET_MQ_assoc_get(struct GNUNET_MQ_Handle *mq, uint32_t request_id);
/**
* @return the associated data
*/
void *
-GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id);
+GNUNET_MQ_assoc_remove(struct GNUNET_MQ_Handle *mq, uint32_t request_id);
/**
* @return a new message queue
*/
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 *cls);
+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 *cls);
/**
* @param handlers_cls new closure to use
*/
void
-GNUNET_MQ_set_handlers_closure (struct GNUNET_MQ_Handle *mq,
- void *handlers_cls);
+GNUNET_MQ_set_handlers_closure(struct GNUNET_MQ_Handle *mq,
+ void *handlers_cls);
/**
* @param cb_cls closure for the callback
*/
void
-GNUNET_MQ_notify_sent (struct GNUNET_MQ_Envelope *ev,
- GNUNET_SCHEDULER_TaskCallback cb,
- void *cb_cls);
+GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev,
+ GNUNET_SCHEDULER_TaskCallback cb,
+ void *cb_cls);
/**
* @param mq message queue to destroy
*/
void
-GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq);
+GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq);
/**
* @return handle for #GNUNET_MQ_destroy_notify_cancel().
*/
struct GNUNET_MQ_DestroyNotificationHandle *
-GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
- GNUNET_SCHEDULER_TaskCallback cb,
- void *cb_cls);
+GNUNET_MQ_destroy_notify(struct GNUNET_MQ_Handle *mq,
+ GNUNET_SCHEDULER_TaskCallback cb,
+ void *cb_cls);
/**
* Cancel registration from #GNUNET_MQ_destroy_notify().
* @param dnh handle for registration to cancel
*/
void
-GNUNET_MQ_destroy_notify_cancel (
+GNUNET_MQ_destroy_notify_cancel(
struct GNUNET_MQ_DestroyNotificationHandle *dnh);
* @param mh message to dispatch
*/
void
-GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq,
- const struct GNUNET_MessageHeader *mh);
+GNUNET_MQ_inject_message(struct GNUNET_MQ_Handle *mq,
+ const struct GNUNET_MessageHeader *mh);
/**
* @param error the error type
*/
void
-GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq,
- enum GNUNET_MQ_Error error);
+GNUNET_MQ_inject_error(struct GNUNET_MQ_Handle *mq,
+ enum GNUNET_MQ_Error error);
/**
* @param mq message queue to send the next message with
*/
void
-GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq);
+GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq);
/**
* @param mq message queue to send the next message with
*/
void
-GNUNET_MQ_impl_send_in_flight (struct GNUNET_MQ_Handle *mq);
+GNUNET_MQ_impl_send_in_flight(struct GNUNET_MQ_Handle *mq);
/**
* @return message to send, never NULL
*/
void *
-GNUNET_MQ_impl_state (struct GNUNET_MQ_Handle *mq);
+GNUNET_MQ_impl_state(struct GNUNET_MQ_Handle *mq);
/**
* @return message to send, never NULL
*/
const struct GNUNET_MessageHeader *
-GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq);
+GNUNET_MQ_impl_current(struct GNUNET_MQ_Handle *mq);
/**
*
* @deprecated will be replaced by `enum GNUNET_MQ_PriorityPreference`
*/
-enum GNUNET_MQ_PreferenceKind
-{
-
+enum GNUNET_MQ_PreferenceKind {
/**
* No preference was expressed.
*/
GNUNET_MQ_PREFERENCE_RELIABILITY = 3
/**
- * Number of preference values allowed.
- */
+ * Number of preference values allowed.
+ */
#define GNUNET_MQ_PREFERENCE_COUNT 4
-
};
* @deprecated will be replaced by `enum GNUNET_MQ_PriorityPreference`
*/
const char *
-GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type);
+GNUNET_MQ_preference_to_string(enum GNUNET_MQ_PreferenceKind type);
#endif