aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_scalarproduct_service.h
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2013-09-02 13:29:11 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2013-09-02 13:29:11 +0000
commitac96c0fed4c6831772c198e6ad65714d525efceb (patch)
tree20733bd60abad9df404fd14b553cd0efcd6b7ae3 /src/include/gnunet_scalarproduct_service.h
parent4979b8e4e40c52ab898996cacffb27e90000e301 (diff)
downloadgnunet-ac96c0fed4c6831772c198e6ad65714d525efceb.tar.gz
gnunet-ac96c0fed4c6831772c198e6ad65714d525efceb.zip
updated API definitions as part of the API rework
Diffstat (limited to 'src/include/gnunet_scalarproduct_service.h')
-rw-r--r--src/include/gnunet_scalarproduct_service.h143
1 files changed, 77 insertions, 66 deletions
diff --git a/src/include/gnunet_scalarproduct_service.h b/src/include/gnunet_scalarproduct_service.h
index 4f877a735..64134d9ec 100644
--- a/src/include/gnunet_scalarproduct_service.h
+++ b/src/include/gnunet_scalarproduct_service.h
@@ -46,7 +46,8 @@ extern "C" {
46 * Message type passed from client to service 46 * Message type passed from client to service
47 * to initiate a request or responder role 47 * to initiate a request or responder role
48 */ 48 */
49struct GNUNET_SCALARPRODUCT_client_request { 49struct GNUNET_SCALARPRODUCT_client_request
50{
50 /** 51 /**
51 * GNUNET message header 52 * GNUNET message header
52 */ 53 */
@@ -55,13 +56,13 @@ struct GNUNET_SCALARPRODUCT_client_request {
55 /** 56 /**
56 * how many elements the vector in payload contains 57 * how many elements the vector in payload contains
57 */ 58 */
58 uint16_t element_count GNUNET_PACKED; 59 uint16_t element_count GNUNET_PACKED;
59 60
60 /** 61 /**
61 * how many bytes the mask has 62 * how many bytes the mask has
62 */ 63 */
63 uint16_t mask_length GNUNET_PACKED; 64 uint16_t mask_length GNUNET_PACKED;
64 65
65 /** 66 /**
66 * the transaction/session key used to identify a session 67 * the transaction/session key used to identify a session
67 */ 68 */
@@ -81,7 +82,8 @@ struct GNUNET_SCALARPRODUCT_client_request {
81 * Message type passed from service client 82 * Message type passed from service client
82 * to finalize a session as requester or responder 83 * to finalize a session as requester or responder
83 */ 84 */
84struct GNUNET_SCALARPRODUCT_client_response { 85struct GNUNET_SCALARPRODUCT_client_response
86{
85 /** 87 /**
86 * GNUNET message header 88 * GNUNET message header
87 */ 89 */
@@ -103,11 +105,17 @@ struct GNUNET_SCALARPRODUCT_client_response {
103 struct GNUNET_PeerIdentity peer; 105 struct GNUNET_PeerIdentity peer;
104 106
105 /** 107 /**
108 * Workaround for libgcrypt: -1 if negative, 0 if zero, else 1
109 */
110 int8_t range;
111
112 /**
106 * followed by product of length product_length (or nothing) 113 * followed by product of length product_length (or nothing)
107 */ 114 */
108}; 115};
109 116
110enum GNUNET_SCALARPRODUCT_ResponseStatus { 117enum GNUNET_SCALARPRODUCT_ResponseStatus
118{
111 GNUNET_SCALARPRODUCT_Status_Success = 0, 119 GNUNET_SCALARPRODUCT_Status_Success = 0,
112 GNUNET_SCALARPRODUCT_Status_Failure, 120 GNUNET_SCALARPRODUCT_Status_Failure,
113 GNUNET_SCALARPRODUCT_Status_Timeout, 121 GNUNET_SCALARPRODUCT_Status_Timeout,
@@ -115,7 +123,8 @@ enum GNUNET_SCALARPRODUCT_ResponseStatus {
115 GNUNET_SCALARPRODUCT_Status_ServiceDisconnected 123 GNUNET_SCALARPRODUCT_Status_ServiceDisconnected
116}; 124};
117 125
118struct GNUNET_SCALARPRODUCT_Handle { 126struct GNUNET_SCALARPRODUCT_Handle
127{
119 /** 128 /**
120 * Our configuration. 129 * Our configuration.
121 */ 130 */
@@ -132,33 +141,53 @@ struct GNUNET_SCALARPRODUCT_Handle {
132 struct GNUNET_STATISTICS_Handle *stats; 141 struct GNUNET_STATISTICS_Handle *stats;
133 142
134 /** 143 /**
135 * Current head of priority queue. 144 * Current transmit handle.
136 */ 145 */
137 struct GNUNET_SCALARPRODUCT_QueueEntry *queue_head; 146 struct GNUNET_CLIENT_TransmitHandle *th;
138 147
139 /** 148 /**
140 * Current tail of priority queue. 149 * Handle to the master context.
141 */ 150 */
142 struct GNUNET_SCALARPRODUCT_QueueEntry *queue_tail; 151 struct GNUNET_SCALARPRODUCT_Handle *h;
143 152
144 /** 153 /**
145 * Are we currently trying to receive from the service? 154 * The shared session key identifying this computation
146 */ 155 */
147 int in_receive; 156 struct GNUNET_HashCode * key;
157
158 /**
159 * The message to be transmitted
160 */
161 void * msg;
162
163 union
164 {
165 /**
166 * Function to call after transmission of the request.
167 */
168 GNUNET_SCALARPRODUCT_ContinuationWithStatus cont_status;
169
170 /**
171 * Function to call after transmission of the request.
172 */
173 GNUNET_SCALARPRODUCT_DatumProcessor cont_datum;
174 };
148 175
149 /** 176 /**
150 * Current transmit handle. 177 * Closure for 'cont'.
151 */ 178 */
152 struct GNUNET_CLIENT_TransmitHandle *th; 179 void *cont_cls;
153 180
154 /** 181 /**
155 * TODO: What else should/could go here? 182 * Response Processor for response from the service. This function calls the
183 * continuation function provided by the client.
156 */ 184 */
185 GNUNET_SCALARPRODUCT_ResponseMessageHandler response_proc;
157}; 186};
158 187
159typedef void (*GNUNET_SCALARPRODUCT_ResponseMessageHandler) (void *cls, 188typedef void (*GNUNET_SCALARPRODUCT_ResponseMessageHandler) (void *cls,
160 const struct GNUNET_MessageHeader *msg, 189 const struct GNUNET_MessageHeader *msg,
161 enum GNUNET_SCALARPRODUCT_ResponseStatus status); 190 enum GNUNET_SCALARPRODUCT_ResponseStatus status);
162 191
163/** 192/**
164 * Continuation called to notify client about result of the 193 * Continuation called to notify client about result of the
@@ -171,8 +200,7 @@ typedef void (*GNUNET_SCALARPRODUCT_ResponseMessageHandler) (void *cls,
171 * @param msg NULL on success, otherwise an error message 200 * @param msg NULL on success, otherwise an error message
172 */ 201 */
173typedef void (*GNUNET_SCALARPRODUCT_ContinuationWithStatus) (void *cls, 202typedef void (*GNUNET_SCALARPRODUCT_ContinuationWithStatus) (void *cls,
174 const struct GNUNET_HashCode * key, 203 enum GNUNET_SCALARPRODUCT_ResponseStatus status);
175 enum GNUNET_SCALARPRODUCT_ResponseStatus status);
176/** 204/**
177 * Process a datum that was stored in the scalarproduct. 205 * Process a datum that was stored in the scalarproduct.
178 * 206 *
@@ -185,75 +213,58 @@ typedef void (*GNUNET_SCALARPRODUCT_ContinuationWithStatus) (void *cls,
185 * @param type Type of data 213 * @param type Type of data
186 */ 214 */
187typedef void (*GNUNET_SCALARPRODUCT_DatumProcessor) (void *cls, 215typedef void (*GNUNET_SCALARPRODUCT_DatumProcessor) (void *cls,
188 const struct GNUNET_HashCode * key, 216 enum GNUNET_SCALARPRODUCT_ResponseStatus status,
189 const struct GNUNET_PeerIdentity * peer, 217 gcry_mpi_t result);
190 enum GNUNET_SCALARPRODUCT_ResponseStatus status,
191 const struct GNUNET_SCALARPRODUCT_client_response *msg);
192 218
193/** 219/**
194 * Request the Scalar Product Evaluation 220 * Request by Alice's client for computing a scalar product
195 * 221 *
196 * @param h handle to the master context 222 * @param h handle to the master context
197 * @param key Session key - unique to the requesting client 223 * @param key Session key - unique to the requesting client
198 * @param peer PeerID of the other peer 224 * @param peer PeerID of the other peer
199 * @param element_count Number of elements in the vector
200 * @param mask_bytes number of bytes in the mask
201 * @param elements Array of elements of the vector 225 * @param elements Array of elements of the vector
226 * @param element_count Number of elements in the vector
202 * @param mask Array of the mask 227 * @param mask Array of the mask
203 * @param timeout Relative timeout for the operation 228 * @param mask_bytes number of bytes in the mask
204 * @param cont Callback function 229 * @param cont Callback function
205 * @param cont_cls Closure for the callback function 230 * @param cont_cls Closure for the callback function
206 */ 231 */
207struct GNUNET_SCALARPRODUCT_QueueEntry * 232struct GNUNET_SCALARPRODUCT_Handle *
208GNUNET_SCALARPRODUCT_request(struct GNUNET_SCALARPRODUCT_Handle *h, 233GNUNET_SCALARPRODUCT_request (const struct GNUNET_CONFIGURATION_Handle *h,
209 const struct GNUNET_HashCode * key, 234 const struct GNUNET_HashCode * key,
210 const struct GNUNET_PeerIdentity *peer, 235 const struct GNUNET_PeerIdentity *peer,
211 uint16_t element_count, 236 const int32_t * elements,
212 uint16_t mask_bytes, 237 uint32_t element_count,
213 int32_t * elements, const unsigned char * mask, 238 const unsigned char * mask,
214 struct GNUNET_TIME_Relative timeout, 239 uint32_t mask_bytes,
215 GNUNET_SCALARPRODUCT_DatumProcessor cont, 240 GNUNET_SCALARPRODUCT_DatumProcessor cont,
216 void *cont_cls); 241 void *cont_cls);
217 242
218/** 243/**
219 * Called by the responder client to prepare response 244 * Used by Bob's client to cooperate with Alice,
220 * 245 *
221 * @param h handle to the master context 246 * @param h handle to the master context
222 * @param key Session key - unique to the requesting client 247 * @param key Session key - unique to the requesting client
223 * @param element_count Number of elements in the vector
224 * @param mask_bytes number of bytes in the mask
225 * @param elements Array of elements of the vector 248 * @param elements Array of elements of the vector
226 * @param mask Array of the mask 249 * @param element_count Number of elements in the vector
227 * @param timeout Relative timeout for the operation
228 * @param cont Callback function 250 * @param cont Callback function
229 * @param cont_cls Closure for the callback function 251 * @param cont_cls Closure for the callback function
230 */ 252 */
231struct GNUNET_SCALARPRODUCT_QueueEntry *
232GNUNET_SCALARPRODUCT_prepare_response(struct GNUNET_SCALARPRODUCT_Handle *h,
233 const struct GNUNET_HashCode * key,
234 uint16_t element_count,
235 int32_t* elements,
236 struct GNUNET_TIME_Relative timeout,
237 GNUNET_SCALARPRODUCT_ContinuationWithStatus cont,
238 void *cont_cls);
239
240/**
241 * Connect to the scalarproduct service.
242 *
243 * @param cfg configuration to use
244 * @return handle to use to access the service
245 */
246struct GNUNET_SCALARPRODUCT_Handle * 253struct GNUNET_SCALARPRODUCT_Handle *
247GNUNET_SCALARPRODUCT_connect(const struct GNUNET_CONFIGURATION_Handle * cfg); 254GNUNET_SCALARPRODUCT_response (const struct GNUNET_CONFIGURATION_Handle *h,
248 255 const struct GNUNET_HashCode * key,
256 const int32_t * elements,
257 uint32_t element_count,
258 GNUNET_SCALARPRODUCT_ContinuationWithStatus cont,
259 void *cont_cls);
249/** 260/**
250 * Disconnect from the scalarproduct service. 261 * Cancel an ongoing computation or revoke our collaboration offer.
262 * Closes the connection to the service
251 * 263 *
252 * @param h handle to the scalarproduct 264 * @param h handel to terminate
253 */ 265 */
254void 266void
255GNUNET_SCALARPRODUCT_disconnect(struct GNUNET_SCALARPRODUCT_Handle * h); 267GNUNET_SCALARPRODUCT_cancel (const struct GNUNET_SCALARPRODUCT_Handle *h);
256
257 268
258#if 0 /* keep Emacsens' auto-indent happy */ 269#if 0 /* keep Emacsens' auto-indent happy */
259{ 270{