- cleanup dead code
[oweals/gnunet.git] / src / scalarproduct / test_scalarproduct_api.c
index 8020156945ac76922518887ebbb402a4962b8949..082723278124bb8b7ad8431a7616d3f4d31f6fad 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 /**
- * Aim of test_vectorproduct_api : This test creates two peers. Peer1 is the 
+ * Aim of test_scalarproduct_api : This test creates two peers. Peer1 is the
  * responder peer, Bob and Peer2 is the initiator peer, Alice. Both peers
  * connect to VectorProduct Service, and use the API to issue requests to
  * service. Test passes, when the expected scalar product is received from the
@@ -27,7 +27,7 @@
  */
 
 /**
- * @file vectorproduct/testbed_vectorproduct_api.c
+ * @file scalarproduct/testbed_scalarproduct_api.c
  * @brief VectorProduct API testing between 4 peers using testing API
  * @author Gaurav Kukreja
  * @author Christian Fuchs
 #include "gnunet_util_lib.h"
 #include "gnunet_testbed_service.h"
 #include "gnunet_common.h"
-#include "gnunet_vectorproduct_service.h"
+#include "gnunet_scalarproduct_service.h"
 #include "gnunet_protocols.h"
 
 #define NUM_PEERS 2
 
-#define LOG(kind,...) GNUNET_log_from (kind, "test-vectorproduct-api",__VA_ARGS__)
+#define LOG(kind,...) GNUNET_log_from (kind, "test-scalarproduct-api",__VA_ARGS__)
 
 /**
  * Structure for holding peer's sockets and IO Handles
@@ -70,7 +70,7 @@ struct PeerData
   /**
    * Pointer to Vector Product Handle
    */
-  struct GNUNET_VECTORPRODUCT_Handle *vh;
+  struct GNUNET_SCALARPRODUCT_Handle *vh;
 };
 
 /**
@@ -91,12 +91,12 @@ enum SetupState
   /**
    * Connect to stream service of peer 1
    */
-  PEER1_VECTORPRODUCT_CONNECT,
+  PEER1_SCALARPRODUCT_CONNECT,
 
   /**
    * Connect to stream service of peer 2
    */
-  PEER2_VECTORPRODUCT_CONNECT
+  PEER2_SCALARPRODUCT_CONNECT
 
 };
 
@@ -219,7 +219,7 @@ do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
 /**
  * Shutdown a peer
- * 
+ *
  * @param cls pointer to "struct PeerData" of the peer to be disconnected
  * @param tc Task Context
  */
@@ -236,7 +236,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     LOG (GNUNET_ERROR_TYPE_INFO, "Disconnecting Peer2\n\n");
 
   // peer->op contains handle to the TESTBED_connect_service operation
