gnunet_nc_lib.h (3294B)
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 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 21 22 #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) 23 #error "Only <gnunet_util_lib.h> can be included directly." 24 #endif 25 26 /** 27 * @addtogroup libgnunetutil 28 * Multi-function utilities library for GNUnet programs 29 * @{ 30 * 31 * @author Christian Grothoff 32 * 33 * @file 34 * General-purpose broadcast mechanism for message queues 35 * 36 * @defgroup mq NC library 37 * General-purpose broadcast mechanism for message queues 38 * 39 * @see [Documentation](https://gnunet.org/nc) 40 * 41 * @{ 42 */ 43 #ifndef GNUNET_NC_H 44 #define GNUNET_NC_H 45 46 47 /** 48 * The notification context is the key datastructure for a convenience 49 * API used for transmission of notifications to the subscriber until the 50 * subscriber disconnects (or the notification context is destroyed, in 51 * which case we disconnect these subscribers). Essentially, all 52 * (notification) messages are queued up until the subscriber is able to 53 * read them. 54 */ 55 struct GNUNET_NotificationContext; 56 57 58 /** 59 * Create a new notification context. 60 * 61 * @param queue_length maximum number of messages to keep in 62 * the notification queue; optional messages are dropped 63 * if the queue gets longer than this number of messages 64 * @return handle to the notification context 65 */ 66 struct GNUNET_NotificationContext * 67 GNUNET_notification_context_create (unsigned int queue_length); 68 69 70 /** 71 * Destroy the context, force disconnect for all subscribers. 72 * 73 * @param nc context to destroy. 74 */ 75 void 76 GNUNET_notification_context_destroy (struct GNUNET_NotificationContext *nc); 77 78 79 /** 80 * Add a subscriber to the notification context. 81 * 82 * @param nc context to modify 83 * @param mq message queue add 84 */ 85 void 86 GNUNET_notification_context_add (struct GNUNET_NotificationContext *nc, 87 struct GNUNET_MQ_Handle *mq); 88 89 90 /** 91 * Send a message to all subscribers of this context. 92 * 93 * @param nc context to modify 94 * @param msg message to send 95 * @param can_drop can this message be dropped due to queue length limitations 96 */ 97 void 98 GNUNET_notification_context_broadcast (struct GNUNET_NotificationContext *nc, 99 const struct GNUNET_MessageHeader *msg, 100 int can_drop); 101 102 /** 103 * Return active number of subscribers in this context. 104 * 105 * @param nc context to query 106 * @return number of current subscribers 107 */ 108 unsigned int 109 GNUNET_notification_context_get_size (struct GNUNET_NotificationContext *nc); 110 111 #endif 112 113 /** @} */ /* end of group mq */ 114 115 /** @} */ /* end of group addition */