2 This file is part of GNUnet.
3 (C) 2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file include/gnunet_scalarproduct_service.h
23 * @brief API to the scalarproduct service
24 * @author Christian M. Fuchs
25 * @author Gaurav Kukreja
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...
35 #if 0 /* keep Emacsens' auto-indent happy */
41 * Version of the scalarproduct API.
43 #define GNUNET_SCALARPRODUCT_VERSION 0x00000042
46 * Message type passed from client to service
47 * to initiate a request or responder role
49 struct GNUNET_SCALARPRODUCT_client_request
52 * GNUNET message header
54 struct GNUNET_MessageHeader header;
57 * how many elements the vector in payload contains
59 uint16_t element_count GNUNET_PACKED;
62 * how many bytes the mask has
64 uint16_t mask_length GNUNET_PACKED;
67 * the transaction/session key used to identify a session
69 struct GNUNET_HashCode key;
72 * the identity of a remote peer we want to communicate with
74 struct GNUNET_PeerIdentity peer;
77 * followed by long vector[element_count] | [unsigned char mask[mask_bytes]]
82 * Message type passed from service client
83 * to finalize a session as requester or responder
85 struct GNUNET_SCALARPRODUCT_client_response
88 * GNUNET message header
90 struct GNUNET_MessageHeader header;
93 * 0 if no product attached
95 uint32_t product_length GNUNET_PACKED;
98 * the transaction/session key used to identify a session
100 struct GNUNET_HashCode key;
103 * the identity of a remote peer we want to communicate with
105 struct GNUNET_PeerIdentity peer;
108 * Workaround for libgcrypt: -1 if negative, 0 if zero, else 1
113 * followed by product of length product_length (or nothing)
117 enum GNUNET_SCALARPRODUCT_ResponseStatus
119 GNUNET_SCALARPRODUCT_Status_Success = 0,
120 GNUNET_SCALARPRODUCT_Status_Failure,
121 GNUNET_SCALARPRODUCT_Status_Timeout,
122 GNUNET_SCALARPRODUCT_Status_InvalidResponse,
123 GNUNET_SCALARPRODUCT_Status_ServiceDisconnected
126 struct GNUNET_SCALARPRODUCT_Handle
131 const struct GNUNET_CONFIGURATION_Handle *cfg;
134 * Current connection to the scalarproduct service.
136 struct GNUNET_CLIENT_Connection *client;
139 * Handle for statistics.
141 struct GNUNET_STATISTICS_Handle *stats;
144 * Current transmit handle.
146 struct GNUNET_CLIENT_TransmitHandle *th;
149 * Handle to the master context.
151 struct GNUNET_SCALARPRODUCT_Handle *h;
154 * The shared session key identifying this computation
156 struct GNUNET_HashCode * key;
159 * The message to be transmitted
166 * Function to call after transmission of the request.
168 GNUNET_SCALARPRODUCT_ContinuationWithStatus cont_status;
171 * Function to call after transmission of the request.
173 GNUNET_SCALARPRODUCT_DatumProcessor cont_datum;
177 * Closure for 'cont'.
182 * Response Processor for response from the service. This function calls the
183 * continuation function provided by the client.
185 GNUNET_SCALARPRODUCT_ResponseMessageHandler response_proc;
188 typedef void (*GNUNET_SCALARPRODUCT_ResponseMessageHandler) (void *cls,
189 const struct GNUNET_MessageHeader *msg,
190 enum GNUNET_SCALARPRODUCT_ResponseStatus status);
193 * Continuation called to notify client about result of the
197 * @param success GNUNET_SYSERR on failure (including timeout/queue drop)
198 * GNUNET_NO if content was already there
199 * GNUNET_YES (or other positive value) on success
200 * @param msg NULL on success, otherwise an error message
202 typedef void (*GNUNET_SCALARPRODUCT_ContinuationWithStatus) (void *cls,
203 enum GNUNET_SCALARPRODUCT_ResponseStatus status);
205 * Process a datum that was stored in the scalarproduct.
208 * @param key Sessioon key
209 * @param peer PeerID of the peer with whom the scalar product was calculated.
210 * @param status Status of the request
211 * @param size Size of the received message
212 * @param data Pointer to the data
213 * @param type Type of data
215 typedef void (*GNUNET_SCALARPRODUCT_DatumProcessor) (void *cls,
216 enum GNUNET_SCALARPRODUCT_ResponseStatus status,
220 * Request by Alice's client for computing a scalar product
222 * @param h handle to the master context
223 * @param key Session key - unique to the requesting client
224 * @param peer PeerID of the other peer
225 * @param elements Array of elements of the vector
226 * @param element_count Number of elements in the vector
227 * @param mask Array of the mask
228 * @param mask_bytes number of bytes in the mask
229 * @param cont Callback function
230 * @param cont_cls Closure for the callback function
232 struct GNUNET_SCALARPRODUCT_Handle *
233 GNUNET_SCALARPRODUCT_request (const struct GNUNET_CONFIGURATION_Handle *h,
234 const struct GNUNET_HashCode * key,
235 const struct GNUNET_PeerIdentity *peer,
236 const int32_t * elements,
237 uint32_t element_count,
238 const unsigned char * mask,
240 GNUNET_SCALARPRODUCT_DatumProcessor cont,
244 * Used by Bob's client to cooperate with Alice,
246 * @param h handle to the master context
247 * @param key Session key - unique to the requesting client
248 * @param elements Array of elements of the vector
249 * @param element_count Number of elements in the vector
250 * @param cont Callback function
251 * @param cont_cls Closure for the callback function
253 struct GNUNET_SCALARPRODUCT_Handle *
254 GNUNET_SCALARPRODUCT_response (const struct GNUNET_CONFIGURATION_Handle *h,
255 const struct GNUNET_HashCode * key,
256 const int32_t * elements,
257 uint32_t element_count,
258 GNUNET_SCALARPRODUCT_ContinuationWithStatus cont,
261 * Cancel an ongoing computation or revoke our collaboration offer.
262 * Closes the connection to the service
264 * @param h handel to terminate
267 GNUNET_SCALARPRODUCT_cancel (const struct GNUNET_SCALARPRODUCT_Handle *h);
269 #if 0 /* keep Emacsens' auto-indent happy */