gnunet_scalarproduct_service.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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) (
  100. void *cls,
  101. enum GNUNET_SCALARPRODUCT_ResponseStatus status);
  102. /**
  103. * Process a datum that was stored in the scalarproduct.
  104. *
  105. * @param cls closure
  106. * @param status Status of the request
  107. * @param result result of the computation
  108. */
  109. typedef void
  110. (*GNUNET_SCALARPRODUCT_DatumProcessor) (
  111. void *cls,
  112. enum GNUNET_SCALARPRODUCT_ResponseStatus status,
  113. gcry_mpi_t result);
  114. /**
  115. * Entry in the request queue per client
  116. */
  117. struct GNUNET_SCALARPRODUCT_ComputationHandle;
  118. /**
  119. * Request by Alice's client for computing a scalar product
  120. *
  121. * @param cfg the gnunet configuration handle
  122. * @param session_key Session key should be unique to the requesting client
  123. * @param peer PeerID of the other peer
  124. * @param elements Array of elements of the vector
  125. * @param element_count Number of elements in the @a elements vector
  126. * @param cont Callback function
  127. * @param cont_cls Closure for the @a cont callback function
  128. * @return a new handle for this computation
  129. */
  130. struct GNUNET_SCALARPRODUCT_ComputationHandle *
  131. GNUNET_SCALARPRODUCT_start_computation (
  132. const struct GNUNET_CONFIGURATION_Handle *cfg,
  133. const struct GNUNET_HashCode *session_key,
  134. const struct GNUNET_PeerIdentity *peer,
  135. const struct GNUNET_SCALARPRODUCT_Element *elements,
  136. uint32_t element_count,
  137. GNUNET_SCALARPRODUCT_DatumProcessor cont,
  138. void *cont_cls);
  139. /**
  140. * Used by Bob's client to cooperate with Alice,
  141. *
  142. * @param cfg the gnunet configuration handle
  143. * @param session_key Session key unique to the requesting client
  144. * @param elements Array of elements of the vector
  145. * @param element_count Number of elements in the @a elements vector
  146. * @param cont Callback function
  147. * @param cont_cls Closure for the @a cont callback function
  148. * @return a new handle for this computation
  149. */
  150. struct GNUNET_SCALARPRODUCT_ComputationHandle *
  151. GNUNET_SCALARPRODUCT_accept_computation (
  152. const struct GNUNET_CONFIGURATION_Handle *cfg,
  153. const struct GNUNET_HashCode *key,
  154. const struct GNUNET_SCALARPRODUCT_Element *elements,
  155. uint32_t element_count,
  156. GNUNET_SCALARPRODUCT_ContinuationWithStatus cont,
  157. void *cont_cls);
  158. /**
  159. * Cancel an ongoing computation or revoke our collaboration offer.
  160. * Closes the connection to the service
  161. *
  162. * @param h computation handle to terminate
  163. */
  164. void
  165. GNUNET_SCALARPRODUCT_cancel (struct GNUNET_SCALARPRODUCT_ComputationHandle *h);
  166. #if 0 /* keep Emacsens' auto-indent happy */
  167. {
  168. #endif
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif
  173. /** @} */ /* end of group */