gnunet_nc_lib.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2012-2016 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Christian Grothoff
  18. *
  19. * @file
  20. * General-purpose broadcast mechanism for message queues
  21. *
  22. * @defgroup mq NC library
  23. * General-purpose broadcast mechanism for message queues
  24. *
  25. * @see [Documentation](https://gnunet.org/nc)
  26. *
  27. * @{
  28. */
  29. #ifndef GNUNET_NC_H
  30. #define GNUNET_NC_H
  31. /**
  32. * The notification context is the key datastructure for a convenience
  33. * API used for transmission of notifications to the subscriber until the
  34. * subscriber disconnects (or the notification context is destroyed, in
  35. * which case we disconnect these subscribers). Essentially, all
  36. * (notification) messages are queued up until the subscriber is able to
  37. * read them.
  38. */
  39. struct GNUNET_NotificationContext;
  40. /**
  41. * Create a new notification context.
  42. *
  43. * @param queue_length maximum number of messages to keep in
  44. * the notification queue; optional messages are dropped
  45. * if the queue gets longer than this number of messages
  46. * @return handle to the notification context
  47. */
  48. struct GNUNET_NotificationContext *
  49. GNUNET_notification_context_create (unsigned int queue_length);
  50. /**
  51. * Destroy the context, force disconnect for all subscribers.
  52. *
  53. * @param nc context to destroy.
  54. */
  55. void
  56. GNUNET_notification_context_destroy (struct GNUNET_NotificationContext *nc);
  57. /**
  58. * Add a subscriber to the notification context.
  59. *
  60. * @param nc context to modify
  61. * @param mq message queue add
  62. */
  63. void
  64. GNUNET_notification_context_add (struct GNUNET_NotificationContext *nc,
  65. struct GNUNET_MQ_Handle *mq);
  66. /**
  67. * Send a message to all subscribers of this context.
  68. *
  69. * @param nc context to modify
  70. * @param msg message to send
  71. * @param can_drop can this message be dropped due to queue length limitations
  72. */
  73. void
  74. GNUNET_notification_context_broadcast (struct GNUNET_NotificationContext *nc,
  75. const struct GNUNET_MessageHeader *msg,
  76. int can_drop);
  77. /**
  78. * Return active number of subscribers in this context.
  79. *
  80. * @param nc context to query
  81. * @return number of current subscribers
  82. */
  83. unsigned int
  84. GNUNET_notification_context_get_size (struct GNUNET_NotificationContext *nc);
  85. #endif