[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r29350 - gnunet/src/scalarproduct
From: |
gnunet |
Subject: |
[GNUnet-SVN] r29350 - gnunet/src/scalarproduct |
Date: |
Tue, 17 Sep 2013 16:41:39 +0200 |
Author: cfuchs
Date: 2013-09-17 16:41:39 +0200 (Tue, 17 Sep 2013)
New Revision: 29350
Added:
gnunet/src/scalarproduct/test_scalarproduct.sh
Removed:
gnunet/src/scalarproduct/test_scalarproduct_api_4peers.c
gnunet/src/scalarproduct/test_scalarproduct_api_data.conf
gnunet/src/scalarproduct/test_scalarproduct_api_regression.c
gnunet/src/scalarproduct/test_scalarproduct_api_regression2.c
Modified:
gnunet/src/scalarproduct/gnunet-service-scalarproduct.c
Log:
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
Modified: gnunet/src/scalarproduct/gnunet-service-scalarproduct.c
===================================================================
--- gnunet/src/scalarproduct/gnunet-service-scalarproduct.c 2013-09-17
14:30:46 UTC (rev 29349)
+++ gnunet/src/scalarproduct/gnunet-service-scalarproduct.c 2013-09-17
14:41:39 UTC (rev 29350)
@@ -2079,7 +2079,7 @@
session->client = NULL;
}
}
- for (session = from_service_head; NULL != session; session =
from_service_head)
+ for (session = from_service_head; NULL != session; session = session->next)
if (NULL != session->tunnel){
GNUNET_MESH_tunnel_destroy (session->tunnel);
session->tunnel = NULL;
Added: gnunet/src/scalarproduct/test_scalarproduct.sh
===================================================================
--- gnunet/src/scalarproduct/test_scalarproduct.sh
(rev 0)
+++ gnunet/src/scalarproduct/test_scalarproduct.sh 2013-09-17 14:41:39 UTC
(rev 29350)
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+CFGA="-c ./test_scalarproduct_alice.conf"
+CFGB="-c ./test_scalarproduct_bob.conf"
+ #can't use ` directly
+SESSIONDATA="-k AAAA -e 10,10,10"
+EXPECTED="2C0"
+
+gnunet-arm -s $CFGA
+sleep 2
+gnunet-arm -s $CFGB
+sleep 2
+
+IDB=`gnunet-peerinfo -s $CFGB | awk -F "\x60" '{print $2}' | awk -F "'"
'{print $1}'`
+
+gnunet-scalarproduct $CFGB $SESSIONDATA
+
+RESULT=`gnunet-scalarproduct $CFGA $SESSIONDATA -p $IDB`
+
+gnunet-arm -e $CFGA &
+gnunet-arm -e $CFGB &
+
+if [ "$RESULT" == "$EXPECTED" ]
+then
+ echo "OK"
+ exit 0
+else
+ echo "Result $RESULT NOTOK"
+ exit 1
+fi
+
Property changes on: gnunet/src/scalarproduct/test_scalarproduct.sh
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Deleted: gnunet/src/scalarproduct/test_scalarproduct_api_4peers.c
===================================================================
--- gnunet/src/scalarproduct/test_scalarproduct_api_4peers.c 2013-09-17
14:30:46 UTC (rev 29349)
+++ gnunet/src/scalarproduct/test_scalarproduct_api_4peers.c 2013-09-17
14:41:39 UTC (rev 29350)
@@ -1,1084 +0,0 @@
-
-/*
- This file is part of GNUnet.
- (C) 2013 Christian Grothoff (and other contributing authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-/**
- * AIM OF THIS TEST
- *
- * The aim for the extended test is to verify the queuing functionality in the
- * service and the API. The API queues requests received from the clients. The
- * service queues requests that are received from other services.
- *
- * To test this, we create 4 peers. peer1 and peer2 are designated responders,
- * and peer3 and peer4 are designated as requesters. Each peer calls API for
the
- * scalarproduct service accordingly.
- *
- * * peer1 tells the service to prepare response for requests with keys
- * input_key_p1_p3(shared key b/w peer1 and peer3) and input_key_p1_p4.
- * Similarly peer2 tells service to prepare response for requests with keys
- * input_key_p2_p3, and input_key_p2_p4.
- * * Simultaneously, peer3 tells its service to send a request to peer1 with
key
- * input_key_p1_p3, and a request to peer2 with key input_key_p2_p3.
Similarly,
- * peer 4 sends requests with appropriate keys.
- *
- * Each peer sends 2 requests to its service, which tests the queuing in API.
- * Each service receives 2 requests from other service, which tests the
queuing
- * functionality in the service.
- */
-
-
-/**
- * @file scalarproduct/test_scalarproduct_api_4peers.c
- * @brief Vectorproduct API testing between 4 peers using testing API
- * @author Gaurav Kukreja
- * @author Christian Fuchs
- */
-
-#include <string.h>
-
-#include <inttypes.h>
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testbed_service.h"
-#include "gnunet_common.h"
-#include "gnunet_scalarproduct_service.h"
-#include "gnunet_protocols.h"
-
-#define LOG(kind,...) GNUNET_log_from (kind,
"test-scalarproduct-api-4peers",__VA_ARGS__)
-
-#define NUM_PEERS 4
-
-/**
- * Structure for holding peer's sockets and IO Handles
- */
-struct PeerData
-{
- /**
- * Handle to testbed peer
- */
- struct GNUNET_TESTBED_Peer *peer;
-
- /**
- * The service connect operation to stream
- */
- struct GNUNET_TESTBED_Operation *op;
-
- /**
- * Our Peer id
- */
- struct GNUNET_PeerIdentity our_id;
-
- /**
- * Pointer to Vector Product Handle
- */
- struct GNUNET_SCALARPRODUCT_Handle *vh;
-
- /**
- * Input elements for peer
- */
- char * input_elements;
-
- /**
- * Input Mask for peer
- */
- char * input_mask;
-
- /**
- * 2 Input keys for peer for 2 sessions of each peer
- */
- char * input_keys[2];
-
- /**
- * Number of requests(or prepare_response) sent by the peer
- */
- int request_num;
-
- /**
- * Number of callbacks received by the peer
- */
- int callback_num;
-
- /**
- * PeerData of the peers, this peer will talk to
- */
- struct PeerData * peers[2];
-
-
-};
-
-/**
- * Different states in test setup
- */
-enum SetupState
-{
- /**
- * Get the identity of peer 1
- */
- PEER1_GET_IDENTITY,
-
- /**
- * Get the identity of peer 2
- */
- PEER2_GET_IDENTITY,
-
- /**
- * Get the identity of peer 3
- */
- PEER3_GET_IDENTITY,
-
- /**
- * Get the identity of peer 4
- */
- PEER4_GET_IDENTITY,
-
- /**
- * Connect to stream service of peer 1
- */
- PEER1_SCALARPRODUCT_CONNECT,
-
- /**
- * Connect to stream service of peer 2
- */
- PEER2_SCALARPRODUCT_CONNECT,
-
- /**
- * Connect to stream service of peer 3
- */
- PEER3_SCALARPRODUCT_CONNECT,
-
- /**
- * Connect to stream service of peer 4
- */
- PEER4_SCALARPRODUCT_CONNECT
-
-};
-
-/******************************************************************************
- *** Global Variables *****************************
-
******************************************************************************/
-
-/**
- * Maximum allowed message-ids we can check in one go (with one GNUNET_message)
- */
-static unsigned int max_mids;
-
-/**
- * Session Key used by both the test peers
- */
-char input_key_p1_p3[103] =
"111111111111111111111111111111111111111111111111113333333333333333333333333333333333333333333333333333";
-
-/**
- * Session Key used by both the test peers
- */
-char input_key_p1_p4[103] =
"111111111111111111111111111111111111111111111111114444444444444444444444444444444444444444444444444444";
-
-/**
- * Session Key used by both the test peers
- */
-char input_key_p2_p3[103] =
"222222222222222222222222222222222222222222222222223333333333333333333333333333333333333333333333333333";
-
-/**
- * Session Key used by both the test peers
- */
-char input_key_p2_p4[103] =
"222222222222222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444";
-
-/**
- * Input elements for peer1
- */
-//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";
-char input_elements_peer1[] = "11,11,11";
-
-/**
- * Input Mask for peer 1
- */
-//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";
-char input_mask_peer1[] = "1,1,1";
-
-/**
- * Input elements for peer2
- */
-//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";
-char input_elements_peer2[] = "11,11,11";
-/**
- * Input Mask for peer 2
- */
-//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";
-char input_mask_peer2[] = "1,1,1";
-
-/**
- * Input elements for peer3
- */
-//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";
-char input_elements_peer3[] = "11,11,11";
-
-/**
- * Input Mask for peer 3
- */
-//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";
-char input_mask_peer3[] = "1,1,1";
-
-/**
- * Input elements for peer4
- */
-//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";
-char input_elements_peer4[] = "11,11,11";
-/**
- * Input Mask for peer 4
- */
-//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";
-char input_mask_peer4[] = "1,1,1";
-
-
-/**
- * Data context for peer 1
- */
-static struct PeerData peer1;
-
-/**
- * Data context for peer 2
- */
-static struct PeerData peer2;
-
-/**
- * Data context for peer 3
- */
-static struct PeerData peer3;
-
-/**
- * Data context for peer 4
- */
-static struct PeerData peer4;
-
-/**
- * Various states during test setup
- */
-static enum SetupState setup_state;
-
-/**
- * Testbed operation handle
- */
-static struct GNUNET_TESTBED_Operation *op;
-
-/**
- * Return value for the test
- */
-static int ok;
-
-/**
- * Abort Task for timeout
- */
-static GNUNET_SCHEDULER_TaskIdentifier abort_task;
-/******************************************************************************
- *** Static Functions *****************************
-
******************************************************************************/
-
-static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-
-/**
- * Close sockets and stop testing deamons nicely
- */
-static void
-do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- if (peer1.op != NULL)
- GNUNET_SCHEDULER_add_now (&do_shutdown, &peer1);
-
- if (peer2.op != NULL)
- GNUNET_SCHEDULER_add_now (&do_shutdown, &peer2);
-
- if (peer3.op != NULL)
- GNUNET_SCHEDULER_add_now (&do_shutdown, &peer3);
-
- if (peer4.op != NULL)
- GNUNET_SCHEDULER_add_now (&do_shutdown, &peer4);
-
- if (GNUNET_SCHEDULER_NO_TASK != abort_task)
- GNUNET_SCHEDULER_cancel (abort_task);
-
- GNUNET_SCHEDULER_shutdown (); /* For shutting down testbed */
-}
-
-
-static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- static int shutdown;
- shutdown++;
- struct PeerData* peer = (struct PeerData*) cls;
-
- if (peer == &peer1)
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down Peer 1!!! \n");
- else if (peer == &peer2)
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down Peer 2!!! \n");
- else if (peer == &peer3)
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down Peer 3!!! \n");
- else if (peer == &peer4)
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down Peer 4!!! \n");
-
- // peer->op contains handle to the TESTBED_connect_service operation
- // calling operation done, leads to call to scalarproduct_da
- GNUNET_TESTBED_operation_done (peer->op);
- peer->op = NULL;
-
- if (shutdown == 4)
- GNUNET_SCHEDULER_add_now (&do_close, NULL);
-}
-
-
-/**
- * Something went wrong and timed out. Kill everything and set error flag
- */
-static void
-do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: ABORT due to Timeout\n");
- ok = GNUNET_SYSERR;
- abort_task = 0;
- do_close (cls, tc);
-}
-
-
-/**
- * Controller event callback
- *
- * @param cls NULL
- * @param event the controller event
- */
-static void
-controller_event_cb (void *cls,
- const struct GNUNET_TESTBED_EventInformation *event)
-{
- switch (event->type)
- {
- case GNUNET_TESTBED_ET_OPERATION_FINISHED:
- switch (setup_state)
- {
- case PEER1_SCALARPRODUCT_CONNECT:
- case PEER2_SCALARPRODUCT_CONNECT:
- GNUNET_assert (NULL == event->details.operation_finished.emsg);
- break;
- default:
- GNUNET_assert (0);
- }
- break;
- default:
- GNUNET_assert (0);
- }
-}
-
-
-static void
-responder_callback (void *cls,
- const struct GNUNET_HashCode * key,
- enum GNUNET_SCALARPRODUCT_ResponseStatus status)
-{
- struct PeerData * peer = cls;
-
- peer->callback_num++;
-
- if (peer == &peer1)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer1 received callback!!!\n");
- }
- else if (peer == &peer2)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer2 received callback!!!\n");
- }
- else
- LOG (GNUNET_ERROR_TYPE_ERROR, "Requester callback received, but peer is
neither peer1 nor peer2!!!\n");
-
-
- if (status == GNUNET_SCALARPRODUCT_Status_Failure)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client received status
failure\n");
- ok = -1;
- }
- else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client received status invalid
response\n");
- ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_Timeout == status)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client received timeout
occured\n");
- ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client received service
disconnected!!\n");
- ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_Success == status)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Responder Client expected response
received!\n");
- ok = 1;
- }
- else
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "Responder Client status = %d!\n", (int)
status);
- ok = -1;
- }
-
- // TODO : Responder Session Complete. Shutdown Test Cleanly!!!
- if (peer->callback_num == 2)
- GNUNET_SCHEDULER_add_now (&do_shutdown, peer);
-}
-
-
-static void
-requester_callback (void *cls,
- const struct GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * peer,
- enum GNUNET_SCALARPRODUCT_ResponseStatus status,
- const struct GNUNET_SCALARPRODUCT_client_response *msg)
-{
- struct PeerData * peer_ = cls;
- uint32_t product_len;
-
- peer_->callback_num++;
-
- if (peer_ == &peer3)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer3 received callback!!!\n");
- }
- else if (peer_ == &peer4)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer4 received callback!!!\n");
- }
- else
- LOG (GNUNET_ERROR_TYPE_ERROR, "Requester callback received, but peer is
neither peer3 nor peer4!!!\n");
-
-
- if (status == GNUNET_SCALARPRODUCT_Status_Failure)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client received status
failure\n");
- ok = -1;
- }
- else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client received status invalid
response\n");
- ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_Timeout == status)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client timeout occured\n");
- ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client service
disconnected!!\n");
- ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_Success != status)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "Requester Client Status = %d\n", (int)
status);
- ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_Success == status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requester client received status
successful!\n");
- product_len = ntohl (msg->product_length);
-
- if (0 < product_len)
- {
- gcry_mpi_t result;
- gcry_error_t ret = 0;
- size_t read = 0;
-
- ret = gcry_mpi_scan (&result, GCRYMPI_FMT_USG, (void*) &(msg[1]),
product_len, &read);
-
- if (0 != ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not convert to mpi
to value!\n");
- }
- else
- {
- gcry_mpi_release (result);
- }
- ok = 1;
- }
- else
- {
- //currently not used, but if we get more info due to MESH we will
need this
- LOG (GNUNET_ERROR_TYPE_ERROR, "Error during computation of vector
product, return code: %d\n", product_len);
- ok = -1;
- }
- }
-
- if (peer_->callback_num == 2)
- GNUNET_SCHEDULER_add_now (&do_shutdown, peer_);
-}
-
-
-static struct GNUNET_SCALARPRODUCT_QueueEntry *
-requester_request (char * input_elements,
- char * input_mask,
- char * input_key,
- struct PeerData * peer,
- struct PeerData * to_peer)
-{
-
-
- unsigned int i;
- uint16_t element_count = 0;
- int32_t * elements = NULL;
- uint16_t mask_length = 0;
- unsigned char * mask = NULL;
- int32_t element;
- struct GNUNET_SCALARPRODUCT_QueueEntry *qe;
- struct GNUNET_HashCode key;
- int exit_loop;
- char * begin = input_elements;
- char * end;
-
- GNUNET_assert (peer->vh != NULL);
-
- GNUNET_CRYPTO_hash_from_string (input_key, &key);
-
- exit_loop = 0;
- /* Read input_elements, and put in elements array */
- do
- {
- unsigned int mcount = element_count;
- //ignore empty rows of ,,,,,,
- while (*begin == ',')
- begin++;
- // get the length of the current element and replace , with null
- for (end = begin; *end && *end != ','; end++);
-
- if (*end == '\0')
- exit_loop = 1;
-
-
- if (1 != sscanf (begin, "%" SCNd32, &element))
- {
- FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin);
- ok = -1;
- return NULL;
- }
-
- GNUNET_array_append (elements, mcount, element);
- element_count++;
-
- begin = ++end;
- }
- while (!exit_loop && element_count < max_mids);
- GNUNET_assert (elements != NULL);
- GNUNET_assert (element_count >= 1);
-
- /* Read input_mask and read in mask array */
- mask_length = element_count / 8 + (element_count % 8 ? 1 : 0);
- mask = GNUNET_malloc ((element_count / 8) + 2);
- GNUNET_assert (NULL != mask);
- if (NULL != input_mask)
- {
- begin = input_mask;
- unsigned short mask_count = 0;
- int exit_loop = 0;
-
- do
- {
- //ignore empty rows of ,,,,,,
- while (* begin == ',')
- begin++;
- // get the length of the current element and replace , with null
- // gnunet_ascii-armor uses base32, thus we can use , as separator!
- for (end = begin; *end && *end != ','; end++);
-
- if (*end == '\0')
- exit_loop = 1;
-
-
- if (1 != sscanf (begin, "%" SCNd32, &element))
- {
- FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"),
begin);
- ok = -1;
- return NULL;
- }
-
- GNUNET_assert (mask_count <= element_count);
-
- if (element)
- mask[mask_count / 8] = mask[mask_count / 8] | 1 << (mask_count %
8);
-
- mask_count++;
- begin = ++end;
- }
- while (!exit_loop);
- // +1 to see if we would have more data, which would indicate
malformed/superficial input
- GNUNET_assert (mask_count == element_count);
- }
- else
- {
- for (i = 0; i <= mask_length; i++)
- mask[i] = UCHAR_MAX; // all 1's
- }
-
- qe = GNUNET_SCALARPRODUCT_request (peer->vh,
- &key,
- &to_peer->our_id,
- element_count,
- mask_length,
- elements, mask,
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 60),
- &requester_callback,
- peer);
-
- if (qe == NULL)
- {
- LOG(GNUNET_ERROR_TYPE_WARNING, "Could not send request to scalarproduct
service! Exitting!");
- ok = -1;
- return NULL;
- }
-
- return qe;
-}
-
-
-/**
- * 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_SCALARPRODUCT_QueueEntry *
-responder_prepare_response (char * input_elements,
- char * input_mask,
- char * input_key,
- struct PeerData * peer)
-{
- GNUNET_assert (peer->vh != NULL);
-
- unsigned int i;
- uint16_t element_count = 0;
- int32_t * elements = NULL;
- unsigned short mask_length = 0;
- unsigned char * mask = NULL;
- int32_t element;
- struct GNUNET_SCALARPRODUCT_QueueEntry *qe;
- struct GNUNET_HashCode key;
- int exit_loop;
- char * begin;
- char * end;
-
- GNUNET_CRYPTO_hash_from_string (input_key, &key);
-
- /* Read input_elements, and put in elements array */
- exit_loop = 0;
- begin = input_elements;
- do
- {
- unsigned int mcount = element_count;
- //ignore empty rows of ,,,,,,
- while (*begin == ',')
- begin++;
- // get the length of the current element and replace , with null
- for (end = begin; *end && *end != ','; end++);
-
- if (*end == '\0')
- exit_loop = 1;
-
- if (1 != sscanf (begin, "%" SCNd32, &element))
- {
- FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin);
- ok = -1;
- return NULL;
- }
-
- GNUNET_array_append (elements, mcount, element);
- element_count++;
-
- begin = ++end;
- }
- while (!exit_loop && element_count < max_mids);
- GNUNET_assert (elements != NULL);
- GNUNET_assert (element_count >= 1);
-
- /* Read input_mask and read in mask array */
- mask_length = element_count / 8 + (element_count % 8 ? 1 : 0);
- mask = GNUNET_malloc ((element_count / 8) + 2);
- GNUNET_assert (NULL != mask);
- if (NULL != input_mask)
- {
- begin = input_mask;
- unsigned short mask_count = 0;
- int exit_loop = 0;
-
- do
- {
- //ignore empty rows of ,,,,,,
- while (* begin == ',')
- begin++;
- // get the length of the current element and replace , with null
- // gnunet_ascii-armor uses base32, thus we can use , as separator!
- for (end = begin; *end && *end != ','; end++);
-
- if (*end == '\0')
- exit_loop = 1;
-
- if (1 != sscanf (begin, "%" SCNd32, &element))
- {
- FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"),
begin);
- ok = -1;
- return NULL;
- }
-
- GNUNET_assert (mask_count <= element_count);
-
- if (element)
- mask[mask_count / 8] = mask[mask_count / 8] | 1 << (mask_count %
8);
-
- mask_count++;
- begin = ++end;
- }
- while (!exit_loop);
- // +1 to see if we would have more data, which would indicate
malformed/superficial input
- GNUNET_assert (mask_count == element_count);
- }
- else
- {
- for (i = 0; i <= mask_length; i++)
- mask[i] = UCHAR_MAX; // all 1's
- }
-
- qe = GNUNET_SCALARPRODUCT_prepare_response (peer->vh,
- &key,
- element_count,
- elements,
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 60),
- &responder_callback,
- peer);
-
- if (qe == NULL)
- {
- LOG(GNUNET_ERROR_TYPE_ERROR, "Could not send request to scalarproduct
service! Exitting!");
- ok = -1;
- return NULL;
- }
-
- return qe;
-}
-
-
-static void
-request_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext
- * tc)
-{
- struct PeerData * peer = cls;
-
- requester_request (peer->input_elements, peer->input_mask,
peer->input_keys[peer->request_num], peer, peer->peers[peer->request_num]);
- peer->request_num++;
- return;
-}
-
-
-static void
-prepare_response_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext
- * tc)
-{
- struct PeerData * peer = cls;
-
- responder_prepare_response (peer->input_elements, peer->input_mask,
peer->input_keys[peer->request_num], peer);
- peer->request_num++;
- return;
-}
-
-
-/**
- * Adapter function called to destroy a connection to
- * 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
-scalarproduct_da (void *cls, void *op_result)
-{
- struct PeerData* peer = (struct PeerData*) cls;
-
- GNUNET_SCALARPRODUCT_cancel (peer->vh);
- return;
-
- GNUNET_assert (0);
-}
-
-
-/**
- * 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
- * from GNUNET_TESTBED_service_connect()
- * @return service handle to return in 'op_result', NULL on error
- */
-static void *
-scalarproduct_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct PeerData *p = cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", (&peer1 ==
p) ? 1 : 2,
- GNUNET_i2s (&p->our_id));
-
- switch (setup_state)
- {
- case PEER1_SCALARPRODUCT_CONNECT:
- /* Connect peer 2 to scalarproduct service */
- {
- peer2.op = GNUNET_TESTBED_service_connect (&peer2, peer2.peer,
"scalarproduct",
- NULL, NULL,
scalarproduct_ca,
- scalarproduct_da, &peer2);
- setup_state = PEER2_SCALARPRODUCT_CONNECT;
- }
-
- peer1.vh = GNUNET_SCALARPRODUCT_connect (cfg);
- return peer1.vh;
-
- case PEER2_SCALARPRODUCT_CONNECT:
- /* Connect peer 3 to scalarproduct service */
- {
- peer3.op = GNUNET_TESTBED_service_connect (&peer3, peer3.peer,
"scalarproduct",
- NULL, NULL,
scalarproduct_ca,
- scalarproduct_da, &peer3);
- setup_state = PEER3_SCALARPRODUCT_CONNECT;
- }
-
- peer2.vh = GNUNET_SCALARPRODUCT_connect (cfg);
- return peer2.vh;
-
- case PEER3_SCALARPRODUCT_CONNECT:
- /* Connect peer 4 to scalarproduct service */
- {
- peer4.op = GNUNET_TESTBED_service_connect (&peer4, peer4.peer,
"scalarproduct",
- NULL, NULL,
scalarproduct_ca,
- scalarproduct_da, &peer4);
- setup_state = PEER4_SCALARPRODUCT_CONNECT;
- }
-
- peer3.vh = GNUNET_SCALARPRODUCT_connect (cfg);
- return peer3.vh;
-
- case PEER4_SCALARPRODUCT_CONNECT:
- peer4.vh = GNUNET_SCALARPRODUCT_connect (cfg);
-
- /* Schedule the tasks to issue prepare_response calls from peer1 and
peer2
- * for peer3 and peer4.
- */
- GNUNET_SCHEDULER_add_now (&prepare_response_task, &peer1);
- GNUNET_SCHEDULER_add_now (&prepare_response_task, &peer1);
- GNUNET_SCHEDULER_add_now (&prepare_response_task, &peer2);
- GNUNET_SCHEDULER_add_now (&prepare_response_task, &peer2);
-
- /*
- * Schedule the tasks to issue requests calls from peer3 and peer4
- * to peer1 and peer2
- */
- GNUNET_SCHEDULER_add_now (&request_task, &peer3);
- GNUNET_SCHEDULER_add_now (&request_task, &peer3);
- GNUNET_SCHEDULER_add_now (&request_task, &peer4);
- GNUNET_SCHEDULER_add_now (&request_task, &peer4);
-
- return peer2.vh;
- default:
- GNUNET_assert (0);
- }
-}
-
-
-/**
- * Callback to be called when the requested peer information is available
- *
- * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
- * @param op the operation this callback corresponds to
- * @param pinfo the result; will be NULL if the operation has failed
- * @param emsg error message if the operation has failed; will be NULL if the
- * operation is successfull
- */
-static void
-peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_,
- const struct GNUNET_TESTBED_PeerInformation *pinfo,
- const char *emsg)
-{
- GNUNET_assert (NULL == emsg);
- GNUNET_assert (op == op_);
- switch (setup_state)
- {
- case PEER1_GET_IDENTITY:
- {
- memcpy (&peer1.our_id, pinfo->result.id,
- sizeof (struct GNUNET_PeerIdentity));
- GNUNET_TESTBED_operation_done (op);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 id: %s\n", GNUNET_i2s_full
- (&peer1.our_id));
-
- /* Request for peer id of peer 2*/
- op = GNUNET_TESTBED_peer_get_information (peer2.peer,
- GNUNET_TESTBED_PIT_IDENTITY,
- &peerinfo_cb, NULL);
- setup_state = PEER2_GET_IDENTITY;
- }
- break;
- case PEER2_GET_IDENTITY:
- {
- memcpy (&peer2.our_id, pinfo->result.id,
- sizeof (struct GNUNET_PeerIdentity));
- GNUNET_TESTBED_operation_done (op);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n", GNUNET_i2s_full
- (&peer2.our_id));
-
- /* Request for peer id of peer 3*/
- op = GNUNET_TESTBED_peer_get_information (peer3.peer,
- GNUNET_TESTBED_PIT_IDENTITY,
- &peerinfo_cb, NULL);
- setup_state = PEER3_GET_IDENTITY;
- }
- break;
- case PEER3_GET_IDENTITY:
- {
- memcpy (&peer3.our_id, pinfo->result.id,
- sizeof (struct GNUNET_PeerIdentity));
- GNUNET_TESTBED_operation_done (op);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 3 id: %s\n", GNUNET_i2s_full
- (&peer3.our_id));
-
- /* Request for peer id of peer 4*/
- op = GNUNET_TESTBED_peer_get_information (peer4.peer,
- GNUNET_TESTBED_PIT_IDENTITY,
- &peerinfo_cb, NULL);
- setup_state = PEER4_GET_IDENTITY;
- }
- break;
- case PEER4_GET_IDENTITY:
- {
- memcpy (&peer4.our_id, pinfo->result.id,
- sizeof (struct GNUNET_PeerIdentity));
- GNUNET_TESTBED_operation_done (op);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n", GNUNET_i2s_full
- (&peer2.our_id));
-
- /* 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:
- GNUNET_assert (0);
- }
-}
-
-
-/**
- * Signature of a main function for a testcase.
- *
- * @param cls closure
- * @param num_peers number of peers in 'peers'
- * @param peers handle to peers run in the testbed
- */
-static void
-test_master (void *cls, unsigned int num_peers,
- struct GNUNET_TESTBED_Peer **peers)
-{
- GNUNET_assert (NULL != peers);
- GNUNET_assert (NULL != peers[0]);
- GNUNET_assert (NULL != peers[1]);
- GNUNET_assert (NULL != peers[2]);
- GNUNET_assert (NULL != peers[3]);
- peer1.peer = peers[0];
- peer1.input_elements = input_elements_peer1;
- peer1.input_mask = input_mask_peer1;
- peer1.request_num = 0;
- peer1.callback_num = 0;
- peer1.input_keys[0] = input_key_p1_p3;
- peer1.input_keys[1] = input_key_p1_p4;
-
- peer2.peer = peers[1];
- peer2.input_elements = input_elements_peer2;
- peer2.input_mask = input_mask_peer2;
- peer2.request_num = 0;
- peer2.callback_num = 0;
- peer2.input_keys[0] = input_key_p2_p3;
- peer2.input_keys[1] = input_key_p2_p4;
-
- peer3.peer = peers[2];
- peer3.input_elements = input_elements_peer3;
- peer3.input_mask = input_mask_peer3;
- peer3.request_num = 0;
- peer3.callback_num = 0;
- peer3.input_keys[0] = input_key_p1_p3;
- peer3.input_keys[1] = input_key_p2_p3;
- peer3.peers[0] = &peer1;
- peer3.peers[1] = &peer2;
-
-
- peer4.peer = peers[3];
- peer4.input_elements = input_elements_peer4;
- peer4.input_mask = input_mask_peer4;
- peer4.request_num = 0;
- peer4.callback_num = 0;
- peer4.input_keys[0] = input_key_p1_p4;
- peer4.input_keys[1] = input_key_p2_p4;
- peer4.peers[0] = &peer1;
- peer4.peers[1] = &peer2;
-
- /* Get the peer identity and configuration of peer 1 */
- op = GNUNET_TESTBED_peer_get_information (peer1.peer,
- GNUNET_TESTBED_PIT_IDENTITY,
- &peerinfo_cb, NULL);
- setup_state = PEER1_GET_IDENTITY;
- abort_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 120),
&do_abort,
- NULL);
-}
-
-
-/**
- * Main function
- */
-int
-main (int argc, char **argv)
-{
- uint64_t event_mask;
-
- ok = GNUNET_NO;
- event_mask = 0;
- event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
- max_mids = (GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct
GNUNET_MessageHeader))
- / sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1;
- (void) GNUNET_TESTBED_test_run ("test_scalarproduct_api_4peers",
- "test_scalarproduct_api_data.conf",
- NUM_PEERS, event_mask, &controller_event_cb,
- NULL,
- &test_master, NULL);
- if (GNUNET_SYSERR == ok)
- return 1;
- return 0;
-}
Deleted: gnunet/src/scalarproduct/test_scalarproduct_api_data.conf
===================================================================
--- gnunet/src/scalarproduct/test_scalarproduct_api_data.conf 2013-09-17
14:30:46 UTC (rev 29349)
+++ gnunet/src/scalarproduct/test_scalarproduct_api_data.conf 2013-09-17
14:41:39 UTC (rev 29350)
@@ -1,96 +0,0 @@
-[arm]
-DEFAULTSERVICES = core transport vectorproduct mesh testbed
-PORT = 12366
-
-[core]
-PORT = 12092
-
-[vectorproduct]
-#AUTOSTART = YES
-BINARY = gnunet-service-vectorproduct
-UNIXPATH = /tmp/gnunet-service-vectorproduct.sock
-HOME = $SERVICEHOME
-HOSTNAME = localhost
-PORT = 2087
-
-[testbed]
-OVERLAY_TOPOLOGY = CLIQUE
-
-[lockmanager]
-AUTOSTART = NO
-ACCEPT_FROM = 127.0.0.1;
-HOSTNAME = localhost
-PORT = 12101
-
-[statistics]
-AUTOSTART = YES
-ACCEPT_FROM = 127.0.0.1;
-PORT = 12102
-
-[fs]
-AUTOSTART = NO
-
-[resolver]
-AUTOSTART = NO
-
-[mesh]
-# AUTOSTART = YES
-ACCEPT_FROM = 127.0.0.1;
-HOSTNAME = localhost
-PORT = 10700
-# PREFIX = valgrind --leak-check=full
-# PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args
-
-[dht]
-AUTOSTART = YES
-ACCEPT_FROM6 = ::1;
-ACCEPT_FROM = 127.0.0.1;
-HOSTNAME = localhost
-PORT = 12100
-
-[block]
-plugins = dht test
-
-[dhtcache]
-QUOTA = 1 MB
-DATABASE = sqlite
-
-[transport]
-PLUGINS = tcp
-ACCEPT_FROM6 = ::1;
-ACCEPT_FROM = 127.0.0.1;
-NEIGHBOUR_LIMIT = 50
-PORT = 12365
-
-[ats]
-WAN_QUOTA_OUT = 3932160
-WAN_QUOTA_IN = 3932160
-
-[transport-tcp]
-TIMEOUT = 300 s
-PORT = 12368
-
-[TESTING]
-WEAKRANDOM = YES
-
-[gnunetd]
-HOSTKEY = $SERVICEHOME/.hostkey
-
-[PATHS]
-SERVICEHOME = /tmp/test-vectorproduct/
-
-[dns]
-AUTOSTART = NO
-
-[nse]
-AUTOSTART = NO
-
-[vpn]
-AUTOSTART = NO
-
-[nat]
-RETURN_LOCAL_ADDRESSES = YES
-
-[consensus]
-AUTOSTART = NO
-
Deleted: gnunet/src/scalarproduct/test_scalarproduct_api_regression.c
===================================================================
--- gnunet/src/scalarproduct/test_scalarproduct_api_regression.c
2013-09-17 14:30:46 UTC (rev 29349)
+++ gnunet/src/scalarproduct/test_scalarproduct_api_regression.c
2013-09-17 14:41:39 UTC (rev 29350)
@@ -1,851 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2013 Christian Grothoff (and other contributing authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file scalarproduct/test_scalarproduct_api_regression.c
- * @brief VectorProduct API regression test
- * @author Gaurav Kukreja
- * @author Christian Fuchs
- */
-
-/**
- * AIM of the regression test
- *
- * This test tries to check whether the service can handle abrupt client
disconnect.
- *
- * 1. We create a responder peer, and ask the service to prepare_response.
After this,
- * we disconnect responder peer from service.
- *
- * 2. Then we create a requester peer, and ask service to request another
peer. We
- * should check that the service on responder peer is still active and
receives
- * request from the requester. We then disconnect requester peer from
service. Both
- * the requester and responder service should handle this cleanly.
- */
-
-#include <string.h>
-
-#include <inttypes.h>
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testbed_service.h"
-#include "gnunet_common.h"
-#include "gnunet_scalarproduct_service.h"
-#include "gnunet_protocols.h"
-
-#define LOG(kind,...) GNUNET_log_from (kind,
"test-scalarproduct-api-regression",__VA_ARGS__)
-#define NUM_PEERS 2
-
-/**
- * Structure for holding peer's sockets and IO Handles
- */
-struct PeerData
-{
- /**
- * Handle to testbed peer
- */
- struct GNUNET_TESTBED_Peer *peer;
-
- /**
- * The service connect operation to stream
- */
- struct GNUNET_TESTBED_Operation *op;
-
- /**
- * Our Peer id
- */
- struct GNUNET_PeerIdentity our_id;
-
- /**
- * Pointer to Vector Product Handle
- */
- struct GNUNET_SCALARPRODUCT_Handle *vh;
-};
-
-/**
- * Different states in test setup
- */
-enum SetupState
-{
- /**
- * Get the identity of peer 1
- */
- PEER1_GET_IDENTITY,
-
- /**
- * Get the identity of peer 2
- */
- PEER2_GET_IDENTITY,
-
- /**
- * Connect to stream service of peer 1
- */
- PEER1_SCALARPRODUCT_CONNECT,
-
- /**
- * Connect to stream service of peer 2
- */
- PEER2_SCALARPRODUCT_CONNECT
-
-};
-
-/******************************************************************************
- *** Global Variables *****************************
-
******************************************************************************/
-
-/**
- * Maximum allowed message-ids we can check in one go (with one GNUNET_message)
- */
-static unsigned int max_mids;
-
-/**
- * Session Key used by both the test peers
- */
-char input_key[103] =
"helloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhe";
-
-/**
- * Input elements for peer1
- */
-//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";
-char input_elements_peer1[] = "11,11,11";
-
-/**
- * Input Mask for peer 1
- */
-//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";
-char input_mask_peer1[] = "1,1,1";
-
-/**
- * the array of converted message IDs to send to our service
- */
-static int32_t * elements_peer1 = NULL;
-
-/**
- * Input elements for peer2
- */
-//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";
-char input_elements_peer2[] = "11,11,11";
-/**
- * Input Mask for peer 2
- */
-//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";
-char input_mask_peer2[] = "1,1,1";
-/**
- * the array of converted message IDs to send to our service
- */
-static int32_t * elements_peer2 = NULL;
-
-/**
- * the array of converted message IDs to send to our service
- */
-static unsigned char * mask_peer2 = NULL;
-
-/**
- * Data context for peer 1
- */
-static struct PeerData peer1;
-
-/**
- * Data context for peer 2
- */
-static struct PeerData peer2;
-
-/**
- * Various states during test setup
- */
-static enum SetupState setup_state;
-
-/**
- * Testbed operation handle
- */
-static struct GNUNET_TESTBED_Operation *op;
-
-/**
- * Return value of the test.
- */
-static int ok;
-
-/**
- * Abort Task for timeout
- */
-static GNUNET_SCHEDULER_TaskIdentifier abort_task;
-/******************************************************************************
- *** Static Functions *****************************
-
******************************************************************************/
-
-/**
- * Helper function to shutdown a test peer
- *
- * @param cls void* to struct PeerData of the peer to be disconnected
- * @param tc Task Context
- */
-static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-
-/**
- * Helper function to connect a test peer
- *
- * @param cls void* to struct PeerData of the peer to be connected
- * @param tc Task Context
- */
-static void
-connect_peer (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc);
-
-
-/**
- * Close sockets and stop testing deamons nicely
- */
-static void
-do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-
- if (peer1.op != NULL)
- do_shutdown (&peer1, NULL);
-
- if (peer2.op != NULL)
- do_shutdown (&peer2, NULL);
-
- if (GNUNET_SCHEDULER_NO_TASK != abort_task)
- GNUNET_SCHEDULER_cancel (abort_task);
-
- GNUNET_SCHEDULER_shutdown (); /* For shutting down testbed */
-}
-
-
-/**
- * Helper function to shutdown a test peer
- *
- * @param cls void* to struct PeerData of the peer to be disconnected
- * @param tc Task Context
- */
-static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- static int shutdown;
- shutdown++;
- struct PeerData* peer = (struct PeerData*) cls;
-
- if (peer == &peer1)
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting Peer1\n\n");
- else if (peer == &peer2)
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting Peer2\n\n");
-
- // peer->op contains handle to the TESTBED_connect_service operation
- // calling operation done, leads to call to scalarproduct_da
- if (peer->op != NULL)
- {
- GNUNET_TESTBED_operation_done (peer->op);
- peer->op = NULL;
- }
-
- if (shutdown >= 2)
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS, 10), &do_close, NULL);
-}
-
-
-/**
- * Something went wrong and timed out. Kill everything and set error flag
- */
-static void
-do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: ABORT due to Timeout\n");
- ok = GNUNET_SYSERR;
- abort_task = 0;
- do_close (cls, tc);
-}
-
-
-/**
- * Controller event callback
- *
- * @param cls NULL
- * @param event the controller event
- */
-static void
-controller_event_cb (void *cls,
- const struct GNUNET_TESTBED_EventInformation *event)
-{
- switch (event->type)
- {
- case GNUNET_TESTBED_ET_OPERATION_FINISHED:
- switch (setup_state)
- {
- case PEER1_SCALARPRODUCT_CONNECT:
- case PEER2_SCALARPRODUCT_CONNECT:
- GNUNET_assert (NULL == event->details.operation_finished.emsg);
- break;
- default:
- GNUNET_assert (0);
- }
- break;
- default:
- GNUNET_assert (0);
- }
-}
-
-
-/**
- * Callback function called for the responder peer i.e. peer1
- *
- * @param cls
- * @param key Session key
- * @param status Status of the message
- */
-static void
-responder_callback (void *cls,
- const struct GNUNET_HashCode * key,
- enum GNUNET_SCALARPRODUCT_ResponseStatus status)
-{
- if (status == GNUNET_SCALARPRODUCT_Status_Failure)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received status
failure\n");
- ok = -1;
- }
- else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received status
invalid response\n");
- ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_Timeout == status)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received timeout
occured\n");
- ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received service
disconnected!!\n");
- ok = 1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_Success == status)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Responder Client expected response
received!\n");
- ok = -1;
- }
- else
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client status = %d!\n", (int)
status);
- ok = -1;
- }
-
- // Not shutting down this time, only for this regression test. We have
shutdown explicitly earlier.
- // Shutting down again is causing problems.
-
- // if(peer1.vh != NULL)
- // {
- // GNUNET_SCHEDULER_add_now(&do_shutdown, &peer1);
- // }
- return;
-}
-
-
-/**
- * Callback function called for the requester peer i.e. peer2
- *
- * @param cls
- * @param key Session key
- * @param status Status of the message
- */
-static void
-requester_callback (void *cls,
- const struct GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * peer,
- enum GNUNET_SCALARPRODUCT_ResponseStatus status,
- const struct GNUNET_SCALARPRODUCT_client_response *msg)
-{
- uint32_t product_len;
-
- if (status == GNUNET_SCALARPRODUCT_Status_Failure)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client received status
failure\n");
- ok = -1;
- }
- else if (status == GNUNET_SCALARPRODUCT_Status_InvalidResponse)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client received status
invalid response\n");
- ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_Timeout == status)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client timeout occured\n");
- ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client service
disconnected!!\n");
- ok = 1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_Success != status)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Requester Client Status = %d\n", (int)
status);
- ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_Success == status)
- {
- product_len = ntohl (msg->product_length);
-
- if (0 < product_len)
- {
- gcry_mpi_t result;
- gcry_error_t ret = 0;
- size_t read = 0;
-
- ret = gcry_mpi_scan (&result, GCRYMPI_FMT_USG, (void *) &msg[1],
product_len, &read);
-
- if (0 != ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not convert to mpi
to value!\n");
- }
- else
- {
- gcry_mpi_dump (result);
- gcry_mpi_release (result);
- }
- ok = -1;
- }
- else
- { //currently not used, but if we get more info due to MESH we will
need this
- LOG (GNUNET_ERROR_TYPE_WARNING, "Error during computation of vector
product, return code: %d\n", product_len);
- ok = -1;
- }
- }
-
- // Not shutting down this time, only for this regression test. We have
shutdown explicitly earlier.
- // Shutting down again is causing problems.
-
- // if(peer2.vh != NULL)
- // {
- // GNUNET_SCHEDULER_add_now(&do_shutdown, &peer2);
- // }
- return;
-}
-
-
-static void
-requester_request (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
-{
- GNUNET_assert (peer2.vh != NULL);
-
- unsigned int i;
- uint16_t element_count = 0;
- uint16_t mask_length = 0;
- char * begin = input_elements_peer2;
- char * end;
- int32_t element;
- struct GNUNET_SCALARPRODUCT_QueueEntry *qe;
- struct GNUNET_HashCode key;
- int exit_loop = 0;
-
- GNUNET_CRYPTO_hash (input_key, strlen (input_key), &key);
-
- /* Read input_elements_peer2, and put in elements_peer2 array */
- exit_loop = 0;
- do
- {
- unsigned int mcount = element_count;
- //ignore empty rows of ,,,,,,
- while (*begin == ',')
- begin++;
- // get the length of the current element and replace , with null
- for (end = begin; *end && *end != ','; end++);
-
- if (*end == '\0')
- exit_loop = 1;
-
- if (1 != sscanf (begin, "%" SCNd32, &element))
- {
- FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin);
- ok = -1;
- return;
- }
-
- GNUNET_array_append (elements_peer2, mcount, element);
- element_count++;
-
- begin = ++end;
- }
- while (!exit_loop && element_count < max_mids);
- GNUNET_assert (elements_peer2 != NULL);
- GNUNET_assert (element_count >= 1);
-
- /* Read input_mask_peer2 and read in mask_peer2 array */
- mask_length = element_count / 8 + (element_count % 8 ? 1 : 0);
- mask_peer2 = GNUNET_malloc ((element_count / 8) + 2);
- GNUNET_assert (NULL != mask_peer2);
- if (NULL != input_mask_peer2)
- {
- begin = input_mask_peer2;
- unsigned short mask_count = 0;
- exit_loop = 0;
-
- do
- {
- //ignore empty rows of ,,,,,,
- while (* begin == ',')
- begin++;
- // get the length of the current element and replace , with null
- // gnunet_ascii-armor uses base32, thus we can use , as separator!
- for (end = begin; *end && *end != ','; end++);
-
- if (*end == '\0')
- exit_loop = 1;
-
- if (1 != sscanf (begin, "%" SCNd32, &element))
- {
- FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"),
begin);
- ok = -1;
- return;
- }
-
- GNUNET_assert (mask_count <= element_count);
-
- if (element)
- mask_peer2[mask_count / 8] = mask_peer2[mask_count / 8] | 1 <<
(mask_count % 8);
-
- mask_count++;
- begin = ++end;
- }
- while (!exit_loop);
- // +1 to see if we would have more data, which would indicate
malformed/superficial input
- GNUNET_assert (mask_count == element_count);
- }
- else
- {
- for (i = 0; i <= mask_length; i++)
- mask_peer2[i] = UCHAR_MAX; // all 1's
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Responder peer key %s\n",
&peer1.our_id);
-
- qe = GNUNET_SCALARPRODUCT_request (peer2.vh,
- &key,
- &peer1.our_id,
- element_count,
- mask_length,
- elements_peer2, mask_peer2,
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 10),
- &requester_callback,
- NULL);
-
- if (qe == NULL)
- {
- FPRINTF (stderr, "%s", _ ("Could not send request to scalarproduct
service! Exitting!"));
- ok = -1;
- return;
- }
-
- /**
- * For regression, we shutdown the initiator peer, peer2, one second after
- * issuing a request. Hopefully, peer1 notices that the tunnel has been
- * been destroyed, and will shutdown cleanly.
- */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown,
&peer2);
-
- return;
-}
-
-
-/**
- * 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 void
-responder_prepare_response (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
-{
- GNUNET_assert (peer1.vh != NULL);
-
- uint16_t element_count = 0;
- char * begin = input_elements_peer1;
- char * end;
- int32_t element;
-
- struct GNUNET_SCALARPRODUCT_QueueEntry *qe;
-
- struct GNUNET_HashCode key;
- GNUNET_CRYPTO_hash (input_key, strlen (input_key), &key);
-
- int exit_loop = 0;
- /* Read input_elements_peer1, and put in elements_peer1 array */
- do
- {
- unsigned int mcount = element_count;
- //ignore empty rows of ,,,,,,
- while (*begin == ',')
- begin++;
- // get the length of the current element and replace , with null
- for (end = begin; *end && *end != ','; end++);
-
- if (*end == '\0')
- exit_loop = 1;
-
- if (1 != sscanf (begin, "%" SCNd32, &element))
- {
- FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin);
- ok = -1;
- return;
- }
-
- GNUNET_array_append (elements_peer1, mcount, element);
- element_count++;
-
- begin = ++end;
- }
- while (!exit_loop && element_count < max_mids);
-
- GNUNET_assert (elements_peer1 != NULL);
- GNUNET_assert (element_count >= 1);
-
- qe = GNUNET_SCALARPRODUCT_prepare_response (peer1.vh,
- &key,
- element_count,
- elements_peer1,
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 10),
- &responder_callback,
- NULL);
-
- if (qe == NULL)
- {
- FPRINTF (stderr, "%s", _ ("Could not send request to scalarproduct
service! Exitting!"));
- ok = -1;
- return;
- }
-
- // connect the second peer
- setup_state = PEER2_SCALARPRODUCT_CONNECT;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 1), &connect_peer, &peer2);
-
- // while the service is waiting for a matching request, disconnect the test
client
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown,
&peer1);
-
- return;
-}
-
-
-/**
- * Adapter function called to destroy a connection to
- * 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
-scalarproduct_da (void *cls, void *op_result)
-{
- struct PeerData* peer = (struct PeerData*) cls;
-
- GNUNET_SCALARPRODUCT_cancel (peer->vh);
- peer->vh = NULL;
- return;
-}
-
-
-/**
- * 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
- * from GNUNET_TESTBED_service_connect()
- * @return service handle to return in 'op_result', NULL on error
- */
-static void *
-scalarproduct_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct PeerData *p = cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", (&peer1 ==
p) ? 1 : 2,
- GNUNET_i2s (&p->our_id));
-
- switch (setup_state)
- {
- case PEER1_SCALARPRODUCT_CONNECT:
- peer1.vh = GNUNET_SCALARPRODUCT_connect (cfg);
-
- if (peer1.vh != NULL)
- {
- /* prepare_response from peer1 */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
&responder_prepare_response, NULL);
- }
- else
- {
- ok = -1;
- return NULL;
- }
-
- return peer1.vh;
-
- case PEER2_SCALARPRODUCT_CONNECT:
- /* Actually connect peer 2 to scalarproduct service */
- peer2.vh = GNUNET_SCALARPRODUCT_connect (cfg);
-
- if (peer2.vh != NULL)
- {
- /* initiate request from peer2 */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
&requester_request, NULL);
- }
- else
- {
- ok = -1;
- return NULL;
- }
-
- return peer2.vh;
- default:
- GNUNET_assert (0);
- }
-}
-
-
-/**
- * Helper function to connect a test peer
- *
- * @param cls void* to struct PeerData of the peer to be connected
- * @param tc Task Context
- */
-static void
-connect_peer (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
-{
- struct PeerData *peer = cls;
-
- peer->op = GNUNET_TESTBED_service_connect (peer, peer->peer, "scalarproduct",
- NULL, NULL, scalarproduct_ca,
- scalarproduct_da, peer);
-
-}
-
-
-/**
- * Callback to be called when the requested peer information is available
- *
- * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
- * @param op the operation this callback corresponds to
- * @param pinfo the result; will be NULL if the operation has failed
- * @param emsg error message if the operation has failed; will be NULL if the
- * operation is successfull
- */
-static void
-peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_,
- const struct GNUNET_TESTBED_PeerInformation *pinfo,
- const char *emsg)
-{
- GNUNET_assert (NULL == emsg);
- GNUNET_assert (op == op_);
-
- switch (setup_state)
- {
- case PEER1_GET_IDENTITY:
- {
- memcpy (&peer1.our_id, pinfo->result.id,
- sizeof (struct GNUNET_PeerIdentity));
- GNUNET_TESTBED_operation_done (op);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 id: %s\n", GNUNET_i2s_full
- (&peer1.our_id));
-
- /* Request for peer id of peer 2*/
- setup_state = PEER2_GET_IDENTITY;
- op = GNUNET_TESTBED_peer_get_information (peer2.peer,
- GNUNET_TESTBED_PIT_IDENTITY,
- &peerinfo_cb, NULL);
- }
- break;
- case PEER2_GET_IDENTITY:
- {
- memcpy (&peer2.our_id, pinfo->result.id,
- sizeof (struct GNUNET_PeerIdentity));
- GNUNET_TESTBED_operation_done (op);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n", GNUNET_i2s_full
- (&peer2.our_id));
-
- /* Connect peer 1 to scalarproduct service */
- setup_state = PEER1_SCALARPRODUCT_CONNECT;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
&connect_peer, &peer1);
- }
- break;
- default:
- GNUNET_assert (0);
- }
-}
-
-
-/**
- * Signature of a main function for a testcase.
- *
- * @param cls closure
- * @param num_peers number of peers in 'peers'
- * @param peers handle to peers run in the testbed
- */
-static void
-test_master (void *cls, unsigned int num_peers,
- struct GNUNET_TESTBED_Peer **peers)
-{
- GNUNET_assert (NULL != peers);
- GNUNET_assert (NULL != peers[0]);
- GNUNET_assert (NULL != peers[1]);
- peer1.peer = peers[0];
- peer2.peer = peers[1];
-
- /* Get the peer identity and configuration of peer 1 */
- setup_state = PEER1_GET_IDENTITY;
- op = GNUNET_TESTBED_peer_get_information (peer1.peer,
- GNUNET_TESTBED_PIT_IDENTITY,
- &peerinfo_cb, NULL);
-
- abort_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 20),
&do_abort,
- NULL);
-}
-
-
-/**
- * Main function
- */
-int
-main (int argc, char **argv)
-{
- uint64_t event_mask;
-
- ok = GNUNET_NO;
- event_mask = 0;
- event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
- max_mids = (GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct
GNUNET_MessageHeader))
- / sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1;
-
- (void) GNUNET_TESTBED_test_run ("test_scalarproduct_api_regression",
- "test_scalarproduct_api_data.conf",
- NUM_PEERS, event_mask, &controller_event_cb,
- NULL,
- &test_master, NULL);
-
- if (GNUNET_SYSERR == ok)
- return 1;
- return 0;
-}
-
-
Deleted: gnunet/src/scalarproduct/test_scalarproduct_api_regression2.c
===================================================================
--- gnunet/src/scalarproduct/test_scalarproduct_api_regression2.c
2013-09-17 14:30:46 UTC (rev 29349)
+++ gnunet/src/scalarproduct/test_scalarproduct_api_regression2.c
2013-09-17 14:41:39 UTC (rev 29350)
@@ -1,931 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2013 Christian Grothoff (and other contributing authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file scalarproduct/test_scalarproduct_api_regression2.c
- * @brief Regression test, destroys requester service before receiving response
- * responder service
- * @author Gaurav Kukreja
- * @author Christian Fuchs
- */
-
-#include <string.h>
-
-#include <inttypes.h>
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testbed_service.h"
-#include "gnunet_common.h"
-#include "gnunet_scalarproduct_service.h"
-#include "gnunet_protocols.h"
-
-#define LOG(kind,...) GNUNET_log_from (kind,
"test-scalarproduct-api-regression2",__VA_ARGS__)
-#define NUM_PEERS 2
-
-/**
- * Structure for holding peer's sockets and IO Handles
- */
-struct PeerData
-{
- /**
- * Handle to testbed peer
- */
- struct GNUNET_TESTBED_Peer *peer;
-
- /**
- * The service connect operation to stream
- */
- struct GNUNET_TESTBED_Operation *op;
-
- /**
- * Our Peer id
- */
- struct GNUNET_PeerIdentity our_id;
-
- /**
- * Pointer to Vector Product Handle
- */
- struct GNUNET_SCALARPRODUCT_Handle *vh;
-};
-
-/**
- * Different states in test setup
- */
-enum SetupState
-{
- /**
- * Get the identity of peer 1
- */
- PEER1_GET_IDENTITY,
-
- /**
- * Get the identity of peer 2
- */
- PEER2_GET_IDENTITY,
-
- /**
- * Connect to stream service of peer 1
- */
- PEER1_SCALARPRODUCT_CONNECT,
-
- /**
- * Connect to stream service of peer 2
- */
- PEER2_SCALARPRODUCT_CONNECT
-
-};
-
-/******************************************************************************
- *** Global Variables *****************************
-
******************************************************************************/
-
-/**
- * Maximum allowed message-ids we can check in one go (with one GNUNET_message)
- */
-static unsigned int max_mids;
-
-/**
- * Session Key used by both the test peers
- */
-char input_key[103] =
"helloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhe";
-
-/**
- * Input elements for peer1
- */
-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";
-//char input_elements_peer1[] = "11,11,11";
-
-/**
- * Input Mask for peer 1
- */
-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";
-//char input_mask_peer1[] = "1,1,1";
-
-/**
- * the array of converted message IDs to send to our service
- */
-static int32_t * elements_peer1 = NULL;
-
-/**
- * the array of converted message IDs to send to our service
- */
-static unsigned char * mask_peer1 = NULL;
-
-/**
- * Number of elements
- */
-uint16_t element_count_peer1 = 0;
-
-/**
- * Input elements for peer2
- */
-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";
-//char input_elements_peer2[] = "11,11,11";
-
-/**
- * Input Mask for peer 2
- */
-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";
-//char input_mask_peer2[] = "1,1,1";
-
-/**
- * the array of converted message IDs to send to our service
- */
-static int32_t * elements_peer2 = NULL;
-
-/**
- * the array of converted message IDs to send to our service
- */
-static unsigned char * mask_peer2 = NULL;
-
-/**
- * Number of elements
- */
-uint16_t element_count_peer2 = 0;
-
-/**
- * Data context for peer 1
- */
-static struct PeerData peer1;
-
-/**
- * Data context for peer 2
- */
-static struct PeerData peer2;
-
-/**
- * Various states during test setup
- */
-static enum SetupState setup_state;
-
-/**
- * Testbed operation handle
- */
-static struct GNUNET_TESTBED_Operation *op;
-
-static int ok;
-
-static int responder_ok;
-
-static int requester_ok;
-
-static GNUNET_SCHEDULER_TaskIdentifier abort_task;
-/******************************************************************************
- *** Static Functions *****************************
-
******************************************************************************/
-
-static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-
-/**
- * Close sockets and stop testing deamons nicely
- */
-static void
-do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- static int closed;
-
- if (peer1.op != NULL)
- {
- do_shutdown (&peer1, NULL);
- }
-
- if (peer2.op != NULL)
- {
- do_shutdown (&peer2, NULL);
- }
-
- if (GNUNET_SCHEDULER_NO_TASK != abort_task)
- {
- GNUNET_SCHEDULER_cancel (abort_task);
- abort_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_shutdown (); /* For shutting down testbed */
- }
-
- if (!closed)
- {
- closed++;
- GNUNET_SCHEDULER_shutdown (); /* For shutting down testbed */
- }
-}
-
-/**
- * Shutdown a peer
- *
- * @param cls closure is a pointer to the struct PeerData of the peer to be
disconnected
- * @param tc Task Context
- */
-static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- static int shutdown;
- shutdown++;
- struct PeerData* peer = (struct PeerData*) cls;
-
- // peer->op contains handle to the TESTBED_connect_service operation
- // calling operation done, leads to call to scalarproduct_da
- if (peer->op != NULL)
- {
- if (peer == &peer1)
- LOG (GNUNET_ERROR_TYPE_INFO, "Disconnecting Peer1\n\n");
- else if (peer == &peer2)
- LOG (GNUNET_ERROR_TYPE_INFO, "Disconnecting Peer2\n\n");
-
- GNUNET_TESTBED_operation_done (peer->op);
- peer->op = NULL;
- }
-
- if (peer1.op == NULL && peer2.op == NULL)
- GNUNET_SCHEDULER_add_now (&do_close, NULL);
-}
-
-
-/**
- * Something went wrong and timed out. Kill everything and set error flag
- */
-static void
-do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: ABORT due to Timeout\n");
- ok = GNUNET_SYSERR;
- abort_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&do_shutdown, &peer1);
- GNUNET_SCHEDULER_add_now (&do_shutdown, &peer2);
-}
-
-
-/**
- * Controller event callback
- *
- * @param cls NULL
- * @param event the controller event
- */
-static void
-controller_event_cb (void *cls,
- const struct GNUNET_TESTBED_EventInformation *event)
-{
- switch (event->type)
- {
- case GNUNET_TESTBED_ET_OPERATION_FINISHED:
- switch (setup_state)
- {
- case PEER1_SCALARPRODUCT_CONNECT:
- case PEER2_SCALARPRODUCT_CONNECT:
- GNUNET_assert (NULL == event->details.operation_finished.emsg);
- break;
- default:
- GNUNET_assert (0);
- }
- break;
- default:
- GNUNET_assert (0);
- }
-}
-
-
-static void
-responder_callback (void *cls,
- const struct GNUNET_HashCode * key,
- enum GNUNET_SCALARPRODUCT_ResponseStatus status)
-{
- if (status == GNUNET_SCALARPRODUCT_Status_Failure)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received status
failure\n");
- responder_ok = -1;
- }
- 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_SCALARPRODUCT_Status_Timeout == status)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received timeout
occured\n");
- // In this regression test, requester is supposed to fail due to timeout
- // therefore responder_ok is set to 1, to make regression test pass
- responder_ok = 1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client received service
disconnected!!\n");
- responder_ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_Success == status)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Responder Client expected response
received!\n");
- responder_ok = 1;
- }
- else
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Responder Client status = %d!\n", (int)
status);
- responder_ok = -1;
- }
- // TODO : Responder Session Complete. Shutdown Test Cleanly!!!
- //do_shutdown(&peer1, NULL);
- GNUNET_SCHEDULER_add_now (&do_shutdown, &peer1);
- return;
-}
-
-
-static void
-requester_callback (void *cls,
- const struct GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity * peer,
- enum GNUNET_SCALARPRODUCT_ResponseStatus status,
- uint16_t size, struct GNUNET_SCALARPRODUCT_client_response
*msg,
- uint16_t type)
-{
- uint32_t product_len;
-
- if (status == GNUNET_SCALARPRODUCT_Status_Failure)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client received status
failure\n");
- // In this regression test, requester is supposed to receive status
failure
- // therefore requester_ok is set to 1, to make regression test pass
- requester_ok = 1;
- }
- 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_SCALARPRODUCT_Status_Timeout == status)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client timeout occured\n");
- requester_ok = -1;
- }
- else if (GNUNET_SCALARPRODUCT_Status_ServiceDisconnected == status)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Requester Client service
disconnected!!\n");
- requester_ok = -1;
- }
- 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_SCALARPRODUCT_Status_Success == status)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Requester Client expected response
received!\n");
-
- product_len = ntohl (msg->product_length);
-
- if (0 < product_len)
- {
- gcry_mpi_t result;
- gcry_error_t ret = 0;
- size_t read = 0;
-
- ret = gcry_mpi_scan (&result, GCRYMPI_FMT_USG, (void *) &msg[1],
product_len, &read);
-
- if (0 != ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not convert to mpi
to value!\n");
- ok = -1;
- }
- else
- {
- uint16_t i = 0;
-
- // calculate expected product
- gcry_mpi_t expected_result;
- gcry_mpi_t v1;
- gcry_mpi_t v2;
- gcry_mpi_t v1_v2_prod;
-
- expected_result = gcry_mpi_new (0);
-
- for (i = 0; i < element_count_peer1; i++)
- {
- uint32_t value;
- v1_v2_prod = gcry_mpi_new (0);
-
- // long to gcry_mpi_t
- value = elements_peer1[i] >= 0 ? elements_peer1[i] :
-elements_peer1[i];
- if (elements_peer1[i] < 0)
- {
- v1 = gcry_mpi_new (0);
- gcry_mpi_sub_ui (v1, v1, value);
- }
- else
- v1 = gcry_mpi_set_ui (NULL, value);
-
- // long to gcry_mpi_t
- value = elements_peer2[i] >= 0 ? elements_peer2[i] :
-elements_peer2[i];
- if (elements_peer2[i] < 0)
- {
- v2 = gcry_mpi_new (0);
- gcry_mpi_sub_ui (v2, v2, value);
- }
- else
- v2 = gcry_mpi_set_ui (NULL, value);
-
- gcry_mpi_mul (v1_v2_prod, v1, v2);
- gcry_mpi_add (expected_result, expected_result, v1_v2_prod);
-
- gcry_mpi_release (v1);
- gcry_mpi_release (v2);
- gcry_mpi_release (v1_v2_prod);
-
- }
-
- // compare the result
- if (!gcry_mpi_cmp (expected_result, result))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Scalar Product matches
expected Result!!\n");
- requester_ok = 1;
- }
- else
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "Scalar Product DOES NOT
match expected Result!!\n");
- requester_ok = -1;
- }
- gcry_mpi_release (result);
- gcry_mpi_release (expected_result);
- }
- }
- else
- { //currently not used, but if we get more info due to MESH we will
need this
- LOG (GNUNET_ERROR_TYPE_WARNING, "Error during computation of vector
product, return code: %d\n", product_len);
- requester_ok = -1;
- }
- }
-
- //do_shutdown(&peer2, NULL);
- GNUNET_SCHEDULER_add_now (&do_shutdown, &peer2);
- return;
-}
-
-
-static struct GNUNET_SCALARPRODUCT_QueueEntry *
-requester_request ()
-{
- GNUNET_assert (peer2.vh != NULL);
-
- unsigned int i;
- //uint16_t element_count_peer2 = 0;
- uint16_t mask_length = 0;
- char * begin = input_elements_peer2;
- char * end;
- int32_t element;
-
- struct GNUNET_SCALARPRODUCT_QueueEntry *qe;
-
- struct GNUNET_HashCode key;
- GNUNET_CRYPTO_hash (input_key, strlen (input_key), &key);
-
- int exit_loop = 0;
- /* Read input_elements_peer2, and put in elements_peer2 array */
- do
- {
- unsigned int mcount = element_count_peer2;
- //ignore empty rows of ,,,,,,
- while (*begin == ',')
- begin++;
- // get the length of the current element and replace , with null
- for (end = begin; *end && *end != ','; end++);
-
- if (*end == '\0')
- exit_loop = 1;
-
- if (1 != sscanf (begin, "%" SCNd32, &element))
- {
- FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin);
- ok = -1;
- return NULL;
- }
-
- GNUNET_array_append (elements_peer2, mcount, element);
- element_count_peer2++;
-
- begin = ++end;
- }
- while (!exit_loop && element_count_peer2 < max_mids);
-
- GNUNET_assert (elements_peer2 != NULL);
- GNUNET_assert (element_count_peer2 >= 1);
- mask_length = element_count_peer2 / 8 + (element_count_peer2 % 8 ? 1 : 0);
- mask_peer2 = GNUNET_malloc ((element_count_peer2 / 8) + 2);
- GNUNET_assert (NULL != mask_peer2);
-
- /* Read input_mask_peer2 and read in mask_peer2 array */
- if (NULL != input_mask_peer2)
- {
- begin = input_mask_peer2;
- unsigned short mask_count = 0;
- int exit_loop = 0;
-
- do
- {
- //ignore empty rows of ,,,,,,
- while (* begin == ',')
- begin++;
- // get the length of the current element and replace , with null
- // gnunet_ascii-armor uses base32, thus we can use , as separator!
- for (end = begin; *end && *end != ','; end++);
-
- if (*end == '\0')
- exit_loop = 1;
-
- if (1 != sscanf (begin, "%" SCNd32, &element))
- {
- FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"),
begin);
- ok = -1;
- return NULL;
- }
-
- GNUNET_assert (mask_count <= element_count_peer2);
-
- if (element)
- mask_peer2[mask_count / 8] = mask_peer2[mask_count / 8] | 1 <<
(mask_count % 8);
-
- mask_count++;
- begin = ++end;
- }
- while (!exit_loop);
- // +1 to see if we would have more data, which would indicate
malformed/superficial input
- GNUNET_assert (mask_count == element_count_peer2);
- }
- else
- {
- for (i = 0; i <= mask_length; i++)
- mask_peer2[i] = UCHAR_MAX; // all 1's
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Responder peer key %s\n",
&peer1.our_id);
-
- // TODO : Create the mask array
- qe = GNUNET_SCALARPRODUCT_request (peer2.vh,
- &key,
- &peer1.our_id,
- element_count_peer2,
- mask_length,
- elements_peer2, mask_peer2,
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 10),
- &requester_callback,
- NULL);
-
- if (qe == NULL)
- {
- FPRINTF (stderr, "%s", _ ("Could not send request to scalarproduct
service! Exitting!"));
- ok = -1;
- return NULL;
- }
-
- return qe;
-}
-
-
-/**
- * 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_SCALARPRODUCT_QueueEntry *
-responder_prepare_response ()
-{
- GNUNET_assert (peer1.vh != NULL);
-
- unsigned int i;
- //uint16_t element_count_peer1 = 0;
- char * begin = input_elements_peer1;
- char * end;
- int32_t element;
-
- struct GNUNET_SCALARPRODUCT_QueueEntry *qe;
-
- struct GNUNET_HashCode key;
- GNUNET_CRYPTO_hash (input_key, strlen (input_key), &key);
-
- int exit_loop = 0;
- /* Read input_elements_peer1, and put in elements_peer1 array */
- do
- {
- unsigned int mcount = element_count_peer1;
- //ignore empty rows of ,,,,,,
- while (*begin == ',')
- begin++;
- // get the length of the current element and replace , with null
- for (end = begin; *end && *end != ','; end++);
-
- if (*end == '\0')
- exit_loop = 1;
-
- if (*end == ',')
- *end = '\0';
-
- if (1 != sscanf (begin, "%" SCNd32, &element))
- {
- FPRINTF (stderr, _ ("Could not convert `%s' to int32_t.\n"), begin);
- ok = -1;
- return NULL;
- }
-
- GNUNET_array_append (elements_peer1, mcount, element);
- element_count_peer1++;
-
- begin = ++end;
- }
- while (!exit_loop && element_count_peer1 < max_mids);
-
- GNUNET_assert (elements_peer1 != NULL);
- GNUNET_assert (element_count_peer1 >= 1);
-
- qe = GNUNET_SCALARPRODUCT_prepare_response (peer1.vh,
- &key,
- element_count_peer1,
- elements_peer1,
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 10),
- &responder_callback,
- NULL);
-
- if (qe == NULL)
- {
- FPRINTF (stderr, "%s", _ ("Could not send request to scalarproduct
service! Exitting!"));
- ok = -1;
- return NULL;
- }
- return qe;
-}
-
-
-/**
- * Scheduler task to initiate requester client
- *
- * @param cls void* to struct PeerData
- * @param tc Task Context
- */
-static void
-request_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext
- * tc)
-{
- struct PeerData * peer = cls;
-
- requester_request ();
- return;
-}
-
-
-/**
- * Scheduler task to initiate responder client
- *
- * @param cls void* to struct PeerData
- * @param tc Task Context
- */
-static void
-prepare_response_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext
- * tc)
-{
- struct PeerData * peer = cls;
-
- responder_prepare_response ();
- return;
-}
-
-
-static void
-peer_stop_callback (void *cls,
- const char *emsg)
-{
- GNUNET_TESTBED_peer_destroy (peer2.peer);
-}
-
-/**
- * Destroys Peer2 i.e. the initiator peer (Alice) This function is scheduled to
- * run a few milliseconds after the request has been sent to the Responding
Peer (Bob).
- * This function tries to emulate a crash of Peer2.
- *
- * @param cls Not used
- * @param tc Task Context - Not used
- */
-static void
-destroy_server (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- LOG (GNUNET_ERROR_TYPE_INFO, "\n***\nKilling the Requesting Client,
hopefully before it receives response\n***\n");
- do_shutdown (&peer2, NULL);
- GNUNET_TESTBED_peer_stop (peer2.peer, &peer_stop_callback, NULL);
-}
-
-
-/**
- * Adapter function called to destroy a connection to
- * 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
-scalarproduct_da (void *cls, void *op_result)
-{
- struct PeerData* peer = (struct PeerData*) cls;
-
- GNUNET_SCALARPRODUCT_cancel (peer->vh);
- return;
-}
-
-
-/**
- * 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
- * from GNUNET_TESTBED_service_connect()
- * @return service handle to return in 'op_result', NULL on error
- */
-static void *
-scalarproduct_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct PeerData *p = cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", (&peer1 ==
p) ? 1 : 2,
- GNUNET_i2s (&p->our_id));
-
- switch (setup_state)
- {
- case PEER1_SCALARPRODUCT_CONNECT:
- /* Connect peer 2 to scalarproduct service */
- /* The connect adapter scalarproduct_ca will be called to perform the
actual connection */
- {
- 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 scalarproduct service */
- peer1.vh = GNUNET_SCALARPRODUCT_connect (cfg);
- return peer1.vh;
-
- case PEER2_SCALARPRODUCT_CONNECT:
- /* Actually connect peer 2 to scalarproduct service */
- peer2.vh = GNUNET_SCALARPRODUCT_connect (cfg);
-
-
- if (peer1.vh != NULL && peer2.vh != NULL)
- {
- GNUNET_SCHEDULER_add_now (&prepare_response_task, &peer1);
- GNUNET_SCHEDULER_add_now (&request_task, &peer2);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS, 6),
- &destroy_server, NULL);
- }
- else
- {
- // TODO : Handle error. One of the peers is not connected. Cleanly
shutdown
- ok = -1;
- return NULL;
- }
- return peer2.vh;
- default:
- GNUNET_assert (0);
- }
-}
-
-
-/**
- * Callback to be called when the requested peer information is available
- *
- * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
- * @param op the operation this callback corresponds to
- * @param pinfo the result; will be NULL if the operation has failed
- * @param emsg error message if the operation has failed; will be NULL if the
- * operation is successfull
- */
-static void
-peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_,
- const struct GNUNET_TESTBED_PeerInformation *pinfo,
- const char *emsg)
-{
- GNUNET_assert (NULL == emsg);
- GNUNET_assert (op == op_);
- switch (setup_state)
- {
- case PEER1_GET_IDENTITY:
- {
- memcpy (&peer1.our_id, pinfo->result.id,
- sizeof (struct GNUNET_PeerIdentity));
- GNUNET_TESTBED_operation_done (op);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 id: %s\n", GNUNET_i2s_full
- (&peer1.our_id));
-
- /* Request for peer id of peer 2*/
- op = GNUNET_TESTBED_peer_get_information (peer2.peer,
- GNUNET_TESTBED_PIT_IDENTITY,
- &peerinfo_cb, NULL);
- setup_state = PEER2_GET_IDENTITY;
- }
- break;
- case PEER2_GET_IDENTITY:
- {
- memcpy (&peer2.our_id, pinfo->result.id,
- sizeof (struct GNUNET_PeerIdentity));
- GNUNET_TESTBED_operation_done (op);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n", GNUNET_i2s_full
- (&peer2.our_id));
-
- /* Connect peer 1 to scalarproduct service */
- /* The connect adapter scalarproduct_ca will be called to perform the
actual connection */
- peer1.op = GNUNET_TESTBED_service_connect (&peer1, peer1.peer,
"scalarproduct",
- NULL, NULL,
scalarproduct_ca,
- scalarproduct_da, &peer1);
- setup_state = PEER1_SCALARPRODUCT_CONNECT;
- }
- break;
- default:
- GNUNET_assert (0);
- }
-}
-
-
-/**
- * Signature of a main function for a testcase.
- *
- * @param cls closure
- * @param num_peers number of peers in 'peers'
- * @param peers handle to peers run in the testbed
- */
-static void
-test_master (void *cls, unsigned int num_peers,
- struct GNUNET_TESTBED_Peer **peers)
-{
- GNUNET_assert (NULL != peers);
- GNUNET_assert (NULL != peers[0]);
- GNUNET_assert (NULL != peers[1]);
- peer1.peer = peers[0];
- peer2.peer = peers[1];
- /* Get the peer identity and configuration of peer 1 */
- op = GNUNET_TESTBED_peer_get_information (peer1.peer,
- GNUNET_TESTBED_PIT_IDENTITY,
- &peerinfo_cb, NULL);
- setup_state = PEER1_GET_IDENTITY;
- abort_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 20),
&do_abort,
- NULL);
-}
-
-
-/**
- * Main function
- */
-int
-main (int argc, char **argv)
-{
- uint64_t event_mask;
-
- ok = GNUNET_NO;
- event_mask = 0;
- event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
- max_mids = (GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct
GNUNET_MessageHeader))
- / sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1;
-
- (void) GNUNET_TESTBED_test_run ("test_scalarproduct_api_regression2",
- "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");
- return 1;
- }
- else if (GNUNET_SYSERR == responder_ok)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "Test failing due to some error in
response for responding_client\n");
- return 1;
- }
- else if (GNUNET_SYSERR == requester_ok)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, "Test failing due to some error in
response for requesting client\n");
- return 1;
- }
- else
- return 0;
-}
-
-
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r29350 - gnunet/src/scalarproduct,
gnunet <=