5affd6377fa3780cd576b76bc6253700085734f0
[oweals/gnunet.git] / src / include / gnunet_scalarproduct_service.h
1 /*
2       This file is part of GNUnet.
3       (C) 2013 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 // including gcrypt crashes netbeans after the next restart...
31 #include <gcrypt.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 /**
41  * Version of the scalarproduct API.
42  */
43 #define GNUNET_SCALARPRODUCT_VERSION 0x00000042
44
45 enum GNUNET_SCALARPRODUCT_ResponseStatus
46 {
47   GNUNET_SCALARPRODUCT_Status_Success = 0,
48   GNUNET_SCALARPRODUCT_Status_Failure,
49   GNUNET_SCALARPRODUCT_Status_Timeout,
50   GNUNET_SCALARPRODUCT_Status_InvalidResponse,
51   GNUNET_SCALARPRODUCT_Status_ServiceDisconnected
52 };
53
54 struct GNUNET_SCALARPRODUCT_Handle
55 {
56   /**
57    * Our configuration.
58    */
59   const struct GNUNET_CONFIGURATION_Handle *cfg;
60
61   /**
62    * Current connection to the scalarproduct service.
63    */
64   struct GNUNET_CLIENT_Connection *client;
65
66   /**
67    * Handle for statistics.
68    */
69   struct GNUNET_STATISTICS_Handle *stats;
70
71   /**
72    * Current transmit handle.
73    */
74   struct GNUNET_CLIENT_TransmitHandle *th;
75   
76   /**
77    * Handle to the master context.
78    */
79   struct GNUNET_SCALARPRODUCT_Handle *h;
80   
81   /**
82    * The shared session key identifying this computation
83    */
84   struct GNUNET_HashCode * key;
85   
86   /**
87    * The message to be transmitted
88    */
89   void * msg;
90
91   union
92   {
93     /**
94      * Function to call after transmission of the request.
95      */
96     GNUNET_SCALARPRODUCT_ContinuationWithStatus cont_status;
97
98     /**
99      * Function to call after transmission of the request.
100      */
101     GNUNET_SCALARPRODUCT_DatumProcessor cont_datum;
102   };
103
104   /**
105    * Closure for 'cont'.
106    */
107   void *cont_cls;
108
109   /**
110    * Response Processor for response from the service. This function calls the
111    * continuation function provided by the client.
112    */
113   GNUNET_SCALARPRODUCT_ResponseMessageHandler response_proc;
114 };
115
116 typedef void (*GNUNET_SCALARPRODUCT_ResponseMessageHandler) (void *cls,
117                                                              const struct GNUNET_MessageHeader *msg,
118                                                              enum GNUNET_SCALARPRODUCT_ResponseStatus status);
119
120 /**
121  * Continuation called to notify client about result of the
122  * operation.
123  *
124  * @param cls closure
125  * @param status Status of the request
126  */
127 typedef void (*GNUNET_SCALARPRODUCT_ContinuationWithStatus) (void *cls,
128                                                              enum GNUNET_SCALARPRODUCT_ResponseStatus status);
129 /**
130  * Process a datum that was stored in the scalarproduct.
131  * 
132  * @param cls closure
133  * @param status Status of the request
134  * @param type result of the computation
135  */
136 typedef void (*GNUNET_SCALARPRODUCT_DatumProcessor) (void *cls,
137                                                      enum GNUNET_SCALARPRODUCT_ResponseStatus status,
138                                                      gcry_mpi_t result);
139
140 /**
141  * Request by Alice's client for computing a scalar product
142  * 
143  * @param h handle to the master context
144  * @param key Session key - unique to the requesting client
145  * @param peer PeerID of the other peer
146  * @param elements Array of elements of the vector
147  * @param element_count Number of elements in the vector
148  * @param mask Array of the mask
149  * @param mask_bytes number of bytes in the mask
150  * @param cont Callback function
151  * @param cont_cls Closure for the callback function
152  */
153 struct GNUNET_SCALARPRODUCT_Handle *
154 GNUNET_SCALARPRODUCT_request (const struct GNUNET_CONFIGURATION_Handle *h,
155                               const struct GNUNET_HashCode * key,
156                               const struct GNUNET_PeerIdentity *peer,
157                               const int32_t * elements,
158                               uint32_t element_count,
159                               const unsigned char * mask,
160                               uint32_t mask_bytes,
161                               GNUNET_SCALARPRODUCT_DatumProcessor cont,
162                               void *cont_cls);
163
164 /**
165  * Used by Bob's client to cooperate with Alice, 
166  * 
167  * @param h handle to the master context
168  * @param key Session key - unique to the requesting client
169  * @param elements Array of elements of the vector
170  * @param element_count Number of elements in the vector
171  * @param cont Callback function
172  * @param cont_cls Closure for the callback function
173  */
174 struct GNUNET_SCALARPRODUCT_Handle *
175 GNUNET_SCALARPRODUCT_response (const struct GNUNET_CONFIGURATION_Handle *h,
176                                const struct GNUNET_HashCode * key,
177                                const int32_t * elements,
178                                uint32_t element_count,
179                                GNUNET_SCALARPRODUCT_ContinuationWithStatus cont,
180                                void *cont_cls);
181 /**
182  * Cancel an ongoing computation or revoke our collaboration offer.
183  * Closes the connection to the service
184  * 
185  * @param h handel to terminate
186  */
187 void 
188 GNUNET_SCALARPRODUCT_cancel (const struct GNUNET_SCALARPRODUCT_Handle *h);
189
190 #if 0                           /* keep Emacsens' auto-indent happy */
191 {
192 #endif
193 #ifdef __cplusplus
194 }
195 #endif
196
197 #endif