client_manager: add API for async operations
[oweals/gnunet.git] / src / include / gnunet_scalarproduct_service.h
1 /*
2       This file is part of GNUnet.
3       Copyright (C) 2013, 2014 Christian Grothoff (and other contributing authors)
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, USA.
19  */
20
21 /**
22  * @file include/gnunet_scalarproduct_service.h
23  * @brief API to the scalarproduct service
24  * @author Christian M. Fuchs
25  * @author Gaurav Kukreja
26  */
27 #ifndef GNUNET_SCALARPRODUCT_SERVICE_H
28 #define GNUNET_SCALARPRODUCT_SERVICE_H
29 #define GCRYPT_NO_DEPRECATED
30 #include <gcrypt.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #if 0                           /* keep Emacsens' auto-indent happy */
35 }
36 #endif
37 #endif
38
39 /**
40  * Version of the scalarproduct API.
41  */
42 #define GNUNET_SCALARPRODUCT_VERSION 0x00000044
43
44 /**
45  * Result status values for the computation.
46  */
47 enum GNUNET_SCALARPRODUCT_ResponseStatus
48 {
49
50   /**
51    * Operation is still active (never returned, used internally).
52    */
53   GNUNET_SCALARPRODUCT_STATUS_ACTIVE = 0,
54
55   /**
56    * The computation was successful.
57    */
58   GNUNET_SCALARPRODUCT_STATUS_SUCCESS,
59
60   /**
61    * We encountered some error.
62    */
63   GNUNET_SCALARPRODUCT_STATUS_FAILURE,
64
65   /**
66    * We got an invalid response.
67    */
68   GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE,
69
70   /**
71    * We got disconnected from the SCALARPRODUCT service.
72    */
73   GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED
74 };
75
76
77 /**
78  * Opaque declaration of the SP-Handle
79  */
80 struct GNUNET_SCALARPRODUCT_Handle;
81
82
83 GNUNET_NETWORK_STRUCT_BEGIN
84
85 /**
86  * An element key-value pair for scalarproduct
87  */
88 struct GNUNET_SCALARPRODUCT_Element
89 {
90   /**
91    * Key used to identify matching pairs of values to multiply.
92    */
93   struct GNUNET_HashCode key;
94
95   /**
96    * Value to multiply in scalar product, in NBO.
97    */
98   int64_t value GNUNET_PACKED;
99 };
100
101 GNUNET_NETWORK_STRUCT_END
102
103
104 /**
105  * Continuation called to notify client about result of the
106  * operation.
107  *
108  * @param cls closure
109  * @param status Status of the request
110  */
111 typedef void
112 (*GNUNET_SCALARPRODUCT_ContinuationWithStatus) (void *cls,
113                                                 enum GNUNET_SCALARPRODUCT_ResponseStatus status);
114
115
116 /**
117  * Process a datum that was stored in the scalarproduct.
118  *
119  * @param cls closure
120  * @param status Status of the request
121  * @param result result of the computation
122  */
123 typedef void
124 (*GNUNET_SCALARPRODUCT_DatumProcessor) (void *cls,
125                                         enum GNUNET_SCALARPRODUCT_ResponseStatus status,
126                                         gcry_mpi_t result);
127
128
129 /**
130  * Entry in the request queue per client
131  */
132 struct GNUNET_SCALARPRODUCT_ComputationHandle;
133
134
135 /**
136  * Request by Alice's client for computing a scalar product
137  *
138  * @param cfg the gnunet configuration handle
139  * @param session_key Session key should be unique to the requesting client
140  * @param peer PeerID of the other peer
141  * @param elements Array of elements of the vector
142  * @param element_count Number of elements in the @a elements vector
143  * @param cont Callback function
144  * @param cont_cls Closure for the @a cont callback function
145  * @return a new handle for this computation
146  */
147 struct GNUNET_SCALARPRODUCT_ComputationHandle *
148 GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle *cfg,
149                               const struct GNUNET_HashCode *session_key,
150                               const struct GNUNET_PeerIdentity *peer,
151                               const struct GNUNET_SCALARPRODUCT_Element *elements,
152                               uint32_t element_count,
153                               GNUNET_SCALARPRODUCT_DatumProcessor cont,
154                               void *cont_cls);
155
156
157 /**
158  * Used by Bob's client to cooperate with Alice,
159  *
160  * @param cfg the gnunet configuration handle
161  * @param session_key Session key unique to the requesting client
162  * @param elements Array of elements of the vector
163  * @param element_count Number of elements in the @a elements vector
164  * @param cont Callback function
165  * @param cont_cls Closure for the @a cont callback function
166  * @return a new handle for this computation
167  */
168 struct GNUNET_SCALARPRODUCT_ComputationHandle *
169 GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handle *cfg,
170                                          const struct GNUNET_HashCode *key,
171                                          const struct GNUNET_SCALARPRODUCT_Element *elements,
172                                          uint32_t element_count,
173                                          GNUNET_SCALARPRODUCT_ContinuationWithStatus cont,
174                                          void *cont_cls);
175
176
177 /**
178  * Cancel an ongoing computation or revoke our collaboration offer.
179  * Closes the connection to the service
180  *
181  * @param h computation handle to terminate
182  */
183 void
184 GNUNET_SCALARPRODUCT_cancel (struct GNUNET_SCALARPRODUCT_ComputationHandle *h);
185
186 #if 0                           /* keep Emacsens' auto-indent happy */
187 {
188 #endif
189 #ifdef __cplusplus
190 }
191 #endif
192
193 #endif