3 This file is part of GNUnet.
4 (C) 2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
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.
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.
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.
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.
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
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"
64 #define LOG(kind,...) GNUNET_log_from (kind, "test-scalarproduct-api-4peers",__VA_ARGS__)
69 * Structure for holding peer's sockets and IO Handles
74 * Handle to testbed peer
76 struct GNUNET_TESTBED_Peer *peer;
79 * The service connect operation to stream
81 struct GNUNET_TESTBED_Operation *op;
86 struct GNUNET_PeerIdentity our_id;
89 * Pointer to Vector Product Handle
91 struct GNUNET_SCALARPRODUCT_Handle *vh;
94 * Input elements for peer
96 char * input_elements;
104 * 2 Input keys for peer for 2 sessions of each peer
106 char * input_keys[2];
109 * Number of requests(or prepare_response) sent by the peer
114 * Number of callbacks received by the peer
119 * PeerData of the peers, this peer will talk to
121 struct PeerData * peers[2];
127 * Different states in test setup
132 * Get the identity of peer 1
137 * Get the identity of peer 2
142 * Get the identity of peer 3
147 * Get the identity of peer 4
152 * Connect to stream service of peer 1
154 PEER1_SCALARPRODUCT_CONNECT,
157 * Connect to stream service of peer 2
159 PEER2_SCALARPRODUCT_CONNECT,
162 * Connect to stream service of peer 3
164 PEER3_SCALARPRODUCT_CONNECT,
167 * Connect to stream service of peer 4
169 PEER4_SCALARPRODUCT_CONNECT
173 /******************************************************************************
174 *** Global Variables *****************************
175 ******************************************************************************/
178 * Maximum allowed message-ids we can check in one go (with one GNUNET_message)
180 static unsigned int max_mids;
183 * Session Key used by both the test peers
185 char input_key_p1_p3[103] = "111111111111111111111111111111111111111111111111113333333333333333333333333333333333333333333333333333";
188 * Session Key used by both the test peers
190 char input_key_p1_p4[103] = "111111111111111111111111111111111111111111111111114444444444444444444444444444444444444444444444444444";
193 * Session Key used by both the test peers
195 char input_key_p2_p3[103] = "222222222222222222222222222222222222222222222222223333333333333333333333333333333333333333333333333333";
198 * Session Key used by both the test peers
200 char input_key_p2_p4[103] = "222222222222222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444";
203 * Input elements for peer1
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";
209 * Input Mask for peer 1
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";
215 * Input elements for peer2
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";
220 * Input Mask for peer 2
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";
226 * Input elements for peer3
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";
232 * Input Mask for peer 3
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";
238 * Input elements for peer4
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";
243 * Input Mask for peer 4
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";
250 * Data context for peer 1
252 static struct PeerData peer1;
255 * Data context for peer 2
257 static struct PeerData peer2;
260 * Data context for peer 3
262 static struct PeerData peer3;
265 * Data context for peer 4
267 static struct PeerData peer4;
270 * Various states during test setup
272 static enum SetupState setup_state;
275 * Testbed operation handle
277 static struct GNUNET_TESTBED_Operation *op;
280 * Return value for the test
285 * Abort Task for timeout
287 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
288 /******************************************************************************
289 *** Static Functions *****************************
290 ******************************************************************************/
293 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
297 * Close sockets and stop testing deamons nicely
300 do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
302 if (peer1.op != NULL)
303 GNUNET_SCHEDULER_add_now (&do_shutdown, &peer1);
305 if (peer2.op != NULL)
306 GNUNET_SCHEDULER_add_now (&do_shutdown, &peer2);
308 if (peer3.op != NULL)
309 GNUNET_SCHEDULER_add_now (&do_shutdown, &peer3);
311 if (peer4.op != NULL)
312 GNUNET_SCHEDULER_add_now (&do_shutdown, &peer4);
314 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
315 GNUNET_SCHEDULER_cancel (abort_task);
317 GNUNET_SCHEDULER_shutdown (); /* For shutting down testbed */
322 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
326 struct PeerData* peer = (struct PeerData*) cls;
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");
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);
343 GNUNET_SCHEDULER_add_now (&do_close, NULL);
348 * Something went wrong and timed out. Kill everything and set error flag
351 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
353 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: ABORT due to Timeout\n");
361 * Controller event callback
364 * @param event the controller event
367 controller_event_cb (void *cls,
368 const struct GNUNET_TESTBED_EventInformation *event)
372 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
375 case PEER1_SCALARPRODUCT_CONNECT:
376 case PEER2_SCALARPRODUCT_CONNECT:
377 GNUNET_assert (NULL == event->details.operation_finished.emsg);
390 responder_callback (void *cls,
391 const struct GNUNET_HashCode * key,
392 enum GNUNET_SCALARPRODUCT_ResponseStatus status)
394 struct PeerData * peer = cls;
396 peer->callback_num++;
400 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer1 received callback!!!\n");
402 else if (peer == &peer2)
404 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer2 received callback!!!\n");
407 LOG (GNUNET_ERROR_TYPE_ERROR, "Requester callback received, but peer is neither peer1 nor peer2!!!\n");
410 if (status == GNUNET_SCALARPRODUCT_Status_Failure)
412 LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client received status failure\n");
415 else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse)
417 LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client received status invalid response\n");
420 else if (GNUNET_SCALARPRODUCT_Status_Timeout == status)
422 LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client received timeout occured\n");
425 else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status)
427 LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client received service disconnected!!\n");
430 else if (GNUNET_SCALARPRODUCT_Status_Success == status)
432 LOG (GNUNET_ERROR_TYPE_DEBUG, "Responder Client expected response received!\n");
437 LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client status = %d!\n", (int) status);
441 // TODO : Responder Session Complete. Shutdown Test Cleanly!!!
442 if (peer->callback_num == 2)
443 GNUNET_SCHEDULER_add_now (&do_shutdown, peer);
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)
454 struct PeerData * peer_ = cls;
455 uint32_t product_len;
457 peer_->callback_num++;
461 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer3 received callback!!!\n");
463 else if (peer_ == &peer4)
465 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer4 received callback!!!\n");
468 LOG (GNUNET_ERROR_TYPE_ERROR, "Requester callback received, but peer is neither peer3 nor peer4!!!\n");
471 if (status == GNUNET_SCALARPRODUCT_Status_Failure)
473 LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client received status failure\n");
476 else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse)
478 LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client received status invalid response\n");
481 else if (GNUNET_SCALARPRODUCT_Status_Timeout == status)
483 LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client timeout occured\n");
486 else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status)
488 LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client service disconnected!!\n");
491 else if (GNUNET_SCALARPRODUCT_Status_Success != status)
493 LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client Status = %d\n", (int) status);
496 else if (GNUNET_SCALARPRODUCT_Status_Success == status)
498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requester client received status successful!\n");
499 product_len = ntohl (msg->product_length);
504 gcry_error_t ret = 0;
507 ret = gcry_mpi_scan (&result, GCRYMPI_FMT_USG, (void*) &(msg[1]), product_len, &read);
511 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not convert to mpi to value!\n");
515 gcry_mpi_release (result);
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);
527 if (peer_->callback_num == 2)
528 GNUNET_SCHEDULER_add_now (&do_shutdown, peer_);
532 static struct GNUNET_SCALARPRODUCT_QueueEntry *
533 requester_request (char * input_elements,
536 struct PeerData * peer,
537 struct PeerData * to_peer)
542 uint16_t element_count = 0;
543 int32_t * elements = NULL;
544 uint16_t mask_length = 0;
545 unsigned char * mask = NULL;
547 struct GNUNET_SCALARPRODUCT_QueueEntry *qe;
548 struct GNUNET_HashCode key;
550 char * begin = input_elements;
553 GNUNET_assert (peer->vh != NULL);
555 GNUNET_CRYPTO_hash_from_string (input_key, &key);
558 /* Read input_elements, and put in elements array */
561 unsigned int mcount = element_count;
562 //ignore empty rows of ,,,,,,
563 while (*begin == ',')
565 // get the length of the current element and replace , with null
566 for (end = begin; *end && *end != ','; end++);
572 if (1 != sscanf (begin, "%" SCNd32, &element))
574 FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin);
579 GNUNET_array_append (elements, mcount, element);
584 while (!exit_loop && element_count < max_mids);
585 GNUNET_assert (elements != NULL);
586 GNUNET_assert (element_count >= 1);
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)
595 unsigned short mask_count = 0;
600 //ignore empty rows of ,,,,,,
601 while (* 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++);
611 if (1 != sscanf (begin, "%" SCNd32, &element))
613 FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin);
618 GNUNET_assert (mask_count <= element_count);
621 mask[mask_count / 8] = mask[mask_count / 8] | 1 << (mask_count % 8);
627 // +1 to see if we would have more data, which would indicate malformed/superficial input
628 GNUNET_assert (mask_count == element_count);
632 for (i = 0; i <= mask_length; i++)
633 mask[i] = UCHAR_MAX; // all 1's
636 qe = GNUNET_SCALARPRODUCT_request (peer->vh,
642 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60),
648 LOG(GNUNET_ERROR_TYPE_WARNING, "Could not send request to scalarproduct service! Exitting!");
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
661 static struct GNUNET_SCALARPRODUCT_QueueEntry *
662 responder_prepare_response (char * input_elements,
665 struct PeerData * peer)
667 GNUNET_assert (peer->vh != NULL);
670 uint16_t element_count = 0;
671 int32_t * elements = NULL;
672 unsigned short mask_length = 0;
673 unsigned char * mask = NULL;
675 struct GNUNET_SCALARPRODUCT_QueueEntry *qe;
676 struct GNUNET_HashCode key;
681 GNUNET_CRYPTO_hash_from_string (input_key, &key);
683 /* Read input_elements, and put in elements array */
685 begin = input_elements;
688 unsigned int mcount = element_count;
689 //ignore empty rows of ,,,,,,
690 while (*begin == ',')
692 // get the length of the current element and replace , with null
693 for (end = begin; *end && *end != ','; end++);
698 if (1 != sscanf (begin, "%" SCNd32, &element))
700 FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin);
705 GNUNET_array_append (elements, mcount, element);
710 while (!exit_loop && element_count < max_mids);
711 GNUNET_assert (elements != NULL);
712 GNUNET_assert (element_count >= 1);
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)
721 unsigned short mask_count = 0;
726 //ignore empty rows of ,,,,,,
727 while (* 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++);
736 if (1 != sscanf (begin, "%" SCNd32, &element))
738 FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin);
743 GNUNET_assert (mask_count <= element_count);
746 mask[mask_count / 8] = mask[mask_count / 8] | 1 << (mask_count % 8);
752 // +1 to see if we would have more data, which would indicate malformed/superficial input
753 GNUNET_assert (mask_count == element_count);
757 for (i = 0; i <= mask_length; i++)
758 mask[i] = UCHAR_MAX; // all 1's
761 qe = GNUNET_SCALARPRODUCT_prepare_response (peer->vh,
765 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60),
771 LOG(GNUNET_ERROR_TYPE_ERROR, "Could not send request to scalarproduct service! Exitting!");
781 request_task (void *cls,
782 const struct GNUNET_SCHEDULER_TaskContext
785 struct PeerData * peer = cls;
787 requester_request (peer->input_elements, peer->input_mask, peer->input_keys[peer->request_num], peer, peer->peers[peer->request_num]);
794 prepare_response_task (void *cls,
795 const struct GNUNET_SCHEDULER_TaskContext
798 struct PeerData * peer = cls;
800 responder_prepare_response (peer->input_elements, peer->input_mask, peer->input_keys[peer->request_num], peer);
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
813 * @param op_result service handle returned from the connect adapter
816 scalarproduct_da (void *cls, void *op_result)
818 struct PeerData* peer = (struct PeerData*) cls;
820 GNUNET_SCALARPRODUCT_cancel (peer->vh);
828 * Adapter function called to establish a connection to
829 * a service. This function is called to by GNUNET_TESTBED_service_connect.
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
838 scalarproduct_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
840 struct PeerData *p = cls;
842 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", (&peer1 == p) ? 1 : 2,
843 GNUNET_i2s (&p->our_id));
847 case PEER1_SCALARPRODUCT_CONNECT:
848 /* Connect peer 2 to scalarproduct service */
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;
856 peer1.vh = GNUNET_SCALARPRODUCT_connect (cfg);
859 case PEER2_SCALARPRODUCT_CONNECT:
860 /* Connect peer 3 to scalarproduct service */
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;
868 peer2.vh = GNUNET_SCALARPRODUCT_connect (cfg);
871 case PEER3_SCALARPRODUCT_CONNECT:
872 /* Connect peer 4 to scalarproduct service */
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;
880 peer3.vh = GNUNET_SCALARPRODUCT_connect (cfg);
883 case PEER4_SCALARPRODUCT_CONNECT:
884 peer4.vh = GNUNET_SCALARPRODUCT_connect (cfg);
886 /* Schedule the tasks to issue prepare_response calls from peer1 and peer2
887 * for peer3 and peer4.
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);
895 * Schedule the tasks to issue requests calls from peer3 and peer4
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);
911 * Callback to be called when the requested peer information is available
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
920 peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_,
921 const struct GNUNET_TESTBED_PeerInformation *pinfo,
924 GNUNET_assert (NULL == emsg);
925 GNUNET_assert (op == op_);
928 case PEER1_GET_IDENTITY:
930 memcpy (&peer1.our_id, pinfo->result.id,
931 sizeof (struct GNUNET_PeerIdentity));
932 GNUNET_TESTBED_operation_done (op);
934 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 id: %s\n", GNUNET_i2s_full
937 /* Request for peer id of peer 2*/
938 op = GNUNET_TESTBED_peer_get_information (peer2.peer,
939 GNUNET_TESTBED_PIT_IDENTITY,
941 setup_state = PEER2_GET_IDENTITY;
944 case PEER2_GET_IDENTITY:
946 memcpy (&peer2.our_id, pinfo->result.id,
947 sizeof (struct GNUNET_PeerIdentity));
948 GNUNET_TESTBED_operation_done (op);
950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n", GNUNET_i2s_full
953 /* Request for peer id of peer 3*/
954 op = GNUNET_TESTBED_peer_get_information (peer3.peer,
955 GNUNET_TESTBED_PIT_IDENTITY,
957 setup_state = PEER3_GET_IDENTITY;
960 case PEER3_GET_IDENTITY:
962 memcpy (&peer3.our_id, pinfo->result.id,
963 sizeof (struct GNUNET_PeerIdentity));
964 GNUNET_TESTBED_operation_done (op);
966 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 3 id: %s\n", GNUNET_i2s_full
969 /* Request for peer id of peer 4*/
970 op = GNUNET_TESTBED_peer_get_information (peer4.peer,
971 GNUNET_TESTBED_PIT_IDENTITY,
973 setup_state = PEER4_GET_IDENTITY;
976 case PEER4_GET_IDENTITY:
978 memcpy (&peer4.our_id, pinfo->result.id,
979 sizeof (struct GNUNET_PeerIdentity));
980 GNUNET_TESTBED_operation_done (op);
982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n", GNUNET_i2s_full
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;
999 * Signature of a main function for a testcase.
1001 * @param cls closure
1002 * @param num_peers number of peers in 'peers'
1003 * @param peers handle to peers run in the testbed
1006 test_master (void *cls, unsigned int num_peers,
1007 struct GNUNET_TESTBED_Peer **peers)
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;
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;
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;
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;
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;
1057 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1058 (GNUNET_TIME_UNIT_SECONDS, 120), &do_abort,
1067 main (int argc, char **argv)
1069 uint64_t event_mask;
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,
1080 &test_master, NULL);
1081 if (GNUNET_SYSERR == ok)