towards PEERSTORE file plugin
[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 #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 0x00000042
43
44 enum GNUNET_SCALARPRODUCT_ResponseStatus
45 {
46   GNUNET_SCALARPRODUCT_Status_Success = 0,
47   GNUNET_SCALARPRODUCT_Status_Failure,
48   GNUNET_SCALARPRODUCT_Status_InvalidResponse,
49   GNUNET_SCALARPRODUCT_Status_ServiceDisconnected
50 };
51
52
53 /**
54  * Opaque declaration of the SP-Handle
55  */
56 struct GNUNET_SCALARPRODUCT_Handle;
57
58
59 /**
60  * Continuation called to notify client about result of the
61  * operation.
62  *
63  * @param cls closure
64  * @param status Status of the request
65  */
66 typedef void (*GNUNET_SCALARPRODUCT_ContinuationWithStatus) (void *cls,
67                                                              enum GNUNET_SCALARPRODUCT_ResponseStatus status);
68
69
70 /**
71  * Process a datum that was stored in the scalarproduct.
72  *
73  * @param cls closure
74  * @param status Status of the request
75  * @param result result of the computation
76  */
77 typedef void (*GNUNET_SCALARPRODUCT_DatumProcessor) (void *cls,
78                                                      enum GNUNET_SCALARPRODUCT_ResponseStatus status,
79                                                      gcry_mpi_t result);
80
81 /**
82  * Entry in the request queue per client
83  */
84 struct GNUNET_SCALARPRODUCT_ComputationHandle;
85
86 /**
87  * Request by Alice's client for computing a scalar product
88  *
89  * @param cfg the gnunet configuration handle
90  * @param key Session key should be unique to the requesting client
91  * @param peer PeerID of the other peer
92  * @param elements Array of elements of the vector
93  * @param element_count Number of elements in the vector
94  * @param mask Array of the mask
95  * @param mask_bytes number of bytes in the mask
96  * @param cont Callback function
97  * @param cont_cls Closure for @a cont
98  * @return a new handle for this computation
99  */
100 struct GNUNET_SCALARPRODUCT_ComputationHandle *
101 GNUNET_SCALARPRODUCT_request (const struct GNUNET_CONFIGURATION_Handle *cfg,
102                               const struct GNUNET_HashCode *key,
103                               const struct GNUNET_PeerIdentity *peer,
104                               const int32_t *elements,
105                               uint32_t element_count,
106                               const unsigned char *mask,
107                               uint32_t mask_bytes,
108                               GNUNET_SCALARPRODUCT_DatumProcessor cont,
109                               void * cont_cls);
110
111 /**
112  * Used by Bob's client to cooperate with Alice,
113  *
114  * @param cfg the gnunet configuration handle
115  * @param key Session key unique to the requesting client
116  * @param elements Array of elements of the vector
117  * @param element_count Number of elements in the vector
118  * @param cont Callback function
119  * @param cont_cls Closure for @a cont
120  * @return a new handle for this computation
121  */
122 struct GNUNET_SCALARPRODUCT_ComputationHandle *
123 GNUNET_SCALARPRODUCT_response (const struct GNUNET_CONFIGURATION_Handle *cfg,
124                                const struct GNUNET_HashCode *key,
125                                const int32_t *elements,
126                                uint32_t element_count,
127                                GNUNET_SCALARPRODUCT_ContinuationWithStatus cont,
128                                void *cont_cls);
129
130
131 /**
132  * Cancel an ongoing computation or revoke our collaboration offer.
133  * Closes the connection to the service
134  *
135  * @param h computation handle to terminate
136  */
137 void
138 GNUNET_SCALARPRODUCT_cancel (struct GNUNET_SCALARPRODUCT_ComputationHandle *h);
139
140
141 /**
142  * Cancel ALL ongoing computation or revoke our collaboration offer.
143  * Closes ALL connections to the service
144  *
145  * FIXME: this should take an argument, and we should
146  * have an explicit 'connect' API which returns an opaque
147  * connection handle.  Avoid (globals) in the library!
148  * @deprecated in this form
149  */
150 void
151 GNUNET_SCALARPRODUCT_disconnect ();
152
153
154 #if 0                           /* keep Emacsens' auto-indent happy */
155 {
156 #endif
157 #ifdef __cplusplus
158 }
159 #endif
160
161 #endif