-  // calling operation done, leads to call to vectorproduct_da
+  // calling operation done, leads to call to scalarproduct_da
   if (peer->op != NULL)
     {
       GNUNET_TESTBED_operation_done (peer->op);
@@ -272,11 +272,11 @@ controller_event_cb (void *cls,
                      const struct GNUNET_TESTBED_EventInformation *event)
 {
   GNUNET_assert (event->type == GNUNET_TESTBED_ET_OPERATION_FINISHED);
-  
+
   switch (setup_state)
     {
-    case PEER1_VECTORPRODUCT_CONNECT:
-    case PEER2_VECTORPRODUCT_CONNECT:
+    case PEER1_SCALARPRODUCT_CONNECT:
+    case PEER2_SCALARPRODUCT_CONNECT:
       GNUNET_assert (NULL == event->details.operation_finished.emsg);
       break;
     default:
@@ -288,30 +288,30 @@ controller_event_cb (void *cls,
 static void
 responder_callback (void *cls,
                     const struct GNUNET_HashCode * key,
-                    enum GNUNET_VECTORPRODUCT_ResponseStatus status)
+                    enum GNUNET_SCALARPRODUCT_ResponseStatus status)
 {
 
-  if (status == GNUNET_VECTORPRODUCT_Status_Failure)
+  if (status == GNUNET_SCALARPRODUCT_Status_Failure)
     {
       LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received status failure\n");
       responder_ok = -1;
     }
-  else if (status == GNUNET_VECTORPRODUCT_Status_InvalidResponse)
+  else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse)
     {
       LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received status invalid response\n");
       responder_ok = -1;
     }
-  else if (GNUNET_VECTORPRODUCT_Status_Timeout == status)
+  else if (GNUNET_SCALARPRODUCT_Status_Timeout == status)
     {
       LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received timeout occured\n");
       responder_ok = -1;
     }
-  else if (GNUNET_VECTORPRODUCT_Status_ServiceDisconnected == status)
+  else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status)
     {
       LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received service disconnected!!\n");
       responder_ok = -1;
     }
-  else if (GNUNET_VECTORPRODUCT_Status_Success == status)
+  else if (GNUNET_SCALARPRODUCT_Status_Success == status)
     {
       LOG (GNUNET_ERROR_TYPE_INFO, "Responder Client expected response received!\n");
       responder_ok = 1;
@@ -332,41 +332,41 @@ static void
 requester_callback (void *cls,
         const struct GNUNET_HashCode * key,
         const struct GNUNET_PeerIdentity * peer,
-        enum GNUNET_VECTORPRODUCT_ResponseStatus status,
-        const struct GNUNET_VECTORPRODUCT_client_response *msg)
+        enum GNUNET_SCALARPRODUCT_ResponseStatus status,
+        const struct GNUNET_SCALARPRODUCT_client_response *msg)
 {
   uint32_t product_len;
 
-  if (status == GNUNET_VECTORPRODUCT_Status_Failure)
+  if (status == GNUNET_SCALARPRODUCT_Status_Failure)
     {
       LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client received status failure\n");
       requester_ok = -1;
     }
-  else if (status == GNUNET_VECTORPRODUCT_Status_InvalidResponse)
+  else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse)
     {
       LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client received status invalid response\n");
       requester_ok = -1;
     }
-  else if (GNUNET_VECTORPRODUCT_Status_Timeout == status)
+  else if (GNUNET_SCALARPRODUCT_Status_Timeout == status)
     {
       LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client timeout occured\n");
       requester_ok = -1;
     }
-  else if (GNUNET_VECTORPRODUCT_Status_ServiceDisconnected == status)
+  else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status)
     {
       LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client service disconnected!!\n");
       requester_ok = -1;
     }
-  else if (GNUNET_VECTORPRODUCT_Status_Success != status)
+  else if (GNUNET_SCALARPRODUCT_Status_Success != status)
     {
       LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client Status = %d\n", (int) status);
       requester_ok = -1;
     }
-  else if (GNUNET_VECTORPRODUCT_Status_Success == status)
+  else if (GNUNET_SCALARPRODUCT_Status_Success == status)
     {
       LOG (GNUNET_ERROR_TYPE_INFO, "Requester Client expected response received!\n");
       product_len = ntohl(msg->product_length);
-      
+
       if (0 < product_len)
         {
           gcry_mpi_t result;
@@ -383,7 +383,7 @@ requester_callback (void *cls,
             {
               uint16_t i = 0;
 
-              // calculate expected product 
+              // calculate expected product
               gcry_mpi_t expected_result;
               gcry_mpi_t v1;
               gcry_mpi_t v2;
@@ -424,7 +424,7 @@ requester_callback (void *cls,
                   gcry_mpi_release (v1_v2_prod);
 
                 }
-              
+
               // compare the result
               if (!gcry_mpi_cmp (expected_result, result))
                 {
@@ -453,10 +453,10 @@ requester_callback (void *cls,
 }
 
 /**
- * Prepare the message to be sent by peer2 to its vectorproduct service, to 
+ * Prepare the message to be sent by peer2 to its scalarproduct service, to
  * initiate a request to peer1.
  */
-static struct GNUNET_VECTORPRODUCT_QueueEntry *
+static struct GNUNET_SCALARPRODUCT_QueueEntry *
 requester_request ()
 {
   unsigned int i;
@@ -465,11 +465,11 @@ requester_request ()
   char * begin = input_elements_peer2;
   char * end;
   int32_t element;
-  struct GNUNET_VECTORPRODUCT_QueueEntry *qe;
+  struct GNUNET_SCALARPRODUCT_QueueEntry *qe;
   struct GNUNET_HashCode key;
-  
+
   GNUNET_assert (peer2.vh != NULL);
-  
+
   GNUNET_CRYPTO_hash (input_key, strlen (input_key), &key);
 
   /* Read input_elements_peer2, and put in elements_peer2 array */
@@ -501,7 +501,7 @@ requester_request ()
   while (!exit_loop && element_count_peer2 < max_mids);
   GNUNET_assert (elements_peer2 != NULL);
   GNUNET_assert (element_count_peer2 >= 1);
-  
+
   /* Read input_mask_peer2 and read in mask_peer2 array */
   mask_length = element_count_peer2 / 8 + (element_count_peer2 % 8 ? 1 : 0);
   mask_peer2 = GNUNET_malloc ((element_count_peer2 / 8) + 2);
@@ -549,7 +549,7 @@ requester_request ()
         mask_peer2[i] = UCHAR_MAX; // all 1's
     }
 
-  qe = GNUNET_VECTORPRODUCT_request (peer2.vh,
+  qe = GNUNET_SCALARPRODUCT_request (peer2.vh,
                                      &key,
                                      &peer1.our_id,
                                      element_count_peer2,
@@ -561,7 +561,7 @@ requester_request ()
 
   if (qe == NULL)
     {
-      LOG(GNUNET_ERROR_TYPE_ERROR, "Could not send request to vectorproduct service! Exitting!");
+      LOG(GNUNET_ERROR_TYPE_ERROR, "Could not send request to scalarproduct service! Exitting!");
       ok = -1;
       return NULL;
     }
@@ -571,10 +571,10 @@ requester_request ()
 
 
 /**
- * Function prepares the message to be sent by peer1 to its vectorproduct service
+ * Function prepares the message to be sent by peer1 to its scalarproduct service
  * to prepare response, and wait for a request session to be initiated by peer1
  */
-static struct GNUNET_VECTORPRODUCT_QueueEntry *
+static struct GNUNET_SCALARPRODUCT_QueueEntry *
 responder_prepare_response ()
 {
   GNUNET_assert (peer1.vh != NULL);
@@ -582,9 +582,9 @@ responder_prepare_response ()
   char * begin = input_elements_peer1;
   char * end;
   int32_t element;
-  struct GNUNET_VECTORPRODUCT_QueueEntry *qe;
+  struct GNUNET_SCALARPRODUCT_QueueEntry *qe;
   struct GNUNET_HashCode key;
-  
+
   GNUNET_CRYPTO_hash (input_key, strlen (input_key), &key);
 
   /* Read input_elements_peer1, and put in elements_peer1 array */
@@ -617,7 +617,7 @@ responder_prepare_response ()
   GNUNET_assert (elements_peer1 != NULL);
   GNUNET_assert (element_count_peer1 >= 1);
 
-  qe = GNUNET_VECTORPRODUCT_prepare_response (peer1.vh,
+  qe = GNUNET_SCALARPRODUCT_prepare_response (peer1.vh,
                                               &key,
                                               element_count_peer1,
                                               elements_peer1,
@@ -627,7 +627,7 @@ responder_prepare_response ()
 
   if (qe == NULL)
     {
-      LOG(GNUNET_ERROR_TYPE_ERROR, "Could not send request to vectorproduct service! Exitting!");
+      LOG(GNUNET_ERROR_TYPE_ERROR, "Could not send request to scalarproduct service! Exitting!");
       ok = -1;
       return NULL;
     }
@@ -638,7 +638,7 @@ responder_prepare_response ()
 
 /**
  * Scheduler task to initiate requester client
- * 
+ *
  * @param cls void* to struct PeerData
  * @param tc Task Context
  */
@@ -653,7 +653,7 @@ request_task(void *cls,
 
 /**
  * Scheduler task to initiate responder client
- * 
+ *
  * @param cls void* to struct PeerData
  * @param tc Task Context
  */
@@ -661,7 +661,7 @@ static void
 prepare_response_task(void *cls,
               const struct GNUNET_SCHEDULER_TaskContext
               * tc)
-{ 
+{
   responder_prepare_response();
   return;
 }
@@ -672,16 +672,16 @@ prepare_response_task(void *cls,
  * a service. This function is called when GNUNET_TESTBED_operation_done is
  * called for peer->op, which holds the handle for GNUNET_TESTBED_service_connect
  * operation.
- * 
+ *
  * @param cls closure
  * @param op_result service handle returned from the connect adapter
  */
 static void
-vectorproduct_da (void *cls, void *op_result)
+scalarproduct_da (void *cls, void *op_result)
 {
   struct PeerData* peer = (struct PeerData*) cls;
 
-  GNUNET_VECTORPRODUCT_disconnect (peer->vh);
+  GNUNET_SCALARPRODUCT_cancel (peer->vh);
   return;
 }
 
@@ -689,7 +689,7 @@ vectorproduct_da (void *cls, void *op_result)
 /**
  * Adapter function called to establish a connection to
  * a service. This function is called to by GNUNET_TESTBED_service_connect.
- * 
+ *
  * @param cls closure
  * @param cfg configuration of the peer to connect to; will be available until
  *          GNUNET_TESTBED_operation_done() is called on the operation returned
@@ -697,7 +697,7 @@ vectorproduct_da (void *cls, void *op_result)
  * @return service handle to return in 'op_result', NULL on error
  */
 static void *
-vectorproduct_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
+scalarproduct_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct PeerData *p = cls;
 
@@ -706,22 +706,22 @@ vectorproduct_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 
   switch (setup_state)
     {
-    case PEER1_VECTORPRODUCT_CONNECT:
-      /* Connect peer 2 to vectorproduct service */
+    case PEER1_SCALARPRODUCT_CONNECT:
+      /* Connect peer 2 to scalarproduct service */
       {
-        peer2.op = GNUNET_TESTBED_service_connect (&peer2, peer2.peer, "vectorproduct",
-                                                   NULL, NULL, vectorproduct_ca,
-                                                   vectorproduct_da, &peer2);
-        setup_state = PEER2_VECTORPRODUCT_CONNECT;
+        peer2.op = GNUNET_TESTBED_service_connect (&peer2, peer2.peer, "scalarproduct",
+                                                   NULL, NULL, scalarproduct_ca,
+                                                   scalarproduct_da, &peer2);
+        setup_state = PEER2_SCALARPRODUCT_CONNECT;
       }
 
-      /* Actually connect peer 1 to vectorproduct service */
-      peer1.vh = GNUNET_VECTORPRODUCT_connect (cfg);
+      /* Actually connect peer 1 to scalarproduct service */
+      peer1.vh = GNUNET_SCALARPRODUCT_connect (cfg);
       return peer1.vh;
 
-    case PEER2_VECTORPRODUCT_CONNECT:
-      /* Actually connect peer 2 to vectorproduct service */
-      peer2.vh = GNUNET_VECTORPRODUCT_connect (cfg);
+    case PEER2_SCALARPRODUCT_CONNECT:
+      /* Actually connect peer 2 to scalarproduct service */
+      peer2.vh = GNUNET_SCALARPRODUCT_connect (cfg);
 
       /* Schedule tasks to initiate request from peer2 and prepare_response from peer1 */
       if(peer1.vh != NULL && peer2.vh != NULL)
@@ -729,7 +729,7 @@ vectorproduct_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
         GNUNET_SCHEDULER_add_now(&prepare_response_task, &peer1);
         GNUNET_SCHEDULER_add_now(&request_task, &peer2);
       }
-      
+
       return peer2.vh;
     default:
       GNUNET_assert (0);
@@ -780,11 +780,11 @@ peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_,
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n", GNUNET_i2s_full
                     (&peer2.our_id));
 
-        /* Connect peer 1 to vectorproduct service */
-        peer1.op = GNUNET_TESTBED_service_connect (&peer1, peer1.peer, "vectorproduct",
-                                                   NULL, NULL, vectorproduct_ca,
-                                                   vectorproduct_da, &peer1);
-        setup_state = PEER1_VECTORPRODUCT_CONNECT;
+        /* Connect peer 1 to scalarproduct service */
+        peer1.op = GNUNET_TESTBED_service_connect (&peer1, peer1.peer, "scalarproduct",
+                                                   NULL, NULL, scalarproduct_ca,
+                                                   scalarproduct_da, &peer1);
+        setup_state = PEER1_SCALARPRODUCT_CONNECT;
       }
       break;
     default:
@@ -814,7 +814,7 @@ test_master (void *cls, unsigned int num_peers,
                                             GNUNET_TESTBED_PIT_IDENTITY,
                                             &peerinfo_cb, NULL);
   setup_state = PEER1_GET_IDENTITY;
-  
+
   /* Abort task for stopping test on timeout */
   abort_task =
           GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
@@ -837,12 +837,12 @@ main (int argc, char **argv)
   max_mids = (GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_MessageHeader))
           / sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1;
 
-  (void) GNUNET_TESTBED_test_run ("test_vectorproduct_api",
-                                  "test_vectorproduct_api_data.conf",
+  (void) GNUNET_TESTBED_test_run ("test_scalarproduct_api",
+                                  "test_scalarproduct_api_data.conf",
                                   NUM_PEERS, event_mask, &controller_event_cb,
                                   NULL,
                                   &test_master, NULL);
-  
+
   if (GNUNET_SYSERR == ok)
     {
       LOG (GNUNET_ERROR_TYPE_ERROR, "Test failing due to some error before calling API for request or prepare_response\n");