gnunet_scalarproduct_service.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2013, 2014 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 M. Fuchs
  18. * @author Gaurav Kukreja
  19. *
  20. * @file
  21. * API to the scalarproduct service
  22. *
  23. * @defgroup scalarproduct Scalar Product service
  24. *
  25. * @{
  26. */
  27. #ifndef GNUNET_SCALARPRODUCT_SERVICE_H
  28. #define GNUNET_SCALARPRODUCT_SERVICE_H
  29. #define GCRYPT_NO_DEPRECATED
  30. #include <gcrypt.h>
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #if 0 /* keep Emacsens' auto-indent happy */
  34. }
  35. #endif
  36. #endif
  37. /**
  38. * Version of the scalarproduct API.
  39. */
  40. #define GNUNET_SCALARPRODUCT_VERSION 0x00000044
  41. /**
  42. * Result status values for the computation.
  43. */
  44. enum GNUNET_SCALARPRODUCT_ResponseStatus
  45. {
  46. /**
  47. * Operation is still active (never returned, used internally).
  48. */
  49. GNUNET_SCALARPRODUCT_STATUS_INIT = 0,
  50. /**
  51. * Operation is still active (never returned, used internally).
  52. */
  53. GNUNET_SCALARPRODUCT_STATUS_ACTIVE = 1,
  54. /**
  55. * The computation was successful.
  56. */
  57. GNUNET_SCALARPRODUCT_STATUS_SUCCESS,
  58. /**
  59. * We encountered some error.
  60. */
  61. GNUNET_SCALARPRODUCT_STATUS_FAILURE,
  62. /**
  63. * We got an invalid response.
  64. */
  65. GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE,
  66. /**
  67. * We got disconnected from the SCALARPRODUCT service.
  68. */
  69. GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED
  70. };
  71. /**
  72. * Opaque declaration of the SP-Handle
  73. */
  74. struct GNUNET_SCALARPRODUCT_Handle;
  75. GNUNET_NETWORK_STRUCT_BEGIN
  76. /**
  77. * An element key-value pair for scalarproduct
  78. */
  79. struct GNUNET_SCALARPRODUCT_Element
  80. {
  81. /**
  82. * Key used to identify matching pairs of values to multiply.
  83. */
  84. struct GNUNET_HashCode key;
  85. /**
  86. * Value to multiply in scalar product, in NBO.
  87. */
  88. int64_t value GNUNET_PACKED;
  89. };
  90. GNUNET_NETWORK_STRUCT_END
  91. /**
  92. * Continuation called to notify client about result of the
  93. * operation.
  94. *
  95. * @param cls closure
  96. * @param status Status of the request
  97. */
  98. typedef void
  99. (*GNUNET_SCALARPRODUCT_ContinuationWithStatus) (void *cls,
  100. enum
  101. GNUNET_SCALARPRODUCT_ResponseStatus
  102. status);
  103. /**
  104. * Process a datum that was stored in the scalarproduct.
  105. *
  106. * @param cls closure
  107. * @param status Status of the request
  108. * @param result result of the computation
  109. */
  110. typedef void
  111. (*GNUNET_SCALARPRODUCT_DatumProcessor) (void *cls,
  112. enum GNUNET_SCALARPRODUCT_ResponseStatus
  113. status,
  114. gcry_mpi_t result);
  115. /**
  116. * Entry in the request queue per client
  117. */
  118. struct GNUNET_SCALARPRODUCT_ComputationHandle;
  119. /**
  120. * Request by Alice's client for computing a scalar product
  121. *
  122. * @param cfg the gnunet configuration handle
  123. * @param session_key Session key should be unique to the requesting client
  124. * @param peer PeerID of the other peer
  125. * @param elements Array of elements of the vector
  126. * @param element_count Number of elements in the @a elements vector
  127. * @param cont Callback function
  128. * @param cont_cls Closure for the @a cont callback function
  129. * @return a new handle for this computation
  130. */
  131. struct GNUNET_SCALARPRODUCT_ComputationHandle *
  132. GNUNET_SCALARPRODUCT_start_computation (const struct
  133. GNUNET_CONFIGURATION_Handle *cfg,
  134. const struct
  135. GNUNET_HashCode *session_key,
  136. const struct GNUNET_PeerIdentity *peer,
  137. const struct
  138. GNUNET_SCALARPRODUCT_Element *elements,
  139. uint32_t element_count,
  140. GNUNET_SCALARPRODUCT_DatumProcessor cont,
  141. void *cont_cls);
  142. /**
  143. * Used by Bob's client to cooperate with Alice,
  144. *
  145. * @param cfg the gnunet configuration handle
  146. * @param session_key Session key unique to the requesting client
  147. * @param elements Array of elements of the vector
  148. * @param element_count Number of elements in the @a elements vector
  149. * @param cont Callback function
  150. * @param cont_cls Closure for the @a cont callback function
  151. * @return a new handle for this computation
  152. */
  153. struct GNUNET_SCALARPRODUCT_ComputationHandle *
  154. GNUNET_SCALARPRODUCT_accept_computation (const struct
  155. GNUNET_CONFIGURATION_Handle *cfg,
  156. const struct GNUNET_HashCode *key,
  157. const struct
  158. GNUNET_SCALARPRODUCT_Element *elements,
  159. uint32_t element_count,
  160. GNUNET_SCALARPRODUCT_ContinuationWithStatus
  161. cont,
  162. void *cont_cls);
  163. /**
  164. * Cancel an ongoing computation or revoke our collaboration offer.
  165. * Closes the connection to the service
  166. *
  167. * @param h computation handle to terminate
  168. */
  169. void
  170. GNUNET_SCALARPRODUCT_cancel (struct GNUNET_SCALARPRODUCT_ComputationHandle *h);
  171. #if 0 /* keep Emacsens' auto-indent happy */
  172. {
  173. #endif
  174. #ifdef __cplusplus
  175. }
  176. #endif
  177. #endif
  178. /** @} */ /* end of group */