- proper service-side error reporting for the SP API
[oweals/gnunet.git] / src / scalarproduct / scalarproduct.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010, 2011, 2012, 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   scalarproduct.h
23  * @brief  Scalar Product Message Types
24  * @author Christian M. Fuchs
25  *
26  * Created on September 2, 2013, 3:43 PM
27  */
28
29 #ifndef SCALARPRODUCT_H
30 #define SCALARPRODUCT_H
31
32 #ifdef  __cplusplus
33 extern "C"
34 {
35 #endif
36 ///////////////////////////////////////////////////////////////////////////////
37 //                      Defines
38 ///////////////////////////////////////////////////////////////////////////////
39
40 /**
41  * Maximum count of elements we can put into a multipart message
42  */
43 #define MULTIPART_ELEMENT_CAPACITY ((GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct GNUNET_SCALARPRODUCT_multipart_message)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext))
44
45 /**
46  * Log an error message at log-level 'level' that indicates
47  * a failure of the command 'cmd' with the message given
48  * by gcry_strerror(rc).
49  */
50 #define LOG_GCRY(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gcry_strerror(rc)); } while(0)
51
52 ///////////////////////////////////////////////////////////////////////////////
53 //                     Scalar Product Message Types
54 ///////////////////////////////////////////////////////////////////////////////
55
56 /**
57  * Message type passed from client to service
58  * to initiate a request or responder role
59  */
60 struct GNUNET_SCALARPRODUCT_computation_message
61 {
62   /**
63    * GNUNET message header
64    */
65   struct GNUNET_MessageHeader header;
66
67   /**
68    * how many elements the vector in payload contains
69    */
70   uint32_t element_count_total GNUNET_PACKED;
71   
72   /**
73    * contained elements the vector in payload contains
74    */
75   uint32_t element_count_contained GNUNET_PACKED;
76
77   /**
78    * the transaction/session key used to identify a session
79    */
80   struct GNUNET_HashCode session_key;
81
82   /**
83    * the identity of a remote peer we want to communicate with
84    */
85   struct GNUNET_PeerIdentity peer;
86
87   /**
88    * followed by struct GNUNET_SCALARPRODUCT_Element[]
89    */
90 };
91
92 /**
93  * multipart messages following GNUNET_SCALARPRODUCT_client_request
94  */
95 struct GNUNET_SCALARPRODUCT_computation_message_multipart
96 {
97   /**
98    * GNUNET message header
99    */
100   struct GNUNET_MessageHeader header;
101   
102   /**
103    * contained elements the vector in payload contains
104    */
105   uint32_t element_count_contained GNUNET_PACKED;
106
107   /**
108    * followed by struct GNUNET_SCALARPRODUCT_Element[]
109    */
110 };
111
112
113 /**
114  * Message type passed from requesting service Alice to responding service Bob
115  * to initiate a request and make bob participate in our protocol
116  */
117 struct GNUNET_SCALARPRODUCT_service_request {
118   /**
119    * GNUNET message header
120    */
121   struct GNUNET_MessageHeader header;
122
123   /**
124    * how many elements the total message including all multipart msgs contains
125    */
126   uint32_t total_element_count GNUNET_PACKED;
127
128   /**
129    * the transaction/session key used to identify a session
130    */
131   struct GNUNET_HashCode session_id;
132
133   /**
134    * Alice's public key
135    */
136   struct GNUNET_CRYPTO_PaillierPublicKey public_key;
137
138 };
139
140
141 /**
142  * Message type passed from requesting service Alice to responding service Bob
143  * to initiate a request and make bob participate in our protocol
144  */
145 struct GNUNET_SCALARPRODUCT_alices_cryptodata_message {
146   /**
147    * GNUNET message header
148    */
149   struct GNUNET_MessageHeader header;
150
151   /**
152    * how many elements we appended to this message
153    */
154   uint32_t contained_element_count GNUNET_PACKED;
155
156   /**
157    * struct GNUNET_CRYPTO_PaillierCiphertext[contained_element_count]
158    */
159 };
160
161 /**
162  * Multipart Message type passed between to supply additional elements for the peer
163  */
164 struct GNUNET_SCALARPRODUCT_multipart_message {
165   /**
166    * GNUNET message header
167    */
168   struct GNUNET_MessageHeader header;
169
170   /**
171    * how many elements we supply within this message
172    */
173   uint32_t contained_element_count GNUNET_PACKED;
174
175   // struct GNUNET_CRYPTO_PaillierCiphertext[multipart_element_count]
176 };
177
178 /**
179  * Message type passed from responding service Bob to responding service Alice
180  * to complete a request and allow Alice to compute the result
181  */
182 struct GNUNET_SCALARPRODUCT_service_response {
183   /**
184    * GNUNET message header
185    */
186   struct GNUNET_MessageHeader header;
187
188   /**
189    * how many elements the session input had
190    */
191   uint32_t total_element_count GNUNET_PACKED;
192
193   /**
194    * how many elements were included after the mask was applied including all multipart msgs.
195    */
196   uint32_t used_element_count GNUNET_PACKED;
197
198   /**
199    * how many elements this individual message delivers
200    */
201   uint32_t contained_element_count GNUNET_PACKED;
202
203   /**
204    * the transaction/session key used to identify a session
205    */
206   struct GNUNET_HashCode key;
207
208   /**
209    * followed by s | s' | k[i][perm]
210    */
211 };
212
213 /**
214  * Message type passed from service client
215  * to finalize a session as requester or responder
216  */
217 struct GNUNET_SCALARPRODUCT_client_response
218 {
219   /**
220    * GNUNET message header
221    */
222   struct GNUNET_MessageHeader header;
223
224   /**
225    * 0 if no product attached
226    */
227   uint32_t product_length GNUNET_PACKED;
228
229   /**
230    * the transaction/session key used to identify a session
231    */
232   struct GNUNET_HashCode key;
233
234   /**
235    * the identity of a remote peer we want to communicate with
236    */
237   struct GNUNET_PeerIdentity peer;
238
239   /**
240    * status information about the outcome of this session
241    */
242   int32_t status;
243   
244   /**
245    * Workaround for libgcrypt: -1 if negative, 0 if zero, else 1
246    */
247   int8_t range;
248
249   /**
250    * followed by product of length product_length (or nothing)
251    */
252 };
253
254 #ifdef  __cplusplus
255 }
256 #endif
257
258 #endif  /* SCALARPRODUCT_H */
259