gnunet_consensus_service.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2012 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 Florian Dold
  18. *
  19. * @file
  20. * Multi-peer set reconciliation
  21. *
  22. * @defgroup consensus Consensus service
  23. * Multi-peer set reconciliation
  24. * @{
  25. */
  26. #ifndef GNUNET_CONSENSUS_SERVICE_H
  27. #define GNUNET_CONSENSUS_SERVICE_H
  28. #ifdef __cplusplus
  29. extern "C"
  30. {
  31. #if 0 /* keep Emacsens' auto-indent happy */
  32. }
  33. #endif
  34. #endif
  35. #include "gnunet_common.h"
  36. #include "gnunet_time_lib.h"
  37. #include "gnunet_configuration_lib.h"
  38. #include "gnunet_set_service.h"
  39. /**
  40. * Elements inserted into the consensus set by the client
  41. * may not be larger than this constant, since types in
  42. * the upper range are used by CONSENSUS internally.
  43. */
  44. #define GNUNET_CONSENSUS_ELEMENT_TYPE_USER_MAX 0xFFF0
  45. /**
  46. * Called when a new element was received from another peer, or an error occurred.
  47. * May deliver duplicate values.
  48. * Elements given to a consensus operation by the local peer are NOT given
  49. * to this callback.
  50. *
  51. * @param cls closure
  52. * @param element new element, NULL on error
  53. */
  54. typedef void (*GNUNET_CONSENSUS_ElementCallback) (void *cls,
  55. const struct
  56. GNUNET_SET_Element *element);
  57. /**
  58. * Opaque handle for the consensus service.
  59. */
  60. struct GNUNET_CONSENSUS_Handle;
  61. /**
  62. * Create a consensus session. The set being reconciled is initially
  63. * empty.
  64. *
  65. * @param cfg
  66. * @param num_peers
  67. * @param peers array of peers participating in this consensus session
  68. * Inclusion of the local peer is optional.
  69. * @param session_id session identifier
  70. * Allows a group of peers to have more than consensus session.
  71. * @param start start time of the consensus, conclude should be called before
  72. * the start time.
  73. * @param deadline time when the consensus should have concluded
  74. * @param new_element_cb callback, called when a new element is added to the set by
  75. * another peer. Also called when an error occurs.
  76. * @param new_element_cls closure for new_element
  77. * @return handle to use, NULL on error
  78. */
  79. struct GNUNET_CONSENSUS_Handle *
  80. GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
  81. unsigned int num_peers,
  82. const struct GNUNET_PeerIdentity *peers,
  83. const struct GNUNET_HashCode *session_id,
  84. struct GNUNET_TIME_Absolute start,
  85. struct GNUNET_TIME_Absolute deadline,
  86. GNUNET_CONSENSUS_ElementCallback new_element_cb,
  87. void *new_element_cls);
  88. /**
  89. * Called when an insertion (transmission to consensus service, which
  90. * does not imply fully consensus on this element with all other
  91. * peers) was successful. May not call GNUNET_CONSENSUS_destroy();
  92. * schedule a task to call GNUNET_CONSENSUS_destroy() instead (if
  93. * needed).
  94. *
  95. * @param cls
  96. * @param success #GNUNET_OK on success, #GNUNET_SYSERR if
  97. * the insertion and thus the consensus failed for good
  98. */
  99. typedef void (*GNUNET_CONSENSUS_InsertDoneCallback) (void *cls,
  100. int success);
  101. /**
  102. * Insert an element in the set being reconsiled. Only transmit changes to
  103. * other peers if GNUNET_CONSENSUS_begin() has been called.
  104. * Must not be called after GNUNET_CONSENSUS_conclude().
  105. * May not call GNUNET_CONSENSUS_destroy(); schedule a task to call
  106. * GNUNET_CONSENSUS_destroy() instead (if needed).
  107. *
  108. * @param consensus handle for the consensus session
  109. * @param element the element to be inserted
  110. * @param idc function called when we are done with this element and it
  111. * is thus allowed to call GNUNET_CONSENSUS_insert() again
  112. * @param idc_cls closure for @a idc
  113. */
  114. void
  115. GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus,
  116. const struct GNUNET_SET_Element *element,
  117. GNUNET_CONSENSUS_InsertDoneCallback idc,
  118. void *idc_cls);
  119. /**
  120. * Called when a conclusion was successful.
  121. *
  122. * @param cls
  123. */
  124. typedef void (*GNUNET_CONSENSUS_ConcludeCallback) (void *cls);
  125. /**
  126. * We are finished inserting new elements into the consensus;
  127. * try to conclude the consensus within a given time window.
  128. *
  129. * @param consensus consensus session
  130. * @param conclude called when the conclusion was successful
  131. * @param conclude_cls closure for the conclude callback
  132. */
  133. void
  134. GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
  135. GNUNET_CONSENSUS_ConcludeCallback conclude,
  136. void *conclude_cls);
  137. /**
  138. * Destroy a consensus handle (free all state associated with
  139. * it, no longer call any of the callbacks).
  140. *
  141. * @param consensus handle to destroy
  142. */
  143. void
  144. GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus);
  145. #if 0 /* keep Emacsens' auto-indent happy */
  146. {
  147. #endif
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151. #endif
  152. /** @} */ /* end of group */