/*
This file is part of GNUnet.
Copyright (C) 2013, 2014, 2017 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License,
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
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file scalarproduct/gnunet-service-scalarproduct_alice.c
* @brief scalarproduct service implementation
* @author Christian M. Fuchs
* @author Christian Grothoff
*/
#include "platform.h"
#include <limits.h>
#include <gcrypt.h>
#include "gnunet_util_lib.h"
#include "gnunet_core_service.h"
#include "gnunet_cadet_service.h"
#include "gnunet_applications.h"
#include "gnunet_protocols.h"
#include "gnunet_scalarproduct_service.h"
#include "gnunet_set_service.h"
#include "scalarproduct.h"
#include "gnunet-service-scalarproduct.h"
#define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__)
/**
* An encrypted element key-value pair.
*/
struct MpiElement
{
/**
* Key used to identify matching pairs of values to multiply.
* Points into an existing data structure, to avoid copying
* and doubling memory use.
*/
const struct GNUNET_HashCode *key;
/**
* Value represented (a).
*/
gcry_mpi_t value;
};
/**
* A scalarproduct session which tracks
* a request form the client to our final response.
*/
struct AliceServiceSession
{
/**
* (hopefully) unique transaction ID
*/
struct GNUNET_HashCode session_id;
/**
* Alice or Bob's peerID
*/
struct GNUNET_PeerIdentity peer;
/**
* The client this request is related to.
*/
struct GNUNET_SERVICE_Client *client;
/**
* The message queue for the client.
*/
struct GNUNET_MQ_Handle *client_mq;
/**
* The message queue for CADET.
*/
struct GNUNET_MQ_Handle *cadet_mq;
/**
* all non-0-value'd elements transmitted to us.
* Values are of type `struct GNUNET_SCALARPRODUCT_Element *`
*/
struct GNUNET_CONTAINER_MultiHashMap *intersected_elements;
/**
* Set of elements for which will conduction an intersection.
* the resulting elements are then used for computing the scalar product.
*/
struct GNUNET_SET_Handle *intersection_set;
/**
* Set of elements for which will conduction an intersection.
* the resulting elements are then used for computing the scalar product.
*/
struct GNUNET_SET_OperationHandle *intersection_op;
/**
* Handl