gnunet_consensus_service.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. This file is part of GNUnet
  3. (C) 2012 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. 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. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file include/gnunet_consensus_service.h
  19. * @brief multi-peer set reconciliation
  20. * @author Florian Dold
  21. */
  22. #ifndef GNUNET_CONSENSUS_SERVICE_H
  23. #define GNUNET_CONSENSUS_SERVICE_H
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #if 0 /* keep Emacsens' auto-indent happy */
  28. }
  29. #endif
  30. #endif
  31. #include "platform.h"
  32. #include "gnunet_common.h"
  33. #include "gnunet_time_lib.h"
  34. #include "gnunet_configuration_lib.h"
  35. #include "gnunet_set_service.h"
  36. /**
  37. * Called when a new element was received from another peer, or an error occured.
  38. * May deliver duplicate values.
  39. * Elements given to a consensus operation by the local peer are NOT given
  40. * to this callback.
  41. *
  42. * @param cls closure
  43. * @param element new element, NULL on error
  44. */
  45. typedef void (*GNUNET_CONSENSUS_ElementCallback) (void *cls,
  46. const struct GNUNET_SET_Element *element);
  47. /**
  48. * Opaque handle for the consensus service.
  49. */
  50. struct GNUNET_CONSENSUS_Handle;
  51. /**
  52. * Create a consensus session. The set being reconciled is initially
  53. * empty.
  54. *
  55. * @param cfg
  56. * @param num_peers
  57. * @param peers array of peers participating in this consensus session
  58. * Inclusion of the local peer is optional.
  59. * @param session_id session identifier
  60. * Allows a group of peers to have more than consensus session.
  61. * @param start start time of the consensus, conclude should be called before
  62. * the start time.
  63. * @param deadline time when the consensus should have concluded
  64. * @param new_element_cb callback, called when a new element is added to the set by
  65. * another peer. Also called when an error occurs.
  66. * @param new_element_cls closure for new_element
  67. * @return handle to use, NULL on error
  68. */
  69. struct GNUNET_CONSENSUS_Handle *
  70. GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
  71. unsigned int num_peers,
  72. const struct GNUNET_PeerIdentity *peers,
  73. const struct GNUNET_HashCode *session_id,
  74. struct GNUNET_TIME_Absolute start,
  75. struct GNUNET_TIME_Absolute deadline,
  76. GNUNET_CONSENSUS_ElementCallback new_element_cb,
  77. void *new_element_cls);
  78. /**
  79. * Called when an insertion (transmission to consensus service, which
  80. * does not imply fully consensus on this element with all other
  81. * peers) was successful. May not call GNUNET_CONSENSUS_destroy();
  82. * schedule a task to call GNUNET_CONSENSUS_destroy() instead (if
  83. * needed).
  84. *
  85. * @param cls
  86. * @param success #GNUNET_OK on success, #GNUNET_SYSERR if
  87. * the insertion and thus the consensus failed for good
  88. */
  89. typedef void (*GNUNET_CONSENSUS_InsertDoneCallback) (void *cls,
  90. int success);
  91. /**
  92. * Insert an element in the set being reconsiled. Only transmit changes to
  93. * other peers if GNUNET_CONSENSUS_begin() has been called.
  94. * Must not be called after GNUNET_CONSENSUS_conclude().
  95. * May not call GNUNET_CONSENSUS_destroy(); schedule a task to call
  96. * GNUNET_CONSENSUS_destroy() instead (if needed).
  97. *
  98. * @param consensus handle for the consensus session
  99. * @param element the element to be inserted
  100. * @param idc function called when we are done with this element and it
  101. * is thus allowed to call GNUNET_CONSENSUS_insert() again
  102. * @param idc_cls closure for @a idc
  103. */
  104. void
  105. GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus,
  106. const struct GNUNET_SET_Element *element,
  107. GNUNET_CONSENSUS_InsertDoneCallback idc,
  108. void *idc_cls);
  109. /**
  110. * Called when a conclusion was successful.
  111. *
  112. * @param cls
  113. */
  114. typedef void (*GNUNET_CONSENSUS_ConcludeCallback) (void *cls);
  115. /**
  116. * We are finished inserting new elements into the consensus;
  117. * try to conclude the consensus within a given time window.
  118. *
  119. * @param consensus consensus session
  120. * @param conclude called when the conclusion was successful
  121. * @param conclude_cls closure for the conclude callback
  122. */
  123. void
  124. GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
  125. GNUNET_CONSENSUS_ConcludeCallback conclude,
  126. void *conclude_cls);
  127. /**
  128. * Destroy a consensus handle (free all state associated with
  129. * it, no longer call any of the callbacks).
  130. *
  131. * @param consensus handle to destroy
  132. */
  133. void
  134. GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus);
  135. #if 0 /* keep Emacsens' auto-indent happy */
  136. {
  137. #endif
  138. #ifdef __cplusplus
  139. }
  140. #endif
  141. #endif