peerstore: completed iterate functionality
[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 0x00000043
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  * An element key-value pair for scalarproduct
60  */
61 struct GNUNET_SCALARPRODUCT_Element {
62     int32_t value;
63     struct GNUNET_HashCode key;
64 };
65
66
67 /**
68  * Continuation called to notify client about result of the
69  * operation.
70  *
71  * @param cls closure
72  * @param status Status of the request
73  */
74 typedef void (*GNUNET_SCALARPRODUCT_ContinuationWithStatus) (void *cls,
75                                                              enum GNUNET_SCALARPRODUCT_ResponseStatus status);
76
77
78 /**
79  * Process a datum that was stored in the scalarproduct.
80  *
81  * @param cls closure
82  * @param status Status of the request
83  * @param result result of the computation
84  */
85 typedef void (*GNUNET_SCALARPRODUCT_DatumProcessor) (void *cls,
86                                                      enum GNUNET_SCALARPRODUCT_ResponseStatus status,
87                                                      gcry_mpi_t result);
88
89 /**
90  * Entry in the request queue per client
91  */
92 struct GNUNET_SCALARPRODUCT_ComputationHandle;
93
94 /**
95  * Request by Alice's client for computing a scalar product
96  *
97  * @param cfg the gnunet configuration handle
98  * @param session_key Session key should be unique to the requesting client
99  * @param peer PeerID of the other peer
100  * @param elements Array of elements of the vector
101  * @param element_count Number of elements in the vector
102  * @param cont Callback function
103  * @param cont_cls Closure for the callback function
104  *
105  * @return a new handle for this computation
106  */
107 struct GNUNET_SCALARPRODUCT_ComputationHandle *
108 GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle * cfg,
109                               const struct GNUNET_HashCode * session_key,
110                               const struct GNUNET_PeerIdentity *peer,
111                               const struct GNUNET_SCALARPRODUCT_Element * elements,
112                               uint32_t element_count,
113                               GNUNET_SCALARPRODUCT_DatumProcessor cont,
114                               void * cont_cls);
115
116 /**
117  * Used by Bob's client to cooperate with Alice,
118  *
119  * @param cfg the gnunet configuration handle
120  * @param session_key Session key unique to the requesting client
121  * @param elements Array of elements of the vector
122  * @param element_count Number of elements in the vector
123  * @param cont Callback function
124  * @param cont_cls Closure for the callback function
125  *
126  * @return a new handle for this computation
127  */
128 struct GNUNET_SCALARPRODUCT_ComputationHandle *
129 GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handle * cfg,
130                                const struct GNUNET_HashCode * key,
131                                const struct GNUNET_SCALARPRODUCT_Element * elements,
132                                uint32_t element_count,
133                                GNUNET_SCALARPRODUCT_ContinuationWithStatus cont,
134                                void * cont_cls);
135
136
137 /**
138  * Cancel an ongoing computation or revoke our collaboration offer.
139  * Closes the connection to the service
140  *
141  * @param h computation handle to terminate
142  */
143 void
144 GNUNET_SCALARPRODUCT_cancel (struct GNUNET_SCALARPRODUCT_ComputationHandle *h);
145
146 #if 0                           /* keep Emacsens' auto-indent happy */
147 {
148 #endif
149 #ifdef __cplusplus
150 }
151 #endif
152
153 #endif