diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-09-17 14:41:39 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-09-17 14:41:39 +0000 |
commit | f605b91f795d125009fd402dc92fdae987e3c012 (patch) | |
tree | 7a18399310f66d133d6e529a166ebc3dfa48af7d /src/scalarproduct | |
parent | 86bfb1ddbff2bd7b45d9927b24e50f5afb063feb (diff) | |
download | gnunet-f605b91f795d125009fd402dc92fdae987e3c012.tar.gz gnunet-f605b91f795d125009fd402dc92fdae987e3c012.zip |
removed old, deprecated SP tests
added new test which is only a bash script and computes the vectorproduct.
TODO: proper logging output, add a second test that kills one service instance
Diffstat (limited to 'src/scalarproduct')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 2 | ||||
-rwxr-xr-x | src/scalarproduct/test_scalarproduct.sh | 31 | ||||
-rw-r--r-- | src/scalarproduct/test_scalarproduct_api_4peers.c | 1084 | ||||
-rw-r--r-- | src/scalarproduct/test_scalarproduct_api_data.conf | 96 | ||||
-rw-r--r-- | src/scalarproduct/test_scalarproduct_api_regression.c | 851 | ||||
-rw-r--r-- | src/scalarproduct/test_scalarproduct_api_regression2.c | 931 |
6 files changed, 32 insertions, 2963 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index ebc953624..99ae47332 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -2079,7 +2079,7 @@ shutdown_task (void *cls, | |||
2079 | session->client = NULL; | 2079 | session->client = NULL; |
2080 | } | 2080 | } |
2081 | } | 2081 | } |
2082 | for (session = from_service_head; NULL != session; session = from_service_head) | 2082 | for (session = from_service_head; NULL != session; session = session->next) |
2083 | if (NULL != session->tunnel){ | 2083 | if (NULL != session->tunnel){ |
2084 | GNUNET_MESH_tunnel_destroy (session->tunnel); | 2084 | GNUNET_MESH_tunnel_destroy (session->tunnel); |
2085 | session->tunnel = NULL; | 2085 | session->tunnel = NULL; |
diff --git a/src/scalarproduct/test_scalarproduct.sh b/src/scalarproduct/test_scalarproduct.sh new file mode 100755 index 000000000..81bd9c2ec --- /dev/null +++ b/src/scalarproduct/test_scalarproduct.sh | |||
@@ -0,0 +1,31 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | CFGA="-c ./test_scalarproduct_alice.conf" | ||
4 | CFGB="-c ./test_scalarproduct_bob.conf" | ||
5 | #can't use ` directly | ||
6 | SESSIONDATA="-k AAAA -e 10,10,10" | ||
7 | EXPECTED="2C0" | ||
8 | |||
9 | gnunet-arm -s $CFGA | ||
10 | sleep 2 | ||
11 | gnunet-arm -s $CFGB | ||
12 | sleep 2 | ||
13 | |||
14 | IDB=`gnunet-peerinfo -s $CFGB | awk -F "\x60" '{print $2}' | awk -F "'" '{print $1}'` | ||
15 | |||
16 | gnunet-scalarproduct $CFGB $SESSIONDATA | ||
17 | |||
18 | RESULT=`gnunet-scalarproduct $CFGA $SESSIONDATA -p $IDB` | ||
19 | |||
20 | gnunet-arm -e $CFGA & | ||
21 | gnunet-arm -e $CFGB & | ||
22 | |||
23 | if [ "$RESULT" == "$EXPECTED" ] | ||
24 | then | ||
25 | echo "OK" | ||
26 | exit 0 | ||
27 | else | ||
28 | echo "Result $RESULT NOTOK" | ||
29 | exit 1 | ||
30 | fi | ||
31 | |||
diff --git a/src/scalarproduct/test_scalarproduct_api_4peers.c b/src/scalarproduct/test_scalarproduct_api_4peers.c deleted file mode 100644 index c0e045e28..000000000 --- a/src/scalarproduct/test_scalarproduct_api_4peers.c +++ /dev/null | |||
@@ -1,1084 +0,0 @@ | |||
1 | |||
2 | /* | ||
3 | This file is part of GNUnet. | ||
4 | (C) 2013 Christian Grothoff (and other contributing authors) | ||
5 | |||
6 | GNUnet is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published | ||
8 | by the Free Software Foundation; either version 3, or (at your | ||
9 | option) any later version. | ||
10 | |||
11 | GNUnet is distributed in the hope that it will be useful, but | ||
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with GNUnet; see the file COPYING. If not, write to the | ||
18 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
19 | Boston, MA 02111-1307, USA. | ||
20 | */ | ||
21 | |||
22 | /** | ||
23 | * AIM OF THIS TEST | ||
24 | * | ||
25 | * The aim for the extended test is to verify the queuing functionality in the | ||
26 | * service and the API. The API queues requests received from the clients. The | ||
27 | * service queues requests that are received from other services. | ||
28 | * | ||
29 | * To test this, we create 4 peers. peer1 and peer2 are designated responders, | ||
30 | * and peer3 and peer4 are designated as requesters. Each peer calls API for the | ||
31 | * scalarproduct service accordingly. | ||
32 | * | ||
33 | * * peer1 tells the service to prepare response for requests with keys | ||
34 | * input_key_p1_p3(shared key b/w peer1 and peer3) and input_key_p1_p4. | ||
35 | * Similarly peer2 tells service to prepare response for requests with keys | ||
36 | * input_key_p2_p3, and input_key_p2_p4. | ||
37 | * * Simultaneously, peer3 tells its service to send a request to peer1 with key | ||
38 | * input_key_p1_p3, and a request to peer2 with key input_key_p2_p3. Similarly, | ||
39 | * peer 4 sends requests with appropriate keys. | ||
40 | * | ||
41 | * Each peer sends 2 requests to its service, which tests the queuing in API. | ||
42 | * Each service receives 2 requests from other service, which tests the queuing | ||
43 | * functionality in the service. | ||
44 | */ | ||
45 | |||
46 | |||
47 | /** | ||
48 | * @file scalarproduct/test_scalarproduct_api_4peers.c | ||
49 | * @brief Vectorproduct API testing between 4 peers using testing API | ||
50 | * @author Gaurav Kukreja | ||
51 | * @author Christian Fuchs | ||
52 | */ | ||
53 | |||
54 | #include <string.h> | ||
55 | |||
56 | #include <inttypes.h> | ||
57 | #include "platform.h" | ||
58 | #include "gnunet_util_lib.h" | ||
59 | #include "gnunet_testbed_service.h" | ||
60 | #include "gnunet_common.h" | ||
61 | #include "gnunet_scalarproduct_service.h" | ||
62 | #include "gnunet_protocols.h" | ||
63 | |||
64 | #define LOG(kind,...) GNUNET_log_from (kind, "test-scalarproduct-api-4peers",__VA_ARGS__) | ||
65 | |||
66 | #define NUM_PEERS 4 | ||
67 | |||
68 | /** | ||
69 | * Structure for holding peer's sockets and IO Handles | ||
70 | */ | ||
71 | struct PeerData | ||
72 | { | ||
73 | /** | ||
74 | * Handle to testbed peer | ||
75 | */ | ||
76 | struct GNUNET_TESTBED_Peer *peer; | ||
77 | |||
78 | /** | ||
79 | * The service connect operation to stream | ||
80 | */ | ||
81 | struct GNUNET_TESTBED_Operation *op; | ||
82 | |||
83 | /** | ||
84 | * Our Peer id | ||
85 | */ | ||
86 | struct GNUNET_PeerIdentity our_id; | ||
87 | |||
88 | /** | ||
89 | * Pointer to Vector Product Handle | ||
90 | */ | ||
91 | struct GNUNET_SCALARPRODUCT_Handle *vh; | ||
92 | |||
93 | /** | ||
94 | * Input elements for peer | ||
95 | */ | ||
96 | char * input_elements; | ||
97 | |||
98 | /** | ||
99 | * Input Mask for peer | ||
100 | */ | ||
101 | char * input_mask; | ||
102 | |||
103 | /** | ||
104 | * 2 Input keys for peer for 2 sessions of each peer | ||
105 | */ | ||
106 | char * input_keys[2]; | ||
107 | |||
108 | /** | ||
109 | * Number of requests(or prepare_response) sent by the peer | ||
110 | */ | ||
111 | int request_num; | ||
112 | |||
113 | /** | ||
114 | * Number of callbacks received by the peer | ||
115 | */ | ||
116 | int callback_num; | ||
117 | |||
118 | /** | ||
119 | * PeerData of the peers, this peer will talk to | ||
120 | */ | ||
121 | struct PeerData * peers[2]; | ||
122 | |||
123 | |||
124 | }; | ||
125 | |||
126 | /** | ||
127 | * Different states in test setup | ||
128 | */ | ||
129 | enum SetupState | ||
130 | { | ||
131 | /** | ||
132 | * Get the identity of peer 1 | ||
133 | */ | ||
134 | PEER1_GET_IDENTITY, | ||
135 | |||
136 | /** | ||
137 | * Get the identity of peer 2 | ||
138 | */ | ||
139 | PEER2_GET_IDENTITY, | ||
140 | |||
141 | /** | ||
142 | * Get the identity of peer 3 | ||
143 | */ | ||
144 | PEER3_GET_IDENTITY, | ||
145 | |||
146 | /** | ||
147 | * Get the identity of peer 4 | ||
148 | */ | ||
149 | PEER4_GET_IDENTITY, | ||
150 | |||
151 | /** | ||
152 | * Connect to stream service of peer 1 | ||
153 | */ | ||
154 | PEER1_SCALARPRODUCT_CONNECT, | ||
155 | |||
156 | /** | ||
157 | * Connect to stream service of peer 2 | ||
158 | */ | ||
159 | PEER2_SCALARPRODUCT_CONNECT, | ||
160 | |||
161 | /** | ||
162 | * Connect to stream service of peer 3 | ||
163 | */ | ||
164 | PEER3_SCALARPRODUCT_CONNECT, | ||
165 | |||
166 | /** | ||
167 | * Connect to stream service of peer 4 | ||
168 | */ | ||
169 | PEER4_SCALARPRODUCT_CONNECT | ||
170 | |||
171 | }; | ||
172 | |||
173 | /****************************************************************************** | ||
174 | *** Global Variables ***************************** | ||
175 | ******************************************************************************/ | ||
176 | |||
177 | /** | ||
178 | * Maximum allowed message-ids we can check in one go (with one GNUNET_message) | ||
179 | */ | ||
180 | static unsigned int max_mids; | ||
181 | |||
182 | /** | ||
183 | * Session Key used by both the test peers | ||
184 | */ | ||
185 | char input_key_p1_p3[103] = "111111111111111111111111111111111111111111111111113333333333333333333333333333333333333333333333333333"; | ||
186 | |||
187 | /** | ||
188 | * Session Key used by both the test peers | ||
189 | */ | ||
190 | char input_key_p1_p4[103] = "111111111111111111111111111111111111111111111111114444444444444444444444444444444444444444444444444444"; | ||
191 | |||
192 | /** | ||
193 | * Session Key used by both the test peers | ||
194 | */ | ||
195 | char input_key_p2_p3[103] = "222222222222222222222222222222222222222222222222223333333333333333333333333333333333333333333333333333"; | ||
196 | |||
197 | /** | ||
198 | * Session Key used by both the test peers | ||
199 | */ | ||
200 | char input_key_p2_p4[103] = "222222222222222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444"; | ||
201 | |||
202 | /** | ||
203 | * Input elements for peer1 | ||
204 | */ | ||
205 | //char input_elements_peer1[] = "11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11"; | ||
206 | char input_elements_peer1[] = "11,11,11"; | ||
207 | |||
208 | /** | ||
209 | * Input Mask for peer 1 | ||
210 | */ | ||
211 | //char input_mask_peer1[] = "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"; | ||
212 | char input_mask_peer1[] = "1,1,1"; | ||
213 | |||
214 | /** | ||
215 | * Input elements for peer2 | ||
216 | */ | ||
217 | //char input_elements_peer2[] = "11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11"; | ||
218 | char input_elements_peer2[] = "11,11,11"; | ||
219 | /** | ||
220 | * Input Mask for peer 2 | ||
221 | */ | ||
222 | //char input_mask_peer2[] = "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"; | ||
223 | char input_mask_peer2[] = "1,1,1"; | ||
224 | |||
225 | /** | ||
226 | * Input elements for peer3 | ||
227 | */ | ||
228 | //char input_elements_peer3[] = "11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11"; | ||
229 | char input_elements_peer3[] = "11,11,11"; | ||
230 | |||
231 | /** | ||
232 | * Input Mask for peer 3 | ||
233 | */ | ||
234 | //char input_mask_peer3[] = "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"; | ||
235 | char input_mask_peer3[] = "1,1,1"; | ||
236 | |||
237 | /** | ||
238 | * Input elements for peer4 | ||
239 | */ | ||
240 | //char input_elements_peer4[] = "11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11"; | ||
241 | char input_elements_peer4[] = "11,11,11"; | ||
242 | /** | ||
243 | * Input Mask for peer 4 | ||
244 | */ | ||
245 | //char input_mask_peer4[] = "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"; | ||
246 | char input_mask_peer4[] = "1,1,1"; | ||
247 | |||
248 | |||
249 | /** | ||
250 | * Data context for peer 1 | ||
251 | */ | ||
252 | static struct PeerData peer1; | ||
253 | |||
254 | /** | ||
255 | * Data context for peer 2 | ||
256 | */ | ||
257 | static struct PeerData peer2; | ||
258 | |||
259 | /** | ||
260 | * Data context for peer 3 | ||
261 | */ | ||
262 | static struct PeerData peer3; | ||
263 | |||
264 | /** | ||
265 | * Data context for peer 4 | ||
266 | */ | ||
267 | static struct PeerData peer4; | ||
268 | |||
269 | /** | ||
270 | * Various states during test setup | ||
271 | */ | ||
272 | static enum SetupState setup_state; | ||
273 | |||
274 | /** | ||
275 | * Testbed operation handle | ||
276 | */ | ||
277 | static struct GNUNET_TESTBED_Operation *op; | ||
278 | |||
279 | /** | ||
280 | * Return value for the test | ||
281 | */ | ||
282 | static int ok; | ||
283 | |||
284 | /** | ||
285 | * Abort Task for timeout | ||
286 | */ | ||
287 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | ||
288 | /****************************************************************************** | ||
289 | *** Static Functions ***************************** | ||
290 | ******************************************************************************/ | ||
291 | |||
292 | static void | ||
293 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
294 | |||
295 | |||
296 | /** | ||
297 | * Close sockets and stop testing deamons nicely | ||
298 | */ | ||
299 | static void | ||
300 | do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
301 | { | ||
302 | if (peer1.op != NULL) | ||
303 | GNUNET_SCHEDULER_add_now (&do_shutdown, &peer1); | ||
304 | |||
305 | if (peer2.op != NULL) | ||
306 | GNUNET_SCHEDULER_add_now (&do_shutdown, &peer2); | ||
307 | |||
308 | if (peer3.op != NULL) | ||
309 | GNUNET_SCHEDULER_add_now (&do_shutdown, &peer3); | ||
310 | |||
311 | if (peer4.op != NULL) | ||
312 | GNUNET_SCHEDULER_add_now (&do_shutdown, &peer4); | ||
313 | |||
314 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
315 | GNUNET_SCHEDULER_cancel (abort_task); | ||
316 | |||
317 | GNUNET_SCHEDULER_shutdown (); /* For shutting down testbed */ | ||
318 | } | ||
319 | |||
320 | |||
321 | static void | ||
322 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
323 | { | ||
324 | static int shutdown; | ||
325 | shutdown++; | ||
326 | struct PeerData* peer = (struct PeerData*) cls; | ||
327 | |||
328 | if (peer == &peer1) | ||
329 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down Peer 1!!! \n"); | ||
330 | else if (peer == &peer2) | ||
331 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down Peer 2!!! \n"); | ||
332 | else if (peer == &peer3) | ||
333 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down Peer 3!!! \n"); | ||
334 | else if (peer == &peer4) | ||
335 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down Peer 4!!! \n"); | ||
336 | |||
337 | // peer->op contains handle to the TESTBED_connect_service operation | ||
338 | // calling operation done, leads to call to scalarproduct_da | ||
339 | GNUNET_TESTBED_operation_done (peer->op); | ||
340 | peer->op = NULL; | ||
341 | |||
342 | if (shutdown == 4) | ||
343 | GNUNET_SCHEDULER_add_now (&do_close, NULL); | ||
344 | } | ||
345 | |||
346 | |||
347 | /** | ||
348 | * Something went wrong and timed out. Kill everything and set error flag | ||
349 | */ | ||
350 | static void | ||
351 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
352 | { | ||
353 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: ABORT due to Timeout\n"); | ||
354 | ok = GNUNET_SYSERR; | ||
355 | abort_task = 0; | ||
356 | do_close (cls, tc); | ||
357 | } | ||
358 | |||
359 | |||
360 | /** | ||
361 | * Controller event callback | ||
362 | * | ||
363 | * @param cls NULL | ||
364 | * @param event the controller event | ||
365 | */ | ||
366 | static void | ||
367 | controller_event_cb (void *cls, | ||
368 | const struct GNUNET_TESTBED_EventInformation *event) | ||
369 | { | ||
370 | switch (event->type) | ||
371 | { | ||
372 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
373 | switch (setup_state) | ||
374 | { | ||
375 | case PEER1_SCALARPRODUCT_CONNECT: | ||
376 | case PEER2_SCALARPRODUCT_CONNECT: | ||
377 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | ||
378 | break; | ||
379 | default: | ||
380 | GNUNET_assert (0); | ||
381 | } | ||
382 | break; | ||
383 | default: | ||
384 | GNUNET_assert (0); | ||
385 | } | ||
386 | } | ||
387 | |||
388 | |||
389 | static void | ||
390 | responder_callback (void *cls, | ||
391 | const struct GNUNET_HashCode * key, | ||
392 | enum GNUNET_SCALARPRODUCT_ResponseStatus status) | ||
393 | { | ||
394 | struct PeerData * peer = cls; | ||
395 | |||
396 | peer->callback_num++; | ||
397 | |||
398 | if (peer == &peer1) | ||
399 | { | ||
400 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer1 received callback!!!\n"); | ||
401 | } | ||
402 | else if (peer == &peer2) | ||
403 | { | ||
404 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer2 received callback!!!\n"); | ||
405 | } | ||
406 | else | ||
407 | LOG (GNUNET_ERROR_TYPE_ERROR, "Requester callback received, but peer is neither peer1 nor peer2!!!\n"); | ||
408 | |||
409 | |||
410 | if (status == GNUNET_SCALARPRODUCT_Status_Failure) | ||
411 | { | ||
412 | LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client received status failure\n"); | ||
413 | ok = -1; | ||
414 | } | ||
415 | else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse) | ||
416 | { | ||
417 | LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client received status invalid response\n"); | ||
418 | ok = -1; | ||
419 | } | ||
420 | else if (GNUNET_SCALARPRODUCT_Status_Timeout == status) | ||
421 | { | ||
422 | LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client received timeout occured\n"); | ||
423 | ok = -1; | ||
424 | } | ||
425 | else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status) | ||
426 | { | ||
427 | LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client received service disconnected!!\n"); | ||
428 | ok = -1; | ||
429 | } | ||
430 | else if (GNUNET_SCALARPRODUCT_Status_Success == status) | ||
431 | { | ||
432 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Responder Client expected response received!\n"); | ||
433 | ok = 1; | ||
434 | } | ||
435 | else | ||
436 | { | ||
437 | LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client status = %d!\n", (int) status); | ||
438 | ok = -1; | ||
439 | } | ||
440 | |||
441 | // TODO : Responder Session Complete. Shutdown Test Cleanly!!! | ||
442 | if (peer->callback_num == 2) | ||
443 | GNUNET_SCHEDULER_add_now (&do_shutdown, peer); | ||
444 | } | ||
445 | |||
446 | |||
447 | static void | ||
448 | requester_callback (void *cls, | ||
449 | const struct GNUNET_HashCode * key, | ||
450 | const struct GNUNET_PeerIdentity * peer, | ||
451 | enum GNUNET_SCALARPRODUCT_ResponseStatus status, | ||
452 | const struct GNUNET_SCALARPRODUCT_client_response *msg) | ||
453 | { | ||
454 | struct PeerData * peer_ = cls; | ||
455 | uint32_t product_len; | ||
456 | |||
457 | peer_->callback_num++; | ||
458 | |||
459 | if (peer_ == &peer3) | ||
460 | { | ||
461 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer3 received callback!!!\n"); | ||
462 | } | ||
463 | else if (peer_ == &peer4) | ||
464 | { | ||
465 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer4 received callback!!!\n"); | ||
466 | } | ||
467 | else | ||
468 | LOG (GNUNET_ERROR_TYPE_ERROR, "Requester callback received, but peer is neither peer3 nor peer4!!!\n"); | ||
469 | |||
470 | |||
471 | if (status == GNUNET_SCALARPRODUCT_Status_Failure) | ||
472 | { | ||
473 | LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client received status failure\n"); | ||
474 | ok = -1; | ||
475 | } | ||
476 | else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse) | ||
477 | { | ||
478 | LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client received status invalid response\n"); | ||
479 | ok = -1; | ||
480 | } | ||
481 | else if (GNUNET_SCALARPRODUCT_Status_Timeout == status) | ||
482 | { | ||
483 | LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client timeout occured\n"); | ||
484 | ok = -1; | ||
485 | } | ||
486 | else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status) | ||
487 | { | ||
488 | LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client service disconnected!!\n"); | ||
489 | ok = -1; | ||
490 | } | ||
491 | else if (GNUNET_SCALARPRODUCT_Status_Success != status) | ||
492 | { | ||
493 | LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client Status = %d\n", (int) status); | ||
494 | ok = -1; | ||
495 | } | ||
496 | else if (GNUNET_SCALARPRODUCT_Status_Success == status) | ||
497 | { | ||
498 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requester client received status successful!\n"); | ||
499 | product_len = ntohl (msg->product_length); | ||
500 | |||
501 | if (0 < product_len) | ||
502 | { | ||
503 | gcry_mpi_t result; | ||
504 | gcry_error_t ret = 0; | ||
505 | size_t read = 0; | ||
506 | |||
507 | ret = gcry_mpi_scan (&result, GCRYMPI_FMT_USG, (void*) &(msg[1]), product_len, &read); | ||
508 | |||
509 | if (0 != ret) | ||
510 | { | ||
511 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not convert to mpi to value!\n"); | ||
512 | } | ||
513 | else | ||
514 | { | ||
515 | gcry_mpi_release (result); | ||
516 | } | ||
517 | ok = 1; | ||
518 | } | ||
519 | else | ||
520 | { | ||
521 | //currently not used, but if we get more info due to MESH we will need this | ||
522 | LOG (GNUNET_ERROR_TYPE_ERROR, "Error during computation of vector product, return code: %d\n", product_len); | ||
523 | ok = -1; | ||
524 | } | ||
525 | } | ||
526 | |||
527 | if (peer_->callback_num == 2) | ||
528 | GNUNET_SCHEDULER_add_now (&do_shutdown, peer_); | ||
529 | } | ||
530 | |||
531 | |||
532 | static struct GNUNET_SCALARPRODUCT_QueueEntry * | ||
533 | requester_request (char * input_elements, | ||
534 | char * input_mask, | ||
535 | char * input_key, | ||
536 | struct PeerData * peer, | ||
537 | struct PeerData * to_peer) | ||
538 | { | ||
539 | |||
540 | |||
541 | unsigned int i; | ||
542 | uint16_t element_count = 0; | ||
543 | int32_t * elements = NULL; | ||
544 | uint16_t mask_length = 0; | ||
545 | unsigned char * mask = NULL; | ||
546 | int32_t element; | ||
547 | struct GNUNET_SCALARPRODUCT_QueueEntry *qe; | ||
548 | struct GNUNET_HashCode key; | ||
549 | int exit_loop; | ||
550 | char * begin = input_elements; | ||
551 | char * end; | ||
552 | |||
553 | GNUNET_assert (peer->vh != NULL); | ||
554 | |||
555 | GNUNET_CRYPTO_hash_from_string (input_key, &key); | ||
556 | |||
557 | exit_loop = 0; | ||
558 | /* Read input_elements, and put in elements array */ | ||
559 | do | ||
560 | { | ||
561 | unsigned int mcount = element_count; | ||
562 | //ignore empty rows of ,,,,,, | ||
563 | while (*begin == ',') | ||
564 | begin++; | ||
565 | // get the length of the current element and replace , with null | ||
566 | for (end = begin; *end && *end != ','; end++); | ||
567 | |||
568 | if (*end == '\0') | ||
569 | exit_loop = 1; | ||
570 | |||
571 | |||
572 | if (1 != sscanf (begin, "%" SCNd32, &element)) | ||
573 | { | ||
574 | FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin); | ||
575 | ok = -1; | ||
576 | return NULL; | ||
577 | } | ||
578 | |||
579 | GNUNET_array_append (elements, mcount, element); | ||
580 | element_count++; | ||
581 | |||
582 | begin = ++end; | ||
583 | } | ||
584 | while (!exit_loop && element_count < max_mids); | ||
585 | GNUNET_assert (elements != NULL); | ||
586 | GNUNET_assert (element_count >= 1); | ||
587 | |||
588 | /* Read input_mask and read in mask array */ | ||
589 | mask_length = element_count / 8 + (element_count % 8 ? 1 : 0); | ||
590 | mask = GNUNET_malloc ((element_count / 8) + 2); | ||
591 | GNUNET_assert (NULL != mask); | ||
592 | if (NULL != input_mask) | ||
593 | { | ||
594 | begin = input_mask; | ||
595 | unsigned short mask_count = 0; | ||
596 | int exit_loop = 0; | ||
597 | |||
598 | do | ||
599 | { | ||
600 | //ignore empty rows of ,,,,,, | ||
601 | while (* begin == ',') | ||
602 | begin++; | ||
603 | // get the length of the current element and replace , with null | ||
604 | // gnunet_ascii-armor uses base32, thus we can use , as separator! | ||
605 | for (end = begin; *end && *end != ','; end++); | ||
606 | |||
607 | if (*end == '\0') | ||
608 | exit_loop = 1; | ||
609 | |||
610 | |||
611 | if (1 != sscanf (begin, "%" SCNd32, &element)) | ||
612 | { | ||
613 | FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin); | ||
614 | ok = -1; | ||
615 | return NULL; | ||
616 | } | ||
617 | |||
618 | GNUNET_assert (mask_count <= element_count); | ||
619 | |||
620 | if (element) | ||
621 | mask[mask_count / 8] = mask[mask_count / 8] | 1 << (mask_count % 8); | ||
622 | |||
623 | mask_count++; | ||
624 | begin = ++end; | ||
625 | } | ||
626 | while (!exit_loop); | ||
627 | // +1 to see if we would have more data, which would indicate malformed/superficial input | ||
628 | GNUNET_assert (mask_count == element_count); | ||
629 | } | ||
630 | else | ||
631 | { | ||
632 | for (i = 0; i <= mask_length; i++) | ||
633 | mask[i] = UCHAR_MAX; // all 1's | ||
634 | } | ||
635 | |||
636 | qe = GNUNET_SCALARPRODUCT_request (peer->vh, | ||
637 | &key, | ||
638 | &to_peer->our_id, | ||
639 | element_count, | ||
640 | mask_length, | ||
641 | elements, mask, | ||
642 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60), | ||
643 | &requester_callback, | ||
644 | peer); | ||
645 | |||
646 | if (qe == NULL) | ||
647 | { | ||
648 | LOG(GNUNET_ERROR_TYPE_WARNING, "Could not send request to scalarproduct service! Exitting!"); | ||
649 | ok = -1; | ||
650 | return NULL; | ||
651 | } | ||
652 | |||
653 | return qe; | ||
654 | } | ||
655 | |||
656 | |||
657 | /** | ||
658 | * Function prepares the message to be sent by peer1 to its scalarproduct service | ||
659 | * to prepare response, and wait for a request session to be initiated by peer1 | ||
660 | */ | ||
661 | static struct GNUNET_SCALARPRODUCT_QueueEntry * | ||
662 | responder_prepare_response (char * input_elements, | ||
663 | char * input_mask, | ||
664 | char * input_key, | ||
665 | struct PeerData * peer) | ||
666 | { | ||
667 | GNUNET_assert (peer->vh != NULL); | ||
668 | |||
669 | unsigned int i; | ||
670 | uint16_t element_count = 0; | ||
671 | int32_t * elements = NULL; | ||
672 | unsigned short mask_length = 0; | ||
673 | unsigned char * mask = NULL; | ||
674 | int32_t element; | ||
675 | struct GNUNET_SCALARPRODUCT_QueueEntry *qe; | ||
676 | struct GNUNET_HashCode key; | ||
677 | int exit_loop; | ||
678 | char * begin; | ||
679 | char * end; | ||
680 | |||
681 | GNUNET_CRYPTO_hash_from_string (input_key, &key); | ||
682 | |||
683 | /* Read input_elements, and put in elements array */ | ||
684 | exit_loop = 0; | ||
685 | begin = input_elements; | ||
686 | do | ||
687 | { | ||
688 | unsigned int mcount = element_count; | ||
689 | //ignore empty rows of ,,,,,, | ||
690 | while (*begin == ',') | ||
691 | begin++; | ||
692 | // get the length of the current element and replace , with null | ||
693 | for (end = begin; *end && *end != ','; end++); | ||
694 | |||
695 | if (*end == '\0') | ||
696 | exit_loop = 1; | ||
697 | |||
698 | if (1 != sscanf (begin, "%" SCNd32, &element)) | ||
699 | { | ||
700 | FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin); | ||
701 | ok = -1; | ||
702 | return NULL; | ||
703 | } | ||
704 | |||
705 | GNUNET_array_append (elements, mcount, element); | ||
706 | element_count++; | ||
707 | |||
708 | begin = ++end; | ||
709 | } | ||
710 | while (!exit_loop && element_count < max_mids); | ||
711 | GNUNET_assert (elements != NULL); | ||
712 | GNUNET_assert (element_count >= 1); | ||
713 | |||
714 | /* Read input_mask and read in mask array */ | ||
715 | mask_length = element_count / 8 + (element_count % 8 ? 1 : 0); | ||
716 | mask = GNUNET_malloc ((element_count / 8) + 2); | ||
717 | GNUNET_assert (NULL != mask); | ||
718 | if (NULL != input_mask) | ||
719 | { | ||
720 | begin = input_mask; | ||
721 | unsigned short mask_count = 0; | ||
722 | int exit_loop = 0; | ||
723 | |||
724 | do | ||
725 | { | ||
726 | //ignore empty rows of ,,,,,, | ||
727 | while (* begin == ',') | ||
728 | begin++; | ||
729 | // get the length of the current element and replace , with null | ||
730 | // gnunet_ascii-armor uses base32, thus we can use , as separator! | ||
731 | for (end = begin; *end && *end != ','; end++); | ||
732 | |||
733 | if (*end == '\0') | ||
734 | exit_loop = 1; | ||
735 | |||
736 | if (1 != sscanf (begin, "%" SCNd32, &element)) | ||
737 | { | ||
738 | FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin); | ||
739 | ok = -1; | ||
740 | return NULL; | ||
741 | } | ||
742 | |||
743 | GNUNET_assert (mask_count <= element_count); | ||
744 | |||
745 | if (element) | ||
746 | mask[mask_count / 8] = mask[mask_count / 8] | 1 << (mask_count % 8); | ||
747 | |||
748 | mask_count++; | ||
749 | begin = ++end; | ||
750 | } | ||
751 | while (!exit_loop); | ||
752 | // +1 to see if we would have more data, which would indicate malformed/superficial input | ||
753 | GNUNET_assert (mask_count == element_count); | ||
754 | } | ||
755 | else | ||
756 | { | ||
757 | for (i = 0; i <= mask_length; i++) | ||
758 | mask[i] = UCHAR_MAX; // all 1's | ||
759 | } | ||
760 | |||
761 | qe = GNUNET_SCALARPRODUCT_prepare_response (peer->vh, | ||
762 | &key, | ||
763 | element_count, | ||
764 | elements, | ||
765 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60), | ||
766 | &responder_callback, | ||
767 | peer); | ||
768 | |||
769 | if (qe == NULL) | ||
770 | { | ||
771 | LOG(GNUNET_ERROR_TYPE_ERROR, "Could not send request to scalarproduct service! Exitting!"); | ||
772 | ok = -1; | ||
773 | return NULL; | ||
774 | } | ||
775 | |||
776 | return qe; | ||
777 | } | ||
778 | |||
779 | |||
780 | static void | ||
781 | request_task (void *cls, | ||
782 | const struct GNUNET_SCHEDULER_TaskContext | ||
783 | * tc) | ||
784 | { | ||
785 | struct PeerData * peer = cls; | ||
786 | |||
787 | requester_request (peer->input_elements, peer->input_mask, peer->input_keys[peer->request_num], peer, peer->peers[peer->request_num]); | ||
788 | peer->request_num++; | ||
789 | return; | ||
790 | } | ||
791 | |||
792 | |||
793 | static void | ||
794 | prepare_response_task (void *cls, | ||
795 | const struct GNUNET_SCHEDULER_TaskContext | ||
796 | * tc) | ||
797 | { | ||
798 | struct PeerData * peer = cls; | ||
799 | |||
800 | responder_prepare_response (peer->input_elements, peer->input_mask, peer->input_keys[peer->request_num], peer); | ||
801 | peer->request_num++; | ||
802 | return; | ||
803 | } | ||
804 | |||
805 | |||
806 | /** | ||
807 | * Adapter function called to destroy a connection to | ||
808 | * a service. This function is called when GNUNET_TESTBED_operation_done is | ||
809 | * called for peer->op, which holds the handle for GNUNET_TESTBED_service_connect | ||
810 | * operation. | ||
811 | * | ||
812 | * @param cls closure | ||
813 | * @param op_result service handle returned from the connect adapter | ||
814 | */ | ||
815 | static void | ||
816 | scalarproduct_da (void *cls, void *op_result) | ||
817 | { | ||
818 | struct PeerData* peer = (struct PeerData*) cls; | ||
819 | |||
820 | GNUNET_SCALARPRODUCT_cancel (peer->vh); | ||
821 | return; | ||
822 | |||
823 | GNUNET_assert (0); | ||
824 | } | ||
825 | |||
826 | |||
827 | /** | ||
828 | * Adapter function called to establish a connection to | ||
829 | * a service. This function is called to by GNUNET_TESTBED_service_connect. | ||
830 | * | ||
831 | * @param cls closure | ||
832 | * @param cfg configuration of the peer to connect to; will be available until | ||
833 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
834 | * from GNUNET_TESTBED_service_connect() | ||
835 | * @return service handle to return in 'op_result', NULL on error | ||
836 | */ | ||
837 | static void * | ||
838 | scalarproduct_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
839 | { | ||
840 | struct PeerData *p = cls; | ||
841 | |||
842 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", (&peer1 == p) ? 1 : 2, | ||
843 | GNUNET_i2s (&p->our_id)); | ||
844 | |||
845 | switch (setup_state) | ||
846 | { | ||
847 | case PEER1_SCALARPRODUCT_CONNECT: | ||
848 | /* Connect peer 2 to scalarproduct service */ | ||
849 | { | ||
850 | peer2.op = GNUNET_TESTBED_service_connect (&peer2, peer2.peer, "scalarproduct", | ||
851 | NULL, NULL, scalarproduct_ca, | ||
852 | scalarproduct_da, &peer2); | ||
853 | setup_state = PEER2_SCALARPRODUCT_CONNECT; | ||
854 | } | ||
855 | |||
856 | peer1.vh = GNUNET_SCALARPRODUCT_connect (cfg); | ||
857 | return peer1.vh; | ||
858 | |||
859 | case PEER2_SCALARPRODUCT_CONNECT: | ||
860 | /* Connect peer 3 to scalarproduct service */ | ||
861 | { | ||
862 | peer3.op = GNUNET_TESTBED_service_connect (&peer3, peer3.peer, "scalarproduct", | ||
863 | NULL, NULL, scalarproduct_ca, | ||
864 | scalarproduct_da, &peer3); | ||
865 | setup_state = PEER3_SCALARPRODUCT_CONNECT; | ||
866 | } | ||
867 | |||
868 | peer2.vh = GNUNET_SCALARPRODUCT_connect (cfg); | ||
869 | return peer2.vh; | ||
870 | |||
871 | case PEER3_SCALARPRODUCT_CONNECT: | ||
872 | /* Connect peer 4 to scalarproduct service */ | ||
873 | { | ||
874 | peer4.op = GNUNET_TESTBED_service_connect (&peer4, peer4.peer, "scalarproduct", | ||
875 | NULL, NULL, scalarproduct_ca, | ||
876 | scalarproduct_da, &peer4); | ||
877 | setup_state = PEER4_SCALARPRODUCT_CONNECT; | ||
878 | } | ||
879 | |||
880 | peer3.vh = GNUNET_SCALARPRODUCT_connect (cfg); | ||
881 | return peer3.vh; | ||
882 | |||
883 | case PEER4_SCALARPRODUCT_CONNECT: | ||
884 | peer4.vh = GNUNET_SCALARPRODUCT_connect (cfg); | ||
885 | |||
886 | /* Schedule the tasks to issue prepare_response calls from peer1 and peer2 | ||
887 | * for peer3 and peer4. | ||
888 | */ | ||
889 | GNUNET_SCHEDULER_add_now (&prepare_response_task, &peer1); | ||
890 | GNUNET_SCHEDULER_add_now (&prepare_response_task, &peer1); | ||
891 | GNUNET_SCHEDULER_add_now (&prepare_response_task, &peer2); | ||
892 | GNUNET_SCHEDULER_add_now (&prepare_response_task, &peer2); | ||
893 | |||
894 | /* | ||
895 | * Schedule the tasks to issue requests calls from peer3 and peer4 | ||
896 | * to peer1 and peer2 | ||
897 | */ | ||
898 | GNUNET_SCHEDULER_add_now (&request_task, &peer3); | ||
899 | GNUNET_SCHEDULER_add_now (&request_task, &peer3); | ||
900 | GNUNET_SCHEDULER_add_now (&request_task, &peer4); | ||
901 | GNUNET_SCHEDULER_add_now (&request_task, &peer4); | ||
902 | |||
903 | return peer2.vh; | ||
904 | default: | ||
905 | GNUNET_assert (0); | ||
906 | } | ||
907 | } | ||
908 | |||
909 | |||
910 | /** | ||
911 | * Callback to be called when the requested peer information is available | ||
912 | * | ||
913 | * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information() | ||
914 | * @param op the operation this callback corresponds to | ||
915 | * @param pinfo the result; will be NULL if the operation has failed | ||
916 | * @param emsg error message if the operation has failed; will be NULL if the | ||
917 | * operation is successfull | ||
918 | */ | ||
919 | static void | ||
920 | peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_, | ||
921 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
922 | const char *emsg) | ||
923 | { | ||
924 | GNUNET_assert (NULL == emsg); | ||
925 | GNUNET_assert (op == op_); | ||
926 | switch (setup_state) | ||
927 | { | ||
928 | case PEER1_GET_IDENTITY: | ||
929 | { | ||
930 | memcpy (&peer1.our_id, pinfo->result.id, | ||
931 | sizeof (struct GNUNET_PeerIdentity)); | ||
932 | GNUNET_TESTBED_operation_done (op); | ||
933 | |||
934 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 id: %s\n", GNUNET_i2s_full | ||
935 | (&peer1.our_id)); | ||
936 | |||
937 | /* Request for peer id of peer 2*/ | ||
938 | op = GNUNET_TESTBED_peer_get_information (peer2.peer, | ||
939 | GNUNET_TESTBED_PIT_IDENTITY, | ||
940 | &peerinfo_cb, NULL); | ||
941 | setup_state = PEER2_GET_IDENTITY; | ||
942 | } | ||
943 | break; | ||
944 | case PEER2_GET_IDENTITY: | ||
945 | { | ||
946 | memcpy (&peer2.our_id, pinfo->result.id, | ||
947 | sizeof (struct GNUNET_PeerIdentity)); | ||
948 | GNUNET_TESTBED_operation_done (op); | ||
949 | |||
950 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n", GNUNET_i2s_full | ||
951 | (&peer2.our_id)); | ||
952 | |||
953 | /* Request for peer id of peer 3*/ | ||
954 | op = GNUNET_TESTBED_peer_get_information (peer3.peer, | ||
955 | GNUNET_TESTBED_PIT_IDENTITY, | ||
956 | &peerinfo_cb, NULL); | ||
957 | setup_state = PEER3_GET_IDENTITY; | ||
958 | } | ||
959 | break; | ||
960 | case PEER3_GET_IDENTITY: | ||
961 | { | ||
962 | memcpy (&peer3.our_id, pinfo->result.id, | ||
963 | sizeof (struct GNUNET_PeerIdentity)); | ||
964 | GNUNET_TESTBED_operation_done (op); | ||
965 | |||
966 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 3 id: %s\n", GNUNET_i2s_full | ||
967 | (&peer3.our_id)); | ||
968 | |||
969 | /* Request for peer id of peer 4*/ | ||
970 | op = GNUNET_TESTBED_peer_get_information (peer4.peer, | ||
971 | GNUNET_TESTBED_PIT_IDENTITY, | ||
972 | &peerinfo_cb, NULL); | ||
973 | setup_state = PEER4_GET_IDENTITY; | ||
974 | } | ||
975 | break; | ||
976 | case PEER4_GET_IDENTITY: | ||
977 | { | ||
978 | memcpy (&peer4.our_id, pinfo->result.id, | ||
979 | sizeof (struct GNUNET_PeerIdentity)); | ||
980 | GNUNET_TESTBED_operation_done (op); | ||
981 | |||
982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n", GNUNET_i2s_full | ||
983 | (&peer2.our_id)); | ||
984 | |||
985 | /* Connect peer 1 to scalarproduct service */ | ||
986 | peer1.op = GNUNET_TESTBED_service_connect (&peer1, peer1.peer, "scalarproduct", | ||
987 | NULL, NULL, scalarproduct_ca, | ||
988 | scalarproduct_da, &peer1); | ||
989 | setup_state = PEER1_SCALARPRODUCT_CONNECT; | ||
990 | } | ||
991 | break; | ||
992 | default: | ||
993 | GNUNET_assert (0); | ||
994 | } | ||
995 | } | ||
996 | |||
997 | |||
998 | /** | ||
999 | * Signature of a main function for a testcase. | ||
1000 | * | ||
1001 | * @param cls closure | ||
1002 | * @param num_peers number of peers in 'peers' | ||
1003 | * @param peers handle to peers run in the testbed | ||
1004 | */ | ||
1005 | static void | ||
1006 | test_master (void *cls, unsigned int num_peers, | ||
1007 | struct GNUNET_TESTBED_Peer **peers) | ||
1008 | { | ||
1009 | GNUNET_assert (NULL != peers); | ||
1010 | GNUNET_assert (NULL != peers[0]); | ||
1011 | GNUNET_assert (NULL != peers[1]); | ||
1012 | GNUNET_assert (NULL != peers[2]); | ||
1013 | GNUNET_assert (NULL != peers[3]); | ||
1014 | peer1.peer = peers[0]; | ||
1015 | peer1.input_elements = input_elements_peer1; | ||
1016 | peer1.input_mask = input_mask_peer1; | ||
1017 | peer1.request_num = 0; | ||
1018 | peer1.callback_num = 0; | ||
1019 | peer1.input_keys[0] = input_key_p1_p3; | ||
1020 | peer1.input_keys[1] = input_key_p1_p4; | ||
1021 | |||
1022 | peer2.peer = peers[1]; | ||
1023 | peer2.input_elements = input_elements_peer2; | ||
1024 | peer2.input_mask = input_mask_peer2; | ||
1025 | peer2.request_num = 0; | ||
1026 | peer2.callback_num = 0; | ||
1027 | peer2.input_keys[0] = input_key_p2_p3; | ||
1028 | peer2.input_keys[1] = input_key_p2_p4; | ||
1029 | |||
1030 | peer3.peer = peers[2]; | ||
1031 | peer3.input_elements = input_elements_peer3; | ||
1032 | peer3.input_mask = input_mask_peer3; | ||
1033 | peer3.request_num = 0; | ||
1034 | peer3.callback_num = 0; | ||
1035 | peer3.input_keys[0] = input_key_p1_p3; | ||
1036 | peer3.input_keys[1] = input_key_p2_p3; | ||
1037 | peer3.peers[0] = &peer1; | ||
1038 | peer3.peers[1] = &peer2; | ||
1039 | |||
1040 | |||
1041 | peer4.peer = peers[3]; | ||
1042 | peer4.input_elements = input_elements_peer4; | ||
1043 | peer4.input_mask = input_mask_peer4; | ||
1044 | peer4.request_num = 0; | ||
1045 | peer4.callback_num = 0; | ||
1046 | peer4.input_keys[0] = input_key_p1_p4; | ||
1047 | peer4.input_keys[1] = input_key_p2_p4; | ||
1048 | peer4.peers[0] = &peer1; | ||
1049 | peer4.peers[1] = &peer2; | ||
1050 | |||
1051 | /* Get the peer identity and configuration of peer 1 */ | ||
1052 | op = GNUNET_TESTBED_peer_get_information (peer1.peer, | ||
1053 | GNUNET_TESTBED_PIT_IDENTITY, | ||
1054 | &peerinfo_cb, NULL); | ||
1055 | setup_state = PEER1_GET_IDENTITY; | ||
1056 | abort_task = | ||
1057 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
1058 | (GNUNET_TIME_UNIT_SECONDS, 120), &do_abort, | ||
1059 | NULL); | ||
1060 | } | ||
1061 | |||
1062 | |||
1063 | /** | ||
1064 | * Main function | ||
1065 | */ | ||
1066 | int | ||
1067 | main (int argc, char **argv) | ||
1068 | { | ||
1069 | uint64_t event_mask; | ||
1070 | |||
1071 | ok = GNUNET_NO; | ||
1072 | event_mask = 0; | ||
1073 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
1074 | max_mids = (GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_MessageHeader)) | ||
1075 | / sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1; | ||
1076 | (void) GNUNET_TESTBED_test_run ("test_scalarproduct_api_4peers", | ||
1077 | "test_scalarproduct_api_data.conf", | ||
1078 | NUM_PEERS, event_mask, &controller_event_cb, | ||
1079 | NULL, | ||
1080 | &test_master, NULL); | ||
1081 | if (GNUNET_SYSERR == ok) | ||
1082 | return 1; | ||
1083 | return 0; | ||
1084 | } | ||
diff --git a/src/scalarproduct/test_scalarproduct_api_data.conf b/src/scalarproduct/test_scalarproduct_api_data.conf deleted file mode 100644 index b0b1c257e..000000000 --- a/src/scalarproduct/test_scalarproduct_api_data.conf +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | [arm] | ||
2 | DEFAULTSERVICES = core transport vectorproduct mesh testbed | ||
3 | PORT = 12366 | ||
4 | |||
5 | [core] | ||
6 | PORT = 12092 | ||
7 | |||
8 | [vectorproduct] | ||
9 | #AUTOSTART = YES | ||
10 | BINARY = gnunet-service-vectorproduct | ||
11 | UNIXPATH = /tmp/gnunet-service-vectorproduct.sock | ||
12 | HOME = $SERVICEHOME | ||
13 | HOSTNAME = localhost | ||
14 | PORT = 2087 | ||
15 | |||
16 | [testbed] | ||
17 | OVERLAY_TOPOLOGY = CLIQUE | ||
18 | |||
19 | [lockmanager] | ||
20 | AUTOSTART = NO | ||
21 | ACCEPT_FROM = 127.0.0.1; | ||
22 | HOSTNAME = localhost | ||
23 | PORT = 12101 | ||
24 | |||
25 | [statistics] | ||
26 | AUTOSTART = YES | ||
27 | ACCEPT_FROM = 127.0.0.1; | ||
28 | PORT = 12102 | ||
29 | |||
30 | [fs] | ||
31 | AUTOSTART = NO | ||
32 | |||
33 | [resolver] | ||
34 | AUTOSTART = NO | ||
35 | |||
36 | [mesh] | ||
37 | # AUTOSTART = YES | ||
38 | ACCEPT_FROM = 127.0.0.1; | ||
39 | HOSTNAME = localhost | ||
40 | PORT = 10700 | ||
41 | # PREFIX = valgrind --leak-check=full | ||
42 | # PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args | ||
43 | |||
44 | [dht] | ||
45 | AUTOSTART = YES | ||
46 | ACCEPT_FROM6 = ::1; | ||
47 | ACCEPT_FROM = 127.0.0.1; | ||
48 | HOSTNAME = localhost | ||
49 | PORT = 12100 | ||
50 | |||
51 | [block] | ||
52 | plugins = dht test | ||
53 | |||
54 | [dhtcache] | ||
55 | QUOTA = 1 MB | ||
56 | DATABASE = sqlite | ||
57 | |||
58 | [transport] | ||
59 | PLUGINS = tcp | ||
60 | ACCEPT_FROM6 = ::1; | ||
61 | ACCEPT_FROM = 127.0.0.1; | ||
62 | NEIGHBOUR_LIMIT = 50 | ||
63 | PORT = 12365 | ||
64 | |||
65 | [ats] | ||
66 | WAN_QUOTA_OUT = 3932160 | ||
67 | WAN_QUOTA_IN = 3932160 | ||
68 | |||
69 | [transport-tcp] | ||
70 | TIMEOUT = 300 s | ||
71 | PORT = 12368 | ||
72 | |||
73 | [TESTING] | ||
74 | WEAKRANDOM = YES | ||
75 | |||
76 | [gnunetd] | ||
77 | HOSTKEY = $SERVICEHOME/.hostkey | ||
78 | |||
79 | [PATHS] | ||
80 | SERVICEHOME = /tmp/test-vectorproduct/ | ||
81 | |||
82 | [dns] | ||
83 | AUTOSTART = NO | ||
84 | |||
85 | [nse] | ||
86 | AUTOSTART = NO | ||
87 | |||
88 | [vpn] | ||
89 | AUTOSTART = NO | ||
90 | |||
91 | [nat] | ||
92 | RETURN_LOCAL_ADDRESSES = YES | ||
93 | |||
94 | [consensus] | ||
95 | AUTOSTART = NO | ||
96 | |||
diff --git a/src/scalarproduct/test_scalarproduct_api_regression.c b/src/scalarproduct/test_scalarproduct_api_regression.c deleted file mode 100644 index 391fa483a..000000000 --- a/src/scalarproduct/test_scalarproduct_api_regression.c +++ /dev/null | |||
@@ -1,851 +0,0 @@ | |||
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 scalarproduct/test_scalarproduct_api_regression.c | ||
23 | * @brief VectorProduct API regression test | ||
24 | * @author Gaurav Kukreja | ||
25 | * @author Christian Fuchs | ||
26 | */ | ||
27 | |||
28 | /** | ||
29 | * AIM of the regression test | ||
30 | * | ||
31 | * This test tries to check whether the service can handle abrupt client disconnect. | ||
32 | * | ||
33 | * 1. We create a responder peer, and ask the service to prepare_response. After this, | ||
34 | * we disconnect responder peer from service. | ||
35 | * | ||
36 | * 2. Then we create a requester peer, and ask service to request another peer. We | ||
37 | * should check that the service on responder peer is still active and receives | ||
38 | * request from the requester. We then disconnect requester peer from service. Both | ||
39 | * the requester and responder service should handle this cleanly. | ||
40 | */ | ||
41 | |||
42 | #include <string.h> | ||
43 | |||
44 | #include <inttypes.h> | ||
45 | #include "platform.h" | ||
46 | #include "gnunet_util_lib.h" | ||
47 | #include "gnunet_testbed_service.h" | ||
48 | #include "gnunet_common.h" | ||
49 | #include "gnunet_scalarproduct_service.h" | ||
50 | #include "gnunet_protocols.h" | ||
51 | |||
52 | #define LOG(kind,...) GNUNET_log_from (kind, "test-scalarproduct-api-regression",__VA_ARGS__) | ||
53 | #define NUM_PEERS 2 | ||
54 | |||
55 | /** | ||
56 | * Structure for holding peer's sockets and IO Handles | ||
57 | */ | ||
58 | struct PeerData | ||
59 | { | ||
60 | /** | ||
61 | * Handle to testbed peer | ||
62 | */ | ||
63 | struct GNUNET_TESTBED_Peer *peer; | ||
64 | |||
65 | /** | ||
66 | * The service connect operation to stream | ||
67 | */ | ||
68 | struct GNUNET_TESTBED_Operation *op; | ||
69 | |||
70 | /** | ||
71 | * Our Peer id | ||
72 | */ | ||
73 | struct GNUNET_PeerIdentity our_id; | ||
74 | |||
75 | /** | ||
76 | * Pointer to Vector Product Handle | ||
77 | */ | ||
78 | struct GNUNET_SCALARPRODUCT_Handle *vh; | ||
79 | }; | ||
80 | |||
81 | /** | ||
82 | * Different states in test setup | ||
83 | */ | ||
84 | enum SetupState | ||
85 | { | ||
86 | /** | ||
87 | * Get the identity of peer 1 | ||
88 | */ | ||
89 | PEER1_GET_IDENTITY, | ||
90 | |||
91 | /** | ||
92 | * Get the identity of peer 2 | ||
93 | */ | ||
94 | PEER2_GET_IDENTITY, | ||
95 | |||
96 | /** | ||
97 | * Connect to stream service of peer 1 | ||
98 | */ | ||
99 | PEER1_SCALARPRODUCT_CONNECT, | ||
100 | |||
101 | /** | ||
102 | * Connect to stream service of peer 2 | ||
103 | */ | ||
104 | PEER2_SCALARPRODUCT_CONNECT | ||
105 | |||
106 | }; | ||
107 | |||
108 | /****************************************************************************** | ||
109 | *** Global Variables ***************************** | ||
110 | ******************************************************************************/ | ||
111 | |||
112 | /** | ||
113 | * Maximum allowed message-ids we can check in one go (with one GNUNET_message) | ||
114 | */ | ||
115 | static unsigned int max_mids; | ||
116 | |||
117 | /** | ||
118 | * Session Key used by both the test peers | ||
119 | */ | ||
120 | char input_key[103] = "helloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhe"; | ||
121 | |||
122 | /** | ||
123 | * Input elements for peer1 | ||
124 | */ | ||
125 | //char input_elements_peer1[] = "11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11"; | ||
126 | char input_elements_peer1[] = "11,11,11"; | ||
127 | |||
128 | /** | ||
129 | * Input Mask for peer 1 | ||
130 | */ | ||
131 | //char input_mask_peer1[] = "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"; | ||
132 | char input_mask_peer1[] = "1,1,1"; | ||
133 | |||
134 | /** | ||
135 | * the array of converted message IDs to send to our service | ||
136 | */ | ||
137 | static int32_t * elements_peer1 = NULL; | ||
138 | |||
139 | /** | ||
140 | * Input elements for peer2 | ||
141 | */ | ||
142 | //char input_elements_peer2[] = "11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11"; | ||
143 | char input_elements_peer2[] = "11,11,11"; | ||
144 | /** | ||
145 | * Input Mask for peer 2 | ||
146 | */ | ||
147 | //char input_mask_peer2[] = "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"; | ||
148 | char input_mask_peer2[] = "1,1,1"; | ||
149 | /** | ||
150 | * the array of converted message IDs to send to our service | ||
151 | */ | ||
152 | static int32_t * elements_peer2 = NULL; | ||
153 | |||
154 | /** | ||
155 | * the array of converted message IDs to send to our service | ||
156 | */ | ||
157 | static unsigned char * mask_peer2 = NULL; | ||
158 | |||
159 | /** | ||
160 | * Data context for peer 1 | ||
161 | */ | ||
162 | static struct PeerData peer1; | ||
163 | |||
164 | /** | ||
165 | * Data context for peer 2 | ||
166 | */ | ||
167 | static struct PeerData peer2; | ||
168 | |||
169 | /** | ||
170 | * Various states during test setup | ||
171 | */ | ||
172 | static enum SetupState setup_state; | ||
173 | |||
174 | /** | ||
175 | * Testbed operation handle | ||
176 | */ | ||
177 | static struct GNUNET_TESTBED_Operation *op; | ||
178 | |||
179 | /** | ||
180 | * Return value of the test. | ||
181 | */ | ||
182 | static int ok; | ||
183 | |||
184 | /** | ||
185 | * Abort Task for timeout | ||
186 | */ | ||
187 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | ||
188 | /****************************************************************************** | ||
189 | *** Static Functions ***************************** | ||
190 | ******************************************************************************/ | ||
191 | |||
192 | /** | ||
193 | * Helper function to shutdown a test peer | ||
194 | * | ||
195 | * @param cls void* to struct PeerData of the peer to be disconnected | ||
196 | * @param tc Task Context | ||
197 | */ | ||
198 | static void | ||
199 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
200 | |||
201 | |||
202 | /** | ||
203 | * Helper function to connect a test peer | ||
204 | * | ||
205 | * @param cls void* to struct PeerData of the peer to be connected | ||
206 | * @param tc Task Context | ||
207 | */ | ||
208 | static void | ||
209 | connect_peer (void *cls, | ||
210 | const struct GNUNET_SCHEDULER_TaskContext * tc); | ||
211 | |||
212 | |||
213 | /** | ||
214 | * Close sockets and stop testing deamons nicely | ||
215 | */ | ||
216 | static void | ||
217 | do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
218 | { | ||
219 | |||
220 | if (peer1.op != NULL) | ||
221 | do_shutdown (&peer1, NULL); | ||
222 | |||
223 | if (peer2.op != NULL) | ||
224 | do_shutdown (&peer2, NULL); | ||
225 | |||
226 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
227 | GNUNET_SCHEDULER_cancel (abort_task); | ||
228 | |||
229 | GNUNET_SCHEDULER_shutdown (); /* For shutting down testbed */ | ||
230 | } | ||
231 | |||
232 | |||
233 | /** | ||
234 | * Helper function to shutdown a test peer | ||
235 | * | ||
236 | * @param cls void* to struct PeerData of the peer to be disconnected | ||
237 | * @param tc Task Context | ||
238 | */ | ||
239 | static void | ||
240 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
241 | { | ||
242 | static int shutdown; | ||
243 | shutdown++; | ||
244 | struct PeerData* peer = (struct PeerData*) cls; | ||
245 | |||
246 | if (peer == &peer1) | ||
247 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting Peer1\n\n"); | ||
248 | else if (peer == &peer2) | ||
249 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting Peer2\n\n"); | ||
250 | |||
251 | // peer->op contains handle to the TESTBED_connect_service operation | ||
252 | // calling operation done, leads to call to scalarproduct_da | ||
253 | if (peer->op != NULL) | ||
254 | { | ||
255 | GNUNET_TESTBED_operation_done (peer->op); | ||
256 | peer->op = NULL; | ||
257 | } | ||
258 | |||
259 | if (shutdown >= 2) | ||
260 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 10), &do_close, NULL); | ||
261 | } | ||
262 | |||
263 | |||
264 | /** | ||
265 | * Something went wrong and timed out. Kill everything and set error flag | ||
266 | */ | ||
267 | static void | ||
268 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
269 | { | ||
270 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: ABORT due to Timeout\n"); | ||
271 | ok = GNUNET_SYSERR; | ||
272 | abort_task = 0; | ||
273 | do_close (cls, tc); | ||
274 | } | ||
275 | |||
276 | |||
277 | /** | ||
278 | * Controller event callback | ||
279 | * | ||
280 | * @param cls NULL | ||
281 | * @param event the controller event | ||
282 | */ | ||
283 | static void | ||
284 | controller_event_cb (void *cls, | ||
285 | const struct GNUNET_TESTBED_EventInformation *event) | ||
286 | { | ||
287 | switch (event->type) | ||
288 | { | ||
289 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
290 | switch (setup_state) | ||
291 | { | ||
292 | case PEER1_SCALARPRODUCT_CONNECT: | ||
293 | case PEER2_SCALARPRODUCT_CONNECT: | ||
294 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | ||
295 | break; | ||
296 | default: | ||
297 | GNUNET_assert (0); | ||
298 | } | ||
299 | break; | ||
300 | default: | ||
301 | GNUNET_assert (0); | ||
302 | } | ||
303 | } | ||
304 | |||
305 | |||
306 | /** | ||
307 | * Callback function called for the responder peer i.e. peer1 | ||
308 | * | ||
309 | * @param cls | ||
310 | * @param key Session key | ||
311 | * @param status Status of the message | ||
312 | */ | ||
313 | static void | ||
314 | responder_callback (void *cls, | ||
315 | const struct GNUNET_HashCode * key, | ||
316 | enum GNUNET_SCALARPRODUCT_ResponseStatus status) | ||
317 | { | ||
318 | if (status == GNUNET_SCALARPRODUCT_Status_Failure) | ||
319 | { | ||
320 | LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received status failure\n"); | ||
321 | ok = -1; | ||
322 | } | ||
323 | else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse) | ||
324 | { | ||
325 | LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received status invalid response\n"); | ||
326 | ok = -1; | ||
327 | } | ||
328 | else if (GNUNET_SCALARPRODUCT_Status_Timeout == status) | ||
329 | { | ||
330 | LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received timeout occured\n"); | ||
331 | ok = -1; | ||
332 | } | ||
333 | else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status) | ||
334 | { | ||
335 | LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received service disconnected!!\n"); | ||
336 | ok = 1; | ||
337 | } | ||
338 | else if (GNUNET_SCALARPRODUCT_Status_Success == status) | ||
339 | { | ||
340 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Responder Client expected response received!\n"); | ||
341 | ok = -1; | ||
342 | } | ||
343 | else | ||
344 | { | ||
345 | LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client status = %d!\n", (int) status); | ||
346 | ok = -1; | ||
347 | } | ||
348 | |||
349 | // Not shutting down this time, only for this regression test. We have shutdown explicitly earlier. | ||
350 | // Shutting down again is causing problems. | ||
351 | |||
352 | // if(peer1.vh != NULL) | ||
353 | // { | ||
354 | // GNUNET_SCHEDULER_add_now(&do_shutdown, &peer1); | ||
355 | // } | ||
356 | return; | ||
357 | } | ||
358 | |||
359 | |||
360 | /** | ||
361 | * Callback function called for the requester peer i.e. peer2 | ||
362 | * | ||
363 | * @param cls | ||
364 | * @param key Session key | ||
365 | * @param status Status of the message | ||
366 | */ | ||
367 | static void | ||
368 | requester_callback (void *cls, | ||
369 | const struct GNUNET_HashCode * key, | ||
370 | const struct GNUNET_PeerIdentity * peer, | ||
371 | enum GNUNET_SCALARPRODUCT_ResponseStatus status, | ||
372 | const struct GNUNET_SCALARPRODUCT_client_response *msg) | ||
373 | { | ||
374 | uint32_t product_len; | ||
375 | |||
376 | if (status == GNUNET_SCALARPRODUCT_Status_Failure) | ||
377 | { | ||
378 | LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client received status failure\n"); | ||
379 | ok = -1; | ||
380 | } | ||
381 | else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse) | ||
382 | { | ||
383 | LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client received status invalid response\n"); | ||
384 | ok = -1; | ||
385 | } | ||
386 | else if (GNUNET_SCALARPRODUCT_Status_Timeout == status) | ||
387 | { | ||
388 | LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client timeout occured\n"); | ||
389 | ok = -1; | ||
390 | } | ||
391 | else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status) | ||
392 | { | ||
393 | LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client service disconnected!!\n"); | ||
394 | ok = 1; | ||
395 | } | ||
396 | else if (GNUNET_SCALARPRODUCT_Status_Success != status) | ||
397 | { | ||
398 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requester Client Status = %d\n", (int) status); | ||
399 | ok = -1; | ||
400 | } | ||
401 | else if (GNUNET_SCALARPRODUCT_Status_Success == status) | ||
402 | { | ||
403 | product_len = ntohl (msg->product_length); | ||
404 | |||
405 | if (0 < product_len) | ||
406 | { | ||
407 | gcry_mpi_t result; | ||
408 | gcry_error_t ret = 0; | ||
409 | size_t read = 0; | ||
410 | |||
411 | ret = gcry_mpi_scan (&result, GCRYMPI_FMT_USG, (void *) &msg[1], product_len, &read); | ||
412 | |||
413 | if (0 != ret) | ||
414 | { | ||
415 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not convert to mpi to value!\n"); | ||
416 | } | ||
417 | else | ||
418 | { | ||
419 | gcry_mpi_dump (result); | ||
420 | gcry_mpi_release (result); | ||
421 | } | ||
422 | ok = -1; | ||
423 | } | ||
424 | else | ||
425 | { //currently not used, but if we get more info due to MESH we will need this | ||
426 | LOG (GNUNET_ERROR_TYPE_WARNING, "Error during computation of vector product, return code: %d\n", product_len); | ||
427 | ok = -1; | ||
428 | } | ||
429 | } | ||
430 | |||
431 | // Not shutting down this time, only for this regression test. We have shutdown explicitly earlier. | ||
432 | // Shutting down again is causing problems. | ||
433 | |||
434 | // if(peer2.vh != NULL) | ||
435 | // { | ||
436 | // GNUNET_SCHEDULER_add_now(&do_shutdown, &peer2); | ||
437 | // } | ||
438 | return; | ||
439 | } | ||
440 | |||
441 | |||
442 | static void | ||
443 | requester_request (void *cls, | ||
444 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
445 | { | ||
446 | GNUNET_assert (peer2.vh != NULL); | ||
447 | |||
448 | unsigned int i; | ||
449 | uint16_t element_count = 0; | ||
450 | uint16_t mask_length = 0; | ||
451 | char * begin = input_elements_peer2; | ||
452 | char * end; | ||
453 | int32_t element; | ||
454 | struct GNUNET_SCALARPRODUCT_QueueEntry *qe; | ||
455 | struct GNUNET_HashCode key; | ||
456 | int exit_loop = 0; | ||
457 | |||
458 | GNUNET_CRYPTO_hash (input_key, strlen (input_key), &key); | ||
459 | |||
460 | /* Read input_elements_peer2, and put in elements_peer2 array */ | ||
461 | exit_loop = 0; | ||
462 | do | ||
463 | { | ||
464 | unsigned int mcount = element_count; | ||
465 | //ignore empty rows of ,,,,,, | ||
466 | while (*begin == ',') | ||
467 | begin++; | ||
468 | // get the length of the current element and replace , with null | ||
469 | for (end = begin; *end && *end != ','; end++); | ||
470 | |||
471 | if (*end == '\0') | ||
472 | exit_loop = 1; | ||
473 | |||
474 | if (1 != sscanf (begin, "%" SCNd32, &element)) | ||
475 | { | ||
476 | FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin); | ||
477 | ok = -1; | ||
478 | return; | ||
479 | } | ||
480 | |||
481 | GNUNET_array_append (elements_peer2, mcount, element); | ||
482 | element_count++; | ||
483 | |||
484 | begin = ++end; | ||
485 | } | ||
486 | while (!exit_loop && element_count < max_mids); | ||
487 | GNUNET_assert (elements_peer2 != NULL); | ||
488 | GNUNET_assert (element_count >= 1); | ||
489 | |||
490 | /* Read input_mask_peer2 and read in mask_peer2 array */ | ||
491 | mask_length = element_count / 8 + (element_count % 8 ? 1 : 0); | ||
492 | mask_peer2 = GNUNET_malloc ((element_count / 8) + 2); | ||
493 | GNUNET_assert (NULL != mask_peer2); | ||
494 | if (NULL != input_mask_peer2) | ||
495 | { | ||
496 | begin = input_mask_peer2; | ||
497 | unsigned short mask_count = 0; | ||
498 | exit_loop = 0; | ||
499 | |||
500 | do | ||
501 | { | ||
502 | //ignore empty rows of ,,,,,, | ||
503 | while (* begin == ',') | ||
504 | begin++; | ||
505 | // get the length of the current element and replace , with null | ||
506 | // gnunet_ascii-armor uses base32, thus we can use , as separator! | ||
507 | for (end = begin; *end && *end != ','; end++); | ||
508 | |||
509 | if (*end == '\0') | ||
510 | exit_loop = 1; | ||
511 | |||
512 | if (1 != sscanf (begin, "%" SCNd32, &element)) | ||
513 | { | ||
514 | FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin); | ||
515 | ok = -1; | ||
516 | return; | ||
517 | } | ||
518 | |||
519 | GNUNET_assert (mask_count <= element_count); | ||
520 | |||
521 | if (element) | ||
522 | mask_peer2[mask_count / 8] = mask_peer2[mask_count / 8] | 1 << (mask_count % 8); | ||
523 | |||
524 | mask_count++; | ||
525 | begin = ++end; | ||
526 | } | ||
527 | while (!exit_loop); | ||
528 | // +1 to see if we would have more data, which would indicate malformed/superficial input | ||
529 | GNUNET_assert (mask_count == element_count); | ||
530 | } | ||
531 | else | ||
532 | { | ||
533 | for (i = 0; i <= mask_length; i++) | ||
534 | mask_peer2[i] = UCHAR_MAX; // all 1's | ||
535 | } | ||
536 | |||
537 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Responder peer key %s\n", &peer1.our_id); | ||
538 | |||
539 | qe = GNUNET_SCALARPRODUCT_request (peer2.vh, | ||
540 | &key, | ||
541 | &peer1.our_id, | ||
542 | element_count, | ||
543 | mask_length, | ||
544 | elements_peer2, mask_peer2, | ||
545 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | ||
546 | &requester_callback, | ||
547 | NULL); | ||
548 | |||
549 | if (qe == NULL) | ||
550 | { | ||
551 | FPRINTF (stderr, "%s", _ ("Could not send request to scalarproduct service! Exitting!")); | ||
552 | ok = -1; | ||
553 | return; | ||
554 | } | ||
555 | |||
556 | /** | ||
557 | * For regression, we shutdown the initiator peer, peer2, one second after | ||
558 | * issuing a request. Hopefully, peer1 notices that the tunnel has been | ||
559 | * been destroyed, and will shutdown cleanly. | ||
560 | */ | ||
561 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, &peer2); | ||
562 | |||
563 | return; | ||
564 | } | ||
565 | |||
566 | |||
567 | /** | ||
568 | * Function prepares the message to be sent by peer1 to its scalarproduct service | ||
569 | * to prepare response, and wait for a request session to be initiated by peer1 | ||
570 | */ | ||
571 | static void | ||
572 | responder_prepare_response (void *cls, | ||
573 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
574 | { | ||
575 | GNUNET_assert (peer1.vh != NULL); | ||
576 | |||
577 | uint16_t element_count = 0; | ||
578 | char * begin = input_elements_peer1; | ||
579 | char * end; | ||
580 | int32_t element; | ||
581 | |||
582 | struct GNUNET_SCALARPRODUCT_QueueEntry *qe; | ||
583 | |||
584 | struct GNUNET_HashCode key; | ||
585 | GNUNET_CRYPTO_hash (input_key, strlen (input_key), &key); | ||
586 | |||
587 | int exit_loop = 0; | ||
588 | /* Read input_elements_peer1, and put in elements_peer1 array */ | ||
589 | do | ||
590 | { | ||
591 | unsigned int mcount = element_count; | ||
592 | //ignore empty rows of ,,,,,, | ||
593 | while (*begin == ',') | ||
594 | begin++; | ||
595 | // get the length of the current element and replace , with null | ||
596 | for (end = begin; *end && *end != ','; end++); | ||
597 | |||
598 | if (*end == '\0') | ||
599 | exit_loop = 1; | ||
600 | |||
601 | if (1 != sscanf (begin, "%" SCNd32, &element)) | ||
602 | { | ||
603 | FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin); | ||
604 | ok = -1; | ||
605 | return; | ||
606 | } | ||
607 | |||
608 | GNUNET_array_append (elements_peer1, mcount, element); | ||
609 | element_count++; | ||
610 | |||
611 | begin = ++end; | ||
612 | } | ||
613 | while (!exit_loop && element_count < max_mids); | ||
614 | |||
615 | GNUNET_assert (elements_peer1 != NULL); | ||
616 | GNUNET_assert (element_count >= 1); | ||
617 | |||
618 | qe = GNUNET_SCALARPRODUCT_prepare_response (peer1.vh, | ||
619 | &key, | ||
620 | element_count, | ||
621 | elements_peer1, | ||
622 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | ||
623 | &responder_callback, | ||
624 | NULL); | ||
625 | |||
626 | if (qe == NULL) | ||
627 | { | ||
628 | FPRINTF (stderr, "%s", _ ("Could not send request to scalarproduct service! Exitting!")); | ||
629 | ok = -1; | ||
630 | return; | ||
631 | } | ||
632 | |||
633 | // connect the second peer | ||
634 | setup_state = PEER2_SCALARPRODUCT_CONNECT; | ||
635 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &connect_peer, &peer2); | ||
636 | |||
637 | // while the service is waiting for a matching request, disconnect the test client | ||
638 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, &peer1); | ||
639 | |||
640 | return; | ||
641 | } | ||
642 | |||
643 | |||
644 | /** | ||
645 | * Adapter function called to destroy a connection to | ||
646 | * a service. This function is called when GNUNET_TESTBED_operation_done is | ||
647 | * called for peer->op, which holds the handle for GNUNET_TESTBED_service_connect | ||
648 | * operation. | ||
649 | * | ||
650 | * @param cls closure | ||
651 | * @param op_result service handle returned from the connect adapter | ||
652 | */ | ||
653 | static void | ||
654 | scalarproduct_da (void *cls, void *op_result) | ||
655 | { | ||
656 | struct PeerData* peer = (struct PeerData*) cls; | ||
657 | |||
658 | GNUNET_SCALARPRODUCT_cancel (peer->vh); | ||
659 | peer->vh = NULL; | ||
660 | return; | ||
661 | } | ||
662 | |||
663 | |||
664 | /** | ||
665 | * Adapter function called to establish a connection to | ||
666 | * a service. This function is called to by GNUNET_TESTBED_service_connect. | ||
667 | * | ||
668 | * @param cls closure | ||
669 | * @param cfg configuration of the peer to connect to; will be available until | ||
670 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
671 | * from GNUNET_TESTBED_service_connect() | ||
672 | * @return service handle to return in 'op_result', NULL on error | ||
673 | */ | ||
674 | static void * | ||
675 | scalarproduct_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
676 | { | ||
677 | struct PeerData *p = cls; | ||
678 | |||
679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", (&peer1 == p) ? 1 : 2, | ||
680 | GNUNET_i2s (&p->our_id)); | ||
681 | |||
682 | switch (setup_state) | ||
683 | { | ||
684 | case PEER1_SCALARPRODUCT_CONNECT: | ||
685 | peer1.vh = GNUNET_SCALARPRODUCT_connect (cfg); | ||
686 | |||
687 | if (peer1.vh != NULL) | ||
688 | { | ||
689 | /* prepare_response from peer1 */ | ||
690 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, &responder_prepare_response, NULL); | ||
691 | } | ||
692 | else | ||
693 | { | ||
694 | ok = -1; | ||
695 | return NULL; | ||
696 | } | ||
697 | |||
698 | return peer1.vh; | ||
699 | |||
700 | case PEER2_SCALARPRODUCT_CONNECT: | ||
701 | /* Actually connect peer 2 to scalarproduct service */ | ||
702 | peer2.vh = GNUNET_SCALARPRODUCT_connect (cfg); | ||
703 | |||
704 | if (peer2.vh != NULL) | ||
705 | { | ||
706 | /* initiate request from peer2 */ | ||
707 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, &requester_request, NULL); | ||
708 | } | ||
709 | else | ||
710 | { | ||
711 | ok = -1; | ||
712 | return NULL; | ||
713 | } | ||
714 | |||
715 | return peer2.vh; | ||
716 | default: | ||
717 | GNUNET_assert (0); | ||
718 | } | ||
719 | } | ||
720 | |||
721 | |||
722 | /** | ||
723 | * Helper function to connect a test peer | ||
724 | * | ||
725 | * @param cls void* to struct PeerData of the peer to be connected | ||
726 | * @param tc Task Context | ||
727 | */ | ||
728 | static void | ||
729 | connect_peer (void *cls, | ||
730 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
731 | { | ||
732 | struct PeerData *peer = cls; | ||
733 | |||
734 | peer->op = GNUNET_TESTBED_service_connect (peer, peer->peer, "scalarproduct", | ||
735 | NULL, NULL, scalarproduct_ca, | ||
736 | scalarproduct_da, peer); | ||
737 | |||
738 | } | ||
739 | |||
740 | |||
741 | /** | ||
742 | * Callback to be called when the requested peer information is available | ||
743 | * | ||
744 | * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information() | ||
745 | * @param op the operation this callback corresponds to | ||
746 | * @param pinfo the result; will be NULL if the operation has failed | ||
747 | * @param emsg error message if the operation has failed; will be NULL if the | ||
748 | * operation is successfull | ||
749 | */ | ||
750 | static void | ||
751 | peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_, | ||
752 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
753 | const char *emsg) | ||
754 | { | ||
755 | GNUNET_assert (NULL == emsg); | ||
756 | GNUNET_assert (op == op_); | ||
757 | |||
758 | switch (setup_state) | ||
759 | { | ||
760 | case PEER1_GET_IDENTITY: | ||
761 | { | ||
762 | memcpy (&peer1.our_id, pinfo->result.id, | ||
763 | sizeof (struct GNUNET_PeerIdentity)); | ||
764 | GNUNET_TESTBED_operation_done (op); | ||
765 | |||
766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 id: %s\n", GNUNET_i2s_full | ||
767 | (&peer1.our_id)); | ||
768 | |||
769 | /* Request for peer id of peer 2*/ | ||
770 | setup_state = PEER2_GET_IDENTITY; | ||
771 | op = GNUNET_TESTBED_peer_get_information (peer2.peer, | ||
772 | GNUNET_TESTBED_PIT_IDENTITY, | ||
773 | &peerinfo_cb, NULL); | ||
774 | } | ||
775 | break; | ||
776 | case PEER2_GET_IDENTITY: | ||
777 | { | ||
778 | memcpy (&peer2.our_id, pinfo->result.id, | ||
779 | sizeof (struct GNUNET_PeerIdentity)); | ||
780 | GNUNET_TESTBED_operation_done (op); | ||
781 | |||
782 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n", GNUNET_i2s_full | ||
783 | (&peer2.our_id)); | ||
784 | |||
785 | /* Connect peer 1 to scalarproduct service */ | ||
786 | setup_state = PEER1_SCALARPRODUCT_CONNECT; | ||
787 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, &connect_peer, &peer1); | ||
788 | } | ||
789 | break; | ||
790 | default: | ||
791 | GNUNET_assert (0); | ||
792 | } | ||
793 | } | ||
794 | |||
795 | |||
796 | /** | ||
797 | * Signature of a main function for a testcase. | ||
798 | * | ||
799 | * @param cls closure | ||
800 | * @param num_peers number of peers in 'peers' | ||
801 | * @param peers handle to peers run in the testbed | ||
802 | */ | ||
803 | static void | ||
804 | test_master (void *cls, unsigned int num_peers, | ||
805 | struct GNUNET_TESTBED_Peer **peers) | ||
806 | { | ||
807 | GNUNET_assert (NULL != peers); | ||
808 | GNUNET_assert (NULL != peers[0]); | ||
809 | GNUNET_assert (NULL != peers[1]); | ||
810 | peer1.peer = peers[0]; | ||
811 | peer2.peer = peers[1]; | ||
812 | |||
813 | /* Get the peer identity and configuration of peer 1 */ | ||
814 | setup_state = PEER1_GET_IDENTITY; | ||
815 | op = GNUNET_TESTBED_peer_get_information (peer1.peer, | ||
816 | GNUNET_TESTBED_PIT_IDENTITY, | ||
817 | &peerinfo_cb, NULL); | ||
818 | |||
819 | abort_task = | ||
820 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
821 | (GNUNET_TIME_UNIT_SECONDS, 20), &do_abort, | ||
822 | NULL); | ||
823 | } | ||
824 | |||
825 | |||
826 | /** | ||
827 | * Main function | ||
828 | */ | ||
829 | int | ||
830 | main (int argc, char **argv) | ||
831 | { | ||
832 | uint64_t event_mask; | ||
833 | |||
834 | ok = GNUNET_NO; | ||
835 | event_mask = 0; | ||
836 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
837 | max_mids = (GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_MessageHeader)) | ||
838 | / sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1; | ||
839 | |||
840 | (void) GNUNET_TESTBED_test_run ("test_scalarproduct_api_regression", | ||
841 | "test_scalarproduct_api_data.conf", | ||
842 | NUM_PEERS, event_mask, &controller_event_cb, | ||
843 | NULL, | ||
844 | &test_master, NULL); | ||
845 | |||
846 | if (GNUNET_SYSERR == ok) | ||
847 | return 1; | ||
848 | return 0; | ||
849 | } | ||
850 | |||
851 | |||
diff --git a/src/scalarproduct/test_scalarproduct_api_regression2.c b/src/scalarproduct/test_scalarproduct_api_regression2.c deleted file mode 100644 index 24d7e9057..000000000 --- a/src/scalarproduct/test_scalarproduct_api_regression2.c +++ /dev/null | |||
@@ -1,931 +0,0 @@ | |||
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 scalarproduct/test_scalarproduct_api_regression2.c | ||
23 | * @brief Regression test, destroys requester service before receiving response | ||
24 | * responder service | ||
25 | * @author Gaurav Kukreja | ||
26 | * @author Christian Fuchs | ||
27 | */ | ||
28 | |||
29 | #include <string.h> | ||
30 | |||
31 | #include <inttypes.h> | ||
32 | #include "platform.h" | ||
33 | #include "gnunet_util_lib.h" | ||
34 | #include "gnunet_testbed_service.h" | ||
35 | #include "gnunet_common.h" | ||
36 | #include "gnunet_scalarproduct_service.h" | ||
37 | #include "gnunet_protocols.h" | ||
38 | |||
39 | #define LOG(kind,...) GNUNET_log_from (kind, "test-scalarproduct-api-regression2",__VA_ARGS__) | ||
40 | #define NUM_PEERS 2 | ||
41 | |||
42 | /** | ||
43 | * Structure for holding peer's sockets and IO Handles | ||
44 | */ | ||
45 | struct PeerData | ||
46 | { | ||
47 | /** | ||
48 | * Handle to testbed peer | ||
49 | */ | ||
50 | struct GNUNET_TESTBED_Peer *peer; | ||
51 | |||
52 | /** | ||
53 | * The service connect operation to stream | ||
54 | */ | ||
55 | struct GNUNET_TESTBED_Operation *op; | ||
56 | |||
57 | /** | ||
58 | * Our Peer id | ||
59 | */ | ||
60 | struct GNUNET_PeerIdentity our_id; | ||
61 | |||
62 | /** | ||
63 | * Pointer to Vector Product Handle | ||
64 | */ | ||
65 | struct GNUNET_SCALARPRODUCT_Handle *vh; | ||
66 | }; | ||
67 | |||
68 | /** | ||
69 | * Different states in test setup | ||
70 | */ | ||
71 | enum SetupState | ||
72 | { | ||
73 | /** | ||
74 | * Get the identity of peer 1 | ||
75 | */ | ||
76 | PEER1_GET_IDENTITY, | ||
77 | |||
78 | /** | ||
79 | * Get the identity of peer 2 | ||
80 | */ | ||
81 | PEER2_GET_IDENTITY, | ||
82 | |||
83 | /** | ||
84 | * Connect to stream service of peer 1 | ||
85 | */ | ||
86 | PEER1_SCALARPRODUCT_CONNECT, | ||
87 | |||
88 | /** | ||
89 | * Connect to stream service of peer 2 | ||
90 | */ | ||
91 | PEER2_SCALARPRODUCT_CONNECT | ||
92 | |||
93 | }; | ||
94 | |||
95 | /****************************************************************************** | ||
96 | *** Global Variables ***************************** | ||
97 | ******************************************************************************/ | ||
98 | |||
99 | /** | ||
100 | * Maximum allowed message-ids we can check in one go (with one GNUNET_message) | ||
101 | */ | ||
102 | static unsigned int max_mids; | ||
103 | |||
104 | /** | ||
105 | * Session Key used by both the test peers | ||
106 | */ | ||
107 | char input_key[103] = "helloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhe"; | ||
108 | |||
109 | /** | ||
110 | * Input elements for peer1 | ||
111 | */ | ||
112 | char input_elements_peer1[] = "11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11"; | ||
113 | //char input_elements_peer1[] = "11,11,11"; | ||
114 | |||
115 | /** | ||
116 | * Input Mask for peer 1 | ||
117 | */ | ||
118 | char input_mask_peer1[] = "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"; | ||
119 | //char input_mask_peer1[] = "1,1,1"; | ||
120 | |||
121 | /** | ||
122 | * the array of converted message IDs to send to our service | ||
123 | */ | ||
124 | static int32_t * elements_peer1 = NULL; | ||
125 | |||
126 | /** | ||
127 | * the array of converted message IDs to send to our service | ||
128 | */ | ||
129 | static unsigned char * mask_peer1 = NULL; | ||
130 | |||
131 | /** | ||
132 | * Number of elements | ||
133 | */ | ||
134 | uint16_t element_count_peer1 = 0; | ||
135 | |||
136 | /** | ||
137 | * Input elements for peer2 | ||
138 | */ | ||
139 | char input_elements_peer2[] = "11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11"; | ||
140 | //char input_elements_peer2[] = "11,11,11"; | ||
141 | |||
142 | /** | ||
143 | * Input Mask for peer 2 | ||
144 | */ | ||
145 | char input_mask_peer2[] = "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"; | ||
146 | //char input_mask_peer2[] = "1,1,1"; | ||
147 | |||
148 | /** | ||
149 | * the array of converted message IDs to send to our service | ||
150 | */ | ||
151 | static int32_t * elements_peer2 = NULL; | ||
152 | |||
153 | /** | ||
154 | * the array of converted message IDs to send to our service | ||
155 | */ | ||
156 | static unsigned char * mask_peer2 = NULL; | ||
157 | |||
158 | /** | ||
159 | * Number of elements | ||
160 | */ | ||
161 | uint16_t element_count_peer2 = 0; | ||
162 | |||
163 | /** | ||
164 | * Data context for peer 1 | ||
165 | */ | ||
166 | static struct PeerData peer1; | ||
167 | |||
168 | /** | ||
169 | * Data context for peer 2 | ||
170 | */ | ||
171 | static struct PeerData peer2; | ||
172 | |||
173 | /** | ||
174 | * Various states during test setup | ||
175 | */ | ||
176 | static enum SetupState setup_state; | ||
177 | |||
178 | /** | ||
179 | * Testbed operation handle | ||
180 | */ | ||
181 | static struct GNUNET_TESTBED_Operation *op; | ||
182 | |||
183 | static int ok; | ||
184 | |||
185 | static int responder_ok; | ||
186 | |||
187 | static int requester_ok; | ||
188 | |||
189 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | ||
190 | /****************************************************************************** | ||
191 | *** Static Functions ***************************** | ||
192 | ******************************************************************************/ | ||
193 | |||
194 | static void | ||
195 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
196 | |||
197 | |||
198 | /** | ||
199 | * Close sockets and stop testing deamons nicely | ||
200 | */ | ||
201 | static void | ||
202 | do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
203 | { | ||
204 | static int closed; | ||
205 | |||
206 | if (peer1.op != NULL) | ||
207 | { | ||
208 | do_shutdown (&peer1, NULL); | ||
209 | } | ||
210 | |||
211 | if (peer2.op != NULL) | ||
212 | { | ||
213 | do_shutdown (&peer2, NULL); | ||
214 | } | ||
215 | |||
216 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
217 | { | ||
218 | GNUNET_SCHEDULER_cancel (abort_task); | ||
219 | abort_task = GNUNET_SCHEDULER_NO_TASK; | ||
220 | GNUNET_SCHEDULER_shutdown (); /* For shutting down testbed */ | ||
221 | } | ||
222 | |||
223 | if (!closed) | ||
224 | { | ||
225 | closed++; | ||
226 | GNUNET_SCHEDULER_shutdown (); /* For shutting down testbed */ | ||
227 | } | ||
228 | } | ||
229 | |||
230 | /** | ||
231 | * Shutdown a peer | ||
232 | * | ||
233 | * @param cls closure is a pointer to the struct PeerData of the peer to be disconnected | ||
234 | * @param tc Task Context | ||
235 | */ | ||
236 | static void | ||
237 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
238 | { | ||
239 | static int shutdown; | ||
240 | shutdown++; | ||
241 | struct PeerData* peer = (struct PeerData*) cls; | ||
242 | |||
243 | // peer->op contains handle to the TESTBED_connect_service operation | ||
244 | // calling operation done, leads to call to scalarproduct_da | ||
245 | if (peer->op != NULL) | ||
246 | { | ||
247 | if (peer == &peer1) | ||
248 | LOG (GNUNET_ERROR_TYPE_INFO, "Disconnecting Peer1\n\n"); | ||
249 | else if (peer == &peer2) | ||
250 | LOG (GNUNET_ERROR_TYPE_INFO, "Disconnecting Peer2\n\n"); | ||
251 | |||
252 | GNUNET_TESTBED_operation_done (peer->op); | ||
253 | peer->op = NULL; | ||
254 | } | ||
255 | |||
256 | if (peer1.op == NULL && peer2.op == NULL) | ||
257 | GNUNET_SCHEDULER_add_now (&do_close, NULL); | ||
258 | } | ||
259 | |||
260 | |||
261 | /** | ||
262 | * Something went wrong and timed out. Kill everything and set error flag | ||
263 | */ | ||
264 | static void | ||
265 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
266 | { | ||
267 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: ABORT due to Timeout\n"); | ||
268 | ok = GNUNET_SYSERR; | ||
269 | abort_task = GNUNET_SCHEDULER_NO_TASK; | ||
270 | GNUNET_SCHEDULER_add_now (&do_shutdown, &peer1); | ||
271 | GNUNET_SCHEDULER_add_now (&do_shutdown, &peer2); | ||
272 | } | ||
273 | |||
274 | |||
275 | /** | ||
276 | * Controller event callback | ||
277 | * | ||
278 | * @param cls NULL | ||
279 | * @param event the controller event | ||
280 | */ | ||
281 | static void | ||
282 | controller_event_cb (void *cls, | ||
283 | const struct GNUNET_TESTBED_EventInformation *event) | ||
284 | { | ||
285 | switch (event->type) | ||
286 | { | ||
287 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
288 | switch (setup_state) | ||
289 | { | ||
290 | case PEER1_SCALARPRODUCT_CONNECT: | ||
291 | case PEER2_SCALARPRODUCT_CONNECT: | ||
292 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | ||
293 | break; | ||
294 | default: | ||
295 | GNUNET_assert (0); | ||
296 | } | ||
297 | break; | ||
298 | default: | ||
299 | GNUNET_assert (0); | ||
300 | } | ||
301 | } | ||
302 | |||
303 | |||
304 | static void | ||
305 | responder_callback (void *cls, | ||
306 | const struct GNUNET_HashCode * key, | ||
307 | enum GNUNET_SCALARPRODUCT_ResponseStatus status) | ||
308 | { | ||
309 | if (status == GNUNET_SCALARPRODUCT_Status_Failure) | ||
310 | { | ||
311 | LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received status failure\n"); | ||
312 | responder_ok = -1; | ||
313 | } | ||
314 | else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse) | ||
315 | { | ||
316 | LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received status invalid response\n"); | ||
317 | responder_ok = -1; | ||
318 | } | ||
319 | else if (GNUNET_SCALARPRODUCT_Status_Timeout == status) | ||
320 | { | ||
321 | LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received timeout occured\n"); | ||
322 | // In this regression test, requester is supposed to fail due to timeout | ||
323 | // therefore responder_ok is set to 1, to make regression test pass | ||
324 | responder_ok = 1; | ||
325 | } | ||
326 | else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status) | ||
327 | { | ||
328 | LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received service disconnected!!\n"); | ||
329 | responder_ok = -1; | ||
330 | } | ||
331 | else if (GNUNET_SCALARPRODUCT_Status_Success == status) | ||
332 | { | ||
333 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Responder Client expected response received!\n"); | ||
334 | responder_ok = 1; | ||
335 | } | ||
336 | else | ||
337 | { | ||
338 | LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client status = %d!\n", (int) status); | ||
339 | responder_ok = -1; | ||
340 | } | ||
341 | // TODO : Responder Session Complete. Shutdown Test Cleanly!!! | ||
342 | //do_shutdown(&peer1, NULL); | ||
343 | GNUNET_SCHEDULER_add_now (&do_shutdown, &peer1); | ||
344 | return; | ||
345 | } | ||
346 | |||
347 | |||
348 | static void | ||
349 | requester_callback (void *cls, | ||
350 | const struct GNUNET_HashCode * key, | ||
351 | const struct GNUNET_PeerIdentity * peer, | ||
352 | enum GNUNET_SCALARPRODUCT_ResponseStatus status, | ||
353 | uint16_t size, struct GNUNET_SCALARPRODUCT_client_response *msg, | ||
354 | uint16_t type) | ||
355 | { | ||
356 | uint32_t product_len; | ||
357 | |||
358 | if (status == GNUNET_SCALARPRODUCT_Status_Failure) | ||
359 | { | ||
360 | LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client received status failure\n"); | ||
361 | // In this regression test, requester is supposed to receive status failure | ||
362 | // therefore requester_ok is set to 1, to make regression test pass | ||
363 | requester_ok = 1; | ||
364 | } | ||
365 | else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse) | ||
366 | { | ||
367 | LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client received status invalid response\n"); | ||
368 | requester_ok = -1; | ||
369 | } | ||
370 | else if (GNUNET_SCALARPRODUCT_Status_Timeout == status) | ||
371 | { | ||
372 | LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client timeout occured\n"); | ||
373 | requester_ok = -1; | ||
374 | } | ||
375 | else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status) | ||
376 | { | ||
377 | LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client service disconnected!!\n"); | ||
378 | requester_ok = -1; | ||
379 | } | ||
380 | else if (GNUNET_SCALARPRODUCT_Status_Success != status) | ||
381 | { | ||
382 | LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client Status = %d\n", (int) status); | ||
383 | requester_ok = -1; | ||
384 | } | ||
385 | else if (GNUNET_SCALARPRODUCT_Status_Success == status) | ||
386 | { | ||
387 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requester Client expected response received!\n"); | ||
388 | |||
389 | product_len = ntohl (msg->product_length); | ||
390 | |||
391 | if (0 < product_len) | ||
392 | { | ||
393 | gcry_mpi_t result; | ||
394 | gcry_error_t ret = 0; | ||
395 | size_t read = 0; | ||
396 | |||
397 | ret = gcry_mpi_scan (&result, GCRYMPI_FMT_USG, (void *) &msg[1], product_len, &read); | ||
398 | |||
399 | if (0 != ret) | ||
400 | { | ||
401 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not convert to mpi to value!\n"); | ||
402 | ok = -1; | ||
403 | } | ||
404 | else | ||
405 | { | ||
406 | uint16_t i = 0; | ||
407 | |||
408 | // calculate expected product | ||
409 | gcry_mpi_t expected_result; | ||
410 | gcry_mpi_t v1; | ||
411 | gcry_mpi_t v2; | ||
412 | gcry_mpi_t v1_v2_prod; | ||
413 | |||
414 | expected_result = gcry_mpi_new (0); | ||
415 | |||
416 | for (i = 0; i < element_count_peer1; i++) | ||
417 | { | ||
418 | uint32_t value; | ||
419 | v1_v2_prod = gcry_mpi_new (0); | ||
420 | |||
421 | // long to gcry_mpi_t | ||
422 | value = elements_peer1[i] >= 0 ? elements_peer1[i] : -elements_peer1[i]; | ||
423 | if (elements_peer1[i] < 0) | ||
424 | { | ||
425 | v1 = gcry_mpi_new (0); | ||
426 | gcry_mpi_sub_ui (v1, v1, value); | ||
427 | } | ||
428 | else | ||
429 | v1 = gcry_mpi_set_ui (NULL, value); | ||
430 | |||
431 | // long to gcry_mpi_t | ||
432 | value = elements_peer2[i] >= 0 ? elements_peer2[i] : -elements_peer2[i]; | ||
433 | if (elements_peer2[i] < 0) | ||
434 | { | ||
435 | v2 = gcry_mpi_new (0); | ||
436 | gcry_mpi_sub_ui (v2, v2, value); | ||
437 | } | ||
438 | else | ||
439 | v2 = gcry_mpi_set_ui (NULL, value); | ||
440 | |||
441 | gcry_mpi_mul (v1_v2_prod, v1, v2); | ||
442 | gcry_mpi_add (expected_result, expected_result, v1_v2_prod); | ||
443 | |||
444 | gcry_mpi_release (v1); | ||
445 | gcry_mpi_release (v2); | ||
446 | gcry_mpi_release (v1_v2_prod); | ||
447 | |||
448 | } | ||
449 | |||
450 | // compare the result | ||
451 | if (!gcry_mpi_cmp (expected_result, result)) | ||
452 | { | ||
453 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Scalar Product matches expected Result!!\n"); | ||
454 | requester_ok = 1; | ||
455 | } | ||
456 | else | ||
457 | { | ||
458 | LOG (GNUNET_ERROR_TYPE_WARNING, "Scalar Product DOES NOT match expected Result!!\n"); | ||
459 | requester_ok = -1; | ||
460 | } | ||
461 | gcry_mpi_release (result); | ||
462 | gcry_mpi_release (expected_result); | ||
463 | } | ||
464 | } | ||
465 | else | ||
466 | { //currently not used, but if we get more info due to MESH we will need this | ||
467 | LOG (GNUNET_ERROR_TYPE_WARNING, "Error during computation of vector product, return code: %d\n", product_len); | ||
468 | requester_ok = -1; | ||
469 | } | ||
470 | } | ||
471 | |||
472 | //do_shutdown(&peer2, NULL); | ||
473 | GNUNET_SCHEDULER_add_now (&do_shutdown, &peer2); | ||
474 | return; | ||
475 | } | ||
476 | |||
477 | |||
478 | static struct GNUNET_SCALARPRODUCT_QueueEntry * | ||
479 | requester_request () | ||
480 | { | ||
481 | GNUNET_assert (peer2.vh != NULL); | ||
482 | |||
483 | unsigned int i; | ||
484 | //uint16_t element_count_peer2 = 0; | ||
485 | uint16_t mask_length = 0; | ||
486 | char * begin = input_elements_peer2; | ||
487 | char * end; | ||
488 | int32_t element; | ||
489 | |||
490 | struct GNUNET_SCALARPRODUCT_QueueEntry *qe; | ||
491 | |||
492 | struct GNUNET_HashCode key; | ||
493 | GNUNET_CRYPTO_hash (input_key, strlen (input_key), &key); | ||
494 | |||
495 | int exit_loop = 0; | ||
496 | /* Read input_elements_peer2, and put in elements_peer2 array */ | ||
497 | do | ||
498 | { | ||
499 | unsigned int mcount = element_count_peer2; | ||
500 | //ignore empty rows of ,,,,,, | ||
501 | while (*begin == ',') | ||
502 | begin++; | ||
503 | // get the length of the current element and replace , with null | ||
504 | for (end = begin; *end && *end != ','; end++); | ||
505 | |||
506 | if (*end == '\0') | ||
507 | exit_loop = 1; | ||
508 | |||
509 | if (1 != sscanf (begin, "%" SCNd32, &element)) | ||
510 | { | ||
511 | FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin); | ||
512 | ok = -1; | ||
513 | return NULL; | ||
514 | } | ||
515 | |||
516 | GNUNET_array_append (elements_peer2, mcount, element); | ||
517 | element_count_peer2++; | ||
518 | |||
519 | begin = ++end; | ||
520 | } | ||
521 | while (!exit_loop && element_count_peer2 < max_mids); | ||
522 | |||
523 | GNUNET_assert (elements_peer2 != NULL); | ||
524 | GNUNET_assert (element_count_peer2 >= 1); | ||
525 | mask_length = element_count_peer2 / 8 + (element_count_peer2 % 8 ? 1 : 0); | ||
526 | mask_peer2 = GNUNET_malloc ((element_count_peer2 / 8) + 2); | ||
527 | GNUNET_assert (NULL != mask_peer2); | ||
528 | |||
529 | /* Read input_mask_peer2 and read in mask_peer2 array */ | ||
530 | if (NULL != input_mask_peer2) | ||
531 | { | ||
532 | begin = input_mask_peer2; | ||
533 | unsigned short mask_count = 0; | ||
534 | int exit_loop = 0; | ||
535 | |||
536 | do | ||
537 | { | ||
538 | //ignore empty rows of ,,,,,, | ||
539 | while (* begin == ',') | ||
540 | begin++; | ||
541 | // get the length of the current element and replace , with null | ||
542 | // gnunet_ascii-armor uses base32, thus we can use , as separator! | ||
543 | for (end = begin; *end && *end != ','; end++); | ||
544 | |||
545 | if (*end == '\0') | ||
546 | exit_loop = 1; | ||
547 | |||
548 | if (1 != sscanf (begin, "%" SCNd32, &element)) | ||
549 | { | ||
550 | FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin); | ||
551 | ok = -1; | ||
552 | return NULL; | ||
553 | } | ||
554 | |||
555 | GNUNET_assert (mask_count <= element_count_peer2); | ||
556 | |||
557 | if (element) | ||
558 | mask_peer2[mask_count / 8] = mask_peer2[mask_count / 8] | 1 << (mask_count % 8); | ||
559 | |||
560 | mask_count++; | ||
561 | begin = ++end; | ||
562 | } | ||
563 | while (!exit_loop); | ||
564 | // +1 to see if we would have more data, which would indicate malformed/superficial input | ||
565 | GNUNET_assert (mask_count == element_count_peer2); | ||
566 | } | ||
567 | else | ||
568 | { | ||
569 | for (i = 0; i <= mask_length; i++) | ||
570 | mask_peer2[i] = UCHAR_MAX; // all 1's | ||
571 | } | ||
572 | |||
573 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Responder peer key %s\n", &peer1.our_id); | ||
574 | |||
575 | // TODO : Create the mask array | ||
576 | qe = GNUNET_SCALARPRODUCT_request (peer2.vh, | ||
577 | &key, | ||
578 | &peer1.our_id, | ||
579 | element_count_peer2, | ||
580 | mask_length, | ||
581 | elements_peer2, mask_peer2, | ||
582 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | ||
583 | &requester_callback, | ||
584 | NULL); | ||
585 | |||
586 | if (qe == NULL) | ||
587 | { | ||
588 | FPRINTF (stderr, "%s", _ ("Could not send request to scalarproduct service! Exitting!")); | ||
589 | ok = -1; | ||
590 | return NULL; | ||
591 | } | ||
592 | |||
593 | return qe; | ||
594 | } | ||
595 | |||
596 | |||
597 | /** | ||
598 | * Function prepares the message to be sent by peer1 to its scalarproduct service | ||
599 | * to prepare response, and wait for a request session to be initiated by peer1 | ||
600 | */ | ||
601 | static struct GNUNET_SCALARPRODUCT_QueueEntry * | ||
602 | responder_prepare_response () | ||
603 | { | ||
604 | GNUNET_assert (peer1.vh != NULL); | ||
605 | |||
606 | unsigned int i; | ||
607 | //uint16_t element_count_peer1 = 0; | ||
608 | char * begin = input_elements_peer1; | ||
609 | char * end; | ||
610 | int32_t element; | ||
611 | |||
612 | struct GNUNET_SCALARPRODUCT_QueueEntry *qe; | ||
613 | |||
614 | struct GNUNET_HashCode key; | ||
615 | GNUNET_CRYPTO_hash (input_key, strlen (input_key), &key); | ||
616 | |||
617 | int exit_loop = 0; | ||
618 | /* Read input_elements_peer1, and put in elements_peer1 array */ | ||
619 | do | ||
620 | { | ||
621 | unsigned int mcount = element_count_peer1; | ||
622 | //ignore empty rows of ,,,,,, | ||
623 | while (*begin == ',') | ||
624 | begin++; | ||
625 | // get the length of the current element and replace , with null | ||
626 | for (end = begin; *end && *end != ','; end++); | ||
627 | |||
628 | if (*end == '\0') | ||
629 | exit_loop = 1; | ||
630 | |||
631 | if (*end == ',') | ||
632 | *end = '\0'; | ||
633 | |||
634 | if (1 != sscanf (begin, "%" SCNd32, &element)) | ||
635 | { | ||
636 | FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin); | ||
637 | ok = -1; | ||
638 | return NULL; | ||
639 | } | ||
640 | |||
641 | GNUNET_array_append (elements_peer1, mcount, element); | ||
642 | element_count_peer1++; | ||
643 | |||
644 | begin = ++end; | ||
645 | } | ||
646 | while (!exit_loop && element_count_peer1 < max_mids); | ||
647 | |||
648 | GNUNET_assert (elements_peer1 != NULL); | ||
649 | GNUNET_assert (element_count_peer1 >= 1); | ||
650 | |||
651 | qe = GNUNET_SCALARPRODUCT_prepare_response (peer1.vh, | ||
652 | &key, | ||
653 | element_count_peer1, | ||
654 | elements_peer1, | ||
655 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | ||
656 | &responder_callback, | ||
657 | NULL); | ||
658 | |||
659 | if (qe == NULL) | ||
660 | { | ||
661 | FPRINTF (stderr, "%s", _ ("Could not send request to scalarproduct service! Exitting!")); | ||
662 | ok = -1; | ||
663 | return NULL; | ||
664 | } | ||
665 | return qe; | ||
666 | } | ||
667 | |||
668 | |||
669 | /** | ||
670 | * Scheduler task to initiate requester client | ||
671 | * | ||
672 | * @param cls void* to struct PeerData | ||
673 | * @param tc Task Context | ||
674 | */ | ||
675 | static void | ||
676 | request_task (void *cls, | ||
677 | const struct GNUNET_SCHEDULER_TaskContext | ||
678 | * tc) | ||
679 | { | ||
680 | struct PeerData * peer = cls; | ||
681 | |||
682 | requester_request (); | ||
683 | return; | ||
684 | } | ||
685 | |||
686 | |||
687 | /** | ||
688 | * Scheduler task to initiate responder client | ||
689 | * | ||
690 | * @param cls void* to struct PeerData | ||
691 | * @param tc Task Context | ||
692 | */ | ||
693 | static void | ||
694 | prepare_response_task (void *cls, | ||
695 | const struct GNUNET_SCHEDULER_TaskContext | ||
696 | * tc) | ||
697 | { | ||
698 | struct PeerData * peer = cls; | ||
699 | |||
700 | responder_prepare_response (); | ||
701 | return; | ||
702 | } | ||
703 | |||
704 | |||
705 | static void | ||
706 | peer_stop_callback (void *cls, | ||
707 | const char *emsg) | ||
708 | { | ||
709 | GNUNET_TESTBED_peer_destroy (peer2.peer); | ||
710 | } | ||
711 | |||
712 | /** | ||
713 | * Destroys Peer2 i.e. the initiator peer (Alice) This function is scheduled to | ||
714 | * run a few milliseconds after the request has been sent to the Responding Peer (Bob). | ||
715 | * This function tries to emulate a crash of Peer2. | ||
716 | * | ||
717 | * @param cls Not used | ||
718 | * @param tc Task Context - Not used | ||
719 | */ | ||
720 | static void | ||
721 | destroy_server (void *cls, | ||
722 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
723 | { | ||
724 | LOG (GNUNET_ERROR_TYPE_INFO, "\n***\nKilling the Requesting Client, hopefully before it receives response\n***\n"); | ||
725 | do_shutdown (&peer2, NULL); | ||
726 | GNUNET_TESTBED_peer_stop (peer2.peer, &peer_stop_callback, NULL); | ||
727 | } | ||
728 | |||
729 | |||
730 | /** | ||
731 | * Adapter function called to destroy a connection to | ||
732 | * a service. This function is called when GNUNET_TESTBED_operation_done is | ||
733 | * called for peer->op, which holds the handle for GNUNET_TESTBED_service_connect | ||
734 | * operation. | ||
735 | * | ||
736 | * @param cls closure | ||
737 | * @param op_result service handle returned from the connect adapter | ||
738 | */ | ||
739 | static void | ||
740 | scalarproduct_da (void *cls, void *op_result) | ||
741 | { | ||
742 | struct PeerData* peer = (struct PeerData*) cls; | ||
743 | |||
744 | GNUNET_SCALARPRODUCT_cancel (peer->vh); | ||
745 | return; | ||
746 | } | ||
747 | |||
748 | |||
749 | /** | ||
750 | * Adapter function called to establish a connection to | ||
751 | * a service. This function is called to by GNUNET_TESTBED_service_connect. | ||
752 | * | ||
753 | * @param cls closure | ||
754 | * @param cfg configuration of the peer to connect to; will be available until | ||
755 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
756 | * from GNUNET_TESTBED_service_connect() | ||
757 | * @return service handle to return in 'op_result', NULL on error | ||
758 | */ | ||
759 | static void * | ||
760 | scalarproduct_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
761 | { | ||
762 | struct PeerData *p = cls; | ||
763 | |||
764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", (&peer1 == p) ? 1 : 2, | ||
765 | GNUNET_i2s (&p->our_id)); | ||
766 | |||
767 | switch (setup_state) | ||
768 | { | ||
769 | case PEER1_SCALARPRODUCT_CONNECT: | ||
770 | /* Connect peer 2 to scalarproduct service */ | ||
771 | /* The connect adapter scalarproduct_ca will be called to perform the actual connection */ | ||
772 | { | ||
773 | peer2.op = GNUNET_TESTBED_service_connect (&peer2, peer2.peer, "scalarproduct", | ||
774 | NULL, NULL, scalarproduct_ca, | ||
775 | scalarproduct_da, &peer2); | ||
776 | setup_state = PEER2_SCALARPRODUCT_CONNECT; | ||
777 | } | ||
778 | |||
779 | /* Actually connect peer 1 to scalarproduct service */ | ||
780 | peer1.vh = GNUNET_SCALARPRODUCT_connect (cfg); | ||
781 | return peer1.vh; | ||
782 | |||
783 | case PEER2_SCALARPRODUCT_CONNECT: | ||
784 | /* Actually connect peer 2 to scalarproduct service */ | ||
785 | peer2.vh = GNUNET_SCALARPRODUCT_connect (cfg); | ||
786 | |||
787 | |||
788 | if (peer1.vh != NULL && peer2.vh != NULL) | ||
789 | { | ||
790 | GNUNET_SCHEDULER_add_now (&prepare_response_task, &peer1); | ||
791 | GNUNET_SCHEDULER_add_now (&request_task, &peer2); | ||
792 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 6), | ||
793 | &destroy_server, NULL); | ||
794 | } | ||
795 | else | ||
796 | { | ||
797 | // TODO : Handle error. One of the peers is not connected. Cleanly shutdown | ||
798 | ok = -1; | ||
799 | return NULL; | ||
800 | } | ||
801 | return peer2.vh; | ||
802 | default: | ||
803 | GNUNET_assert (0); | ||
804 | } | ||
805 | } | ||
806 | |||
807 | |||
808 | /** | ||
809 | * Callback to be called when the requested peer information is available | ||
810 | * | ||
811 | * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information() | ||
812 | * @param op the operation this callback corresponds to | ||
813 | * @param pinfo the result; will be NULL if the operation has failed | ||
814 | * @param emsg error message if the operation has failed; will be NULL if the | ||
815 | * operation is successfull | ||
816 | */ | ||
817 | static void | ||
818 | peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_, | ||
819 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
820 | const char *emsg) | ||
821 | { | ||
822 | GNUNET_assert (NULL == emsg); | ||
823 | GNUNET_assert (op == op_); | ||
824 | switch (setup_state) | ||
825 | { | ||
826 | case PEER1_GET_IDENTITY: | ||
827 | { | ||
828 | memcpy (&peer1.our_id, pinfo->result.id, | ||
829 | sizeof (struct GNUNET_PeerIdentity)); | ||
830 | GNUNET_TESTBED_operation_done (op); | ||
831 | |||
832 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 id: %s\n", GNUNET_i2s_full | ||
833 | (&peer1.our_id)); | ||
834 | |||
835 | /* Request for peer id of peer 2*/ | ||
836 | op = GNUNET_TESTBED_peer_get_information (peer2.peer, | ||
837 | GNUNET_TESTBED_PIT_IDENTITY, | ||
838 | &peerinfo_cb, NULL); | ||
839 | setup_state = PEER2_GET_IDENTITY; | ||
840 | } | ||
841 | break; | ||
842 | case PEER2_GET_IDENTITY: | ||
843 | { | ||
844 | memcpy (&peer2.our_id, pinfo->result.id, | ||
845 | sizeof (struct GNUNET_PeerIdentity)); | ||
846 | GNUNET_TESTBED_operation_done (op); | ||
847 | |||
848 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n", GNUNET_i2s_full | ||
849 | (&peer2.our_id)); | ||
850 | |||
851 | /* Connect peer 1 to scalarproduct service */ | ||
852 | /* The connect adapter scalarproduct_ca will be called to perform the actual connection */ | ||
853 | peer1.op = GNUNET_TESTBED_service_connect (&peer1, peer1.peer, "scalarproduct", | ||
854 | NULL, NULL, scalarproduct_ca, | ||
855 | scalarproduct_da, &peer1); | ||
856 | setup_state = PEER1_SCALARPRODUCT_CONNECT; | ||
857 | } | ||
858 | break; | ||
859 | default: | ||
860 | GNUNET_assert (0); | ||
861 | } | ||
862 | } | ||
863 | |||
864 | |||
865 | /** | ||
866 | * Signature of a main function for a testcase. | ||
867 | * | ||
868 | * @param cls closure | ||
869 | * @param num_peers number of peers in 'peers' | ||
870 | * @param peers handle to peers run in the testbed | ||
871 | */ | ||
872 | static void | ||
873 | test_master (void *cls, unsigned int num_peers, | ||
874 | struct GNUNET_TESTBED_Peer **peers) | ||
875 | { | ||
876 | GNUNET_assert (NULL != peers); | ||
877 | GNUNET_assert (NULL != peers[0]); | ||
878 | GNUNET_assert (NULL != peers[1]); | ||
879 | peer1.peer = peers[0]; | ||
880 | peer2.peer = peers[1]; | ||
881 | /* Get the peer identity and configuration of peer 1 */ | ||
882 | op = GNUNET_TESTBED_peer_get_information (peer1.peer, | ||
883 | GNUNET_TESTBED_PIT_IDENTITY, | ||
884 | &peerinfo_cb, NULL); | ||
885 | setup_state = PEER1_GET_IDENTITY; | ||
886 | abort_task = | ||
887 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
888 | (GNUNET_TIME_UNIT_SECONDS, 20), &do_abort, | ||
889 | NULL); | ||
890 | } | ||
891 | |||
892 | |||
893 | /** | ||
894 | * Main function | ||
895 | */ | ||
896 | int | ||
897 | main (int argc, char **argv) | ||
898 | { | ||
899 | uint64_t event_mask; | ||
900 | |||
901 | ok = GNUNET_NO; | ||
902 | event_mask = 0; | ||
903 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
904 | max_mids = (GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_MessageHeader)) | ||
905 | / sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1; | ||
906 | |||
907 | (void) GNUNET_TESTBED_test_run ("test_scalarproduct_api_regression2", | ||
908 | "test_scalarproduct_api_data.conf", | ||
909 | NUM_PEERS, event_mask, &controller_event_cb, | ||
910 | NULL, | ||
911 | &test_master, NULL); | ||
912 | if (GNUNET_SYSERR == ok) | ||
913 | { | ||
914 | LOG (GNUNET_ERROR_TYPE_ERROR, "Test failing due to some error before calling API for request or prepare_response\n"); | ||
915 | return 1; | ||
916 | } | ||
917 | else if (GNUNET_SYSERR == responder_ok) | ||
918 | { | ||
919 | LOG (GNUNET_ERROR_TYPE_ERROR, "Test failing due to some error in response for responding_client\n"); | ||
920 | return 1; | ||
921 | } | ||
922 | else if (GNUNET_SYSERR == requester_ok) | ||
923 | { | ||
924 | LOG (GNUNET_ERROR_TYPE_ERROR, "Test failing due to some error in response for requesting client\n"); | ||
925 | return 1; | ||
926 | } | ||
927 | else | ||
928 | return 0; | ||
929 | } | ||
930 | |||
931 | |||