print active/inactive information
[oweals/gnunet.git] / src / include / gnunet_scalarproduct_service.h
1 /*
2       This file is part of GNUnet.
3       (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    * The computation was successful.
51    */
52   GNUNET_SCALARPRODUCT_Status_Success = 0,
53
54   /**
55    * We encountered some error.
56    */
57   GNUNET_SCALARPRODUCT_Status_Failure,
58
59   /**
60    * We got an invalid response.
61    */
62   GNUNET_SCALARPRODUCT_Status_InvalidResponse,
63
64   /**
65    * We got disconnected from the SCALARPRODUCT service.
66    */
67   GNUNET_SCALARPRODUCT_Status_ServiceDisconnected
68 };
69
70
71 /**
72  * Opaque declaration of the SP-Handle
73  */
74 struct GNUNET_SCALARPRODUCT_Handle;
75
76
77 GNUNET_NETWORK_STRUCT_BEGIN
78
79 /**
80  * An element key-value pair for scalarproduct
81  */
82 struct GNUNET_SCALARPRODUCT_Element
83 {
84   /**
85    * Key used to identify matching pairs of values to multiply.
86    */
87   struct GNUNET_HashCode key;
88
89   /**
90    * Value to multiply in scalar product.
91    */
92   int64_t value GNUNET_PACKED;
93 };
94
95 GNUNET_NETWORK_STRUCT_END
96
97
98 /**
99  * Continuation called to notify client about result of the
100  * operation.
101  *
102  * @param cls closure
103  * @param status Status of the request
104  */
105 typedef void
106 (*GNUNET_SCALARPRODUCT_ContinuationWithStatus) (void *cls,
107                                                 enum GNUNET_SCALARPRODUCT_ResponseStatus status);
108
109
110 /**
111  * Process a datum that was stored in the scalarproduct.
112  *
113  * @param cls closure
114  * @param status Status of the request
115  * @param result result of the computation
116  */
117 typedef void
118 (*GNUNET_SCALARPRODUCT_DatumProcessor) (void *cls,
119                                         enum GNUNET_SCALARPRODUCT_ResponseStatus status,
120                                         gcry_mpi_t result);
121
122
123 /**
124  * Entry in the request queue per client
125  */
126 struct GNUNET_SCALARPRODUCT_ComputationHandle;
127
128
129 /**
130  * Request by Alice's client for computing a scalar product
131  *
132  * @param cfg the gnunet configuration handle
133  * @param session_key Session key should be unique to the requesting client
134  * @param peer PeerID of the other peer
135  * @param elements Array of elements of the vector
136  * @param element_count Number of elements in the @a elements vector
137  * @param cont Callback function
138  * @param cont_cls Closure for the @a cont callback function
139  * @return a new handle for this computation
140  */
141 struct GNUNET_SCALARPRODUCT_ComputationHandle *
142 GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle *cfg,
143                               const struct GNUNET_HashCode *session_key,
144                               const struct GNUNET_PeerIdentity *peer,
145                               const struct GNUNET_SCALARPRODUCT_Element *elements,
146                               uint32_t element_count,
147                               GNUNET_SCALARPRODUCT_DatumProcessor cont,
148                               void *cont_cls);
149
150
151 /**
152  * Used by Bob's client to cooperate with Alice,
153  *
154  * @param cfg the gnunet configuration handle
155  * @param session_key Session key unique to the requesting client
156  * @param elements Array of elements of the vector
157  * @param element_count Number of elements in the @a elements vector
158  * @param cont Callback function
159  * @param cont_cls Closure for the @a cont callback function
160  * @return a new handle for this computation
161  */
162 struct GNUNET_SCALARPRODUCT_ComputationHandle *
163 GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handle *cfg,
164                                          const struct GNUNET_HashCode *key,
165                                          const struct GNUNET_SCALARPRODUCT_Element *elements,
166                                          uint32_t element_count,
167                                          GNUNET_SCALARPRODUCT_ContinuationWithStatus cont,
168                                          void *cont_cls);
169
170
171 /**
172  * Cancel an ongoing computation or revoke our collaboration offer.
173  * Closes the connection to the service
174  *
175  * @param h computation handle to terminate
176  */
177 void
178 GNUNET_SCALARPRODUCT_cancel (struct GNUNET_SCALARPRODUCT_ComputationHandle *h);
179
180 #if 0                           /* keep Emacsens' auto-indent happy */
181 {
182 #endif
183 #ifdef __cplusplus
184 }
185 #endif
186
187 #endif